Annotation of 43BSDReno/sbin/clri/clri.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Rich $alz of BBN Inc.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted provided
                      9:  * that: (1) source distributions retain this entire copyright notice and
                     10:  * comment, and (2) distributions including binaries display the following
                     11:  * acknowledgement:  ``This product includes software developed by the
                     12:  * University of California, Berkeley and its contributors'' in the
                     13:  * documentation or other materials provided with the distribution and in
                     14:  * all advertising materials mentioning features or use of this software.
                     15:  * Neither the name of the University nor the names of its contributors may
                     16:  * be used to endorse or promote products derived from this software without
                     17:  * specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: char copyright[] =
                     25: "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
                     26:  All rights reserved.\n";
                     27: #endif /* not lint */
                     28: 
                     29: #ifndef lint
                     30: static char sccsid[] = "@(#)clri.c     5.2 (Berkeley) 6/11/90";
                     31: #endif /* not lint */
                     32: 
                     33: /*
                     34:  * clri(8)
                     35:  */
                     36: 
                     37: #include <sys/param.h>
                     38: #include <sys/time.h>
                     39: #include <sys/vnode.h>
                     40: #include <ufs/quota.h>
                     41: #include <ufs/inode.h>
                     42: #include <ufs/fs.h>
                     43: #include <unistd.h>
                     44: #include <stdio.h>
                     45: #include <fcntl.h>
                     46: #include <errno.h>
                     47: 
                     48: char *fs;
                     49: 
                     50: main(argc, argv)
                     51:        int argc;
                     52:        char **argv;
                     53: {
                     54:        register struct fs *sbp;
                     55:        register struct dinode *ip;
                     56:        register int fd;
                     57:        struct dinode ibuf[MAXBSIZE / sizeof (struct dinode)];
                     58:        long generation, offset, bsize;
                     59:        int inonum;
                     60:        char sblock[SBSIZE];
                     61: 
                     62:        if (argc < 3) {
                     63:                (void)fprintf(stderr, "usage: clri filesystem inode ...\n");
                     64:                exit(1);
                     65:        }
                     66: 
                     67:        fs = *++argv;
                     68: 
                     69:        /* get the superblock. */
                     70:        if ((fd = open(fs, O_RDWR, 0)) < 0)
                     71:                error();
                     72:        if (lseek(fd, SBLOCK * DEV_BSIZE, SEEK_SET) < 0)
                     73:                error();
                     74:        if (read(fd, sblock, sizeof(sblock)) != sizeof(sblock)) {
                     75:                (void)fprintf(stderr,
                     76:                    "clri: %s: can't read the superblock.\n", fs);
                     77:                exit(1);
                     78:        }
                     79: 
                     80:        sbp = (struct fs *)sblock;
                     81:        if (sbp->fs_magic != FS_MAGIC) {
                     82:                (void)fprintf(stderr,
                     83:                    "clri: %s: superblock magic number 0x%x, not 0x%x.\n",
                     84:                    fs, sbp->fs_magic, FS_MAGIC);
                     85:                exit(1);
                     86:        }
                     87:        bsize = sbp->fs_bsize;
                     88: 
                     89:        /* remaining arguments are inode numbers. */
                     90:        while (*++argv) {
                     91:                /* get the inode number. */
                     92:                if ((inonum = atoi(*argv)) <= 0) {
                     93:                        (void)fprintf(stderr,
                     94:                            "clri: %s is not a valid inode number.\n", *argv);
                     95:                        exit(1);
                     96:                }
                     97:                (void)printf("clearing %d\n", inonum);
                     98: 
                     99:                /* read in the appropriate block. */
                    100:                offset = itod(sbp, inonum);     /* inode to fs block */
                    101:                offset = fsbtodb(sbp, offset);  /* fs block to disk block */
                    102:                offset *= DEV_BSIZE;            /* disk block to disk bytes */
                    103: 
                    104:                /* seek and read the block */
                    105:                if (lseek(fd, offset, SEEK_SET) < 0)
                    106:                        error();
                    107:                if (read(fd, (char *)ibuf, bsize) != bsize)
                    108:                        error();
                    109: 
                    110:                /* get the inode within the block. */
                    111:                ip = &ibuf[itoo(sbp, inonum)];
                    112: 
                    113:                /* clear the inode, and bump the generation count. */
                    114:                generation = ip->di_gen + 1;
                    115:                bzero((char *)ip, sizeof *ip);
                    116:                ip->di_gen = generation;
                    117: 
                    118:                /* backup and write the block */
                    119:                if (lseek(fd, -bsize, SEEK_CUR) < 0)
                    120:                        error();
                    121:                if (write(fd, (char *)ibuf, bsize) != bsize)
                    122:                        error();
                    123:                (void)fsync(fd);
                    124:        }
                    125:        (void)close(fd);
                    126:        exit(0);
                    127: }
                    128: 
                    129: error()
                    130: {
                    131:        (void)fprintf(stderr, "clri: %s: %s\n", fs, strerror(errno));
                    132:        exit(1);
                    133: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.