ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

  commit e870d1e6f97cc73308c11c40684b775bcfa906a2
  Author: Kirk McKusick <mckusick@FreeBSD.org>
  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>
  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.
This commit is contained in:
chs 2023-01-07 19:41:29 +00:00
parent 9ff0ed4038
commit f298a94b73
21 changed files with 183 additions and 167 deletions

View File

@ -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 * Copyright (c) 1980, 1986, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95"; static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -368,7 +368,7 @@ checkfilesys(const char *filesys, const char *origfs, int child)
daddr_t n_ffree, n_bfree; daddr_t n_ffree, n_bfree;
struct dups *dp; struct dups *dp;
struct zlncnt *zlnp; struct zlncnt *zlnp;
int cylno; uint32_t cylno;
#ifdef LITE2BORKEN #ifdef LITE2BORKEN
int flags; int flags;
#endif #endif

View File

@ -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 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)pass1.c 8.6 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)pass1.c 8.6 (Berkeley) 4/28/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -68,7 +68,7 @@ pass1(void)
{ {
ino_t inumber, inosused, ninosused, ii; ino_t inumber, inosused, ninosused, ii;
size_t inospace; size_t inospace;
int c; uint32_t c;
daddr_t i, cgd; daddr_t i, cgd;
struct inodesc idesc; struct inodesc idesc;
struct cg *cgp = cgrp; struct cg *cgp = cgrp;

View File

@ -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 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)pass1b.c 8.4 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)pass1b.c 8.4 (Berkeley) 4/28/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -56,7 +56,7 @@ static int pass1bcheck(struct inodesc *);
void void
pass1b(void) pass1b(void)
{ {
int c, i; uint32_t c, i;
union dinode *dp; union dinode *dp;
struct inodesc idesc; struct inodesc idesc;
ino_t inumber; ino_t inumber;

View File

@ -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 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)pass4.c 8.4 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)pass4.c 8.4 (Berkeley) 4/28/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -62,7 +62,8 @@ pass4(void)
struct zlncnt *zlnp; struct zlncnt *zlnp;
union dinode *dp; union dinode *dp;
struct inodesc idesc; struct inodesc idesc;
int n, i, cg; int n, i;
uint32_t cg;
struct inostat *info; struct inostat *info;
memset(&idesc, 0, sizeof(struct inodesc)); memset(&idesc, 0, sizeof(struct inodesc));

View File

