aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2024-08-05 10:40:14 -0700
committerMike Buland <mike@xagasoft.com>2024-08-05 10:40:14 -0700
commite343acc2548fba7670977029da8373a0e58fa25a (patch)
tree3584cbee31d23b4ea4dd8d54545ee092ae5076f3
parentd344a682170e42ef3ca4e37b397428f9ba5fdb11 (diff)
downloadlibbu++-e343acc2548fba7670977029da8373a0e58fa25a.tar.gz
libbu++-e343acc2548fba7670977029da8373a0e58fa25a.tar.bz2
libbu++-e343acc2548fba7670977029da8373a0e58fa25a.tar.xz
libbu++-e343acc2548fba7670977029da8373a0e58fa25a.zip
Added loads and loads of debugging output to myriad.
There's an issue somewhere sometimes and streams are being truncated. My guess is a multi-threaded issue.
Diffstat (limited to '')
-rw-r--r--src/stable/myriad.cpp71
-rw-r--r--src/stable/myriadstream.cpp5
-rw-r--r--src/tools/myriad.cpp27
-rw-r--r--src/unstable/myriadfs.cpp27
4 files changed, 125 insertions, 5 deletions
diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp
index 4d7595a..86f651e 100644
--- a/src/stable/myriad.cpp
+++ b/src/stable/myriad.cpp
@@ -18,6 +18,8 @@ using Bu::Fmt;
18 18
19#define Myriad_MAGIC_CODE ((unsigned char *)"\x0a\xd3\xfa\x84") 19#define Myriad_MAGIC_CODE ((unsigned char *)"\x0a\xd3\xfa\x84")
20 20
21#define TRACE( x ) Bu::println("%1:%2: %3: %4 - %5").arg(__FILE__).arg( __LINE__ ).arg(__PRETTY_FUNCTION__).arg(sStore.getLocation()).arg(x)
22
21namespace Bu 23namespace Bu
22{ 24{
23 subExceptionDef( MyriadException ) 25 subExceptionDef( MyriadException )
@@ -53,11 +55,13 @@ Bu::Myriad::Myriad( Bu::Stream &sStore, int iBlockSize, int iPreallocate ) :
53Bu::Myriad::~Myriad() 55Bu::Myriad::~Myriad()
54{ 56{
55 mActiveBlocks.lock(); 57 mActiveBlocks.lock();
58 TRACE("mActiveBlocks locked.");
56 if( !hActiveBlocks.isEmpty() ) 59 if( !hActiveBlocks.isEmpty() )
57 { 60 {
58 sio << "Bu::Myriad::~Myriad(): Error: There are " 61 sio << "Bu::Myriad::~Myriad(): Error: There are "
59 << hActiveBlocks.getSize() << " unsynced blocks!" << sio.nl; 62 << hActiveBlocks.getSize() << " unsynced blocks!" << sio.nl;
60 } 63 }
64 TRACE("mActiveBlocks unlocking...");
61 mActiveBlocks.unlock(); 65 mActiveBlocks.unlock();
62 sync(); 66 sync();
63 67
@@ -72,6 +76,7 @@ void Bu::Myriad::sync()
72 updateHeader(); 76 updateHeader();
73 77
74 mActiveBlocks.lock(); 78 mActiveBlocks.lock();
79 TRACE("mActiveBlocks locked.");
75 for( BlockHash::iterator i = hActiveBlocks.begin(); i; i++ ) 80 for( BlockHash::iterator i = hActiveBlocks.begin(); i; i++ )
76 { 81 {
77 if( (*i)->bChanged ) 82 if( (*i)->bChanged )
@@ -79,12 +84,14 @@ void Bu::Myriad::sync()
79 syncBlock( *i ); 84 syncBlock( *i );
80 } 85 }
81 } 86 }
87 TRACE("mActiveBlocks unlocked...");
82 mActiveBlocks.unlock(); 88 mActiveBlocks.unlock();
83} 89}
84 90
85void Bu::Myriad::initialize() 91void Bu::Myriad::initialize()
86{ 92{
87 MutexLocker mLock( mHeader ); 93 MutexLocker mLock( mHeader );
94 TRACE("mHeader locked.");
88 lFreeBlocks.clear(); 95 lFreeBlocks.clear();
89 sStore.setPosEnd( 0 ); 96 sStore.setPosEnd( 0 );
90 Bu::size iSize = sStore.tell(); 97 Bu::size iSize = sStore.tell();
@@ -92,20 +99,30 @@ void Bu::Myriad::initialize()
92 99
93 unsigned char buf[4]; 100 unsigned char buf[4];
94 if( sStore.read( buf, 4 ) < 4 ) 101 if( sStore.read( buf, 4 ) < 4 )
102 {
103 TRACE("mHeader unlocked...");
95 throw MyriadException( MyriadException::emptyStream, 104 throw MyriadException( MyriadException::emptyStream,
96 "Input stream appears to be empty."); 105 "Input stream appears to be empty.");
106 }
97 if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) ) 107 if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) )
98 { 108 {
109 TRACE("mHeader unlocked...");
99 throw MyriadException( MyriadException::invalidFormat, 110 throw MyriadException( MyriadException::invalidFormat,
100 "Stream does not appear to be a valid Myriad format."); 111 "Stream does not appear to be a valid Myriad format.");
101 } 112 }
102 sStore.read( buf, 2 ); 113 sStore.read( buf, 2 );
103 if( buf[0] != 1 ) 114 if( buf[0] != 1 )
115 {
116 TRACE("mHeader unlocked...");
104 throw MyriadException( MyriadException::badVersion, 117 throw MyriadException( MyriadException::badVersion,
105 "We can only handle version 1 for now."); 118 "We can only handle version 1 for now.");
119 }
106 if( buf[1] != 32 ) 120 if( buf[1] != 32 )
121 {
122 TRACE("mHeader unlocked...");
107 throw MyriadException( MyriadException::invalidWordSize, 123 throw MyriadException( MyriadException::invalidWordSize,
108 "We can only handle 32-bit words at the moment."); 124 "We can only handle 32-bit words at the moment.");
125 }
109 sStore.read( &iBlockSize, 4 ); 126 sStore.read( &iBlockSize, 4 );
110 int iStreams; 127 int iStreams;
111 sStore.read( &iStreams, 4 ); 128 sStore.read( &iStreams, 4 );
@@ -188,11 +205,13 @@ void Bu::Myriad::initialize()
188 } 205 }
189 } 206 }
190// sio << "Myriad: Blocks used: " << bsBlockUsed.toString() << sio.nl; 207// sio << "Myriad: Blocks used: " << bsBlockUsed.toString() << sio.nl;
208 TRACE("mHeader unlocked...");
191} 209}
192 210
193void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate ) 211void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
194{ 212{
195 MutexLocker mLock( mHeader ); 213 MutexLocker mLock( mHeader );
214 TRACE("mHeader locked.");
196 lFreeBlocks.clear(); 215 lFreeBlocks.clear();
197 216
198 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 217 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
@@ -286,16 +305,24 @@ void Bu::Myriad::initialize( int iBlockSize, int iPreAllocate )
286 305
287 bHeaderChanged = true; 306 bHeaderChanged = true;
288 //hStreams.insert( 0, BlockArray( 0 ) ); 307 //hStreams.insert( 0, BlockArray( 0 ) );
308 TRACE("mHeader unlocked...");
289} 309}
290 310
291void Bu::Myriad::updateHeader() 311void Bu::Myriad::updateHeader()
292{ 312{
293 MutexLocker mLock( mHeader ); 313 MutexLocker mLock( mHeader );
314 TRACE("mHeader locked.");
294 315
295 if( bHeaderChanged == false ) 316 if( bHeaderChanged == false )
317 {
318 TRACE("mHeader unlocked...");
296 return; 319 return;
320 }
297 if( !sStore.canWrite() ) 321 if( !sStore.canWrite() )
322 {
323 TRACE("mHeader unlocked...");
298 return; 324 return;
325 }
299 326
300 char cBuf; 327 char cBuf;
301 int iBuf; 328 int iBuf;
@@ -363,11 +390,13 @@ void Bu::Myriad::updateHeader()
363 } 390 }
364 391
365 bHeaderChanged = false; 392 bHeaderChanged = false;
393 TRACE("mHeader unlocked...");
366} 394}
367 395
368int Bu::Myriad::createStream( int iPreAllocate ) 396int Bu::Myriad::createStream( int iPreAllocate )
369{ 397{
370 MutexLocker mLock( mHeader ); 398 MutexLocker mLock( mHeader );
399 TRACE("mHeader locked.");
371 400
372 Stream *pStr = new Stream(); 401 Stream *pStr = new Stream();
373 pStr->iId = aStreams.last()->iId+1; 402 pStr->iId = aStreams.last()->iId+1;
@@ -387,16 +416,19 @@ int Bu::Myriad::createStream( int iPreAllocate )
387 416
388 bHeaderChanged = true; 417 bHeaderChanged = true;
389 418
419 TRACE("mHeader unlocked...");
390 return pStr->iId; 420 return pStr->iId;
391} 421}
392 422
393int Bu::Myriad::createStreamWithId( int iId, int iPreAllocate ) 423int Bu::Myriad::createStreamWithId( int iId, int iPreAllocate )
394{ 424{
395 MutexLocker mLock( mHeader ); 425 MutexLocker mLock( mHeader );
426 TRACE("mHeader locked.");
396 427
397 try 428 try
398 { 429 {
399 findStream( iId ); 430 findStream( iId );
431 TRACE("mHeader unlocked...");
400 throw MyriadException( MyriadException::streamExists, 432 throw MyriadException( MyriadException::streamExists,
401 "There is already a stream with the given id."); 433 "There is already a stream with the given id.");
402 } 434 }
@@ -434,8 +466,10 @@ int Bu::Myriad::createStreamWithId( int iId, int iPreAllocate )
434 466
435 bHeaderChanged = true; 467 bHeaderChanged = true;
436 468
469 TRACE("mHeader unlocked...");
437 return pStr->iId; 470 return pStr->iId;
438 } 471 }
472 TRACE("mHeader unlocked...");
439} 473}
440 474
441int Bu::Myriad::findEmptyBlock() 475int Bu::Myriad::findEmptyBlock()
@@ -456,13 +490,20 @@ int Bu::Myriad::findEmptyBlock()
456void Bu::Myriad::deleteStream( int iId ) 490void Bu::Myriad::deleteStream( int iId )
457{ 491{
458 MutexLocker mLock( mHeader ); 492 MutexLocker mLock( mHeader );
493 TRACE("mHeader locked.");
459 494
460 if( iId < 0 ) 495 if( iId < 0 )
496 {
497 TRACE("mHeader unlocked...");
461 throw MyriadException( MyriadException::invalidStreamId, 498 throw MyriadException( MyriadException::invalidStreamId,
462 "Invalid stream id."); 499 "Invalid stream id.");
500 }
463 if( iId == 0 ) 501 if( iId == 0 )
502 {
503 TRACE("mHeader unlocked...");
464 throw MyriadException( MyriadException::protectedStream, 504 throw MyriadException( MyriadException::protectedStream,
465 "You cannot delete stream zero, it is protected."); 505 "You cannot delete stream zero, it is protected.");
506 }
466 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 507 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
467 { 508 {
468 if( (*i)->iId == iId ) 509 if( (*i)->iId == iId )
@@ -477,14 +518,17 @@ void Bu::Myriad::deleteStream( int iId )
477 aStreams.erase( i ); 518 aStreams.erase( i );
478 bHeaderChanged = true; 519 bHeaderChanged = true;
479 delete pStream; 520 delete pStream;
521 TRACE("mHeader unlocked...");
480 return; 522 return;
481 } 523 }
482 } 524 }
525 TRACE("mHeader unlocked...");
483} 526}
484 527
485Bu::Array<int> Bu::Myriad::getStreamIds() 528Bu::Array<int> Bu::Myriad::getStreamIds()
486{ 529{
487 MutexLocker mLock( mHeader ); 530 MutexLocker mLock( mHeader );
531 TRACE("mHeader locked.");
488 532
489 Bu::Array<int> aRet( aStreams.getSize() ); 533 Bu::Array<int> aRet( aStreams.getSize() );
490 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 534 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
@@ -492,26 +536,32 @@ Bu::Array<int> Bu::Myriad::getStreamIds()
492 aRet.append( (*i)->iId ); 536 aRet.append( (*i)->iId );
493 } 537 }
494 538
539 TRACE("mHeader unlocked...");
495 return aRet; 540 return aRet;
496} 541}
497 542
498int Bu::Myriad::getStreamSize( int iId ) 543int Bu::Myriad::getStreamSize( int iId )
499{ 544{
500 MutexLocker mLock( mHeader ); 545 MutexLocker mLock( mHeader );
546 TRACE("mHeader locked.");
501 547
548 TRACE("mHeader unlocked...");
502 return findStream( iId )->iSize; 549 return findStream( iId )->iSize;
503} 550}
504 551
505bool Bu::Myriad::hasStream( int iId ) 552bool Bu::Myriad::hasStream( int iId )
506{ 553{
507 MutexLocker mLock( mHeader ); 554 MutexLocker mLock( mHeader );
555 TRACE("mHeader locked.");
508 556
509 try 557 try
510 { 558 {
511 findStream( iId ); 559 findStream( iId );
560 TRACE("mHeader unlocked...");
512 return true; 561 return true;
513 }catch(...) 562 }catch(...)
514 { 563 {
564 TRACE("mHeader unlocked...");
515 return false; 565 return false;
516 } 566 }
517} 567}
@@ -519,7 +569,9 @@ bool Bu::Myriad::hasStream( int iId )
519Bu::MyriadStream Bu::Myriad::openStream( int iId ) 569Bu::MyriadStream Bu::Myriad::openStream( int iId )
520{ 570{
521 MutexLocker mLock( mHeader ); 571 MutexLocker mLock( mHeader );
572 TRACE("mHeader locked.");
522 573
574 TRACE("mHeader unlocked...");
523 //sio << "Myriad: Request to open stream: " << iId << sio.nl; 575 //sio << "Myriad: Request to open stream: " << iId << sio.nl;
524 return MyriadStream( *this, findStream( iId ) ); 576 return MyriadStream( *this, findStream( iId ) );
525} 577}
@@ -527,7 +579,9 @@ Bu::MyriadStream Bu::Myriad::openStream( int iId )
527int Bu::Myriad::getNumStreams() 579int Bu::Myriad::getNumStreams()
528{ 580{
529 MutexLocker mLock( mHeader ); 581 MutexLocker mLock( mHeader );
582 TRACE("mHeader locked.");
530 583
584 TRACE("mHeader unlocked...");
531 return aStreams.getSize(); 585 return aStreams.getSize();
532} 586}
533 587
@@ -549,36 +603,42 @@ int Bu::Myriad::getNumUsedBlocks()
549Bu::size Bu::Myriad::getTotalUsedBytes() 603Bu::size Bu::Myriad::getTotalUsedBytes()
550{ 604{
551 MutexLocker mLock( mHeader ); 605 MutexLocker mLock( mHeader );
606 TRACE("mHeader locked.");
552 607
553 Bu::size iTotalSize = 0; 608 Bu::size iTotalSize = 0;
554 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 609 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
555 { 610 {
556 iTotalSize += (*i)->iSize; 611 iTotalSize += (*i)->iSize;
557 } 612 }
613 TRACE("mHeader unlocked...");
558 return iTotalSize; 614 return iTotalSize;
559} 615}
560 616
561Bu::size Bu::Myriad::getTotalUnusedBytes() 617Bu::size Bu::Myriad::getTotalUnusedBytes()
562{ 618{
563 MutexLocker mLock( mHeader ); 619 MutexLocker mLock( mHeader );
620 TRACE("mHeader locked.");
564 621
565 Bu::size iTotalSize = (iBlocks-iUsed)*iBlockSize; 622 Bu::size iTotalSize = (iBlocks-iUsed)*iBlockSize;
566 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 623 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
567 { 624 {
568 iTotalSize += iBlockSize - ((Bu::size)(*i)->iSize%iBlockSize); 625 iTotalSize += iBlockSize - ((Bu::size)(*i)->iSize%iBlockSize);
569 } 626 }
627 TRACE("mHeader unlocked...");
570 return iTotalSize; 628 return iTotalSize;
571} 629}
572 630
573Bu::size Bu::Myriad::getTotalUnusedBytes( int iFakeBlockSize ) 631Bu::size Bu::Myriad::getTotalUnusedBytes( int iFakeBlockSize )
574{ 632{
575 MutexLocker mLock( mHeader ); 633 MutexLocker mLock( mHeader );
634 TRACE("mHeader locked.");
576 635
577 Bu::size iTotalSize = (iBlocks-iUsed)*iFakeBlockSize; 636 Bu::size iTotalSize = (iBlocks-iUsed)*iFakeBlockSize;
578 for( StreamArray::iterator i = aStreams.begin(); i; i++ ) 637 for( StreamArray::iterator i = aStreams.begin(); i; i++ )
579 { 638 {
580 iTotalSize += iFakeBlockSize - ((*i)->iSize%iFakeBlockSize); 639 iTotalSize += iFakeBlockSize - ((*i)->iSize%iFakeBlockSize);
581 } 640 }
641 TRACE("mHeader unlocked...");
582 return iTotalSize; 642 return iTotalSize;
583} 643}
584 644
@@ -608,7 +668,9 @@ Bu::Myriad::Block *Bu::Myriad::getBlock( int iBlock )
608 pBlock->iBlockIndex = iBlock; 668 pBlock->iBlockIndex = iBlock;
609 669
610 mActiveBlocks.lock(); 670 mActiveBlocks.lock();
671 TRACE("mHeader locked.");
611 hActiveBlocks.insert( iBlock, pBlock ); 672 hActiveBlocks.insert( iBlock, pBlock );
673 TRACE("mHeader unlocked...");
612 mActiveBlocks.unlock(); 674 mActiveBlocks.unlock();
613 675
614 return pBlock; 676 return pBlock;
@@ -621,7 +683,9 @@ void Bu::Myriad::releaseBlock( Bu::Myriad::Block *pBlock )
621// sio << "Myriad: Releasing block " << pBlock->iBlockIndex << sio.nl; 683// sio << "Myriad: Releasing block " << pBlock->iBlockIndex << sio.nl;
622 syncBlock( pBlock ); 684 syncBlock( pBlock );
623 mActiveBlocks.lock(); 685 mActiveBlocks.lock();
686 TRACE("mHeader locked.");
624 hActiveBlocks.erase( pBlock->iBlockIndex ); 687 hActiveBlocks.erase( pBlock->iBlockIndex );
688 TRACE("mHeader unlocked...");
625 mActiveBlocks.unlock(); 689 mActiveBlocks.unlock();
626 690
627 delete[] pBlock->pData; 691 delete[] pBlock->pData;
@@ -642,26 +706,31 @@ void Bu::Myriad::syncBlock( Block *pBlock )
642int Bu::Myriad::streamAddBlock( Stream *pStream ) 706int Bu::Myriad::streamAddBlock( Stream *pStream )
643{ 707{
644 MutexLocker mLock( mHeader ); 708 MutexLocker mLock( mHeader );
709 TRACE("mHeader locked.");
645 710
646 int iBlock = findEmptyBlock(); 711 int iBlock = findEmptyBlock();
647 pStream->aBlocks.append( iBlock ); 712 pStream->aBlocks.append( iBlock );
648// bsBlockUsed.setBit( iBlock ); 713// bsBlockUsed.setBit( iBlock );
649// bHeaderChanged = true; 714// bHeaderChanged = true;
650 iUsed++; 715 iUsed++;
716 TRACE("mHeader unlocked...");
651 return iBlock; 717 return iBlock;
652} 718}
653 719
654void Bu::Myriad::setStreamSize( Stream *pStream, long iSize ) 720void Bu::Myriad::setStreamSize( Stream *pStream, long iSize )
655{ 721{
656 MutexLocker mLock( mHeader ); 722 MutexLocker mLock( mHeader );
723 TRACE("mHeader locked.");
657 724
658 if( pStream->iSize == iSize ) 725 if( pStream->iSize == iSize )
659 { 726 {
727 TRACE("mHeader unlocked...");
660 return; 728 return;
661 } 729 }
662 else if( pStream->iSize > iSize ) 730 else if( pStream->iSize > iSize )
663 { 731 {
664 // Shrink 732 // Shrink
733 TRACE(Bu::String("Shrink stream %1 from %2 to %3").arg(pStream->iId).arg(pStream->iSize).arg(iSize).end() );
665 for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; 734 for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize;
666 iNewSize-iBlockSize > iSize; iNewSize -= iBlockSize ) 735 iNewSize-iBlockSize > iSize; iNewSize -= iBlockSize )
667 { 736 {
@@ -679,6 +748,7 @@ void Bu::Myriad::setStreamSize( Stream *pStream, long iSize )
679 else 748 else
680 { 749 {
681 // Grow 750 // Grow
751 TRACE(Bu::String("Grow stream %1 from %2 to %3").arg(pStream->iId).arg(pStream->iSize).arg(iSize).end() );
682 for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize; 752 for( int iNewSize = pStream->aBlocks.getSize()*iBlockSize;
683 iNewSize < iSize; iNewSize += iBlockSize ) 753 iNewSize < iSize; iNewSize += iBlockSize )
684 { 754 {
@@ -692,6 +762,7 @@ void Bu::Myriad::setStreamSize( Stream *pStream, long iSize )
692 pStream->iSize = iSize; 762 pStream->iSize = iSize;
693 bHeaderChanged = true; 763 bHeaderChanged = true;
694 } 764 }
765 TRACE("mHeader unlocked...");
695} 766}
696 767
697void Bu::Myriad::headerChanged() 768void Bu::Myriad::headerChanged()
diff --git a/src/stable/myriadstream.cpp b/src/stable/myriadstream.cpp
index b2ed75e..50c6924 100644
--- a/src/stable/myriadstream.cpp
+++ b/src/stable/myriadstream.cpp
@@ -17,6 +17,9 @@
17using Bu::sio; 17using Bu::sio;
18using Bu::Fmt; 18using Bu::Fmt;
19#endif 19#endif
20#include "bu/sio.h"
21
22#define TRACE( x ) Bu::println("%1:%2: %3: %4 - %5").arg(__FILE__).arg( __LINE__ ).arg(__PRETTY_FUNCTION__).arg(rMyriad.sStore.getLocation()).arg(x)
20 23
21Bu::MyriadStream::MyriadStream( Bu::Myriad &rMyriad, 24Bu::MyriadStream::MyriadStream( Bu::Myriad &rMyriad,
22 Bu::Myriad::Stream *pStream ) : 25 Bu::Myriad::Stream *pStream ) :
@@ -205,7 +208,9 @@ Bu::size Bu::MyriadStream::write( const void *pBuf, Bu::size nBytes )
205 iAmnt 208 iAmnt
206 ); 209 );
207 iPos += iAmnt; 210 iPos += iAmnt;
211 TRACE(Bu::String("Stream=%1 - pStream->iSize(%2) += iAmnt(%3)").arg(pStream->iId).arg( pStream->iSize ).arg(iAmnt).end());
208 pStream->iSize += iAmnt; 212 pStream->iSize += iAmnt;
213 TRACE(Bu::String("Stream=%1 - pStream->iSize = %2").arg(pStream->iId).arg( pStream->iSize ).end());
209 rMyriad.headerChanged(); 214 rMyriad.headerChanged();
210 pBuf = &((char *)pBuf)[iAmnt]; 215 pBuf = &((char *)pBuf)[iAmnt];
211 iLeft -= iAmnt; 216 iLeft -= iAmnt;
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp
index 0130b49..ccf3d3b 100644
--- a/src/tools/myriad.cpp
+++ b/src/tools/myriad.cpp
@@ -23,6 +23,7 @@ enum Mode
23 modeStreamDump, 23 modeStreamDump,
24 modeStreamPut, 24 modeStreamPut,
25 modeStreamGet, 25 modeStreamGet,
26 modeBlockMap,
26 27
27 modeNone 28 modeNone
28}; 29};
@@ -49,6 +50,8 @@ public:
49 "Get a file out of a Myriad stream (use --dst)."); 50 "Get a file out of a Myriad stream (use --dst).");
50 addOption( eMode, "put", 51 addOption( eMode, "put",
51 "Put a file into a Myriad stream (usr --src)."); 52 "Put a file into a Myriad stream (usr --src).");
53 addOption( eMode, 'm', "block-map",
54 "Visualize block usage.");
52 addHelpOption(); 55 addHelpOption();
53 56
54 addHelpBanner("\nGeneral options:"); 57 addHelpBanner("\nGeneral options:");
@@ -67,6 +70,7 @@ public:
67 setOverride( "dump", modeStreamDump ); 70 setOverride( "dump", modeStreamDump );
68 setOverride( "put", modeStreamPut ); 71 setOverride( "put", modeStreamPut );
69 setOverride( "get", modeStreamGet ); 72 setOverride( "get", modeStreamGet );
73 setOverride( "block-map", modeBlockMap );
70 74
71 parse( argc, argv ); 75 parse( argc, argv );
72 } 76 }
@@ -242,6 +246,29 @@ int main( int argc, char *argv[] )
242 } 246 }
243 break; 247 break;
244 248
249 case modeBlockMap:
250 if( !opts.sFile.isSet() )
251 {
252 sio << "Please specify a file manipulate." << sio.nl;
253 return 0;
254 }
255 {
256 File fIn( opts.sFile, File::Write|File::Read );
257 Myriad m( fIn );
258 Bu::BitString bs = m.getBlocksUsed();
259 for( int j = 0; j < bs.getSize(); j++ )
260 {
261 if( j>0 && (j%50) == 0 )
262 Bu::println("");
263 if( bs.getBit( j ) )
264 Bu::print("#");
265 else
266 Bu::print("-");
267 }
268 Bu::println("\n");
269 }
270 break;
271
245 case modeNone: 272 case modeNone:
246 sio << "Please select a mode, for more info, try --help." 273 sio << "Please select a mode, for more info, try --help."
247 << sio.nl << sio.nl; 274 << sio.nl << sio.nl;
diff --git a/src/unstable/myriadfs.cpp b/src/unstable/myriadfs.cpp
index e02620d..b24997a 100644
--- a/src/unstable/myriadfs.cpp
+++ b/src/unstable/myriadfs.cpp
@@ -476,17 +476,32 @@ Bu::MyriadFs::Dir Bu::MyriadFs::readDir( int32_t iNode )
476 476
477 Bu::MyriadStream is = mStore.openStream( 2 ); 477 Bu::MyriadStream is = mStore.openStream( 2 );
478 Dir lDir; 478 Dir lDir;
479// sio << "Reading dir, " << iNumChildren << " entries:" << sio.nl; 479 sio << "Reading dir " << iNode << ", " << iNumChildren << " entries:" << sio.nl;
480 for( int32_t j = 0; j < iNumChildren; j++ ) 480 for( int32_t j = 0; j < iNumChildren; j++ )
481 { 481 {
482 int32_t iChildNode; 482 int32_t iChildNode = 0;
483 ms.read( &iChildNode, 4 ); 483 if( ms.read( &iChildNode, 4 ) < 4 )
484 {
485 throw Bu::MyriadFsException(
486 "Failed to read iChildNode from directory.");
487 }
488 Bu::println(" - iNode = %1").arg( iChildNode );
484 Stat s; 489 Stat s;
485 stat( iChildNode, s, is ); 490 stat( iChildNode, s, is );
486 uint8_t uLen; 491 uint8_t uLen;
487 ms.read( &uLen, 1 ); 492 if( ms.read( &uLen, 1 ) < 1 )
493 {
494 throw Bu::MyriadFsException(
495 "Failed to read uLen from directory.");
496 }
497 Bu::println(" - Name bytes = %1").arg( uLen );
488 s.sName.setSize( uLen ); 498 s.sName.setSize( uLen );
489 ms.read( s.sName.getStr(), uLen ); 499 if( ms.read( s.sName.getStr(), uLen ) < uLen )
500 {
501 throw Bu::MyriadFsException(
502 "Failed to read sName from directory.");
503 }
504 Bu::println(" - Name = \"%1\"").arg( s.sName );
490 lDir.append( s ); 505 lDir.append( s );
491 506
492// sio << " " << s.sName << sio.nl; 507// sio << " " << s.sName << sio.nl;
@@ -504,6 +519,8 @@ Bu::MyriadStream Bu::MyriadFs::openByInode( int32_t iNode )
504 case typeDir: 519 case typeDir:
505 case typeSymLink: 520 case typeSymLink:
506 case typeRegFile: 521 case typeRegFile:
522 Bu::println("Opening stream by iNode=%1, myriad stream=%2")
523 .arg( iNode ).arg( rs.uStreamIndex );
507 return mStore.openStream( rs.uStreamIndex ); 524 return mStore.openStream( rs.uStreamIndex );
508 525
509 default: 526 default: