open-source-search-engine/rescue.cpp

43 lines
1.0 KiB
C++
Raw Normal View History

2013-08-03 00:12:24 +04:00
// Matt Wells, copyright Apr 2002
// program to rescue data from a core and save it as coreSeg.offset.size
#include "gb-include.h"
#include "File.h"
int main ( int argc , char *argv[] ) {
// must have big filename
if ( argc != 4 ) {
fprintf(stderr,"rescure [corefile] [offset] [size]\n");
exit(-1);
}
2014-11-11 01:45:11 +03:00
int32_t coreOffset = atol(argv[2]);
int32_t coreSize = atol(argv[3]);
2013-08-03 00:12:24 +04:00
File f;
f.set ( argv[1] );
if ( ! f.open ( O_RDONLY ) ) {
fprintf(stderr,"could not open core file %s", argv[1] );
exit(-1);
}
// read whole file into memory
char *buf = (char *) malloc ( coreSize );
if ( ! buf ) {
2014-11-11 01:45:11 +03:00
fprintf(stderr,"could not alloc %"INT32" bytes", coreSize );
2013-08-03 00:12:24 +04:00
exit(-1);
}
if ( f.read ( buf , coreSize , coreOffset ) < 0 ) {
2014-11-11 01:45:11 +03:00
fprintf(stderr,"could not read %"INT32" bytes", coreSize );
2013-08-03 00:12:24 +04:00
exit(-1);
}
// now dump to separate file
f.close();
char name[64];
2014-11-11 01:45:11 +03:00
sprintf(name,"coreSeg.%"INT32".%"INT32"", coreOffset, coreSize );
2013-08-03 00:12:24 +04:00
f.set ( name );
f.open ( O_RDWR );
f.write ( buf , coreSize );
f.flush();
}