Back to index

avfs  1.0.1
Functions
virtual.h File Reference
#include <sys/types.h>
#include <dirent.h>
#include <utime.h>
#include <sys/stat.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int virt_stat (const char *path, struct stat *buf)
int virt_lstat (const char *path, struct stat *buf)
int virt_access (const char *path, int amode)
int virt_readlink (const char *path, char *buf, size_t bsiz)
int virt_truncate (const char *path, off_t length)
int virt_utime (const char *path, struct utimbuf *buf)
int virt_chmod (const char *path, mode_t mode)
int virt_chown (const char *path, uid_t owner, gid_t grp)
int virt_lchown (const char *path, uid_t owner, gid_t grp)
int virt_unlink (const char *path)
int virt_rmdir (const char *path)
int virt_mkdir (const char *path, mode_t mode)
int virt_mknod (const char *path, mode_t mode, dev_t dev)
int virt_symlink (const char *path, const char *newpath)
int virt_rename (const char *path, const char *newpath)
int virt_link (const char *path, const char *newpath)
int virt_fstat (int fh, struct stat *buf)
int virt_ftruncate (int fh, off_t length)
int virt_fchmod (int fh, mode_t mode)
int virt_fchown (int fh, uid_t owner, gid_t grp)
int virt_open (const char *path, int flags, mode_t mode)
int virt_close (int fh)
ssize_t virt_read (int fh, void *buf, size_t nbyte)
ssize_t virt_write (int fh, const void *buf, size_t nbyte)
off_t virt_lseek (int fh, off_t offset, int whence)
DIR * virt_opendir (const char *path)
int virt_closedir (DIR *dirp)
struct dirent * virt_readdir (DIR *dirp)
void virt_rewinddir (DIR *dirp)
int virt_remove (const char *path)
int virt_islocal (const char *path)

Function Documentation

int virt_access ( const char *  path,
int  amode 
)

Definition at line 517 of file redir.c.

{
       int ret;
       mm_segment_t old_fs;
       char *newfilename;
       
       if(!cwd_virtual()) {
              ret = (*orig_access)(filename, mode);
              if(ret != -ENOENT) 
                     return ret;
       }
       else 
              ret = 0;

       newfilename = resolve_name(filename, 1, 1);
       if(!newfilename) {
              if(ret)
                     return ret;
              else
                     return (*orig_access)(filename, mode);
       }
       if(IS_ERR(newfilename))
              return PTR_ERR(newfilename);

       DEB((KERN_INFO "ACCESS: trying '%s'\n", newfilename));
              
       old_fs = get_fs();
       set_fs(get_ds());
       ret = (*orig_access)(newfilename, mode);
       set_fs(old_fs);
       kfree(newfilename);

       DEB((KERN_INFO "ACCESS: result %i\n", ret));
       
       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_chmod ( const char *  path,
mode_t  mode 
)

Definition at line 378 of file virtual.c.

{
    struct avstat stbuf;

    stbuf.mode = mode & 07777;

    return common_setattr(path, &stbuf, AVA_MODE, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_chown ( const char *  path,
uid_t  owner,
gid_t  grp 
)

Definition at line 403 of file virtual.c.

{
    return common_chown(path, owner, grp, 0);
}

Here is the call graph for this function:

int virt_close ( int  fh)

Definition at line 55 of file virtual.c.

{
    int res;
    int errno_save = errno;

    res = av_fd_close(fd);
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_closedir ( DIR *  dirp)

Definition at line 229 of file virtual.c.

{
    int res;
    AVDIR *dp = (AVDIR *) dirp;
    int errno_save = errno;
    int fd;

    if(dp == NULL) {
       errno = EINVAL;
       return -1;
    }
    
    fd = dp->fd;
    av_free(dp);
    res = av_fd_close(fd);
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_fchmod ( int  fh,
mode_t  mode 
)

Definition at line 443 of file virtual.c.

{
    struct avstat stbuf;
    
    stbuf.mode = mode & 07777;

    return common_fsetattr(fd, &stbuf, AVA_MODE);
}

Here is the call graph for this function:

int virt_fchown ( int  fh,
uid_t  owner,
gid_t  grp 
)

Definition at line 452 of file virtual.c.

{
    struct avstat stbuf;
    int attrmask = 0;
        
    stbuf.uid = owner;
    stbuf.gid = grp;

    if(owner != (uid_t) -1)
       attrmask |= AVA_UID;
    if(grp != (gid_t) -1)
       attrmask |= AVA_GID;

    return common_fsetattr(fd, &stbuf, attrmask);
}

Here is the call graph for this function:

int virt_fstat ( int  fh,
struct stat buf 
)

Definition at line 133 of file virtual.c.

{
    int res;
    struct avstat avbuf;
    int errno_save = errno;

    res = av_fd_getattr(fd, &avbuf, AVA_ALL);
    if(res < 0) {
        errno = -res;
        return -1;
    }
    avstat_to_stat(buf, &avbuf);

    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_ftruncate ( int  fh,
off_t  length 
)

Definition at line 413 of file virtual.c.

{
    int res;
    int errno_save = errno;
    
    res = av_fd_truncate(fd, length);
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

int virt_islocal ( const char *  path)

Definition at line 693 of file virtual.c.

{
    int res;
    ventry *ve;
    int errno_save = errno;
    int erg = 0;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
        if(ve->mnt->base == NULL)
            erg = 1;
        else
            erg = 0;
        av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return erg;
}

Here is the call graph for this function:

int virt_lchown ( const char *  path,
uid_t  owner,
gid_t  grp 
)

Definition at line 408 of file virtual.c.

{
    return common_chown(path, owner, grp, AVO_NOFOLLOW);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_link ( const char *  path,
const char *  newpath 
)

Definition at line 650 of file virtual.c.

{
    int res;
    ventry *ve;
    ventry *newve;
    int errno_save = errno;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
       res = av_get_ventry(newpath, 0, &newve);
       if(res == 0) {
            res = av_link(ve, newve);
           av_free_ventry(newve);
       }
       av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

off_t virt_lseek ( int  fh,
off_t  offset,
int  whence 
)

Definition at line 101 of file virtual.c.

{
    off_t res;
    int errno_save = errno;

    res = av_fd_lseek(fd, offset, whence);
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 483 of file redir.c.

{
       int ret;
       char *newfilename;

       if(!cwd_virtual()) {
              ret = (*orig_lstat)(filename, statbuf);
              if(ret != -ENOENT) 
                     return ret;
       }
       else 
              ret = 0;

       newfilename = resolve_name(filename, 1, 0);
       if(!newfilename) {
              if(ret)
                     return ret;
              else
                     return (*orig_lstat)(filename, statbuf);
       }
       if(IS_ERR(newfilename))
              return PTR_ERR(newfilename);

       DEB((KERN_INFO "LSTAT: trying '%s'\n", newfilename));

       ret = do_orig_stat(orig_lstat, newfilename, statbuf);
       kfree(newfilename);

       DEB((KERN_INFO "LSTAT: result %i\n", ret));

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_mkdir ( const char *  path,
mode_t  mode 
)

Definition at line 565 of file virtual.c.

{
    int res;
    ventry *ve;
    int errno_save = errno;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
        res = av_mkdir(ve, mode);
        av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_mknod ( const char *  path,
mode_t  mode,
dev_t  dev 
)

Definition at line 585 of file virtual.c.

{
    int res;
    ventry *ve;
    int errno_save = errno;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
        res = av_mknod(ve, mode, dev);
       av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_open ( const char *  path,
int  flags,
mode_t  mode 
)

Definition at line 40 of file virtual.c.

{
    int res;
    int errno_save = errno;

    res = av_fd_open(path, oflags_to_avfs(flags), mode & 07777);
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return res;
}

Here is the call graph for this function:

DIR* virt_opendir ( const char *  path)

Definition at line 210 of file virtual.c.

{
    AVDIR *dp;
    int res;
    int errno_save = errno;

    res = av_fd_open(path, AVO_DIRECTORY, 0);
    if(res < 0) {
        errno = -res;
        return NULL;
    }

    AV_NEW(dp);
    dp->fd = res;

    errno = errno_save;
    return (DIR *) dp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t virt_read ( int  fh,
void *  buf,
size_t  nbyte 
)

Definition at line 86 of file virtual.c.

{
    ssize_t res;
    int errno_save = errno;

    res = av_fd_read(fd, buf, nbyte);
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct dirent* virt_readdir ( DIR *  dirp) [read]

Definition at line 288 of file virtual.c.

{
    int res;
    struct avdirent buf;
    avoff_t n;
    AVDIR *dp = (AVDIR *) dirp;
    int errno_save = errno;

    if(dp == NULL) {
       errno = EINVAL;
       return NULL;
    }
    res = av_fd_readdir(dp->fd, &buf, &n);
    if(res <= 0) {
        if(res < 0)
            errno = -res;
        else
            errno = errno_save;
        return NULL;
    }

    avdirent_to_dirent(&dp->entry, &buf, n);
    av_free(buf.name);

    errno = errno_save;
    return &dp->entry;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_readlink ( const char *  path,
char *  buf,
size_t  bsiz 
)

Definition at line 500 of file virtual.c.

{
    int res;
    ventry *ve;
    char *avbuf;
    int errno_save = errno;
   
    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
        res = av_readlink(ve, &avbuf);
       if(res == 0) {
           res = copy_readlink(buf, bsiz, avbuf);
           av_free(avbuf);
       }
       av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return res;
}

Here is the call graph for this function:

int virt_remove ( const char *  path)

Definition at line 675 of file virtual.c.

{
    struct stat stbuf;

    if(path != NULL) {
        if(virt_lstat(path, &stbuf) == 0) {
            if(S_ISDIR(stbuf.st_mode)) {
                return virt_rmdir(path);
            } else {
                return virt_unlink(path);
            }
        }
    }

    errno = EFAULT;
    return -1;
}

Here is the call graph for this function:

int virt_rename ( const char *  path,
const char *  newpath 
)

Definition at line 625 of file virtual.c.

{
    int res;
    ventry *ve;
    ventry *newve;
    int errno_save = errno;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
       res = av_get_ventry(newpath, 0, &newve);
       if(res == 0) {
            res = av_rename(ve, newve);
           av_free_ventry(newve);
       }
       av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void virt_rewinddir ( DIR *  dirp)

Definition at line 253 of file virtual.c.

{
    int res;
    AVDIR *dp = (AVDIR *) dirp;
    int errno_save = errno;

    if(dp == NULL) {
       errno = EINVAL;
       return;
    }

    res = av_fd_lseek(dp->fd, 0, AVSEEK_SET);
    if(res < 0)
        errno = -res;

    errno = errno_save;
}

Here is the call graph for this function:

int virt_rmdir ( const char *  path)

Definition at line 545 of file virtual.c.

{
    int res;
    ventry *ve;
    int errno_save = errno;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
        res = av_rmdir(ve);
       av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 450 of file redir.c.

{
       int ret;
       char *newfilename;

       if(!cwd_virtual()) {
              ret = (*orig_stat)(filename, statbuf);
              if(ret != -ENOENT) 
                     return ret;
       }
       else 
              ret = 0;

       newfilename = resolve_name(filename, 1, 1);
       if(!newfilename) {
              if(ret)
                     return ret;
              else
                     return (*orig_stat)(filename, statbuf);
       }
       if(IS_ERR(newfilename))
              return PTR_ERR(newfilename);

       DEB((KERN_INFO "STAT: trying '%s'\n", newfilename));

       ret = do_orig_stat(orig_stat, newfilename, statbuf);
       kfree(newfilename);

       DEB((KERN_INFO "STAT: result %i\n", ret));

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_symlink ( const char *  path,
const char *  newpath 
)

Definition at line 605 of file virtual.c.

{
    int res;
    ventry *newve;
    int errno_save = errno;

    res = av_get_ventry(newpath, 0, &newve);
    if(res == 0) {
        res = av_symlink(path, newve);
       av_free_ventry(newve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_truncate ( const char *  path,
off_t  length 
)

Definition at line 317 of file virtual.c.

{
    int res;
    vfile vf;
    int errno_save = errno;

    res = open_path(&vf, path, AVO_WRONLY, 0);
    if(res == 0) {
        av_file_truncate(&vf, length);
        av_file_close(&vf);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_unlink ( const char *  path)

Definition at line 525 of file virtual.c.

{
    int res;
    ventry *ve;
    int errno_save = errno;

    res = av_get_ventry(path, 0, &ve);
    if(res == 0) {
        res = av_unlink(ve);
       av_free_ventry(ve);
    }
    if(res < 0) {
        errno = -res;
        return -1;
    }
    
    errno = errno_save;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int virt_utime ( const char *  path,
struct utimbuf *  buf 
)

Definition at line 358 of file virtual.c.

{
    struct avstat stbuf;

    if(buf == NULL) {
        int errno_save = errno;
       av_curr_time(&stbuf.mtime);
        errno = errno_save;
       stbuf.atime = stbuf.mtime;
    }
    else {
       stbuf.mtime.sec = buf->modtime;
       stbuf.mtime.nsec = 0;
       stbuf.atime.sec = buf->actime;
       stbuf.atime.nsec = 0;
    }
    
    return common_setattr(path, &stbuf, AVA_MTIME | AVA_ATIME, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t virt_write ( int  fh,
const void *  buf,
size_t  nbyte 
)

Definition at line 71 of file virtual.c.

{
    ssize_t res;
    int errno_save = errno;

    res = av_fd_write(fd, buf, nbyte);
    if(res < 0) {
        errno = -res;
        return -1;
    }

    errno = errno_save;
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function: