1995-11-03 22:38:54 +00:00
|
|
|
/* $NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $ */
|
|
|
|
|
2017-11-27 15:37:16 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1995-11-03 22:38:54 +00:00
|
|
|
* Copyright (c) 1995 John T. Kohl
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <ctype.h>
|
1998-06-15 07:12:20 +00:00
|
|
|
#include <err.h>
|
1995-11-03 22:38:54 +00:00
|
|
|
#include <grp.h>
|
|
|
|
#include <histedit.h>
|
|
|
|
#include <pwd.h>
|
2012-09-27 23:31:06 +00:00
|
|
|
#include <stdint.h>
|
1995-11-03 22:38:54 +00:00
|
|
|
#include <string.h>
|
2011-01-24 06:17:05 +00:00
|
|
|
#include <time.h>
|
2003-11-13 19:08:43 +00:00
|
|
|
#include <timeconv.h>
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
|
|
|
#include "fsdb.h"
|
|
|
|
#include "fsck.h"
|
|
|
|
|
2002-03-21 13:10:52 +00:00
|
|
|
static void usage(void) __dead2;
|
|
|
|
int cmdloop(void);
|
2006-06-02 12:55:26 +00:00
|
|
|
static int compare_blk32(uint32_t *wantedblk, uint32_t curblk);
|
|
|
|
static int compare_blk64(uint64_t *wantedblk, uint64_t curblk);
|
|
|
|
static int founddatablk(uint64_t blk);
|
|
|
|
static int find_blks32(uint32_t *buf, int size, uint32_t *blknum);
|
|
|
|
static int find_blks64(uint64_t *buf, int size, uint64_t *blknum);
|
|
|
|
static int find_indirblks32(uint32_t blk, int ind_level, uint32_t *blknum);
|
|
|
|
static int find_indirblks64(uint64_t blk, int ind_level, uint64_t *blknum);
|
1995-11-03 22:38:54 +00:00
|
|
|
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
/*
|
|
|
|
* Track modifications to the filesystem. Two types of changes are tracked.
|
|
|
|
* The first type of changes are those that are not critical to the integrity
|
|
|
|
* of the filesystem such as owner, group, time stamps, access mode, and
|
|
|
|
* generation number. The second type of changes are those that do affect
|
|
|
|
* the integrity of the filesystem including zeroing inodes, changing block
|
|
|
|
* pointers, directory entries, link counts, file lengths, file types and
|
|
|
|
* file flags.
|
|
|
|
*
|
|
|
|
* When quitting having made no changes or only changes to data that is not
|
|
|
|
* critical to filesystem integrity, the clean state of the filesystem is
|
|
|
|
* left unchanged. But if filesystem critical data are changed then fsdb
|
|
|
|
* will set the unclean flag which will require a full fsck to be run
|
|
|
|
* before the filesystem can be mounted.
|
|
|
|
*/
|
|
|
|
static int fsnoncritmodified; /* filesystem non-critical modifications */
|
|
|
|
static int fscritmodified; /* filesystem integrity critical mods */
|
2021-01-07 01:37:08 +00:00
|
|
|
struct inode curip;
|
|
|
|
union dinode *curinode;
|
|
|
|
ino_t curinum, ocurrent;
|
|
|
|
|
1997-06-11 07:13:30 +00:00
|
|
|
static void
|
2002-03-21 13:10:52 +00:00
|
|
|
usage(void)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
1997-06-11 07:13:30 +00:00
|
|
|
fprintf(stderr, "usage: fsdb [-d] [-f] [-r] fsname\n");
|
|
|
|
exit(1);
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We suck in lots of fsck code, and just pick & choose the stuff we want.
|
|
|
|
*
|
2002-08-21 18:11:48 +00:00
|
|
|
* fsreadfd is set up to read from the file system, fswritefd to write to
|
|
|
|
* the file system.
|
1995-11-03 22:38:54 +00:00
|
|
|
*/
|
1999-04-25 22:33:30 +00:00
|
|
|
int
|
2002-03-21 13:10:52 +00:00
|
|
|
main(int argc, char *argv[])
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
|
|
|
int ch, rval;
|
|
|
|
char *fsys = NULL;
|
|
|
|
|
1997-06-11 07:13:30 +00:00
|
|
|
while (-1 != (ch = getopt(argc, argv, "fdr"))) {
|
1995-11-03 22:38:54 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
1997-06-11 07:13:30 +00:00
|
|
|
/* The -f option is left for historical
|
|
|
|
* reasons and has no meaning.
|
|
|
|
*/
|
1995-11-03 22:38:54 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
debug++;
|
|
|
|
break;
|
1997-04-15 09:02:48 +00:00
|
|
|
case 'r':
|
|
|
|
nflag++; /* "no" in fsck, readonly for us */
|
|
|
|
break;
|
1995-11-03 22:38:54 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
1996-09-30 20:04:24 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
1997-06-11 07:13:30 +00:00
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
else
|
|
|
|
fsys = argv[0];
|
1996-09-30 20:04:24 +00:00
|
|
|
|
2001-04-23 21:39:14 +00:00
|
|
|
sblock_init();
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 19:41:53 +00:00
|
|
|
if (openfilesys(fsys) == 0 || readsb() == 0 || setup(fsys) == 0)
|
2002-08-21 18:11:48 +00:00
|
|
|
errx(1, "cannot set up file system `%s'", fsys);
|
2020-09-19 20:06:12 +00:00
|
|
|
if (fswritefd < 0)
|
|
|
|
nflag++;
|
2002-08-21 18:11:48 +00:00
|
|
|
printf("%s file system `%s'\nLast Mounted on %s\n",
|
1997-04-15 09:02:48 +00:00
|
|
|
nflag? "Examining": "Editing", fsys, sblock.fs_fsmnt);
|
1995-11-03 22:38:54 +00:00
|
|
|
rval = cmdloop();
|
1997-04-15 09:02:48 +00:00
|
|
|
if (!nflag) {
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
if (fscritmodified != 0) {
|
|
|
|
sblock.fs_clean = 0; /* mark it dirty */
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
ckfini(fscritmodified ? 0 : sblock.fs_clean);
|
|
|
|
if (fscritmodified == 0)
|
|
|
|
exit(0);
|
1997-04-15 09:02:48 +00:00
|
|
|
printf("*** FILE SYSTEM MARKED DIRTY\n");
|
|
|
|
printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n");
|
2021-01-07 01:37:08 +00:00
|
|
|
printf("*** IF IT IS MOUNTED, RE-MOUNT WITH -u -o reload\n");
|
1997-04-15 09:02:48 +00:00
|
|
|
}
|
1995-11-03 22:38:54 +00:00
|
|
|
exit(rval);
|
|
|
|
}
|
|
|
|
|
2002-03-21 13:10:52 +00:00
|
|
|
#define CMDFUNC(func) int func(int argc, char *argv[])
|
|
|
|
#define CMDFUNCSTART(func) int func(int argc, char *argv[])
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
CMDFUNC(helpfn);
|
|
|
|
CMDFUNC(focus); /* focus on inode */
|
|
|
|
CMDFUNC(active); /* print active inode */
|
2002-01-26 15:53:23 +00:00
|
|
|
CMDFUNC(blocks); /* print blocks for active inode */
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNC(focusname); /* focus by name */
|
|
|
|
CMDFUNC(zapi); /* clear inode */
|
|
|
|
CMDFUNC(uplink); /* incr link */
|
|
|
|
CMDFUNC(downlink); /* decr link */
|
|
|
|
CMDFUNC(linkcount); /* set link count */
|
|
|
|
CMDFUNC(quit); /* quit */
|
2023-07-26 02:42:41 +00:00
|
|
|
CMDFUNC(quitclean); /* quit with filesystem marked clean */
|
2006-06-02 12:55:26 +00:00
|
|
|
CMDFUNC(findblk); /* find block */
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNC(ls); /* list directory */
|
|
|
|
CMDFUNC(rm); /* remove name */
|
|
|
|
CMDFUNC(ln); /* add name */
|
|
|
|
CMDFUNC(newtype); /* change type */
|
|
|
|
CMDFUNC(chmode); /* change mode */
|
1996-09-26 19:40:04 +00:00
|
|
|
CMDFUNC(chlen); /* change length */
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNC(chaflags); /* change flags */
|
|
|
|
CMDFUNC(chgen); /* change generation */
|
|
|
|
CMDFUNC(chowner); /* change owner */
|
|
|
|
CMDFUNC(chgroup); /* Change group */
|
|
|
|
CMDFUNC(back); /* pop back to last ino */
|
2006-08-23 22:44:00 +00:00
|
|
|
CMDFUNC(chbtime); /* Change btime */
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNC(chmtime); /* Change mtime */
|
|
|
|
CMDFUNC(chctime); /* Change ctime */
|
|
|
|
CMDFUNC(chatime); /* Change atime */
|
|
|
|
CMDFUNC(chinum); /* Change inode # of dirent */
|
|
|
|
CMDFUNC(chname); /* Change dirname of dirent */
|
2019-02-25 21:58:19 +00:00
|
|
|
CMDFUNC(chsize); /* Change size */
|
2023-04-18 05:42:32 +00:00
|
|
|
CMDFUNC(chdb); /* Change direct block pointer */
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
struct cmdtable cmds[] = {
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "help", "Print out help", 1, 1, FL_RO, helpfn },
|
|
|
|
{ "?", "Print out help", 1, 1, FL_RO, helpfn },
|
|
|
|
{ "inode", "Set active inode to INUM", 2, 2, FL_RO, focus },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "clri", "Clear inode INUM", 2, 2, FL_CWR, zapi },
|
2006-04-21 20:33:16 +00:00
|
|
|
{ "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO | FL_ST, focusname },
|
|
|
|
{ "cd", "Set active inode by looking up NAME", 2, 2, FL_RO | FL_ST, focusname },
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "back", "Go to previous active inode", 1, 1, FL_RO, back },
|
|
|
|
{ "active", "Print active inode", 1, 1, FL_RO, active },
|
|
|
|
{ "print", "Print active inode", 1, 1, FL_RO, active },
|
2002-01-26 15:53:23 +00:00
|
|
|
{ "blocks", "Print block numbers of active inode", 1, 1, FL_RO, blocks },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "uplink", "Increment link count", 1, 1, FL_CWR, uplink },
|
|
|
|
{ "downlink", "Decrement link count", 1, 1, FL_CWR, downlink },
|
|
|
|
{ "linkcount", "Set link count to COUNT", 2, 2, FL_CWR, linkcount },
|
2006-06-02 12:55:26 +00:00
|
|
|
{ "findblk", "Find inode owning disk block(s)", 2, 33, FL_RO, findblk},
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "ls", "List current inode as directory", 1, 1, FL_RO, ls },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "rm", "Remove NAME from current inode directory", 2, 2, FL_CWR | FL_ST, rm },
|
|
|
|
{ "del", "Remove NAME from current inode directory", 2, 2, FL_CWR | FL_ST, rm },
|
|
|
|
{ "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_CWR | FL_ST, ln },
|
|
|
|
{ "chinum", "Change dir entry number INDEX to INUM", 3, 3, FL_CWR, chinum },
|
2006-04-21 20:33:16 +00:00
|
|
|
{ "chname", "Change dir entry number INDEX to NAME", 3, 3, FL_WR | FL_ST, chname },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "chtype", "Change type of current inode to TYPE", 2, 2, FL_CWR, newtype },
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "chmod", "Change mode of current inode to MODE", 2, 2, FL_WR, chmode },
|
|
|
|
{ "chown", "Change owner of current inode to OWNER", 2, 2, FL_WR, chowner },
|
|
|
|
{ "chgrp", "Change group of current inode to GROUP", 2, 2, FL_WR, chgroup },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "chflags", "Change flags of current inode to FLAGS", 2, 2, FL_CWR, chaflags },
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "chgen", "Change generation number of current inode to GEN", 2, 2, FL_WR, chgen },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "chsize", "Change size of current inode to SIZE", 2, 2, FL_CWR, chsize },
|
2006-08-23 22:44:00 +00:00
|
|
|
{ "btime", "Change btime of current inode to BTIME", 2, 2, FL_WR, chbtime },
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "mtime", "Change mtime of current inode to MTIME", 2, 2, FL_WR, chmtime },
|
|
|
|
{ "ctime", "Change ctime of current inode to CTIME", 2, 2, FL_WR, chctime },
|
|
|
|
{ "atime", "Change atime of current inode to ATIME", 2, 2, FL_WR, chatime },
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
{ "chdb", "Change db pointer N of current inode to BLKNO", 3, 3, FL_CWR, chdb },
|
2023-07-26 02:42:41 +00:00
|
|
|
{ "quitclean", "Exit with filesystem marked clean", 1, 1, FL_RO, quitclean },
|
1997-04-15 09:02:48 +00:00
|
|
|
{ "quit", "Exit", 1, 1, FL_RO, quit },
|
|
|
|
{ "q", "Exit", 1, 1, FL_RO, quit },
|
|
|
|
{ "exit", "Exit", 1, 1, FL_RO, quit },
|
2004-10-09 15:56:34 +00:00
|
|
|
{ NULL, 0, 0, 0, 0, NULL },
|
1995-11-03 22:38:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2002-03-21 13:10:52 +00:00
|
|
|
helpfn(int argc, char *argv[])
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct cmdtable *cmdtp;
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
printf("Commands are:\n%-10s %5s %5s %s\n",
|
2006-04-21 20:33:16 +00:00
|
|
|
"command", "min args", "max args", "what");
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
for (cmdtp = cmds; cmdtp->cmd; cmdtp++)
|
|
|
|
printf("%-10s %5u %5u %s\n",
|
2006-04-21 20:33:16 +00:00
|
|
|
cmdtp->cmd, cmdtp->minargc-1, cmdtp->maxargc-1, cmdtp->helptxt);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2002-03-21 13:10:52 +00:00
|
|
|
prompt(EditLine *el)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
|
|
|
static char pstring[64];
|
2012-09-27 23:31:06 +00:00
|
|
|
snprintf(pstring, sizeof(pstring), "fsdb (inum: %ju)> ",
|
|
|
|
(uintmax_t)curinum);
|
1995-11-03 22:38:54 +00:00
|
|
|
return pstring;
|
|
|
|
}
|
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
static void
|
|
|
|
setcurinode(ino_t inum)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (curip.i_number != 0)
|
|
|
|
irelse(&curip);
|
|
|
|
ginode(inum, &curip);
|
|
|
|
curinode = curip.i_dp;
|
|
|
|
curinum = inum;
|
|
|
|
}
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
int
|
2002-03-21 13:10:52 +00:00
|
|
|
cmdloop(void)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
const char *elline;
|
|
|
|
int cmd_argc, rval = 0, known;
|
|
|
|
#define scratch known
|
|
|
|
char **cmd_argv;
|
|
|
|
struct cmdtable *cmdp;
|
|
|
|
History *hist;
|
|
|
|
EditLine *elptr;
|
2001-10-01 08:43:58 +00:00
|
|
|
HistEvent he;
|
1995-11-03 22:38:54 +00:00
|
|
|
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(UFS_ROOTINO);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
hist = history_init();
|
2005-10-19 15:37:43 +00:00
|
|
|
history(hist, &he, H_SETSIZE, 100); /* 100 elt history buffer */
|
1995-11-03 22:38:54 +00:00
|
|
|
|
2001-10-01 08:43:58 +00:00
|
|
|
elptr = el_init("fsdb", stdin, stdout, stderr);
|
1995-11-03 22:38:54 +00:00
|
|
|
el_set(elptr, EL_EDITOR, "emacs");
|
|
|
|
el_set(elptr, EL_PROMPT, prompt);
|
|
|
|
el_set(elptr, EL_HIST, history, hist);
|
|
|
|
el_source(elptr, NULL);
|
|
|
|
|
|
|
|
while ((elline = el_gets(elptr, &scratch)) != NULL && scratch != 0) {
|
|
|
|
if (debug)
|
1998-06-15 07:12:20 +00:00
|
|
|
printf("command `%s'\n", elline);
|
1995-11-03 22:38:54 +00:00
|
|
|
|
2001-10-01 08:43:58 +00:00
|
|
|
history(hist, &he, H_ENTER, elline);
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
line = strdup(elline);
|
|
|
|
cmd_argv = crack(line, &cmd_argc);
|
|
|
|
/*
|
|
|
|
* el_parse returns -1 to signal that it's not been handled
|
|
|
|
* internally.
|
|
|
|
*/
|
2005-08-07 20:53:33 +00:00
|
|
|
if (el_parse(elptr, cmd_argc, (const char **)cmd_argv) != -1)
|
1995-11-03 22:38:54 +00:00
|
|
|
continue;
|
|
|
|
if (cmd_argc) {
|
|
|
|
known = 0;
|
|
|
|
for (cmdp = cmds; cmdp->cmd; cmdp++) {
|
|
|
|
if (!strcmp(cmdp->cmd, cmd_argv[0])) {
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
if ((cmdp->flags & (FL_CWR | FL_WR)) != 0 && nflag)
|
1997-04-15 09:02:48 +00:00
|
|
|
warnx("`%s' requires write access", cmd_argv[0]),
|
|
|
|
rval = 1;
|
|
|
|
else if (cmd_argc >= cmdp->minargc &&
|
1995-11-03 22:38:54 +00:00
|
|
|
cmd_argc <= cmdp->maxargc)
|
|
|
|
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
2006-04-21 20:33:16 +00:00
|
|
|
else if (cmd_argc >= cmdp->minargc &&
|
|
|
|
(cmdp->flags & FL_ST) == FL_ST) {
|
2002-01-25 18:31:57 +00:00
|
|
|
strcpy(line, elline);
|
|
|
|
cmd_argv = recrack(line, &cmd_argc, cmdp->maxargc);
|
|
|
|
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
|
|
|
} else
|
1995-11-03 22:38:54 +00:00
|
|
|
rval = argcount(cmdp, cmd_argc, cmd_argv);
|
|
|
|
known = 1;
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
if (rval == 0) {
|
|
|
|
if ((cmdp->flags & FL_WR) != 0)
|
|
|
|
fsnoncritmodified = 1;
|
|
|
|
if ((cmdp->flags & FL_CWR) != 0)
|
|
|
|
fscritmodified = 1;
|
|
|
|
}
|
1995-11-03 22:38:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!known)
|
|
|
|
warnx("unknown command `%s'", cmd_argv[0]), rval = 1;
|
|
|
|
} else
|
|
|
|
rval = 0;
|
|
|
|
free(line);
|
2021-01-07 01:37:08 +00:00
|
|
|
if (rval < 0) {
|
2002-01-26 11:21:19 +00:00
|
|
|
/* user typed "quit" */
|
2021-01-07 01:37:08 +00:00
|
|
|
irelse(&curip);
|
2002-01-26 11:21:19 +00:00
|
|
|
return 0;
|
2021-01-07 01:37:08 +00:00
|
|
|
}
|
1995-11-03 22:38:54 +00:00
|
|
|
if (rval)
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
warnx("command failed, return value was %d", rval);
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
el_end(elptr);
|
|
|
|
history_end(hist);
|
2021-01-07 01:37:08 +00:00
|
|
|
irelse(&curip);
|
1995-11-03 22:38:54 +00:00
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \
|
2017-02-15 19:50:26 +00:00
|
|
|
if (inum < UFS_ROOTINO || inum > maxino || cp == argv[ac] || *cp != '\0' ) { \
|
2012-09-27 23:31:06 +00:00
|
|
|
printf("inode %ju out of range; range is [%ju,%ju]\n", \
|
2017-02-15 19:50:26 +00:00
|
|
|
(uintmax_t)inum, (uintmax_t)UFS_ROOTINO, (uintmax_t)maxino);\
|
1995-11-03 22:38:54 +00:00
|
|
|
return 1; \
|
2017-02-15 19:50:26 +00:00
|
|
|
}
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Focus on given inode number
|
|
|
|
*/
|
|
|
|
CMDFUNCSTART(focus)
|
|
|
|
{
|
|
|
|
ino_t inum;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
GETINUM(1,inum);
|
|
|
|
ocurrent = curinum;
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(inum);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(back)
|
|
|
|
{
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(ocurrent);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(zapi)
|
|
|
|
{
|
2021-01-07 01:37:08 +00:00
|
|
|
struct inode ip;
|
1995-11-03 22:38:54 +00:00
|
|
|
ino_t inum;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
GETINUM(1,inum);
|
2021-01-07 01:37:08 +00:00
|
|
|
ginode(inum, &ip);
|
|
|
|
clearinode(ip.i_dp);
|
|
|
|
inodirty(&ip);
|
|
|
|
irelse(&ip);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(active)
|
|
|
|
{
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-01-26 15:53:23 +00:00
|
|
|
CMDFUNCSTART(blocks)
|
|
|
|
{
|
|
|
|
printactive(1);
|
|
|
|
return 0;
|
|
|
|
}
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
CMDFUNCSTART(quit)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-07-26 02:42:41 +00:00
|
|
|
CMDFUNCSTART(quitclean)
|
|
|
|
{
|
|
|
|
if (fscritmodified) {
|
|
|
|
printf("Warning: modified filesystem marked clean\n");
|
|
|
|
fscritmodified = 0;
|
|
|
|
sblock.fs_clean = 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNCSTART(uplink)
|
|
|
|
{
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) + 1);
|
2012-09-27 23:31:06 +00:00
|
|
|
printf("inode %ju link count now %d\n",
|
|
|
|
(uintmax_t)curinum, DIP(curinode, di_nlink));
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(downlink)
|
|
|
|
{
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) - 1);
|
2012-09-27 23:31:06 +00:00
|
|
|
printf("inode %ju link count now %d\n",
|
|
|
|
(uintmax_t)curinum, DIP(curinode, di_nlink));
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *typename[] = {
|
|
|
|
"unknown",
|
|
|
|
"fifo",
|
|
|
|
"char special",
|
|
|
|
"unregistered #3",
|
|
|
|
"directory",
|
|
|
|
"unregistered #5",
|
|
|
|
"blk special",
|
|
|
|
"unregistered #7",
|
|
|
|
"regular",
|
|
|
|
"unregistered #9",
|
|
|
|
"symlink",
|
|
|
|
"unregistered #11",
|
|
|
|
"socket",
|
|
|
|
"unregistered #13",
|
|
|
|
"whiteout",
|
|
|
|
};
|
2010-04-24 07:05:35 +00:00
|
|
|
|
|
|
|
int diroff;
|
1995-11-03 22:38:54 +00:00
|
|
|
int slot;
|
|
|
|
|
|
|
|
int
|
2002-03-21 13:10:52 +00:00
|
|
|
scannames(struct inodesc *idesc)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
1995-11-03 22:38:54 +00:00
|
|
|
|
2010-04-24 07:05:35 +00:00
|
|
|
printf("slot %d off %d ino %d reclen %d: %s, `%.*s'\n",
|
|
|
|
slot++, diroff, dirp->d_ino, dirp->d_reclen,
|
|
|
|
typename[dirp->d_type], dirp->d_namlen, dirp->d_name);
|
|
|
|
diroff += dirp->d_reclen;
|
1995-11-03 22:38:54 +00:00
|
|
|
return (KEEPON);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(ls)
|
|
|
|
{
|
|
|
|
struct inodesc idesc;
|
|
|
|
checkactivedir(); /* let it go on anyway */
|
|
|
|
|
|
|
|
slot = 0;
|
2010-04-24 07:05:35 +00:00
|
|
|
diroff = 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = scannames;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
ckinode(curinode, &idesc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-02 12:55:26 +00:00
|
|
|
static int findblk_numtofind;
|
|
|
|
static int wantedblksize;
|
|
|
|
|
|
|
|
CMDFUNCSTART(findblk)
|
|
|
|
{
|
|
|
|
ino_t inum, inosused;
|
|
|
|
uint32_t *wantedblk32;
|
|
|
|
uint64_t *wantedblk64;
|
2013-03-23 20:00:02 +00:00
|
|
|
struct bufarea *cgbp;
|
|
|
|
struct cg *cgp;
|
2006-06-02 12:55:26 +00:00
|
|
|
int c, i, is_ufs2;
|
|
|
|
|
|
|
|
wantedblksize = (argc - 1);
|
|
|
|
is_ufs2 = sblock.fs_magic == FS_UFS2_MAGIC;
|
|
|
|
ocurrent = curinum;
|
|
|
|
|
|
|
|
if (is_ufs2) {
|
|
|
|
wantedblk64 = calloc(wantedblksize, sizeof(uint64_t));
|
|
|
|
if (wantedblk64 == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
wantedblk64[i - 1] = dbtofsb(&sblock, strtoull(argv[i], NULL, 0));
|
|
|
|
} else {
|
|
|
|
wantedblk32 = calloc(wantedblksize, sizeof(uint32_t));
|
|
|
|
if (wantedblk32 == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
wantedblk32[i - 1] = dbtofsb(&sblock, strtoull(argv[i], NULL, 0));
|
|
|
|
}
|
|
|
|
findblk_numtofind = wantedblksize;
|
|
|
|
/*
|
|
|
|
* sblock.fs_ncg holds a number of cylinder groups.
|
|
|
|
* Iterate over all cylinder groups.
|
|
|
|
*/
|
|
|
|
for (c = 0; c < sblock.fs_ncg; c++) {
|
|
|
|
/*
|
|
|
|
* sblock.fs_ipg holds a number of inodes per cylinder group.
|
|
|
|
* Calculate a highest inode number for a given cylinder group.
|
|
|
|
*/
|
|
|
|
inum = c * sblock.fs_ipg;
|
|
|
|
/* Read cylinder group. */
|
2018-01-17 13:19:37 +00:00
|
|
|
cgbp = cglookup(c);
|
2013-03-23 20:00:02 +00:00
|
|
|
cgp = cgbp->b_un.b_cg;
|
2006-06-02 12:55:26 +00:00
|
|
|
/*
|
|
|
|
* Get a highest used inode number for a given cylinder group.
|
|
|
|
* For UFS1 all inodes initialized at the newfs stage.
|
|
|
|
*/
|
|
|
|
if (is_ufs2)
|
|
|
|
inosused = cgp->cg_initediblk;
|
|
|
|
else
|
|
|
|
inosused = sblock.fs_ipg;
|
|
|
|
|
|
|
|
for (; inosused > 0; inum++, inosused--) {
|
2017-02-15 19:50:26 +00:00
|
|
|
/* Skip magic inodes: 0, UFS_WINO, UFS_ROOTINO. */
|
|
|
|
if (inum < UFS_ROOTINO)
|
2006-06-02 12:55:26 +00:00
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Check if the block we are looking for is just an inode block.
|
|
|
|
*
|
|
|
|
* ino_to_fsba() - get block containing inode from its number.
|
|
|
|
* INOPB() - get a number of inodes in one disk block.
|
|
|
|
*/
|
|
|
|
if (is_ufs2 ?
|
|
|
|
compare_blk64(wantedblk64, ino_to_fsba(&sblock, inum)) :
|
|
|
|
compare_blk32(wantedblk32, ino_to_fsba(&sblock, inum))) {
|
2012-09-27 23:31:06 +00:00
|
|
|
printf("block %llu: inode block (%ju-%ju)\n",
|
2006-06-02 12:55:26 +00:00
|
|
|
(unsigned long long)fsbtodb(&sblock,
|
|
|
|
ino_to_fsba(&sblock, inum)),
|
2012-09-27 23:31:06 +00:00
|
|
|
(uintmax_t)(inum / INOPB(&sblock)) * INOPB(&sblock),
|
|
|
|
(uintmax_t)(inum / INOPB(&sblock) + 1) * INOPB(&sblock));
|
2006-06-02 12:55:26 +00:00
|
|
|
findblk_numtofind--;
|
|
|
|
if (findblk_numtofind == 0)
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
/* Get on-disk inode aka dinode. */
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(inum);
|
2018-03-17 12:59:55 +00:00
|
|
|
/* Find IFLNK dinode with allocated data blocks. */
|
|
|
|
switch (DIP(curinode, di_mode) & IFMT) {
|
|
|
|
case IFDIR:
|
|
|
|
case IFREG:
|
2006-06-02 12:55:26 +00:00
|
|
|
if (DIP(curinode, di_blocks) == 0)
|
|
|
|
continue;
|
|
|
|
break;
|
2018-03-17 12:59:55 +00:00
|
|
|
case IFLNK:
|
2006-06-02 12:55:26 +00:00
|
|
|
{
|
|
|
|
uint64_t size = DIP(curinode, di_size);
|
|
|
|
if (size > 0 && size < sblock.fs_maxsymlinklen &&
|
|
|
|
DIP(curinode, di_blocks) == 0)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Look through direct data blocks. */
|
|
|
|
if (is_ufs2 ?
|
2017-02-15 19:50:26 +00:00
|
|
|
find_blks64(curinode->dp2.di_db, UFS_NDADDR, wantedblk64) :
|
|
|
|
find_blks32(curinode->dp1.di_db, UFS_NDADDR, wantedblk32))
|
2006-06-02 12:55:26 +00:00
|
|
|
goto end;
|
2017-02-15 19:50:26 +00:00
|
|
|
for (i = 0; i < UFS_NIADDR; i++) {
|
2006-06-02 12:55:26 +00:00
|
|
|
/*
|
|
|
|
* Does the block we are looking for belongs to the
|
|
|
|
* indirect blocks?
|
|
|
|
*/
|
|
|
|
if (is_ufs2 ?
|
|
|
|
compare_blk64(wantedblk64, curinode->dp2.di_ib[i]) :
|
|
|
|
compare_blk32(wantedblk32, curinode->dp1.di_ib[i]))
|
|
|
|
if (founddatablk(is_ufs2 ? curinode->dp2.di_ib[i] :
|
|
|
|
curinode->dp1.di_ib[i]))
|
|
|
|
goto end;
|
|
|
|
/*
|
|
|
|
* Search through indirect, double and triple indirect
|
|
|
|
* data blocks.
|
|
|
|
*/
|
|
|
|
if (is_ufs2 ? (curinode->dp2.di_ib[i] != 0) :
|
|
|
|
(curinode->dp1.di_ib[i] != 0))
|
|
|
|
if (is_ufs2 ?
|
|
|
|
find_indirblks64(curinode->dp2.di_ib[i], i,
|
|
|
|
wantedblk64) :
|
|
|
|
find_indirblks32(curinode->dp1.di_ib[i], i,
|
|
|
|
wantedblk32))
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(ocurrent);
|
2017-12-29 06:22:05 +00:00
|
|
|
if (is_ufs2)
|
|
|
|
free(wantedblk64);
|
|
|
|
else
|
|
|
|
free(wantedblk32);
|
2006-06-02 12:55:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_blk32(uint32_t *wantedblk, uint32_t curblk)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < wantedblksize; i++) {
|
|
|
|
if (wantedblk[i] != 0 && wantedblk[i] == curblk) {
|
|
|
|
wantedblk[i] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
compare_blk64(uint64_t *wantedblk, uint64_t curblk)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < wantedblksize; i++) {
|
|
|
|
if (wantedblk[i] != 0 && wantedblk[i] == curblk) {
|
|
|
|
wantedblk[i] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
founddatablk(uint64_t blk)
|
|
|
|
{
|
|
|
|
|
2012-09-27 23:31:06 +00:00
|
|
|
printf("%llu: data block of inode %ju\n",
|
|
|
|
(unsigned long long)fsbtodb(&sblock, blk), (uintmax_t)curinum);
|
2006-06-02 12:55:26 +00:00
|
|
|
findblk_numtofind--;
|
|
|
|
if (findblk_numtofind == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_blks32(uint32_t *buf, int size, uint32_t *wantedblk)
|
|
|
|
{
|
|
|
|
int blk;
|
|
|
|
for (blk = 0; blk < size; blk++) {
|
|
|
|
if (buf[blk] == 0)
|
|
|
|
continue;
|
|
|
|
if (compare_blk32(wantedblk, buf[blk])) {
|
|
|
|
if (founddatablk(buf[blk]))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_indirblks32(uint32_t blk, int ind_level, uint32_t *wantedblk)
|
|
|
|
{
|
|
|
|
#define MAXNINDIR (MAXBSIZE / sizeof(uint32_t))
|
|
|
|
uint32_t idblk[MAXNINDIR];
|
|
|
|
int i;
|
|
|
|
|
2006-10-31 22:07:29 +00:00
|
|
|
blread(fsreadfd, (char *)idblk, fsbtodb(&sblock, blk), (int)sblock.fs_bsize);
|
2006-06-02 12:55:26 +00:00
|
|
|
if (ind_level <= 0) {
|
|
|
|
if (find_blks32(idblk, sblock.fs_bsize / sizeof(uint32_t), wantedblk))
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
ind_level--;
|
|
|
|
for (i = 0; i < sblock.fs_bsize / sizeof(uint32_t); i++) {
|
|
|
|
if (compare_blk32(wantedblk, idblk[i])) {
|
|
|
|
if (founddatablk(idblk[i]))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (idblk[i] != 0)
|
|
|
|
if (find_indirblks32(idblk[i], ind_level, wantedblk))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef MAXNINDIR
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_blks64(uint64_t *buf, int size, uint64_t *wantedblk)
|
|
|
|
{
|
|
|
|
int blk;
|
|
|
|
for (blk = 0; blk < size; blk++) {
|
|
|
|
if (buf[blk] == 0)
|
|
|
|
continue;
|
|
|
|
if (compare_blk64(wantedblk, buf[blk])) {
|
|
|
|
if (founddatablk(buf[blk]))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_indirblks64(uint64_t blk, int ind_level, uint64_t *wantedblk)
|
|
|
|
{
|
|
|
|
#define MAXNINDIR (MAXBSIZE / sizeof(uint64_t))
|
|
|
|
uint64_t idblk[MAXNINDIR];
|
|
|
|
int i;
|
|
|
|
|
2006-10-31 22:07:29 +00:00
|
|
|
blread(fsreadfd, (char *)idblk, fsbtodb(&sblock, blk), (int)sblock.fs_bsize);
|
2006-06-02 12:55:26 +00:00
|
|
|
if (ind_level <= 0) {
|
|
|
|
if (find_blks64(idblk, sblock.fs_bsize / sizeof(uint64_t), wantedblk))
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
ind_level--;
|
|
|
|
for (i = 0; i < sblock.fs_bsize / sizeof(uint64_t); i++) {
|
|
|
|
if (compare_blk64(wantedblk, idblk[i])) {
|
|
|
|
if (founddatablk(idblk[i]))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (idblk[i] != 0)
|
|
|
|
if (find_indirblks64(idblk[i], ind_level, wantedblk))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef MAXNINDIR
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-21 13:10:52 +00:00
|
|
|
int findino(struct inodesc *idesc); /* from fsck */
|
|
|
|
static int dolookup(char *name);
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
static int
|
2002-03-21 13:10:52 +00:00
|
|
|
dolookup(char *name)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
|
|
|
struct inodesc idesc;
|
|
|
|
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 0;
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = findino;
|
|
|
|
idesc.id_name = name;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
if (ckinode(curinode, &idesc) & FOUND) {
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(idesc.id_parent);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
warnx("name `%s' not found in current inode directory", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(focusname)
|
|
|
|
{
|
|
|
|
char *p, *val;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
ocurrent = curinum;
|
|
|
|
|
|
|
|
if (argv[1][0] == '/') {
|
2021-01-07 01:37:08 +00:00
|
|
|
setcurinode(UFS_ROOTINO);
|
1995-11-03 22:38:54 +00:00
|
|
|
} else {
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (p = argv[1]; p != NULL;) {
|
|
|
|
while ((val = strsep(&p, "/")) != NULL && *val == '\0');
|
|
|
|
if (val) {
|
|
|
|
printf("component `%s': ", val);
|
|
|
|
fflush(stdout);
|
|
|
|
if (!dolookup(val)) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(ln)
|
|
|
|
{
|
|
|
|
ino_t inum;
|
|
|
|
int rval;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
GETINUM(1,inum);
|
|
|
|
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
rval = makeentry(curinum, inum, argv[2]);
|
|
|
|
if (rval)
|
2012-09-27 23:31:06 +00:00
|
|
|
printf("Ino %ju entered as `%s'\n", (uintmax_t)inum, argv[2]);
|
1995-11-03 22:38:54 +00:00
|
|
|
else
|
|
|
|
printf("could not enter name? weird.\n");
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(rm)
|
|
|
|
{
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
Improvement in UFS/FFS directory placement when doing mkdir(2).
The algorithm for laying out new directories was devised in the 1980s
and markedly improved the performance of the filesystem. In those days
large disks had at most 100 cylinder groups and often as few as 10-20.
Modern multi-terrabyte disks have thousands of cylinder groups. The
original algorithm does not handle these large sizes well. This change
attempts to expand the scope of the original algorithm to work well
with these much larger disks while still retaining the properties
of the original algorithm for small disks.
The filesystem implementation is divided into policy routines and
implementation routines. The policy routines can be changed in any
way desired without risk of corrupting the filesystem. The policy
requests are handled by the implementation layer. If the policy
asks for an available resource, it is granted. But if it asks for
an already in-use resource, then the implementation will provide
an available one nearby the request. Thus it is impossible for a
policy to double allocate. This change is limited to the policy
implementation.
This change updates the ffs_dirpref() routine which is responsible
for selecting the cylinder group into which a new directory should
be placed. If we are near the root of the filesystem we aim to
spread them out as much as possible. As we descend deeper from the
root we cluster them closer together around their parent as we
expect them to be more closely interactive. Higher-level directories
like usr/src/sys and usr/src/bin should be separated while the
directories in these areas are more likely to be accessed together
so should be closer. And directories within commands or kernel
subsystems should be closer still.
We pick a range of cylinder groups around the cylinder group of the
directory in which we are being created. The size of the range for
our search is based on our depth from the root of our filesystem.
We then probe that range based on how many directories are already
present. The first new directory is at 1/2 (middle) of the range;
the second is in the first 1/4 of the range, then at 3/4, 1/8, 3/8,
5/8, 7/8, 1/16, 3/16, 5/16, etc.
It is desirable to store the depth of a directory in its on-disk
inode so that it is available when we need it. We add a new field
di_dirdepth to track the depth of each directory. Because there are
few spare fields left in the inode, we choose to share an existing
field in the inode rather than having one of our own. Specifically
we create a union with the di_freelink field. The di_freelink field
is used to track inodes that have been unlinked but remain referenced.
It is not needed until a rmdir(2) operation has been done on a
directory. At that point, the directory has no contents and even
if it is kept active as a current directory is no longer able to
have any new directories or files created in it. Thus the use of
di_dirdepth and di_freelink will never coincide.
Reported by: Timo Voelker
Reviewed by: kib
Tested by: Peter Holm
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39246
2023-03-30 04:09:39 +00:00
|
|
|
rval = changeino(curinum, argv[1], 0, 0);
|
1995-11-03 22:38:54 +00:00
|
|
|
if (rval & ALTERED) {
|
|
|
|
printf("Name `%s' removed\n", argv[1]);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2002-01-25 18:31:57 +00:00
|
|
|
printf("could not remove name ('%s')? weird.\n", argv[1]);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long slotcount, desired;
|
|
|
|
|
|
|
|
int
|
2002-03-21 13:10:52 +00:00
|
|
|
chinumfunc(struct inodesc *idesc)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
if (slotcount++ == desired) {
|
|
|
|
dirp->d_ino = idesc->id_parent;
|
|
|
|
return STOP|ALTERED|FOUND;
|
|
|
|
}
|
|
|
|
return KEEPON;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chinum)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
ino_t inum;
|
|
|
|
struct inodesc idesc;
|
|
|
|
|
|
|
|
slotcount = 0;
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
GETINUM(2,inum);
|
|
|
|
|
|
|
|
desired = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' || desired < 0) {
|
|
|
|
printf("invalid slot number `%s'\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = chinumfunc;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_parent = inum; /* XXX convenient hiding place */
|
|
|
|
|
|
|
|
if (ckinode(curinode, &idesc) & FOUND)
|
|
|
|
return 0;
|
|
|
|
else {
|
|
|
|
warnx("no %sth slot in current directory", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-21 13:10:52 +00:00
|
|
|
chnamefunc(struct inodesc *idesc)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
1995-11-03 22:38:54 +00:00
|
|
|
struct direct testdir;
|
|
|
|
|
|
|
|
if (slotcount++ == desired) {
|
|
|
|
/* will name fit? */
|
|
|
|
testdir.d_namlen = strlen(idesc->id_name);
|
|
|
|
if (DIRSIZ(NEWDIRFMT, &testdir) <= dirp->d_reclen) {
|
|
|
|
dirp->d_namlen = testdir.d_namlen;
|
|
|
|
strcpy(dirp->d_name, idesc->id_name);
|
|
|
|
return STOP|ALTERED|FOUND;
|
|
|
|
} else
|
|
|
|
return STOP|FOUND; /* won't fit, so give up */
|
|
|
|
}
|
|
|
|
return KEEPON;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chname)
|
|
|
|
{
|
|
|
|
int rval;
|
|
|
|
char *cp;
|
|
|
|
struct inodesc idesc;
|
|
|
|
|
|
|
|
slotcount = 0;
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
desired = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
printf("invalid slot number `%s'\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = chnamefunc;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_name = argv[2];
|
|
|
|
|
|
|
|
rval = ckinode(curinode, &idesc);
|
|
|
|
if ((rval & (FOUND|ALTERED)) == (FOUND|ALTERED))
|
|
|
|
return 0;
|
|
|
|
else if (rval & FOUND) {
|
|
|
|
warnx("new name `%s' does not fit in slot %s\n", argv[2], argv[1]);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
warnx("no %sth slot in current directory", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct typemap {
|
|
|
|
const char *typename;
|
|
|
|
int typebits;
|
|
|
|
} typenamemap[] = {
|
2018-03-17 12:59:55 +00:00
|
|
|
{"file", IFREG},
|
|
|
|
{"dir", IFDIR},
|
|
|
|
{"socket", IFSOCK},
|
|
|
|
{"fifo", IFIFO},
|
1995-11-03 22:38:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CMDFUNCSTART(newtype)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
struct typemap *tp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
2018-03-17 12:59:55 +00:00
|
|
|
type = DIP(curinode, di_mode) & IFMT;
|
1995-11-03 22:38:54 +00:00
|
|
|
for (tp = typenamemap;
|
2016-07-30 06:19:34 +00:00
|
|
|
tp < &typenamemap[nitems(typenamemap)];
|
1995-11-03 22:38:54 +00:00
|
|
|
tp++) {
|
|
|
|
if (!strcmp(argv[1], tp->typename)) {
|
|
|
|
printf("setting type to %s\n", tp->typename);
|
|
|
|
type = tp->typebits;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-07-30 06:19:34 +00:00
|
|
|
if (tp == &typenamemap[nitems(typenamemap)]) {
|
1995-11-03 22:38:54 +00:00
|
|
|
warnx("type `%s' not known", argv[1]);
|
|
|
|
warnx("try one of `file', `dir', `socket', `fifo'");
|
|
|
|
return 1;
|
|
|
|
}
|
2018-03-17 12:59:55 +00:00
|
|
|
DIP_SET(curinode, di_mode, DIP(curinode, di_mode) & ~IFMT);
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | type);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chmode)
|
|
|
|
{
|
|
|
|
long modebits;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
modebits = strtol(argv[1], &cp, 8);
|
2001-11-11 10:44:02 +00:00
|
|
|
if (cp == argv[1] || *cp != '\0' || (modebits & ~07777)) {
|
1995-11-03 22:38:54 +00:00
|
|
|
warnx("bad modebits `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_mode, DIP(curinode, di_mode) & ~07777);
|
|
|
|
DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | modebits);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chaflags)
|
|
|
|
{
|
|
|
|
u_long flags;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
flags = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' ) {
|
|
|
|
warnx("bad flags `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags > UINT_MAX) {
|
|
|
|
warnx("flags set beyond 32-bit range of field (%lx)\n", flags);
|
|
|
|
return(1);
|
|
|
|
}
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_flags, flags);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chgen)
|
|
|
|
{
|
|
|
|
long gen;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
gen = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' ) {
|
|
|
|
warnx("bad gen `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
if (gen > UINT_MAX) {
|
|
|
|
warnx("gen set beyond 32-bit range of field (0x%lx), max is 0x%x\n",
|
|
|
|
gen, UINT_MAX);
|
1995-11-03 22:38:54 +00:00
|
|
|
return(1);
|
|
|
|
}
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_gen, gen);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 21:58:19 +00:00
|
|
|
CMDFUNCSTART(chsize)
|
|
|
|
{
|
|
|
|
off_t size;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
size = strtoll(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
warnx("bad size `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < 0) {
|
|
|
|
warnx("size set to negative (%jd)\n", (intmax_t)size);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
DIP_SET(curinode, di_size, size);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2019-02-25 21:58:19 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
2019-02-25 21:58:19 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 05:42:32 +00:00
|
|
|
CMDFUNC(chdb)
|
|
|
|
{
|
|
|
|
unsigned int idx;
|
|
|
|
daddr_t bno;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
idx = strtoull(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
warnx("bad pointer idx `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bno = strtoll(argv[2], &cp, 0);
|
|
|
|
if (cp == argv[2] || *cp != '\0') {
|
|
|
|
warnx("bad block number `%s'", argv[2]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (idx >= UFS_NDADDR) {
|
|
|
|
warnx("pointer index %d is out of range", idx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIP_SET(curinode, di_db[idx], bno);
|
|
|
|
inodirty(&curip);
|
|
|
|
printactive(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNCSTART(linkcount)
|
|
|
|
{
|
|
|
|
int lcnt;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
lcnt = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' ) {
|
|
|
|
warnx("bad link count `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (lcnt > USHRT_MAX || lcnt < 0) {
|
|
|
|
warnx("max link count is %d\n", USHRT_MAX);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_nlink, lcnt);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chowner)
|
|
|
|
{
|
|
|
|
unsigned long uid;
|
|
|
|
char *cp;
|
|
|
|
struct passwd *pwd;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
uid = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' ) {
|
|
|
|
/* try looking up name */
|
1998-06-15 07:12:20 +00:00
|
|
|
if ((pwd = getpwnam(argv[1]))) {
|
1995-11-03 22:38:54 +00:00
|
|
|
uid = pwd->pw_uid;
|
|
|
|
} else {
|
|
|
|
warnx("bad uid `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_uid, uid);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chgroup)
|
|
|
|
{
|
|
|
|
unsigned long gid;
|
|
|
|
char *cp;
|
|
|
|
struct group *grp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
gid = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' ) {
|
1998-06-15 07:12:20 +00:00
|
|
|
if ((grp = getgrnam(argv[1]))) {
|
1995-11-03 22:38:54 +00:00
|
|
|
gid = grp->gr_gid;
|
|
|
|
} else {
|
|
|
|
warnx("bad gid `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_gid, gid);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
Have fsdb(8) only mark a filesystem dirty when it is modified.
Until this update, the fsdb(8) command always marked a filesystem
as needing a full fsck unless it was run with the -n flag which
allowed no changes to be made.
This change tracks modifications to the filesystem. Two types of
changes are tracked. The first type of changes are those that are
not critical to the integrity of the filesystem such as changes to
owner, group, time stamps, access mode, and generation number. The
second type of changes are those that do affect the integrity of
the filesystem including zeroing inodes, changing block pointers,
directory entries, link counts, file lengths, file types, and file
flags.
When quitting having made no changes or only changes to data that
is not critical to filesystem integrity, the clean state of the
filesystem is left unchanged. But if filesystem critical data are
changed then fsdb will set the unclean flag which will require a
full fsck to be run before the filesystem can be mounted.
MFC-after: 1 week
Sponsored-by: The FreeBSD Foundation
2023-07-26 02:27:59 +00:00
|
|
|
return 0;
|
1995-11-03 22:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-06-21 06:18:05 +00:00
|
|
|
dotime(char *name, time_t *secp, int32_t *nsecp)
|
1995-11-03 22:38:54 +00:00
|
|
|
{
|
|
|
|
char *p, *val;
|
|
|
|
struct tm t;
|
|
|
|
int32_t nsec;
|
|
|
|
p = strchr(name, '.');
|
|
|
|
if (p) {
|
|
|
|
*p = '\0';
|
|
|
|
nsec = strtoul(++p, &val, 0);
|
|
|
|
if (val == p || *val != '\0' || nsec >= 1000000000 || nsec < 0) {
|
|
|
|
warnx("invalid nanoseconds");
|
|
|
|
goto badformat;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
nsec = 0;
|
|
|
|
if (strlen(name) != 14) {
|
|
|
|
badformat:
|
|
|
|
warnx("date format: YYYYMMDDHHMMSS[.nsec]");
|
|
|
|
return 1;
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
*nsecp = nsec;
|
1995-11-03 22:38:54 +00:00
|
|
|
|
|
|
|
for (p = name; *p; p++)
|
|
|
|
if (*p < '0' || *p > '9')
|
|
|
|
goto badformat;
|
|
|
|
|
|
|
|
p = name;
|
|
|
|
#define VAL() ((*p++) - '0')
|
|
|
|
t.tm_year = VAL();
|
|
|
|
t.tm_year = VAL() + t.tm_year * 10;
|
|
|
|
t.tm_year = VAL() + t.tm_year * 10;
|
|
|
|
t.tm_year = VAL() + t.tm_year * 10 - 1900;
|
|
|
|
t.tm_mon = VAL();
|
|
|
|
t.tm_mon = VAL() + t.tm_mon * 10 - 1;
|
|
|
|
t.tm_mday = VAL();
|
|
|
|
t.tm_mday = VAL() + t.tm_mday * 10;
|
|
|
|
t.tm_hour = VAL();
|
|
|
|
t.tm_hour = VAL() + t.tm_hour * 10;
|
|
|
|
t.tm_min = VAL();
|
|
|
|
t.tm_min = VAL() + t.tm_min * 10;
|
|
|
|
t.tm_sec = VAL();
|
|
|
|
t.tm_sec = VAL() + t.tm_sec * 10;
|
|
|
|
t.tm_isdst = -1;
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
*secp = mktime(&t);
|
|
|
|
if (*secp == -1) {
|
1995-11-03 22:38:54 +00:00
|
|
|
warnx("date/time out of range");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-23 22:44:00 +00:00
|
|
|
CMDFUNCSTART(chbtime)
|
|
|
|
{
|
|
|
|
time_t secs;
|
|
|
|
int32_t nsecs;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &secs, &nsecs))
|
|
|
|
return 1;
|
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
|
|
|
return 1;
|
|
|
|
curinode->dp2.di_birthtime = _time_to_time64(secs);
|
|
|
|
curinode->dp2.di_birthnsec = nsecs;
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2006-08-23 22:44:00 +00:00
|
|
|
printactive(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-11-03 22:38:54 +00:00
|
|
|
CMDFUNCSTART(chmtime)
|
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
time_t secs;
|
|
|
|
int32_t nsecs;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &secs, &nsecs))
|
1995-11-03 22:38:54 +00:00
|
|
|
return 1;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
|
|
|
curinode->dp1.di_mtime = _time_to_time32(secs);
|
|
|
|
else
|
|
|
|
curinode->dp2.di_mtime = _time_to_time64(secs);
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_mtimensec, nsecs);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chatime)
|
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
time_t secs;
|
|
|
|
int32_t nsecs;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &secs, &nsecs))
|
1995-11-03 22:38:54 +00:00
|
|
|
return 1;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
|
|
|
curinode->dp1.di_atime = _time_to_time32(secs);
|
|
|
|
else
|
|
|
|
curinode->dp2.di_atime = _time_to_time64(secs);
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_atimensec, nsecs);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chctime)
|
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
time_t secs;
|
|
|
|
int32_t nsecs;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &secs, &nsecs))
|
1995-11-03 22:38:54 +00:00
|
|
|
return 1;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
|
|
|
curinode->dp1.di_ctime = _time_to_time32(secs);
|
|
|
|
else
|
|
|
|
curinode->dp2.di_ctime = _time_to_time64(secs);
|
2004-10-09 15:56:34 +00:00
|
|
|
DIP_SET(curinode, di_ctimensec, nsecs);
|
2021-01-07 01:37:08 +00:00
|
|
|
inodirty(&curip);
|
2002-01-26 15:53:23 +00:00
|
|
|
printactive(0);
|
1995-11-03 22:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|