Back to index

avfs  1.0.1
Classes | Functions
uxz.c File Reference
#include "version.h"
#include "xzfile.h"
#include "filecache.h"
#include "oper.h"

Go to the source code of this file.

Classes

struct  xznode
struct  xzhandle

Functions

static void xznode_destroy (struct xznode *nod)
static struct xznodexz_new_node (ventry *ve, struct avstat *stbuf)
static int xz_same (struct xznode *nod, struct avstat *stbuf)
static struct xznodexz_do_get_node (ventry *ve, const char *key, struct avstat *stbuf)
static int xz_getnode (ventry *ve, vfile *base, struct xznode **resp)
static int xz_lookup (ventry *ve, const char *name, void **newp)
static int xz_access (ventry *ve, int amode)
static int xz_open (ventry *ve, int flags, avmode_t mode, void **resp)
static int xz_close (vfile *vf)
static avssize_t xz_read (vfile *vf, char *buf, avsize_t nbyte)
static int xz_getattr (vfile *vf, struct avstat *buf, int attrmask)
int av_init_module_uxz (struct vmodule *module)

Class Documentation

struct xznode

Definition at line 18 of file uxz.c.

Collaboration diagram for xznode:
Class Members
struct xzcache * cache
avino_t ino
struct xzhandle

Definition at line 24 of file uxz.c.

Collaboration diagram for xzhandle:
Class Members
vfile * base
struct xznode * node
struct xzfile * zfil

Function Documentation

int av_init_module_uxz ( struct vmodule module)

Definition at line 230 of file uxz.c.

{
    int res;
    struct avfs *avfs;
    struct ext_info uxz_exts[5];

    uxz_exts[0].from = ".tar.xz",  uxz_exts[0].to = ".tar";
    uxz_exts[1].from = ".txz",  uxz_exts[1].to = ".tar";
    uxz_exts[2].from = ".xz",  uxz_exts[2].to = NULL;
    uxz_exts[3].from = ".lzma",  uxz_exts[3].to = NULL;
    uxz_exts[4].from = NULL;

    res = av_new_avfs("uxz", uxz_exts, AV_VER, AVF_NOLOCK, module, &avfs);
    if(res < 0)
        return res;

    avfs->lookup   = xz_lookup;
    avfs->access   = xz_access;
    avfs->open     = xz_open;
    avfs->close    = xz_close; 
    avfs->read     = xz_read;
    avfs->getattr  = xz_getattr;

    av_add_avfs(avfs);

    return 0;
}

Here is the call graph for this function:

static int xz_access ( ventry *  ve,
int  amode 
) [static]

Definition at line 129 of file uxz.c.

