diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-02-20 07:19:44 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-02-20 07:19:44 +0000 |
commit | 9af80a223128dd465aabdd311fdf529e97b40e13 (patch) | |
tree | 062288ceb5816a50aa95bf77715395b76b5a12ae /src/myriadfs.cpp | |
parent | 3bb19feba42174a08842e035d21edd424ce9ced1 (diff) | |
download | libbu++-9af80a223128dd465aabdd311fdf529e97b40e13.tar.gz libbu++-9af80a223128dd465aabdd311fdf529e97b40e13.tar.bz2 libbu++-9af80a223128dd465aabdd311fdf529e97b40e13.tar.xz libbu++-9af80a223128dd465aabdd311fdf529e97b40e13.zip |
Well, unlink, mkHardLink, setFileSize, and more are freshly implemented, as is
rename, but there seems to be a problem, rename uses mkHardLink, and if the
target exists, hey, it adds another one...not quite ideal...
Diffstat (limited to 'src/myriadfs.cpp')
-rw-r--r-- | src/myriadfs.cpp | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/src/myriadfs.cpp b/src/myriadfs.cpp index 41ba652..cebae1c 100644 --- a/src/myriadfs.cpp +++ b/src/myriadfs.cpp | |||
@@ -191,8 +191,8 @@ void Bu::MyriadFs::mkDir( const Bu::String &sPath, uint16_t iPerms ) | |||
191 | create( sPath, (iPerms&permMask)|typeDir, 0 ); | 191 | create( sPath, (iPerms&permMask)|typeDir, 0 ); |
192 | } | 192 | } |
193 | 193 | ||
194 | void Bu::MyriadFs::mkSymLink( const Bu::String &sPath, | 194 | void Bu::MyriadFs::mkSymLink( const Bu::String &sTarget, |
195 | const Bu::String &sTarget ) | 195 | const Bu::String &sPath ) |
196 | { | 196 | { |
197 | int32_t iParent = -1; | 197 | int32_t iParent = -1; |
198 | int32_t iNode; | 198 | int32_t iNode; |
@@ -222,6 +222,42 @@ void Bu::MyriadFs::mkSymLink( const Bu::String &sPath, | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | void Bu::MyriadFs::mkHardLink( const Bu::String &sTarget, | ||
226 | const Bu::String &sPath ) | ||
227 | { | ||
228 | int32_t iParent = -1; | ||
229 | int32_t iNode; | ||
230 | |||
231 | iNode = lookupInode( sTarget, iParent ); | ||
232 | |||
233 | try | ||
234 | { | ||
235 | lookupInode( sPath, iParent ); | ||
236 | throw Bu::MyriadFsException("Path already exists."); | ||
237 | } | ||
238 | catch( Bu::MyriadFsException &e ) | ||
239 | { | ||
240 | if( iParent < 0 ) | ||
241 | throw; | ||
242 | |||
243 | // This means that an intermediate path component couldn't be found | ||
244 | if( e.getErrorCode() == 1 ) | ||
245 | throw; | ||
246 | |||
247 | // The file wasn't found, but the path leading up to it was. | ||
248 | // first, figure out the final path element... | ||
249 | Bu::String sName = filePart( sPath ); | ||
250 | sio << "End filename: " << sName << sio.nl; | ||
251 | sio << "Parent inode: " << iParent << sio.nl; | ||
252 | addToDir( iParent, iNode, sName ); | ||
253 | MyriadStream is = mStore.openStream( 2 ); | ||
254 | RawStat rs; | ||
255 | readInode( iNode, rs, is ); | ||
256 | rs.iLinks++; | ||
257 | writeInode( rs, is ); | ||
258 | } | ||
259 | } | ||
260 | |||
225 | Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) | 261 | Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) |
226 | { | 262 | { |
227 | int32_t iParent = -1; | 263 | int32_t iParent = -1; |
@@ -305,6 +341,21 @@ void Bu::MyriadFs::unlink( const Bu::String &sPath ) | |||
305 | ms.setSize( ms.tell() ); | 341 | ms.setSize( ms.tell() ); |
306 | } | 342 | } |
307 | 343 | ||
344 | void Bu::MyriadFs::setFileSize( const Bu::String &sPath, int32_t iSize ) | ||
345 | { | ||
346 | int32_t iParent = -1; | ||
347 | int32_t iNode; | ||
348 | iNode = lookupInode( sPath, iParent ); | ||
349 | MyriadStream ms = openByInode( iNode ); | ||
350 | ms.setSize( iSize ); | ||
351 | } | ||
352 | |||
353 | void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo ) | ||
354 | { | ||
355 | mkHardLink( sFrom, sTo ); | ||
356 | unlink( sFrom ); | ||
357 | } | ||
358 | |||
308 | dev_t Bu::MyriadFs::devToSys( uint32_t uDev ) | 359 | dev_t Bu::MyriadFs::devToSys( uint32_t uDev ) |
309 | { | 360 | { |
310 | return (((uDev&0xFFFF0000)>>8)&0xFF00) | ((uDev&0xFF)); | 361 | return (((uDev&0xFFFF0000)>>8)&0xFF00) | ((uDev&0xFF)); |
@@ -454,25 +505,31 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode ) | |||
454 | } | 505 | } |
455 | } | 506 | } |
456 | 507 | ||
457 | int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, | 508 | void Bu::MyriadFs::addToDir( int32_t iDir, int32_t iNode, |
458 | uint16_t uPerms, uint32_t uSpecial ) | 509 | const Bu::String &sName ) |
459 | { | 510 | { |
460 | if( sName.getSize() > 255 ) | 511 | if( sName.getSize() > 255 ) |
461 | { | 512 | { |
462 | throw Bu::MyriadFsException("Filename too long, max is 255 bytes."); | 513 | throw Bu::MyriadFsException("Filename too long, max is 255 bytes."); |
463 | } | 514 | } |
464 | Bu::MyriadStream ms = openByInode( iParent ); | 515 | Bu::MyriadStream ms = openByInode( iDir ); |
465 | int32_t iNumChildren = 0; | 516 | int32_t iNumChildren = 0; |
466 | ms.read( &iNumChildren, 4 ); | 517 | ms.read( &iNumChildren, 4 ); |
467 | iNumChildren++; | 518 | iNumChildren++; |
468 | ms.setPos( 0 ); | 519 | ms.setPos( 0 ); |
469 | ms.write( &iNumChildren, 4 ); | 520 | ms.write( &iNumChildren, 4 ); |
470 | ms.setPosEnd( 0 ); | 521 | ms.setPosEnd( 0 ); |
471 | int32_t iNode = allocInode( uPerms, uSpecial ); | ||
472 | ms.write( &iNode, 4 ); | 522 | ms.write( &iNode, 4 ); |
473 | uint8_t uLen = sName.getSize(); | 523 | uint8_t uLen = sName.getSize(); |
474 | ms.write( &uLen, 1 ); | 524 | ms.write( &uLen, 1 ); |
475 | ms.write( sName.getStr(), uLen ); | 525 | ms.write( sName.getStr(), uLen ); |
526 | } | ||
527 | |||
528 | int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, | ||
529 | uint16_t uPerms, uint32_t uSpecial ) | ||
530 | { | ||
531 | int32_t iNode = allocInode( uPerms, uSpecial ); | ||
532 | addToDir( iParent, iNode, sName ); | ||
476 | return iNode; | 533 | return iNode; |
477 | } | 534 | } |
478 | 535 | ||