From aefab051dd21df0123ffa45a5a28d594bfecf82d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 10 Nov 2010 21:18:58 +0000 Subject: Added a couple more debugging functions to Bu::Myriad, and exposed them in the cli tool. --- src/myriad.cpp | 30 ++++++++++++++++++++++++++++++ src/myriad.h | 3 +++ src/tools/myriad.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/myriad.cpp b/src/myriad.cpp index c3eb97e..b656b52 100644 --- a/src/myriad.cpp +++ b/src/myriad.cpp @@ -510,6 +510,36 @@ int Bu::Myriad::getNumUsedBlocks() return iUsed; } +int Bu::Myriad::getTotalUsedBytes() +{ + int iTotalSize = 0; + for( StreamArray::iterator i = aStreams.begin(); i; i++ ) + { + iTotalSize += (*i)->iSize; + } + return iTotalSize; +} + +int Bu::Myriad::getTotalUnusedBytes() +{ + int iTotalSize = (iBlocks-iUsed)*iBlockSize; + for( StreamArray::iterator i = aStreams.begin(); i; i++ ) + { + iTotalSize += iBlockSize - ((*i)->iSize%iBlockSize); + } + return iTotalSize; +} + +int Bu::Myriad::getTotalUnusedBytes( int iFakeBlockSize ) +{ + int iTotalSize = (iBlocks-iUsed)*iFakeBlockSize; + for( StreamArray::iterator i = aStreams.begin(); i; i++ ) + { + iTotalSize += iFakeBlockSize - ((*i)->iSize%iFakeBlockSize); + } + return iTotalSize; +} + Bu::Myriad::Stream *Bu::Myriad::findStream( int iId ) { for( StreamArray::iterator i = aStreams.begin(); i; i++ ) diff --git a/src/myriad.h b/src/myriad.h index 79c3cda..3d203bb 100644 --- a/src/myriad.h +++ b/src/myriad.h @@ -138,6 +138,9 @@ namespace Bu int getBlockSize(); int getNumBlocks(); int getNumUsedBlocks(); + int getTotalUsedBytes(); + int getTotalUnusedBytes(); + int getTotalUnusedBytes( int iFakeBlockSize ); /** * Syncronize the header data, etc. with the storage stream. It's not diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index c6a3a4d..b6e435d 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp @@ -22,6 +22,7 @@ enum Mode modeStreamNew, modeStreamDump, modeStreamPut, + modeStreamGet, modeNone }; @@ -43,9 +44,11 @@ public: addOption( eMode, 'n', "new", "Create a new sub-stream in a Myriad file."); addOption( eMode, 'd', "dump", - "Read a stream from a Myriad file."); + "Display a hexdump of a stream from a Myriad file."); + addOption( eMode, "get", + "Get a file out of a Myriad stream (use --dst)."); addOption( eMode, "put", - "Put a file into a Myriad stream."); + "Put a file into a Myriad stream (usr --src)."); addHelpOption(); addHelpBanner("\nGeneral options:"); @@ -55,12 +58,15 @@ public: addOption( sFile, 'f', "file", "Set the Myriad filename." ); addOption( iStream, 's', "stream", "Substream to work with."); addOption( sSrc, "src", "Source file for copying into a Myriad file."); + addOption( sDst, "dst", + "Destination file for copying out of a Myriad file."); setOverride( "create", modeCreate ); setOverride( "info", modeInfo ); setOverride( "new", modeStreamNew ); setOverride( "dump", modeStreamDump ); setOverride( "put", modeStreamPut ); + setOverride( "get", modeStreamGet ); parse( argc, argv ); } @@ -71,6 +77,7 @@ public: int iStream; Bu::FString sFile; Bu::FString sSrc; + Bu::FString sDst; }; Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) @@ -114,7 +121,10 @@ int main( int argc, char *argv[] ) << " Blocks used: " << m.getNumUsedBlocks() << " (" << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" << sio.nl - << " Stream count: " << m.getNumStreams() << sio.nl; + << " Stream count: " << m.getNumStreams() << sio.nl + << " Used space: " << m.getTotalUsedBytes() << sio.nl + << " Unused space: " << m.getTotalUnusedBytes() << sio.nl + << " % of files: " << (double)(m.getNumBlocks()*m.getBlockSize())/(double)(m.getTotalUsedBytes() + m.getTotalUnusedBytes( 4096 ))*100.0 << sio.nl; Bu::Array aStreams = m.getStreamIds(); sio << " Stream info:" << sio.nl; for( Bu::Array::iterator i = aStreams.begin(); i; i++ ) @@ -208,6 +218,30 @@ int main( int argc, char *argv[] ) } break; + case modeStreamGet: + if( !opts.sFile.isSet() ) + { + sio << "Please specify a file manipulate." << sio.nl; + return 0; + } + else if( !opts.sDst.isSet() ) + { + sio << "Please specify a destination file to write." << sio.nl; + } + else + { + File fIn( opts.sFile, File::Write|File::Read ); + Myriad m( fIn ); + MyriadStream sIn = m.openStream( opts.iStream ); + File fOut( opts.sDst, File::Write|File::Create|File::Truncate ); + char buf[1024]; + while( !sIn.isEos() ) + { + fOut.write( buf, sIn.read( buf, 1024 ) ); + } + } + break; + case modeNone: sio << "Please select a mode, for more info, try --help." << sio.nl << sio.nl; -- cgit v1.2.3