Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src ufs: fixed signed/unsigned bugs affecting large file systems



details:   https://anonhg.NetBSD.org/src/rev/b99ef69aebc5
branches:  trunk
changeset: 372954:b99ef69aebc5
user:      chs <chs%NetBSD.org@localhost>
date:      Sat Jan 07 19:41:29 2023 +0000

description:
ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

  commit e870d1e6f97cc73308c11c40684b775bcfa906a2
  Author: Kirk McKusick <mckusick%FreeBSD.org@localhost>
  Date:   Wed Feb 10 20:10:35 2010 +0000

    This fix corrects a problem in the file system that treats large
    inode numbers as negative rather than unsigned. For a default
    (16K block) file system, this bug began to show up at a file system
    size above about 16Tb.

    To fully handle this problem, newfs must be updated to ensure that
    it will never create a filesystem with more than 2^32 inodes. That
    patch will be forthcoming soon.

    Reported by: Scott Burns, John Kilburg, Bruce Evans
    Followup by: Jeff Roberson
    PR:          133980
    MFC after:   2 weeks

  commit 81479e688b0f643ffacd3f335b4b4bba460b769d
  Author: Kirk McKusick <mckusick%FreeBSD.org@localhost>
  Date:   Thu Feb 11 18:14:53 2010 +0000

    One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.

diffstat:

 sbin/fsck_ffs/main.c             |   6 +-
 sbin/fsck_ffs/pass1.c            |   6 +-
 sbin/fsck_ffs/pass1b.c           |   6 +-
 sbin/fsck_ffs/pass4.c            |   7 +-
 sbin/fsck_ffs/pass5.c            |  13 ++--
 sbin/fsck_ffs/setup.c            |   6 +-
 sbin/fsdb/fsdb.c                 |   7 +-
 sbin/newfs/mkfs.c                |  16 +++---
 sbin/resize_ffs/resize_ffs.c     |  35 +++++++-------
 sbin/tunefs/tunefs.c             |  12 ++--
 sys/ufs/ffs/ffs_alloc.c          |  97 +++++++++++++++++++++------------------
 sys/ufs/ffs/ffs_extern.h         |   4 +-
 sys/ufs/ffs/ffs_subr.c           |   6 +-
 sys/ufs/ffs/fs.h                 |  54 +++++++++++-----------
 usr.sbin/dumpfs/dumpfs.c         |  16 +++--
 usr.sbin/makefs/Makefile         |   4 +-
 usr.sbin/makefs/ffs.c            |   6 +-
 usr.sbin/makefs/ffs/ffs_alloc.c  |  18 +++---
 usr.sbin/makefs/ffs/ffs_extern.h |   4 +-
 usr.sbin/makefs/ffs/mkfs.c       |  20 ++++---
 usr.sbin/quotacheck/quotacheck.c |   7 +-
 21 files changed, 183 insertions(+), 167 deletions(-)

diffs (truncated from 1199 to 300 lines):

