1: static char sccsid[] = "@(#)clri.c 2.2 4/11/82";
   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: 
  34: main(argc, argv)
  35:     int argc;
  36:     char *argv[];
  37: {
  38:     register i, f;
  39:     unsigned n;
  40:     int j, k;
  41:     long off;
  42: 
  43:     if (argc < 3) {
  44:         printf("usage: clri filsys inumber ...\n");
  45:         exit(4);
  46:     }
  47:     f = open(argv[1], 2);
  48:     if (f < 0) {
  49:         printf("cannot open %s\n", argv[1]);
  50:         exit(4);
  51:     }
  52:     lseek(f, SBLOCK * DEV_BSIZE, 0);
  53:     if (read(f, &sblock, SBSIZE) != SBSIZE) {
  54:         printf("cannot read %s\n", argv[1]);
  55:         exit(4);
  56:     }
  57:     if (sblock.fs_magic != FS_MAGIC) {
  58:         printf("bad super block magic number\n");
  59:         exit(4);
  60:     }
  61:     for (i = 2; i < argc; i++) {
  62:         if (!isnumber(argv[i])) {
  63:             printf("%s: is not a number\n", argv[i]);
  64:             status = 1;
  65:             continue;
  66:         }
  67:         n = atoi(argv[i]);
  68:         if (n == 0) {
  69:             printf("%s: is zero\n", argv[i]);
  70:             status = 1;
  71:             continue;
  72:         }
  73:         off = fsbtodb(&sblock, itod(&sblock, n)) * DEV_BSIZE;
  74:         lseek(f, off, 0);
  75:         if (read(f, (char *)buf, sblock.fs_bsize) != sblock.fs_bsize) {
  76:             printf("%s: read error\n", argv[i]);
  77:             status = 1;
  78:         }
  79:     }
  80:     if (status)
  81:         exit(status);
  82:     for (i = 2; i < argc; i++) {
  83:         n = atoi(argv[i]);
  84:         printf("clearing %u\n", n);
  85:         off = fsbtodb(&sblock, itod(&sblock, n)) * DEV_BSIZE;
  86:         lseek(f, off, 0);
  87:         read(f, (char *)buf, sblock.fs_bsize);
  88:         j = itoo(&sblock, n);
  89:         for (k = 0; k < ISIZE; k++)
  90:             buf[j].junk[k] = 0;
  91:         lseek(f, off, 0);
  92:         write(f, (char *)buf, sblock.fs_bsize);
  93:     }
  94:     exit(status);
  95: }
  96: 
  97: isnumber(s)
  98:     char *s;
  99: {
 100:     register c;
 101: 
 102:     while(c = *s++)
 103:         if (c < '0' || c > '9')
 104:             return(0);
 105:     return(1);
 106: }

Defined functions

isnumber defined in line 97; used 1 times
  • in line 62
main defined in line 34; never used

Defined variables

buf defined in line 24; used 4 times
sccsid defined in line 1; never used
status defined in line 32; used 6 times

Defined struct's

ino defined in line 21; used 2 times
  • in line 24(2)

Defined macros

ISIZE defined in line 19; used 3 times
NI defined in line 20; used 1 times
  • in line 24
sblock defined in line 30; used 11 times
Last modified: 1982-06-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1147
Valid CSS Valid XHTML 1.0 Strict