+ extern int errno;
+ struct stat stbuf;
+ struct statfs statfsbuf;
+ register struct statfs *sfsp;
+ struct fstab *fsp;
+ char *mntpt;
+
+ if (stat(file, &stbuf) == 0 &&
+ (stbuf.st_mode&S_IFMT) != S_IFCHR &&
+ (stbuf.st_mode&S_IFMT) != S_IFBLK) {
+ if (infsent) {
+ fprintf(stderr, "df: %s: screwy fstab entry\n", file);
+ return;
+ }
+ (void)setfsent();
+ while (fsp = getfsent()) {
+ struct stat stb;
+
+ if (stat(fsp->fs_spec, &stb) == 0 &&
+ stb.st_rdev == stbuf.st_dev) {
+ file = fsp->fs_spec;
+ (void)endfsent();
+ goto found;
+ }
+ }
+ (void)endfsent();
+ fprintf(stderr, "df: %s: mounted on unknown device\n", file);
+ return;
+ }
+found:
+ if ((fi = open(file, O_RDONLY)) < 0) {
+ fprintf(stderr, "df: %s: %s\n", file, strerror(errno));
+ return;
+ }
+ if (bread((long)SBOFF, (char *)&sblock, SBSIZE) == 0) {
+ (void) close(fi);
+ return;
+ }
+ sfsp = &statfsbuf;
+ sfsp->f_type = MOUNT_UFS;
+ sfsp->f_flags = 0;
+ sfsp->f_fsize = sblock.fs_fsize;
+ sfsp->f_bsize = sblock.fs_bsize;
+ sfsp->f_blocks = sblock.fs_dsize;
+ sfsp->f_bfree = sblock.fs_cstotal.cs_nbfree * sblock.fs_frag +
+ sblock.fs_cstotal.cs_nffree;
+ sfsp->f_bavail = (sblock.fs_dsize * (100 - sblock.fs_minfree) / 100) -
+ (sblock.fs_dsize - sfsp->f_bfree);
+ if (sfsp->f_bavail < 0)
+ sfsp->f_bavail = 0;
+ sfsp->f_files = sblock.fs_ncg * sblock.fs_ipg;
+ sfsp->f_ffree = sblock.fs_cstotal.cs_nifree;
+ sfsp->f_fsid.val[0] = 0;
+ sfsp->f_fsid.val[1] = 0;
+ if ((mntpt = getmntpt(file)) == 0)
+ mntpt = "";
+ bcopy((caddr_t)mntpt, (caddr_t)&sfsp->f_mntonname[0], MNAMELEN);
+ bcopy((caddr_t)file, (caddr_t)&sfsp->f_mntfromname[0], MNAMELEN);
+ prtstat(sfsp, maxwidth);
+ (void) close(fi);