Back to index

avfs  1.0.1
Functions
archutil.c File Reference
#include "archint.h"

Go to the source code of this file.

Functions

static void archnode_destroy (struct archnode *nod)
struct archnodeav_arch_new_node (struct archive *arch, struct entry *ent, int isdir)
void av_arch_del_node (struct entry *ent)
struct archnodeav_arch_default_dir (struct archive *arch, struct entry *ent)
struct entryav_arch_resolve (struct archive *arch, const char *path, int create, int flags)
int av_arch_isroot (struct archive *arch, struct entry *ent)
struct entryav_arch_create (struct archive *arch, const char *path, int flags)

Function Documentation

static void archnode_destroy ( struct archnode nod) [static]

Definition at line 11 of file archutil.c.

{
    av_free(nod->linkname);
    av_unref_obj(nod->data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct entry* av_arch_create ( struct archive arch,
const char *  path,
int  flags 
) [read]

Definition at line 173 of file archutil.c.

{
    struct archnode *nod;
    struct entry *ent;

    ent = av_arch_resolve(arch, path, 1, flags);
    if(ent == NULL)
        return NULL;

    if(av_arch_isroot(arch, ent)) {
        av_log(AVLOG_WARNING, "Empty filename");
        av_unref_obj(ent);
        return NULL;
    }
    
    nod = (struct archnode *) av_namespace_get(ent);
    if(nod != NULL) {
        av_log(AVLOG_WARNING, "Entry for %s already exists", path);
        av_unref_obj(ent);
        return NULL;
    }

    av_namespace_setflags(ent, flags, 0);

    return ent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct archnode* av_arch_default_dir ( struct archive arch,
struct entry ent 
) [read]

Definition at line 84 of file archutil.c.

{
    struct archnode *nod;
    avmode_t mode;

    nod = av_arch_new_node(arch, ent, 1);

    mode = (arch->st.mode & 0777) | AV_IFDIR;
    if (mode & 0400) mode |= 0100;
    if (mode & 0040) mode |= 0010;
    if (mode & 0004) mode |= 0001;

    nod->st.mode = mode;
    nod->flags |= ANOF_AUTODIR;

    return nod;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void av_arch_del_node ( struct entry ent)

Definition at line 74 of file archutil.c.

{
    struct archnode *nod;

    nod = (struct archnode *) av_namespace_get(ent);
    av_namespace_set(ent, NULL);
    av_unref_obj(nod);
    av_unref_obj(ent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_arch_isroot ( struct archive arch,
struct entry ent 
)

Definition at line 157 of file archutil.c.

{
    int res;
    struct entry *root;
    
    root = av_namespace_subdir(arch->ns, NULL);
    if(root == ent)
        res = 1;
    else
        res = 0;

    av_unref_obj(root);
    
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct archnode* av_arch_new_node ( struct archive arch,
struct entry ent,
int  isdir 
) [read]

Definition at line 17 of file archutil.c.

{
    struct archnode *nod;

    nod = (struct archnode *) av_namespace_get(ent);
    if(nod != NULL) {
        av_unref_obj(nod);
        av_unref_obj(ent);
    }

    AV_NEW_OBJ(nod, archnode_destroy);

    av_default_stat(&nod->st);
    nod->linkname = NULL;
    nod->offset = 0;
    nod->realsize = 0;
    nod->data = NULL;
    nod->flags = 0;
    nod->numopen = 0;

    /* FIXME: This scheme will allocate the same device to a tar file
       inside a tarfile. While this is not fatal, 'find -xdev' would not do
       what is expected.  */

    nod->st.dev = arch->avfs->dev;
    nod->st.ino = av_new_ino(arch->avfs);

    nod->st.mode = 0644 | AV_IFREG;
    nod->st.uid = arch->st.uid;
    nod->st.gid = arch->st.gid;
    nod->st.mtime = arch->st.mtime;
    nod->st.atime = nod->st.mtime;
    nod->st.ctime = nod->st.mtime;
    if(!isdir)
        nod->st.nlink = 1;
    else {
        struct entry *parent;
        struct archnode *parnod;

        nod->st.nlink = 2;        
        parent = av_namespace_parent(ent);
        if(parent != NULL) {
            parnod = (struct archnode *) av_namespace_get(parent);
            if(parnod != NULL) 
                parnod->st.nlink ++;

            av_unref_obj(parent);
        }
    }

    av_namespace_set(ent, nod);
    av_ref_obj(ent);

    return nod;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct entry* av_arch_resolve ( struct archive arch,
const char *  path,
int  create,
int  flags 
) [read]

Definition at line 102 of file archutil.c.

{
    struct entry *ent;
    char *s, *p;
    char *pathdup = av_strdup(path);

    p = pathdup;
    ent = av_namespace_subdir(arch->ns, NULL);
    while(1) {
        struct entry *next;
        struct archnode *nod;
        char c;

        for(;*p == '/'; p++);
        for(s = p; *s && *s != '/'; s++);
        c = *s;
        *s = '\0';
        if(!*p)
            break;

        nod = (struct archnode *) av_namespace_get(ent);
        if(nod == NULL) {
            if(!create) {
                av_unref_obj(ent);
                ent = NULL;
                break;
            }
            av_arch_default_dir(arch, ent);
            av_namespace_setflags(ent, flags, 0);
        }
        else if(!AV_ISDIR(nod->st.mode)) {
            if(create) 
                av_log(AVLOG_WARNING,
                       "ARCH: cannot create %s: Not a directory", path);
            av_unref_obj(ent);
            ent = NULL;
            break;
        }
        
        next = av_namespace_lookup_all(arch->ns, ent, p);
        if(next != NULL) {
            av_unref_obj(ent);
            ent = next;
        }
        
        *s = c;
        p = s;
    }

    av_free(pathdup);

    return ent;
}

Here is the call graph for this function:

Here is the caller graph for this function: