1    | /*
2    |   fcfs_updateobj.c
3    |   -------------
4    |   
5    |   Real nasty stuff that tries to do updates to objects.
6    |   I'm quaking in my boots doing this kinda stuff.
7    | 
8    |   $Id: fcfs_updateobj.c,v 1.1 2003/09/30 12:56:25 stewart Exp $
9    |   
10   |   (C)2003 Stewart Smith
11   |   Distributed under the GPL
12   | */
13   | 
14   | #include <stdio.h>
15   | #include <stdlib.h>
16   | #include <sys/stat.h>
17   | #include <unistd.h>
18   | #include <fcntl.h>
19   | #include <string.h>
20   | #include <time.h>
21   | 
22   | 
23   | #include "testkit/block_dev.h"
24   | #include "testkit/types.h"
25   | #include "testkit/bitops.h"
26   | #include "disk.h"
27   | 
28   | #include "super_block.h"
29   | #include "onode.h"
30   | #include "onode_index.h"
31   | #include "space_bitmap.h"
32   | #include "fcfs_vfs.h"
33   | 
34   | #define EXPERIMENTAL
35   | 
36   | int main(int argc, char* argv[])
37   | {
38   |   struct fcfs_disk* disk;
39   |   struct fcfs_onode_index* index;
40   |   int i;
41   | 
42   |   if(argc<3)
43   |     {
44   |       fprintf(stderr,"fcfs_newobj\n");
45   |       fprintf(stderr,"-----------\n");
46   |       fprintf(stderr,"$Id: fcfs_updateobj.c,v 1.1 2003/09/30 12:56:25 stewart Exp $\n");
47   |       fprintf(stderr,"Usage:\n");
48   |       fprintf(stderr,"\t%s volume file offset length onode_id\n\n",argv[0]);
49   |       exit(1);
50   |     }
51   | 
52   |   disk = fcfs_mount(argv[1]);
53   | 
54   |   index = onode_index_read(disk);
55   | 
56   |   {
57   |     struct fcfs_onode1 *onode;
58   |     struct fcfs_disk_block *onode_block;
59   |     struct fcfs_block_run onode_br;
60   |     char *data; int j;
61   |     int infile;
62   |     int rlen;
63   |     struct stat statbuf;
64   | 
65   |     onode_block = onode_index_lookup(index, &onode_br,atoi(argv[5]));
66   |     onode = (struct fcfs_onode1*)onode_block->data;
67   | 
68   |     infile = open(argv[2],O_RDONLY);
69   |     fstat(infile,&statbuf);
70   |     lseek(infile,atoi(argv[3]),SEEK_SET);
71   | 
72   |     fprintf(stderr,"+++++++GOING TO GO AND WRITE %s++++++++\n",argv[3]);
73   | 
74   |     data = (char*)malloc(sizeof(char)*atoi(argv[4]));
75   | 
76   |     j=0;
77   |     rlen = read(infile,data,atoi(argv[4]));
78   |     fprintf(stderr,"*******WRITING %d bytes*******\n",rlen);
79   |     onode1_fork_write_versioned(disk,onode,&onode_br,1,atoi(argv[3]),(u64)rlen,data);
80   |     
81   |     close(infile);
82   |     free(onode);
83   |     free(data);
84   |   }  
85   |   
86   |   fcfs_umount(disk);
87   | 
88   |   return 0;
89   | }