@ -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 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -59,8 +59,9 @@ void print_bmap(u_char *,u_int32_t);
void void
pass5(void) pass5(void)
{ {
int c, blk, frags, basesize, sumsize, mapsize, cssize; int blk, frags, basesize, sumsize, mapsize, cssize;
int inomapsize, blkmapsize; int inomapsize, blkmapsize;
uint32_t c;
struct fs *fs = sblock; struct fs *fs = sblock;
daddr_t dbase, dmax; daddr_t dbase, dmax;
daddr_t d; daddr_t d;
@ -290,15 +291,15 @@ pass5(void)
newcg->cg_cs.cs_nffree = 0; newcg->cg_cs.cs_nffree = 0;
newcg->cg_cs.cs_nbfree = 0; newcg->cg_cs.cs_nbfree = 0;
newcg->cg_cs.cs_nifree = fs->fs_ipg; 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; newcg->cg_rotor = cg->cg_rotor;
else else
newcg->cg_rotor = 0; 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; newcg->cg_frotor = cg->cg_frotor;
else else
newcg->cg_frotor = 0; 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; newcg->cg_irotor = cg->cg_irotor;
else else
newcg->cg_irotor = 0; newcg->cg_irotor = 0;

View File

@ -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 * Copyright (c) 1980, 1986, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -1150,7 +1150,7 @@ static int
check_snapinum(void) check_snapinum(void)
{ {
int loc, loc2, res; int loc, loc2, res;
int *snapinum = &sblock->fs_snapinum[0]; uint32_t *snapinum = &sblock->fs_snapinum[0];
res = 0; res = 0;

View File

@ -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. * Copyright (c) 1996, 2017 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #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 */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
@ -620,7 +620,8 @@ CMDFUNC(findblk)
uint32_t *wantedblk32 = NULL; uint32_t *wantedblk32 = NULL;
uint64_t *wantedblk64 = NULL; uint64_t *wantedblk64 = NULL;
struct cg *cgp = cgrp; struct cg *cgp = cgrp;
int i, c; int i;
uint32_t c;
ocurrent = curinum; ocurrent = curinum;
wantedblksize = (argc - 1); wantedblksize = (argc - 1);

View File

@ -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 * Copyright (c) 1980, 1989, 1993
@ -73,7 +73,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else #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
#endif /* not lint */ #endif /* not lint */
@ -108,7 +108,7 @@ union dinode {
struct ufs2_dinode dp2; 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); static int fsinit(const struct timeval *, mode_t, uid_t, gid_t);
union Buffer; union Buffer;
static int makedir(union Buffer *, struct direct *, int); static int makedir(union Buffer *, struct direct *, int);
@ -184,7 +184,8 @@ mkfs(const char *fsys, int fi, int fo,
uint fragsperinodeblk, ncg, u; uint fragsperinodeblk, ncg, u;
uint cgzero; uint cgzero;
uint64_t inodeblks, cgall; uint64_t inodeblks, cgall;
int32_t cylno, i, csfrags; uint32_t cylno;
int i, csfrags;
int inodes_per_cg; int inodes_per_cg;
struct timeval tv; struct timeval tv;
long long sizepb; long long sizepb;
@ -773,11 +774,10 @@ mkfs(const char *fsys, int fi, int fo,
* Initialize a cylinder group. * Initialize a cylinder group.
*/ */
void void
initcg(int cylno, const struct timeval *tv) initcg(uint32_t cylno, const struct timeval *tv)
{ {
daddr_t cbase, dmax; daddr_t cbase, dmax;
int32_t i, d, dlower, dupper, blkno; uint32_t i, d, dlower, dupper, blkno, u;
uint32_t u;
struct ufs1_dinode *dp1; struct ufs1_dinode *dp1;
struct ufs2_dinode *dp2; struct ufs2_dinode *dp2;
int start; int start;
@ -849,7 +849,7 @@ initcg(int cylno, const struct timeval *tv)
acg.cg_nextfreeoff = acg.cg_clusteroff + acg.cg_nextfreeoff = acg.cg_clusteroff +
howmany(ffs_fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT); 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"); printf("Panic: cylinder group too big\n");
fserr(37); fserr(37);
} }

View File

@ -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 */ /* From sources sent on February 17, 2003 */
/*- /*-
* As its sole author, I explicitly place this code in the public * As its sole author, I explicitly place this code in the public
@ -36,7 +36,7 @@
*/ */
#include <sys/cdefs.h> #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/disk.h>
#include <sys/disklabel.h> #include <sys/disklabel.h>
@ -327,7 +327,7 @@ alloconce(size_t nb, const char *tag)
static void static void
loadcgs(void) loadcgs(void)
{ {
int cg; uint32_t cg;
char *cgp; char *cgp;
cgblksz = roundup(oldsb->fs_cgsize, oldsb->fs_fsize); cgblksz = roundup(oldsb->fs_cgsize, oldsb->fs_fsize);
@ -460,7 +460,7 @@ blk_is_clr(unsigned char *bitvec, int blkbase, int blkfrags)
* bit simpler than it would otherwise be. * bit simpler than it would otherwise be.
*/ */
static void static void
initcg(int cgn) initcg(uint32_t cgn)
{ {
struct cg *cg; /* The in-core cg, of course */ struct cg *cg; /* The in-core cg, of course */
int64_t base; /* Disk address of cg base */ int64_t base; /* Disk address of cg base */
@ -658,7 +658,7 @@ find_freespace(unsigned int nfrags)
{ {
static int hand = 0; /* hand rotates through all frags in the fs */ static int hand = 0; /* hand rotates through all frags in the fs */
int cgsize; /* size of the cg hand currently points into */ int cgsize; /* size of the cg hand currently points into */
int cgn; /* number of cg hand currently points into */ uint32_t cgn; /* number of cg hand currently points into */
int fwc; /* frag-within-cg number of frag hand points int fwc; /* frag-within-cg number of frag hand points
* to */ * to */
unsigned int run; /* length of run of free frags seen so far */ unsigned int run; /* length of run of free frags seen so far */
@ -711,7 +711,7 @@ static int
find_freeblock(void) find_freeblock(void)
{ {
static int hand = 0; /* hand rotates through all frags in fs */ static int hand = 0; /* hand rotates through all frags in fs */
int cgn; /* cg number of cg hand points into */ uint32_t cgn; /* cg number of cg hand points into */
int fwc; /* frag-within-cg number of frag hand points int fwc; /* frag-within-cg number of frag hand points
* to */ * to */
int cgsize; /* size of cg hand points into */ int cgsize; /* size of cg hand points into */
@ -754,8 +754,8 @@ static int
find_freeinode(void) find_freeinode(void)
{ {
static int hand = 0; /* hand rotates through all inodes in fs */ static int hand = 0; /* hand rotates through all inodes in fs */
int cgn; /* cg number of cg hand points into */ uint32_t cgn; /* cg number of cg hand points into */
int iwc; /* inode-within-cg number of inode hand points uint32_t iwc; /* inode-within-cg number of inode hand points
* to */ * to */
int secondpass; /* have we wrapped from end to beginning? */ int secondpass; /* have we wrapped from end to beginning? */
unsigned char *bits; /* cg_inosused()[] for cg hand points into */ unsigned char *bits; /* cg_inosused()[] for cg hand points into */
@ -895,7 +895,7 @@ csum_fixup(void)
static void static void
recompute_fs_dsize(void) recompute_fs_dsize(void)
{ {
int i; uint32_t i;
newsb->fs_dsize = 0; newsb->fs_dsize = 0;
for (i = 0; i < newsb->fs_ncg; i++) { for (i = 0; i < newsb->fs_ncg; i++) {
@ -986,7 +986,7 @@ makegeometry(int chatter)
static void static void
grow(void) grow(void)
{ {
int i; uint32_t i;
if (makegeometry(1)) { if (makegeometry(1)) {
printf("New fs size %"PRIu64" = old fs size %"PRIu64 printf("New fs size %"PRIu64" = old fs size %"PRIu64
@ -1252,7 +1252,8 @@ blkmove_init(void)
static void static void
loadinodes(void) loadinodes(void)
{ {
int imax, ino, i, j; int imax, ino, j;
uint32_t i;
struct ufs1_dinode *dp1 = NULL; struct ufs1_dinode *dp1 = NULL;
struct ufs2_dinode *dp2 = NULL; struct ufs2_dinode *dp2 = NULL;
@ -1641,8 +1642,8 @@ static void
evict_inodes(struct cg * cg) evict_inodes(struct cg * cg)
{ {
int inum; int inum;
int i;
int fi; int fi;
uint32_t i;
inum = newsb->fs_ipg * cg->cg_cgx; inum = newsb->fs_ipg * cg->cg_cgx;
for (i = 0; i < newsb->fs_ipg; i++, inum++) { for (i = 0; i < newsb->fs_ipg; i++, inum++) {
@ -1751,7 +1752,7 @@ update_for_inode_move(void)
static void static void
shrink(void) shrink(void)
{ {
int i; uint32_t i;
if (makegeometry(1)) { if (makegeometry(1)) {
printf("New fs size %"PRIu64" = old fs size %"PRIu64 printf("New fs size %"PRIu64" = old fs size %"PRIu64
@ -1864,7 +1865,7 @@ static void
rescan_blkmaps(int cgn) rescan_blkmaps(int cgn)
{ {
struct cg *cg; struct cg *cg;
int f; uint32_t f;
int b; int b;
int blkfree; int blkfree;
int blkrun; int blkrun;
@ -1983,7 +1984,7 @@ rescan_inomaps(int cgn)
{ {
struct cg *cg; struct cg *cg;
int inum; int inum;
int iwc; uint32_t iwc;
cg = cgs[cgn]; cg = cgs[cgn];
newsb->fs_cstotal.cs_ndir -= cg->cg_cs.cs_ndir; newsb->fs_cstotal.cs_ndir -= cg->cg_cs.cs_ndir;
@ -2023,7 +2024,7 @@ rescan_inomaps(int cgn)
static void static void
flush_cgs(void) flush_cgs(void)
{ {
int i; uint32_t i;
for (i = 0; i < newsb->fs_ncg; i++) { for (i = 0; i < newsb->fs_ncg; i++) {
progress_bar(special, "flush cg", progress_bar(special, "flush cg",
@ -2057,7 +2058,7 @@ flush_cgs(void)
static void static void
write_sbs(void) write_sbs(void)
{ {
int i; uint32_t i;
if (newsb->fs_magic == FS_UFS1_MAGIC && if (newsb->fs_magic == FS_UFS1_MAGIC &&
(newsb->fs_old_flags & FS_FLAGS_UPDATED) == 0) { (newsb->fs_old_flags & FS_FLAGS_UPDATED) == 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: tunefs.c,v 1.57 2022/12/19 21:13:16 chs Exp $ */ /* $NetBSD: tunefs.c,v 1.58 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)tunefs.c 8.3 (Berkeley) 5/3/95"; static char sccsid[] = "@(#)tunefs.c 8.3 (Berkeley) 5/3/95";
#else #else
__RCSID("$NetBSD: tunefs.c,v 1.57 2022/12/19 21:13:16 chs Exp $"); __RCSID("$NetBSD: tunefs.c,v 1.58 2023/01/07 19:41:30 chs Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -62,6 +62,7 @@ __RCSID("$NetBSD: tunefs.c,v 1.57 2022/12/19 21:13:16 chs Exp $");
#include <fcntl.h> #include <fcntl.h>
#include <fstab.h> #include <fstab.h>
#include <paths.h> #include <paths.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -103,11 +104,12 @@ __dead static void usage(void);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i, ch, aflag, pflag, Aflag, Fflag, Nflag, openflags; int ch, aflag, pflag, Aflag, Fflag, Nflag, openflags;
const char *special, *chg[2]; const char *special, *chg[2];
char device[MAXPATHLEN]; char device[MAXPATHLEN];
int maxbpg, minfree, optim, secsize; int maxbpg, minfree, optim, secsize;
int avgfilesize, avgfpdir, active; uint32_t i, avgfilesize, avgfpdir;
bool active;
long long logfilesize; long long logfilesize;
int secshift, fsbtodb; int secshift, fsbtodb;
const char *avalue, *pvalue, *name; const char *avalue, *pvalue, *name;
@ -241,7 +243,7 @@ main(int argc, char *argv[])
getsb(&sblock, special); getsb(&sblock, special);
#define CHANGEVAL(old, new, type, suffix) do \ #define CHANGEVAL(old, new, type, suffix) do \
if ((new) != -1) { \ if ((uint32_t)(new) != (uint32_t)-1) { \
if ((new) == (old)) \ if ((new) == (old)) \
warnx("%s remains unchanged at %d%s", \ warnx("%s remains unchanged at %d%s", \
(type), (old), (suffix)); \ (type), (old), (suffix)); \

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_alloc.c,v 1.171 2022/04/23 16:22:23 hannken Exp $ */ /* $NetBSD: ffs_alloc.c,v 1.172 2023/01/07 19:41:30 chs Exp $ */
/*- /*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -70,7 +70,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.171 2022/04/23 16:22:23 hannken Exp $"); __KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.172 2023/01/07 19:41:30 chs Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_ffs.h" #include "opt_ffs.h"
@ -107,14 +107,14 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.171 2022/04/23 16:22:23 hannken Exp
#include <uvm/uvm_page.h> #include <uvm/uvm_page.h>
#endif #endif
static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int, int, int); static daddr_t ffs_alloccg(struct inode *, u_int, daddr_t, int, int, int);
static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int, int); static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int, int);
static ino_t ffs_dirpref(struct inode *); static ino_t ffs_dirpref(struct inode *);
static daddr_t ffs_fragextend(struct inode *, int, daddr_t, int, int); static daddr_t ffs_fragextend(struct inode *, u_int, daddr_t, int, int);
static void ffs_fserr(struct fs *, kauth_cred_t, const char *); static void ffs_fserr(struct fs *, kauth_cred_t, const char *);
static daddr_t ffs_hashalloc(struct inode *, int, daddr_t, int, int, int, static daddr_t ffs_hashalloc(struct inode *, u_int, daddr_t, int, int, int,
daddr_t (*)(struct inode *, int, daddr_t, int, int, int)); daddr_t (*)(struct inode *, u_int, daddr_t, int, int, int));
static daddr_t ffs_nodealloccg(struct inode *, int, daddr_t, int, int, int); static daddr_t ffs_nodealloccg(struct inode *, u_int, daddr_t, int, int, int);
static int32_t ffs_mapsearch(struct fs *, struct cg *, static int32_t ffs_mapsearch(struct fs *, struct cg *,
daddr_t, int); daddr_t, int);
static void ffs_blkfree_common(struct ufsmount *, struct fs *, dev_t, struct buf *, static void ffs_blkfree_common(struct ufsmount *, struct fs *, dev_t, struct buf *,
@ -179,7 +179,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size,
struct ufsmount *ump; struct ufsmount *ump;
struct fs *fs; struct fs *fs;
daddr_t bno; daddr_t bno;
int cg; u_int cg;
#if defined(QUOTA) || defined(QUOTA2) #if defined(QUOTA) || defined(QUOTA2)
int error; int error;
#endif #endif
@ -311,7 +311,8 @@ ffs_realloccg(struct inode *ip, daddr_t lbprev, daddr_t bprev, daddr_t bpref,
struct ufsmount *ump; struct ufsmount *ump;
struct fs *fs; struct fs *fs;
struct buf *bp; struct buf *bp;
int cg, request, error; u_int cg, request;
int error;
daddr_t bno; daddr_t bno;
fs = ip->i_fs; fs = ip->i_fs;
@ -571,7 +572,8 @@ ffs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred, ino_t *inop)
struct inode *pip; struct inode *pip;
struct fs *fs; struct fs *fs;
ino_t ino, ipref; ino_t ino, ipref;
int cg, error; u_int cg;
int error;
UFS_WAPBL_JUNLOCK_ASSERT(pvp->v_mount); UFS_WAPBL_JUNLOCK_ASSERT(pvp->v_mount);
@ -637,12 +639,12 @@ static ino_t
ffs_dirpref(struct inode *pip) ffs_dirpref(struct inode *pip)
{ {
register struct fs *fs; register struct fs *fs;
int cg, prefcg; u_int cg, prefcg;
int64_t dirsize, cgsize, curdsz; uint64_t dirsize, cgsize, curdsz;
int avgifree, avgbfree, avgndir; u_int avgifree, avgbfree, avgndir;
int minifree, minbfree, maxndir; u_int minifree, minbfree, maxndir;
int mincg, minndir; u_int mincg, minndir;
int maxcontigdirs; u_int maxcontigdirs;
KASSERT(mutex_owned(&pip->i_ump->um_lock)); KASSERT(mutex_owned(&pip->i_ump->um_lock));
@ -770,8 +772,8 @@ ffs_blkpref_ufs1(struct inode *ip, daddr_t lbn, int indx, int flags,
int32_t *bap /* XXX ondisk32 */) int32_t *bap /* XXX ondisk32 */)
{ {
struct fs *fs; struct fs *fs;
int cg; u_int cg;
int avgbfree, startcg; u_int avgbfree, startcg;
KASSERT(mutex_owned(&ip->i_ump->um_lock)); KASSERT(mutex_owned(&ip->i_ump->um_lock));
@ -834,8 +836,8 @@ ffs_blkpref_ufs2(struct inode *ip, daddr_t lbn, int indx, int flags,
int64_t *bap) int64_t *bap)
{ {
struct fs *fs; struct fs *fs;
int cg; u_int cg;
int avgbfree, startcg; u_int avgbfree, startcg;
KASSERT(mutex_owned(&ip->i_ump->um_lock)); KASSERT(mutex_owned(&ip->i_ump->um_lock));
@ -908,15 +910,15 @@ ffs_blkpref_ufs2(struct inode *ip, daddr_t lbn, int indx, int flags,
*/ */
/*VARARGS5*/ /*VARARGS5*/
static daddr_t static daddr_t
ffs_hashalloc(struct inode *ip, int cg, daddr_t pref, ffs_hashalloc(struct inode *ip, u_int cg, daddr_t pref,
int size /* size for data blocks, mode for inodes */, int size /* size for data blocks, mode for inodes */,
int realsize, int realsize,
int flags, int flags,
daddr_t (*allocator)(struct inode *, int, daddr_t, int, int, int)) daddr_t (*allocator)(struct inode *, u_int, daddr_t, int, int, int))
{ {
struct fs *fs; struct fs *fs;
daddr_t result; daddr_t result;
int i, icg = cg; u_int i, icg = cg;
fs = ip->i_fs; fs = ip->i_fs;
/* /*
@ -966,7 +968,7 @@ ffs_hashalloc(struct inode *ip, int cg, daddr_t pref,
* => returns with um_lock released on success, held on failure * => returns with um_lock released on success, held on failure
*/ */
static daddr_t static daddr_t
ffs_fragextend(struct inode *ip, int cg, daddr_t bprev, int osize, int nsize) ffs_fragextend(struct inode *ip, u_int cg, daddr_t bprev, int osize, int nsize)
{ {
struct ufsmount *ump; struct ufsmount *ump;
struct fs *fs; struct fs *fs;
@ -1046,7 +1048,7 @@ ffs_fragextend(struct inode *ip, int cg, daddr_t bprev, int osize, int nsize)
* and if it is, allocate it. * and if it is, allocate it.
*/ */
static daddr_t static daddr_t
ffs_alloccg(struct inode *ip, int cg, daddr_t bpref, int size, int realsize, ffs_alloccg(struct inode *ip, u_int cg, daddr_t bpref, int size, int realsize,
int flags) int flags)
{ {
struct ufsmount *ump; struct ufsmount *ump;
@ -1257,7 +1259,7 @@ gotit:
* inode in the specified cylinder group. * inode in the specified cylinder group.
*/ */
static daddr_t static daddr_t
ffs_nodealloccg(struct inode *ip, int cg, daddr_t ipref, int mode, int realsize, ffs_nodealloccg(struct inode *ip, u_int cg, daddr_t ipref, int mode, int realsize,
int flags) int flags)
{ {
struct ufsmount *ump = ip->i_ump; struct ufsmount *ump = ip->i_ump;
@ -1416,7 +1418,7 @@ gotit:
bwrite(bp); bwrite(bp);
} else } else
bdwrite(bp); bdwrite(bp);
return (cg * fs->fs_ipg + ipref); return ((ino_t)(cg * fs->fs_ipg + ipref));
fail: fail:
if (bp != NULL) if (bp != NULL)
brelse(bp, 0); brelse(bp, 0);
@ -1456,7 +1458,8 @@ ffs_blkalloc_ump(struct ufsmount *ump, daddr_t bno, long size)
struct cg *cgp; struct cg *cgp;
struct buf *bp; struct buf *bp;
int32_t fragno, cgbno; int32_t fragno, cgbno;
int i, error, cg, blk, frags, bbase; int i, error, blk, frags, bbase;
u_int cg;
u_int8_t *blksfree; u_int8_t *blksfree;
const int needswap = UFS_FSNEEDSWAP(fs); const int needswap = UFS_FSNEEDSWAP(fs);
@ -1560,7 +1563,8 @@ ffs_blkfree_cg(struct fs *fs, struct vnode *devvp, daddr_t bno, long size)
struct buf *bp; struct buf *bp;
struct ufsmount *ump; struct ufsmount *ump;
daddr_t cgblkno; daddr_t cgblkno;
int error, cg; int error;
u_int cg;
dev_t dev; dev_t dev;
const bool devvp_is_snapshot = (devvp->v_type != VBLK); const bool devvp_is_snapshot = (devvp->v_type != VBLK);
const int needswap = UFS_FSNEEDSWAP(fs); const int needswap = UFS_FSNEEDSWAP(fs);
@ -1870,7 +1874,8 @@ ffs_blkfree_common(struct ufsmount *ump, struct fs *fs, dev_t dev,
{ {
struct cg *cgp; struct cg *cgp;
int32_t fragno, cgbno; int32_t fragno, cgbno;
int i, cg, blk, frags, bbase; int i, blk, frags, bbase;
u_int cg;
u_int8_t *blksfree; u_int8_t *blksfree;
const int needswap = UFS_FSNEEDSWAP(fs); const int needswap = UFS_FSNEEDSWAP(fs);
@ -1993,7 +1998,8 @@ ffs_freefile(struct mount *mp, ino_t ino, int mode)
struct vnode *devvp; struct vnode *devvp;
struct cg *cgp; struct cg *cgp;
struct buf *bp; struct buf *bp;
int error, cg; int error;
u_int cg;
daddr_t cgbno; daddr_t cgbno;
dev_t dev; dev_t dev;
const int needswap = UFS_FSNEEDSWAP(fs); const int needswap = UFS_FSNEEDSWAP(fs);
@ -2003,7 +2009,7 @@ ffs_freefile(struct mount *mp, ino_t ino, int mode)
dev = devvp->v_rdev; dev = devvp->v_rdev;
cgbno = FFS_FSBTODB(fs, cgtod(fs, cg)); cgbno = FFS_FSBTODB(fs, cgtod(fs, cg));
if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg) if (ino >= fs->fs_ipg * fs->fs_ncg)
panic("%s: range: dev = 0x%llx, ino = %llu, fs = %s", __func__, panic("%s: range: dev = 0x%llx, ino = %llu, fs = %s", __func__,
(long long)dev, (unsigned long long)ino, fs->fs_fsmnt); (long long)dev, (unsigned long long)ino, fs->fs_fsmnt);
error = bread(devvp, cgbno, (int)fs->fs_cgsize, error = bread(devvp, cgbno, (int)fs->fs_cgsize,
@ -2041,7 +2047,7 @@ ffs_freefile_snap(struct fs *fs, struct vnode *devvp, ino_t ino, int mode)
dev = VTOI(devvp)->i_devvp->v_rdev; dev = VTOI(devvp)->i_devvp->v_rdev;
ump = VFSTOUFS(devvp->v_mount); ump = VFSTOUFS(devvp->v_mount);
cgbno = ffs_fragstoblks(fs, cgtod(fs, cg)); cgbno = ffs_fragstoblks(fs, cgtod(fs, cg));
if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg) if (ino >= fs->fs_ipg * fs->fs_ncg)
panic("%s: range: dev = 0x%llx, ino = %llu, fs = %s", __func__, panic("%s: range: dev = 0x%llx, ino = %llu, fs = %s", __func__,
(unsigned long long)dev, (unsigned long long)ino, (unsigned long long)dev, (unsigned long long)ino,
fs->fs_fsmnt); fs->fs_fsmnt);
@ -2066,10 +2072,11 @@ static void
ffs_freefile_common(struct ufsmount *ump, struct fs *fs, dev_t dev, ffs_freefile_common(struct ufsmount *ump, struct fs *fs, dev_t dev,
struct buf *bp, ino_t ino, int mode, bool devvp_is_snapshot) struct buf *bp, ino_t ino, int mode, bool devvp_is_snapshot)
{ {
int cg; u_int cg;
struct cg *cgp; struct cg *cgp;
u_int8_t *inosused; u_int8_t *inosused;
const int needswap = UFS_FSNEEDSWAP(fs); const int needswap = UFS_FSNEEDSWAP(fs);
ino_t cgino;
cg = ino_to_cg(fs, ino); cg = ino_to_cg(fs, ino);
cgp = (struct cg *)bp->b_data; cgp = (struct cg *)bp->b_data;
@ -2078,20 +2085,19 @@ ffs_freefile_common(struct ufsmount *ump, struct fs *fs, dev_t dev,
(fs->fs_old_flags & FS_FLAGS_UPDATED)) (fs->fs_old_flags & FS_FLAGS_UPDATED))
cgp->cg_time = ufs_rw64(time_second, needswap); cgp->cg_time = ufs_rw64(time_second, needswap);
inosused = cg_inosused(cgp, needswap); inosused = cg_inosused(cgp, needswap);
ino %= fs->fs_ipg; cgino = ino % fs->fs_ipg;
if (isclr(inosused, ino)) { if (isclr(inosused, cgino)) {
printf("ifree: dev = 0x%llx, ino = %llu, fs = %s\n", printf("ifree: dev = 0x%llx, ino = %llu, fs = %s\n",
(unsigned long long)dev, (unsigned long long)ino + (unsigned long long)dev, (unsigned long long)ino,
cg * fs->fs_ipg, fs->fs_fsmnt); fs->fs_fsmnt);
if (fs->fs_ronly == 0) if (fs->fs_ronly == 0)
panic("%s: freeing free inode", __func__); panic("%s: freeing free inode", __func__);
} }
clrbit(inosused, ino); clrbit(inosused, cgino);
if (!devvp_is_snapshot) if (!devvp_is_snapshot)
UFS_WAPBL_UNREGISTER_INODE(ump->um_mountp, UFS_WAPBL_UNREGISTER_INODE(ump->um_mountp, ino, mode);
ino + cg * fs->fs_ipg, mode); if (cgino < ufs_rw32(cgp->cg_irotor, needswap))
if (ino < ufs_rw32(cgp->cg_irotor, needswap)) cgp->cg_irotor = ufs_rw32(cgino, needswap);
cgp->cg_irotor = ufs_rw32(ino, needswap);
ufs_add32(cgp->cg_cs.cs_nifree, 1, needswap); ufs_add32(cgp->cg_cs.cs_nifree, 1, needswap);
mutex_enter(&ump->um_lock); mutex_enter(&ump->um_lock);
fs->fs_cstotal.cs_nifree++; fs->fs_cstotal.cs_nifree++;
@ -2115,7 +2121,8 @@ ffs_checkfreefile(struct fs *fs, struct vnode *devvp, ino_t ino)
struct cg *cgp; struct cg *cgp;
struct buf *bp; struct buf *bp;
daddr_t cgbno; daddr_t cgbno;
int ret, cg; int ret;
u_int cg;
u_int8_t *inosused; u_int8_t *inosused;
const bool devvp_is_snapshot = (devvp->v_type != VBLK); const bool devvp_is_snapshot = (devvp->v_type != VBLK);
@ -2126,7 +2133,7 @@ ffs_checkfreefile(struct fs *fs, struct vnode *devvp, ino_t ino)
cgbno = ffs_fragstoblks(fs, cgtod(fs, cg)); cgbno = ffs_fragstoblks(fs, cgtod(fs, cg));
else else
cgbno = FFS_FSBTODB(fs, cgtod(fs, cg)); cgbno = FFS_FSBTODB(fs, cgtod(fs, cg));
if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg) if (ino >= fs->fs_ipg * fs->fs_ncg)
return 1; return 1;
if (bread(devvp, cgbno, (int)fs->fs_cgsize, 0, &bp)) { if (bread(devvp, cgbno, (int)fs->fs_cgsize, 0, &bp)) {
return 1; return 1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_extern.h,v 1.87 2022/11/28 04:52:04 chs Exp $ */ /* $NetBSD: ffs_extern.h,v 1.88 2023/01/07 19:41:30 chs Exp $ */
/*- /*-
* Copyright (c) 1991, 1993, 1994 * Copyright (c) 1991, 1993, 1994
@ -202,7 +202,7 @@ void ffs_cg_swap(struct cg *, struct cg *, struct fs *);
void ffs_load_inode(struct buf *, struct inode *, struct fs *, ino_t); void ffs_load_inode(struct buf *, struct inode *, struct fs *, ino_t);
int ffs_getblk(struct vnode *, daddr_t, daddr_t, int, bool, buf_t **); int ffs_getblk(struct vnode *, daddr_t, daddr_t, int, bool, buf_t **);
#endif /* defined(_KERNEL) */ #endif /* defined(_KERNEL) */
void ffs_fragacct(struct fs *, int, int32_t[], int, int); void ffs_fragacct(struct fs *, int, uint32_t[], int, int);
int ffs_isblock(struct fs *, u_char *, int32_t); int ffs_isblock(struct fs *, u_char *, int32_t);
int ffs_isfreeblock(struct fs *, u_char *, int32_t); int ffs_isfreeblock(struct fs *, u_char *, int32_t);
void ffs_clrblock(struct fs *, u_char *, int32_t); void ffs_clrblock(struct fs *, u_char *, int32_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_subr.c,v 1.53 2022/05/24 06:28:02 andvar Exp $ */ /* $NetBSD: ffs_subr.c,v 1.54 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 1982, 1986, 1989, 1993 * Copyright (c) 1982, 1986, 1989, 1993
@ -36,7 +36,7 @@
#endif #endif
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.53 2022/05/24 06:28:02 andvar Exp $"); __KERNEL_RCSID(0, "$NetBSD: ffs_subr.c,v 1.54 2023/01/07 19:41:30 chs Exp $");
#include <sys/param.h> #include <sys/param.h>
@ -141,7 +141,7 @@ ffs_getblk(struct vnode *vp, daddr_t lblkno, daddr_t blkno, int size,
* of some frags. * of some frags.
*/ */
void void
ffs_fragacct(struct fs *fs, int fragmap, int32_t fraglist[], int cnt, ffs_fragacct(struct fs *fs, int fragmap, uint32_t fraglist[], int cnt,
int needswap) int needswap)
{ {
int inblk; int inblk;

View File

@ -1,4 +1,4 @@
/* $NetBSD: fs.h,v 1.70 2022/11/17 06:40:40 chs Exp $ */ /* $NetBSD: fs.h,v 1.71 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 1982, 1986, 1993 * Copyright (c) 1982, 1986, 1993
@ -265,7 +265,7 @@ struct fs {
int32_t fs_old_time; /* last time written */ int32_t fs_old_time; /* last time written */
int32_t fs_old_size; /* number of blocks in fs */ int32_t fs_old_size; /* number of blocks in fs */
int32_t fs_old_dsize; /* number of data blocks in fs */ int32_t fs_old_dsize; /* number of data blocks in fs */
int32_t fs_ncg; /* number of cylinder groups */ u_int32_t fs_ncg; /* number of cylinder groups */
int32_t fs_bsize; /* size of basic blocks in fs */ int32_t fs_bsize; /* size of basic blocks in fs */
int32_t fs_fsize; /* size of frag blocks in fs */ int32_t fs_fsize; /* size of frag blocks in fs */
int32_t fs_frag; /* number of frags in a block in fs */ int32_t fs_frag; /* number of frags in a block in fs */
@ -288,7 +288,7 @@ struct fs {
int32_t fs_spare1[2]; /* old fs_csmask */ int32_t fs_spare1[2]; /* old fs_csmask */
/* old fs_csshift */ /* old fs_csshift */
int32_t fs_nindir; /* value of FFS_NINDIR */ int32_t fs_nindir; /* value of FFS_NINDIR */
int32_t fs_inopb; /* value of FFS_INOPB */ u_int32_t fs_inopb; /* value of FFS_INOPB */
int32_t fs_old_nspf; /* value of NSPF */ int32_t fs_old_nspf; /* value of NSPF */
/* yet another configuration parameter */ /* yet another configuration parameter */
int32_t fs_optim; /* optimization preference, see below */ int32_t fs_optim; /* optimization preference, see below */
@ -308,7 +308,7 @@ struct fs {
int32_t fs_old_spc; /* sectors per cylinder */ int32_t fs_old_spc; /* sectors per cylinder */
int32_t fs_old_ncyl; /* cylinders in file system */ int32_t fs_old_ncyl; /* cylinders in file system */
int32_t fs_old_cpg; /* cylinders per group */ int32_t fs_old_cpg; /* cylinders per group */
int32_t fs_ipg; /* inodes per group */ u_int32_t fs_ipg; /* inodes per group */
int32_t fs_fpg; /* blocks per group * fs_frag */ int32_t fs_fpg; /* blocks per group * fs_frag */
/* this data must be re-computed after crashes */ /* this data must be re-computed after crashes */
struct csum fs_old_cstotal; /* cylinder summary information */ struct csum fs_old_cstotal; /* cylinder summary information */
@ -348,11 +348,11 @@ struct fs {
int64_t fs_dsize; /* number of data blocks in fs */ int64_t fs_dsize; /* number of data blocks in fs */
int64_t fs_csaddr; /* blk addr of cyl grp summary area */ int64_t fs_csaddr; /* blk addr of cyl grp summary area */
int64_t fs_pendingblocks; /* blocks in process of being freed */ int64_t fs_pendingblocks; /* blocks in process of being freed */
int32_t fs_pendinginodes; /* inodes in process of being freed */ u_int32_t fs_pendinginodes; /* inodes in process of being freed */
int32_t fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */ uint32_t fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */
/* back to stuff that has been around a while */ /* back to stuff that has been around a while */
int32_t fs_avgfilesize; /* expected average file size */ u_int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */ u_int32_t fs_avgfpdir; /* expected # of files per directory */
int32_t fs_save_cgsize; /* save real cg size to use fs_bsize */ int32_t fs_save_cgsize; /* save real cg size to use fs_bsize */
int32_t fs_sparecon32[26]; /* reserved for future constants */ int32_t fs_sparecon32[26]; /* reserved for future constants */
uint32_t fs_flags; /* see FS_ flags below */ uint32_t fs_flags; /* see FS_ flags below */
@ -507,25 +507,25 @@ struct cg {
int32_t cg_firstfield; /* historic cyl groups linked list */ int32_t cg_firstfield; /* historic cyl groups linked list */
int32_t cg_magic; /* magic number */ int32_t cg_magic; /* magic number */
int32_t cg_old_time; /* time last written */ int32_t cg_old_time; /* time last written */
int32_t cg_cgx; /* we are the cgx'th cylinder group */ u_int32_t cg_cgx; /* we are the cgx'th cylinder group */
int16_t cg_old_ncyl; /* number of cyl's this cg */ int16_t cg_old_ncyl; /* number of cyl's this cg */
int16_t cg_old_niblk; /* number of inode blocks this cg */ int16_t cg_old_niblk; /* number of inode blocks this cg */
int32_t cg_ndblk; /* number of data blocks this cg */ u_int32_t cg_ndblk; /* number of data blocks this cg */
struct csum cg_cs; /* cylinder summary information */ struct csum cg_cs; /* cylinder summary information */
int32_t cg_rotor; /* position of last used block */ u_int32_t cg_rotor; /* position of last used block */
int32_t cg_frotor; /* position of last used frag */ u_int32_t cg_frotor; /* position of last used frag */
int32_t cg_irotor; /* position of last used inode */ u_int32_t cg_irotor; /* position of last used inode */
int32_t cg_frsum[MAXFRAG]; /* counts of available frags */ u_int32_t cg_frsum[MAXFRAG]; /* counts of available frags */
int32_t cg_old_btotoff; /* (int32) block totals per cylinder */ int32_t cg_old_btotoff; /* (int32) block totals per cylinder */
int32_t cg_old_boff; /* (u_int16) free block positions */ int32_t cg_old_boff; /* (u_int16) free block positions */
int32_t cg_iusedoff; /* (u_int8) used inode map */ u_int32_t cg_iusedoff; /* (u_int8) used inode map */
int32_t cg_freeoff; /* (u_int8) free block map */ u_int32_t cg_freeoff; /* (u_int8) free block map */
int32_t cg_nextfreeoff; /* (u_int8) next available space */ u_int32_t cg_nextfreeoff; /* (u_int8) next available space */
int32_t cg_clustersumoff; /* (u_int32) counts of avail clusters */ u_int32_t cg_clustersumoff; /* (u_int32) counts of avail clusters */
int32_t cg_clusteroff; /* (u_int8) free cluster map */ u_int32_t cg_clusteroff; /* (u_int8) free cluster map */
int32_t cg_nclusterblks; /* number of clusters this cg */ u_int32_t cg_nclusterblks; /* number of clusters this cg */
int32_t cg_niblk; /* number of inode blocks this cg */ u_int32_t cg_niblk; /* number of inode blocks this cg */
int32_t cg_initediblk; /* last initialized inode */ u_int32_t cg_initediblk; /* last initialized inode */
int32_t cg_sparecon32[3]; /* reserved for future use */ int32_t cg_sparecon32[3]; /* reserved for future use */
int64_t cg_time; /* time last written */ int64_t cg_time; /* time last written */
int64_t cg_sparecon64[3]; /* reserved for future use */ int64_t cg_sparecon64[3]; /* reserved for future use */
@ -647,11 +647,11 @@ struct ocg {
* inode number to cylinder group number. * inode number to cylinder group number.
* inode number to file system block address. * inode number to file system block address.
*/ */
#define ino_to_cg(fs, x) ((x) / (fs)->fs_ipg) #define ino_to_cg(fs, x) (((ino_t)(x)) / (fs)->fs_ipg)
#define ino_to_fsba(fs, x) \ #define ino_to_fsba(fs, x) \
((daddr_t)(cgimin(fs, ino_to_cg(fs, x)) + \ ((daddr_t)(cgimin(fs, ino_to_cg(fs, (ino_t)(x))) + \
(ffs_blkstofrags((fs), (((x) % (fs)->fs_ipg) / FFS_INOPB(fs)))))) (ffs_blkstofrags((fs), ((((ino_t)(x)) % (fs)->fs_ipg) / FFS_INOPB(fs))))))
#define ino_to_fsbo(fs, x) ((x) % FFS_INOPB(fs)) #define ino_to_fsbo(fs, x) (((ino_t)(x)) % FFS_INOPB(fs))
/* /*
* Give cylinder group number for a file system block. * Give cylinder group number for a file system block.

View File

@ -1,4 +1,4 @@
/* $NetBSD: dumpfs.c,v 1.67 2022/12/19 18:51:42 chs Exp $ */ /* $NetBSD: dumpfs.c,v 1.68 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 1983, 1992, 1993 * Copyright (c) 1983, 1992, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1992, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95"; static char sccsid[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95";
#else #else
__RCSID("$NetBSD: dumpfs.c,v 1.67 2022/12/19 18:51:42 chs Exp $"); __RCSID("$NetBSD: dumpfs.c,v 1.68 2023/01/07 19:41:30 chs Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -493,6 +493,7 @@ print_cgsum(const char *name, int fd)
{ {
struct csum *ccsp; struct csum *ccsp;
int i, j, size; int i, j, size;
uint32_t cgnum;
afs.fs_csp = calloc(1, afs.fs_cssize); afs.fs_csp = calloc(1, afs.fs_cssize);
for (i = 0, j = 0; i < afs.fs_cssize; i += afs.fs_bsize, j++) { for (i = 0, j = 0; i < afs.fs_cssize; i += afs.fs_bsize, j++) {
@ -510,8 +511,8 @@ print_cgsum(const char *name, int fd)
} }
printf("cs[].cs_(nbfree,ndir,nifree,nffree):\n\t"); printf("cs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
for (i = 0; i < afs.fs_ncg; i++) { for (cgnum = 0; cgnum < afs.fs_ncg; cgnum++) {
struct csum *cs = &afs.fs_cs(&afs, i); struct csum *cs = &afs.fs_cs(&afs, cgnum);
if (i && i % 4 == 0) if (i && i % 4 == 0)
printf("\n\t"); printf("\n\t");
printf("(%d,%d,%d,%d) ", printf("(%d,%d,%d,%d) ",
@ -534,7 +535,7 @@ static int
print_alt_super(const char *name, int fd) print_alt_super(const char *name, int fd)
{ {
union fsun alt; union fsun alt;
int i; uint32_t i;
off_t loc; off_t loc;
uint16_t alt_opostblsave[32*8]; uint16_t alt_opostblsave[32*8];
int save_printold; int save_printold;
@ -560,7 +561,7 @@ print_alt_super(const char *name, int fd)
static int static int
print_cginfo(const char *name, int fd) print_cginfo(const char *name, int fd)
{ {
int i; uint32_t i;
printf("\n"); printf("\n");
for (i = 0; i < afs.fs_ncg; i++) { for (i = 0; i < afs.fs_ncg; i++) {
@ -578,7 +579,8 @@ print_inodes(const char *name, int fd, int c, int n)
{ {
void *ino_buf = malloc(afs.fs_bsize); void *ino_buf = malloc(afs.fs_bsize);
void (*print_inode)(int, int, void *); void (*print_inode)(int, int, void *);
int i, inum; ino_t inum;
uint32_t i;
if (ino_buf == 0) if (ino_buf == 0)
return 1; return 1;

View File

@ -1,8 +1,6 @@
# $NetBSD: Makefile,v 1.39 2022/04/09 14:38:47 riastradh Exp $ # $NetBSD: Makefile,v 1.40 2023/01/07 19:41:30 chs Exp $
# #
WARNS?= 5
.include <bsd.own.mk> .include <bsd.own.mk>
PROG= makefs PROG= makefs

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs.c,v 1.73 2022/11/17 06:40:41 chs Exp $ */ /* $NetBSD: ffs.c,v 1.74 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 2001 Wasabi Systems, Inc. * Copyright (c) 2001 Wasabi Systems, Inc.
@ -71,7 +71,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint) #if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: ffs.c,v 1.73 2022/11/17 06:40:41 chs Exp $"); __RCSID("$NetBSD: ffs.c,v 1.74 2023/01/07 19:41:30 chs Exp $");
#endif /* !__lint */ #endif /* !__lint */
#include <sys/param.h> #include <sys/param.h>
@ -1067,7 +1067,7 @@ ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts)
struct ufs2_dinode *dp2, *dip; struct ufs2_dinode *dp2, *dip;
struct cg *cgp; struct cg *cgp;
struct fs *fs; struct fs *fs;
int cg, cgino, i; uint32_t cg, cgino, i;
daddr_t d; daddr_t d;
char sbbuf[FFS_MAXBSIZE]; char sbbuf[FFS_MAXBSIZE];
uint32_t initediblk; uint32_t initediblk;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_alloc.c,v 1.30 2022/04/09 10:05:35 riastradh Exp $ */ /* $NetBSD: ffs_alloc.c,v 1.31 2023/01/07 19:41:30 chs Exp $ */
/* From: NetBSD: ffs_alloc.c,v 1.50 2001/09/06 02:16:01 lukem Exp */ /* From: NetBSD: ffs_alloc.c,v 1.50 2001/09/06 02:16:01 lukem Exp */
/* /*
@ -47,7 +47,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint) #if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: ffs_alloc.c,v 1.30 2022/04/09 10:05:35 riastradh Exp $"); __RCSID("$NetBSD: ffs_alloc.c,v 1.31 2023/01/07 19:41:30 chs Exp $");
#endif /* !__lint */ #endif /* !__lint */
#include <sys/param.h> #include <sys/param.h>
@ -70,7 +70,7 @@ static int scanc(u_int, const u_char *, const u_char *, int);
static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int); static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int);
static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t); static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t);
static daddr_t ffs_hashalloc(struct inode *, int, daddr_t, int, static daddr_t ffs_hashalloc(struct inode *, uint32_t, daddr_t, int,
daddr_t (*)(struct inode *, int, daddr_t, int)); daddr_t (*)(struct inode *, int, daddr_t, int));
static int32_t ffs_mapsearch(struct fs *, struct cg *, daddr_t, int); static int32_t ffs_mapsearch(struct fs *, struct cg *, daddr_t, int);
@ -159,8 +159,8 @@ daddr_t
ffs_blkpref_ufs1(struct inode *ip, daddr_t lbn, int indx, int32_t *bap) ffs_blkpref_ufs1(struct inode *ip, daddr_t lbn, int indx, int32_t *bap)
{ {
struct fs *fs; struct fs *fs;
int cg; uint32_t cg, startcg;
int avgbfree, startcg; int avgbfree;
fs = ip->i_fs; fs = ip->i_fs;
if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) { if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
@ -198,8 +198,8 @@ daddr_t
ffs_blkpref_ufs2(struct inode *ip, daddr_t lbn, int indx, int64_t *bap) ffs_blkpref_ufs2(struct inode *ip, daddr_t lbn, int indx, int64_t *bap)
{ {
struct fs *fs; struct fs *fs;
int cg; uint32_t cg, startcg;
int avgbfree, startcg; int avgbfree;
fs = ip->i_fs; fs = ip->i_fs;
if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) { if (indx % fs->fs_maxbpg == 0 || bap[indx - 1] == 0) {
@ -247,12 +247,12 @@ ffs_blkpref_ufs2(struct inode *ip, daddr_t lbn, int indx, int64_t *bap)
*/ */
/*VARARGS5*/ /*VARARGS5*/
static daddr_t static daddr_t
ffs_hashalloc(struct inode *ip, int cg, daddr_t pref, int size, ffs_hashalloc(struct inode *ip, uint32_t cg, daddr_t pref, int size,
daddr_t (*allocator)(struct inode *, int, daddr_t, int)) daddr_t (*allocator)(struct inode *, int, daddr_t, int))
{ {
struct fs *fs; struct fs *fs;
daddr_t result; daddr_t result;
int i, icg = cg; uint32_t i, icg = cg;
fs = ip->i_fs; fs = ip->i_fs;
/* /*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_extern.h,v 1.8 2022/04/09 10:05:35 riastradh Exp $ */ /* $NetBSD: ffs_extern.h,v 1.9 2023/01/07 19:41:30 chs Exp $ */
/* From: NetBSD: ffs_extern.h,v 1.19 2001/08/17 02:18:48 lukem Exp */ /* From: NetBSD: ffs_extern.h,v 1.19 2001/08/17 02:18:48 lukem Exp */
/*- /*-
@ -66,7 +66,7 @@ void ffs_csum_swap(struct csum *, struct csum *, int);
void ffs_cg_swap(struct cg *, struct cg *, struct fs *); void ffs_cg_swap(struct cg *, struct cg *, struct fs *);
/* ffs_subr.c */ /* ffs_subr.c */
void ffs_fragacct(struct fs *, int, int32_t[], int, int); void ffs_fragacct(struct fs *, int, uint32_t[], int, int);
int ffs_isblock(struct fs *, u_char *, int32_t); int ffs_isblock(struct fs *, u_char *, int32_t);
int ffs_isfreeblock(struct fs *, u_char *, int32_t); int ffs_isfreeblock(struct fs *, u_char *, int32_t);
void ffs_clrblock(struct fs *, u_char *, int32_t); void ffs_clrblock(struct fs *, u_char *, int32_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkfs.c,v 1.41 2022/11/17 06:40:41 chs Exp $ */ /* $NetBSD: mkfs.c,v 1.42 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 2002 Networks Associates Technology, Inc. * Copyright (c) 2002 Networks Associates Technology, Inc.
@ -48,7 +48,7 @@
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else #else
#ifdef __RCSID #ifdef __RCSID
__RCSID("$NetBSD: mkfs.c,v 1.41 2022/11/17 06:40:41 chs Exp $"); __RCSID("$NetBSD: mkfs.c,v 1.42 2023/01/07 19:41:30 chs Exp $");
#endif #endif
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -75,7 +75,7 @@ __RCSID("$NetBSD: mkfs.c,v 1.41 2022/11/17 06:40:41 chs Exp $");
#include "ffs/ffs_extern.h" #include "ffs/ffs_extern.h"
#include "ffs/newfs_extern.h" #include "ffs/newfs_extern.h"
static void initcg(int, time_t, const fsinfo_t *); static void initcg(uint32_t, time_t, const fsinfo_t *);
static int ilog2(int); static int ilog2(int);
static int count_digits(int); static int count_digits(int);
@ -141,7 +141,8 @@ struct fs *
ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp)
{ {
int fragsperinode, optimalfpg, origdensity, minfpg, lastminfpg; int fragsperinode, optimalfpg, origdensity, minfpg, lastminfpg;
int32_t cylno, i, csfrags; uint32_t cylno, i;
int32_t csfrags;
long long sizepb; long long sizepb;
void *space; void *space;
int size; int size;
@ -443,7 +444,7 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp)
sblock.fs_maxcluster = lp = space; sblock.fs_maxcluster = lp = space;
for (i = 0; i < sblock.fs_ncg; i++) for (i = 0; i < sblock.fs_ncg; i++)
*lp++ = sblock.fs_contigsumsize; *lp++ = sblock.fs_contigsumsize;
} }
sblock.fs_sbsize = ffs_fragroundup(&sblock, sizeof(struct fs)); sblock.fs_sbsize = ffs_fragroundup(&sblock, sizeof(struct fs));
@ -566,7 +567,8 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp)
void void
ffs_write_superblock(struct fs *fs, const fsinfo_t *fsopts) ffs_write_superblock(struct fs *fs, const fsinfo_t *fsopts)
{ {
int cylno, size, blks, i, saveflag; int size, blks, i, saveflag;
uint32_t cylno;
void *space; void *space;
char *wrbuf; char *wrbuf;
@ -606,10 +608,10 @@ ffs_write_superblock(struct fs *fs, const fsinfo_t *fsopts)
* Initialize a cylinder group. * Initialize a cylinder group.
*/ */
static void static void
initcg(int cylno, time_t utime, const fsinfo_t *fsopts) initcg(uint32_t cylno, time_t utime, const fsinfo_t *fsopts)
{ {
daddr_t cbase, dmax; daddr_t cbase, dmax;
int i, j, d, dlower, dupper, blkno; uint32_t i, j, d, dlower, dupper, blkno;
struct ufs1_dinode *dp1; struct ufs1_dinode *dp1;
struct ufs2_dinode *dp2; struct ufs2_dinode *dp2;
int start; int start;
@ -671,7 +673,7 @@ initcg(int cylno, time_t utime, const fsinfo_t *fsopts)
acg.cg_nextfreeoff = acg.cg_clusteroff + acg.cg_nextfreeoff = acg.cg_clusteroff +
howmany(ffs_fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT); 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"); printf("Panic: cylinder group too big\n");
exit(37); exit(37);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: quotacheck.c,v 1.50 2022/11/17 06:40:41 chs Exp $ */ /* $NetBSD: quotacheck.c,v 1.51 2023/01/07 19:41:30 chs Exp $ */
/* /*
* Copyright (c) 1980, 1990, 1993 * Copyright (c) 1980, 1990, 1993
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)quotacheck.c 8.6 (Berkeley) 4/28/95"; static char sccsid[] = "@(#)quotacheck.c 8.6 (Berkeley) 4/28/95";
#else #else
__RCSID("$NetBSD: quotacheck.c,v 1.50 2022/11/17 06:40:41 chs Exp $"); __RCSID("$NetBSD: quotacheck.c,v 1.51 2023/01/07 19:41:30 chs Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -319,7 +319,8 @@ chkquota(const char *type, const char *fsname, const char *mntpt, void *v,
struct quotaname *qnp = v; struct quotaname *qnp = v;
struct fileusage *fup; struct fileusage *fup;
union comb_dinode *dp; union comb_dinode *dp;
int cg, i, mode, errs = 0, inosused; int i, mode, errs = 0, inosused;
uint32_t cg;
ino_t ino; ino_t ino;
struct cg *cgp; struct cg *cgp;
char msgbuf[4096]; char msgbuf[4096];