summaryrefslogtreecommitdiff
path: root/src/myriadfs.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/myriadfs.h')
-rw-r--r--src/myriadfs.h100
1 files changed, 94 insertions, 6 deletions
diff --git a/src/myriadfs.h b/src/myriadfs.h
index 856137c..808444b 100644
--- a/src/myriadfs.h
+++ b/src/myriadfs.h
@@ -19,13 +19,10 @@ namespace Bu
19 /** 19 /**
20 * A POSIX compliant, node based filesystem built on top of Myriad. 20 * A POSIX compliant, node based filesystem built on top of Myriad.
21 * 21 *
22 * Think about putting this all in one stream, on block boundaries.
23 *
24 * A header is placed into stream 1. 22 * A header is placed into stream 1.
25 * Header format: 23 * Header format:
26 * int32_t iMagicHeader (A7188B39) 24 * int32_t iMagicHeader (A7188B39)
27 * int8_t iVersion (1) 25 * int8_t iVersion (1)
28 * int32_t iNodeSize
29 * int32_t iNumNodes 26 * int32_t iNumNodes
30 * NodeLookup[iNumNodes] nNode 27 * NodeLookup[iNumNodes] nNode
31 * 28 *
@@ -33,10 +30,10 @@ namespace Bu
33 * int32_t iInode 30 * int32_t iInode
34 * int32_t iPosition 31 * int32_t iPosition
35 * 32 *
36 * The node headers or inode structures have a base size of 22 bytes. 33 * The node headers or inode structures have a base size of 46 bytes.
37 * Everything else in the block is used for the name. I.e. if you have 34 * Everything else in the block is used for the name. I.e. if you have
38 * a blocksize of 512 bytes then you wind up with a max name size of 35 * a blocksize of 512 bytes then you wind up with a max name size of
39 * 512-22=490 characters, or a blocksize of 256 gives you 234 chraacters 36 * 512-46=466 characters, or a blocksize of 256 gives you 210 chraacters
40 * as a max. The node headers are all stored in stream 2. 37 * as a max. The node headers are all stored in stream 2.
41 * Basic node header format: 38 * Basic node header format:
42 * int32_t iUser 39 * int32_t iUser
@@ -50,6 +47,27 @@ namespace Bu
50 * int64_t iCTime 47 * int64_t iCTime
51 * int16_t iNameSize 48 * int16_t iNameSize
52 * char[iNameSize] sName 49 * char[iNameSize] sName
50 *
51 * Some types get special formats for their assosiated data stream, or
52 * other special considerations, here's a list:
53 *
54 * - typeFifo: No stream, iStreamIndex unused (probably)
55 * - typeChrDev: No stream, iStreamIndex is device hi/lo
56 * - typeDir: The stream contains a directory contents listing, described
57 * below
58 * - typeBlkDev: No stream, iStreamIndex is device hi/lo
59 * - typeRegFile: The stream is the file data
60 * - typeSymLink: The stream is the destination of the symlink
61 * - typeSocket: No steram, iStreamIndex unused (probably)
62 *
63 * Directory streams have this simple listing format. They contain a list
64 * of all child elements, with no particular order at the moment. The . and
65 * .. entries are not listed, they are implicit:
66 * int32_t iNumNodes
67 * NodeTable[iNumNodes] nChildren
68 *
69 * NodeTable:
70 * int32_t iInode
53 */ 71 */
54 class MyriadFs 72 class MyriadFs
55 { 73 {
@@ -79,11 +97,81 @@ namespace Bu
79 typeSymLink = 0120000, 97 typeSymLink = 0120000,
80 typeSocket = 0140000, 98 typeSocket = 0140000,
81 typeMask = 0170000 99 typeMask = 0170000
82 } 100 };
101
102 enum
103 {
104 Read = 0x01, ///< Open file for reading
105 Write = 0x02, ///< Open file for writing
106 Create = 0x04, ///< Create file if it doesn't exist
107 Truncate = 0x08, ///< Truncate file if it does exist
108 Append = 0x10, ///< Always append on every write
109 NonBlock = 0x20, ///< Open file in non-blocking mode
110 Exclusive = 0x44, ///< Create file, if it exists then fail
111
112 // Helpful mixes
113 ReadWrite = 0x03, ///< Open for reading and writing
114 WriteNew = 0x0E ///< Create a file (or truncate) for writing.
115 /// Same as Write|Create|Truncate
116 };
117
118 class Stat
119 {
120 public:
121 int32_t iNode;
122 int32_t iUser;
123 int32_t iGroup;
124 uint16_t uPerms;
125 int16_t iLinks;
126 int64_t iATime;
127 int64_t iMTime;
128 int64_t iCTime;
129 int32_t iSize;
130 Bu::String sName;
131 };
132 typedef Bu::List<Stat> Dir;
133
134 void stat( const Bu::String &sPath, Stat &rBuf );
135 MyriadStream open( const Bu::String &sPath, int iMode );
136// void create( const Bu::String &sPath, uint16_t iPerms );
137
138
139 private:
140 class RawStat
141 {
142 public:
143 int32_t iUser;
144 int32_t iGroup;
145 uint16_t uPerms;
146 int16_t iLinks;
147 int32_t iStreamIndex;
148 int32_t iParentNode;
149 int64_t iATime;
150 int64_t iMTime;
151 int64_t iCTime;
152 int16_t iNameSize;
153 };
154 typedef Bu::Hash<int32_t, int32_t> NodeIndex;
155
156 private:
157 int32_t lookupInode( const Bu::String &sPath, int32_t &iParent );
158 int32_t lookupInode( Bu::String::const_iterator iStart,
159 int32_t iNode, int32_t &iParent );
160 Dir readDir( int32_t iNode );
161 MyriadStream openByInode( int32_t iNode );
162 int32_t create( int32_t iParent, const Bu::String &sName,
163 uint16_t uPerms );
164 int32_t allocInode( const Bu::String &sName, int32_t iParent,
165 uint16_t uPerms );
166 void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs );
167 void writeHeader();
83 168
84 private: 169 private:
85 Bu::Stream &rStore; 170 Bu::Stream &rStore;
86 Bu::Myriad mStore; 171 Bu::Myriad mStore;
172 NodeIndex hNodeIndex;
173 int32_t iUser;
174 int32_t iGroup;
87 }; 175 };
88}; 176};
89 177