aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/myriadfs.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unstable/myriadfs.h368
1 files changed, 184 insertions, 184 deletions
diff --git a/src/unstable/myriadfs.h b/src/unstable/myriadfs.h
index 126be7a..dfb051b 100644
--- a/src/unstable/myriadfs.h
+++ b/src/unstable/myriadfs.h
@@ -14,190 +14,190 @@
14 14
15namespace Bu 15namespace Bu
16{ 16{
17 class Stream; 17 class Stream;
18 18
19 subExceptionDecl( MyriadFsException ); 19 subExceptionDecl( MyriadFsException );
20 20
21 /** 21 /**
22 * A POSIX compliant, node based filesystem built on top of Myriad. 22 * A POSIX compliant, node based filesystem built on top of Myriad.
23 * 23 *
24 * A header is placed into stream 1. 24 * A header is placed into stream 1.
25 * Header format: 25 * Header format:
26 * int32_t iMagicHeader (A7188B39) 26 * int32_t iMagicHeader (A7188B39)
27 * int8_t iVersion (1) 27 * int8_t iVersion (1)
28 * int32_t iNumNodes 28 * int32_t iNumNodes
29 * NodeLookup[iNumNodes] nNode 29 * NodeLookup[iNumNodes] nNode
30 * 30 *
31 * Node lookup: 31 * Node lookup:
32 * int32_t iInode 32 * int32_t iInode
33 * int32_t iPosition 33 * int32_t iPosition
34 * 34 *
35 * The node headers or inode structures have a base size of 44 bytes. 35 * The node headers or inode structures have a base size of 44 bytes.
36 * The name is stored in the directory format. 36 * The name is stored in the directory format.
37 * Basic node header format: 37 * Basic node header format:
38 * int32_t iNode 38 * int32_t iNode
39 * int32_t iUser 39 * int32_t iUser
40 * int32_t iGroup 40 * int32_t iGroup
41 * uint16_t uPerms 41 * uint16_t uPerms
42 * int16_t iLinks 42 * int16_t iLinks
43 * uint32_t uStreamIndex 43 * uint32_t uStreamIndex
44 * int64_t iATime 44 * int64_t iATime
45 * int64_t iMTime 45 * int64_t iMTime
46 * int64_t iCTime 46 * int64_t iCTime
47 * 47 *
48 * Some types get special formats for their assosiated data stream, or 48 * Some types get special formats for their assosiated data stream, or
49 * other special considerations, here's a list: 49 * other special considerations, here's a list:
50 * 50 *
51 * - typeFifo: No stream, uStreamIndex unused (probably) 51 * - typeFifo: No stream, uStreamIndex unused (probably)
52 * - typeChrDev: No stream, uStreamIndex is device hi/lo 52 * - typeChrDev: No stream, uStreamIndex is device hi/lo
53 * - typeDir: The stream contains a directory contents listing, described 53 * - typeDir: The stream contains a directory contents listing, described
54 * below 54 * below
55 * - typeBlkDev: No stream, uStreamIndex is device hi/lo 55 * - typeBlkDev: No stream, uStreamIndex is device hi/lo
56 * - typeRegFile: The stream is the file data 56 * - typeRegFile: The stream is the file data
57 * - typeSymLink: The stream is the destination of the symlink 57 * - typeSymLink: The stream is the destination of the symlink
58 * - typeSocket: No steram, uStreamIndex unused (probably) 58 * - typeSocket: No steram, uStreamIndex unused (probably)
59 * 59 *
60 * Directory streams have this simple listing format. They contain a list 60 * Directory streams have this simple listing format. They contain a list
61 * of all child elements, with no particular order at the moment. The . and 61 * of all child elements, with no particular order at the moment. The . and
62 * .. entries are not listed, they are implicit: 62 * .. entries are not listed, they are implicit:
63 * int32_t iNumNodes 63 * int32_t iNumNodes
64 * NodeTable[iNumNodes] nChildren 64 * NodeTable[iNumNodes] nChildren
65 * 65 *
66 * NodeTable: 66 * NodeTable:
67 * int32_t iInode 67 * int32_t iInode
68 * uint8_t uNameSize 68 * uint8_t uNameSize
69 * char[uNameSize] sName 69 * char[uNameSize] sName
70 */ 70 */
71 class MyriadFs 71 class MyriadFs
72 { 72 {
73 public: 73 public:
74 MyriadFs( Bu::Stream &rStore, int iBlockSize=512 ); 74 MyriadFs( Bu::Stream &rStore, int iBlockSize=512 );
75 virtual ~MyriadFs(); 75 virtual ~MyriadFs();
76 76
77 enum 77 enum
78 { 78 {
79 permOthX = 0000001, 79 permOthX = 0000001,
80 permOthW = 0000002, 80 permOthW = 0000002,
81 permOthR = 0000004, 81 permOthR = 0000004,
82 permGrpX = 0000010, 82 permGrpX = 0000010,
83 permGrpW = 0000020, 83 permGrpW = 0000020,
84 permGrpR = 0000040, 84 permGrpR = 0000040,
85 permUsrX = 0000100, 85 permUsrX = 0000100,
86 permUsrW = 0000200, 86 permUsrW = 0000200,
87 permUsrR = 0000400, 87 permUsrR = 0000400,
88 permSticky = 0001000, 88 permSticky = 0001000,
89 permSetGid = 0002000, 89 permSetGid = 0002000,
90 permSetUid = 0004000, 90 permSetUid = 0004000,
91 permMask = 0007777, 91 permMask = 0007777,
92 typeFifo = 0010000, 92 typeFifo = 0010000,
93 typeChrDev = 0020000, 93 typeChrDev = 0020000,
94 typeDir = 0040000, 94 typeDir = 0040000,
95 typeBlkDev = 0060000, 95 typeBlkDev = 0060000,
96 typeRegFile = 0100000, 96 typeRegFile = 0100000,
97 typeSymLink = 0120000, 97 typeSymLink = 0120000,
98 typeSocket = 0140000, 98 typeSocket = 0140000,
99 typeMask = 0170000 99 typeMask = 0170000
100 }; 100 };
101 101
102 enum 102 enum
103 { 103 {
104 Read = 0x01, ///< Open file for reading 104 Read = 0x01, ///< Open file for reading
105 Write = 0x02, ///< Open file for writing 105 Write = 0x02, ///< Open file for writing
106 Create = 0x04, ///< Create file if it doesn't exist 106 Create = 0x04, ///< Create file if it doesn't exist
107 Truncate = 0x08, ///< Truncate file if it does exist 107 Truncate = 0x08, ///< Truncate file if it does exist
108 Append = 0x10, ///< Always append on every write 108 Append = 0x10, ///< Always append on every write
109 NonBlock = 0x20, ///< Open file in non-blocking mode 109 NonBlock = 0x20, ///< Open file in non-blocking mode
110 Exclusive = 0x44, ///< Create file, if it exists then fail 110 Exclusive = 0x44, ///< Create file, if it exists then fail
111 111
112 // Helpful mixes 112 // Helpful mixes
113 ReadWrite = 0x03, ///< Open for reading and writing 113 ReadWrite = 0x03, ///< Open for reading and writing
114 WriteNew = 0x0E ///< Create a file (or truncate) for writing. 114 WriteNew = 0x0E ///< Create a file (or truncate) for writing.
115 /// Same as Write|Create|Truncate 115 /// Same as Write|Create|Truncate
116 }; 116 };
117 117
118 class Stat 118 class Stat
119 { 119 {
120 public: 120 public:
121 int32_t iNode; 121 int32_t iNode;
122 int32_t iUser; 122 int32_t iUser;
123 int32_t iGroup; 123 int32_t iGroup;
124 uint16_t uPerms; 124 uint16_t uPerms;
125 int16_t iLinks; 125 int16_t iLinks;
126 int64_t iATime; 126 int64_t iATime;
127 int64_t iMTime; 127 int64_t iMTime;
128 int64_t iCTime; 128 int64_t iCTime;
129 int32_t iSize; 129 int32_t iSize;
130 uint32_t uDev; 130 uint32_t uDev;
131 Bu::String sName; 131 Bu::String sName;
132 }; 132 };
133 typedef Bu::List<Stat> Dir; 133 typedef Bu::List<Stat> Dir;
134 134
135 void stat( const Bu::String &sPath, Stat &rBuf ); 135 void stat( const Bu::String &sPath, Stat &rBuf );
136 MyriadStream open( const Bu::String &sPath, int iMode, 136 MyriadStream open( const Bu::String &sPath, int iMode,
137 uint16_t uPerms=0664 ); 137 uint16_t uPerms=0664 );
138 void create( const Bu::String &sPath, uint16_t iPerms ); 138 void create( const Bu::String &sPath, uint16_t iPerms );
139 void create( const Bu::String &sPath, uint16_t iPerms, 139 void create( const Bu::String &sPath, uint16_t iPerms,
140 uint16_t iDevHi, uint16_t iDevLo ); 140 uint16_t iDevHi, uint16_t iDevLo );
141 void create( const Bu::String &sPath, uint16_t iPerms, 141 void create( const Bu::String &sPath, uint16_t iPerms,
142 uint32_t uSpecial ); 142 uint32_t uSpecial );
143 void mkDir( const Bu::String &sPath, uint16_t iPerms ); 143 void mkDir( const Bu::String &sPath, uint16_t iPerms );
144 void mkSymLink( const Bu::String &sTarget, const Bu::String &sPath ); 144 void mkSymLink( const Bu::String &sTarget, const Bu::String &sPath );
145 void mkHardLink( const Bu::String &sTarget, const Bu::String &sPath ); 145 void mkHardLink( const Bu::String &sTarget, const Bu::String &sPath );
146 Bu::String readSymLink( const Bu::String &sPath ); 146 Bu::String readSymLink( const Bu::String &sPath );
147 Dir readDir( const Bu::String &sPath ); 147 Dir readDir( const Bu::String &sPath );
148 void setTimes( const Bu::String &sPath, int64_t iATime, 148 void setTimes( const Bu::String &sPath, int64_t iATime,
149 int64_t iMTime ); 149 int64_t iMTime );
150 void unlink( const Bu::String &sPath ); 150 void unlink( const Bu::String &sPath );
151 void setFileSize( const Bu::String &sPath, int32_t iSize ); 151 void setFileSize( const Bu::String &sPath, int32_t iSize );
152 void rename( const Bu::String &sFrom, const Bu::String &sTo ); 152 void rename( const Bu::String &sFrom, const Bu::String &sTo );
153 153
154 static dev_t devToSys( uint32_t uDev ); 154 static dev_t devToSys( uint32_t uDev );
155 static uint32_t sysToDev( dev_t uDev ); 155 static uint32_t sysToDev( dev_t uDev );
156 156
157 private: 157 private:
158 class RawStat 158 class RawStat
159 { 159 {
160 public: 160 public:
161 int32_t iNode; 161 int32_t iNode;
162 int32_t iUser; 162 int32_t iUser;
163 int32_t iGroup; 163 int32_t iGroup;
164 uint16_t uPerms; 164 uint16_t uPerms;
165 int16_t iLinks; 165 int16_t iLinks;
166 uint32_t uStreamIndex; 166 uint32_t uStreamIndex;
167 int64_t iATime; 167 int64_t iATime;
168 int64_t iMTime; 168 int64_t iMTime;
169 int64_t iCTime; 169 int64_t iCTime;
170 }; 170 };
171 typedef Bu::Hash<int32_t, int32_t> NodeIndex; 171 typedef Bu::Hash<int32_t, int32_t> NodeIndex;
172 172
173 private: 173 private:
174 int32_t lookupInode( const Bu::String &sPath, int32_t &iParent ); 174 int32_t lookupInode( const Bu::String &sPath, int32_t &iParent );
175 int32_t lookupInode( Bu::String::const_iterator iStart, 175 int32_t lookupInode( Bu::String::const_iterator iStart,
176 int32_t iNode, int32_t &iParent ); 176 int32_t iNode, int32_t &iParent );
177 void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ); 177 void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs );
178 void readInode( int32_t iNode, RawStat &rs ); 178 void readInode( int32_t iNode, RawStat &rs );
179 void writeInode( const RawStat &rs ); 179 void writeInode( const RawStat &rs );
180 void writeInode( const RawStat &rs, MyriadStream &rOs ); 180 void writeInode( const RawStat &rs, MyriadStream &rOs );
181 Dir readDir( int32_t iNode ); 181 Dir readDir( int32_t iNode );
182 MyriadStream openByInode( int32_t iNode ); 182 MyriadStream openByInode( int32_t iNode );
183 void addToDir( int32_t iDir, int32_t iNode, const Bu::String &sName ); 183 void addToDir( int32_t iDir, int32_t iNode, const Bu::String &sName );
184 int32_t create( int32_t iParent, const Bu::String &sName, 184 int32_t create( int32_t iParent, const Bu::String &sName,
185 uint16_t uPerms, uint32_t uSpecial ); 185 uint16_t uPerms, uint32_t uSpecial );
186 int32_t allocInode( uint16_t uPerms, uint32_t uSpecial ); 186 int32_t allocInode( uint16_t uPerms, uint32_t uSpecial );
187 void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ); 187 void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs );
188 void writeHeader(); 188 void writeHeader();
189 void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); 189 void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime );
190 void destroyNode( int32_t iNode ); 190 void destroyNode( int32_t iNode );
191 191
192 Bu::String filePart( const Bu::String &sPath ); 192 Bu::String filePart( const Bu::String &sPath );
193 193
194 private: 194 private:
195 Bu::Stream &rStore; 195 Bu::Stream &rStore;
196 Bu::Myriad mStore; 196 Bu::Myriad mStore;
197 NodeIndex hNodeIndex; 197 NodeIndex hNodeIndex;
198 int32_t iUser; 198 int32_t iUser;
199 int32_t iGroup; 199 int32_t iGroup;
200 }; 200 };
201}; 201};
202 202
203#endif 203#endif