summaryrefslogtreecommitdiff
path: root/sbin/fsck/preen.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/fsck/preen.c')
-rw-r--r--sbin/fsck/preen.c60
1 files changed, 26 insertions, 34 deletions
diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c
index cc8bba6e1e66d..9705aeea92807 100644
--- a/sbin/fsck/preen.c
+++ b/sbin/fsck/preen.c
@@ -36,7 +36,7 @@
static const char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
- "$Id: preen.c,v 1.9 1998/06/15 07:07:20 charnier Exp $";
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
@@ -46,7 +46,7 @@ static const char rcsid[] =
#include <ufs/ufs/dinode.h>
#include <ctype.h>
-#include <errno.h>
+#include <err.h>
#include <fstab.h>
#include <string.h>
@@ -93,8 +93,7 @@ checkfstab(preen, maxrun, docheck, chkit)
sumstatus = 0;
for (passno = 1; passno <= 2; passno++) {
if (setfsent() == 0) {
- fprintf(stderr, "Can't open checklist file: %s\n",
- _PATH_FSTAB);
+ warnx("can't open checklist file: %s", _PATH_FSTAB);
return (8);
}
while ((fsp = getfsent()) != 0) {
@@ -223,15 +222,11 @@ finddisk(name)
dk->name[len] == 0)
return (dk);
}
- if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
+ if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL)
+ errx(8, "out of memory");
dk = *dkp;
- if ((dk->name = malloc(len + 1)) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
+ if ((dk->name = malloc(len + 1)) == NULL)
+ errx(8, "out of memory");
(void)strncpy(dk->name, name, len);
dk->name[len] = '\0';
dk->part = NULL;
@@ -254,20 +249,14 @@ addpart(name, fsname, auxdata)
printf("%s in fstab more than once!\n", name);
return;
}
- if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
+ if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL)
+ errx(8, "out of memory");
pt = *ppt;
- if ((pt->name = malloc(strlen(name) + 1)) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
+ if ((pt->name = malloc(strlen(name) + 1)) == NULL)
+ errx(8, "out of memory");
(void)strcpy(pt->name, name);
- if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
+ if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL)
+ errx(8, "out of memory");
(void)strcpy(pt->fsname, fsname);
pt->next = NULL;
pt->auxdata = auxdata;
@@ -282,7 +271,7 @@ startdisk(dk, checkit)
dk->pid = fork();
if (dk->pid < 0) {
- perror("fork");
+ warn("fork");
return (8);
}
if (dk->pid == 0)
@@ -298,17 +287,19 @@ blockcheck(origname)
struct stat stslash, stblock, stchar;
char *newname, *raw;
struct fstab *fsinfo;
- int retried = 0, len;
+ int retried = 0, l;
hotroot = 0;
if (stat("/", &stslash) < 0) {
- printf("Can't stat /: %s\n", strerror(errno));
+ warn("/");
+ printf("Can't stat root\n");
return (origname);
}
newname = origname;
retry:
if (stat(newname, &stblock) < 0) {
- printf("Can't stat %s: %s\n", newname, strerror(errno));
+ warn("%s", newname);
+ printf("Can't stat %s\n", newname);
return (origname);
}
if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
@@ -316,7 +307,8 @@ retry:
hotroot++;
raw = rawname(newname);
if (stat(raw, &stchar) < 0) {
- printf("Can't stat %s: %s\n", raw, strerror(errno));
+ warn("%s", raw);
+ printf("Can't stat %s\n", raw);
return (origname);
}
if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
@@ -326,15 +318,15 @@ retry:
return (origname);
}
} else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
- newname = unrawname(newname);
+ newname = unrawname(origname);
retried++;
goto retry;
} else if ((stblock.st_mode & S_IFMT) == S_IFDIR && !retried) {
- len = strlen(origname) - 1;
- if (len > 0 && origname[len] == '/')
+ l = strlen(origname) - 1;
+ if (l > 0 && origname[l] == '/')
/* remove trailing slash */
- origname[len] = '\0';
- if ((fsinfo = getfsfile(origname)) == NULL) {
+ origname[l] = '\0';
+ if(!(fsinfo=getfsfile(origname))) {
printf("Can't resolve %s to character special device",
origname);
return (0);