Commit | Line | Data |
---|---|---|
a66ab591 | 1 | static char sccsid[] = "@(#)clri.c 2.3 %G%"; |
be79e615 | 2 | |
e335baf5 | 3 | /* static char *sccsid = "@(#)clri.c 4.1 (Berkeley) 10/1/80"; */ |
45eb394d | 4 | |
be79e615 KM |
5 | /* |
6 | * clri filsys inumber ... | |
7 | */ | |
8 | ||
45eb394d KM |
9 | #ifndef SIMFS |
10 | #include <sys/param.h> | |
11 | #include <sys/inode.h> | |
12 | #include <sys/fs.h> | |
13 | #else | |
e335baf5 KM |
14 | #include "../h/param.h" |
15 | #include "../h/inode.h" | |
16 | #include "../h/fs.h" | |
45eb394d | 17 | #endif |
be79e615 KM |
18 | |
19 | #define ISIZE (sizeof(struct dinode)) | |
e335baf5 KM |
20 | #define NI (MAXBSIZE/ISIZE) |
21 | struct ino { | |
be79e615 KM |
22 | char junk[ISIZE]; |
23 | }; | |
24 | struct ino buf[NI]; | |
e335baf5 KM |
25 | |
26 | union { | |
27 | char dummy[SBSIZE]; | |
28 | struct fs sblk; | |
29 | } sb_un; | |
30 | #define sblock sb_un.sblk | |
31 | ||
be79e615 | 32 | int status; |
a66ab591 | 33 | long dev_bsize = 1; |
be79e615 KM |
34 | |
35 | main(argc, argv) | |
e335baf5 KM |
36 | int argc; |
37 | char *argv[]; | |
be79e615 KM |
38 | { |
39 | register i, f; | |
40 | unsigned n; | |
41 | int j, k; | |
42 | long off; | |
43 | ||
e335baf5 | 44 | if (argc < 3) { |
be79e615 KM |
45 | printf("usage: clri filsys inumber ...\n"); |
46 | exit(4); | |
47 | } | |
48 | f = open(argv[1], 2); | |
e335baf5 | 49 | if (f < 0) { |
be79e615 KM |
50 | printf("cannot open %s\n", argv[1]); |
51 | exit(4); | |
52 | } | |
a66ab591 | 53 | lseek(f, SBOFF, 0); |
e335baf5 KM |
54 | if (read(f, &sblock, SBSIZE) != SBSIZE) { |
55 | printf("cannot read %s\n", argv[1]); | |
56 | exit(4); | |
57 | } | |
87ad4e58 KM |
58 | if (sblock.fs_magic != FS_MAGIC) { |
59 | printf("bad super block magic number\n"); | |
60 | exit(4); | |
61 | } | |
a66ab591 | 62 | dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); |
e335baf5 KM |
63 | for (i = 2; i < argc; i++) { |
64 | if (!isnumber(argv[i])) { | |
be79e615 KM |
65 | printf("%s: is not a number\n", argv[i]); |
66 | status = 1; | |
67 | continue; | |
68 | } | |
69 | n = atoi(argv[i]); | |
e335baf5 | 70 | if (n == 0) { |
be79e615 KM |
71 | printf("%s: is zero\n", argv[i]); |
72 | status = 1; | |
73 | continue; | |
74 | } | |
a66ab591 | 75 | off = fsbtodb(&sblock, itod(&sblock, n)) * dev_bsize; |
be79e615 | 76 | lseek(f, off, 0); |
e335baf5 | 77 | if (read(f, (char *)buf, sblock.fs_bsize) != sblock.fs_bsize) { |
be79e615 KM |
78 | printf("%s: read error\n", argv[i]); |
79 | status = 1; | |
80 | } | |
81 | } | |
e335baf5 | 82 | if (status) |
be79e615 | 83 | exit(status); |
e335baf5 | 84 | for (i = 2; i < argc; i++) { |
be79e615 KM |
85 | n = atoi(argv[i]); |
86 | printf("clearing %u\n", n); | |
a66ab591 | 87 | off = fsbtodb(&sblock, itod(&sblock, n)) * dev_bsize; |
be79e615 | 88 | lseek(f, off, 0); |
e335baf5 | 89 | read(f, (char *)buf, sblock.fs_bsize); |
6994bf5d | 90 | j = itoo(&sblock, n); |
e335baf5 | 91 | for (k = 0; k < ISIZE; k++) |
be79e615 KM |
92 | buf[j].junk[k] = 0; |
93 | lseek(f, off, 0); | |
e335baf5 | 94 | write(f, (char *)buf, sblock.fs_bsize); |
be79e615 KM |
95 | } |
96 | exit(status); | |
97 | } | |
98 | ||
99 | isnumber(s) | |
e335baf5 | 100 | char *s; |
be79e615 KM |
101 | { |
102 | register c; | |
103 | ||
104 | while(c = *s++) | |
e335baf5 | 105 | if (c < '0' || c > '9') |
be79e615 KM |
106 | return(0); |
107 | return(1); | |
108 | } |