1    | /*
2    |   fcfs_newobj.c
3    |   -------------
4    |   
5    |   Program that inserts an object onto an FCFS volume
6    |   from a unix file.
7    | 
8    |   $Id: fcfs_newobj.c,v 1.5 2003/10/20 07:18:11 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_newobj.c,v 1.5 2003/10/20 07:18:11 stewart Exp $\n");
47   |       fprintf(stderr,"Usage:\n");
48   |       fprintf(stderr,"\t%s volume file [file2...]\n\n",argv[0]);
49   |       exit(1);
50   |     }
51   | 
52   |   disk = fcfs_mount(argv[1]);
53   | 
54   |   index = onode_index_read(disk);
55   |   for(i=2;i<argc;i++)
56   |   {
57   |     struct fcfs_onode1 *node;
58   |     struct fcfs_block_run *onode_br;
59   |     int forknr;
60   |     char data[8200]; int j;
61   |     int infile;
62   |     int rlen;
63   |     struct stat statbuf;
64   | 
65   |     node = onode1_new(disk);
66   |     onode_br = onode_index_insert(index,node);
67   | 
68   |     infile = open(argv[i],O_RDONLY);
69   |     fstat(infile,&statbuf);
70   | 
71   |     /* UNIX source File name fork  */
72   |     onode1_fork_new(disk,onode_br,0x42,strlen(argv[i]),argv[i],1);
73   | 
74   |     /* Current revision fork */
75   |     forknr = onode1_fork_new(disk,onode_br,0x69,statbuf.st_size,NULL,0);
76   |     onode1_fork_new(disk,onode_br,0x6A,0,NULL,0); /* Revision history fork */
77   |     onode1_fork_new(disk,onode_br,0x6B,0,NULL,0); /* Revision history data fork */
78   | 
79   |     fprintf(stderr,"%s in fork %d\n",argv[i],forknr);
80   | 
81   |     j=0;
82   |     while(0 < (rlen = read(infile,data,8192)))
83   |       {	
84   | 	//	fprintf(stderr,"*******WRITING %d bytes*******\n",rlen);
85   | 	onode1_fork_write(disk,onode_br,forknr,j,(u64)rlen,data);
86   | 	j+=rlen;
87   |       }
88   |     close(infile);
89   |     free(node);
90   |     free(onode_br);
91   |   }  
92   |   
93   |   fcfs_umount(disk);
94   | 
95   |   return 0;
96   | }