From nobody Sun Dec 11 00:38:20 2022 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 4NV5TS6g8Zz4jglG; Sun, 11 Dec 2022 00:38:20 +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 4NV5TS6BVgz4HVq; Sun, 11 Dec 2022 00:38:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670719100; 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=8vMEeIbeSsTLn3NcUGSqGRm8kVB5ka55ddzet9ng7Ik=; b=NzHxK90lfxp464DrxBPEQwQYHbH4NvTg3777g52XWzMI1F1G7z1mhvzROTylPIupibiTYe usDUG68Kh6mZWseSOSknmSw0QmPfJ6xHribVGMbeprFcf5F6lgzeynA5727poa7gJ2mqhe 716/b3NuLe4vj9Q2meZWxcVWO/3AP/3ZCCRx+GrKJNUFmvycbf3uPBDx8+c7KhbrgREyIC fdCRXc5TGRp3m1aczs1w43ueqBGPqqKDQCERqvadEqTFizkyZiwy1OyB1iVVKDUZZtfApW RMTWCXTnqJsruQDTwVB4UiQCSpYLEqMYnJe7G03cJ0RClM/orPj27+ZssMWVzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670719100; 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=8vMEeIbeSsTLn3NcUGSqGRm8kVB5ka55ddzet9ng7Ik=; b=XzetwW/Ts/UpSY2fSgA/SWQXQNErtjdVa3DO4KpClV53ceZym0IkC60xBmvfHmxyYZghCI SYzSyncwENw8DMa/eGOj1qKN35oA6q5zBoF2sxbY60FlGKsgoKGI9LEOpPKy3UkRdL0A2G d3ITAX6MB8mMuquL6kxmbVKAhiAXWhIR43p1F1EiYpvQSDSusBegCB+0+90TvXUKyQks0k GIeF6pOX3ZPSrEz0V7PKzN/+A71H+Aslf5Lfxm7gjQlclFndD8OjFojTQ36qkm3rIppY0h tRRJgo/PX87ZdWqc6tmIwPG/BLM1GsGRfH7SpeL1TN8qYx054PnvceNFROHc7w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670719100; a=rsa-sha256; cv=none; b=PFA+P6RaPhDHdE6HLU0ybi8gBCAQYHKn2FjeSPot222GfJnbNW+95G4IOrcerOBeo8P7UL urSB8BMa9F0XFZco6pWuVXmxPHty0Xm6R2S3+cgs5qxmP/jRtZlZrrsZAVqSCJU1SARag7 XK+rXZGaiPP/DnbrGyF1lJpBxQWPMCP7KvhF4JwO11/VUbO8wcF4BtviGw4XJAETGnX0Ls m2po8+s9CXzFchj9wg4WJJs6VvIx+JXgh9aIf/i9yz16UQcpr/Ujp5hNdecccWdAI88ziT T58DDdeq8/94weNvCmzzRS1NalCpcgrqnCL9YzxURdWVY82fPxcFO2sS8MU+/A== 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 4NV5TS4r7dzbgh; Sun, 11 Dec 2022 00:38:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BB0cKSV003975; Sun, 11 Dec 2022 00:38:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BB0cK8v003974; Sun, 11 Dec 2022 00:38:20 GMT (envelope-from git) Date: Sun, 11 Dec 2022 00:38:20 GMT Message-Id: <202212110038.2BB0cK8v003974@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: a8d7958cef10 - stable/13 - Properly handle the replacement of a partially allocated root directory. 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: a8d7958cef1031a2860c7f1f41a4b4ae09d78b23 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=a8d7958cef1031a2860c7f1f41a4b4ae09d78b23 commit a8d7958cef1031a2860c7f1f41a4b4ae09d78b23 Author: Kirk McKusick AuthorDate: 2022-09-03 21:46:50 +0000 Commit: Kirk McKusick CommitDate: 2022-12-11 00:37:17 +0000 Properly handle the replacement of a partially allocated root directory. (cherry picked from commit f4fc3895243b9a8ae0577e731a3e450377071196) (cherry picked from commit 2aa6ed881d22e4ed095d04ecb8a11f178274a644) (cherry picked from commit 2567b60f62534bf5b243972f85b4921bba837439) Sponsored by: The FreeBSD Foundation --- sbin/fsck_ffs/dir.c | 18 +++++++++++++----- sbin/fsck_ffs/fsck.h | 8 +++++++- sbin/fsck_ffs/inode.c | 7 +++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index 42ecf4112253..ba286a965513 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -474,6 +474,7 @@ linkup(ino_t orphan, ino_t parentdir, char *name) union dinode *dp; int lostdir; ino_t oldlfdir; + struct inoinfo *inp; struct inodesc idesc; char tempname[BUFSIZ]; @@ -581,10 +582,13 @@ linkup(ino_t orphan, ino_t parentdir, char *name) inodirty(&ip); inoinfo(lfdir)->ino_linkcnt++; pwarn("DIR I=%lu CONNECTED. ", (u_long)orphan); - if (parentdir != (ino_t)-1) { + inp = getinoinfo(parentdir); + if (parentdir != (ino_t)-1 && inp != NULL && + (inp->i_flags & INFO_NEW) == 0) { printf("PARENT WAS I=%lu\n", (u_long)parentdir); /* - * The parent directory, because of the ordering + * If the parent directory did not have to + * be replaced then because of the ordering * guarantees, has had the link count incremented * for the child, but no entry was made. This * fixes the parent link count so that fsck does @@ -823,7 +827,12 @@ allocdir(ino_t parent, ino_t request, int mode) inodirty(&ip); if (ino == UFS_ROOTINO) { inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink); - cacheino(dp, ino); + if ((inp = getinoinfo(ino)) == NULL) + inp = cacheino(dp, ino); + else + inp->i_flags = INFO_NEW; + inp->i_parent = parent; + inp->i_dotdot = parent; irelse(&ip); return(ino); } @@ -832,8 +841,7 @@ allocdir(ino_t parent, ino_t request, int mode) irelse(&ip); return (0); } - cacheino(dp, ino); - inp = getinoinfo(ino); + inp = cacheino(dp, ino); inp->i_parent = parent; inp->i_dotdot = parent; inoinfo(ino)->ino_state = inoinfo(parent)->ino_state; diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 1fb0df0c5124..1d3f9b7943ec 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -311,9 +311,15 @@ extern struct inoinfo { ino_t i_parent; /* inode number of parent */ ino_t i_dotdot; /* inode number of `..' */ size_t i_isize; /* size of inode */ + u_int i_flags; /* flags, see below */ u_int i_numblks; /* size of block array in bytes */ ufs2_daddr_t i_blks[1]; /* actually longer */ } **inphead, **inpsort; +/* + * flags for struct inoinfo + */ +#define INFO_NEW 0x0000001 /* replaced broken directory */ + extern long dirhash, inplast; extern unsigned long numdirs, listmax; extern long countdirs; /* number of directories we actually found */ @@ -447,7 +453,7 @@ void blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size); void blerase(int fd, ufs2_daddr_t blk, long size); void blzero(int fd, ufs2_daddr_t blk, long size); void brelse(struct bufarea *); -void cacheino(union dinode *dp, ino_t inumber); +struct inoinfo *cacheino(union dinode *dp, ino_t inumber); void catch(int); void catchquit(int); void cgdirty(struct bufarea *); diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index f0699aabe349..c9b4a80b50fb 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -698,12 +698,15 @@ freeinodebuf(void) * * Enter inodes into the cache. */ -void +struct inoinfo * cacheino(union dinode *dp, ino_t inumber) { struct inoinfo *inp, **inpp; int i, blks; + if (getinoinfo(inumber) != NULL) + pfatal("cacheino: duplicate entry for ino %ld\n", + (intmax_t)inumber); if (howmany(DIP(dp, di_size), sblock.fs_bsize) > UFS_NDADDR) blks = UFS_NDADDR + UFS_NIADDR; else if (DIP(dp, di_size) > 0) @@ -735,6 +738,7 @@ cacheino(union dinode *dp, ino_t inumber) errx(EEXIT, "cannot increase directory list"); } inpsort[inplast++] = inp; + return (inp); } /* @@ -750,7 +754,6 @@ getinoinfo(ino_t inumber) continue; return (inp); } - errx(EEXIT, "cannot find inode %ju", (uintmax_t)inumber); return ((struct inoinfo *)0); }