- if(status)
- exit(status);
- for(i=2; i<argc; i++) {
- n = atoi(argv[i]);
- printf("clearing %u\n", n);
- off = itod(n) * BSIZE;
- lseek(f, off, 0);
- read(f, (char *)buf, BSIZE);
- j = itoo(n);
- for(k=0; k<ISIZE; k++)
- buf[j].junk[k] = 0;
- lseek(f, off, 0);
- write(f, (char *)buf, BSIZE);
+ bsize = sbp->fs_bsize;
+
+ /* remaining arguments are inode numbers. */
+ while (*++argv) {
+ /* get the inode number. */
+ if ((inonum = atoi(*argv)) <= 0) {
+ (void)fprintf(stderr,
+ "clri: %s is not a valid inode number.\n", *argv);
+ exit(1);
+ }
+ (void)printf("clearing %d\n", inonum);
+
+ /* read in the appropriate block. */
+ offset = itod(sbp, inonum); /* inode to fs block */
+ offset = fsbtodb(sbp, offset); /* fs block to disk block */
+ offset *= DEV_BSIZE; /* disk block to disk bytes */
+
+ /* seek and read the block */
+ if (lseek(fd, offset, SEEK_SET) < 0)
+ error();
+ if (read(fd, (char *)ibuf, bsize) != bsize)
+ error();
+
+ /* get the inode within the block. */
+ ip = &ibuf[itoo(sbp, inonum)];
+
+ /* clear the inode, and bump the generation count. */
+ generation = ip->di_gen + 1;
+ bzero((char *)ip, sizeof *ip);
+ ip->di_gen = generation;
+
+ /* backup and write the block */
+ if (lseek(fd, -bsize, SEEK_CUR) < 0)
+ error();
+ if (write(fd, (char *)ibuf, bsize) != bsize)
+ error();
+ (void)fsync(fd);