Back to index

avfs  1.0.1
Classes | Defines | Functions
archive.h File Reference
#include "avfs.h"
#include "namespace.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  archparams
struct  archnode
struct  archfile

Defines

#define ARF_NOBASE   (1 << 0)
#define ANOF_DIRTY   (1 << 0)
#define ANOF_CREATED   (1 << 1)
#define ANOF_AUTODIR   (1 << 2)

Functions

int av_archive_init (const char *name, struct ext_info *exts, int version, struct vmodule *module, struct avfs **avfsp)
avssize_t av_arch_read (vfile *vf, char *buf, avsize_t nbyte)
struct archnodeav_arch_new_node (struct archive *arch, struct entry *ent, int isdir)
void av_arch_del_node (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)
static struct archfilearch_vfile_file (vfile *vf)

Class Documentation

struct archnode

Definition at line 32 of file archive.h.

Class Members
void * data
int flags
char * linkname
int numopen
avoff_t offset
avoff_t realsize
struct archfile

Definition at line 45 of file archive.h.

Collaboration diagram for archfile:
Class Members
struct archive * arch
vfile * basefile
struct entry * curr
int currn
void * data
struct entry * ent
struct archnode * nod

Define Documentation

#define ANOF_AUTODIR   (1 << 2)

Definition at line 30 of file archive.h.

#define ANOF_CREATED   (1 << 1)

Definition at line 29 of file archive.h.

#define ANOF_DIRTY   (1 << 0)

Definition at line 28 of file archive.h.

#define ARF_NOBASE   (1 << 0)

Definition at line 16 of file archive.h.


Function Documentation

static struct archfile* arch_vfile_file ( vfile *  vf) [static, read]

Definition at line 69 of file archive.h.

{
    return (struct archfile *) vf->data;
}

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:

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:

avssize_t av_arch_read ( vfile *  vf,
char *  buf,
avsize_t  nbyte 
)

Definition at line 423 of file archive.c.

{
    int res;
    avoff_t realoff;
    struct archfile *fil = arch_vfile_file(vf);
    struct archnode *nod = fil->nod;
    avsize_t nact;

    if(AV_ISDIR(nod->st.mode))
        return -EISDIR;

    if(nbyte == 0 || vf->ptr >= nod->realsize)
        return 0;

    realoff = vf->ptr + nod->offset;
    nact = AV_MIN(nbyte, (avsize_t) (nod->realsize - vf->ptr));

    res = av_pread(fil->basefile, buf, nact, realoff);
    if(res > 0)
        vf->ptr += res;

    return res;
}

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:

int av_archive_init ( const char *  name,
struct ext_info exts,
int  version,
struct vmodule module,
struct avfs **  avfsp 
)

Definition at line 598 of file archive.c.

{
    int res;
    struct avfs *avfs;
    struct archparams *ap;

    res = av_new_avfs(name, exts, version, AVF_NOLOCK, module, &avfs);
    if(res < 0)
        return res;

    avfs->lookup    = arch_lookup;
    avfs->putent    = arch_putent;
    avfs->copyent   = arch_copyent;
    avfs->getpath   = arch_getpath;
    avfs->open      = arch_open;
    avfs->close     = arch_close;
    avfs->read      = arch_read;
    avfs->readdir   = arch_readdir;
    avfs->getattr   = arch_getattr;
    avfs->access    = arch_access;
    avfs->readlink  = arch_readlink;
    avfs->destroy   = arch_destroy;

    AV_NEW(ap);
    ap->data = NULL;
    ap->flags = 0;
    ap->parse = NULL;
    ap->open = NULL;
    ap->close = NULL;
    ap->read = av_arch_read;
    ap->release = NULL;

    avfs->data = ap;

    *avfsp = avfs;
    
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: