From 3421522f5324cea391ab07b7c1f8b7b7ce035ba5 Mon Sep 17 00:00:00 2001 From: kris Date: Wed, 9 May 2001 08:44:15 +0000 Subject: Fix operation of df on unmounted filesystems, and add the ability to run df on unmounted non-UFS filesystem using '-t' Submitted by: bde --- bin/df/df.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'bin/df') 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; /* -- cgit v1.1