Back to index

avfs  1.0.1
Functions
stat.c File Reference
#include "utils.h"
#include "config.h"
#include <sys/stat.h>

Go to the source code of this file.

Functions

static int real_stat (const char *path, struct stat *buf, int deref, int undersc)
static int real_fstat (int fd, struct stat *buf, int undersc)
static int real_access (const char *path, int amode, int undersc)
static int cmd_getattr (const char *path, struct avstat *buf, int deref, char *pathbuf, int attrmask)
static int cmd_access (const char *path, int amode, char *pathbuf)
static int fstat_server (int serverfh, struct avstat *buf)
static void convert_stat (struct avstat *vbuf, struct stat *lbuf)
static int virt_stat (const char *path, struct stat *buf, int deref, int undersc)
static int virt_fstat (int fd, struct stat *buf, int undersc)
static int virt_access (const char *path, int amode, int undersc)
int lstat (const char *path, struct stat *buf)
int _lstat (const char *path, struct stat *buf)
int stat (const char *path, struct stat *buf)
int _stat (const char *path, struct stat *buf)
int fstat (int fd, struct stat *buf)
int _fstat (int fd, struct stat *buf)
int access (const char *path, int amode)
int _access (const char *path, int amode)

Function Documentation

int _access ( const char *  path,
int  amode 
)

Definition at line 612 of file stat.c.

{
    return virt_access(path, amode, 1);
}

Here is the call graph for this function:

int _fstat ( int  fd,
struct stat buf 
)

Definition at line 590 of file stat.c.

{
    return virt_fstat(fd, buf, 1);
}

Here is the call graph for this function:

int _lstat ( const char *  path,
struct stat buf 
)

Definition at line 570 of file stat.c.

{
    return virt_stat(path, buf, 0, 1);
}

Here is the call graph for this function:

int _stat ( const char *  path,
struct stat buf 
)

Definition at line 580 of file stat.c.

{
    return virt_stat(path, buf, 1, 1);
}

Here is the call graph for this function:

int access ( const char *  path,
int  amode 
)

Definition at line 607 of file stat.c.

