From nobody Wed Jul 26 02:29:30 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R9dBy6ft3z4p5vr; Wed, 26 Jul 2023 02:29:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R9dBy6F42z3rkf; Wed, 26 Jul 2023 02:29:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690338570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vscnDcEzkKBP8eosk4QVhZe8GMsLdXkzkcW+MCyyPq4=; b=WUW+/ZJJ3SSy9nWinr9c+6gQ92aTojJBU8UxW1S+7E1OrafvTR2UOUFqVPEG35PADPRv8T izjq83E4gcORpWrRZJGD/3ykMEfV9J4346xDRIEMYju1EbOiktIBuJWrkfwm5IkKACFN9g j1BGwEI2k21QdixFpnqc33Ws0c8XbbQtbf9x3lJQ8k87QeAM81xzjHvA2smt8ky5dPFwl6 ig/zUIMwmK88YxRilJyrCUJUmwlwE2U/G3BJvPWFgJS8AtKOsBIEF1Kl+7qdL2+OARCHtx 6oKCbtuOS4enuXE1nuUvFijz2dcPItWCRD1kRh+XwbgUo4ymfgrH3dRlUkgHQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1690338570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vscnDcEzkKBP8eosk4QVhZe8GMsLdXkzkcW+MCyyPq4=; b=NfvYaTUoWrYjEN30zR07s/UiwIqIR2vHS5lR9dINN0cS31xQvkDhjsRhg5HCXXoQMnBqte VbwNZnVLwOynUD/gHdYmFhfOCkJsCoTepOYY7Gg8HdY4bqySbQeq1jyTJJ4WUXG135qC3X OnM8vxDwFlJWU6NLRyNOtNIxrESYYdcgZUYccX8KDijQ1aG28Snfzi+SGn+MjC2Xy1u60q WJYuS9n3GJcWTD3LJMMXOkWCP0gSrvh1id4wNgPV8tmT5auOkHk/9Bv2lhEJEPbwrWO7YY jbUDSIeWb2RJrxjNub6PJ/96+O8ukp/vCU/t3CyvR6Y7oNrA0Vr5IMyXRJyJvg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1690338570; a=rsa-sha256; cv=none; b=U6nvNhIiTXKvAOu83f6RXJDqzPjtOTLAevMiRjp87TQXGE+9zjQNrjUeBYfl+nsBo18DuF NSgh3r2KB3syDRotI8N6fQH4S9mjFRhAovmtsCwG7MdZ3cS8q6GcMs/Z6zubwSlLO+qYnb hF6n1brQ8MXsrTJu2fvg0AYkXhXpIJZcDQxBAhy2QuZtp4VLfTEmhnQ7aiUsJk58vULsyq 10aD7CHe8Xg6IywcIXjq4hOKyblU+qe9Z1qgStfYStX/0nYjf66TOzFWevU6qv7Lyue8kT ayHKKOgfGbDRlV+yh46RgR48F751sy4RMxDcnRQWlO+SSjSghpx/yhdLnnOlqA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R9dBy5HjyzQJ5; Wed, 26 Jul 2023 02:29:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36Q2TU7c027309; Wed, 26 Jul 2023 02:29:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36Q2TUIS027308; Wed, 26 Jul 2023 02:29:30 GMT (envelope-from git) Date: Wed, 26 Jul 2023 02:29:30 GMT Message-Id: <202307260229.36Q2TUIS027308@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: d51bdf327d93 - main - Have fsdb(8) only mark a filesystem dirty when it is modified. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d51bdf327d9381807cbeffead1ed3cc466bdb87b Auto-Submitted: auto-generated The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=d51bdf327d9381807cbeffead1ed3cc466bdb87b commit d51bdf327d9381807cbeffead1ed3cc466bdb87b Author: Kirk McKusick AuthorDate: 2023-07-26 02:27:59 +0000 Commit: Kirk McKusick CommitDate: 2023-07-26 02:29:05 +0000 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 --- sbin/fsdb/fsdb.c | 109 +++++++++++++++++++++++++++---------------------------- sbin/fsdb/fsdb.h | 3 +- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index 887a77dbb8cb..ceb4a884e885 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -63,6 +63,23 @@ 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); +/* + * 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 */ struct inode curip; union dinode *curinode; ino_t curinum, ocurrent; @@ -119,9 +136,13 @@ main(int argc, char *argv[]) nflag? "Examining": "Editing", fsys, sblock.fs_fsmnt); rval = cmdloop(); if (!nflag) { - sblock.fs_clean = 0; /* mark it dirty */ - sbdirty(); - ckfini(0); + if (fscritmodified != 0) { + sblock.fs_clean = 0; /* mark it dirty */ + sbdirty(); + } + ckfini(fscritmodified ? 0 : sblock.fs_clean); + if (fscritmodified == 0) + exit(0); printf("*** FILE SYSTEM MARKED DIRTY\n"); printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); printf("*** IF IT IS MOUNTED, RE-MOUNT WITH -u -o reload\n"); @@ -167,36 +188,35 @@ struct cmdtable cmds[] = { { "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 }, - { "clri", "Clear inode INUM", 2, 2, FL_WR, zapi }, + { "clri", "Clear inode INUM", 2, 2, FL_CWR, zapi }, { "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 }, { "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 }, { "blocks", "Print block numbers of active inode", 1, 1, FL_RO, blocks }, - { "uplink", "Increment link count", 1, 1, FL_WR, uplink }, - { "downlink", "Decrement link count", 1, 1, FL_WR, downlink }, - { "linkcount", "Set link count to COUNT", 2, 2, FL_WR, linkcount }, + { "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 }, { "findblk", "Find inode owning disk block(s)", 2, 33, FL_RO, findblk}, { "ls", "List current inode as directory", 1, 1, FL_RO, ls }, - { "rm", "Remove NAME from current inode directory", 2, 2, FL_WR | FL_ST, rm }, - { "del", "Remove NAME from current inode directory", 2, 2, FL_WR | FL_ST, rm }, - { "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR | FL_ST, ln }, - { "chinum", "Change dir entry number INDEX to INUM", 3, 3, FL_WR, chinum }, + { "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 }, { "chname", "Change dir entry number INDEX to NAME", 3, 3, FL_WR | FL_ST, chname }, - { "chtype", "Change type of current inode to TYPE", 2, 2, FL_WR, newtype }, + { "chtype", "Change type of current inode to TYPE", 2, 2, FL_CWR, newtype }, { "chmod", "Change mode of current inode to MODE", 2, 2, FL_WR, chmode }, - { "chlen", "Change length of current inode to LENGTH", 2, 2, FL_WR, chlen }, { "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 }, - { "chflags", "Change flags of current inode to FLAGS", 2, 2, FL_WR, chaflags }, + { "chflags", "Change flags of current inode to FLAGS", 2, 2, FL_CWR, chaflags }, { "chgen", "Change generation number of current inode to GEN", 2, 2, FL_WR, chgen }, - { "chsize", "Change size of current inode to SIZE", 2, 2, FL_WR, chsize }, + { "chsize", "Change size of current inode to SIZE", 2, 2, FL_CWR, chsize }, { "btime", "Change btime of current inode to BTIME", 2, 2, FL_WR, chbtime }, { "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 }, - { "chdb", "Change db pointer N of current inode to BLKNO", 3, 3, FL_WR, chdb }, + { "chdb", "Change db pointer N of current inode to BLKNO", 3, 3, FL_CWR, chdb }, { "quit", "Exit", 1, 1, FL_RO, quit }, { "q", "Exit", 1, 1, FL_RO, quit }, { "exit", "Exit", 1, 1, FL_RO, quit }, @@ -280,7 +300,7 @@ cmdloop(void) known = 0; for (cmdp = cmds; cmdp->cmd; cmdp++) { if (!strcmp(cmdp->cmd, cmd_argv[0])) { - if ((cmdp->flags & FL_WR) == FL_WR && nflag) + if ((cmdp->flags & (FL_CWR | FL_WR)) != 0 && nflag) warnx("`%s' requires write access", cmd_argv[0]), rval = 1; else if (cmd_argc >= cmdp->minargc && @@ -294,6 +314,12 @@ cmdloop(void) } else rval = argcount(cmdp, cmd_argc, cmd_argv); known = 1; + if (rval == 0) { + if ((cmdp->flags & FL_WR) != 0) + fsnoncritmodified = 1; + if ((cmdp->flags & FL_CWR) != 0) + fscritmodified = 1; + } break; } } @@ -308,7 +334,7 @@ cmdloop(void) return 0; } if (rval) - warnx("rval was %d", rval); + warnx("command failed, return value was %d", rval); } el_end(elptr); history_end(hist); @@ -930,30 +956,8 @@ CMDFUNCSTART(newtype) return 0; } -CMDFUNCSTART(chlen) -{ - int rval = 1; - long len; - char *cp; - - if (!checkactive()) - return 1; - - len = strtol(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' || len < 0) { - warnx("bad length `%s'", argv[1]); - return 1; - } - - DIP_SET(curinode, di_size, len); - inodirty(&curip); - printactive(0); - return rval; -} - CMDFUNCSTART(chmode) { - int rval = 1; long modebits; char *cp; @@ -970,12 +974,11 @@ CMDFUNCSTART(chmode) DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | modebits); inodirty(&curip); printactive(0); - return rval; + return 0; } CMDFUNCSTART(chaflags) { - int rval = 1; u_long flags; char *cp; @@ -995,12 +998,11 @@ CMDFUNCSTART(chaflags) DIP_SET(curinode, di_flags, flags); inodirty(&curip); printactive(0); - return rval; + return 0; } CMDFUNCSTART(chgen) { - int rval = 1; long gen; char *cp; @@ -1013,19 +1015,19 @@ CMDFUNCSTART(chgen) return 1; } - if (gen > INT_MAX || gen < INT_MIN) { - warnx("gen set beyond 32-bit range of field (%lx)\n", gen); + if (gen > UINT_MAX) { + warnx("gen set beyond 32-bit range of field (0x%lx), max is 0x%x\n", + gen, UINT_MAX); return(1); } DIP_SET(curinode, di_gen, gen); inodirty(&curip); printactive(0); - return rval; + return 0; } CMDFUNCSTART(chsize) { - int rval = 1; off_t size; char *cp; @@ -1045,7 +1047,7 @@ CMDFUNCSTART(chsize) DIP_SET(curinode, di_size, size); inodirty(&curip); printactive(0); - return rval; + return 0; } CMDFUNC(chdb) @@ -1080,7 +1082,6 @@ CMDFUNC(chdb) CMDFUNCSTART(linkcount) { - int rval = 1; int lcnt; char *cp; @@ -1100,12 +1101,11 @@ CMDFUNCSTART(linkcount) DIP_SET(curinode, di_nlink, lcnt); inodirty(&curip); printactive(0); - return rval; + return 0; } CMDFUNCSTART(chowner) { - int rval = 1; unsigned long uid; char *cp; struct passwd *pwd; @@ -1127,12 +1127,11 @@ CMDFUNCSTART(chowner) DIP_SET(curinode, di_uid, uid); inodirty(&curip); printactive(0); - return rval; + return 0; } CMDFUNCSTART(chgroup) { - int rval = 1; unsigned long gid; char *cp; struct group *grp; @@ -1153,7 +1152,7 @@ CMDFUNCSTART(chgroup) DIP_SET(curinode, di_gid, gid); inodirty(&curip); printactive(0); - return rval; + return 0; } int diff --git a/sbin/fsdb/fsdb.h b/sbin/fsdb/fsdb.h index fee35886f675..d13caa3c0e93 100644 --- a/sbin/fsdb/fsdb.h +++ b/sbin/fsdb/fsdb.h @@ -49,7 +49,8 @@ struct cmdtable { unsigned int flags; #define FL_RO 0x0000 /* for symmetry */ #define FL_WR 0x0001 /* wants to write */ -#define FL_ST 0x0002 /* resplit final string if argc > maxargc */ +#define FL_CWR 0x0002 /* wants to write critical data */ +#define FL_ST 0x0003 /* resplit final string if argc > maxargc */ int (*handler)(int argc, char *argv[]); }; extern struct inode curip;