Back to index

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

Go to the source code of this file.

Classes

struct  sfilefuncs

Defines

#define SFILE_NOCACHE   (1 << 0)

Functions

struct sfileav_sfile_new (const struct sfilefuncs *func, void *data, int flags)
avssize_t av_sfile_pread (struct sfile *fil, char *buf, avsize_t nbyte, avoff_t offset)
avssize_t av_sfile_pwrite (struct sfile *fil, const char *buf, avsize_t nbyte, avoff_t offset)
avoff_t av_sfile_size (struct sfile *fil)
int av_sfile_truncate (struct sfile *fil, avoff_t length)
int av_sfile_startget (struct sfile *fil)
int av_sfile_flush (struct sfile *fil)
void * av_sfile_getdata (struct sfile *fil)
avoff_t av_sfile_diskusage (struct sfile *fil)

Define Documentation

#define SFILE_NOCACHE   (1 << 0)

Definition at line 11 of file serialfile.h.


Function Documentation

avoff_t av_sfile_diskusage ( struct sfile fil)

Definition at line 469 of file serialfile.c.

{
    int res;
    struct stat buf;

    if(fil->fd == -1)
        return 0;
    
    res = fstat(fil->fd, &buf);
    if(res == -1) {
        av_log(AVLOG_ERROR, "Error in fstat() for %s: %s", fil->localfile,
               strerror(errno));
        return -EIO;
    }
    
    return buf.st_blocks * 512;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_sfile_flush ( struct sfile fil)

Definition at line 441 of file serialfile.c.

{
    int res;
    void *conndata;

    if(!fil->dirty)
        return 0;
    
    res = fil->func->startput(fil->data, &conndata);
    if(res == 0) {
        res = sfile_writeout(fil, conndata);
        if(res == 0)
            res = fil->func->endput(conndata);
    }
    av_unref_obj(conndata);
    if(res < 0)
        sfile_reset(fil);

    fil->dirty = 0;

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* av_sfile_getdata ( struct sfile fil)

Definition at line 464 of file serialfile.c.

{
    return fil->data;
}

Here is the caller graph for this function:

struct sfile* av_sfile_new ( const struct sfilefuncs func,
void *  data,
int  flags 
) [read]

Definition at line 68 of file serialfile.c.

{
    struct sfile *fil;

    AV_NEW_OBJ(fil, sfile_delete);
    fil->func = func;
    fil->data = data;
    fil->flags = flags;

    sfile_init(fil);

    return fil;
}

Here is the call graph for this function:

Here is the caller graph for this function:

avssize_t av_sfile_pread ( struct sfile fil,
char *  buf,
avsize_t  nbyte,
avoff_t  offset 
)

Definition at line 311 of file serialfile.c.

{
    if(nbyte == 0)
        return 0;
    
    return sfile_pread_force(fil, buf, nbyte, offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

avssize_t av_sfile_pwrite ( struct sfile fil,
const char *  buf,
avsize_t  nbyte,
avoff_t  offset 
)

Definition at line 390 of file serialfile.c.

{
    avssize_t res;
    avoff_t end;

    if(nbyte == 0)
        return 0;

    res = sfile_read_until(fil, AV_MAXOFF, 1);
    if(res < 0)
        return res;
    
    res = sfile_cached_pwrite(fil, buf, nbyte, offset);
    if(res < 0) {
        sfile_reset(fil);
        return res;
    }

    end = offset + nbyte; 
    if(end > fil->numbytes)
        fil->numbytes = end;

    fil->dirty = 1;
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

avoff_t av_sfile_size ( struct sfile fil)

Definition at line 343 of file serialfile.c.

{
    avssize_t res;

    res = sfile_read_until(fil, AV_MAXOFF, 0);
    if(res < 0)
        return res;

    return fil->numbytes;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_sfile_startget ( struct sfile fil)

Definition at line 354 of file serialfile.c.

{
    return sfile_read_until(fil, 0, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_sfile_truncate ( struct sfile fil,
avoff_t  length 
)

Definition at line 359 of file serialfile.c.

{
    int res;

    if(length == 0) {
        if(fil->state == SF_FINI && fil->numbytes == 0)
            return 0;

        sfile_reset_usecache(fil);
        res = sfile_open_localfile(fil);
        if(res < 0)
            return res;

        fil->state = SF_FINI;
        fil->dirty = 1;
        return 0;
    }
    
    res = sfile_read_until(fil, length, 1);
    if(res < 0)
        return res;

    if(fil->numbytes > length) {
        ftruncate(fil->fd, length);
        fil->numbytes = length;
        fil->dirty = 1;
    }
    
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: