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