chiche.h

Go to the documentation of this file.
00001 /*
00002 ** chiche.h for  in /root/research/lseosr2a/programs/chiche
00003 **
00004 ** Made Copyright (c)2004 Julien Quintard
00005 ** Login   <quinta_j@epita.fr>
00006 **
00007 ** Started on  Tue Mar 30 13:19:22 2004 Julien Quintard
00008 ** Last update Tue Nov 16 14:07:44 2004 Vianney Rancurel
00009 */
00010 #ifndef CHICHE_H
00011 #define CHICHE_H        1
00012 #include <libc.h>
00013 #include <libide.h>
00014 #include <libpart.h>
00015 #include <libtimer.h>
00016 
00017 #define BLKSZ                   512
00018 
00019 /*
00020  * state entries
00021  */
00022 
00023 #define CHICHE_UNUSED_ENTRIES   2
00024 
00025 #define CHICHE_UNUSED           0x00    /* unused entry */
00026 #define CHICHE_EOL              0x01    /* end of list */
00027 
00028 /*
00029  * defines
00030  */
00031 
00032 #define CHICHE_VERSION          1
00033 #define CHICHE_START            2
00034 #define CHICHE_BLKSZ            512
00035 #define CHICHE_BPC              1       /* blocks per cluster */
00036 #define CHICHE_CLUSTERSZ        (CHICHE_BPC * CHICHE_BLKSZ)
00037 #define CHICHE_ENTRYSZ          sizeof(u_int32_t)
00038 #define CHICHE_MAGIC            0xb00ba
00039 #define CHICHE_RESERVED         0x10    /* always up to 1 */
00040 #define CHICHE_CCACHESZ         8
00041 #define CHICHE_MNGBLKS          2       /* unused blk + super blk */
00042 #define CHICHE_SUPERBLK         1       /* superblock block location */
00043 #define CHICHE_FAT              2       /* fat block location */
00044 #define CHICHE_RDENT            0       /* root direntry located
00045                                            in first data cluster */
00046 #define CHICHE_NAMESZ           31
00047 #define CHICHE_DOTDOT           ".."
00048 #define CHICHE_DOT              "."
00049 
00050 #define CHICHE_ACCESS_MODE      0777
00051 
00052 #define CHICHE_NOFLAG           0x0
00053 #define CHICHE_FOLLOW_LINK      0x1
00054 #define CHICHE_ACCESS           0x2
00055 
00056 /*
00057  * chiche_write() flags
00058  */
00059 
00060 #define CHICHE_RESTORE          1
00061 
00062 /*
00063  * chiche_new_direntry() flags
00064  */
00065 
00066 #define CHICHE_NOFLAGS          0x0
00067 #define CHICHE_ALLOC_CLUSTER    0x1
00068 
00069 /*
00070  * generic defines
00071  */
00072 
00073 #define CHICHE_SYSCALLS         (1 << 0)
00074 #define CHICHE_MISC             (1 << 1)
00075 #define CHICHE_USH              (1 << 2)
00076 #define CHICHE_RELEASE          (1 << 3)
00077 #define CHICHE_STEP             (1 << 4)
00078 #define CHICHE_DEBUG            (CHICHE_RELEASE)
00079 
00080 #define CHICHE_FDTABSZ          1024
00081 #define CHICHE_PSC              "/"     /* path separator character */
00082 
00083 /*
00084  * chiche_poll_directory() return codes
00085  */
00086 
00087 #define CHICHE_POLL_UNUSED      0x00
00088 #define CHICHE_POLL_EOL         0x01
00089 #define CHICHE_POLL_VALID       0x02
00090 #define CHICHE_POLL_ERROR       0x03
00091 
00092 /*
00093  * file system type
00094  */
00095 
00096 #define CHICHE_FSTYPE           0xcd
00097 
00098 /*
00099  * typedef
00100  */
00101 
00102 typedef char **         t_path;
00103 
00104 /*
00105  * link
00106  */
00107 
00108 typedef struct          s_chiche_link
00109 {
00110   u_int32_t             cluster;
00111   u_int32_t             no;
00112 }                       t_chiche_link;
00113 
00114 /*
00115  * direntry
00116  */
00117 
00118 typedef struct          s_chiche_direntry
00119 {
00120 
00121   char                  name[CHICHE_NAMESZ + 1];
00122 
00123 #define CHICHE_ATTR_FILE        0x00000001
00124 #define CHICHE_ATTR_DIR         0x00000002
00125 #define CHICHE_ATTR_LINK        0x00000004
00126 
00127 #define CHICHE_ATTR_ROOT        0x00000010
00128 
00129 #define CHICHE_ATTR_SUID        0x00000020
00130 #define CHICHE_ATTR_SGID        0x00000040
00131 #define CHICHE_ATTR_STICKY      0x00000080
00132 
00133 #define CHICHE_ATTR_UW          0x00000100
00134 #define CHICHE_ATTR_UR          0x00000200
00135 #define CHICHE_ATTR_UX          0x00000400
00136 #define CHICHE_ATTR_GW          0x00000800
00137 #define CHICHE_ATTR_GR          0x00001000
00138 #define CHICHE_ATTR_GX          0x00002000
00139 #define CHICHE_ATTR_OW          0x00004000
00140 #define CHICHE_ATTR_OR          0x00008000
00141 #define CHICHE_ATTR_OX          0x00001000
00142 
00143 #define CHICHE_ROOT_ATTRIBUTES  (CHICHE_ATTR_DIR | CHICHE_ATTR_ROOT |   \
00144                                  CHICHE_ATTR_UW | CHICHE_ATTR_UR |      \
00145                                  CHICHE_ATTR_UX | CHICHE_ATTR_GR |      \
00146                                  CHICHE_ATTR_GX | CHICHE_ATTR_OX)
00147 
00148   u_int32_t             attr;
00149   u_int32_t             uid;
00150   u_int32_t             gid;
00151   u_int32_t             ctime;
00152   u_int32_t             atime;
00153   u_int32_t             mtime;
00154   u_int32_t             data;
00155   u_int32_t             datasz;
00156   u_int16_t             nclusters;
00157 }                       t_chiche_direntry;
00158 
00159 /*
00160  * superblock
00161  */
00162 
00163 typedef struct          s_chiche_super
00164 {
00165   u_int16_t             version;
00166   u_int16_t             clustersz;
00167   u_int32_t             magic;
00168   u_int32_t             fat;
00169   u_int32_t             fatsz;
00170   u_int32_t             data;
00171   u_int32_t             datasz;
00172   u_int32_t             reserved;
00173   u_int32_t             reservedsz;
00174   u_int32_t             rdent;
00175   u_int32_t             root;
00176 }                       t_chiche_super;
00177 
00178 /*
00179  * cluster cache entry
00180  */
00181 
00182 typedef struct          s_chiche_cce
00183 {
00184   u_int32_t             addr;
00185   char                  *data;
00186 }                       t_chiche_cce;
00187 
00188 /*
00189  * useful structure for updating directories
00190  */
00191 
00192 typedef struct          s_chiche_dirupdate
00193 {
00194   u_int32_t             cluster;
00195   u_int32_t             no;
00196 }                       t_chiche_dirupdate;
00197 
00198 /*
00199  * chiche core structure
00200  */
00201 
00202 typedef struct          s_chiche
00203 {
00204 
00205   /*
00206    * superblock image
00207    */
00208 
00209   t_chiche_super        super;
00210 
00211   /*
00212    * cache
00213    */
00214 
00215   t_chiche_cce          cache[CHICHE_CCACHESZ];
00216   u_int32_t             index;
00217 
00218   /*
00219    * owner of the mounted partition
00220    */
00221 
00222   u_int32_t             uid;
00223   u_int32_t             gid;
00224 
00225   /*
00226    * device
00227    */
00228 
00229   u_int32_t             dev;
00230 
00231   /*
00232    * part
00233    */
00234 
00235   u_int32_t             pdev;
00236   u_int32_t             id;
00237   u_int32_t             unit;
00238 
00239   u_int32_t             start;
00240   u_int32_t             size;
00241 
00242 }                       t_chiche;
00243 
00244 typedef struct          s_chiche_fde
00245 {
00246   u_int8_t              state;
00247   u_int32_t             ino;
00248   u_int32_t             cluster;
00249   u_int32_t             no;
00250   u_int32_t             data;
00251 
00252   u_int32_t             block;
00253   off_t                 offset;
00254 }                       t_chiche_fde;
00255 
00256 typedef struct          s_chiche_common
00257 {
00258   __cpu_simple_lock_t   lock;
00259 }                       t_chiche_common;
00260 
00261 /* PROTO chiche.c */
00262 /* chiche.c */
00263 int chiche_init_srv(void);
00264 void chiche_waitfor_service(int gate);
00265 int main(int argc, char **argv);
00266 int chiche_cache_read(t_chiche *chiche, u_int32_t dev, u_int32_t addr, void *buffer, u_int32_t nblocks);
00267 void chiche_cache_write(t_chiche *chiche, u_int32_t addr, void *buffer, u_int32_t nblocks);
00268 int chiche_read(t_chiche *chiche, u_int32_t dev, u_int32_t block, u_int32_t off, void *data, u_int32_t bytes);
00269 int chiche_write(t_chiche *chiche, u_int32_t dev, u_int32_t block, u_int32_t off, void *data, u_int32_t bytes, int restore);
00270 int chiche_write_super(t_chiche *chiche);
00271 int chiche_read_super(t_chiche *chiche);
00272 u_int32_t chiche_nxt_cluster(t_chiche *chiche, u_int32_t cluster);
00273 int chiche_poll_directory(t_chiche *chiche, t_chiche_direntry *direntry, u_int32_t *root, int *no);
00274 int chiche_mkfs(t_chiche *chiche);
00275 void chiche_dump_superblock(t_chiche_super *super);
00276 u_int32_t chiche_pathsz(t_path path);
00277 t_path chiche_reserve_path(t_chiche *chiche, char *upath, char *psc);
00278 void chiche_release_path(t_chiche *chiche, t_path path);
00279 void chiche_dump_path(t_chiche *chiche, t_path path);
00280 void chiche_dump_cce(t_chiche *chiche, t_chiche_cce *cce);
00281 int chiche_mount(t_chiche *chiche);
00282 u_int32_t chiche_find_free_cluster(t_chiche *chiche);
00283 int chiche_set_fat_entry(t_chiche *chiche, u_int32_t cluster, u_int32_t set);
00284 void chiche_dump_direntry(t_chiche *chiche, t_chiche_direntry *direntry);
00285 int chiche_fill_root_direntry(t_chiche *chiche, t_chiche_direntry *direntry);
00286 int chiche_dir_from_path(t_chiche *chiche, t_path path, t_chiche_direntry *dir, t_chiche_dirupdate *du);
00287 void chiche_set_mode(t_chiche *chiche, u_int32_t *attr, mode_t mode, u_int32_t more);
00288 u_int32_t chiche_dirsz(t_chiche *chiche, int fd);
00289 int chiche_new_direntry(t_chiche *chiche, t_path path, mode_t mode, u_int32_t attr, int flags);
00290 int chiche_mkfile(t_chiche *chiche, char *upath, mode_t mode, int flags);
00291 int chiche_mkdir(t_chiche *chiche, char *upath, mode_t mode);
00292 int chiche_mksymlink(t_chiche *chiche, char *upath, mode_t mode);
00293 int chiche_is_fde_valid(t_chiche *chiche, int fd);
00294 void chiche_fill_fde(t_chiche *chiche, t_chiche_direntry *direntry, u_int32_t root, u_int32_t no, int fd);
00295 int chiche_open(t_chiche *chiche, int fd, char *upath, int flags, int chflags);
00296 int chiche_reserve_fde(t_chiche *chiche);
00297 void chiche_release_fde(t_chiche *chiche, int fd);
00298 int chiche_fstat(t_chiche *chiche, int fd, struct stat *stat);
00299 int chiche_getdents(t_chiche *chiche, int fd, void *data, u_int32_t *nbytes);
00300 int chiche_fchmod(t_chiche *chiche, int fd, mode_t mode);
00301 int chiche_resize_dir(t_chiche *chiche, t_chiche_direntry *dir);
00302 int chiche_clean_direntry(t_chiche *chiche, t_chiche_direntry *direntry);
00303 int chiche_rename(t_chiche *chiche, char *uoldpath, int fd, char *unewpath);
00304 int chiche_unlink(t_chiche *chiche, char *upath, int fd);
00305 int chiche_rmdir(t_chiche *chiche, char *upath, int fd);
00306 int chiche_exists(t_chiche *chiche, char *upath);
00307 int chiche_append(t_chiche *chiche, int fd);
00308 void sys_chiche_rename(t_tcb *caller_tcb);
00309 void sys_chiche_fchmod(t_tcb *caller_tcb);
00310 void sys_chiche_chmod(t_tcb *caller_tcb);
00311 void sys_chiche_getdents(t_tcb *caller_tcb);
00312 void sys_chiche_stat(t_tcb *caller_tcb);
00313 void sys_chiche_fstat(t_tcb *caller_tcb);
00314 void sys_chiche_close(t_tcb *caller_tcb);
00315 void sys_chiche_open(t_tcb *caller_tcb);
00316 void sys_chiche_unlink(t_tcb *caller_tcb);
00317 void sys_chiche_rmdir(t_tcb *caller_tcb);
00318 void sys_chiche_mkdir(t_tcb *caller_tcb);
00319 void sys_chiche_umount(t_tcb *caller_tcb);
00320 void sys_chiche_mount(t_tcb *caller_tcb);
00321 void sys_chiche_mkfs(t_tcb *caller_tcb);
00322 void sys_chiche_init(t_tcb *caller_tcb);
00323 void do_sys_chiche(void);
00324 void sys_chiche(void);
00325 #endif

Generated on Wed May 24 23:04:18 2006 for LSE/OS by  doxygen 1.4.6