2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-26 06:35:07 +00:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rich $alz of BBN Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-26 06:35:07 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 18:41:59 +00:00
|
|
|
#if 0
|
1994-05-26 06:35:07 +00:00
|
|
|
#ifndef lint
|
1998-06-04 06:44:18 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 06:35:07 +00:00
|
|
|
"@(#) Copyright (c) 1990, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char sccsid[] = "@(#)clri.c 8.2 (Berkeley) 9/23/93";
|
|
|
|
#endif /* not lint */
|
2003-05-03 18:41:59 +00:00
|
|
|
#endif
|
2005-05-29 16:07:10 +00:00
|
|
|
|
2002-07-03 16:38:04 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <sys/param.h>
|
2002-05-12 21:37:08 +00:00
|
|
|
#include <sys/disklabel.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
2018-01-26 00:58:32 +00:00
|
|
|
#include <errno.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <fcntl.h>
|
2018-01-26 00:58:32 +00:00
|
|
|
#include <libufs.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1998-06-04 06:44:18 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2002-08-26 03:56:23 +00:00
|
|
|
(void)fprintf(stderr, "usage: clri special_device inode_number ...\n");
|
1998-06-04 06:44:18 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
int
|
2002-07-03 16:38:04 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2018-11-01 03:38:57 +00:00
|
|
|
union dinodep dp;
|
|
|
|
struct uufsd disk;
|
|
|
|
long generation;
|
|
|
|
int inonum, exitval;
|
2018-01-26 00:58:32 +00:00
|
|
|
char *fsname;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1998-06-04 06:44:18 +00:00
|
|
|
if (argc < 3)
|
|
|
|
usage();
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/* get the superblock. */
|
2018-11-01 03:38:57 +00:00
|
|
|
fsname = *++argv;
|
|
|
|
if (ufs_disk_fillout(&disk, fsname) == -1) {
|
|
|
|
printf("loading superblock: %s\n", disk.d_error);
|
|
|
|
exit (1);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/* remaining arguments are inode numbers. */
|
2018-11-01 03:38:57 +00:00
|
|
|
exitval = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
while (*++argv) {
|
|
|
|
/* get the inode number. */
|
2018-11-01 03:38:57 +00:00
|
|
|
if ((inonum = atoi(*argv)) < UFS_ROOTINO) {
|
|
|
|
printf("%s is not a valid inode number", *argv);
|
|
|
|
exitval = 1;
|
|
|
|
continue;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
(void)printf("clearing %d\n", inonum);
|
|
|
|
|
2018-11-13 21:40:56 +00:00
|
|
|
if (getinode(&disk, &dp, inonum) == -1) {
|
|
|
|
printf("getinode: %s\n", disk.d_error);
|
2018-11-01 03:38:57 +00:00
|
|
|
exitval = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* clear the inode, and bump the generation count. */
|
|
|
|
if (disk.d_fs.fs_magic == FS_UFS1_MAGIC) {
|
|
|
|
generation = dp.dp1->di_gen + 1;
|
|
|
|
memset(dp.dp1, 0, sizeof(*dp.dp1));
|
|
|
|
dp.dp1->di_gen = generation;
|
2002-06-21 06:18:05 +00:00
|
|
|
} else {
|
2018-11-01 03:38:57 +00:00
|
|
|
generation = dp.dp2->di_gen + 1;
|
|
|
|
memset(dp.dp2, 0, sizeof(*dp.dp2));
|
|
|
|
dp.dp2->di_gen = generation;
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
2018-11-13 21:40:56 +00:00
|
|
|
putinode(&disk);
|
2018-11-01 03:38:57 +00:00
|
|
|
(void)fsync(disk.d_fd);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2018-11-01 03:38:57 +00:00
|
|
|
(void)ufs_disk_close(&disk);
|
|
|
|
exit(exitval);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|