Commit | Line | Data |
---|---|---|
3b600ead TL |
1 | /* |
2 | * clri filsys inumber ... | |
3 | */ | |
4 | ||
5 | #include <sys/types.h> | |
6 | #include <sys/ino.h> | |
7 | #define ISIZE (sizeof(struct dinode)) | |
8 | #define BSIZE 512 | |
9 | #define NI (BSIZE/ISIZE) | |
10 | struct ino | |
11 | { | |
12 | char junk[ISIZE]; | |
13 | }; | |
14 | struct ino buf[NI]; | |
15 | int status; | |
16 | ||
17 | main(argc, argv) | |
18 | char *argv[]; | |
19 | { | |
20 | register i, f; | |
21 | unsigned n; | |
22 | int j, k; | |
23 | long off; | |
24 | ||
25 | if(argc < 3) { | |
26 | printf("usage: clri filsys inumber ...\n"); | |
27 | exit(4); | |
28 | } | |
29 | f = open(argv[1], 2); | |
30 | if(f < 0) { | |
31 | printf("cannot open %s\n", argv[1]); | |
32 | exit(4); | |
33 | } | |
34 | for(i=2; i<argc; i++) { | |
35 | if(!isnumber(argv[i])) { | |
36 | printf("%s: is not a number\n", argv[i]); | |
37 | status = 1; | |
38 | continue; | |
39 | } | |
40 | n = atoi(argv[i]); | |
41 | if(n == 0) { | |
42 | printf("%s: is zero\n", argv[i]); | |
43 | status = 1; | |
44 | continue; | |
45 | } | |
46 | off = ((n-1)/NI + 2) * (long)512; | |
47 | lseek(f, off, 0); | |
48 | if(read(f, (char *)buf, BSIZE) != BSIZE) { | |
49 | printf("%s: read error\n", argv[i]); | |
50 | status = 1; | |
51 | } | |
52 | } | |
53 | if(status) | |
54 | exit(status); | |
55 | for(i=2; i<argc; i++) { | |
56 | n = atoi(argv[i]); | |
57 | printf("clearing %u\n", n); | |
58 | off = ((n-1)/NI + 2) * (long)512; | |
59 | lseek(f, off, 0); | |
60 | read(f, (char *)buf, BSIZE); | |
61 | j = (n-1)%NI; | |
62 | for(k=0; k<ISIZE; k++) | |
63 | buf[j].junk[k] = 0; | |
64 | lseek(f, off, 0); | |
65 | write(f, (char *)buf, BSIZE); | |
66 | } | |
67 | exit(status); | |
68 | } | |
69 | ||
70 | isnumber(s) | |
71 | char *s; | |
72 | { | |
73 | register c; | |
74 | ||
75 | while(c = *s++) | |
76 | if(c < '0' || c > '9') | |
77 | return(0); | |
78 | return(1); | |
79 | } |