summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/myriadfs.cpp144
-rw-r--r--src/myriadfs.h32
-rw-r--r--src/tests/myriadfs.cpp24
-rw-r--r--src/tests/uuid.cpp1
-rw-r--r--src/tools/myriadfs.cpp124
-rw-r--r--src/uuid.cpp10
-rw-r--r--src/uuid.h3
7 files changed, 309 insertions, 29 deletions
diff --git a/src/myriadfs.cpp b/src/myriadfs.cpp
index 4e2a0f6..8312bce 100644
--- a/src/myriadfs.cpp
+++ b/src/myriadfs.cpp
@@ -45,7 +45,17 @@ Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) :
45 45
46 int8_t iVer; 46 int8_t iVer;
47 ms.read( &iVer, 1 ); 47 ms.read( &iVer, 1 );
48 throw MyriadFsException("You totally have a MyriadFs stream, version %d, but they can't be loaded yet.", iVer ); 48
49 int32_t iNumNodes;
50 ms.read( &iNumNodes, 4 );
51 for( int32_t j = 0; j < iNumNodes; j++ )
52 {
53 int32_t iNode;
54 int32_t iPos;
55 ms.read( &iNode, 4 );
56 ms.read( &iPos, 4 );
57 hNodeIndex.insert( iNode, iPos );
58 }
49 } 59 }
50 else 60 else
51 { 61 {
@@ -125,26 +135,103 @@ Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode )
125 if( iParent < 0 ) 135 if( iParent < 0 )
126 throw; 136 throw;
127 137
138 // This means that an intermediate path component couldn't be found
139 if( e.getErrorCode() == 1 )
140 throw;
141
128 // The file wasn't found, but the path leading up to it was. 142 // The file wasn't found, but the path leading up to it was.
129 // first, figure out the final path element... 143 // first, figure out the final path element...
130 Bu::String::const_iterator iStart = sPath.begin(); 144 Bu::String::const_iterator iStart = sPath.begin();
131 if( *iStart == '/' ) 145 if( *iStart == '/' )
132 iStart++; 146 iStart++;
133 sio << "Scanning for filename:" << sio.nl; 147 sio << "Scanning for filename:" << sio.nl;
134 for( Bu::String::const_iterator iEnd = iStart.find('/')+1; iEnd; iStart = iEnd ) { } 148 for( Bu::String::const_iterator iEnd = iStart.find('/'); iEnd;
149 iStart = iEnd+1, iEnd = iStart.find('/') ) { }
135 Bu::String sName( iStart, sPath.end() ); 150 Bu::String sName( iStart, sPath.end() );
136 sio << "End filename: " << sName << sio.nl; 151 sio << "End filename: " << sName << sio.nl;
137 sio << "Parent inode: " << iParent << sio.nl; 152 sio << "Parent inode: " << iParent << sio.nl;
138 iNode = create( iParent, sName, 0664|typeRegFile ); 153 iNode = create( iParent, sName, 0664|typeRegFile, 0 );
139 sio << "New iNode: " << iNode << sio.nl; 154 sio << "New iNode: " << iNode << sio.nl;
140 return openByInode( iNode ); 155 return openByInode( iNode );
141 } 156 }
157}
158
159void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms )
160{
161 create( sPath, iPerms, 0 );
162}
142 163
143 return mStore.openStream( 2 ); 164void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms,
165 uint16_t iDevHi, uint16_t iDevLo )
166{
167 create( sPath, iPerms, ((uint32_t)iDevHi<<16)|(uint32_t)iDevLo );
168}
169
170void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms,
171 uint32_t uSpecial )
172{
173 int32_t iParent = -1;
174 int32_t iNode;
175 try
176 {
177 iNode = lookupInode( sPath, iParent );
178 sio << "File found." << sio.nl;
179 // The file was found
180 throw Bu::MyriadFsException("Path already exists.");
181 }
182 catch( Bu::MyriadFsException &e )
183 {
184 if( iParent < 0 )
185 throw;
186
187 // This means that an intermediate path component couldn't be found
188 if( e.getErrorCode() == 1 )
189 throw;
190
191 // The file wasn't found, but the path leading up to it was.
192 // first, figure out the final path element...
193 Bu::String::const_iterator iStart = sPath.begin();
194 if( *iStart == '/' )
195 iStart++;
196 sio << "Scanning for filename:" << sio.nl;
197 for( Bu::String::const_iterator iEnd = iStart.find('/'); iEnd;
198 iStart = iEnd+1, iEnd = iStart.find('/') ) { }
199 Bu::String sName( iStart, sPath.end() );
200 sio << "End filename: " << sName << sio.nl;
201 sio << "Parent inode: " << iParent << sio.nl;
202 iNode = create( iParent, sName, iPerms, uSpecial );
203 sio << "New iNode: " << iNode << sio.nl;
204 }
205}
206
207void Bu::MyriadFs::mkDir( const Bu::String &sPath, uint16_t iPerms )
208{
209 create( sPath, (iPerms&permMask)|typeDir, 0 );
210}
211
212Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath )
213{
214 int32_t iParent = -1;
215 int32_t iNode = lookupInode( sPath, iParent );
216 return readDir( iNode );
217}
218
219dev_t Bu::MyriadFs::devToSys( uint32_t uDev )
220{
221 return (((uDev&0xFFFF0000)>>8)&0xFF00) | ((uDev&0xFF));
222}
223
224uint32_t Bu::MyriadFs::sysToDev( dev_t uDev )
225{
226 return (((uint32_t)uDev&0xFF00)<<8) | ((uint32_t)uDev&0xFF);
144} 227}
145 228
146int32_t Bu::MyriadFs::lookupInode( const Bu::String &sPath, int32_t &iParent ) 229int32_t Bu::MyriadFs::lookupInode( const Bu::String &sPath, int32_t &iParent )
147{ 230{
231 if( sPath == "/" )
232 {
233 return 0;
234 }
148 if( sPath[0] == '/' ) 235 if( sPath[0] == '/' )
149 { 236 {
150 // Absolute lookup 237 // Absolute lookup
@@ -185,7 +272,7 @@ int32_t Bu::MyriadFs::lookupInode( Bu::String::const_iterator iStart,
185 // Not the last one in our path, double check it's a dir 272 // Not the last one in our path, double check it's a dir
186 if( ((*i).uPerms&typeMask) == typeDir ) 273 if( ((*i).uPerms&typeMask) == typeDir )
187 { 274 {
188 return lookupInode( iEnd+1, (*i).iNode ); 275 return lookupInode( iEnd+1, (*i).iNode, iParent );
189 } 276 }
190 else 277 else
191 { 278 {
@@ -198,13 +285,16 @@ int32_t Bu::MyriadFs::lookupInode( Bu::String::const_iterator iStart,
198 } 285 }
199 } 286 }
200 287
201 throw Bu::MyriadFsException( 1, "Path not found"); 288 if( iEnd )
289 throw Bu::MyriadFsException( 1, "Path not found");
290 else
291 throw Bu::MyriadFsException( 2, "Path not found");
202} 292}
203 293
204Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode ) 294Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode )
205{ 295{
206 Bu::MyriadStream ms = openByInode( iNode ); 296 Bu::MyriadStream ms = openByInode( iNode );
207 int32_t iNumChildren; 297 int32_t iNumChildren = 0;
208 ms.read( &iNumChildren, 4 ); 298 ms.read( &iNumChildren, 4 );
209 299
210 Bu::MyriadStream is = mStore.openStream( 2 ); 300 Bu::MyriadStream is = mStore.openStream( 2 );
@@ -236,7 +326,7 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode )
236 case typeDir: 326 case typeDir:
237 case typeSymLink: 327 case typeSymLink:
238 case typeRegFile: 328 case typeRegFile:
239 return mStore.openStream( rs.iStreamIndex ); 329 return mStore.openStream( rs.uStreamIndex );
240 330
241 default: 331 default:
242 throw Bu::MyriadFsException( 332 throw Bu::MyriadFsException(
@@ -245,22 +335,22 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode )
245} 335}
246 336
247int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, 337int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName,
248 uint16_t uPerms ) 338 uint16_t uPerms, uint32_t uSpecial )
249{ 339{
250 Bu::MyriadStream ms = openByInode( iParent ); 340 Bu::MyriadStream ms = openByInode( iParent );
251 int32_t iNumChildren; 341 int32_t iNumChildren = 0;
252 ms.read( &iNumChildren, 4 ); 342 ms.read( &iNumChildren, 4 );
253 iNumChildren++; 343 iNumChildren++;
254 ms.setPos( 0 ); 344 ms.setPos( 0 );
255 ms.write( &iNumChildren, 4 ); 345 ms.write( &iNumChildren, 4 );
256 ms.setPos( iNumChildren*4 ); // Actually 4+(iNumChildren-1)*4 :-P 346 ms.setPos( iNumChildren*4 ); // Actually 4+(iNumChildren-1)*4 :-P
257 int32_t iNode = allocInode( sName, iParent, uPerms ); 347 int32_t iNode = allocInode( sName, iParent, uPerms, uSpecial );
258 ms.write( &iNode, 4 ); 348 ms.write( &iNode, 4 );
259 return iNode; 349 return iNode;
260} 350}
261 351
262int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, 352int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent,
263 uint16_t uPerms ) 353 uint16_t uPerms, uint32_t uSpecial )
264{ 354{
265 int32_t iNode = 0; 355 int32_t iNode = 0;
266 for(; iNode < 0xfffffff; iNode++ ) 356 for(; iNode < 0xfffffff; iNode++ )
@@ -279,14 +369,29 @@ int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent,
279 rs.iLinks = 1; 369 rs.iLinks = 1;
280 switch( (uPerms&typeMask) ) 370 switch( (uPerms&typeMask) )
281 { 371 {
282 case typeDir:
283 case typeRegFile: 372 case typeRegFile:
284 case typeSymLink: 373 case typeSymLink:
285 rs.iStreamIndex = mStore.createStream(); 374 rs.uStreamIndex = mStore.createStream();
375 break;
376
377 case typeDir:
378 rs.uStreamIndex = mStore.createStream();
379 {
380 Bu::MyriadStream msDir = mStore.openStream(
381 rs.uStreamIndex
382 );
383 uint32_t uSize = 0;
384 msDir.write( &uSize, 4 );
385 }
386 break;
387
388 case typeChrDev:
389 case typeBlkDev:
390 rs.uStreamIndex = uSpecial;
286 break; 391 break;
287 392
288 default: 393 default:
289 rs.iStreamIndex = 0; 394 rs.uStreamIndex = 0;
290 break; 395 break;
291 } 396 }
292 rs.iParentNode = iParent; 397 rs.iParentNode = iParent;
@@ -320,11 +425,18 @@ void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs )
320 rBuf.iATime = rs.iATime; 425 rBuf.iATime = rs.iATime;
321 rBuf.iMTime = rs.iMTime; 426 rBuf.iMTime = rs.iMTime;
322 rBuf.iCTime = rs.iCTime; 427 rBuf.iCTime = rs.iCTime;
428 rBuf.uDev = 0;
429 rBuf.iSize = 0;
323 switch( (rBuf.uPerms&typeMask) ) 430 switch( (rBuf.uPerms&typeMask) )
324 { 431 {
325 case typeRegFile: 432 case typeRegFile:
326 case typeSymLink: 433 case typeSymLink:
327 rBuf.iSize = mStore.getStreamSize( rs.iStreamIndex ); 434 rBuf.iSize = mStore.getStreamSize( rs.uStreamIndex );
435 break;
436
437 case typeChrDev:
438 case typeBlkDev:
439 rBuf.uDev = rs.uStreamIndex;
328 break; 440 break;
329 441
330 default: 442 default:
diff --git a/src/myriadfs.h b/src/myriadfs.h
index 808444b..3eecca5 100644
--- a/src/myriadfs.h
+++ b/src/myriadfs.h
@@ -8,6 +8,8 @@
8#ifndef MYRIAD_FS_H 8#ifndef MYRIAD_FS_H
9#define MYRIAD_FS_H 9#define MYRIAD_FS_H
10 10
11#include <sys/types.h>
12
11#include "bu/myriad.h" 13#include "bu/myriad.h"
12 14
13namespace Bu 15namespace Bu
@@ -38,9 +40,9 @@ namespace Bu
38 * Basic node header format: 40 * Basic node header format:
39 * int32_t iUser 41 * int32_t iUser
40 * int32_t iGroup 42 * int32_t iGroup
41 * int16_t iPerms 43 * uint16_t uPerms
42 * int16_t iLinks 44 * int16_t iLinks
43 * int32_t iStreamIndex 45 * uint32_t uStreamIndex
44 * int32_t iParentNode 46 * int32_t iParentNode
45 * int64_t iATime 47 * int64_t iATime
46 * int64_t iMTime 48 * int64_t iMTime
@@ -51,14 +53,14 @@ namespace Bu
51 * Some types get special formats for their assosiated data stream, or 53 * Some types get special formats for their assosiated data stream, or
52 * other special considerations, here's a list: 54 * other special considerations, here's a list:
53 * 55 *
54 * - typeFifo: No stream, iStreamIndex unused (probably) 56 * - typeFifo: No stream, uStreamIndex unused (probably)
55 * - typeChrDev: No stream, iStreamIndex is device hi/lo 57 * - typeChrDev: No stream, uStreamIndex is device hi/lo
56 * - typeDir: The stream contains a directory contents listing, described 58 * - typeDir: The stream contains a directory contents listing, described
57 * below 59 * below
58 * - typeBlkDev: No stream, iStreamIndex is device hi/lo 60 * - typeBlkDev: No stream, uStreamIndex is device hi/lo
59 * - typeRegFile: The stream is the file data 61 * - typeRegFile: The stream is the file data
60 * - typeSymLink: The stream is the destination of the symlink 62 * - typeSymLink: The stream is the destination of the symlink
61 * - typeSocket: No steram, iStreamIndex unused (probably) 63 * - typeSocket: No steram, uStreamIndex unused (probably)
62 * 64 *
63 * Directory streams have this simple listing format. They contain a list 65 * 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 66 * of all child elements, with no particular order at the moment. The . and
@@ -89,6 +91,7 @@ namespace Bu
89 permSticky = 0001000, 91 permSticky = 0001000,
90 permSetGid = 0002000, 92 permSetGid = 0002000,
91 permSetUid = 0004000, 93 permSetUid = 0004000,
94 permMask = 0007777,
92 typeFifo = 0010000, 95 typeFifo = 0010000,
93 typeChrDev = 0020000, 96 typeChrDev = 0020000,
94 typeDir = 0040000, 97 typeDir = 0040000,
@@ -127,14 +130,23 @@ namespace Bu
127 int64_t iMTime; 130 int64_t iMTime;
128 int64_t iCTime; 131 int64_t iCTime;
129 int32_t iSize; 132 int32_t iSize;
133 uint32_t uDev;
130 Bu::String sName; 134 Bu::String sName;
131 }; 135 };
132 typedef Bu::List<Stat> Dir; 136 typedef Bu::List<Stat> Dir;
133 137
134 void stat( const Bu::String &sPath, Stat &rBuf ); 138 void stat( const Bu::String &sPath, Stat &rBuf );
135 MyriadStream open( const Bu::String &sPath, int iMode ); 139 MyriadStream open( const Bu::String &sPath, int iMode );
136// void create( const Bu::String &sPath, uint16_t iPerms ); 140 void create( const Bu::String &sPath, uint16_t iPerms );
141 void create( const Bu::String &sPath, uint16_t iPerms,
142 uint16_t iDevHi, uint16_t iDevLo );
143 void create( const Bu::String &sPath, uint16_t iPerms,
144 uint32_t uSpecial );
145 void mkDir( const Bu::String &sPath, uint16_t iPerms );
146 Dir readDir( const Bu::String &sPath );
137 147
148 static dev_t devToSys( uint32_t uDev );
149 static uint32_t sysToDev( dev_t uDev );
138 150
139 private: 151 private:
140 class RawStat 152 class RawStat
@@ -144,7 +156,7 @@ namespace Bu
144 int32_t iGroup; 156 int32_t iGroup;
145 uint16_t uPerms; 157 uint16_t uPerms;
146 int16_t iLinks; 158 int16_t iLinks;
147 int32_t iStreamIndex; 159 uint32_t uStreamIndex;
148 int32_t iParentNode; 160 int32_t iParentNode;
149 int64_t iATime; 161 int64_t iATime;
150 int64_t iMTime; 162 int64_t iMTime;
@@ -160,9 +172,9 @@ namespace Bu
160 Dir readDir( int32_t iNode ); 172 Dir readDir( int32_t iNode );
161 MyriadStream openByInode( int32_t iNode ); 173 MyriadStream openByInode( int32_t iNode );
162 int32_t create( int32_t iParent, const Bu::String &sName, 174 int32_t create( int32_t iParent, const Bu::String &sName,
163 uint16_t uPerms ); 175 uint16_t uPerms, uint32_t uSpecial );
164 int32_t allocInode( const Bu::String &sName, int32_t iParent, 176 int32_t allocInode( const Bu::String &sName, int32_t iParent,
165 uint16_t uPerms ); 177 uint16_t uPerms, uint32_t uSpecial );
166 void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ); 178 void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs );
167 void writeHeader(); 179 void writeHeader();
168 180
diff --git a/src/tests/myriadfs.cpp b/src/tests/myriadfs.cpp
index fd96c02..5946b27 100644
--- a/src/tests/myriadfs.cpp
+++ b/src/tests/myriadfs.cpp
@@ -8,19 +8,41 @@ using namespace Bu;
8 8
9int main( int argc, char *argv[] ) 9int main( int argc, char *argv[] )
10{ 10{
11 Bu::MemBuf mb; 11// Bu::MemBuf mb;
12 Bu::File mb("store.myr", File::Read|File::Write|File::Create );
12 Bu::MyriadFs mfs( mb, 512 ); 13 Bu::MyriadFs mfs( mb, 512 );
13 14
15 sio << "Creating dirs..." << sio.nl;
16 mfs.create("/etc", Bu::MyriadFs::typeDir|0755 );
17 mfs.create("/dev", Bu::MyriadFs::typeDir|0755 );
18 mfs.create("/usr", Bu::MyriadFs::typeDir|0755 );
19
20 mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 );
21 mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 );
22 mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 );
23
24 sio << "Creating files..." << sio.nl;
14 { 25 {
15 Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); 26 Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read );
16 ms.write("world!"); 27 ms.write("world!");
17 } 28 }
29 {
30 Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read );
31 ms.write("world, again!");
32 }
18 33
34 sio << "Reading files..." << sio.nl;
19 { 35 {
20 Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); 36 Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read );
21 char buf[512]; 37 char buf[512];
22 buf[ms.read( buf, 512 )] = '\0'; 38 buf[ms.read( buf, 512 )] = '\0';
23 sio << "read: '" << buf << "'" << sio.nl; 39 sio << "read: '" << buf << "'" << sio.nl;
24 } 40 }
41 {
42 Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read );
43 char buf[512];
44 buf[ms.read( buf, 512 )] = '\0';
45 sio << "read: '" << buf << "'" << sio.nl;
46 }
25} 47}
26 48
diff --git a/src/tests/uuid.cpp b/src/tests/uuid.cpp
index b6470fa..d2f67b1 100644
--- a/src/tests/uuid.cpp
+++ b/src/tests/uuid.cpp
@@ -15,6 +15,7 @@ int main()
15 Uuid i = Uuid::gen(); 15 Uuid i = Uuid::gen();
16 16
17 sio << i.toString() << sio.nl; 17 sio << i.toString() << sio.nl;
18 sio << "Version: " << i.getVersion() << sio.nl;
18 19
19 return 0; 20 return 0;
20} 21}
diff --git a/src/tools/myriadfs.cpp b/src/tools/myriadfs.cpp
index 88db0c0..3956311 100644
--- a/src/tools/myriadfs.cpp
+++ b/src/tools/myriadfs.cpp
@@ -10,36 +10,156 @@
10#include <fuse.h> 10#include <fuse.h>
11 11
12#include <string.h> 12#include <string.h>
13#include <errno.h>
14
15#include <bu/file.h>
16#include <bu/myriadfs.h>
17#include <bu/myriadstream.h>
18#include <bu/hash.h>
19
20Bu::File *pF = NULL;
21Bu::MyriadFs *pFs = NULL;
22
23typedef Bu::Hash<int64_t, Bu::MyriadStream> FileHash;
24FileHash hOpenFiles;
25int64_t iNextFileId = 0;
13 26
14extern "C" { 27extern "C" {
15 static int myriadfs_getattr( const char *sPath, struct stat *stbuf ) 28 static int myriadfs_getattr( const char *sPath, struct stat *stbuf )
16 { 29 {
17 30 try
31 {
32 printf("myriadfs_getattr: Statting file: %s\n", sPath );
33 Bu::MyriadFs::Stat st;
34 pFs->stat( sPath, st );
35 stbuf->st_ino = st.iNode;
36 stbuf->st_mode = st.uPerms;
37 stbuf->st_nlink = st.iLinks;
38 stbuf->st_uid = st.iUser;
39 stbuf->st_gid = st.iGroup;
40 stbuf->st_rdev = Bu::MyriadFs::devToSys( st.uDev );
41 stbuf->st_size = st.iSize;
42 stbuf->st_blocks = 8;
43 stbuf->st_atime = st.iATime;
44 stbuf->st_mtime = st.iMTime;
45 stbuf->st_ctime = st.iCTime;
46 return 0;
47 }
48 catch(...)
49 {
50 return -ENOENT;
51 }
18 } 52 }
19 53
20 static int myriadfs_readdir( const char *sPath, void *buf, 54 static int myriadfs_readdir( const char *sPath, void *buf,
21 fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi ) 55 fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi )
22 { 56 {
57 fprintf( stderr, "Reading dir...\n");
58 Bu::MyriadFs::Dir lDir = pFs->readDir( sPath );
59 filler( buf, ".", NULL, 0 );
60 filler( buf, "..", NULL, 0 );
61 for( Bu::MyriadFs::Dir::iterator i = lDir.begin(); i; i++ )
62 {
63 fprintf( stderr, "Adding file: '%s'\n", (*i).sName.getStr() );
64 filler( buf, (*i).sName.getStr(), NULL, 0 );
65 }
66
67 return 0;
68 }
69
70 static int myriadfs_mkdir( const char *sPath, mode_t uMode )
71 {
72 pFs->mkDir( sPath, uMode );
73 return 0;
23 } 74 }
24 75
25 static int myriadfs_open( const char *sPath, struct fuse_file_info *fi ) 76 static int myriadfs_open( const char *sPath, struct fuse_file_info *fi )
26 { 77 {
78 try
79 {
80 Bu::MyriadStream ms = pFs->open( sPath, 0 );
81 fi->fh = iNextFileId;
82 hOpenFiles.insert( iNextFileId++, ms );
83 return 0;
84 }
85 catch(...)
86 {
87 return -EACCES;
88 }
27 } 89 }
28 90
29 static int myriadfs_read( const char *sPath, char *buf, size_t iSize, 91 static int myriadfs_read( const char *sPath, char *buf, size_t iSize,
30 off_t iOffset, struct fuse_file_info *fi ) 92 off_t iOffset, struct fuse_file_info *fi )
31 { 93 {
94 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh );
95 ms.setPos( iOffset );
96 return ms.read( buf, iSize );
97 }
98
99 static int myriadfs_write( const char *sPath, const char *buf, size_t iSize,
100 off_t iOffset, struct fuse_file_info *fi )
101 {
102 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh );
103 ms.setPos( iOffset );
104 return ms.write( buf, iSize );
105 }
106
107 static int myriadfs_create( const char *sPath, mode_t uPerms,
108 struct fuse_file_info *fi )
109 {
110 try
111 {
112 Bu::MyriadStream ms = pFs->open( sPath, 0 );
113 fi->fh = iNextFileId;
114 hOpenFiles.insert( iNextFileId++, ms );
115 return 0;
116 }
117 catch(...)
118 {
119 return -EACCES;
120 }
121 }
122
123 static int myriadfs_mknod( const char *sPath, mode_t uPerms, dev_t Dev )
124 {
125 try
126 {
127 pFs->create( sPath, uPerms, Bu::MyriadFs::sysToDev( Dev ) );
128 return 0;
129 }
130 catch(...)
131 {
132 return -EACCES;
133 }
134 }
135
136 static int myriadfs_release( const char *sPath, struct fuse_file_info *fi )
137 {
138 hOpenFiles.erase( fi->fh );
139
140 return 0;
32 } 141 }
33 142
34 static struct fuse_operations myriadfs_oper; 143 static struct fuse_operations myriadfs_oper;
35 144
36 int main( int argc, char *argv[] ) 145 int main( int argc, char *argv[] )
37 { 146 {
147 pF = new Bu::File("store.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create );
148 pFs = new Bu::MyriadFs( *pF, 512 );
38 memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 ); 149 memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 );
39 myriadfs_oper.getattr = myriadfs_getattr; 150 myriadfs_oper.getattr = myriadfs_getattr;
40 myriadfs_oper.readdir = myriadfs_readdir; 151 myriadfs_oper.readdir = myriadfs_readdir;
152 myriadfs_oper.mkdir = myriadfs_mkdir;
41 myriadfs_oper.open = myriadfs_open; 153 myriadfs_oper.open = myriadfs_open;
42 myriadfs_oper.read = myriadfs_read; 154 myriadfs_oper.read = myriadfs_read;
43 return fuse_main( argc, argv, &myriadfs_oper, NULL ); 155 myriadfs_oper.write = myriadfs_write;
156 myriadfs_oper.create = myriadfs_create;
157 myriadfs_oper.mknod = myriadfs_mknod;
158 printf("Starting fuse_main.\n");
159 int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL );
160 printf("Done with fuse_main.\n");
161 delete pFs;
162 delete pF;
163 return iRet;
44 } 164 }
45} 165}
diff --git a/src/uuid.cpp b/src/uuid.cpp
index 69af5b4..d34a989 100644
--- a/src/uuid.cpp
+++ b/src/uuid.cpp
@@ -45,6 +45,16 @@ Bu::String Bu::Uuid::toString()
45 return mb.getString(); 45 return mb.getString();
46} 46}
47 47
48Bu::String Bu::Uuid::toUrn()
49{
50 return "urn:uuid:" + toString();
51}
52
53int Bu::Uuid::getVersion()
54{
55 return (data[6]&((8|4|2|1)<<4))>>4;
56}
57
48#define msb( i ) (1<<(7-i)) 58#define msb( i ) (1<<(7-i))
49 59
50void Bu::Uuid::clear() 60void Bu::Uuid::clear()
diff --git a/src/uuid.h b/src/uuid.h
index 327686f..ee7469b 100644
--- a/src/uuid.h
+++ b/src/uuid.h
@@ -21,6 +21,9 @@ namespace Bu
21 21
22 Bu::String toRawString(); 22 Bu::String toRawString();
23 Bu::String toString(); 23 Bu::String toString();
24 Bu::String toUrn();
25
26 int getVersion();
24 27
25 static Uuid gen(); 28 static Uuid gen();
26 static Uuid genV1(); 29 static Uuid genV1();