{
    return virt_access(path, amode, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int cmd_access ( const char *  path,
int  amode,
char *  pathbuf 
) [static]

Definition at line 219 of file stat.c.

{
    int res;
    struct avfs_out_message outmsg;
    struct avfs_in_message inmsg;
    struct avfs_cmd cmd;
    struct avfs_result result;
    const char *abspath;

    res = __av_get_abs_path(path, pathbuf, &abspath);
    if(res < 0)
        return res;
    
    cmd.type = CMD_ACCESS;
    cmd.u.access.amode = amode;
    
    outmsg.num = 2;
    outmsg.seg[0].len = sizeof(cmd);
    outmsg.seg[0].buf = &cmd;
    outmsg.seg[1].len = strlen(abspath) + 1;
    outmsg.seg[1].buf = abspath;

    inmsg.seg[0].buf = &result;
    inmsg.seg[1].buf = pathbuf;

    res = __av_send_message(&outmsg, &inmsg, 0);
    if(res == -1)
        return -EIO;

    if(inmsg.seg[1].len == 0)
        pathbuf[0] = '\0';

    return result.result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int cmd_getattr ( const char *  path,
struct avstat buf,
int  deref,
char *  pathbuf,
int  attrmask 
) [static]

Definition at line 178 of file stat.c.

{
    int res;
    struct avfs_out_message outmsg;
    struct avfs_in_message inmsg;
    struct avfs_cmd cmd;
    struct avfs_result result;
    const char *abspath;

    res = __av_get_abs_path(path, pathbuf, &abspath);
    if(res < 0)
        return res;
    
    cmd.type = CMD_GETATTR;
    if(deref)
        cmd.u.getattr.flags = 0;
    else
        cmd.u.getattr.flags = AVO_NOFOLLOW;
    cmd.u.getattr.attrmask = attrmask;
    
    outmsg.num = 2;
    outmsg.seg[0].len = sizeof(cmd);
    outmsg.seg[0].buf = &cmd;
    outmsg.seg[1].len = strlen(abspath) + 1;
    outmsg.seg[1].buf = abspath;

    inmsg.seg[0].buf = &result;
    inmsg.seg[1].buf = pathbuf;
    inmsg.seg[2].buf = buf;

    res = __av_send_message(&outmsg, &inmsg, 0);
    if(res == -1)
        return -EIO;

    if(inmsg.seg[1].len == 0)
        pathbuf[0] = '\0';

    return result.result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void convert_stat ( struct avstat vbuf,
struct stat lbuf 
) [static]

Definition at line 354 of file stat.c.

{
    memset((void *) lbuf, 0, sizeof(*lbuf));
  
    lbuf->st_dev      = vbuf->dev;
    lbuf->st_ino      = vbuf->ino;
    lbuf->st_mode     = vbuf->mode;
    lbuf->st_nlink    = vbuf->nlink;
    lbuf->st_uid      = vbuf->uid;
    lbuf->st_gid      = vbuf->gid;
    lbuf->st_rdev     = vbuf->rdev;
    lbuf->st_size     = vbuf->size;
    lbuf->st_blksize  = vbuf->blksize;
    lbuf->st_blocks   = vbuf->blocks;
    lbuf->st_atime    = vbuf->atime.sec;
    lbuf->st_mtime    = vbuf->mtime.sec;
    lbuf->st_ctime    = vbuf->ctime.sec;
}

Here is the caller graph for this function:

int fstat ( int  fd,
struct stat buf 
)

Definition at line 585 of file stat.c.

{
    return virt_fstat(fd, buf, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int fstat_server ( int  serverfh,
struct avstat buf 
) [static]

Definition at line 255 of file stat.c.

{
    int res;
    struct avfs_out_message outmsg;
    struct avfs_in_message inmsg;
    struct avfs_cmd cmd;
    struct avfs_result result;

    cmd.type = CMD_FSTAT;
    cmd.u.fdops.serverfh = serverfh;
    
    outmsg.num = 1;
    outmsg.seg[0].len = sizeof(cmd);
    outmsg.seg[0].buf = &cmd;

    inmsg.seg[0].buf = &result;
    inmsg.seg[1].buf = buf;

    res = __av_send_message(&outmsg, &inmsg, 0);
    if(res == -1)
        return -EIO;

    return result.result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lstat ( const char *  path,
struct stat buf 
)

Definition at line 565 of file stat.c.

{
    return virt_stat(path, buf, 0, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int real_access ( const char *  path,
int  amode,
int  undersc 
) [static]

Definition at line 160 of file stat.c.

{
    if(undersc == 0) {
        static int (*prev)(const char *, int);
        if(!prev)
            prev = (int (*)(const char *, int))  __av_get_real("access");
        
        return prev(path, amode);
    }
    else {
        static int (*prev)(const char *, int);
        if(!prev)
            prev = (int (*)(const char *, int))  __av_get_real("_access");
        
        return prev(path, amode);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int real_fstat ( int  fd,
struct stat buf,
int  undersc 
) [static]

Definition at line 119 of file stat.c.

{
    if(undersc == 0) {
        static int (*prev)(int, struct stat *);
        if(!prev)
            prev = (int (*)(int, struct stat *)) __av_get_real("fstat");
        
        return prev(fd, buf);
    }
    else {
        static int (*prev)(int, struct stat *);
        if(!prev)
            prev = (int (*)(int, struct stat *)) __av_get_real("_fstat");
        
        return prev(fd, buf);        
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int real_stat ( const char *  path,
struct stat buf,
int  deref,
int  undersc 
) [static]

Definition at line 78 of file stat.c.

{
    if(!deref) {
        if(undersc == 0) {
            static int (*prev)(const char *, struct stat *);
            if(!prev) 
                prev = (int (*)(const char *, struct stat *))
                    __av_get_real("lstat");
            
            return prev(path, buf);
        }
        else {
            static int (*prev)(const char *, struct stat *);
            if(!prev) 
                prev = (int (*)(const char *, struct stat *))
                    __av_get_real("_lstat");
            
            return prev(path, buf);
        }
    }
    else {
        if(undersc == 0) {
            static int (*prev)(const char *, struct stat *);
            if(!prev) 
                prev = (int (*)(const char *, struct stat *))
                    __av_get_real("stat");
            
            return prev(path, buf);
        }
        else {
            static int (*prev)(const char *, struct stat *);
            if(!prev) 
                prev = (int (*)(const char *, struct stat *))
                    __av_get_real("_stat");
            
            return prev(path, buf);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int stat ( const char *  path,
struct stat buf 
)

Definition at line 575 of file stat.c.

{
    return virt_stat(path, buf, 1, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int virt_access ( const char *  path,
int  amode,
int  undersc 
) [static]

Definition at line 506 of file stat.c.

{
    int res = 0;
    int local = 0;

    if(__av_maybe_local(path)) {
        res = real_access(path, amode, undersc);
        local = __av_is_local(res, path);
    }
    
    if(!local) {
        int errnosave;
        char pathbuf[PATHBUF_LEN];

        errnosave = errno;
        res = cmd_access(path, amode, pathbuf);
        errno = errnosave;
        if(pathbuf[0])
            res = real_access(pathbuf, amode, undersc);
        else if(res < 0)
            errno = -res, res = -1;
    }

    return res;
}

Here is the call graph for this function:

static int virt_fstat ( int  fd,
struct stat buf,
int  undersc 
) [static]

Definition at line 403 of file stat.c.

{
    int res;

    if(!FD_OK(fd) || !ISVIRTUAL(fd))
        res =  real_fstat(fd, buf, undersc);
    else {
        struct avstat vbuf;
        int errnosave = errno;
        res = fstat_server(SERVERFH(fd), &vbuf);
        if(res < 0)
            errno = -res, res = -1;
        else {
            errno = errnosave;
            convert_stat(&vbuf, buf);
        }
    }

    return res;
}

Here is the call graph for this function:

static int virt_stat ( const char *  path,
struct stat buf,
int  deref,
int  undersc 
) [static]

Definition at line 373 of file stat.c.

{
    int res = 0;
    int local = 0;

    if(__av_maybe_local(path)) {
        res = real_stat(path, buf, deref, undersc);
        local = __av_is_local(res, path);
    }
    
    if(!local) {
        int errnosave;
        struct avstat vbuf;
        char pathbuf[PATHBUF_LEN];

        errnosave = errno;
        res = cmd_getattr(path, &vbuf, deref, pathbuf, AVA_ALL);
        errno = errnosave;
        if(pathbuf[0])
            res = real_stat(pathbuf, buf, deref, undersc);
        else if(res < 0)
            errno = -res, res = -1;
        else
            convert_stat(&vbuf, buf);
    }

    return res;
}

Here is the call graph for this function: