-/*
- * This code constitutes the pre-system call Berkeley df code for extracting
- * information from filesystem superblocks.
- */
-
-union {
- struct fs iu_fs;
- char dummy[SBSIZE];
-} sb;
-#define sblock sb.iu_fs
-
-int rfd;
-
-int
-ufs_df(char *file, struct maxwidths *mwp)
-{
- struct statfs statfsbuf;
- struct statfs *sfsp;
- const char *mntpt;
- static int synced;
-
- if (synced++ == 0)
- sync();
-
- if ((rfd = open(file, O_RDONLY)) < 0) {
- warn("%s", file);
- return (1);
- }
- if (bread((off_t)SBOFF, &sblock, SBSIZE) == 0) {
- (void)close(rfd);
- return (1);
- }
- sfsp = &statfsbuf;
- sfsp->f_type = 1;
- strcpy(sfsp->f_fstypename, "ufs");
- sfsp->f_flags = 0;
- sfsp->f_bsize = sblock.fs_fsize;
- sfsp->f_iosize = 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 = freespace(&sblock, sblock.fs_minfree);
- 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 = "";
- memmove(&sfsp->f_mntonname[0], mntpt, (size_t)MNAMELEN);
- memmove(&sfsp->f_mntfromname[0], file, (size_t)MNAMELEN);
- prtstat(sfsp, mwp);
- (void)close(rfd);
- return (0);
-}
-
-int
-bread(off_t off, void *buf, int cnt)
-{
- ssize_t nr;
-
- (void)lseek(rfd, off, SEEK_SET);
- if ((nr = read(rfd, buf, (size_t)cnt)) != (ssize_t)cnt) {
- /* Probably a dismounted disk if errno == EIO. */
- if (errno != EIO)
- (void)fprintf(stderr, "\ndf: %lld: %s\n",
- (long long)off, strerror(nr > 0 ? EIO : errno));
- return (0);
- }
- return (1);
-}
-