Fix operation of df on unmounted filesystems, and add the ability to run df
on unmounted non-UFS filesystem using '-t' Submitted by: bde
This commit is contained in:
parent
e58c2d0ce4
commit
f3895a821a
40
bin/df/df.c
40
bin/df/df.c
@ -119,7 +119,9 @@ main(argc, argv)
|
||||
struct statfs statfsbuf, *mntbuf;
|
||||
long mntsize;
|
||||
int ch, err, i, maxwidth, rv, width;
|
||||
char *mntpt, **vfslist;
|
||||
char *fstype, *mntpath, *mntpt, **vfslist;
|
||||
|
||||
fstype = "ufs";
|
||||
|
||||
vfslist = NULL;
|
||||
while ((ch = getopt(argc, argv, "abgHhikmnPt:")) != -1)
|
||||
@ -162,6 +164,7 @@ main(argc, argv)
|
||||
case 't':
|
||||
if (vfslist != NULL)
|
||||
errx(1, "only one -t option may be specified.");
|
||||
fstype = optarg;
|
||||
vfslist = makevfslist(optarg);
|
||||
break;
|
||||
case '?':
|
||||
@ -205,9 +208,40 @@ main(argc, argv)
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
} else if ((stbuf.st_mode & S_IFMT) == S_IFCHR) {
|
||||
rv = ufs_df(*argv, maxwidth) || rv;
|
||||
} else if (S_ISCHR(stbuf.st_mode)) {
|
||||
if ((mntpt = getmntpt(*argv)) == 0) {
|
||||
mdev.fspec = *argv;
|
||||
mntpath = strdup("/tmp/df.XXXXXX");
|
||||
if (mntpath == NULL) {
|
||||
warn("strdup failed");
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
mntpt = mkdtemp(mntpath);
|
||||
if (mntpt == NULL) {
|
||||
warn("mkdtemp(\"%s\") failed", mntpath);
|
||||
rv = 1;
|
||||
free(mntpath);
|
||||
continue;
|
||||
}
|
||||
if (mount(fstype, mntpt, MNT_RDONLY,
|
||||
&mdev) != 0) {
|
||||
rv = ufs_df(*argv, maxwidth) || rv;
|
||||
(void)rmdir(mntpt);
|
||||
free(mntpath);
|
||||
continue;
|
||||
} else if (statfs(mntpt, &statfsbuf) == 0) {
|
||||
statfsbuf.f_mntonname[0] = '\0';
|
||||
prtstat(&statfsbuf, maxwidth);
|
||||
} else {
|
||||
warn("%s", *argv);
|
||||
rv = 1;
|
||||
}
|
||||
(void)unmount(mntpt, 0);
|
||||
(void)rmdir(mntpt);
|
||||
free(mntpath);
|
||||
continue;
|
||||
}
|
||||
} else
|
||||
mntpt = *argv;
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user