1 | /* 2 | fcfs_readobj.c 3 | ------------- 4 | 5 | reads an object from FCFS and writes it to stdout 6 | 7 | $Id: fcfs_readobj.c,v 1.2 2003/09/22 09:03:04 stewart Exp $ 8 | 9 | (C)2003 Stewart Smith 10 | Distributed under the GPL 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <sys/stat.h> 16 | #include <unistd.h> 17 | #include <fcntl.h> 18 | #include <string.h> 19 | #include <time.h> 20 | 21 | 22 | #include "testkit/block_dev.h" 23 | #include "testkit/types.h" 24 | #include "testkit/bitops.h" 25 | #include "disk.h" 26 | 27 | #include "super_block.h" 28 | #include "onode.h" 29 | #include "onode_index.h" 30 | #include "space_bitmap.h" 31 | #include "fcfs_vfs.h" 32 | 33 | #define EXPERIMENTAL 34 | 35 | int main(int argc, char* argv[]) 36 | { 37 | struct fcfs_disk* disk; 38 | struct fcfs_onode_index* index; 39 | int i; 40 | struct fcfs_disk_block *onode_block; 41 | struct fcfs_onode1 *onode; 42 | struct fcfs_block_run onode_br; 43 | int forknr; 44 | char *data; int j; 45 | int infile; 46 | u64 rlen, len; 47 | struct fcfs_block *b; 48 | 49 | data = (char*)malloc(50000); 50 | 51 | if(argc<3) 52 | { 53 | fprintf(stderr,"fcfs_readobj\n"); 54 | fprintf(stderr,"-----------\n"); 55 | fprintf(stderr,"$Id: fcfs_readobj.c,v 1.2 2003/09/22 09:03:04 stewart Exp $\n"); 56 | fprintf(stderr,"Usage:\n"); 57 | fprintf(stderr,"\t%s volume objid\n\n",argv[0]); 58 | exit(1); 59 | } 60 | 61 | disk = fcfs_mount(argv[1]); 62 | 63 | index = onode_index_read(disk); 64 | 65 | onode_block = onode_index_lookup(index, &onode_br,atoi(argv[2])); 66 | onode = (struct fcfs_onode1*)onode_block->data; 67 | 68 | for(rlen = 0; (len=onode1_fork_read(disk,onode,1,rlen,1000,data)) && len>0;rlen+=len) 69 | write(1,data,len); 70 | 71 | disk_freeblock(onode_block); 72 | fcfs_umount(disk); 73 | 74 | return 0; 75 | }