# ubixfs.h

Go to the documentation of this file.

    00001 #ifndef UBIXFS_H
    00002 #define UBIXFS_H
    00003
    00004 #include <sys/types.h>
    00005 #include <unistd.h>
    00006 #include "fsAbstract.h"
    00007 #include "types.h"
    00008 #include "file.h"
    00009
    00010 #define INODE_IN_USE      0x00000001
    00011 #define INODE_DIRECTORY   0x00000002
    00012 #define ATTR_INODE        0x00000004
    00013 #define INODE_LOGGED      0x00000008
    00014 #define INODE_DELETED     0x00000010
    00015 #define PERMANENT_FLAGS   0x0000ffff
    00016 #define INODE_NO_CACHE    0x00010000
    00017 #define INODE_WAS_WRITTEN 0x00020000
    00018 #define NO_TRANSACTION    0x00040000
    00019
    00020 #define NUM_DIRECT_BLOCKS 64
    00021 #define MAX_FILENAME_LENGTH 256
    00022
    00023 #define UBIXFS_MAGIC1 0xA0A0A0A
    00024 #define UBIXFS_MAGIC2 0xB0B0B0B
    00025 #define UBIXFS_MAGIC3 0xC0C0C0C
    00026 #define UBIXFS_INODE_MAGIC 0x3bbe0ad9
    00027
    00028 /* befs magic numbers
    00029 #define SUPER_BLOCK_MAGIC1 0x42465331 // BFS1
    00030 #define SUPER_BLOCK_MAGIC2 0xdd121031
    00031 #define SUPER_BLOCK_MAGIC3 0x15b6830e
    00032  */
    00033 #define UBIXFS_CLEAN 0x434C454E  // CLEN
    00034 #define UBIXFS_DIRTY 0x44495254  // DIRT
    00035
    00036
    00037 typedef struct blockRun {
    00038   int            AG               __attribute__ ((packed));
    00039   unsigned short start            __attribute__ ((packed));
    00040   unsigned short len              __attribute__ ((packed));
    00041 } inodeAddr;
    00042
    00043 struct bNode;
    00044 struct ubixfsInode;
    00045 class bTree;
    00046
    00047 typedef union uPtr {
    00048   inodeAddr iAddr;
    00049   bNode * bPtr;
    00050   bTree * btPtr;
    00051   ubixfsInode * iPtr;
    00052   void * vPtr;
    00053   off_t offset;
    00054 };
    00055
    00056 typedef struct diskSuperBlock {
    00057   char      name[32]      __attribute__ ((packed));
    00058   int32     magic1        __attribute__ ((packed));
    00059   int32     fsByteOrder   __attribute__ ((packed));
    00060
    00061 // blockSize on disk (4096 for UbixFS v2)
    00062   int32     blockSize     __attribute__ ((packed));
    00063
    00064 // number of bits needed to shift a block number to get a byte address
    00065   uInt32     blockShift    __attribute__ ((packed));
    00066
    00067   off_t     numBlocks     __attribute__ ((packed));
    00068   off_t     usedBlocks    __attribute__ ((packed));
    00069
    00070 // BlockAllocationTable
    00071   uInt32    batSectors    __attribute__ ((packed));
    00072
    00073   uInt32    inodeCount    __attribute__ ((packed));
    00074   uInt32    inodeSize     __attribute__ ((packed));
    00075   uInt32    magic2        __attribute__ ((packed));
    00076   uInt32    blocksPerAG   __attribute__ ((packed));
    00077   uInt32    AGShift       __attribute__ ((packed));
    00078   uInt32    numAGs        __attribute__ ((packed));
    00079   uInt32    lastUsedAG    __attribute__ ((packed));
    00080 // flags tells whether the FS is clean (0x434C454E) or dirty (0x44495954)
    00081   int32     flags         __attribute__ ((packed));
    00082
    00083 // journal information
    00084   blockRun  logBlocks     __attribute__ ((packed));
    00085   off_t     logStart      __attribute__ ((packed));
    00086   off_t     logEnd        __attribute__ ((packed));
    00087
    00088   int32     magic3        __attribute__ ((packed));
    00089
    00090 // root dir of the SYS container
    00091   inodeAddr rootDir       __attribute__ ((packed));
    00092
    00093 // indicies
    00094   inodeAddr indicies      __attribute__ ((packed));
    00095
    00096   char      pad[368]      __attribute__ ((packed));
    00097
    00098 } diskSuperBlock;
    00099
    00100 typedef struct dataStream {
    00101   struct blockRun direct[NUM_DIRECT_BLOCKS] __attribute__ ((packed));
    00102   off_t           maxDirectRange            __attribute__ ((packed));
    00103   struct blockRun indirect                  __attribute__ ((packed));
    00104   off_t           maxIndirectRange          __attribute__ ((packed));
    00105   struct blockRun double_indirect           __attribute__ ((packed));
    00106   off_t           maxDoubleIndirectRange    __attribute__ ((packed));
    00107   off_t           size                      __attribute__ ((packed));
    00108 } dataStream;
    00109
    00110 typedef struct ubixfsInode {
    00111   int32       magic1                     __attribute__ ((packed));
    00112   inodeAddr   inodeNum                   __attribute__ ((packed));
    00113   char        name[MAX_FILENAME_LENGTH]  __attribute__ ((packed));
    00114   uid_t       uid                        __attribute__ ((packed));
    00115   gid_t       gid                        __attribute__ ((packed));
    00116   int32       mode                       __attribute__ ((packed));
    00117   int32       flags                      __attribute__ ((packed));
    00118  // uInt64      createTime                 __attribute__ ((packed));
    00119  // uInt64      lastModifiedTime           __attribute__ (packed));
    00120   inodeAddr   attributes                 __attribute__ ((packed));
    00121   uInt32      type                       __attribute__ ((packed));
    00122   uInt32      inodeSize                  __attribute__ ((packed));
    00123   uPtr        parent                     __attribute__ ((packed));
    00124   uPtr        next                       __attribute__ ((packed));
    00125   uPtr        prev                       __attribute__ ((packed));
    00126   uPtr        data                       __attribute__ ((packed));
    00127   dataStream  blocks                     __attribute__ ((packed));
    00128   uInt32      refCount                   __attribute__ ((packed));
    00129   char        smallData[3200]            __attribute__ ((packed));
    00130 } ubixfsInode;
    00131
    00132 class UbixFS : public vfs_abstract {
    00133  protected:
    00134   signed char *    freeBlockList;
    00135   diskSuperBlock * superBlock;
    00136   fileDescriptor * root;
    00137
    00138   blockRun         getFreeBlock(blockRun);
    00139   blockRun         getFreeBlock(uInt32);
    00140   blockRun         getFreeBlock(void);
    00141   blockRun         get8FreeBlocks(uInt32);
    00142   uInt32           getNextAG(void);
    00143   void *           mknod(const char *, ubixfsInode *, mode_t);
    00144   void             printSuperBlock(void);
    00145   void             printFreeBlockList(uInt32);
    00146   void             setFreeBlock(blockRun);
    00147  public:
    00148                    UbixFS(void);
    00149                    UbixFS(device_t *);
    00150   virtual int      vfs_init(void);
    00151   virtual int      vfs_format(device_t *);
    00152   virtual void *   vfs_mknod(const char *, mode_t);
    00153   virtual int      vfs_mkdir(const char *, mode_t);
    00154   virtual int      vfs_open(const char *, fileDescriptor *, int, ...);
    00155   virtual size_t   vfs_read(fileDescriptor *, void *, off_t, size_t);
    00156   virtual size_t   vfs_write(fileDescriptor *, void *, off_t, size_t);
    00157   virtual int      vfs_sync(void);
    00158   virtual int      vfs_stop(void);
    00159   virtual         ~UbixFS(void);
    00160   friend class bTree;
    00161 }; // UbixFS
    00162
    00163 #endif // !UBIXFS_H