diff options
author | kris <kris@FreeBSD.org> | 2001-05-09 08:44:15 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2001-05-09 08:44:15 +0000 |
commit | 3421522f5324cea391ab07b7c1f8b7b7ce035ba5 (patch) | |
tree | c55ce35d1d0fc4c406f87426cf36589dcb07ceb2 /bin/df/df.c | |
parent | e231ed05e32582d27ca2e8cd8958dfb31103db4b (diff) | |
download | FreeBSD-src-3421522f5324cea391ab07b7c1f8b7b7ce035ba5.zip FreeBSD-src-3421522f5324cea391ab07b7c1f8b7b7ce035ba5.tar.gz |
Fix operation of df on unmounted filesystems, and add the ability to run df
on unmounted non-UFS filesystem using '-t'
Submitted by: bde
Diffstat (limited to 'bin/df/df.c')
-rw-r--r-- | bin/df/df.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/bin/df/df.c b/bin/df/df.c index e7ab41f..96c7ae5 100644 --- a/bin/df/df.c +++ b/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; - continue; + } 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; /* |