From e25a029eb2496de2e47cd3a936ad4c24bf0043ba Mon Sep 17 00:00:00 2001 From: Matthew D Fleming Date: Thu, 27 Sep 2012 23:31:06 +0000 Subject: [PATCH] Fix sbin/ build with a 64-bit ino_t. Original code by: Gleb Kurtsou --- sbin/dump/traverse.c | 11 ++++++----- sbin/fsck_ffs/suj.c | 2 +- sbin/fsdb/fsdb.c | 26 +++++++++++++++----------- sbin/fsdb/fsdbutil.c | 13 +++++++------ sbin/fsirand/fsirand.c | 4 ++-- sbin/growfs/growfs.c | 5 +++-- sbin/newfs/mkfs.c | 3 ++- sbin/quotacheck/quotacheck.c | 10 ++++++---- sbin/restore/dirs.c | 14 ++++++++------ sbin/restore/interactive.c | 4 +++- sbin/restore/restore.c | 17 +++++++++-------- sbin/restore/symtab.c | 7 ++++--- sbin/restore/tape.c | 28 +++++++++++++++------------- sbin/tunefs/tunefs.c | 6 +++--- 14 files changed, 84 insertions(+), 66 deletions(-) diff --git a/sbin/dump/traverse.c b/sbin/dump/traverse.c index f593244f40d1..8258f079c0ed 100644 --- a/sbin/dump/traverse.c +++ b/sbin/dump/traverse.c @@ -197,8 +197,8 @@ mapfiles(ino_t maxino, long *tapesize) (mode & IFMT) == 0) continue; if (ino >= maxino) { - msg("Skipping inode %d >= maxino %d\n", - ino, maxino); + msg("Skipping inode %ju >= maxino %ju\n", + (uintmax_t)ino, (uintmax_t)maxino); continue; } /* @@ -400,15 +400,16 @@ searchdir( for (loc = 0; loc < size; ) { dp = (struct direct *)(dblk + loc); if (dp->d_reclen == 0) { - msg("corrupted directory, inumber %d\n", ino); + msg("corrupted directory, inumber %ju\n", + (uintmax_t)ino); break; } loc += dp->d_reclen; if (dp->d_ino == 0) continue; if (dp->d_ino >= maxino) { - msg("corrupted directory entry, d_ino %d >= %d\n", - dp->d_ino, maxino); + msg("corrupted directory entry, d_ino %ju >= %ju\n", + (uintmax_t)dp->d_ino, (uintmax_t)maxino); break; } if (dp->d_name[0] == '.') { diff --git a/sbin/fsck_ffs/suj.c b/sbin/fsck_ffs/suj.c index 6fb180406c09..1ef5d5167887 100644 --- a/sbin/fsck_ffs/suj.c +++ b/sbin/fsck_ffs/suj.c @@ -1945,7 +1945,7 @@ ino_unlinked(void) if (DIP(ip, di_nlink) == 0) { if (debug) printf("Freeing unlinked ino %ju mode %o\n", - ino, mode); + (uintmax_t)ino, mode); ino_reclaim(ip, ino, mode); } else if (debug) printf("Skipping ino %ju mode %o with link %d\n", diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index 172265368208..e169061e9f65 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -39,6 +39,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -211,7 +212,8 @@ char * prompt(EditLine *el) { static char pstring[64]; - snprintf(pstring, sizeof(pstring), "fsdb (inum: %d)> ", curinum); + snprintf(pstring, sizeof(pstring), "fsdb (inum: %ju)> ", + (uintmax_t)curinum); return pstring; } @@ -298,8 +300,8 @@ ino_t curinum, ocurrent; #define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \ if (inum < ROOTINO || inum > maxino || cp == argv[ac] || *cp != '\0' ) { \ - printf("inode %d out of range; range is [%d,%d]\n", \ - inum, ROOTINO, maxino); \ + printf("inode %ju out of range; range is [%ju,%ju]\n", \ + (uintmax_t)inum, (uintmax_t)ROOTINO, (uintmax_t)maxino); \ return 1; \ } @@ -364,7 +366,8 @@ CMDFUNCSTART(uplink) if (!checkactive()) return 1; DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) + 1); - printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); + printf("inode %ju link count now %d\n", + (uintmax_t)curinum, DIP(curinode, di_nlink)); inodirty(); return 0; } @@ -374,7 +377,8 @@ CMDFUNCSTART(downlink) if (!checkactive()) return 1; DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) - 1); - printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); + printf("inode %ju link count now %d\n", + (uintmax_t)curinum, DIP(curinode, di_nlink)); inodirty(); return 0; } @@ -493,11 +497,11 @@ CMDFUNCSTART(findblk) if (is_ufs2 ? compare_blk64(wantedblk64, ino_to_fsba(&sblock, inum)) : compare_blk32(wantedblk32, ino_to_fsba(&sblock, inum))) { - printf("block %llu: inode block (%d-%d)\n", + printf("block %llu: inode block (%ju-%ju)\n", (unsigned long long)fsbtodb(&sblock, ino_to_fsba(&sblock, inum)), - (inum / INOPB(&sblock)) * INOPB(&sblock), - (inum / INOPB(&sblock) + 1) * INOPB(&sblock)); + (uintmax_t)(inum / INOPB(&sblock)) * INOPB(&sblock), + (uintmax_t)(inum / INOPB(&sblock) + 1) * INOPB(&sblock)); findblk_numtofind--; if (findblk_numtofind == 0) goto end; @@ -593,8 +597,8 @@ static int founddatablk(uint64_t blk) { - printf("%llu: data block of inode %d\n", - (unsigned long long)fsbtodb(&sblock, blk), curinum); + printf("%llu: data block of inode %ju\n", + (unsigned long long)fsbtodb(&sblock, blk), (uintmax_t)curinum); findblk_numtofind--; if (findblk_numtofind == 0) return 1; @@ -753,7 +757,7 @@ CMDFUNCSTART(ln) return 1; rval = makeentry(curinum, inum, argv[2]); if (rval) - printf("Ino %d entered as `%s'\n", inum, argv[2]); + printf("Ino %ju entered as `%s'\n", (uintmax_t)inum, argv[2]); else printf("could not enter name? weird.\n"); curinode = ginode(curinum); diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c index 5d6f16d5d864..eaea3db79fd5 100644 --- a/sbin/fsdb/fsdbutil.c +++ b/sbin/fsdb/fsdbutil.c @@ -152,7 +152,7 @@ printstat(const char *cp, ino_t inum, union dinode *dp) puts("fifo"); break; } - printf("I=%lu MODE=%o SIZE=%ju", (u_long)inum, DIP(dp, di_mode), + printf("I=%ju MODE=%o SIZE=%ju", (uintmax_t)inum, DIP(dp, di_mode), (uintmax_t)DIP(dp, di_size)); if (sblock.fs_magic != FS_UFS1_MAGIC) { t = _time64_to_time(dp->dp2.di_birthtime); @@ -290,7 +290,7 @@ printblocks(ino_t inum, union dinode *dp) long ndb, offset; ufs2_daddr_t blkno; - printf("Blocks for inode %d:\n", inum); + printf("Blocks for inode %ju:\n", (uintmax_t)inum); printf("Direct blocks:\n"); ndb = howmany(DIP(dp, di_size), sblock.fs_bsize); for (i = 0; i < NDADDR && i < ndb; i++) { @@ -338,7 +338,7 @@ checkactivedir(void) return 0; } if ((DIP(curinode, di_mode) & IFMT) != IFDIR) { - warnx("inode %d not a directory", curinum); + warnx("inode %ju not a directory", (uintmax_t)curinum); return 0; } return 1; @@ -363,11 +363,12 @@ printactive(int doblocks) printstat("current inode", curinum, curinode); break; case 0: - printf("current inode %d: unallocated inode\n", curinum); + printf("current inode %ju: unallocated inode\n", (uintmax_t)curinum); break; default: - printf("current inode %d: screwy itype 0%o (mode 0%o)?\n", - curinum, DIP(curinode, di_mode) & IFMT, DIP(curinode, di_mode)); + printf("current inode %ju: screwy itype 0%o (mode 0%o)?\n", + (uintmax_t)curinum, DIP(curinode, di_mode) & IFMT, + DIP(curinode, di_mode)); break; } return 0; diff --git a/sbin/fsirand/fsirand.c b/sbin/fsirand/fsirand.c index ca7841a46f3e..c373c5bb56f5 100644 --- a/sbin/fsirand/fsirand.c +++ b/sbin/fsirand/fsirand.c @@ -274,8 +274,8 @@ fsirand(char *device) dp2 = &((struct ufs2_dinode *)inodebuf)[n]; if (inumber >= ROOTINO) { if (printonly) - (void)printf("ino %d gen %08x\n", - inumber, + (void)printf("ino %ju gen %08x\n", + (uintmax_t)inumber, sblock->fs_magic == FS_UFS1_MAGIC ? dp1->di_gen : dp2->di_gen); else if (sblock->fs_magic == FS_UFS1_MAGIC) diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c index 81cafead5fad..0c161198fef2 100644 --- a/sbin/growfs/growfs.c +++ b/sbin/growfs/growfs.c @@ -324,6 +324,7 @@ initcg(int cylno, time_t modtime, int fso, unsigned int Nflag) DBG_FUNC("initcg") static caddr_t iobuf; long blkno, start; + ino_t ino; ufs2_daddr_t i, cbase, dmax; struct ufs1_dinode *dp1; struct csum *cs; @@ -392,8 +393,8 @@ initcg(int cylno, time_t modtime, int fso, unsigned int Nflag) } acg.cg_cs.cs_nifree += sblock.fs_ipg; if (cylno == 0) - for (i = 0; i < ROOTINO; i++) { - setbit(cg_inosused(&acg), i); + for (ino = 0; ino < ROOTINO; ino++) { + setbit(cg_inosused(&acg), ino); acg.cg_cs.cs_nifree--; } /* diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 5e2a57955907..efc22c39f13a 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1003,7 +1003,8 @@ iput(union dinode *ip, ino_t ino) sblock.fs_cstotal.cs_nifree--; fscs[0].cs_nifree--; if (ino >= (unsigned long)sblock.fs_ipg * sblock.fs_ncg) { - printf("fsinit: inode value out of range (%d).\n", ino); + printf("fsinit: inode value out of range (%ju).\n", + (uintmax_t)ino); exit(32); } d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino)); diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c index ed9ce753c553..a32ac841207d 100644 --- a/sbin/quotacheck/quotacheck.c +++ b/sbin/quotacheck/quotacheck.c @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -383,9 +384,9 @@ chkquota(char *specname, struct quotafile *qfu, struct quotafile *qfg) if (vflag) { if (aflag) (void)printf("%s: ", mntpt); - (void)printf("out of range UID/GID (%u/%u) ino=%u\n", + (void)printf("out of range UID/GID (%u/%u) ino=%ju\n", DIP(dp, di_uid), DIP(dp,di_gid), - ino); + (uintmax_t)ino); } continue; } @@ -601,7 +602,8 @@ getnextinode(ino_t inumber) static caddr_t nextinop; if (inumber != nextino++ || inumber > lastvalidinum) - errx(1, "bad inode number %d to nextinode", inumber); + errx(1, "bad inode number %ju to nextinode", + (uintmax_t)inumber); if (inumber >= lastinum) { readcnt++; dblk = fsbtodb(&sblock, ino_to_fsba(&sblock, lastinum)); @@ -635,7 +637,7 @@ setinodebuf(ino_t inum) { if (inum % sblock.fs_ipg != 0) - errx(1, "bad inode number %d to setinodebuf", inum); + errx(1, "bad inode number %ju to setinodebuf", (uintmax_t)inum); lastvalidinum = inum + sblock.fs_ipg - 1; nextino = inum; lastinum = inum; diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index 203d97702f14..b2cd8fd28869 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -637,7 +637,8 @@ setdirmodes(int flags) continue; } if (ep == NULL) { - panic("cannot find directory inode %d\n", node.ino); + panic("cannot find directory inode %ju\n", + (uintmax_t)node.ino); continue; } cp = myname(ep); @@ -678,7 +679,8 @@ genliteraldir(char *name, ino_t ino) itp = inotablookup(ino); if (itp == NULL) - panic("Cannot find directory inode %d named %s\n", ino, name); + panic("Cannot find directory inode %ju named %s\n", + (uintmax_t)ino, name); if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { fprintf(stderr, "%s: ", name); (void) fflush(stderr); @@ -691,15 +693,15 @@ genliteraldir(char *name, ino_t ino) size = i < BUFSIZ ? i : BUFSIZ; if (read(dp, buf, (int) size) == -1) { fprintf(stderr, - "write error extracting inode %d, name %s\n", - curfile.ino, curfile.name); + "write error extracting inode %ju, name %s\n", + (uintmax_t)curfile.ino, curfile.name); fprintf(stderr, "read: %s\n", strerror(errno)); done(1); } if (!Nflag && write(ofile, buf, (int) size) == -1) { fprintf(stderr, - "write error extracting inode %d, name %s\n", - curfile.ino, curfile.name); + "write error extracting inode %ju, name %s\n", + (uintmax_t)curfile.ino, curfile.name); fprintf(stderr, "write: %s\n", strerror(errno)); done(1); } diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c index 3cd311daca97..05d1a5806a14 100644 --- a/sbin/restore/interactive.c +++ b/sbin/restore/interactive.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -675,7 +676,8 @@ formatf(struct afile *list, int nentry) for (j = 0; j < columns; j++) { fp = &list[j * lines + i]; if (vflag) { - fprintf(stderr, "%*d ", precision, fp->fnum); + fprintf(stderr, "%*ju ", + precision, (uintmax_t)fp->fnum); fp->len += precision + 1; } if (haveprefix) { diff --git a/sbin/restore/restore.c b/sbin/restore/restore.c index e494cdb69a7d..fbc24ece7c49 100644 --- a/sbin/restore/restore.c +++ b/sbin/restore/restore.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -61,7 +62,7 @@ listfile(char *name, ino_t ino, int type) if (TSTINO(ino, dumpmap) == 0) return (descend); vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir "); - fprintf(stdout, "%10d\t%s\n", ino, name); + fprintf(stdout, "%10ju\t%s\n", (uintmax_t)ino, name); return (descend); } @@ -83,7 +84,7 @@ addfile(char *name, ino_t ino, int type) if (ino == WINO && command == 'i' && !vflag) return (descend); if (!mflag) { - (void) sprintf(buf, "./%u", ino); + (void) sprintf(buf, "./%ju", (uintmax_t)ino); name = buf; if (type == NODE) { (void) genliteraldir(name, ino); @@ -457,8 +458,8 @@ nodeupdates(char *name, ino_t ino, int type) * next incremental tape. */ case 0: - fprintf(stderr, "%s: (inode %d) not found on tape\n", - name, ino); + fprintf(stderr, "%s: (inode %ju) not found on tape\n", + name, (uintmax_t)ino); break; /* @@ -612,7 +613,7 @@ createleaves(char *symtabfile) while (first < curfile.ino) { ep = lookupino(first); if (ep == NULL) - panic("%d: bad first\n", first); + panic("%ju: bad first\n", (uintmax_t)first); fprintf(stderr, "%s: not found on tape\n", myname(ep)); ep->e_flags &= ~(NEW|EXTRACT); first = lowerbnd(first); @@ -625,8 +626,8 @@ createleaves(char *symtabfile) * on the next incremental tape. */ if (first != curfile.ino) { - fprintf(stderr, "expected next file %d, got %d\n", - first, curfile.ino); + fprintf(stderr, "expected next file %ju, got %ju\n", + (uintmax_t)first, (uintmax_t)curfile.ino); skipfile(); goto next; } @@ -852,7 +853,7 @@ verifyfile(char *name, ino_t ino, int type) if (np == ep) break; if (np == NULL) - panic("missing inumber %d\n", ino); + panic("missing inumber %ju\n", (uintmax_t)ino); if (ep->e_type == LEAF && type != LEAF) badentry(ep, "type should be LEAF"); return (descend); diff --git a/sbin/restore/symtab.c b/sbin/restore/symtab.c index 3e523351924e..9d0313dfb083 100644 --- a/sbin/restore/symtab.c +++ b/sbin/restore/symtab.c @@ -52,6 +52,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -100,7 +101,7 @@ addino(ino_t inum, struct entry *np) struct entry **epp; if (inum < WINO || inum >= maxino) - panic("addino: out of range %d\n", inum); + panic("addino: out of range %ju\n", (uintmax_t)inum); epp = &entry[inum % entrytblsize]; np->e_ino = inum; np->e_next = *epp; @@ -121,7 +122,7 @@ deleteino(ino_t inum) struct entry **prev; if (inum < WINO || inum >= maxino) - panic("deleteino: out of range %d\n", inum); + panic("deleteino: out of range %ju\n", (uintmax_t)inum); prev = &entry[inum % entrytblsize]; for (next = *prev; next != NULL; next = next->e_next) { if (next->e_ino == inum) { @@ -131,7 +132,7 @@ deleteino(ino_t inum) } prev = &next->e_next; } - panic("deleteino: %d not found\n", inum); + panic("deleteino: %ju not found\n", (uintmax_t)inum); } /* diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index a566c5acf339..f63d573617b7 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -274,7 +274,7 @@ setup(void) done(1); } maxino = (spcl.c_count * TP_BSIZE * NBBY) + 1; - dprintf(stdout, "maxino = %d\n", maxino); + dprintf(stdout, "maxino = %ju\n", (uintmax_t)maxino); map = calloc((unsigned)1, (unsigned)howmany(maxino, NBBY)); if (map == NULL) panic("no memory for active inode map\n"); @@ -1050,8 +1050,9 @@ setupextattr(int extsize) } extbufsize = 0; extbuf = NULL; - fprintf(stderr, "Cannot extract %d bytes %s for inode %d, name %s\n", - extsize, "of extended attributes", curfile.ino, curfile.name); + fprintf(stderr, "Cannot extract %d bytes %s for inode %ju, name %s\n", + extsize, "of extended attributes", (uintmax_t)curfile.ino, + curfile.name); return (NULL); } @@ -1079,8 +1080,8 @@ xtrfile(char *buf, long size) return; if (write(ofile, buf, (int) size) == -1) { fprintf(stderr, - "write error extracting inode %d, name %s\nwrite: %s\n", - curfile.ino, curfile.name, strerror(errno)); + "write error extracting inode %ju, name %s\nwrite: %s\n", + (uintmax_t)curfile.ino, curfile.name, strerror(errno)); } } @@ -1094,8 +1095,8 @@ xtrskip(char *buf, long size) if (lseek(ofile, size, SEEK_CUR) == -1) { fprintf(stderr, - "seek error extracting inode %d, name %s\nlseek: %s\n", - curfile.ino, curfile.name, strerror(errno)); + "seek error extracting inode %ju, name %s\nlseek: %s\n", + (uintmax_t)curfile.ino, curfile.name, strerror(errno)); done(1); } } @@ -1243,8 +1244,8 @@ readtape(char *buf) fprintf(stderr, "restoring %s\n", curfile.name); break; case SKIP: - fprintf(stderr, "skipping over inode %d\n", - curfile.ino); + fprintf(stderr, "skipping over inode %ju\n", + (uintmax_t)curfile.ino); break; } if (!yflag && !reply("continue")) @@ -1477,10 +1478,11 @@ accthdr(struct s_spcl *header) fprintf(stderr, "Used inodes map header"); break; case TS_INODE: - fprintf(stderr, "File header, ino %d", previno); + fprintf(stderr, "File header, ino %ju", (uintmax_t)previno); break; case TS_ADDR: - fprintf(stderr, "File continuation header, ino %d", previno); + fprintf(stderr, "File continuation header, ino %ju", + (uintmax_t)previno); break; case TS_END: fprintf(stderr, "End of tape header"); @@ -1631,8 +1633,8 @@ checksum(int *buf) } if (i != CHECKSUM) { - fprintf(stderr, "Checksum error %o, inode %d file %s\n", i, - curfile.ino, curfile.name); + fprintf(stderr, "Checksum error %o, inode %ju file %s\n", i, + (uintmax_t)curfile.ino, curfile.name); return(FAIL); } return(GOOD); diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c index de3db1261779..228132f12680 100644 --- a/sbin/tunefs/tunefs.c +++ b/sbin/tunefs/tunefs.c @@ -894,7 +894,7 @@ journal_clear(void) warnx("Journal file does not exist"); return; } - printf("Clearing journal flags from inode %d\n", ino); + printf("Clearing journal flags from inode %ju\n", (uintmax_t)ino); if (getino(&disk, &ip, ino, &mode) != 0) { warn("Failed to get journal inode"); return; @@ -970,8 +970,8 @@ journal_alloc(int64_t size) ino = cgialloc(&disk); if (ino <= 0) break; - printf("Using inode %d in cg %d for %jd byte journal\n", - ino, cgp->cg_cgx, size); + printf("Using inode %ju in cg %d for %jd byte journal\n", + (uintmax_t)ino, cgp->cg_cgx, size); if (getino(&disk, &ip, ino, &mode) != 0) { warn("Failed to get allocated inode"); sbdirty();