diff options
Diffstat (limited to 'src/unstable')
-rw-r--r-- | src/unstable/bitstring.cpp | 12 | ||||
-rw-r--r-- | src/unstable/bitstring.h | 10 | ||||
-rw-r--r-- | src/unstable/cachebase.h | 10 | ||||
-rw-r--r-- | src/unstable/myriadcache.h | 28 | ||||
-rw-r--r-- | src/unstable/myriadfs.cpp | 76 | ||||
-rw-r--r-- | src/unstable/myriadfs.h | 14 |
6 files changed, 98 insertions, 52 deletions
diff --git a/src/unstable/bitstring.cpp b/src/unstable/bitstring.cpp index 21c1316..b80c073 100644 --- a/src/unstable/bitstring.cpp +++ b/src/unstable/bitstring.cpp | |||
@@ -209,7 +209,7 @@ void Bu::BitString::flipBit( long iBit ) | |||
209 | caData[iBit/8] ^= (1<<(iBit%8)); | 209 | caData[iBit/8] ^= (1<<(iBit%8)); |
210 | } | 210 | } |
211 | 211 | ||
212 | bool Bu::BitString::getBit( long iBit ) | 212 | bool Bu::BitString::getBit( long iBit ) const |
213 | { | 213 | { |
214 | if( iBit >= iBits || iBit < 0 ) return false; | 214 | if( iBit >= iBits || iBit < 0 ) return false; |
215 | if( (caData[iBit/8] & (1<<(iBit%8))) == 0 ) | 215 | if( (caData[iBit/8] & (1<<(iBit%8))) == 0 ) |
@@ -224,7 +224,7 @@ long Bu::BitString::getBitLength() | |||
224 | return iBits; | 224 | return iBits; |
225 | } | 225 | } |
226 | 226 | ||
227 | long Bu::BitString::getSize() | 227 | long Bu::BitString::getSize() const |
228 | { | 228 | { |
229 | return iBits; | 229 | return iBits; |
230 | } | 230 | } |
@@ -311,6 +311,14 @@ void Bu::BitString::clear() | |||
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | void Bu::BitString::fill() | ||
315 | { | ||
316 | if( caData != NULL ) | ||
317 | { | ||
318 | memset( caData, 0xff, iBytes ); | ||
319 | } | ||
320 | } | ||
321 | |||
314 | bool Bu::BitString::setBitLength( long iLength, bool bClear ) | 322 | bool Bu::BitString::setBitLength( long iLength, bool bClear ) |
315 | { | 323 | { |
316 | return setSize( iLength, bClear ); | 324 | return setSize( iLength, bClear ); |
diff --git a/src/unstable/bitstring.h b/src/unstable/bitstring.h index afc22fb..70ba822 100644 --- a/src/unstable/bitstring.h +++ b/src/unstable/bitstring.h | |||
@@ -88,7 +88,7 @@ namespace Bu | |||
88 | *@param iBit The index of the bit to test. | 88 | *@param iBit The index of the bit to test. |
89 | *@returns True for a 1, false for a 0. | 89 | *@returns True for a 1, false for a 0. |
90 | */ | 90 | */ |
91 | bool getBit( long iBit ); | 91 | bool getBit( long iBit ) const; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Inverts the entire BitString, in effect this calls flipBit on every | 94 | * Inverts the entire BitString, in effect this calls flipBit on every |
@@ -106,7 +106,7 @@ namespace Bu | |||
106 | DEPRECATED | 106 | DEPRECATED |
107 | long getBitLength(); | 107 | long getBitLength(); |
108 | 108 | ||
109 | long getSize(); | 109 | long getSize() const; |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Sets the entire BitString to zeros, but it does it very quickly. | 112 | * Sets the entire BitString to zeros, but it does it very quickly. |
@@ -115,6 +115,12 @@ namespace Bu | |||
115 | void clear(); | 115 | void clear(); |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * Sets the entire BitString to ones, but it does it very quickly. | ||
119 | * This operation runs in O(N). | ||
120 | */ | ||
121 | void fill(); | ||
122 | |||
123 | /** | ||
118 | * Gets another BitString that is autonomous of the current one | 124 | * Gets another BitString that is autonomous of the current one |
119 | * (contains a copy of the memory, not a pointer) and contains a subset | 125 | * (contains a copy of the memory, not a pointer) and contains a subset |
120 | * of the data in the current BitString. This is an inclusive | 126 | * of the data in the current BitString. This is an inclusive |
diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h index ec73ede..830f5fe 100644 --- a/src/unstable/cachebase.h +++ b/src/unstable/cachebase.h | |||
@@ -32,11 +32,15 @@ namespace Bu | |||
32 | bDeleted( false ), | 32 | bDeleted( false ), |
33 | pObject( pObject ) | 33 | pObject( pObject ) |
34 | { | 34 | { |
35 | //Bu::println("CacheEntry::CacheEntry: registering pObject (0x%1)"). | ||
36 | // arg( reinterpret_cast<ptrdiff_t>(pObject), Bu::Fmt::hex() ); | ||
35 | } | 37 | } |
36 | 38 | ||
37 | virtual ~CacheEntry() | 39 | virtual ~CacheEntry() |
38 | { | 40 | { |
39 | mEntry.lock(); | 41 | mEntry.lock(); |
42 | //Bu::println("CacheEntry::~CacheEntry: deleting pObject (0x%1)"). | ||
43 | // arg( reinterpret_cast<ptrdiff_t>(pObject), Bu::Fmt::hex() ); | ||
40 | delete pObject; | 44 | delete pObject; |
41 | mEntry.unlock(); | 45 | mEntry.unlock(); |
42 | } | 46 | } |
@@ -497,7 +501,7 @@ namespace Bu | |||
497 | if( pEnt->iRefCount == 0 ) | 501 | if( pEnt->iRefCount == 0 ) |
498 | { | 502 | { |
499 | pEnt->mEntry.unlock(); | 503 | pEnt->mEntry.unlock(); |
500 | delete pEnt->pObject; | 504 | //delete pEnt->pObject; |
501 | delete pEnt; | 505 | delete pEnt; |
502 | } | 506 | } |
503 | else | 507 | else |
@@ -529,7 +533,7 @@ namespace Bu | |||
529 | pEnt->mEntry.unlock(); | 533 | pEnt->mEntry.unlock(); |
530 | throw Bu::ExceptionBase( Bu::String("Cache entry %1 cannot be erased, there are %2 active references.").arg( key ).arg( iCount ).end().getStr() ); | 534 | throw Bu::ExceptionBase( Bu::String("Cache entry %1 cannot be erased, there are %2 active references.").arg( key ).arg( iCount ).end().getStr() ); |
531 | } | 535 | } |
532 | delete pEnt->pObject; | 536 | //delete pEnt->pObject; |
533 | delete pEnt; | 537 | delete pEnt; |
534 | hCacheEntry.erase( key ); | 538 | hCacheEntry.erase( key ); |
535 | } | 539 | } |
@@ -559,7 +563,7 @@ namespace Bu | |||
559 | { | 563 | { |
560 | if( pEnt->isReadyForCleanup() ) | 564 | if( pEnt->isReadyForCleanup() ) |
561 | { | 565 | { |
562 | delete pEnt->pObject; | 566 | //delete pEnt->pObject; |
563 | delete pEnt; | 567 | delete pEnt; |
564 | } | 568 | } |
565 | } | 569 | } |
diff --git a/src/unstable/myriadcache.h b/src/unstable/myriadcache.h index 24002b0..289ab05 100644 --- a/src/unstable/myriadcache.h +++ b/src/unstable/myriadcache.h | |||
@@ -28,7 +28,9 @@ namespace Bu | |||
28 | try | 28 | try |
29 | { | 29 | { |
30 | Bu::ReadWriteMutex::ReadLocker l( rwStore ); | 30 | Bu::ReadWriteMutex::ReadLocker l( rwStore ); |
31 | Bu::MyriadStream ms = mStore.openStream( 1 ); | 31 | Bu::MyriadStream ms = mStore.open( |
32 | 1, Bu::Myriad::WriteNew|Bu::Myriad::Read | ||
33 | ); | ||
32 | Bu::Archive ar( ms, Bu::Archive::load ); | 34 | Bu::Archive ar( ms, Bu::Archive::load ); |
33 | uint8_t uVer; | 35 | uint8_t uVer; |
34 | ar >> uVer; | 36 | ar >> uVer; |
@@ -41,10 +43,15 @@ namespace Bu | |||
41 | } | 43 | } |
42 | catch(...) | 44 | catch(...) |
43 | { | 45 | { |
44 | if( mStore.createStreamWithId( 1 ) != 1 ) | 46 | try |
47 | { | ||
48 | mStore.open( 1, Bu::Myriad::Create|Bu::Myriad::ReadWrite ); | ||
49 | _sync(); | ||
50 | } | ||
51 | catch(...) | ||
52 | { | ||
45 | throw Bu::ExceptionBase("Error creating index stream."); | 53 | throw Bu::ExceptionBase("Error creating index stream."); |
46 | 54 | } | |
47 | _sync(); | ||
48 | } | 55 | } |
49 | } | 56 | } |
50 | 57 | ||
@@ -78,7 +85,10 @@ namespace Bu | |||
78 | virtual void _create( const obtype *o ) | 85 | virtual void _create( const obtype *o ) |
79 | { | 86 | { |
80 | Bu::ReadWriteMutex::WriteLocker wl( rwStore ); | 87 | Bu::ReadWriteMutex::WriteLocker wl( rwStore ); |
81 | hIndex.insert( o->getKey(), mStore.createStream() ); | 88 | { |
89 | Bu::Myriad::StreamId id = mStore.allocate(); | ||
90 | hIndex.insert( o->getKey(), id ); | ||
91 | } | ||
82 | _save( o ); | 92 | _save( o ); |
83 | 93 | ||
84 | bStructureChanged = true; | 94 | bStructureChanged = true; |
@@ -87,7 +97,7 @@ namespace Bu | |||
87 | virtual void _erase( const keytype &k ) | 97 | virtual void _erase( const keytype &k ) |
88 | { | 98 | { |
89 | Bu::ReadWriteMutex::WriteLocker wl( rwStore ); | 99 | Bu::ReadWriteMutex::WriteLocker wl( rwStore ); |
90 | mStore.deleteStream( hIndex.get( k ) ); | 100 | mStore.erase( hIndex.get( k ) ); |
91 | hIndex.erase( k ); | 101 | hIndex.erase( k ); |
92 | 102 | ||
93 | bStructureChanged = true; | 103 | bStructureChanged = true; |
@@ -98,13 +108,13 @@ namespace Bu | |||
98 | const keytype &k | 108 | const keytype &k |
99 | ) | 109 | ) |
100 | { | 110 | { |
101 | Bu::MyriadStream ms = mStore.openStream( hIndex.get( k ) ); | 111 | Bu::MyriadStream ms = mStore.open( hIndex.get( k ), Bu::Myriad::Read ); |
102 | return _cacheObjectLoad<keytype, obtype>( initObj, k, ms ); | 112 | return _cacheObjectLoad<keytype, obtype>( initObj, k, ms ); |
103 | } | 113 | } |
104 | 114 | ||
105 | virtual void _save( const obtype *o ) | 115 | virtual void _save( const obtype *o ) |
106 | { | 116 | { |
107 | Bu::MyriadStream ms = mStore.openStream( hIndex.get( o->getKey() ) ); | 117 | Bu::MyriadStream ms = mStore.open( hIndex.get( o->getKey() ), Bu::Myriad::WriteNew ); |
108 | _cacheObjectSave( ms, o ); | 118 | _cacheObjectSave( ms, o ); |
109 | ms.setSize( ms.tell() ); | 119 | ms.setSize( ms.tell() ); |
110 | 120 | ||
@@ -117,7 +127,7 @@ namespace Bu | |||
117 | if( !bStructureChanged ) | 127 | if( !bStructureChanged ) |
118 | return; | 128 | return; |
119 | 129 | ||
120 | Bu::MyriadStream ms = mStore.openStream( 1 ); | 130 | Bu::MyriadStream ms = mStore.open( 1, Bu::Myriad::WriteNew ); |
121 | Bu::Archive ar( ms, Bu::Archive::save ); | 131 | Bu::Archive ar( ms, Bu::Archive::save ); |
122 | ar << (uint8_t)0 << hIndex; | 132 | ar << (uint8_t)0 << hIndex; |
123 | ar.close(); | 133 | ar.close(); |
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 | ||
diff --git a/src/unstable/myriadfs.h b/src/unstable/myriadfs.h index ff14292..e3008bc 100644 --- a/src/unstable/myriadfs.h +++ b/src/unstable/myriadfs.h | |||
@@ -11,7 +11,7 @@ | |||
11 | #include <sys/types.h> | 11 | #include <sys/types.h> |
12 | 12 | ||
13 | #include "bu/myriad.h" | 13 | #include "bu/myriad.h" |
14 | #include "bu/readwritemutex.h" | 14 | #include "bu/debugmutex.h" |
15 | 15 | ||
16 | namespace Bu | 16 | namespace Bu |
17 | { | 17 | { |
@@ -108,7 +108,7 @@ namespace Bu | |||
108 | Truncate = 0x08, ///< Truncate file if it does exist | 108 | Truncate = 0x08, ///< Truncate file if it does exist |
109 | Append = 0x10, ///< Always append on every write | 109 | Append = 0x10, ///< Always append on every write |
110 | NonBlock = 0x20, ///< Open file in non-blocking mode | 110 | NonBlock = 0x20, ///< Open file in non-blocking mode |
111 | Exclusive = 0x44, ///< Create file, if it exists then fail | 111 | Exclusive = 0x40, ///< Create file, if it exists then fail |
112 | 112 | ||
113 | // Helpful mixes | 113 | // Helpful mixes |
114 | ReadWrite = 0x03, ///< Open for reading and writing | 114 | ReadWrite = 0x03, ///< Open for reading and writing |
@@ -172,7 +172,13 @@ namespace Bu | |||
172 | typedef Bu::Hash<int32_t, int32_t> NodeIndex; | 172 | typedef Bu::Hash<int32_t, int32_t> NodeIndex; |
173 | 173 | ||
174 | private: | 174 | private: |
175 | /** | ||
176 | * Lookup inode. | ||
177 | */ | ||
175 | int32_t lookupInode( const Bu::String &sPath, int32_t &iParent ); | 178 | int32_t lookupInode( const Bu::String &sPath, int32_t &iParent ); |
179 | /** | ||
180 | * Lookup inode. | ||
181 | */ | ||
176 | int32_t lookupInode( Bu::String::const_iterator iStart, | 182 | int32_t lookupInode( Bu::String::const_iterator iStart, |
177 | int32_t iNode, int32_t &iParent ); | 183 | int32_t iNode, int32_t &iParent ); |
178 | void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ); | 184 | void readInode( int32_t iNode, RawStat &rs, MyriadStream &rIs ); |
@@ -190,12 +196,12 @@ namespace Bu | |||
190 | void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); | 196 | void setTimes( int32_t iNode, int64_t iATime, int64_t iMTime ); |
191 | void destroyNode( int32_t iNode ); | 197 | void destroyNode( int32_t iNode ); |
192 | 198 | ||
193 | Bu::String filePart( const Bu::String &sPath ); | 199 | static Bu::String filePart( const Bu::String &sPath ); |
194 | 200 | ||
195 | private: | 201 | private: |
196 | Bu::Stream &rStore; | 202 | Bu::Stream &rStore; |
197 | Bu::Myriad mStore; | 203 | Bu::Myriad mStore; |
198 | Bu::ReadWriteMutex mNodeIndex; | 204 | Bu::DebugMutex mAccess; |
199 | NodeIndex hNodeIndex; | 205 | NodeIndex hNodeIndex; |
200 | int32_t iUser; | 206 | int32_t iUser; |
201 | int32_t iGroup; | 207 | int32_t iGroup; |