diff -r 34453587314d -r b99ef69aebc5 sbin/fsck_ffs/main.c
--- a/sbin/fsck_ffs/main.c      Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsck_ffs/main.c      Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.90 2022/11/17 06:40:38 chs Exp $    */
+/*     $NetBSD: main.c,v 1.91 2023/01/07 19:41:29 chs Exp $    */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 5/14/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.90 2022/11/17 06:40:38 chs Exp $");
+__RCSID("$NetBSD: main.c,v 1.91 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -368,7 +368,7 @@
        daddr_t n_ffree, n_bfree;
        struct dups *dp;
        struct zlncnt *zlnp;
-       int cylno;
+       uint32_t cylno;
 #ifdef LITE2BORKEN
        int flags;
 #endif
diff -r 34453587314d -r b99ef69aebc5 sbin/fsck_ffs/pass1.c
--- a/sbin/fsck_ffs/pass1.c     Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsck_ffs/pass1.c     Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pass1.c,v 1.62 2022/11/18 07:41:31 martin Exp $        */
+/*     $NetBSD: pass1.c,v 1.63 2023/01/07 19:41:29 chs Exp $   */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pass1.c    8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: pass1.c,v 1.62 2022/11/18 07:41:31 martin Exp $");
+__RCSID("$NetBSD: pass1.c,v 1.63 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -68,7 +68,7 @@
 {
        ino_t inumber, inosused, ninosused, ii;
        size_t inospace;
-       int c;
+       uint32_t c;
        daddr_t i, cgd;
        struct inodesc idesc;
        struct cg *cgp = cgrp;
diff -r 34453587314d -r b99ef69aebc5 sbin/fsck_ffs/pass1b.c
--- a/sbin/fsck_ffs/pass1b.c    Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsck_ffs/pass1b.c    Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pass1b.c,v 1.23 2013/01/22 09:39:12 dholland Exp $     */
+/*     $NetBSD: pass1b.c,v 1.24 2023/01/07 19:41:29 chs Exp $  */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pass1b.c   8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: pass1b.c,v 1.23 2013/01/22 09:39:12 dholland Exp $");
+__RCSID("$NetBSD: pass1b.c,v 1.24 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -56,7 +56,7 @@
 void
 pass1b(void)
 {
-       int c, i;
+       uint32_t c, i;
        union dinode *dp;
        struct inodesc idesc;
        ino_t inumber;
diff -r 34453587314d -r b99ef69aebc5 sbin/fsck_ffs/pass4.c
--- a/sbin/fsck_ffs/pass4.c     Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsck_ffs/pass4.c     Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pass4.c,v 1.28 2013/06/23 22:03:34 dholland Exp $      */
+/*     $NetBSD: pass4.c,v 1.29 2023/01/07 19:41:29 chs Exp $   */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pass4.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: pass4.c,v 1.28 2013/06/23 22:03:34 dholland Exp $");
+__RCSID("$NetBSD: pass4.c,v 1.29 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -62,7 +62,8 @@
        struct zlncnt *zlnp;
        union dinode *dp;
        struct inodesc idesc;
-       int n, i, cg;
+       int n, i;
+       uint32_t cg;
        struct inostat *info;
 
        memset(&idesc, 0, sizeof(struct inodesc));
diff -r 34453587314d -r b99ef69aebc5 sbin/fsck_ffs/pass5.c
--- a/sbin/fsck_ffs/pass5.c     Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsck_ffs/pass5.c     Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pass5.c,v 1.55 2022/11/17 06:40:38 chs Exp $   */
+/*     $NetBSD: pass5.c,v 1.56 2023/01/07 19:41:29 chs Exp $   */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pass5.c    8.9 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: pass5.c,v 1.55 2022/11/17 06:40:38 chs Exp $");
+__RCSID("$NetBSD: pass5.c,v 1.56 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,8 +59,9 @@
 void
 pass5(void)
 {
-       int c, blk, frags, basesize, sumsize, mapsize, cssize;
+       int blk, frags, basesize, sumsize, mapsize, cssize;
        int inomapsize, blkmapsize;
+       uint32_t c;
        struct fs *fs = sblock;
        daddr_t dbase, dmax;
        daddr_t d;
@@ -290,15 +291,15 @@
                newcg->cg_cs.cs_nffree = 0;
                newcg->cg_cs.cs_nbfree = 0;
                newcg->cg_cs.cs_nifree = fs->fs_ipg;
-               if (cg->cg_rotor >= 0 && cg->cg_rotor < newcg->cg_ndblk)
+               if (cg->cg_rotor < newcg->cg_ndblk)
                        newcg->cg_rotor = cg->cg_rotor;
                else
                        newcg->cg_rotor = 0;
-               if (cg->cg_frotor >= 0 && cg->cg_frotor < newcg->cg_ndblk)
+               if (cg->cg_frotor < newcg->cg_ndblk)
                        newcg->cg_frotor = cg->cg_frotor;
                else
                        newcg->cg_frotor = 0;
-               if (cg->cg_irotor >= 0 && cg->cg_irotor < fs->fs_ipg)
+               if (cg->cg_irotor < fs->fs_ipg)
                        newcg->cg_irotor = cg->cg_irotor;
                else
                        newcg->cg_irotor = 0;
diff -r 34453587314d -r b99ef69aebc5 sbin/fsck_ffs/setup.c
--- a/sbin/fsck_ffs/setup.c     Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsck_ffs/setup.c     Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setup.c,v 1.104 2022/11/17 06:40:38 chs Exp $  */
+/*     $NetBSD: setup.c,v 1.105 2023/01/07 19:41:29 chs Exp $  */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)setup.c    8.10 (Berkeley) 5/9/95";
 #else
-__RCSID("$NetBSD: setup.c,v 1.104 2022/11/17 06:40:38 chs Exp $");
+__RCSID("$NetBSD: setup.c,v 1.105 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -1150,7 +1150,7 @@
 check_snapinum(void)
 {
        int loc, loc2, res;
-       int *snapinum = &sblock->fs_snapinum[0];
+       uint32_t *snapinum = &sblock->fs_snapinum[0];
 
        res = 0;
  
diff -r 34453587314d -r b99ef69aebc5 sbin/fsdb/fsdb.c
--- a/sbin/fsdb/fsdb.c  Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/fsdb/fsdb.c  Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fsdb.c,v 1.53 2022/11/17 06:40:38 chs Exp $    */
+/*     $NetBSD: fsdb.c,v 1.54 2023/01/07 19:41:29 chs Exp $    */
 
 /*-
  * Copyright (c) 1996, 2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fsdb.c,v 1.53 2022/11/17 06:40:38 chs Exp $");
+__RCSID("$NetBSD: fsdb.c,v 1.54 2023/01/07 19:41:29 chs Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -620,7 +620,8 @@
        uint32_t *wantedblk32 = NULL;
        uint64_t *wantedblk64 = NULL;
        struct cg *cgp = cgrp;
-       int i, c;
+       int i;
+       uint32_t c;
 
        ocurrent = curinum;
        wantedblksize = (argc - 1);
diff -r 34453587314d -r b99ef69aebc5 sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/newfs/mkfs.c Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs.c,v 1.132 2022/11/17 06:40:39 chs Exp $   */
+/*     $NetBSD: mkfs.c,v 1.133 2023/01/07 19:41:29 chs Exp $   */
 
 /*
  * Copyright (c) 1980, 1989, 1993
@@ -73,7 +73,7 @@
 #if 0
 static char sccsid[] = "@(#)mkfs.c     8.11 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: mkfs.c,v 1.132 2022/11/17 06:40:39 chs Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.133 2023/01/07 19:41:29 chs Exp $");
 #endif
 #endif /* not lint */
 
@@ -108,7 +108,7 @@
        struct ufs2_dinode dp2;
 };
 
-static void initcg(int, const struct timeval *);
+static void initcg(uint32_t, const struct timeval *);
 static int fsinit(const struct timeval *, mode_t, uid_t, gid_t);
 union Buffer;
 static int makedir(union Buffer *, struct direct *, int);
@@ -184,7 +184,8 @@
        uint fragsperinodeblk, ncg, u;
        uint cgzero;
        uint64_t inodeblks, cgall;
-       int32_t cylno, i, csfrags;
+       uint32_t cylno;
+       int i, csfrags;
        int inodes_per_cg;
        struct timeval tv;
        long long sizepb;
@@ -773,11 +774,10 @@
  * Initialize a cylinder group.
  */
 void
-initcg(int cylno, const struct timeval *tv)
+initcg(uint32_t cylno, const struct timeval *tv)
 {
        daddr_t cbase, dmax;
-       int32_t i, d, dlower, dupper, blkno;
-       uint32_t u;
+       uint32_t i, d, dlower, dupper, blkno, u;
        struct ufs1_dinode *dp1;
        struct ufs2_dinode *dp2;
        int start;
@@ -849,7 +849,7 @@
                acg.cg_nextfreeoff = acg.cg_clusteroff +
                    howmany(ffs_fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
        }
-       if (acg.cg_nextfreeoff > sblock.fs_cgsize) {
+       if (acg.cg_nextfreeoff > (unsigned)sblock.fs_cgsize) {
                printf("Panic: cylinder group too big\n");
                fserr(37);
        }
diff -r 34453587314d -r b99ef69aebc5 sbin/resize_ffs/resize_ffs.c
--- a/sbin/resize_ffs/resize_ffs.c      Sat Jan 07 15:00:04 2023 +0000
+++ b/sbin/resize_ffs/resize_ffs.c      Sat Jan 07 19:41:29 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize_ffs.c,v 1.57 2022/11/17 06:40:39 chs Exp $      */
+/*     $NetBSD: resize_ffs.c,v 1.58 2023/01/07 19:41:30 chs Exp $      */
 /* From sources sent on February 17, 2003 */
 /*-
  * As its sole author, I explicitly place this code in the public
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: resize_ffs.c,v 1.57 2022/11/17 06:40:39 chs Exp $");
+__RCSID("$NetBSD: resize_ffs.c,v 1.58 2023/01/07 19:41:30 chs Exp $");
 
 #include <sys/disk.h>
 #include <sys/disklabel.h>
@@ -327,7 +327,7 @@
 static void
 loadcgs(void)
 {
-       int cg;
+       uint32_t cg;
        char *cgp;
 
        cgblksz = roundup(oldsb->fs_cgsize, oldsb->fs_fsize);
@@ -460,7 +460,7 @@



Home | Main Index | Thread Index | Old Index