From d704245c81126879f7dc17d84768dfe6451bbe9c Mon Sep 17 00:00:00 2001 From: uqs Date: Sun, 21 Oct 2012 12:01:11 +0000 Subject: sbin/fsck: s/perror/perr/ to avoid shadowing - rename some other vars too - merge NetBSD license changes Obtained from: NetBSD PR: bin/139802 Reviewed by: ed --- sbin/fsck/fsck.c | 16 ++++++---------- sbin/fsck/fsutil.c | 33 +++++++++++++++++---------------- sbin/fsck/fsutil.h | 9 ++------- sbin/fsck/preen.c | 10 +++++----- sbin/fsck_msdosfs/boot.c | 14 +++++++------- sbin/fsck_msdosfs/check.c | 4 ++-- sbin/fsck_msdosfs/dir.c | 33 +++++++++++++++++---------------- sbin/fsck_msdosfs/fat.c | 34 ++++++++++++++++++---------------- 8 files changed, 74 insertions(+), 79 deletions(-) diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c index 768e670..9812b65 100644 --- a/sbin/fsck/fsck.c +++ b/sbin/fsck/fsck.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsck.c,v 1.21 1999/04/22 04:20:53 abs Exp $ */ +/* $NetBSD: fsck.c,v 1.30 2003/08/07 10:04:15 agc Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -13,11 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,7 +31,7 @@ * * From: @(#)mount.c 8.19 (Berkeley) 4/19/94 * From: $NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp - * $NetBSD: fsck.c,v 1.21 1999/04/22 04:20:53 abs Exp $ + * $NetBSD: fsck.c,v 1.30 2003/08/07 10:04:15 agc Exp $ */ #include @@ -315,7 +311,7 @@ checkfs(const char *pvfstype, const char *spec, const char *mntpt, */ vfstype = strdup(pvfstype); if (vfstype == NULL) - perror("strdup(pvfstype)"); + perr("strdup(pvfstype)"); for (i = 0; i < strlen(vfstype); i++) { vfstype[i] = tolower(vfstype[i]); if (vfstype[i] == ' ') @@ -502,7 +498,7 @@ catopt(char **sp, const char *o) static void -mangle(char *options, int *argcp, const char ***argvp, int *maxargcp) +mangle(char *opts, int *argcp, const char ***argvp, int *maxargcp) { char *p, *s; int argc, maxargc; @@ -512,7 +508,7 @@ mangle(char *options, int *argcp, const char ***argvp, int *maxargcp) argv = *argvp; maxargc = *maxargcp; - for (s = options; (p = strsep(&s, ",")) != NULL;) { + for (s = opts; (p = strsep(&s, ",")) != NULL;) { /* Always leave space for one more argument and the NULL. */ if (argc >= maxargc - 3) { maxargc <<= 1; diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c index a4578bd..935992e 100644 --- a/sbin/fsck/fsutil.c +++ b/sbin/fsck/fsutil.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsutil.c,v 1.7 1998/07/30 17:41:03 thorpej Exp $ */ +/* $NetBSD: fsutil.c,v 1.15 2006/06/05 16:52:05 christos Exp $ */ /* * Copyright (c) 1990, 1993 @@ -12,7 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fsutil.c,v 1.7 1998/07/30 17:41:03 thorpej Exp $"); +__RCSID("$NetBSD: fsutil.c,v 1.15 2006/06/05 16:52:05 christos Exp $"); #endif /* not lint */ __FBSDID("$FreeBSD$"); @@ -110,9 +110,13 @@ pwarn(const char *fmt, ...) } void -perror(const char *s) +perr(const char *fmt, ...) { - pfatal("%s (%s)", s, strerror(errno)); + va_list ap; + + va_start(ap, fmt); + vmsg(1, fmt, ap); + va_end(ap); } void @@ -132,18 +136,15 @@ devcheck(const char *origname) struct stat stslash, stchar; if (stat("/", &stslash) < 0) { - perror("/"); - printf("Can't stat root\n"); + perr("Can't stat `/'"); return (origname); } if (stat(origname, &stchar) < 0) { - perror(origname); - printf("Can't stat %s\n", origname); + perr("Can't stat %s\n", origname); return (origname); } if (!S_ISCHR(stchar.st_mode)) { - perror(origname); - printf("%s is not a char device\n", origname); + perr("%s is not a char device\n", origname); } return (origname); } @@ -156,7 +157,7 @@ getmntpt(const char *name) { struct stat devstat, mntdevstat; char device[sizeof(_PATH_DEV) - 1 + MNAMELEN]; - char *devname; + char *dev_name; struct statfs *mntbuf, *statfsp; int i, mntsize, isdev; @@ -169,10 +170,10 @@ getmntpt(const char *name) mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); for (i = 0; i < mntsize; i++) { statfsp = &mntbuf[i]; - devname = statfsp->f_mntfromname; - if (*devname != '/') { + dev_name = statfsp->f_mntfromname; + if (*dev_name != '/') { strcpy(device, _PATH_DEV); - strcat(device, devname); + strcat(device, dev_name); strcpy(statfsp->f_mntfromname, device); } if (isdev == 0) { @@ -180,7 +181,7 @@ getmntpt(const char *name) continue; return (statfsp); } - if (stat(devname, &mntdevstat) == 0 && + if (stat(dev_name, &mntdevstat) == 0 && mntdevstat.st_rdev == devstat.st_rdev) return (statfsp); } diff --git a/sbin/fsck/fsutil.h b/sbin/fsck/fsutil.h index 657668e..b1ce6f1 100644 --- a/sbin/fsck/fsutil.h +++ b/sbin/fsck/fsutil.h @@ -1,4 +1,4 @@ -/* $NetBSD: fsutil.h,v 1.4 1998/07/26 20:02:36 mycroft Exp $ */ +/* $NetBSD: fsutil.h,v 1.114 2009/10/21 01:07:46 snj Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -11,11 +11,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christos Zoulas. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -31,9 +26,9 @@ * $FreeBSD$ */ -void perror(const char *); void pfatal(const char *, ...) __printflike(1, 2); void pwarn(const char *, ...) __printflike(1, 2); +void perr(const char *, ...) __printflike(1, 2); void panic(const char *, ...) __dead2 __printflike(1, 2); const char *devcheck(const char *); const char *cdevname(void); diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c index 787bed0..1437e11 100644 --- a/sbin/fsck/preen.c +++ b/sbin/fsck/preen.c @@ -295,19 +295,19 @@ printpart(void) static void -addpart(const char *type, const char *devname, const char *mntpt) +addpart(const char *type, const char *dev, const char *mntpt) { - struct diskentry *d = finddisk(devname); + struct diskentry *d = finddisk(dev); struct partentry *p; TAILQ_FOREACH(p, &d->d_part, p_entries) - if (strcmp(p->p_devname, devname) == 0) { - warnx("%s in fstab more than once!\n", devname); + if (strcmp(p->p_devname, dev) == 0) { + warnx("%s in fstab more than once!\n", dev); return; } p = emalloc(sizeof(*p)); - p->p_devname = estrdup(devname); + p->p_devname = estrdup(dev); p->p_mntpt = estrdup(mntpt); p->p_type = estrdup(type); diff --git a/sbin/fsck_msdosfs/boot.c b/sbin/fsck_msdosfs/boot.c index fe60f3a..97d9419 100644 --- a/sbin/fsck_msdosfs/boot.c +++ b/sbin/fsck_msdosfs/boot.c @@ -26,7 +26,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.9 2003/07/24 19:25:46 ws Exp $"); +__RCSID("$NetBSD: boot.c,v 1.11 2006/06/05 16:51:18 christos Exp "); static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ @@ -49,7 +49,7 @@ readboot(int dosfs, struct bootblock *boot) int i; if (read(dosfs, block, sizeof block) != sizeof block) { - perror("could not read boot block"); + perr("could not read boot block"); return FSFATAL; } @@ -103,7 +103,7 @@ readboot(int dosfs, struct bootblock *boot) if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) != boot->bpbFSInfo * boot->bpbBytesPerSec || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { - perror("could not read fsinfo block"); + perr("could not read fsinfo block"); return FSFATAL; } if (memcmp(fsinfo, "RRaA", 4) @@ -131,7 +131,7 @@ readboot(int dosfs, struct bootblock *boot) != boot->bpbFSInfo * boot->bpbBytesPerSec || write(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { - perror("Unable to write bpbFSInfo"); + perr("Unable to write bpbFSInfo"); return FSFATAL; } ret = FSBOOTMOD; @@ -151,7 +151,7 @@ readboot(int dosfs, struct bootblock *boot) SEEK_SET) != boot->bpbBackup * boot->bpbBytesPerSec || read(dosfs, backup, sizeof backup) != sizeof backup) { - perror("could not read backup bootblock"); + perr("could not read backup bootblock"); return FSFATAL; } backup[65] = block[65]; /* XXX */ @@ -242,7 +242,7 @@ writefsinfo(int dosfs, struct bootblock *boot) if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) != boot->bpbFSInfo * boot->bpbBytesPerSec || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { - perror("could not read fsinfo block"); + perr("could not read fsinfo block"); return FSFATAL; } fsinfo[0x1e8] = (u_char)boot->FSFree; @@ -257,7 +257,7 @@ writefsinfo(int dosfs, struct bootblock *boot) != boot->bpbFSInfo * boot->bpbBytesPerSec || write(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { - perror("Unable to write bpbFSInfo"); + perr("Unable to write bpbFSInfo"); return FSFATAL; } /* diff --git a/sbin/fsck_msdosfs/check.c b/sbin/fsck_msdosfs/check.c index 2f558bd..a522d88 100644 --- a/sbin/fsck_msdosfs/check.c +++ b/sbin/fsck_msdosfs/check.c @@ -26,7 +26,7 @@ #include #ifndef lint -__RCSID("$NetBSD: check.c,v 1.10 2000/04/25 23:02:51 jdolecek Exp $"); +__RCSID("$NetBSD: check.c,v 1.14 2006/06/05 16:51:18 christos Exp $"); static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ @@ -67,7 +67,7 @@ checkfilesys(const char *fname) printf("\n"); if (dosfs < 0) { - perror("Can't open"); + perr("Can't open `%s'", fname); return 8; } diff --git a/sbin/fsck_msdosfs/dir.c b/sbin/fsck_msdosfs/dir.c index 1dc4456..008d0b3 100644 --- a/sbin/fsck_msdosfs/dir.c +++ b/sbin/fsck_msdosfs/dir.c @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: dir.c,v 1.14 1998/08/25 19:18:15 ross Exp $"); +__RCSID("$NetBSD: dir.c,v 1.20 2006/06/05 16:51:18 christos Exp $"); static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ @@ -218,25 +218,26 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat) int b1, b2; cl_t cl; int ret = FSOK; + size_t len; b1 = boot->bpbRootDirEnts * 32; b2 = boot->bpbSecPerClust * boot->bpbBytesPerSec; - if ((buffer = malloc( b1 > b2 ? b1 : b2)) == NULL) { - perror("No space for directory buffer"); + if ((buffer = malloc(len = b1 > b2 ? b1 : b2)) == NULL) { + perr("No space for directory buffer (%zu)", len); return FSFATAL; } - if ((delbuf = malloc(b2)) == NULL) { + if ((delbuf = malloc(len = b2)) == NULL) { free(buffer); - perror("No space for directory delbuf"); + perr("No space for directory delbuf (%zu)", len); return FSFATAL; } if ((rootDir = newDosDirEntry()) == NULL) { free(buffer); free(delbuf); - perror("No space for directory entry"); + perr("No space for directory entry"); return FSFATAL; } @@ -328,7 +329,7 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl, off *= boot->bpbBytesPerSec; if (lseek(f, off, SEEK_SET) != off || read(f, delbuf, clsz) != clsz) { - perror("Unable to read directory"); + perr("Unable to read directory"); return FSFATAL; } while (s < e) { @@ -337,7 +338,7 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl, } if (lseek(f, off, SEEK_SET) != off || write(f, delbuf, clsz) != clsz) { - perror("Unable to write directory"); + perr("Unable to write directory"); return FSFATAL; } if (startcl == endcl) @@ -475,7 +476,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, off *= boot->bpbBytesPerSec; if (lseek(f, off, SEEK_SET) != off || read(f, buffer, last) != last) { - perror("Unable to read directory"); + perr("Unable to read directory"); return FSFATAL; } last /= 32; @@ -821,7 +822,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, /* create directory tree node */ if (!(d = newDosDirEntry())) { - perror("No space for directory"); + perr("No space for directory"); return FSFATAL; } memcpy(d, &dirent, sizeof(struct dosDirEntry)); @@ -830,7 +831,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, /* Enter this directory into the todo list */ if (!(n = newDirTodo())) { - perror("No space for todo list"); + perr("No space for todo list"); return FSFATAL; } n->next = pendingDirectories; @@ -851,7 +852,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, last *= 32; if (lseek(f, off, SEEK_SET) != off || write(f, buffer, last) != last) { - perror("Unable to write directory"); + perr("Unable to write directory"); return FSFATAL; } mod &= ~THISMOD; @@ -870,7 +871,7 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, last *= 32; if (lseek(f, off, SEEK_SET) != off || write(f, buffer, last) != last) { - perror("Unable to write directory"); + perr("Unable to write directory"); return FSFATAL; } mod &= ~THISMOD; @@ -941,7 +942,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) if (!lfbuf) { lfbuf = malloc(boot->ClusterSize); if (!lfbuf) { - perror("No space for buffer"); + perr("No space for buffer"); return FSFATAL; } p = NULL; @@ -965,7 +966,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) + boot->ClusterOffset * boot->bpbBytesPerSec; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { - perror("could not read LOST.DIR"); + perr("could not read LOST.DIR"); return FSFATAL; } p = lfbuf; @@ -995,7 +996,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) fat[head].flags |= FAT_USED; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff || (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { - perror("could not write LOST.DIR"); + perr("could not write LOST.DIR"); return FSFATAL; } return FSDIRMOD; diff --git a/sbin/fsck_msdosfs/fat.c b/sbin/fsck_msdosfs/fat.c index 7a6368c..837bd69 100644 --- a/sbin/fsck_msdosfs/fat.c +++ b/sbin/fsck_msdosfs/fat.c @@ -26,7 +26,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fat.c,v 1.12 2000/10/10 20:24:52 is Exp $"); +__RCSID("$NetBSD: fat.c,v 1.18 2006/06/05 16:51:18 christos Exp $"); static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ @@ -69,6 +69,7 @@ checkdirty(int fs, struct bootblock *boot) off_t off; u_char *buffer; int ret = 0; + size_t len; if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK) return 0; @@ -76,20 +77,20 @@ checkdirty(int fs, struct bootblock *boot) off = boot->bpbResSectors; off *= boot->bpbBytesPerSec; - buffer = malloc(boot->bpbBytesPerSec); + buffer = malloc(len = boot->bpbBytesPerSec); if (buffer == NULL) { - perror("No space for FAT"); + perr("No space for FAT sectors (%zu)", len); return 1; } if (lseek(fs, off, SEEK_SET) != off) { - perror("Unable to read FAT"); + perr("Unable to read FAT"); goto err; } if ((size_t)read(fs, buffer, boot->bpbBytesPerSec) != boot->bpbBytesPerSec) { - perror("Unable to read FAT"); + perr("Unable to read FAT"); goto err; } @@ -163,10 +164,11 @@ static int _readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer) { off_t off; + size_t len; - *buffer = malloc(boot->FATsecs * boot->bpbBytesPerSec); + *buffer = malloc(len = boot->FATsecs * boot->bpbBytesPerSec); if (*buffer == NULL) { - perror("No space for FAT"); + perr("No space for FAT sectors (%zu)", len); return 0; } @@ -174,13 +176,13 @@ _readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer) off *= boot->bpbBytesPerSec; if (lseek(fs, off, SEEK_SET) != off) { - perror("Unable to read FAT"); + perr("Unable to read FAT"); goto err; } if ((size_t)read(fs, *buffer, boot->FATsecs * boot->bpbBytesPerSec) != boot->FATsecs * boot->bpbBytesPerSec) { - perror("Unable to read FAT"); + perr("Unable to read FAT"); goto err; } @@ -207,10 +209,10 @@ readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp) if (!_readfat(fs, boot, no, &buffer)) return FSFATAL; - + fat = malloc(len = boot->NumClusters * sizeof(struct fatEntry)); if (fat == NULL) { - perror("No space for FAT"); + perr("No space for FAT clusters (%zu)", len); free(buffer); return FSFATAL; } @@ -428,13 +430,13 @@ clearchain(struct bootblock *boot, struct fatEntry *fat, cl_t head) } int -tryclear(struct bootblock *boot, struct fatEntry *fat, cl_t head, cl_t *trunc) +tryclear(struct bootblock *boot, struct fatEntry *fat, cl_t head, cl_t *truncp) { if (ask(0, "Clear chain starting at %u", head)) { clearchain(boot, fat, head); return FSFATMOD; } else if (ask(0, "Truncate")) { - *trunc = CLUST_EOF; + *truncp = CLUST_EOF; return FSFATMOD; } else return FSERROR; @@ -549,7 +551,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) buffer = malloc(fatsz = boot->FATsecs * boot->bpbBytesPerSec); if (buffer == NULL) { - perror("No space for FAT"); + perr("No space for FAT sectors (%zu)", fatsz); return FSFATAL; } memset(buffer, 0, fatsz); @@ -598,7 +600,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) free(old_fat); p += count; } - + for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++) { switch (boot->ClustMask) { case CLUST32_MASK: @@ -634,7 +636,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) off *= boot->bpbBytesPerSec; if (lseek(fs, off, SEEK_SET) != off || (size_t)write(fs, buffer, fatsz) != fatsz) { - perror("Unable to write FAT"); + perr("Unable to write FAT"); ret = FSFATAL; /* Return immediately? XXX */ } } -- cgit v1.1