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