From owner-svn-src-head@freebsd.org Tue Sep 3 14:06:50 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 05B23DCFD5; Tue, 3 Sep 2019 14:06:50 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N7zs0CKmz4Pwv; Tue, 3 Sep 2019 14:06:49 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 3D78D1AC06; Tue, 3 Sep 2019 14:06:18 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 1B91C6180; Sat, 13 Apr 2019 13:31:12 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48F6783FE8; Sat, 13 Apr 2019 13:31:11 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 1ED31610E; Sat, 13 Apr 2019 13:31:11 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 1E97F610C for ; Sat, 13 Apr 2019 13:31:08 +0000 (UTC) (envelope-from mckusick@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E0DB583FD8; Sat, 13 Apr 2019 13:31:07 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BDE0098A2; Sat, 13 Apr 2019 13:31:07 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3DDV7nE014478; Sat, 13 Apr 2019 13:31:07 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3DDV7w1014475; Sat, 13 Apr 2019 13:31:07 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201904131331.x3DDV7w1014475@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346185 - head/sbin/fsck_ffs X-SVN-Group: head X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: head/sbin/fsck_ffs X-SVN-Commit-Revision: 346185 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 48F6783FE8 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.94)[-0.940,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:06:50 -0000 X-Original-Date: Sat, 13 Apr 2019 13:31:07 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:06:50 -0000 Author: mckusick Date: Sat Apr 13 13:31:06 2019 New Revision: 346185 URL: https://svnweb.freebsd.org/changeset/base/346185 Log: Followup to -r344552 in which fsck_ffs checks for a size past the last allocated block of the file and if that is found, shortens the file to reference the last allocated block thus avoiding having it reference a hole at its end. This update corrects an error where fsck_ffs miscalculated the last logical block of the file when the file contained a large hole. Reported by: Jamie Landeg-Jones Tested by: Peter Holm MFC after: 2 weeks Sponsored by: Netflix Modified: head/sbin/fsck_ffs/fsck.h head/sbin/fsck_ffs/inode.c head/sbin/fsck_ffs/pass1.c Modified: head/sbin/fsck_ffs/fsck.h ============================================================================== --- head/sbin/fsck_ffs/fsck.h Sat Apr 13 12:50:47 2019 (r346184) +++ head/sbin/fsck_ffs/fsck.h Sat Apr 13 13:31:06 2019 (r346185) @@ -231,6 +231,7 @@ struct inodesc { ino_t id_parent; /* for DATA nodes, their parent */ ufs_lbn_t id_lbn; /* logical block number of current block */ ufs2_daddr_t id_blkno; /* current block number being examined */ + int id_level; /* level of indirection of this block */ int id_numfrags; /* number of frags contained in block */ ufs_lbn_t id_lballoc; /* pass1: last LBN that is allocated */ off_t id_filesize; /* for DATA nodes, the size of the directory */ Modified: head/sbin/fsck_ffs/inode.c ============================================================================== --- head/sbin/fsck_ffs/inode.c Sat Apr 13 12:50:47 2019 (r346184) +++ head/sbin/fsck_ffs/inode.c Sat Apr 13 13:31:06 2019 (r346185) @@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$"); static ino_t startinum; -static int iblock(struct inodesc *, long ilevel, off_t isize, int type); +static int iblock(struct inodesc *, off_t isize, int type); int ckinode(union dinode *dp, struct inodesc *idesc) @@ -70,6 +70,8 @@ ckinode(union dinode *dp, struct inodesc *idesc) if (idesc->id_fix != IGNORE) idesc->id_fix = DONTKNOW; idesc->id_lbn = -1; + idesc->id_lballoc = -1; + idesc->id_level = 0; idesc->id_entryno = 0; idesc->id_filesize = DIP(dp, di_size); mode = DIP(dp, di_mode) & IFMT; @@ -122,9 +124,10 @@ ckinode(union dinode *dp, struct inodesc *idesc) sizepb = sblock.fs_bsize; for (i = 0; i < UFS_NIADDR; i++) { sizepb *= NINDIR(&sblock); + idesc->id_level = i + 1; if (DIP(&dino, di_ib[i])) { idesc->id_blkno = DIP(&dino, di_ib[i]); - ret = iblock(idesc, i + 1, remsize, BT_LEVEL1 + i); + ret = iblock(idesc, remsize, BT_LEVEL1 + i); if (ret & STOP) return (ret); } else if (remsize > 0) { @@ -154,7 +157,7 @@ ckinode(union dinode *dp, struct inodesc *idesc) } static int -iblock(struct inodesc *idesc, long ilevel, off_t isize, int type) +iblock(struct inodesc *idesc, off_t isize, int type) { struct bufarea *bp; int i, n, (*func)(struct inodesc *), nif; @@ -172,8 +175,8 @@ iblock(struct inodesc *idesc, long ilevel, off_t isize if (chkrange(idesc->id_blkno, idesc->id_numfrags)) return (SKIP); bp = getdatablk(idesc->id_blkno, sblock.fs_bsize, type); - ilevel--; - for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++) + idesc->id_level--; + for (sizepb = sblock.fs_bsize, i = 0; i < idesc->id_level; i++) sizepb *= NINDIR(&sblock); if (howmany(isize, sizepb) > NINDIR(&sblock)) nif = NINDIR(&sblock); @@ -195,19 +198,21 @@ iblock(struct inodesc *idesc, long ilevel, off_t isize flush(fswritefd, bp); } for (i = 0; i < nif; i++) { - if (ilevel == 0) - idesc->id_lbn++; if (IBLK(bp, i)) { idesc->id_blkno = IBLK(bp, i); - if (ilevel == 0) + if (idesc->id_level == 0) { + idesc->id_lbn++; n = (*func)(idesc); - else - n = iblock(idesc, ilevel, isize, type); + } else { + n = iblock(idesc, isize, type); + idesc->id_level++; + } if (n & STOP) { bp->b_flags &= ~B_INUSE; return (n); } } else { + idesc->id_lbn += sizepb / sblock.fs_bsize; if (idesc->id_type == DATA && isize > 0) { /* An empty block in a directory XXX */ getpathname(pathbuf, idesc->id_number, Modified: head/sbin/fsck_ffs/pass1.c ============================================================================== --- head/sbin/fsck_ffs/pass1.c Sat Apr 13 12:50:47 2019 (r346184) +++ head/sbin/fsck_ffs/pass1.c Sat Apr 13 13:31:06 2019 (r346185) @@ -378,7 +378,6 @@ checkinode(ino_t inumber, struct inodesc *idesc, int r idesc->id_type = SNAP; else idesc->id_type = ADDR; - idesc->id_lballoc = -1; (void)ckinode(dp, idesc); if (sblock.fs_magic == FS_UFS2_MAGIC && dp->dp2.di_extsize > 0) { idesc->id_type = ADDR; @@ -565,7 +564,7 @@ pass1check(struct inodesc *idesc) */ idesc->id_entryno++; } - if (idesc->id_lballoc == -1 || idesc->id_lballoc < idesc->id_lbn) + if (idesc->id_level == 0 && idesc->id_lballoc < idesc->id_lbn) idesc->id_lballoc = idesc->id_lbn; return (res); }