00001
00002
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
00019
00020
00021 typedef uint32 BlockAddr;
00022
00023
00024 class BlockRun
00025 {
00026 public:
00027 BlockAddr Start;
00028 uint32 Length;
00029 };
00030
00031
00032 class MFileSystemPrivate
00033 {
00034 public:
00035
00036 GFile File;
00037 GSemaphore FileLock;
00038 bool ReadOnly;
00039
00040
00041 MTreeNode *Uid;
00042 GArray<MTreeNode*> Indexes;
00043
00044
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
00053
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
00058 MFileSystemPrivate();
00059 ~MFileSystemPrivate();
00060 };
00061
00062 class Inode
00063 {
00064 public:
00065 uint32 Uid;
00066 MTreeNode *Md;
00067 int MdOffset;
00068
00069 };
00070
00071 class MFileQueryPrivate
00072 {
00073 public:
00074 char *Query;
00075 };
00076
00077 class MFilePrivate
00078 {
00079 public:
00080 MFileSystem *Sys;
00081 char *Path;
00082 uint32 Uid;
00083
00084 MFilePrivate();
00085 ~MFilePrivate();
00086 };
00087
00088 class MTreeNode
00089 {
00090 public:
00091 MFileSystem *Sys;
00092 MTreeNode *Left;
00093 MTreeNode *Right;
00094 MTreeNode *Parent;
00095 uint32 Block;
00096
00097
00098
00099 char *Data;
00100 bool Dirty;
00101 int Depth;
00102
00103 uint32 GetMagic()
00104 {
00105 return (Data) ? *((uint32*)Data) : 0;
00106 }
00107
00108
00109 MTreeNode(MFileSystem *sys, uint32 block);
00110 ~MTreeNode();
00111
00112
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;
00125 char Id[32];
00126 uint32 BlockSize;
00127 BlockAddr Root;
00128 BlockAddr Index;
00129 BlockRun Bmp;
00130
00131 uint8 Reserved[972];
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;
00150 union
00151 {
00152 uint32 Int;
00153 MString Str;
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;
00179 MKey Value;
00180
00181 MValue *Next()
00182 {
00183 return (MValue*) Value.Next();
00184 }
00185 };
00186
00187 #define MINODE_RUN_SIZE (8<<10)
00188
00189 class MInode
00190 {
00191 public:
00192
00193 BlockAddr Inode;
00194 uint32 Mode;
00195 uint16 UserId;
00196 uint16 GrpId;
00197 uint64 Size;
00198 uint64 ModTime;
00199 uint64 CreateTime;
00200
00201
00202 BlockRun Attributes;
00203
00204
00205 BlockAddr Direct[16];
00206 BlockRun Runs[64];
00207 BlockAddr Indirect[64];
00208 };
00209
00210 #endif