Back to index

avfs  1.0.1
default.c
Go to the documentation of this file.
00001 /*
00002     AVFS: A Virtual File System Library
00003     Copyright (C) 2000  Miklos Szeredi <miklos@szeredi.hu>
00004 
00005     This program can be distributed under the terms of the GNU GPL.
00006     See the file COPYING.
00007 */
00008 
00009 #include "internal.h"
00010 
00011 static void default_destroy(struct avfs *avfs)
00012 {
00013 }
00014 
00015 static int default_lookup(ventry *ve, const char *name, void **newp)
00016 {
00017     char *path = (char *) ve->data;
00018     
00019     if(path == NULL)
00020        path = av_strdup(name);
00021     else if(name == NULL || strcmp(name, "..") == 0) {
00022        char *s;
00023        s = strrchr(path, AV_DIR_SEP_CHAR);
00024        if(s == NULL) {
00025            av_free(path);
00026            path = NULL;
00027        }
00028        else 
00029            *s = '\0';
00030     }
00031     else if(strcmp(name, ".") != 0)
00032        path = av_stradd(path, AV_DIR_SEP_STR, name, NULL);
00033     
00034     *newp = path;
00035 
00036     return 0;
00037 }
00038 
00039 static void default_putent(ventry *ve)
00040 {
00041     char *path = (char *) ve->data;
00042 
00043     av_free(path);
00044 }
00045 
00046 static int default_copyent(ventry *ve, void **resp)
00047 {
00048     char *path = (char *) ve->data;
00049     
00050     *resp =  (void *) av_strdup(path);
00051     
00052     return 0;
00053 }
00054 
00055 static int default_getpath(ventry *ve, char **resp)
00056 {
00057     char *path = (char *) ve->data;
00058     
00059     *resp =  av_strdup(path);
00060 
00061     return 0;
00062 }
00063 
00064 static int default_access(ventry *ve, int amode)
00065 {
00066     return -EINVAL;
00067 }
00068 
00069 static int default_readlink(ventry *ve, char **bufp)
00070 {
00071     return -EINVAL;
00072 }
00073 
00074 static int default_symlink(const char *path, ventry *newve)
00075 {
00076     return -ENOSYS;
00077 }
00078 
00079 static int default_unlink(ventry *ve)
00080 {
00081     return -ENOSYS;
00082 }
00083 
00084 static int default_rmdir(ventry *ve)
00085 {
00086     return -ENOSYS;
00087 }
00088 
00089 static int default_mknod(ventry *ve, avmode_t mode, avdev_t dev)
00090 {
00091     return -ENOSYS;
00092 }
00093 
00094 static int default_mkdir(ventry *ve, avmode_t mode)
00095 {
00096     return -ENOSYS;
00097 }
00098 
00099 static int default_rename(ventry *ve, ventry *newve)
00100 {
00101     return -ENOSYS;
00102 }
00103 
00104 static int default_link(ventry *ve, ventry *newve)
00105 {
00106     return -ENOSYS;
00107 }
00108 
00109 static int default_open(ventry *ve, int flags, avmode_t mode, void **resp)
00110 {
00111     return -ENOSYS;
00112 }
00113 
00114 static int default_close(vfile *vf)
00115 {
00116     return 0;
00117 }
00118 
00119 static avssize_t default_read(vfile *vf, char *buf, avsize_t nbyte)
00120 {
00121     return -ENOSYS;
00122 }
00123 
00124 static avssize_t default_write(vfile *vf, const char *buf,
00125                             avsize_t nbyte)
00126 {
00127     return -ENOSYS;
00128 }
00129 
00130 static int default_readdir(vfile *vf, struct avdirent *buf)
00131 {
00132     return -ENOSYS;
00133 }
00134 
00135 static int default_getattr(vfile *vf, struct avstat *buf, int attrmask)
00136 {
00137     return -ENOSYS;
00138 }
00139 
00140 static int default_setattr(vfile *vf, struct avstat *buf, int attrmask)
00141 {
00142     return -ENOSYS;
00143 }
00144 
00145 static int default_truncate(vfile *vf, avoff_t length)
00146 {
00147     return -ENOSYS;
00148 }
00149 
00150 static avoff_t get_size(vfile *vf)
00151 {
00152     int res;
00153     struct avfs *avfs = vf->mnt->avfs;
00154     struct avstat stbuf;
00155 
00156     res = avfs->getattr(vf, &stbuf, AVA_SIZE);
00157     if(res < 0)
00158        return res;
00159 
00160     return stbuf.size;
00161 }
00162 
00163 static avoff_t default_lseek(vfile *vf, avoff_t offset, int whence)
00164 {
00165     avoff_t res;
00166 
00167     switch(whence) {
00168     case AVSEEK_SET:
00169        res = offset;
00170        break;
00171        
00172     case AVSEEK_CUR:
00173        res = vf->ptr + offset;
00174        break;
00175        
00176     case AVSEEK_END:
00177        res = get_size(vf);
00178        if(res < 0)
00179            return res;
00180 
00181        res = res + offset;
00182        break;
00183        
00184     default:
00185         return -EINVAL;
00186     }
00187 
00188     if(res < 0)
00189         return -EINVAL;
00190 
00191     vf->ptr = res;
00192 
00193     return res;
00194 }
00195 
00196 void av_default_avfs(struct avfs *avfs)
00197 {
00198     avfs->destroy    = default_destroy;
00199 
00200     avfs->lookup     = default_lookup;
00201     avfs->putent     = default_putent;
00202     avfs->copyent    = default_copyent;
00203     avfs->getpath    = default_getpath;
00204 
00205     avfs->access     = default_access;
00206     avfs->readlink   = default_readlink;
00207     avfs->symlink    = default_symlink;
00208     avfs->unlink     = default_unlink;
00209     avfs->rmdir      = default_rmdir;
00210     avfs->mknod      = default_mknod;
00211     avfs->mkdir      = default_mkdir;
00212     avfs->rename     = default_rename;
00213     avfs->link       = default_link;
00214 
00215     avfs->open       = default_open;
00216     avfs->close      = default_close;
00217     avfs->read       = default_read;
00218     avfs->write      = default_write;
00219     avfs->readdir    = default_readdir;
00220     avfs->getattr    = default_getattr;
00221     avfs->setattr    = default_setattr;
00222     avfs->truncate   = default_truncate;
00223     avfs->lseek      = default_lseek;
00224 }
00225