diff --git a/bin/df/Makefile b/bin/df/Makefile index 813c56b59c34..9886abf8a594 100644 --- a/bin/df/Makefile +++ b/bin/df/Makefile @@ -1,8 +1,7 @@ -# from: @(#)Makefile 5.3 (Berkeley) 5/11/90 -# $Id: Makefile,v 1.7 1994/01/28 00:22:37 cgd Exp $ +# from: @(#)Makefile 8.2 (Berkeley) 4/1/94 +# $Id: Makefile,v 1.8 1994/09/16 20:59:27 mycroft Exp $ PROG= df -CFLAGS+=-DCOMPAT_43 BINGRP= operator BINMODE=2555 diff --git a/bin/df/df.1 b/bin/df/df.1 index 14566f7e45d9..43e8d4a59cde 100644 --- a/bin/df/df.1 +++ b/bin/df/df.1 @@ -1,5 +1,5 @@ -.\" Copyright (c) 1989, 1990 The Regents of the University of California. -.\" All rights reserved. +.\" Copyright (c) 1989, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -29,10 +29,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)df.1 6.10 (Berkeley) 3/1/92 -.\" $Id: df.1,v 1.6 1994/03/11 03:07:27 mycroft Exp $ +.\" from: @(#)df.1 8.2 (Berkeley) 1/13/92 +.\" $Id: df.1,v 1.7 1994/09/16 20:59:28 mycroft Exp $ .\" -.Dd March 1, 1992 +.Dd January 13, 1994 .Dt DF 1 .Os BSD 4 .Sh NAME @@ -49,8 +49,12 @@ displays statistics about the amount of free disk space on the specified or on the filesystem of which .Ar file is a part. +Values are displayed in 512-byte per block block counts. If neither a file or a filesystem operand is specified, -statistics for all mounted filesystems are displayed. +statistics for all mounted filesystems are displayed +(subject to the +.Fl l +option below). .Pp The following options are available: .Bl -tag -width Ds diff --git a/bin/df/df.c b/bin/df/df.c index 398457deafcf..d3fb1165a3cd 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -1,6 +1,6 @@ /* - * Copyright (c) 1980, 1990 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1980, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph @@ -37,32 +37,32 @@ */ #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1980, 1990 The Regents of the University of California.\n\ - All rights reserved.\n"; +static char copyright[] = +"@(#) Copyright (c) 1980, 1990, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)df.c 5.30 (Berkeley) 4/23/92";*/ -static char rcsid[] = "$Id: df.c,v 1.14 1994/07/12 07:58:27 glass Exp $"; +/*static char sccsid[] = "from: @(#)df.c 8.7 (Berkeley) 4/2/94";*/ +static char rcsid[] = "$Id: df.c,v 1.15 1994/09/16 20:59:29 mycroft Exp $"; #endif /* not lint */ #include #include #include -#include + #include +#include #include #include #include #include - #include -int bread __P((long, char *, int)); +int bread __P((off_t, void *, int)); char *getmntpt __P((char *)); -void prtstat __P((struct statfs *, long)); -void ufs_df __P((char *, long)); +void prtstat __P((struct statfs *, int)); +void ufs_df __P((char *, int)); void usage __P((void)); int iflag, kflag = 0, nflag, lflag; @@ -82,7 +82,7 @@ main(argc, argv) char *mntpt; while ((ch = getopt(argc, argv, "ikln")) != EOF) - switch(ch) { + switch (ch) { case 'i': iflag = 1; break; @@ -115,12 +115,14 @@ main(argc, argv) if (width > maxwidth) maxwidth = width; } + if (!*argv) { for (i = 0; i < mntsize; i++) if (!lflag || mntbuf[i].f_flags & MNT_LOCAL) prtstat(&mntbuf[i], maxwidth); exit(0); } + for (; *argv; argv++) { if (stat(*argv, &stbuf) < 0) { if ((mntpt = getmntpt(*argv)) == 0) { @@ -182,13 +184,21 @@ getmntpt(name) return (0); } +/* + * Convert statfs returned filesystem size into BLOCKSIZE units. + * Attempts to avoid overflow for large filesystems. + */ +#define fsbtoblk(num, fsbs, bs) \ + (((fsbs) != 0 && (fsbs) < (bs)) ? \ + (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs))) + /* * Print out status about a filesystem. */ void prtstat(sfsp, maxwidth) - register struct statfs *sfsp; - long maxwidth; + struct statfs *sfsp; + int maxwidth; { static int headerlen, timesthrough; static char *header; @@ -202,7 +212,7 @@ prtstat(sfsp, maxwidth) headerlen = strlen(header); } else header = getbsize(&headerlen, &blocksize); - (void)printf("%-*.*s %s Used Avail Capacity", + (void)printf("%-*.*s %s Used Avail Capacity", maxwidth, maxwidth, "Filesystem", header); if (iflag) (void)printf(" iused ifree %%iused"); @@ -211,10 +221,10 @@ prtstat(sfsp, maxwidth) (void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname); used = sfsp->f_blocks - sfsp->f_bfree; availblks = sfsp->f_bavail + used; - (void)printf(" %*ld %7ld %7ld", headerlen, - sfsp->f_blocks * sfsp->f_bsize / blocksize, - used * sfsp->f_bsize / blocksize, - sfsp->f_bavail * sfsp->f_bsize / blocksize); + (void)printf(" %*ld %8ld %8ld", headerlen, + fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize), + fsbtoblk(used, sfsp->f_bsize, blocksize), + fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize)); (void)printf(" %5.0f%%", availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0); if (iflag) { @@ -228,7 +238,7 @@ prtstat(sfsp, maxwidth) } /* - * This code constitutes the old df code for extracting + * This code constitutes the pre-system call Berkeley df code for extracting * information from filesystem superblocks. */ #include @@ -241,36 +251,34 @@ union { } sb; #define sblock sb.iu_fs -int fi; +int rfd; void ufs_df(file, maxwidth) char *file; - long maxwidth; + int maxwidth; { struct statfs statfsbuf; - register struct statfs *sfsp; + struct statfs *sfsp; char *mntpt; static int synced; if (synced++ == 0) sync(); - if ((fi = open(file, O_RDONLY)) < 0) { + if ((rfd = open(file, O_RDONLY)) < 0) { warn("%s", file); return; } - if (bread((long)SBOFF, (char *)&sblock, SBSIZE) == 0) { - (void)close(fi); + if (bread((off_t)SBOFF, &sblock, SBSIZE) == 0) { + (void)close(rfd); return; } sfsp = &statfsbuf; sfsp->f_type = 0; sfsp->f_flags = 0; - sfsp->f_iosize = sblock.fs_fsize; -#ifdef notyet + sfsp->f_bsize = sblock.fs_fsize; sfsp->f_iosize = sblock.fs_bsize; -#endif sfsp->f_blocks = sblock.fs_dsize; sfsp->f_bfree = sblock.fs_cstotal.cs_nbfree * sblock.fs_frag + sblock.fs_cstotal.cs_nffree; @@ -284,29 +292,28 @@ ufs_df(file, maxwidth) 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); + memmove(&sfsp->f_mntonname[0], mntpt, MNAMELEN); + memmove(&sfsp->f_mntfromname[0], file, MNAMELEN); strncpy(sfsp->f_fstypename, MOUNT_UFS, MFSNAMELEN); sfsp->f_fstypename[MFSNAMELEN] = '\0'; prtstat(sfsp, maxwidth); - (void) close(fi); + (void)close(rfd); } int bread(off, buf, cnt) - long off; - char *buf; + off_t off; + void *buf; int cnt; { - int n; + int nr; - (void) lseek(fi, off, SEEK_SET); - if ((n=read(fi, buf, cnt)) != cnt) { - /* probably a dismounted disk if errno == EIO */ - if (errno != EIO) { - (void)printf("\nread error off = %ld\n", off); - (void)printf("count = %d: %s\n", n, strerror(errno)); - } + (void)lseek(rfd, off, SEEK_SET); + if ((nr = read(rfd, buf, cnt)) != cnt) { + /* Probably a dismounted disk if errno == EIO. */ + if (errno != EIO) + (void)fprintf(stderr, "\ndf: %qd: %s\n", + off, strerror(nr > 0 ? EIO : errno)); return (0); } return (1); @@ -315,7 +322,6 @@ bread(off, buf, cnt) void usage() { - - fprintf(stderr, "usage: df [-ikln] [file | file_system ...]\n"); + (void)fprintf(stderr, "usage: df [-ikln] [file | file_system ...]\n"); exit(1); }