diff options
Diffstat (limited to '')
-rw-r--r-- | src/unstable/myriadfs.cpp | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/src/unstable/myriadfs.cpp b/src/unstable/myriadfs.cpp index b24997a..f748a53 100644 --- a/src/unstable/myriadfs.cpp +++ b/src/unstable/myriadfs.cpp | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "bu/config.h" | 8 | #include "bu/config.h" |
9 | #include "bu/myriadfs.h" | 9 | #include "bu/myriadfs.h" |
10 | #include "bu/myriadstream.h" | 10 | #include "bu/myriadstream.h" |
11 | #include "bu/mutexlocker.h" | ||
11 | 12 | ||
12 | #include <string.h> | 13 | #include <string.h> |
13 | #include <unistd.h> | 14 | #include <unistd.h> |
@@ -32,10 +33,10 @@ Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : | |||
32 | iGroup = getgid(); | 33 | iGroup = getgid(); |
33 | #endif | 34 | #endif |
34 | 35 | ||
35 | if( mStore.hasStream( 1 ) ) | 36 | if( mStore.exists( 1 ) ) |
36 | { | 37 | { |
37 | // Check to see if this is a MyriadFs stream. | 38 | // Check to see if this is a MyriadFs stream. |
38 | Bu::MyriadStream ms = mStore.openStream( 1 ); | 39 | Bu::MyriadStream ms = mStore.open( 1, Bu::Myriad::Read ); |
39 | char sMagic[4]; | 40 | char sMagic[4]; |
40 | if( ms.read( sMagic, 4 ) < 4 ) | 41 | if( ms.read( sMagic, 4 ) < 4 ) |
41 | throw MyriadFsException("The provided stream does not appear to be " | 42 | throw MyriadFsException("The provided stream does not appear to be " |
@@ -62,8 +63,8 @@ Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : | |||
62 | { | 63 | { |
63 | // Create initial header stream | 64 | // Create initial header stream |
64 | { | 65 | { |
65 | mStore.createStream( 1 ); | 66 | Bu::MyriadStream ms = mStore.open( |
66 | Bu::MyriadStream ms = mStore.openStream( 1 ); | 67 | 1, Bu::Myriad::WriteNew|Bu::Myriad::Exclusive ); |
67 | ms.write( Myriad_Fs_MAGIC_CODE, 4 ); | 68 | ms.write( Myriad_Fs_MAGIC_CODE, 4 ); |
68 | int8_t iVer = 1; | 69 | int8_t iVer = 1; |
69 | int32_t iTmp = 1; | 70 | int32_t iTmp = 1; |
@@ -77,8 +78,8 @@ Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : | |||
77 | 78 | ||
78 | // Create initial inode stream, with one root node. | 79 | // Create initial inode stream, with one root node. |
79 | { | 80 | { |
80 | mStore.createStream( 2 ); | 81 | Bu::MyriadStream ms = mStore.open( |
81 | Bu::MyriadStream ms = mStore.openStream( 2 ); | 82 | 2, Bu::Myriad::WriteNew|Bu::Myriad::Exclusive ); |
82 | RawStat rs; | 83 | RawStat rs; |
83 | rs.iNode = 0; | 84 | rs.iNode = 0; |
84 | rs.iUser = iUser; | 85 | rs.iUser = iUser; |
@@ -92,8 +93,8 @@ Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : | |||
92 | 93 | ||
93 | // Create inode 0's storage stream. | 94 | // Create inode 0's storage stream. |
94 | { | 95 | { |
95 | mStore.createStream( 3 ); | 96 | Bu::MyriadStream ms = mStore.open( |
96 | Bu::MyriadStream ms = mStore.openStream( 3 ); | 97 | 3, Bu::Myriad::WriteNew|Bu::Myriad::Exclusive ); |
97 | int32_t iTmp32 = 0; | 98 | int32_t iTmp32 = 0; |
98 | ms.write( &iTmp32, 4 ); // iChildCount | 99 | ms.write( &iTmp32, 4 ); // iChildCount |
99 | } | 100 | } |
@@ -107,15 +108,17 @@ Bu::MyriadFs::~MyriadFs() | |||
107 | 108 | ||
108 | void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) | 109 | void Bu::MyriadFs::stat( const Bu::String &sPath, Bu::MyriadFs::Stat &rBuf ) |
109 | { | 110 | { |
111 | Bu::MutexLocker lLock( mAccess ); | ||
110 | int32_t iParent; | 112 | int32_t iParent; |
111 | int32_t iNode = lookupInode( sPath, iParent ); | 113 | int32_t iNode = lookupInode( sPath, iParent ); |
112 | Bu::MyriadStream is = mStore.openStream( 2 ); | 114 | Bu::MyriadStream is = mStore.open( 2, Bu::Myriad::Read ); |
113 | stat( iNode, rBuf, is ); | 115 | stat( iNode, rBuf, is ); |
114 | } | 116 | } |
115 | 117 | ||
116 | Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode, | 118 | Bu::MyriadStream Bu::MyriadFs::open( const Bu::String &sPath, int iMode, |
117 | uint16_t uPerms ) | 119 | uint16_t uPerms ) |
118 | { | 120 | { |
121 | Bu::MutexLocker lLock( mAccess ); | ||
119 | int32_t iParent = -1; | 122 | int32_t iParent = -1; |
120 | int32_t iNode; | 123 | int32_t iNode; |
121 | try | 124 | try |
@@ -164,6 +167,7 @@ void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, | |||
164 | void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, | 167 | void Bu::MyriadFs::create( const Bu::String &sPath, uint16_t iPerms, |
165 | uint32_t uSpecial ) | 168 | uint32_t uSpecial ) |
166 | { | 169 | { |
170 | Bu::MutexLocker lLock( mAccess ); | ||
167 | int32_t iParent = -1; | 171 | int32_t iParent = -1; |
168 | // int32_t iNode; | 172 | // int32_t iNode; |
169 | try | 173 | try |
@@ -200,6 +204,7 @@ void Bu::MyriadFs::mkDir( const Bu::String &sPath, uint16_t iPerms ) | |||
200 | void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, | 204 | void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, |
201 | const Bu::String &sPath ) | 205 | const Bu::String &sPath ) |
202 | { | 206 | { |
207 | Bu::MutexLocker lLock( mAccess ); | ||
203 | int32_t iParent = -1; | 208 | int32_t iParent = -1; |
204 | int32_t iNode; | 209 | int32_t iNode; |
205 | try | 210 | try |
@@ -232,6 +237,7 @@ void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, | |||
232 | void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, | 237 | void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, |
233 | const Bu::String &sPath ) | 238 | const Bu::String &sPath ) |
234 | { | 239 | { |
240 | Bu::MutexLocker lLock( mAccess ); | ||
235 | int32_t iParent = -1; | 241 | int32_t iParent = -1; |
236 | int32_t iNode; | 242 | int32_t iNode; |
237 | 243 | ||
@@ -257,7 +263,7 @@ void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, | |||
257 | // sio << "End filename: " << sName << sio.nl; | 263 | // sio << "End filename: " << sName << sio.nl; |
258 | // sio << "Parent inode: " << iParent << sio.nl; | 264 | // sio << "Parent inode: " << iParent << sio.nl; |
259 | addToDir( iParent, iNode, sName ); | 265 | addToDir( iParent, iNode, sName ); |
260 | MyriadStream is = mStore.openStream( 2 ); | 266 | MyriadStream is = mStore.open( 2, Bu::Myriad::ReadWrite ); |
261 | RawStat rs; | 267 | RawStat rs; |
262 | readInode( iNode, rs, is ); | 268 | readInode( iNode, rs, is ); |
263 | rs.iLinks++; | 269 | rs.iLinks++; |
@@ -267,6 +273,7 @@ void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, | |||
267 | 273 | ||
268 | Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) | 274 | Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) |
269 | { | 275 | { |
276 | Bu::MutexLocker lLock( mAccess ); | ||
270 | int32_t iParent = -1; | 277 | int32_t iParent = -1; |
271 | int32_t iNode; | 278 | int32_t iNode; |
272 | iNode = lookupInode( sPath, iParent ); | 279 | iNode = lookupInode( sPath, iParent ); |
@@ -279,6 +286,7 @@ Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) | |||
279 | 286 | ||
280 | Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) | 287 | Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) |
281 | { | 288 | { |
289 | Bu::MutexLocker lLock( mAccess ); | ||
282 | int32_t iParent = -1; | 290 | int32_t iParent = -1; |
283 | int32_t iNode = lookupInode( sPath, iParent ); | 291 | int32_t iNode = lookupInode( sPath, iParent ); |
284 | return readDir( iNode ); | 292 | return readDir( iNode ); |
@@ -287,6 +295,7 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( const Bu::String &sPath ) | |||
287 | void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, | 295 | void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, |
288 | int64_t iMTime ) | 296 | int64_t iMTime ) |
289 | { | 297 | { |
298 | Bu::MutexLocker lLock( mAccess ); | ||
290 | int32_t iParent = -1; | 299 | int32_t iParent = -1; |
291 | int32_t iNode; | 300 | int32_t iNode; |
292 | 301 | ||
@@ -297,6 +306,7 @@ void Bu::MyriadFs::setTimes( const Bu::String &sPath, int64_t iATime, | |||
297 | 306 | ||
298 | void Bu::MyriadFs::unlink( const Bu::String &sPath ) | 307 | void Bu::MyriadFs::unlink( const Bu::String &sPath ) |
299 | { | 308 | { |
309 | Bu::MutexLocker lLock( mAccess ); | ||
300 | int32_t iParent = -1; | 310 | int32_t iParent = -1; |
301 | // int32_t iNode; | 311 | // int32_t iNode; |
302 | 312 | ||
@@ -314,7 +324,9 @@ void Bu::MyriadFs::unlink( const Bu::String &sPath ) | |||
314 | readInode( (*i).iNode, rs ); | 324 | readInode( (*i).iNode, rs ); |
315 | if( (rs.uPerms&typeMask) == typeDir ) | 325 | if( (rs.uPerms&typeMask) == typeDir ) |
316 | { | 326 | { |
317 | MyriadStream msDir = mStore.openStream( rs.uStreamIndex ); | 327 | MyriadStream msDir = mStore.open( |
328 | rs.uStreamIndex, Bu::Myriad::Read | ||
329 | ); | ||
318 | int32_t iCount; | 330 | int32_t iCount; |
319 | msDir.read( &iCount, 4 ); | 331 | msDir.read( &iCount, 4 ); |
320 | if( iCount > 0 ) | 332 | if( iCount > 0 ) |
@@ -350,6 +362,7 @@ void Bu::MyriadFs::unlink( const Bu::String &sPath ) | |||
350 | 362 | ||
351 | void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) | 363 | void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) |
352 | { | 364 | { |
365 | Bu::MutexLocker lLock( mAccess ); | ||
353 | int32_t iParent = -1; | 366 | int32_t iParent = -1; |
354 | int32_t iNode; | 367 | int32_t iNode; |
355 | iNode = lookupInode( sPath, iParent ); | 368 | iNode = lookupInode( sPath, iParent ); |
@@ -359,6 +372,7 @@ void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) | |||
359 | 372 | ||
360 | void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo ) | 373 | void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo ) |
361 | { | 374 | { |
375 | Bu::MutexLocker lLock( mAccess ); | ||
362 | mkHardLink( sFrom, sTo ); | 376 | mkHardLink( sFrom, sTo ); |
363 | unlink( sFrom ); | 377 | unlink( sFrom ); |
364 | } | 378 | } |
@@ -449,7 +463,7 @@ void Bu::MyriadFs::readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ) | |||
449 | 463 | ||
450 | void Bu::MyriadFs::readInode( int32_t iNode, RawStat &rs ) | 464 | void Bu::MyriadFs::readInode( int32_t iNode, RawStat &rs ) |
451 | { | 465 | { |
452 | MyriadStream ms = mStore.openStream( 2 ); | 466 | MyriadStream ms = mStore.open( 2, Bu::Myriad::Read ); |
453 | readInode( iNode, rs, ms ); | 467 | readInode( iNode, rs, ms ); |
454 | } | 468 | } |
455 | 469 | ||
@@ -464,7 +478,7 @@ void Bu::MyriadFs::writeInode( const RawStat &rs, | |||
464 | 478 | ||
465 | void Bu::MyriadFs::writeInode( const RawStat &rs ) | 479 | void Bu::MyriadFs::writeInode( const RawStat &rs ) |
466 | { | 480 | { |
467 | MyriadStream ms = mStore.openStream( 2 ); | 481 | MyriadStream ms = mStore.open( 2, Bu::Myriad::Write ); |
468 | writeInode( rs, ms ); | 482 | writeInode( rs, ms ); |
469 | } | 483 | } |
470 | 484 | ||
@@ -474,9 +488,9 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode ) | |||
474 | int32_t iNumChildren = 0; | 488 | int32_t iNumChildren = 0; |
475 | ms.read( &iNumChildren, 4 ); | 489 | ms.read( &iNumChildren, 4 ); |
476 | 490 | ||
477 | Bu::MyriadStream is = mStore.openStream( 2 ); | 491 | Bu::MyriadStream is = mStore.open( 2, Bu::Myriad::Read ); |
478 | Dir lDir; | 492 | Dir lDir; |
479 | sio << "Reading dir " << iNode << ", " << iNumChildren << " entries:" << sio.nl; | 493 | // sio << "Reading dir " << iNode << ", " << iNumChildren << " entries:" << sio.nl; |
480 | for( int32_t j = 0; j < iNumChildren; j++ ) | 494 | for( int32_t j = 0; j < iNumChildren; j++ ) |
481 | { | 495 | { |
482 | int32_t iChildNode = 0; | 496 | int32_t iChildNode = 0; |
@@ -485,7 +499,6 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode ) | |||
485 | throw Bu::MyriadFsException( | 499 | throw Bu::MyriadFsException( |
486 | "Failed to read iChildNode from directory."); | 500 | "Failed to read iChildNode from directory."); |
487 | } | 501 | } |
488 | Bu::println(" - iNode = %1").arg( iChildNode ); | ||
489 | Stat s; | 502 | Stat s; |
490 | stat( iChildNode, s, is ); | 503 | stat( iChildNode, s, is ); |
491 | uint8_t uLen; | 504 | uint8_t uLen; |
@@ -494,14 +507,12 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode ) | |||
494 | throw Bu::MyriadFsException( | 507 | throw Bu::MyriadFsException( |
495 | "Failed to read uLen from directory."); | 508 | "Failed to read uLen from directory."); |
496 | } | 509 | } |
497 | Bu::println(" - Name bytes = %1").arg( uLen ); | ||
498 | s.sName.setSize( uLen ); | 510 | s.sName.setSize( uLen ); |
499 | if( ms.read( s.sName.getStr(), uLen ) < uLen ) | 511 | if( ms.read( s.sName.getStr(), uLen ) < uLen ) |
500 | { | 512 | { |
501 | throw Bu::MyriadFsException( | 513 | throw Bu::MyriadFsException( |
502 | "Failed to read sName from directory."); | 514 | "Failed to read sName from directory."); |
503 | } | 515 | } |
504 | Bu::println(" - Name = \"%1\"").arg( s.sName ); | ||
505 | lDir.append( s ); | 516 | lDir.append( s ); |
506 | 517 | ||
507 | // sio << " " << s.sName << sio.nl; | 518 | // sio << " " << s.sName << sio.nl; |
@@ -519,9 +530,7 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode ) | |||
519 | case typeDir: | 530 | case typeDir: |
520 | case typeSymLink: | 531 | case typeSymLink: |
521 | case typeRegFile: | 532 | case typeRegFile: |
522 | Bu::println("Opening stream by iNode=%1, myriad stream=%2") | 533 | return mStore.open( rs.uStreamIndex, Bu::Myriad::ReadWrite ); |
523 | .arg( iNode ).arg( rs.uStreamIndex ); | ||
524 | return mStore.openStream( rs.uStreamIndex ); | ||
525 | 534 | ||
526 | default: | 535 | default: |
527 | throw Bu::MyriadFsException( | 536 | throw Bu::MyriadFsException( |
@@ -575,17 +584,17 @@ int32_t Bu::MyriadFs::allocInode( uint16_t uPerms, uint32_t uSpecial ) | |||
575 | { | 584 | { |
576 | case typeRegFile: | 585 | case typeRegFile: |
577 | case typeSymLink: | 586 | case typeSymLink: |
578 | rs.uStreamIndex = mStore.createStream(); | 587 | rs.uStreamIndex = mStore.allocate(); |
579 | break; | 588 | break; |
580 | 589 | ||
581 | case typeDir: | 590 | case typeDir: |
582 | rs.uStreamIndex = mStore.createStream(); | ||
583 | // sio << "Creating directory node, storage: " | 591 | // sio << "Creating directory node, storage: " |
584 | // << rs.uStreamIndex << sio.nl; | 592 | // << rs.uStreamIndex << sio.nl; |
585 | { | 593 | { |
586 | Bu::MyriadStream msDir = mStore.openStream( | 594 | Bu::MyriadStream msDir = mStore.create( |
587 | rs.uStreamIndex | 595 | Bu::Myriad::Write |
588 | ); | 596 | ); |
597 | rs.uStreamIndex = msDir.getId(); | ||
589 | uint32_t uSize = 0; | 598 | uint32_t uSize = 0; |
590 | msDir.write( &uSize, 4 ); | 599 | msDir.write( &uSize, 4 ); |
591 | } | 600 | } |
@@ -631,7 +640,7 @@ void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ) | |||
631 | { | 640 | { |
632 | case typeRegFile: | 641 | case typeRegFile: |
633 | case typeSymLink: | 642 | case typeSymLink: |
634 | rBuf.iSize = mStore.getStreamSize( rs.uStreamIndex ); | 643 | rBuf.iSize = mStore.getSize( rs.uStreamIndex ); |
635 | break; | 644 | break; |
636 | 645 | ||
637 | case typeChrDev: | 646 | case typeChrDev: |
@@ -647,7 +656,7 @@ void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ) | |||
647 | 656 | ||
648 | void Bu::MyriadFs::writeHeader() | 657 | void Bu::MyriadFs::writeHeader() |
649 | { | 658 | { |
650 | Bu::MyriadStream ms = mStore.openStream( 1 ); | 659 | Bu::MyriadStream ms = mStore.open( 1, Bu::Myriad::Write ); |
651 | ms.write( Myriad_Fs_MAGIC_CODE, 4 ); | 660 | ms.write( Myriad_Fs_MAGIC_CODE, 4 ); |
652 | int8_t iVer = 1; | 661 | int8_t iVer = 1; |
653 | int32_t iNumNodes = hNodeIndex.getSize(); | 662 | int32_t iNumNodes = hNodeIndex.getSize(); |
@@ -668,7 +677,7 @@ void Bu::MyriadFs::writeHeader() | |||
668 | void Bu::MyriadFs::setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ) | 677 | void Bu::MyriadFs::setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ) |
669 | { | 678 | { |
670 | RawStat rs; | 679 | RawStat rs; |
671 | Bu::MyriadStream is = mStore.openStream( 2 ); | 680 | Bu::MyriadStream is = mStore.open( 2, Bu::Myriad::ReadWrite ); |
672 | 681 | ||
673 | readInode( iNode, rs, is ); | 682 | readInode( iNode, rs, is ); |
674 | rs.iATime = iATime; | 683 | rs.iATime = iATime; |
@@ -681,18 +690,21 @@ void Bu::MyriadFs::destroyNode( int32_t iNode ) | |||
681 | if( iNode == 0 ) | 690 | if( iNode == 0 ) |
682 | throw Bu::MyriadFsException("You cannot destroy the root."); | 691 | throw Bu::MyriadFsException("You cannot destroy the root."); |
683 | 692 | ||
684 | Bu::MyriadStream is = mStore.openStream( 2 ); | 693 | uint32_t iPosition; |
694 | RawStat rsOld; | ||
695 | |||
696 | Bu::MyriadStream is = mStore.open( 2, Bu::Myriad::ReadWrite ); | ||
685 | 697 | ||
686 | // This will be overwritten with the last node | 698 | // This will be overwritten with the last node |
687 | uint32_t iPosition = hNodeIndex.get( iNode ); | 699 | iPosition = hNodeIndex.get( iNode ); |
688 | RawStat rsOld; | ||
689 | readInode( iNode, rsOld, is ); | 700 | readInode( iNode, rsOld, is ); |
701 | |||
690 | switch( (rsOld.uPerms&typeMask) ) | 702 | switch( (rsOld.uPerms&typeMask) ) |
691 | { | 703 | { |
692 | case typeRegFile: | 704 | case typeRegFile: |
693 | case typeDir: | 705 | case typeDir: |
694 | case typeSymLink: | 706 | case typeSymLink: |
695 | mStore.deleteStream( rsOld.uStreamIndex ); | 707 | mStore.erase( rsOld.uStreamIndex ); |
696 | break; | 708 | break; |
697 | } | 709 | } |
698 | 710 | ||