diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-28 07:12:35 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-28 07:12:35 +0000 |
commit | 4f59dec6bad120b72f1bc075715d79bfbe881f7e (patch) | |
tree | fa57c546474789d1154f0f70f303cf0b72ed3508 /src | |
parent | 67ec9d667ab0c3f2258f6f69308d0731e74a74d0 (diff) | |
download | libbu++-4f59dec6bad120b72f1bc075715d79bfbe881f7e.tar.gz libbu++-4f59dec6bad120b72f1bc075715d79bfbe881f7e.tar.bz2 libbu++-4f59dec6bad120b72f1bc075715d79bfbe881f7e.tar.xz libbu++-4f59dec6bad120b72f1bc075715d79bfbe881f7e.zip |
The nids tool now has a re-write and cleanup option, it can also change the
block size. Isn't that nifty?
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/nidstool.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tests/nidstool.cpp b/src/tests/nidstool.cpp index 1becba5..d1465ce 100644 --- a/src/tests/nidstool.cpp +++ b/src/tests/nidstool.cpp | |||
@@ -24,6 +24,8 @@ public: | |||
24 | "Dump a stream to a file."); | 24 | "Dump a stream to a file."); |
25 | addParam("analyze", 'a', mkproc(Param::procAnalyze), | 25 | addParam("analyze", 'a', mkproc(Param::procAnalyze), |
26 | "Analyze a nids file."); | 26 | "Analyze a nids file."); |
27 | addParam("copy", 'c', mkproc(Param::procCopy), | ||
28 | "Copy a nids file, changing settings."); | ||
27 | addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); | 29 | addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); |
28 | process( argc, argv ); | 30 | process( argc, argv ); |
29 | } | 31 | } |
@@ -185,6 +187,48 @@ public: | |||
185 | 187 | ||
186 | return 1; | 188 | return 1; |
187 | } | 189 | } |
190 | |||
191 | int procCopy( int argc, char *argv[] ) | ||
192 | { | ||
193 | if( argc < 3 ) | ||
194 | { | ||
195 | printf("You must provide source stream, blocksize, destination.\n"); | ||
196 | exit( 1 ); | ||
197 | } | ||
198 | |||
199 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
200 | Bu::Nids nIn( fIn ); | ||
201 | nIn.initialize(); | ||
202 | |||
203 | Bu::File fOut( argv[2], Bu::File::Read|Bu::File::Write|Bu::File::Create| | ||
204 | Bu::File::Truncate ); | ||
205 | Bu::Nids nOut( fOut ); | ||
206 | nOut.initialize( strtol( argv[1], 0, NULL ) ); | ||
207 | |||
208 | Block b; | ||
209 | for( int j = 0; j < nIn.getNumBlocks(); j++ ) | ||
210 | { | ||
211 | fIn.setPos( nIn.getBlockStart()+nIn.getBlockSize()*j ); | ||
212 | fIn.read( &b, sizeof(Block) ); | ||
213 | if( b.uFirstBlock != (uint32_t)j ) | ||
214 | continue; | ||
215 | |||
216 | Bu::NidsStream sIn = nIn.openStream( j ); | ||
217 | int iNew = nOut.createStream(); | ||
218 | Bu::NidsStream sOut = nOut.openStream( iNew ); | ||
219 | |||
220 | char buf[1024]; | ||
221 | for(;;) | ||
222 | { | ||
223 | int iRead = sIn.read( buf, 1024 ); | ||
224 | sOut.write( buf, iRead ); | ||
225 | if( iRead < 1024 ) | ||
226 | break; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | return 3; | ||
231 | } | ||
188 | }; | 232 | }; |
189 | 233 | ||
190 | 234 | ||