diff options
Diffstat (limited to '')
-rw-r--r-- | default.bld | 1 | ||||
-rw-r--r-- | src/md5.cpp | 2 | ||||
-rw-r--r-- | src/myriadfs.cpp | 90 | ||||
-rw-r--r-- | src/myriadfs.h | 24 | ||||
-rw-r--r-- | src/pearsonhash.cpp | 2 | ||||
-rw-r--r-- | src/tools/myriadfs.cpp | 9 |
6 files changed, 84 insertions, 44 deletions
diff --git a/default.bld b/default.bld index 558b976..c5f4310 100644 --- a/default.bld +++ b/default.bld | |||
@@ -142,7 +142,6 @@ target "libbu++-r$(svnversion "-n").tar.bz2" | |||
142 | { | 142 | { |
143 | input [ | 143 | input [ |
144 | "LICENSE", | 144 | "LICENSE", |
145 | "build.conf", | ||
146 | "Doxyfile", | 145 | "Doxyfile", |
147 | files("*.bld"), | 146 | files("*.bld"), |
148 | "support/vim/syntax/taf.vim", | 147 | "support/vim/syntax/taf.vim", |
diff --git a/src/md5.cpp b/src/md5.cpp index 71f17a0..15cba17 100644 --- a/src/md5.cpp +++ b/src/md5.cpp | |||
@@ -61,7 +61,7 @@ void Bu::Md5::addData( const void *sVData, int iSize ) | |||
61 | unsigned char *p = (unsigned char *) inbuf + t; | 61 | unsigned char *p = (unsigned char *) inbuf + t; |
62 | 62 | ||
63 | t = 64 - t; | 63 | t = 64 - t; |
64 | if( iSize < t ) { | 64 | if( (uint32_t)iSize < t ) { |
65 | memcpy( p, sData, iSize ); | 65 | memcpy( p, sData, iSize ); |
66 | return; | 66 | return; |
67 | } | 67 | } |
diff --git a/src/myriadfs.cpp b/src/myriadfs.cpp index 8312bce..d4cf67f 100644 --- a/src/myriadfs.cpp +++ b/src/myriadfs.cpp | |||
@@ -78,22 +78,15 @@ Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : | |||
78 | { | 78 | { |
79 | mStore.createStream( 2 ); | 79 | mStore.createStream( 2 ); |
80 | Bu::MyriadStream ms = mStore.openStream( 2 ); | 80 | Bu::MyriadStream ms = mStore.openStream( 2 ); |
81 | int32_t iTmp32 = 0; | 81 | RawStat rs; |
82 | int16_t iTmp16 = 0; | 82 | rs.iNode = 0; |
83 | uint16_t uPerms = 775|typeDir; | 83 | rs.iUser = iUser; |
84 | ms.write( &iUser, 4 ); // User | 84 | rs.iGroup = iGroup; |
85 | ms.write( &iGroup, 4 ); // Group | 85 | rs.uPerms = 0755|typeDir; |
86 | ms.write( &uPerms, 2 ); // Permissions/types | 86 | rs.iLinks = 1; |
87 | ms.write( &iTmp16, 2 ); // Link count | 87 | rs.uStreamIndex = 3; |
88 | iTmp32 = 3; | 88 | rs.iCTime = rs.iMTime = rs.iATime = time(NULL); |
89 | ms.write( &iTmp32, 4 ); // Stream index | 89 | ms.write( &rs, sizeof(RawStat) ); |
90 | iTmp32 = 0; | ||
91 | ms.write( &iTmp32, 4 ); // Parent inode (root's it's own parent) | ||
92 | int64_t iTime = time(NULL); | ||
93 | ms.write( &iTime, 8 ); // atime | ||
94 | ms.write( &iTime, 8 ); // mtime | ||
95 | ms.write( &iTime, 8 ); // ctime | ||
96 | ms.write( &iTmp16, 2 ); // Name size | ||
97 | } | 90 | } |
98 | 91 | ||
99 | // Create inode 0's storage stream. | 92 | // Create inode 0's storage stream. |
@@ -216,6 +209,17 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) | |||
216 | return readDir( iNode ); | 209 | return readDir( iNode ); |
217 | } | 210 | } |
218 | 211 | ||
212 | void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, | ||
213 | int64_t iMTime ) | ||
214 | { | ||
215 | int32_t iParent = -1; | ||
216 | int32_t iNode; | ||
217 | |||
218 | iNode = lookupInode( sPath, iParent ); | ||
219 | |||
220 | setTimes( iNode, iATime, iMTime ); | ||
221 | } | ||
222 | |||
219 | dev_t Bu::MyriadFs::devToSys( uint32_t uDev ) | 223 | dev_t Bu::MyriadFs::devToSys( uint32_t uDev ) |
220 | { | 224 | { |
221 | return (((uDev&0xFFFF0000)>>8)&0xFF00) | ((uDev&0xFF)); | 225 | return (((uDev&0xFFFF0000)>>8)&0xFF00) | ((uDev&0xFF)); |
@@ -306,6 +310,10 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode ) | |||
306 | ms.read( &iChildNode, 4 ); | 310 | ms.read( &iChildNode, 4 ); |
307 | Stat s; | 311 | Stat s; |
308 | stat( iChildNode, s, is ); | 312 | stat( iChildNode, s, is ); |
313 | uint8_t uLen; | ||
314 | ms.read( &uLen, 1 ); | ||
315 | s.sName.setSize( uLen ); | ||
316 | ms.read( s.sName.getStr(), uLen ); | ||
309 | lDir.append( s ); | 317 | lDir.append( s ); |
310 | 318 | ||
311 | sio << " " << s.sName << sio.nl; | 319 | sio << " " << s.sName << sio.nl; |
@@ -318,7 +326,7 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode ) | |||
318 | { | 326 | { |
319 | int32_t iIndex = hNodeIndex.get( iNode ); | 327 | int32_t iIndex = hNodeIndex.get( iNode ); |
320 | Bu::MyriadStream ms = mStore.openStream( 2 ); | 328 | Bu::MyriadStream ms = mStore.openStream( 2 ); |
321 | ms.setPos( mStore.getBlockSize()*iIndex ); | 329 | ms.setPos( iIndex*sizeof(RawStat) ); |
322 | RawStat rs; | 330 | RawStat rs; |
323 | ms.read( &rs, sizeof(RawStat) ); | 331 | ms.read( &rs, sizeof(RawStat) ); |
324 | switch( (rs.uPerms&typeMask) ) | 332 | switch( (rs.uPerms&typeMask) ) |
@@ -337,20 +345,26 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode ) | |||
337 | int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, | 345 | int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, |
338 | uint16_t uPerms, uint32_t uSpecial ) | 346 | uint16_t uPerms, uint32_t uSpecial ) |
339 | { | 347 | { |
348 | if( sName.getSize() > 255 ) | ||
349 | { | ||
350 | throw Bu::MyriadFsException("Filename too long, max is 255 bytes."); | ||
351 | } | ||
340 | Bu::MyriadStream ms = openByInode( iParent ); | 352 | Bu::MyriadStream ms = openByInode( iParent ); |
341 | int32_t iNumChildren = 0; | 353 | int32_t iNumChildren = 0; |
342 | ms.read( &iNumChildren, 4 ); | 354 | ms.read( &iNumChildren, 4 ); |
343 | iNumChildren++; | 355 | iNumChildren++; |
344 | ms.setPos( 0 ); | 356 | ms.setPos( 0 ); |
345 | ms.write( &iNumChildren, 4 ); | 357 | ms.write( &iNumChildren, 4 ); |
346 | ms.setPos( iNumChildren*4 ); // Actually 4+(iNumChildren-1)*4 :-P | 358 | ms.setPosEnd( 0 ); |
347 | int32_t iNode = allocInode( sName, iParent, uPerms, uSpecial ); | 359 | int32_t iNode = allocInode( uPerms, uSpecial ); |
348 | ms.write( &iNode, 4 ); | 360 | ms.write( &iNode, 4 ); |
361 | uint8_t uLen = sName.getSize(); | ||
362 | ms.write( &uLen, 1 ); | ||
363 | ms.write( sName.getStr(), uLen ); | ||
349 | return iNode; | 364 | return iNode; |
350 | } | 365 | } |
351 | 366 | ||
352 | int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, | 367 | int32_t Bu::MyriadFs::allocInode( uint16_t uPerms, uint32_t uSpecial ) |
353 | uint16_t uPerms, uint32_t uSpecial ) | ||
354 | { | 368 | { |
355 | int32_t iNode = 0; | 369 | int32_t iNode = 0; |
356 | for(; iNode < 0xfffffff; iNode++ ) | 370 | for(; iNode < 0xfffffff; iNode++ ) |
@@ -358,11 +372,12 @@ int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, | |||
358 | if( !hNodeIndex.has( iNode ) ) | 372 | if( !hNodeIndex.has( iNode ) ) |
359 | { | 373 | { |
360 | Bu::MyriadStream is = mStore.openStream( 2 ); | 374 | Bu::MyriadStream is = mStore.openStream( 2 ); |
361 | is.setSize( (hNodeIndex.getSize()+1)*mStore.getBlockSize() ); | 375 | is.setSize( (hNodeIndex.getSize()+1)*sizeof(RawStat) ); |
362 | is.setPos( hNodeIndex.getSize()*mStore.getBlockSize() ); | 376 | is.setPos( hNodeIndex.getSize()*sizeof(RawStat) ); |
363 | 377 | ||
364 | hNodeIndex.insert( iNode, hNodeIndex.getSize() ); | 378 | hNodeIndex.insert( iNode, hNodeIndex.getSize() ); |
365 | RawStat rs; | 379 | RawStat rs; |
380 | rs.iNode = iNode; | ||
366 | rs.iUser = iUser; | 381 | rs.iUser = iUser; |
367 | rs.iGroup = iGroup; | 382 | rs.iGroup = iGroup; |
368 | rs.uPerms = uPerms; | 383 | rs.uPerms = uPerms; |
@@ -376,6 +391,8 @@ int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, | |||
376 | 391 | ||
377 | case typeDir: | 392 | case typeDir: |
378 | rs.uStreamIndex = mStore.createStream(); | 393 | rs.uStreamIndex = mStore.createStream(); |
394 | sio << "Creating directory node, storage: " | ||
395 | << rs.uStreamIndex << sio.nl; | ||
379 | { | 396 | { |
380 | Bu::MyriadStream msDir = mStore.openStream( | 397 | Bu::MyriadStream msDir = mStore.openStream( |
381 | rs.uStreamIndex | 398 | rs.uStreamIndex |
@@ -394,13 +411,10 @@ int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, | |||
394 | rs.uStreamIndex = 0; | 411 | rs.uStreamIndex = 0; |
395 | break; | 412 | break; |
396 | } | 413 | } |
397 | rs.iParentNode = iParent; | ||
398 | rs.iATime = time(NULL); | 414 | rs.iATime = time(NULL); |
399 | rs.iMTime = time(NULL); | 415 | rs.iMTime = time(NULL); |
400 | rs.iCTime = time(NULL); | 416 | rs.iCTime = time(NULL); |
401 | rs.iNameSize = sName.getSize(); | ||
402 | is.write( &rs, sizeof(RawStat) ); | 417 | is.write( &rs, sizeof(RawStat) ); |
403 | is.write( sName.getStr(), sName.getSize() ); | ||
404 | 418 | ||
405 | return iNode; | 419 | return iNode; |
406 | } | 420 | } |
@@ -412,11 +426,11 @@ int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, | |||
412 | 426 | ||
413 | void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ) | 427 | void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ) |
414 | { | 428 | { |
415 | rIs.setPos( hNodeIndex.get( iNode )*mStore.getBlockSize() ); | 429 | rIs.setPos( hNodeIndex.get( iNode )*sizeof(RawStat) ); |
416 | RawStat rs; | 430 | RawStat rs; |
417 | rIs.read( &rs, sizeof(RawStat) ); | 431 | rIs.read( &rs, sizeof(RawStat) ); |
418 | rBuf.sName.setSize( rs.iNameSize ); | 432 | if( rs.iNode != iNode ) |
419 | rIs.read( rBuf.sName.getStr(), rs.iNameSize ); | 433 | throw Bu::MyriadFsException("Filesystem corruption detected."); |
420 | rBuf.iNode = iNode; | 434 | rBuf.iNode = iNode; |
421 | rBuf.iUser = rs.iUser; | 435 | rBuf.iUser = rs.iUser; |
422 | rBuf.iGroup = rs.iGroup; | 436 | rBuf.iGroup = rs.iGroup; |
@@ -445,6 +459,11 @@ void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ) | |||
445 | } | 459 | } |
446 | } | 460 | } |
447 | 461 | ||
462 | void Bu::MyriadFs::unlink( int32_t iNode ) | ||
463 | { | ||
464 | |||
465 | } | ||
466 | |||
448 | void Bu::MyriadFs::writeHeader() | 467 | void Bu::MyriadFs::writeHeader() |
449 | { | 468 | { |
450 | Bu::MyriadStream ms = mStore.openStream( 1 ); | 469 | Bu::MyriadStream ms = mStore.openStream( 1 ); |
@@ -465,3 +484,16 @@ void Bu::MyriadFs::writeHeader() | |||
465 | ms.setSize( ms.tell() ); | 484 | ms.setSize( ms.tell() ); |
466 | } | 485 | } |
467 | 486 | ||
487 | void Bu::MyriadFs::setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ) | ||
488 | { | ||
489 | RawStat rs; | ||
490 | Bu::MyriadStream is = mStore.openStream( 2 ); | ||
491 | |||
492 | is.setPos( hNodeIndex.get(iNode)*sizeof(RawStat) ); | ||
493 | is.read( &rs, sizeof(RawStat) ); | ||
494 | rs.iATime = iATime; | ||
495 | rs.iMTime = iMTime; | ||
496 | is.setPos( hNodeIndex.get(iNode)*sizeof(RawStat) ); | ||
497 | is.write( &rs, sizeof(RawStat) ); | ||
498 | } | ||
499 | |||
diff --git a/src/myriadfs.h b/src/myriadfs.h index 3eecca5..0b9c97f 100644 --- a/src/myriadfs.h +++ b/src/myriadfs.h | |||
@@ -32,23 +32,18 @@ namespace Bu | |||
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 46 bytes. | 35 | * The node headers or inode structures have a base size of 44 bytes. |
36 | * Everything else in the block is used for the name. I.e. if you have | 36 | * The name is stored in the directory format. |
37 | * a blocksize of 512 bytes then you wind up with a max name size of | ||
38 | * 512-46=466 characters, or a blocksize of 256 gives you 210 chraacters | ||
39 | * as a max. The node headers are all stored in stream 2. | ||
40 | * Basic node header format: | 37 | * Basic node header format: |
38 | * int32_t iNode | ||
41 | * int32_t iUser | 39 | * int32_t iUser |
42 | * int32_t iGroup | 40 | * int32_t iGroup |
43 | * uint16_t uPerms | 41 | * uint16_t uPerms |
44 | * int16_t iLinks | 42 | * int16_t iLinks |
45 | * uint32_t uStreamIndex | 43 | * uint32_t uStreamIndex |
46 | * int32_t iParentNode | ||
47 | * int64_t iATime | 44 | * int64_t iATime |
48 | * int64_t iMTime | 45 | * int64_t iMTime |
49 | * int64_t iCTime | 46 | * int64_t iCTime |
50 | * int16_t iNameSize | ||
51 | * char[iNameSize] sName | ||
52 | * | 47 | * |
53 | * Some types get special formats for their assosiated data stream, or | 48 | * Some types get special formats for their assosiated data stream, or |
54 | * other special considerations, here's a list: | 49 | * other special considerations, here's a list: |
@@ -70,6 +65,8 @@ namespace Bu | |||
70 | * | 65 | * |
71 | * NodeTable: | 66 | * NodeTable: |
72 | * int32_t iInode | 67 | * int32_t iInode |
68 | * uint8_t uNameSize | ||
69 | * char[uNameSize] sName | ||
73 | */ | 70 | */ |
74 | class MyriadFs | 71 | class MyriadFs |
75 | { | 72 | { |
@@ -144,6 +141,9 @@ namespace Bu | |||
144 | uint32_t uSpecial ); | 141 | uint32_t uSpecial ); |
145 | void mkDir( const Bu::String &sPath, uint16_t iPerms ); | 142 | void mkDir( const Bu::String &sPath, uint16_t iPerms ); |
146 | Dir readDir( const Bu::String &sPath ); | 143 | Dir readDir( const Bu::String &sPath ); |
144 | void setTimes( const Bu::String &sPath, int64_t iATime, | ||
145 | int64_t iMTime ); | ||
146 | void unlink( const Bu::String &sPath ); | ||
147 | 147 | ||
148 | static dev_t devToSys( uint32_t uDev ); | 148 | static dev_t devToSys( uint32_t uDev ); |
149 | static uint32_t sysToDev( dev_t uDev ); | 149 | static uint32_t sysToDev( dev_t uDev ); |
@@ -152,16 +152,15 @@ namespace Bu | |||
152 | class RawStat | 152 | class RawStat |
153 | { | 153 | { |
154 | public: | 154 | public: |
155 | int32_t iNode; | ||
155 | int32_t iUser; | 156 | int32_t iUser; |
156 | int32_t iGroup; | 157 | int32_t iGroup; |
157 | uint16_t uPerms; | 158 | uint16_t uPerms; |
158 | int16_t iLinks; | 159 | int16_t iLinks; |
159 | uint32_t uStreamIndex; | 160 | uint32_t uStreamIndex; |
160 | int32_t iParentNode; | ||
161 | int64_t iATime; | 161 | int64_t iATime; |
162 | int64_t iMTime; | 162 | int64_t iMTime; |
163 | int64_t iCTime; | 163 | int64_t iCTime; |
164 | int16_t iNameSize; | ||
165 | }; | 164 | }; |
166 | typedef Bu::Hash<int32_t, int32_t> NodeIndex; | 165 | typedef Bu::Hash<int32_t, int32_t> NodeIndex; |
167 | 166 | ||
@@ -173,10 +172,11 @@ namespace Bu | |||
173 | MyriadStream openByInode( int32_t iNode ); | 172 | MyriadStream openByInode( int32_t iNode ); |
174 | int32_t create( int32_t iParent, const Bu::String &sName, | 173 | int32_t create( int32_t iParent, const Bu::String &sName, |
175 | uint16_t uPerms, uint32_t uSpecial ); | 174 | uint16_t uPerms, uint32_t uSpecial ); |
176 | int32_t allocInode( const Bu::String &sName, int32_t iParent, | 175 | int32_t allocInode( uint16_t uPerms, uint32_t uSpecial ); |
177 | uint16_t uPerms, uint32_t uSpecial ); | ||
178 | void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ); | 176 | void stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ); |
177 | void unlink( int32_t iNode ); | ||
179 | void writeHeader(); | 178 | void writeHeader(); |
179 | void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); | ||
180 | 180 | ||
181 | private: | 181 | private: |
182 | Bu::Stream &rStore; | 182 | Bu::Stream &rStore; |
diff --git a/src/pearsonhash.cpp b/src/pearsonhash.cpp index d068687..d753d20 100644 --- a/src/pearsonhash.cpp +++ b/src/pearsonhash.cpp | |||
@@ -42,7 +42,7 @@ void Bu::PearsonHash::reset() | |||
42 | iValue = 0; | 42 | iValue = 0; |
43 | } | 43 | } |
44 | 44 | ||
45 | void Bu::PearsonHash::setSalt( const Bu::String &sSalt ) | 45 | void Bu::PearsonHash::setSalt( const Bu::String & /*sSalt*/ ) |
46 | { | 46 | { |
47 | } | 47 | } |
48 | 48 | ||
diff --git a/src/tools/myriadfs.cpp b/src/tools/myriadfs.cpp index 3956311..b54390d 100644 --- a/src/tools/myriadfs.cpp +++ b/src/tools/myriadfs.cpp | |||
@@ -140,6 +140,13 @@ extern "C" { | |||
140 | return 0; | 140 | return 0; |
141 | } | 141 | } |
142 | 142 | ||
143 | static int myriadfs_utimens( const char *sPath, | ||
144 | const struct timespec tv[2] ) | ||
145 | { | ||
146 | pFs->setTimes( sPath, tv[0].tv_sec, tv[1].tv_sec ); | ||
147 | return 0; | ||
148 | } | ||
149 | |||
143 | static struct fuse_operations myriadfs_oper; | 150 | static struct fuse_operations myriadfs_oper; |
144 | 151 | ||
145 | int main( int argc, char *argv[] ) | 152 | int main( int argc, char *argv[] ) |
@@ -155,6 +162,8 @@ extern "C" { | |||
155 | myriadfs_oper.write = myriadfs_write; | 162 | myriadfs_oper.write = myriadfs_write; |
156 | myriadfs_oper.create = myriadfs_create; | 163 | myriadfs_oper.create = myriadfs_create; |
157 | myriadfs_oper.mknod = myriadfs_mknod; | 164 | myriadfs_oper.mknod = myriadfs_mknod; |
165 | myriadfs_oper.release = myriadfs_release; | ||
166 | myriadfs_oper.utimens = myriadfs_utimens; | ||
158 | printf("Starting fuse_main.\n"); | 167 | printf("Starting fuse_main.\n"); |
159 | int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL ); | 168 | int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL ); |
160 | printf("Done with fuse_main.\n"); | 169 | printf("Done with fuse_main.\n"); |