From nobody Sat Aug 5 06:19:22 2023 X-Original-To: dev-commits-src-branches@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 4RHsqb3JMhz4pjJW; Sat, 5 Aug 2023 06:19:23 +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 4RHsqb0pQ1z4cXQ; Sat, 5 Aug 2023 06:19:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691216363; 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=shQNRNcrV2M2GHFLh9cPx8gHsR2oWL11h6FYMTCkrlM=; b=ZvbS5gCWDbqjYUvSqoQj3PHVRk8JCkl3Gh8uox17AJUm4viXnfRKr6fC7Hxn6fJdv6HLdV c60VUQA+eBBayMiAbCEFADjyXarUHdu5bUSh0ityW58I8p58kFRVZFBP+UJLutneoZm5av tnZdwxoaW9CqAYO4JuSufF6EkU1Y2yAli/8YGo6UCFPxYh78X5sV8rKvWen3w+pt9nMa6s Lnbm5knrLtQDPd+v+PzMK5e3mWSqzOAcWthr87O/Y/BF2lBIhWTjtps8GJXua2RrWCiSHp vcVEkL94BCbU18trDLxpq/w1HNrfCj+wM8SiSd3k+hJSTKgQCmzlTW1PERan5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691216363; 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=shQNRNcrV2M2GHFLh9cPx8gHsR2oWL11h6FYMTCkrlM=; b=W53twepJT5UY37PZDvKZ6SrRlate9zvnijfI9OtvxOE3bjw/wtMGAHJE0QkQXw0uNqx6ec URe1h8pRcoxHnCpsnxtA+VOBX2FGEAR6dZ9RQldqxtyq/qa9Q67x45Bqbp6f42aNNQuMcf 0PQR60sEPg0dM9/k3KRFMB/Qb3NsPf5v6GF0SLEnXtMVXsglGYX3Qk321SG4O/Pmt+bJgN kDjdylBOhc5xPeRInM61bveLq8cZkb/Wh1fAn4X4u2ZCdwR1oGRqZwYVttulpxrpCo6xI4 HuApSLJvJhh3EOORXWXZZAkuPWigWLr0hAyTPNKT44Az9bLdt2XMbe1bpa42/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691216363; a=rsa-sha256; cv=none; b=FO6+SMQSKHQsJTjumdUdG6fbUAhyskcoCdMsOnoT79ZXD7T6Nxsm0DpWxuMUAK7HBjnmuc fub3FQtJ/THbhyEhj3SFAi4YpVoDIIEJD2h/gZn7dWbnT5AddzM9YLwbvrM7slb7PHl7tg +/OfIVbdaOQ6mZR/4tCL63t/sqbXUqzaxOlyc8fezN+8w8R1+0MpRR8mnvXufqKF9iI1b/ lWY0nUZUCDPJiJ0Qa8ksOkQ/ZFFGF1bzeEKF7rPaRgHvNTGj8elnaFCd2XvLOwz2FJ637e ga/oxA8NZVvS/13PeJHKTIJZqP7BaC11rVeJHmSR48yv2DEW9jE1Ju2e1eYWiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RHsqZ70Zmz3xv; Sat, 5 Aug 2023 06:19:22 +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 3756JM9S011420; Sat, 5 Aug 2023 06:19:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3756JMqe011419; Sat, 5 Aug 2023 06:19:22 GMT (envelope-from git) Date: Sat, 5 Aug 2023 06:19:22 GMT Message-Id: <202308050619.3756JMqe011419@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: bcbb927b97cb - stable/13 - Have fsdb(8) only mark a filesystem dirty when it is modified. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: bcbb927b97cb27cf6309c540ea7100fdbdccf048 Auto-Submitted: auto-generated The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=bcbb927b97cb27cf6309c540ea7100fdbdccf048 commit bcbb927b97cb27cf6309c540ea7100fdbdccf048 Author: Kirk McKusick AuthorDate: 2023-07-26 02:27:59 +0000 Commit: Kirk McKusick CommitDate: 2023-08-05 06:17:30 +0000 Have fsdb(8) only mark a filesystem dirty when it is modified. Sponsored-by: The FreeBSD Foundation (cherry picked from commit d51bdf327d9381807cbeffead1ed3cc466bdb87b) --- 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 f907ea160a16..c80d4b65a830 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;