/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1990, 19934* The Regents of the University of California. All rights reserved.5*6* This code is derived from software contributed to Berkeley by7* Rich $alz of BBN Inc.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17* 3. Neither the name of the University nor the names of its contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#include <sys/param.h>35#include <sys/disklabel.h>3637#include <ufs/ufs/dinode.h>38#include <ufs/ffs/fs.h>3940#include <err.h>41#include <errno.h>42#include <fcntl.h>43#include <libufs.h>44#include <stdlib.h>45#include <string.h>46#include <stdio.h>47#include <unistd.h>4849static void50usage(void)51{52(void)fprintf(stderr, "usage: clri special_device inode_number ...\n");53exit(1);54}5556int57main(int argc, char *argv[])58{59union dinodep dp;60struct uufsd disk;61long generation;62int inonum, exitval;63char *fsname;6465if (argc < 3)66usage();6768/* get the superblock. */69fsname = *++argv;70if (ufs_disk_fillout(&disk, fsname) == -1) {71printf("loading superblock: %s\n", disk.d_error);72exit (1);73}7475/* remaining arguments are inode numbers. */76exitval = 0;77while (*++argv) {78/* get the inode number. */79if ((inonum = atoi(*argv)) < UFS_ROOTINO) {80printf("%s is not a valid inode number", *argv);81exitval = 1;82continue;83}84(void)printf("clearing %d\n", inonum);8586if (getinode(&disk, &dp, inonum) == -1) {87printf("getinode: %s\n", disk.d_error);88exitval = 1;89continue;90}91/* clear the inode, and bump the generation count. */92if (disk.d_fs.fs_magic == FS_UFS1_MAGIC) {93generation = dp.dp1->di_gen + 1;94memset(dp.dp1, 0, sizeof(*dp.dp1));95dp.dp1->di_gen = generation;96} else {97generation = dp.dp2->di_gen + 1;98memset(dp.dp2, 0, sizeof(*dp.dp2));99dp.dp2->di_gen = generation;100}101putinode(&disk);102(void)fsync(disk.d_fd);103}104(void)ufs_disk_close(&disk);105exit(exitval);106}107108109