Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

MfsPriv.h

00001 //
00002 // This should not be used by anything other than the MFS library
00003 //
00004 #ifndef _MFS_PRIV_H_
00005 #define _MFS_PRIV_H_
00006 
00007 #define MFS_SUPER_BLOCK         'bsFM'  // MFsb
00008 #define MFS_INDEX_NODE          'niFM'  // MFin
00009 #define MFS_BITMAP_BLOCK        'bbFM'  // MFbb
00010 #define MFS_PTR_NODE            'npFM'  // MFpn
00011 #define MFS_META_NODE           'nmFM'  // MFmn
00012 
00013 #define MfsSystemId             " MFS v1.0"
00014 
00015 class MTreeNode;
00016 typedef bool (*NodeWalker)(MTreeNode *Node, int Data);
00017 
00018 // A block address type: limits the file system to 4096 GB
00019 // Which seems reasonable considering this was originally
00020 // written as a backend for an email client ;)
00021 typedef uint32 BlockAddr;
00022 
00023 // A block run is a set of contiguous blocks
00024 class BlockRun
00025 {
00026 public:
00027     BlockAddr   Start;
00028     uint32      Length;
00029 };
00030 
00031 // The core file system object.
00032 class MFileSystemPrivate
00033 {
00034 public:
00035     // The global file object and it's lock.
00036     GFile File;
00037     GSemaphore FileLock;
00038     bool ReadOnly;
00039 
00040     // The various trees of BTree nodes
00041     MTreeNode *Uid;
00042     GArray<MTreeNode*> Indexes;
00043 
00044     // Blocks
00045     int BlockSize;
00046     int BlockShift;
00047     MTreeNode *BlockBmp;
00048     GArray<MTreeNode*> Dirty;
00049 
00050     bool AllocateBlocks(GArray<uint32> &Blocks, int Num = 1);
00051     
00052     // File access (these take a int64 Pos and return the new File 
00053     // pointer though the same variable).
00054     int ReadAt(int64 &Pos, void *Buf, int Len, int Flags = 0);
00055     int WriteAt(int64 &Pos, void *Buf, int Len, int Flags = 0);
00056 
00057     // Object
00058     MFileSystemPrivate();
00059     ~MFileSystemPrivate();
00060 };
00061 
00062 class Inode
00063 {
00064 public:
00065     uint32 Uid;         // The UID for the inode.
00066     MTreeNode *Md;      // The current meta data node.
00067     int MdOffset;       // The offset into the meta data node where
00068                         // this inode starts. (In bytes).
00069 };
00070 
00071 class MFileQueryPrivate
00072 {
00073 public:
00074     char *Query;
00075 };
00076 
00077 class MFilePrivate
00078 {
00079 public:
00080     MFileSystem *Sys;   // Filesystem.
00081     char *Path;         // Full path of the file.
00082     uint32 Uid;         // Uid of the Inode
00083     
00084     MFilePrivate();
00085     ~MFilePrivate();
00086 };
00087 
00088 class MTreeNode
00089 {
00090 public:
00091     MFileSystem *Sys;   // The filesystem
00092     MTreeNode *Left;    // The left node in the binary tree
00093     MTreeNode *Right;   // The right node in the binary tree
00094     MTreeNode *Parent;  // The parent node
00095     uint32 Block;       // The current address of the data block on disk.
00096                         // If the disk is an array of blocks, each 'BlockSize'
00097                         // bytes long then this is the array index used to
00098                         // access the data.
00099     char *Data;         // The data block (always BlockSize bytes long)
00100     bool Dirty;         // True if the data block is dirty
00101     int Depth;          // Depth of the node in the tree
00102     
00103     uint32 GetMagic()
00104     {
00105         return (Data) ? *((uint32*)Data) : 0;
00106     }
00107 
00108     // Object
00109     MTreeNode(MFileSystem *sys, uint32 block);
00110     ~MTreeNode();
00111 
00112     // Methods
00113     void SetDirty();
00114     bool SetClean();
00115     bool Load(uint32 Block = 0);
00116     bool Save();
00117     bool Walk(NodeWalker Callback, int Data = 0);
00118     bool OnChildMoved(MTreeNode *Child, uint32 NewPos);
00119 };
00120 
00121 class MSuperNode
00122 {
00123 public:
00124     uint32 Magic;           // MFS_SUPER_BLOCK
00125     char Id[32];            // Always set to MfsSystemId
00126     uint32 BlockSize;       // >= 1k AND <= 8k
00127     BlockAddr Root;
00128     BlockAddr Index;
00129     BlockRun Bmp;
00130     
00131     uint8 Reserved[972];    // Unused
00132 };
00133 
00134 class MString
00135 {
00136 public:
00137     uint8 Len;
00138     char Str[1];
00139     
00140     MString *Next()
00141     {
00142         return (MString*) (Str + Len);
00143     }
00144 };
00145 
00146 class MKey
00147 {
00148 public:
00149     uint8 Type;             // GVariant's type: GV_???
00150     union
00151     {
00152         uint32 Int;         // GV_INT32
00153         MString Str;        // GV_STRING
00154     };
00155 
00156     MKey *Next()
00157     {
00158         switch (Type)
00159         {
00160             case GV_INT32:
00161             {
00162                 return (MKey*) (((char*)this) + sizeof(Int));
00163             }
00164             case GV_STRING:
00165             {
00166                 return (MKey*) Str.Next();
00167             }
00168         }
00169         
00170         LgiAssert(0);
00171         return 0;
00172     }
00173 };
00174 
00175 class MValue
00176 {
00177 public:
00178     uint16 MetaName;        // Key into meta data name hash table
00179     MKey Value;             // Type and value
00180 
00181     MValue *Next()
00182     {
00183         return (MValue*) Value.Next();
00184     }
00185 };
00186 
00187 #define MINODE_RUN_SIZE         (8<<10) // 8kb
00188 
00189 class MInode
00190 {
00191 public:
00192     // Basic information (36 bytes)
00193     BlockAddr   Inode;          // The address on disk
00194     uint32      Mode;           // protection
00195     uint16      UserId;         // user ID of owner
00196     uint16      GrpId;          // group ID of owner
00197     uint64      Size;           // total size, in bytes
00198     uint64      ModTime;        // time of last modification
00199     uint64      CreateTime;     // time of creation
00200 
00201     // Meta stuff (8 bytes)
00202     BlockRun    Attributes;     // Points to the blocks that store attributes
00203 
00204     // The file's data itself
00205     BlockAddr   Direct[16];     // First 16 blocks directly address (64 bytes)
00206     BlockRun    Runs[64];       // Some runs of MINODE_RUN_SIZE bytes (512 bytes)
00207     BlockAddr   Indirect[64];   // Indirect blocks storing runs pointing to MINODE_RUN_SIZE bytes each (256 bytes)
00208 };
00209 
00210 #endif

Generated on Wed Oct 26 14:46:51 2005 for Lgi by  doxygen 1.4.1