convert to new file system format
authorKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Thu, 7 Jan 1982 15:31:57 +0000 (07:31 -0800)
committerKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Thu, 7 Jan 1982 15:31:57 +0000 (07:31 -0800)
SCCS-vsn: sbin/clri/clri.c 1.2

usr/src/sbin/clri/clri.c

index af3f87d..2603b55 100644 (file)
@@ -1,84 +1,97 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-static char sccsid[] = "@(#)clri.c 1.1 %G%";
+static char sccsid[] = "@(#)clri.c 1.2 %G%";
 
 
-static char *sccsid = "@(#)clri.c      4.1 (Berkeley) 10/1/80";
+/* static char *sccsid = "@(#)clri.c   4.1 (Berkeley) 10/1/80"; */
 /*
  * clri filsys inumber ...
  */
 
 /*
  * clri filsys inumber ...
  */
 
-#include <sys/param.h>
-#include <sys/ino.h>
+#include "../h/param.h"
+#include "../h/inode.h"
+#include "../h/fs.h"
 
 #define ISIZE  (sizeof(struct dinode))
 
 #define ISIZE  (sizeof(struct dinode))
-#define        NI      (BSIZE/ISIZE)
-struct ino
-{
+#define        NI      (MAXBSIZE/ISIZE)
+struct ino {
        char    junk[ISIZE];
 };
 struct ino     buf[NI];
        char    junk[ISIZE];
 };
 struct ino     buf[NI];
+
+union {
+       char            dummy[SBSIZE];
+       struct fs       sblk;
+} sb_un;
+#define sblock sb_un.sblk
+
 int    status;
 
 main(argc, argv)
 int    status;
 
 main(argc, argv)
-char *argv[];
+       int argc;
+       char *argv[];
 {
        register i, f;
        unsigned n;
        int j, k;
        long off;
 
 {
        register i, f;
        unsigned n;
        int j, k;
        long off;
 
-       if(argc < 3) {
+       if (argc < 3) {
                printf("usage: clri filsys inumber ...\n");
                exit(4);
        }
        f = open(argv[1], 2);
                printf("usage: clri filsys inumber ...\n");
                exit(4);
        }
        f = open(argv[1], 2);
-       if(f < 0) {
+       if (f < 0) {
                printf("cannot open %s\n", argv[1]);
                exit(4);
        }
                printf("cannot open %s\n", argv[1]);
                exit(4);
        }
-       for(i=2; i<argc; i++) {
-               if(!isnumber(argv[i])) {
+       lseek(f, SBLOCK * DEV_BSIZE, 0);
+       if (read(f, &sblock, SBSIZE) != SBSIZE) {
+               printf("cannot read %s\n", argv[1]);
+               exit(4);
+       }
+       for (i = 2; i < argc; i++) {
+               if (!isnumber(argv[i])) {
                        printf("%s: is not a number\n", argv[i]);
                        status = 1;
                        continue;
                }
                n = atoi(argv[i]);
                        printf("%s: is not a number\n", argv[i]);
                        status = 1;
                        continue;
                }
                n = atoi(argv[i]);
-               if(n == 0) {
+               if (n == 0) {
                        printf("%s: is zero\n", argv[i]);
                        status = 1;
                        continue;
                }
                        printf("%s: is zero\n", argv[i]);
                        status = 1;
                        continue;
                }
-               off = itod(n) * BSIZE;
+               off = fsbtodb(&sblock, itod(n, &sblock)) * DEV_BSIZE;
                lseek(f, off, 0);
                lseek(f, off, 0);
-               if(read(f, (char *)buf, BSIZE) != BSIZE) {
+               if (read(f, (char *)buf, sblock.fs_bsize) != sblock.fs_bsize) {
                        printf("%s: read error\n", argv[i]);
                        status = 1;
                }
        }
                        printf("%s: read error\n", argv[i]);
                        status = 1;
                }
        }
-       if(status)
+       if (status)
                exit(status);
                exit(status);
-       for(i=2; i<argc; i++) {
+       for (i = 2; i < argc; i++) {
                n = atoi(argv[i]);
                printf("clearing %u\n", n);
                n = atoi(argv[i]);
                printf("clearing %u\n", n);
-               off = itod(n) * BSIZE;
+               off = fsbtodb(&sblock, itod(n, &sblock)) * DEV_BSIZE;
                lseek(f, off, 0);
                lseek(f, off, 0);
-               read(f, (char *)buf, BSIZE);
-               j = itoo(n);
-               for(k=0; k<ISIZE; k++)
+               read(f, (char *)buf, sblock.fs_bsize);
+               j = itoo(n, &sblock);
+               for (k = 0; k < ISIZE; k++)
                        buf[j].junk[k] = 0;
                lseek(f, off, 0);
                        buf[j].junk[k] = 0;
                lseek(f, off, 0);
-               write(f, (char *)buf, BSIZE);
+               write(f, (char *)buf, sblock.fs_bsize);
        }
        exit(status);
 }
 
 isnumber(s)
        }
        exit(status);
 }
 
 isnumber(s)
-char *s;
+       char *s;
 {
        register c;
 
        while(c = *s++)
 {
        register c;
 
        while(c = *s++)
-               if(c < '0' || c > '9')
+               if (c < '0' || c > '9')
                        return(0);
        return(1);
 }
                        return(0);
        return(1);
 }