From a66ab5913df7bd47c78355757875e2a7959735a9 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Tue, 24 Feb 1987 01:40:09 -0800 Subject: [PATCH] convert SBLOCK to SBOFF; generalize use of dev_bsize SCCS-vsn: sbin/badsect/badsect.c 5.3 SCCS-vsn: sbin/clri/clri.c 2.3 SCCS-vsn: old/dcheck/dcheck.c 5.2 SCCS-vsn: sbin/dumpfs/dumpfs.c 5.5 SCCS-vsn: sbin/icheck/icheck.c 5.2 SCCS-vsn: usr.sbin/mkproto/mkproto.c 5.2 SCCS-vsn: sbin/ncheck/ncheck.c 5.6 SCCS-vsn: usr.sbin/quot/quot.c 4.12 SCCS-vsn: sbin/quotacheck/quotacheck.c 5.7 SCCS-vsn: sbin/savecore/savecore.c 5.11 SCCS-vsn: sbin/tunefs/tunefs.c 5.4 --- usr/src/old/dcheck/dcheck.c | 8 +++++--- usr/src/sbin/badsect/badsect.c | 8 +++++--- usr/src/sbin/clri/clri.c | 10 ++++++---- usr/src/sbin/dumpfs/dumpfs.c | 11 +++++++---- usr/src/sbin/icheck/icheck.c | 12 +++++++----- usr/src/sbin/ncheck/ncheck.c | 8 +++++--- usr/src/sbin/quotacheck/quotacheck.c | 11 +++++------ usr/src/sbin/savecore/savecore.c | 4 ++-- usr/src/sbin/tunefs/tunefs.c | 12 +++++++----- usr/src/usr.sbin/mkproto/mkproto.c | 13 +++++++------ usr/src/usr.sbin/quot/quot.c | 8 +++++--- 11 files changed, 61 insertions(+), 44 deletions(-) diff --git a/usr/src/old/dcheck/dcheck.c b/usr/src/old/dcheck/dcheck.c index d814ee5681..7f8af61a61 100644 --- a/usr/src/old/dcheck/dcheck.c +++ b/usr/src/old/dcheck/dcheck.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)dcheck.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)dcheck.c 5.2 (Berkeley) %G%"; #endif not lint /* @@ -47,6 +47,7 @@ ino_t ino; ino_t *ecount; int headpr; int nfiles; +long dev_bsize = 1; int nerror; daddr_t bmap(); @@ -99,12 +100,13 @@ char *file; headpr = 0; printf("%s:\n", file); sync(); - bread(SBLOCK, (char *)&sblock, SBSIZE); + bread(SBOFF, (char *)&sblock, SBSIZE); if (sblock.fs_magic != FS_MAGIC) { printf("%s: not a file system\n", file); nerror++; return; } + dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); nfiles = sblock.fs_ipg * sblock.fs_ncg; ecount = (ino_t *)malloc((nfiles+1) * sizeof (*ecount)); if (ecount == 0) { @@ -218,7 +220,7 @@ char *buf; { register i; - lseek(fi, bno * DEV_BSIZE, 0); + lseek(fi, bno * dev_bsize, 0); if (read(fi, buf, cnt) != cnt) { printf("read error %d\n", bno); for(i=0; i < cnt; i++) diff --git a/usr/src/sbin/badsect/badsect.c b/usr/src/sbin/badsect/badsect.c index 8406808d85..9e1b765cfc 100644 --- a/usr/src/sbin/badsect/badsect.c +++ b/usr/src/sbin/badsect/badsect.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)badsect.c 5.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)badsect.c 5.3 (Berkeley) %G%"; #endif not lint /* @@ -44,6 +44,7 @@ union { struct fs *fs; int fso, fsi; int errs; +long dev_bsize = 1; char buf[MAXBSIZE]; @@ -93,7 +94,8 @@ main(argc, argv) exit(6); } fs = &sblock; - rdfs(SBLOCK, SBSIZE, (char *)fs); + rdfs(SBOFF, SBSIZE, (char *)fs); + dev_bsize = fs->fs_fsize / fsbtodb(fs, 1); for (argc -= 2, argv += 2; argc > 0; argc--, argv++) { number = atoi(*argv); if (chkuse(number, 1)) @@ -155,7 +157,7 @@ rdfs(bno, size, bf) { int n; - if (lseek(fsi, bno * DEV_BSIZE, 0) < 0) { + if (lseek(fsi, bno * dev_bsize, 0) < 0) { printf("seek error: %ld\n", bno); perror("rdfs"); exit(1); diff --git a/usr/src/sbin/clri/clri.c b/usr/src/sbin/clri/clri.c index 8bf65c3766..f5af1a95a1 100644 --- a/usr/src/sbin/clri/clri.c +++ b/usr/src/sbin/clri/clri.c @@ -1,4 +1,4 @@ -static char sccsid[] = "@(#)clri.c 2.2 %G%"; +static char sccsid[] = "@(#)clri.c 2.3 %G%"; /* static char *sccsid = "@(#)clri.c 4.1 (Berkeley) 10/1/80"; */ @@ -30,6 +30,7 @@ union { #define sblock sb_un.sblk int status; +long dev_bsize = 1; main(argc, argv) int argc; @@ -49,7 +50,7 @@ main(argc, argv) printf("cannot open %s\n", argv[1]); exit(4); } - lseek(f, SBLOCK * DEV_BSIZE, 0); + lseek(f, SBOFF, 0); if (read(f, &sblock, SBSIZE) != SBSIZE) { printf("cannot read %s\n", argv[1]); exit(4); @@ -58,6 +59,7 @@ main(argc, argv) printf("bad super block magic number\n"); exit(4); } + dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); for (i = 2; i < argc; i++) { if (!isnumber(argv[i])) { printf("%s: is not a number\n", argv[i]); @@ -70,7 +72,7 @@ main(argc, argv) status = 1; continue; } - off = fsbtodb(&sblock, itod(&sblock, n)) * DEV_BSIZE; + off = fsbtodb(&sblock, itod(&sblock, n)) * dev_bsize; lseek(f, off, 0); if (read(f, (char *)buf, sblock.fs_bsize) != sblock.fs_bsize) { printf("%s: read error\n", argv[i]); @@ -82,7 +84,7 @@ main(argc, argv) for (i = 2; i < argc; i++) { n = atoi(argv[i]); printf("clearing %u\n", n); - off = fsbtodb(&sblock, itod(&sblock, n)) * DEV_BSIZE; + off = fsbtodb(&sblock, itod(&sblock, n)) * dev_bsize; lseek(f, off, 0); read(f, (char *)buf, sblock.fs_bsize); j = itoo(&sblock, n); diff --git a/usr/src/sbin/dumpfs/dumpfs.c b/usr/src/sbin/dumpfs/dumpfs.c index ca6135cb48..e021fd4f30 100644 --- a/usr/src/sbin/dumpfs/dumpfs.c +++ b/usr/src/sbin/dumpfs/dumpfs.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)dumpfs.c 5.4 (Berkeley) %G%"; +static char sccsid[] = "@(#)dumpfs.c 5.5 (Berkeley) %G%"; #endif not lint #include @@ -37,6 +37,8 @@ union { } cgun; #define acg cgun.cg +long dev_bsize = 1; + main(argc, argv) char **argv; { @@ -66,11 +68,12 @@ dumpfs(name) perror(name); return; } - lseek(0, SBLOCK * DEV_BSIZE, 0); + lseek(0, SBOFF, 0); if (read(0, &afs, SBSIZE) != SBSIZE) { perror(name); return; } + dev_bsize = afs.fs_fsize / fsbtodb(&afs, 1); printf("magic\t%x\ttime\t%s", afs.fs_magic, ctime(&afs.fs_time)); printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n", afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_ndir, @@ -130,7 +133,7 @@ dumpfs(name) afs.fs_cssize - i : afs.fs_bsize; afs.fs_csp[j] = (struct csum *)calloc(1, size); lseek(0, fsbtodb(&afs, (afs.fs_csaddr + j * afs.fs_frag)) * - DEV_BSIZE, 0); + dev_bsize, 0); if (read(0, afs.fs_csp[j], size) != size) { perror(name); return; @@ -163,7 +166,7 @@ dumpcg(name, c) int i,j; printf("\ncg %d:\n", c); - lseek(0, fsbtodb(&afs, cgtod(&afs, c)) * DEV_BSIZE, 0); + lseek(0, fsbtodb(&afs, cgtod(&afs, c)) * dev_bsize, 0); i = lseek(0, 0, 1); if (read(0, (char *)&acg, afs.fs_bsize) != afs.fs_bsize) { printf("dumpfs: %s: error reading cg\n", name); diff --git a/usr/src/sbin/icheck/icheck.c b/usr/src/sbin/icheck/icheck.c index 46e1d494c1..f633edbdda 100644 --- a/usr/src/sbin/icheck/icheck.c +++ b/usr/src/sbin/icheck/icheck.c @@ -5,7 +5,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)icheck.c 5.1 (Berkeley) %G%"; +static char sccsid[] = "@(#)icheck.c 5.2 (Berkeley) %G%"; #endif not lint @@ -70,6 +70,7 @@ daddr_t nbfree; daddr_t ndup; int nerror; +long dev_bsize = 1; extern int inside[], around[]; extern unsigned char *fragtbl[]; @@ -575,7 +576,7 @@ makecg() } sblock.fs_ronly = 0; sblock.fs_fmod = 0; - bwrite(SBLOCK, (char *)&sblock, SBSIZE); + bwrite(SBOFF / dev_bsize, (char *)&sblock, SBSIZE); } /* @@ -618,7 +619,7 @@ getsb(fs, file) { int i, j, size; - if (bread(SBLOCK, fs, SBSIZE)) { + if (bread(SBOFF, fs, SBSIZE)) { printf("bad super block"); perror(file); nerror |= 04; @@ -629,6 +630,7 @@ getsb(fs, file) nerror |= 04; return; } + dev_bsize = fs->fs_fsize / fsbtodb(fs, 1); for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) { size = sblock.fs_cssize - i < sblock.fs_bsize ? sblock.fs_cssize - i : sblock.fs_bsize; @@ -643,7 +645,7 @@ bwrite(blk, buf, size) daddr_t blk; register size; { - if (lseek(fi, blk * DEV_BSIZE, 0) < 0) { + if (lseek(fi, blk * dev_bsize, 0) < 0) { perror("FS SEEK"); return(1); } @@ -660,7 +662,7 @@ bread(bno, buf, cnt) { register i; - lseek(fi, bno * DEV_BSIZE, 0); + lseek(fi, bno * dev_bsize, 0); if ((i = read(fi, buf, cnt)) != cnt) { if (sflg) { printf("No Update\n"); diff --git a/usr/src/sbin/ncheck/ncheck.c b/usr/src/sbin/ncheck/ncheck.c index cadeedd0e6..4cdd6521ba 100644 --- a/usr/src/sbin/ncheck/ncheck.c +++ b/usr/src/sbin/ncheck/ncheck.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)ncheck.c 5.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)ncheck.c 5.6 (Berkeley) %G%"; #endif not lint /* @@ -60,6 +60,7 @@ int fi; ino_t ino; int nhent; int nxfile; +long dev_bsize = 1; int nerror; daddr_t bmap(); @@ -126,12 +127,13 @@ check(file) nhent = 0; printf("%s:\n", file); sync(); - bread(SBLOCK, (char *)&sblock, SBSIZE); + bread(SBOFF, (char *)&sblock, SBSIZE); if (sblock.fs_magic != FS_MAGIC) { printf("%s: not a file system\n", file); nerror++; return; } + dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); hsize = sblock.fs_ipg * sblock.fs_ncg - sblock.fs_cstotal.cs_nifree + 1; htab = (struct htab *)malloc(hsize * sizeof(struct htab)); strngtab = (char *)malloc(30 * hsize); @@ -359,7 +361,7 @@ bread(bno, buf, cnt) { register i; - lseek(fi, bno * DEV_BSIZE, 0); + lseek(fi, bno * dev_bsize, 0); if (read(fi, buf, cnt) != cnt) { fprintf(stderr, "ncheck: read error %d\n", bno); for(i=0; i < cnt; i++) diff --git a/usr/src/sbin/quotacheck/quotacheck.c b/usr/src/sbin/quotacheck/quotacheck.c index bb60d12785..d15a94eba4 100644 --- a/usr/src/sbin/quotacheck/quotacheck.c +++ b/usr/src/sbin/quotacheck/quotacheck.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)quotacheck.c 5.6 (Berkeley) %G%"; +static char sccsid[] = "@(#)quotacheck.c 5.7 (Berkeley) %G%"; #endif not lint /* @@ -68,6 +68,7 @@ char *qfname = "quotas"; char quotafile[MAXPATHLEN + 1]; struct dqblk zerodqbuf; struct fileusage zerofileusage; +long dev_bsize = 1; main(argc, argv) int argc; @@ -270,7 +271,8 @@ chkquota(fsdev, fsfile, qffile) "*** Warning: Quotas are not compiled into this kernel\n"); } sync(); - bread(SBLOCK, (char *)&sblock, SBSIZE); + bread(SBOFF, (char *)&sblock, SBSIZE); + dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); ino = 0; for (cg = 0; cg < sblock.fs_ncg; cg++) { dp = NULL; @@ -370,11 +372,8 @@ bread(bno, buf, cnt) long unsigned bno; char *buf; { - extern off_t lseek(); - register off_t pos; - pos = (off_t)dbtob(bno); - if (lseek(fi, pos, 0) != pos) { + if (lseek(fi, bno * dev_bsize, 0) < 0) { perror("lseek"); exit(1); } diff --git a/usr/src/sbin/savecore/savecore.c b/usr/src/sbin/savecore/savecore.c index 42292ad25c..e1e272bb2c 100644 --- a/usr/src/sbin/savecore/savecore.c +++ b/usr/src/sbin/savecore/savecore.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)savecore.c 5.10 (Berkeley) %G%"; +static char sccsid[] = "@(#)savecore.c 5.11 (Berkeley) %G%"; #endif not lint /* @@ -317,7 +317,7 @@ check_space() } ddev = find_dev(dsb.st_dev, S_IFBLK); dfd = Open(ddev, O_RDONLY); - Lseek(dfd, (long)(SBLOCK * DEV_BSIZE), L_SET); + Lseek(dfd, SBOFF, L_SET); Read(dfd, (char *)&fs, sizeof (fs)); close(dfd); spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 1024; diff --git a/usr/src/sbin/tunefs/tunefs.c b/usr/src/sbin/tunefs/tunefs.c index 38b3e606e1..44e137907c 100644 --- a/usr/src/sbin/tunefs/tunefs.c +++ b/usr/src/sbin/tunefs/tunefs.c @@ -11,7 +11,7 @@ char copyright[] = #endif not lint #ifndef lint -static char sccsid[] = "@(#)tunefs.c 5.3 (Berkeley) %G%"; +static char sccsid[] = "@(#)tunefs.c 5.4 (Berkeley) %G%"; #endif not lint /* @@ -33,6 +33,7 @@ union { #define sblock sbun.sb int fi; +long dev_bsize = 1; main(argc, argv) int argc; @@ -178,7 +179,7 @@ again: } if (argc != 1) goto usage; - bwrite(SBLOCK, (char *)&sblock, SBSIZE); + bwrite(SBOFF / dev_bsize, (char *)&sblock, SBSIZE); if (Aflag) for (i = 0; i < sblock.fs_ncg; i++) bwrite(fsbtodb(&sblock, cgsblock(&sblock, i)), @@ -207,7 +208,7 @@ getsb(fs, file) perror(file); exit(3); } - if (bread(SBLOCK, (char *)fs, SBSIZE)) { + if (bread(SBOFF, (char *)fs, SBSIZE)) { fprintf(stderr, "bad super block"); perror(file); exit(4); @@ -216,6 +217,7 @@ getsb(fs, file) fprintf(stderr, "%s: bad magic number\n", file); exit(5); } + dev_bsize = fs->fs_fsize / fsbtodb(fs, 1); } bwrite(blk, buf, size) @@ -223,7 +225,7 @@ bwrite(blk, buf, size) daddr_t blk; register size; { - if (lseek(fi, blk * DEV_BSIZE, 0) < 0) { + if (lseek(fi, blk * dev_bsize, 0) < 0) { perror("FS SEEK"); exit(6); } @@ -239,7 +241,7 @@ bread(bno, buf, cnt) { register i; - if (lseek(fi, bno * DEV_BSIZE, 0) < 0) + if (lseek(fi, bno * dev_bsize, 0) < 0) return(1); if ((i = read(fi, buf, cnt)) != cnt) { for(i=0; ifs_fsize / fsbtodb(fs, 1); fscs = (struct csum *)calloc(1, fs->fs_cssize); for (i = 0; i < fs->fs_cssize; i += fs->fs_bsize) rdfs(fsbtodb(fs, fs->fs_csaddr + numfrags(fs, i)), @@ -70,7 +72,7 @@ main(argc, argv) ((char *)fscs) + i); proto = fopen(argv[2], "r"); descend((struct inode *)0); - wtfs(SBLOCK, SBSIZE, (char *)fs); + wtfs(SBOFF / dev_bsize, SBSIZE, (char *)fs); for (i = 0; i < fs->fs_cssize; i += fs->fs_bsize) wtfs(fsbtodb(&sblock, fs->fs_csaddr + numfrags(&sblock, i)), (int)(fs->fs_cssize - i < fs->fs_bsize ? @@ -450,7 +452,7 @@ rdfs(bno, size, bf) { int n; - if (lseek(fsi, bno * DEV_BSIZE, 0) < 0) { + if (lseek(fsi, bno * dev_bsize, 0) < 0) { printf("seek error: %ld\n", bno); perror("rdfs"); exit(1); @@ -472,8 +474,7 @@ wtfs(bno, size, bf) { int n; - lseek(fso, bno * DEV_BSIZE, 0); - if (lseek(fso, bno * DEV_BSIZE, 0) < 0) { + if (lseek(fso, bno * dev_bsize, 0) < 0) { printf("seek error: %ld\n", bno); perror("wtfs"); exit(1); diff --git a/usr/src/usr.sbin/quot/quot.c b/usr/src/usr.sbin/quot/quot.c index 5d08db6d30..15d967e668 100644 --- a/usr/src/usr.sbin/quot/quot.c +++ b/usr/src/usr.sbin/quot/quot.c @@ -1,5 +1,5 @@ #ifndef lint -static char *sccsid = "@(#)quot.c 4.11 (Berkeley) 85/09/09"; +static char *sccsid = "@(#)quot.c 4.12 (Berkeley) 87/02/23"; #endif /* @@ -46,6 +46,7 @@ int cflg; int vflg; int hflg; long now; +long dev_bsize = 1; unsigned ino; @@ -153,7 +154,8 @@ check(file, fsdir) printf(" (%s)", fsdir); printf(":\n"); sync(); - bread(fd, SBLOCK, (char *)&sblock, SBSIZE); + bread(fd, SBOFF, (char *)&sblock, SBSIZE); + dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); if (nflg) { if (isdigit(c = getchar())) ungetc(c, stdin); @@ -269,7 +271,7 @@ bread(fd, bno, buf, cnt) char *buf; { - lseek(fd, (long)bno * DEV_BSIZE, L_SET); + lseek(fd, (long)bno * dev_bsize, L_SET); if (read(fd, buf, cnt) != cnt) { fprintf(stderr, "quot: read error at block %u\n", bno); exit(1); -- 2.20.1