aboutsummaryrefslogtreecommitdiff
path: root/src/myriadfs.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/myriadfs.cpp69
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
194void Bu::MyriadFs::mkSymLink( const Bu::String &sPath, 194void 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
225void 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
225Bu::String Bu::MyriadFs::readSymLink( const Bu::String &sPath ) 261Bu::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
344void 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
353void Bu::MyriadFs::rename( const Bu::String &sFrom, const Bu::String &sTo )
354{
355 mkHardLink( sFrom, sTo );
356 unlink( sFrom );
357}
358
308dev_t Bu::MyriadFs::devToSys( uint32_t uDev ) 359dev_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
457int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, 508void 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
528int32_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