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