{
    return av_access(ve->mnt->base, amode);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xz_close ( vfile *  vf) [static]

Definition at line 170 of file uxz.c.

{
    struct xzhandle *fil = (struct xzhandle *) vf->data;

    av_unref_obj(fil->zfil);
    av_unref_obj(fil->node);
    av_close(fil->base);
    av_free(fil);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct xznode* xz_do_get_node ( ventry *  ve,
const char *  key,
struct avstat stbuf 
) [static, read]

Definition at line 59 of file uxz.c.

{
    static AV_LOCK_DECL(lock);
    struct xznode *nod;

    AV_LOCK(lock);
    nod = (struct xznode *) av_filecache_get(key);
    if(nod != NULL) {
        if(!xz_same(nod, stbuf)) {
            av_unref_obj(nod);
            nod = NULL;
        }
    }
    
    if(nod == NULL) {
        nod =  xz_new_node(ve, stbuf);
        av_filecache_set(key, nod);
    }
    AV_UNLOCK(lock);

    return nod;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xz_getattr ( vfile *  vf,
struct avstat buf,
int  attrmask 
) [static]

Definition at line 194 of file uxz.c.

{
    int res;
    struct xzhandle *fil = (struct xzhandle *) vf->data;
    struct xznode *nod = fil->node;
    avoff_t size;
    const int basemask = AVA_MODE | AVA_UID | AVA_GID | AVA_MTIME | AVA_ATIME | AVA_CTIME;

    res = av_fgetattr(fil->base, buf, basemask);
    if(res < 0)
        return res;

    if((attrmask & (AVA_SIZE | AVA_BLKCNT)) != 0) {
        res = av_xzfile_size(fil->zfil, fil->node->cache, &size);
        if(res == 0 && size == -1) {
            fil->zfil = av_xzfile_new(fil->base);
            res = av_xzfile_size(fil->zfil, fil->node->cache, &size);
        }
        if(res < 0)
            return res;

        buf->size = size;
        buf->blocks = AV_BLOCKS(buf->size);
    }

    buf->mode &= ~(07000);
    buf->blksize = 4096;
    buf->dev = vf->mnt->avfs->dev;
    buf->ino = nod->ino;
    buf->nlink = 1;
    
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xz_getnode ( ventry *  ve,
vfile *  base,
struct xznode **  resp 
) [static]

Definition at line 83 of file uxz.c.

{
    int res;
    struct avstat stbuf;
    const int attrmask = AVA_INO | AVA_DEV | AVA_SIZE | AVA_MTIME;
    struct xznode *nod;
    char *key;

    res = av_fgetattr(base, &stbuf, attrmask);
    if(res < 0)
        return res;

    res = av_filecache_getkey(ve, &key);
    if(res < 0)
        return res;

    nod = xz_do_get_node(ve, key, &stbuf);

    av_free(key);

    *resp = nod;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xz_lookup ( ventry *  ve,
const char *  name,
void **  newp 
) [static]

Definition at line 107 of file uxz.c.

{
    char *path = (char *) ve->data;
    
    if(path == NULL) {
        if(name[0] != '\0')
            return -ENOENT;
       if(ve->mnt->opts[0] != '\0')
            return -ENOENT;
        path = av_strdup(name);
    }
    else if(name == NULL) {
        av_free(path);
        path = NULL;
    }
    else 
        return -ENOENT;
    
    *newp = path;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct xznode* xz_new_node ( ventry *  ve,
struct avstat stbuf 
) [static, read]

Definition at line 36 of file uxz.c.

{
    struct xznode *nod;

    AV_NEW_OBJ(nod, xznode_destroy);
    nod->sig = *stbuf;
    nod->cache = av_xzcache_new();
    nod->ino = av_new_ino(ve->mnt->avfs);
    
    return nod;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xz_open ( ventry *  ve,
int  flags,
avmode_t  mode,
void **  resp 
) [static]

Definition at line 134 of file uxz.c.

{
    int res;
    vfile *base;
    struct xznode *nod;
    struct xzhandle *fil;

    if(flags & AVO_DIRECTORY)
        return -ENOTDIR;

    if(AV_ISWRITE(flags))
        return -EROFS;

    res = av_open(ve->mnt->base, AVO_RDONLY, 0, &base);
    if(res < 0)
        return res;

    res = xz_getnode(ve, base, &nod);
    if(res < 0) {
        av_close(base);
        return res;
    }

    AV_NEW(fil);
    if((flags & AVO_ACCMODE) != AVO_NOPERM)
        fil->zfil = av_xzfile_new(base);
    else
        fil->zfil = NULL;

    fil->base = base;
    fil->node = nod;
    
    *resp = fil;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static avssize_t xz_read ( vfile *  vf,
char *  buf,
avsize_t  nbyte 
) [static]

Definition at line 182 of file uxz.c.

{
    avssize_t res;
    struct xzhandle *fil = (struct xzhandle *) vf->data;
 
    res = av_xzfile_pread(fil->zfil, fil->node->cache, buf, nbyte, vf->ptr);
    if(res > 0)
        vf->ptr += res;

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int xz_same ( struct xznode nod,
struct avstat stbuf 
) [static]

Definition at line 48 of file uxz.c.

{
    if(nod->sig.ino == stbuf->ino &&
       nod->sig.dev == stbuf->dev &&
       nod->sig.size == stbuf->size &&
       AV_TIME_EQ(nod->sig.mtime, stbuf->mtime))
        return 1;
    else
        return 0;
}

Here is the caller graph for this function:

static void xznode_destroy ( struct xznode nod) [static]

Definition at line 31 of file uxz.c.

{
    av_unref_obj(nod->cache);
}

Here is the call graph for this function:

Here is the caller graph for this function: