Back to index

avfs  1.0.1
Defines | Functions
file.c File Reference
#include "utils.h"
#include "config.h"
#include <dirent.h>

Go to the source code of this file.

Defines

#define AVFS_DIR_RECLEN   ((size_t)(((struct dirent *)0)->d_name)+NAME_MAX+1)

Functions

static off_t real_lseek (int fd, off_t offset, int whence, int undersc)
static ssize_t real_read (int fd, void *buf, size_t nbyte, int undersc)
static ssize_t real_write (int fd, const void *buf, size_t nbyte, int undersc)
static int real_getdents (int fd, struct dirent *buf, size_t nbyte, int undersc)
static avoff_t cmd_lseek (int serverfh, avoff_t offset, int whence)
static ssize_t cmd_read (int serverfh, void *buf, size_t nbyte)
static ssize_t cmd_write (int serverfh, const void *buf, size_t nbyte)
static off_t virt_lseek (int fd, off_t offset, int whence, int undersc)
static ssize_t virt_read (int fd, void *buf, size_t nbyte, int undersc)
static ssize_t virt_write (int fd, const void *buf, size_t nbyte, int undersc)
static int cmd_readdir (int serverfh, struct avfs_direntry *de, char *name)
static void avfs_direntry_to_dirent (struct dirent *ent, struct avfs_direntry *avent)
static int virt_getdents (int fd, struct dirent *buf, size_t nbyte, int undersc)
off_t lseek (int fd, off_t offset, int whence)
off_t _lseek (int fd, off_t offset, int whence)
ssize_t read (int fd, void *buf, size_t nbyte)
ssize_t _read (int fd, void *buf, size_t nbyte)
ssize_t write (int fd, const void *buf, size_t nbyte)
ssize_t _write (int fd, const void *buf, size_t nbyte)
int getdents (int fd, struct dirent *buf, size_t nbyte)
int _getdents (int fd, struct dirent *buf, size_t nbyte)

Define Documentation

#define AVFS_DIR_RECLEN   ((size_t)(((struct dirent *)0)->d_name)+NAME_MAX+1)

Definition at line 376 of file file.c.


Function Documentation

int _getdents ( int  fd,
struct dirent *  buf,
size_t  nbyte 
)

Definition at line 477 of file file.c.

{
    return virt_getdents(fd, buf, nbyte, 1);
}

Here is the call graph for this function:

off_t _lseek ( int  fd,
off_t  offset,
int  whence 
)

Definition at line 434 of file file.c.

{
    return virt_lseek(fd, offset, whence, 1);
}

Here is the call graph for this function:

ssize_t _read ( int  fd,
void *  buf,
size_t  nbyte 
)

Definition at line 445 of file file.c.

{
    return virt_read(fd, buf, nbyte, 1);
}

Here is the call graph for this function:

ssize_t _write ( int  fd,
const void *  buf,
size_t  nbyte 
)

Definition at line 455 of file file.c.

{
    return virt_write(fd, buf, nbyte, 1);
}

Here is the call graph for this function:

static void avfs_direntry_to_dirent ( struct dirent *  ent,
struct avfs_direntry avent 
) [static]

Definition at line 378 of file file.c.

{
    ent->d_ino = avent->ino;
    ent->d_off = avent->n * AVFS_DIR_RECLEN; 
    ent->d_reclen = AVFS_DIR_RECLEN;
}

Here is the caller graph for this function:

static avoff_t cmd_lseek ( int  serverfh,
avoff_t  offset,
int  whence 
) [static]

Definition at line 150 of file file.c.

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

    cmd.type = CMD_LSEEK;
    cmd.u.lseek.serverfh = serverfh;
    cmd.u.lseek.offset = offset;
    cmd.u.lseek.whence = whence;
    
    outmsg.num = 1;
    outmsg.seg[0].len = sizeof(cmd);
    outmsg.seg[0].buf = &cmd;

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

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

    return result.u.lseek.offset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static ssize_t cmd_read ( int  serverfh,
void *  buf,
size_t  nbyte 
) [static]

Definition at line 176 of file file.c.

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

    cmd.type = CMD_READ;
    cmd.u.readwrite.serverfh = serverfh;
    cmd.u.readwrite.nbyte = nbyte;
    
    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:

static int cmd_readdir ( int  serverfh,
struct avfs_direntry de,
char *  name 
) [static]

Definition at line 308 of file file.c.

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

    cmd.type = CMD_READDIR;
    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 = de;
    inmsg.seg[2].buf = name;

    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:

static ssize_t cmd_write ( int  serverfh,
const void *  buf,
size_t  nbyte 
) [static]

Definition at line 202 of file file.c.

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

    cmd.type = CMD_WRITE;
    cmd.u.readwrite.serverfh = serverfh;
    cmd.u.readwrite.nbyte = nbyte;
    
    outmsg.num = 2;
    outmsg.seg[0].len = sizeof(cmd);
    outmsg.seg[0].buf = &cmd;
    outmsg.seg[1].len = nbyte;
    outmsg.seg[1].buf = buf;

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

    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 getdents ( int  fd,
struct dirent *  buf,
size_t  nbyte 
)

Definition at line 472 of file file.c.

{
    return virt_getdents(fd, buf, nbyte, 0);
}

Here is the call graph for this function:

off_t lseek ( int  fd,
off_t  offset,
int  whence 
)

Definition at line 429 of file file.c.

{
    return virt_lseek(fd, offset, whence, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t read ( int  fd,
void *  buf,
size_t  nbyte 
)

Definition at line 440 of file file.c.

{
    return virt_read(fd, buf, nbyte, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int real_getdents ( int  fd,
struct dirent *  buf,
size_t  nbyte,
int  undersc 
) [static]

Definition at line 127 of file file.c.

{
    if(undersc == 0) {
        static int (*prev)(int, struct dirent *, size_t);
        
        if(!prev)
            prev = (int (*)(int, struct dirent *, size_t)) 
                __av_get_real("getdents");
        
        return prev(fd, buf, nbyte);
    }
    else {
        static int (*prev)(int, struct dirent *, size_t);
        
        if(!prev)
            prev = (int (*)(int, struct dirent *, size_t)) 
                __av_get_real("_getdents");
        
        return prev(fd, buf, nbyte);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static off_t real_lseek ( int  fd,
off_t  offset,
int  whence,
int  undersc 
) [static]

Definition at line 37 of file file.c.

{
    if(undersc == 0) {
        static off_t (*prev)(int, off_t, int);
        
        if(!prev)
            prev = (off_t (*)(int, off_t, int)) __av_get_real("lseek");
        
        return prev(fd, offset, whence);
    }
    else {
        static off_t (*prev)(int, off_t, int);
        
        if(!prev)
            prev = (off_t (*)(int, off_t, int)) __av_get_real("_lseek");
        
        return prev(fd, offset, whence);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static ssize_t real_read ( int  fd,
void *  buf,
size_t  nbyte,
int  undersc 
) [static]

Definition at line 58 of file file.c.

{
    if(undersc == 0) {
        static ssize_t (*prev)(int, void *, size_t);
        
        if(!prev)
            prev = (ssize_t (*)(int, void *, size_t)) __av_get_real("read");
        
        return prev(fd, buf, nbyte);
    }
    else {
        static ssize_t (*prev)(int, void *, size_t);
        
        if(!prev)
            prev = (ssize_t (*)(int, void *, size_t)) __av_get_real("_read");
        
        return prev(fd, buf, nbyte);

    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static ssize_t real_write ( int  fd,
const void *  buf,
size_t  nbyte,
int  undersc 
) [static]

Definition at line 79 of file file.c.

{
    if(undersc == 0) {
        static ssize_t (*prev)(int, const void *, size_t);
        
        if(!prev)
            prev = (ssize_t (*)(int, const void *, size_t))
                __av_get_real("write");
        
        return prev(fd, buf, nbyte);
    }
    else {
        static ssize_t (*prev)(int, const void *, size_t);
        
        if(!prev)
            prev = (ssize_t (*)(int, const void *, size_t))
                __av_get_real("_write");
        
        return prev(fd, buf, nbyte);

    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int virt_getdents ( int  fd,
struct dirent *  buf,
size_t  nbyte,
int  undersc 
) [static]

Definition at line 386 of file file.c.

{
    int res;

    if(!FD_OK(fd) || !ISVIRTUAL(fd))
        res =  real_getdents(fd, buf, nbyte, undersc);
    else {
        struct avfs_direntry de;
        int errnosave;

        if(nbyte < AVFS_DIR_RECLEN) {
            errno = EINVAL;
            return -1;
        }

        errnosave = errno;
        res = cmd_readdir(SERVERFH(fd), &de, buf->d_name);
        errno = errnosave;
        if(res < 0) 
            errno = -res, res = -1;
        else if(res > 0) {
            avfs_direntry_to_dirent(buf, &de);
            res = AVFS_DIR_RECLEN;
        }
    }

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static off_t virt_lseek ( int  fd,
off_t  offset,
int  whence,
int  undersc 
) [static]

Definition at line 250 of file file.c.

{
    off_t res;

    if(!FD_OK(fd) || !ISVIRTUAL(fd))
        res = real_lseek(fd, offset, whence, undersc);
    else {
        int errnosave = errno;

        res = cmd_lseek(SERVERFH(fd), offset, whence);
        if(res < 0)
            errno = -res, res = -1;
        else
            errno = errnosave;
    }

    return res;
}

Here is the call graph for this function:

static ssize_t virt_read ( int  fd,
void *  buf,
size_t  nbyte,
int  undersc 
) [static]

Definition at line 269 of file file.c.

{
    ssize_t res;

    if(!FD_OK(fd) || !ISVIRTUAL(fd))
        res = real_read(fd, buf, nbyte, undersc);
    else {
        int errnosave = errno;

        res = cmd_read(SERVERFH(fd), buf, nbyte);
        if(res < 0)
            errno = -res, res = -1;
        else
            errno = errnosave;
    }

    return res;
}

Here is the call graph for this function:

static ssize_t virt_write ( int  fd,
const void *  buf,
size_t  nbyte,
int  undersc 
) [static]

Definition at line 288 of file file.c.

{
    ssize_t res;

    if(!FD_OK(fd) || !ISVIRTUAL(fd))
        res = real_write(fd, buf, nbyte, undersc);
    else {
        int errnosave = errno;

        res = cmd_write(SERVERFH(fd), buf, nbyte);
        if(res < 0)
            errno = -res, res = -1;
        else
            errno = errnosave;
    }

    return res;
}

Here is the call graph for this function:

ssize_t write ( int  fd,
const void *  buf,
size_t  nbyte 
)

Definition at line 450 of file file.c.

{
    return virt_write(fd, buf, nbyte, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function: