| ---
tfmtisect.c (1455B)
---
1 #include "stdinc.h"
2 #include "dat.h"
3 #include "fns.h"
4
5 void
6 usage(void)
7 {
8 fprint(2, "usage: fmtisect [-1Z] [-b blocksize] name file\n");
9 threadexitsall(0);
10 }
11
12 void
13 threadmain(int argc, char *argv[])
14 {
15 int vers;
16 ISect *is;
17 Part *part;
18 char *file, *name;
19 int blocksize, setsize, zero;
20
21 ventifmtinstall();
22 statsinit();
23
24 blocksize = 8 * 1024;
25 setsize = 512 * 1024;
26 zero = -1;
27 vers = ISectVersion2;
28 ARGBEGIN{
29 case 'b':
30 blocksize = unittoull(ARGF());
31 if(blocksize == ~0)
32 usage();
33 if(blocksize > MaxDiskBlock){
34 fprint(2, "block size too large, max %d\n", MaxDiskBlock);
35 threadexitsall("usage");
36 }
37 break;
38 case '1':
39 vers = ISectVersion1;
40 break;
41 case 'Z':
42 zero = 0;
43 break;
44 default:
45 usage();
46 break;
47 }ARGEND
48
49 if(zero == -1){
50 if(vers == ISectVersion1)
51 zero = 1;
52 else
53 zero = 0;
54 }
55
56 if(argc != 2)
57 usage();
58
59 name = argv[0];
60 file = argv[1];
61
62 if(nameok(name) < 0)
63 sysfatal("illegal name %s", name);
64
65 part = initpart(file, ORDWR|ODIRECT);
66 if(part == nil)
67 sysfatal("can't open partition %s: %r", file);
68
69 if(zero)
70 zeropart(part, blocksize);
71
72 is = newisect(part, vers, name, blocksize, setsize);
73 if(is == nil)
74 sysfatal("can't initialize new index: %r");
75
76 fprint(2, "fmtisect %s: %,d buckets of %,d entries, %,d bytes for index map\n",
77 file, is->blocks, is->buckmax, setsize);
78
79 if(wbisect(is) < 0)
80 fprint(2, "can't write back index section header for %s: %r\n", file);
81
82 threadexitsall(0);
83 } |