diff options
Diffstat (limited to '')
| -rw-r--r-- | src/myriad.cpp | 30 | ||||
| -rw-r--r-- | src/myriad.h | 3 | ||||
| -rw-r--r-- | src/tools/myriad.cpp | 40 |
3 files changed, 70 insertions, 3 deletions
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() | |||
| 510 | return iUsed; | 510 | return iUsed; |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | int Bu::Myriad::getTotalUsedBytes() | ||
| 514 | { | ||
| 515 | int iTotalSize = 0; | ||
| 516 | for( StreamArray::iterator i = aStreams.begin(); i; i++ ) | ||
| 517 | { | ||
| 518 | iTotalSize += (*i)->iSize; | ||
| 519 | } | ||
| 520 | return iTotalSize; | ||
| 521 | } | ||
| 522 | |||
| 523 | int Bu::Myriad::getTotalUnusedBytes() | ||
| 524 | { | ||
| 525 | int iTotalSize = (iBlocks-iUsed)*iBlockSize; | ||
| 526 | for( StreamArray::iterator i = aStreams.begin(); i; i++ ) | ||
| 527 | { | ||
| 528 | iTotalSize += iBlockSize - ((*i)->iSize%iBlockSize); | ||
| 529 | } | ||
| 530 | return iTotalSize; | ||
| 531 | } | ||
| 532 | |||
| 533 | int Bu::Myriad::getTotalUnusedBytes( int iFakeBlockSize ) | ||
| 534 | { | ||
| 535 | int iTotalSize = (iBlocks-iUsed)*iFakeBlockSize; | ||
| 536 | for( StreamArray::iterator i = aStreams.begin(); i; i++ ) | ||
| 537 | { | ||
| 538 | iTotalSize += iFakeBlockSize - ((*i)->iSize%iFakeBlockSize); | ||
| 539 | } | ||
| 540 | return iTotalSize; | ||
| 541 | } | ||
| 542 | |||
| 513 | Bu::Myriad::Stream *Bu::Myriad::findStream( int iId ) | 543 | Bu::Myriad::Stream *Bu::Myriad::findStream( int iId ) |
| 514 | { | 544 | { |
| 515 | for( StreamArray::iterator i = aStreams.begin(); i; i++ ) | 545 | 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 | |||
| 138 | int getBlockSize(); | 138 | int getBlockSize(); |
| 139 | int getNumBlocks(); | 139 | int getNumBlocks(); |
| 140 | int getNumUsedBlocks(); | 140 | int getNumUsedBlocks(); |
| 141 | int getTotalUsedBytes(); | ||
| 142 | int getTotalUnusedBytes(); | ||
| 143 | int getTotalUnusedBytes( int iFakeBlockSize ); | ||
| 141 | 144 | ||
| 142 | /** | 145 | /** |
| 143 | * Syncronize the header data, etc. with the storage stream. It's not | 146 | * 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 | |||
| 22 | modeStreamNew, | 22 | modeStreamNew, |
| 23 | modeStreamDump, | 23 | modeStreamDump, |
| 24 | modeStreamPut, | 24 | modeStreamPut, |
| 25 | modeStreamGet, | ||
| 25 | 26 | ||
| 26 | modeNone | 27 | modeNone |
| 27 | }; | 28 | }; |
| @@ -43,9 +44,11 @@ public: | |||
| 43 | addOption( eMode, 'n', "new", | 44 | addOption( eMode, 'n', "new", |
| 44 | "Create a new sub-stream in a Myriad file."); | 45 | "Create a new sub-stream in a Myriad file."); |
| 45 | addOption( eMode, 'd', "dump", | 46 | addOption( eMode, 'd', "dump", |
| 46 | "Read a stream from a Myriad file."); | 47 | "Display a hexdump of a stream from a Myriad file."); |
| 48 | addOption( eMode, "get", | ||
| 49 | "Get a file out of a Myriad stream (use --dst)."); | ||
| 47 | addOption( eMode, "put", | 50 | addOption( eMode, "put", |
| 48 | "Put a file into a Myriad stream."); | 51 | "Put a file into a Myriad stream (usr --src)."); |
| 49 | addHelpOption(); | 52 | addHelpOption(); |
| 50 | 53 | ||
| 51 | addHelpBanner("\nGeneral options:"); | 54 | addHelpBanner("\nGeneral options:"); |
| @@ -55,12 +58,15 @@ public: | |||
| 55 | addOption( sFile, 'f', "file", "Set the Myriad filename." ); | 58 | addOption( sFile, 'f', "file", "Set the Myriad filename." ); |
| 56 | addOption( iStream, 's', "stream", "Substream to work with."); | 59 | addOption( iStream, 's', "stream", "Substream to work with."); |
| 57 | addOption( sSrc, "src", "Source file for copying into a Myriad file."); | 60 | addOption( sSrc, "src", "Source file for copying into a Myriad file."); |
| 61 | addOption( sDst, "dst", | ||
| 62 | "Destination file for copying out of a Myriad file."); | ||
| 58 | 63 | ||
| 59 | setOverride( "create", modeCreate ); | 64 | setOverride( "create", modeCreate ); |
| 60 | setOverride( "info", modeInfo ); | 65 | setOverride( "info", modeInfo ); |
| 61 | setOverride( "new", modeStreamNew ); | 66 | setOverride( "new", modeStreamNew ); |
| 62 | setOverride( "dump", modeStreamDump ); | 67 | setOverride( "dump", modeStreamDump ); |
| 63 | setOverride( "put", modeStreamPut ); | 68 | setOverride( "put", modeStreamPut ); |
| 69 | setOverride( "get", modeStreamGet ); | ||
| 64 | 70 | ||
| 65 | parse( argc, argv ); | 71 | parse( argc, argv ); |
| 66 | } | 72 | } |
| @@ -71,6 +77,7 @@ public: | |||
| 71 | int iStream; | 77 | int iStream; |
| 72 | Bu::FString sFile; | 78 | Bu::FString sFile; |
| 73 | Bu::FString sSrc; | 79 | Bu::FString sSrc; |
| 80 | Bu::FString sDst; | ||
| 74 | }; | 81 | }; |
| 75 | 82 | ||
| 76 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) | 83 | Bu::Formatter &operator>>( Bu::Formatter &f, Mode &e ) |
| @@ -114,7 +121,10 @@ int main( int argc, char *argv[] ) | |||
| 114 | << " Blocks used: " << m.getNumUsedBlocks() << " (" | 121 | << " Blocks used: " << m.getNumUsedBlocks() << " (" |
| 115 | << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" | 122 | << m.getNumUsedBlocks()*100/m.getNumBlocks() << "%)" |
| 116 | << sio.nl | 123 | << sio.nl |
| 117 | << " Stream count: " << m.getNumStreams() << sio.nl; | 124 | << " Stream count: " << m.getNumStreams() << sio.nl |
| 125 | << " Used space: " << m.getTotalUsedBytes() << sio.nl | ||
| 126 | << " Unused space: " << m.getTotalUnusedBytes() << sio.nl | ||
| 127 | << " % of files: " << (double)(m.getNumBlocks()*m.getBlockSize())/(double)(m.getTotalUsedBytes() + m.getTotalUnusedBytes( 4096 ))*100.0 << sio.nl; | ||
| 118 | Bu::Array<int> aStreams = m.getStreamIds(); | 128 | Bu::Array<int> aStreams = m.getStreamIds(); |
| 119 | sio << " Stream info:" << sio.nl; | 129 | sio << " Stream info:" << sio.nl; |
| 120 | for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) | 130 | for( Bu::Array<int>::iterator i = aStreams.begin(); i; i++ ) |
| @@ -208,6 +218,30 @@ int main( int argc, char *argv[] ) | |||
| 208 | } | 218 | } |
| 209 | break; | 219 | break; |
| 210 | 220 | ||
| 221 | case modeStreamGet: | ||
| 222 | if( !opts.sFile.isSet() ) | ||
| 223 | { | ||
| 224 | sio << "Please specify a file manipulate." << sio.nl; | ||
| 225 | return 0; | ||
| 226 | } | ||
| 227 | else if( !opts.sDst.isSet() ) | ||
| 228 | { | ||
| 229 | sio << "Please specify a destination file to write." << sio.nl; | ||
| 230 | } | ||
| 231 | else | ||
| 232 | { | ||
| 233 | File fIn( opts.sFile, File::Write|File::Read ); | ||
| 234 | Myriad m( fIn ); | ||
| 235 | MyriadStream sIn = m.openStream( opts.iStream ); | ||
| 236 | File fOut( opts.sDst, File::Write|File::Create|File::Truncate ); | ||
| 237 | char buf[1024]; | ||
| 238 | while( !sIn.isEos() ) | ||
| 239 | { | ||
| 240 | fOut.write( buf, sIn.read( buf, 1024 ) ); | ||
| 241 | } | ||
| 242 | } | ||
| 243 | break; | ||
| 244 | |||
| 211 | case modeNone: | 245 | case modeNone: |
| 212 | sio << "Please select a mode, for more info, try --help." | 246 | sio << "Please select a mode, for more info, try --help." |
| 213 | << sio.nl << sio.nl; | 247 | << sio.nl << sio.nl; |
