aboutsummaryrefslogtreecommitdiff
path: root/src/myriadfs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/myriadfs.cpp')
-rw-r--r--src/myriadfs.cpp90
1 files changed, 61 insertions, 29 deletions
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
212void 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
219dev_t Bu::MyriadFs::devToSys( uint32_t uDev ) 223dev_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 )
337int32_t Bu::MyriadFs::create( int32_t iParent, const Bu::String &sName, 345int32_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
352int32_t Bu::MyriadFs::allocInode( const Bu::String &sName, int32_t iParent, 367int32_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
413void Bu::MyriadFs::stat( int32_t iNode, Stat &rBuf, MyriadStream &rIs ) 427void 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
462void Bu::MyriadFs::unlink( int32_t iNode )
463{
464
465}
466
448void Bu::MyriadFs::writeHeader() 467void 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
487void 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