#include #include #include #include extern char * malloc(); #define BLOCK_SIZE (512 * 64) int main( argc, argv) int argc; char ** argv; { long start; int len, fd, stuff_read; char * device_name, * buf; char command[ 80]; if( argv[ 1]) { device_name = argv[ 1]; } else { fprintf( stderr, "usage: %s \n", argv[ 0]); exit( 1); } if( !(buf = malloc( BLOCK_SIZE))) { fprintf( stderr, "%s: ", argv[ 0]); perror( device_name); exit( 1); } if( (fd = open( device_name, O_RDONLY)) < 0) { fprintf( stderr, "%s: ", argv[ 0]); perror( device_name); exit( 1); } while( fgets( command, 80, stdin)) { sscanf( command, "%ld %d", &start, &len); if( lseek( fd, start, SEEK_SET) < 0) { fprintf( stderr, "%s: ", argv[ 0]); perror( device_name); exit( 1); } stuff_read = 0; while( stuff_read < len) { int amount_to_read; amount_to_read = ((len - stuff_read) < BLOCK_SIZE) ? (len - stuff_read) : BLOCK_SIZE; if( read( fd, buf, amount_to_read) < 0) { fprintf( stderr, "%s: ", argv[ 0]); perror( device_name); exit( 1); } write( 1, buf, amount_to_read); stuff_read += amount_to_read; } } close( fd); return( 0); }