diff --git a/bin/df/df.c b/bin/df/df.c index e7ab41fd966f..96c7ae54f018 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; /*