X-Git-Url: https://git.saurik.com/apple/file_cmds.git/blobdiff_plain/40bf83fed3260cbe00f8bd41f2f5a5f622d625be..a019b610f6010f8f8e8fd3ec0e13d4113b3ffb07:/df/df.c?ds=sidebyside diff --git a/df/df.c b/df/df.c index e7c03cc..7e576d7 100644 --- a/df/df.c +++ b/df/df.c @@ -36,8 +36,9 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static const char copyright[] = +__used static const char copyright[] = "@(#) Copyright (c) 1980, 1990, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ @@ -46,7 +47,7 @@ static const char copyright[] = #if 0 static char sccsid[] = "@(#)df.c 8.9 (Berkeley) 5/8/95"; #else -static const char rcsid[] = +__used static const char rcsid[] = "$FreeBSD: src/bin/df/df.c,v 1.23.2.9 2002/07/01 00:14:24 iedowse Exp $"; #endif #endif /* not lint */ @@ -120,7 +121,7 @@ unit_t unitp [] = { NONE, KILO, MEGA, GIGA, TERA, PETA }; int bread(off_t, void *, int); int checkvfsname(const char *, char **); char *getmntpt(char *); -int longwidth(long long); +int int64width(int64_t); char *makenetvfslist(void); char **makevfslist(const char *); void prthuman(struct statfs *, uint64_t); @@ -144,7 +145,6 @@ main(int argc, char *argv[]) struct stat stbuf; struct statfs statfsbuf, *mntbuf; struct maxwidths maxwidths; - const char *fstype; char *mntpt, **vfslist; long mntsize; int ch, i, rv, tflag = 0, kludge_tflag = 0; @@ -156,10 +156,9 @@ main(int argc, char *argv[]) *not* expect a string after -t (we provide -T in both cases to cover the old use of -t) */ options = "abgHhiklmnPtT:"; + iflag = 1; } - fstype = "hfs"; - vfslist = NULL; while ((ch = getopt(argc, argv, options)) != -1) switch (ch) { @@ -174,6 +173,7 @@ main(int argc, char *argv[]) /* -k overrides -P */ putenv("BLOCKSIZE=512"); } + iflag = 0; } else { putenv("BLOCKSIZE=512"); } @@ -231,7 +231,6 @@ main(int argc, char *argv[]) errx(1, "-l and -%c are mutually exclusive.", ch); } tflag++; - fstype = optarg; vfslist = makevfslist(optarg); break; case '?': @@ -246,9 +245,7 @@ main(int argc, char *argv[]) This makes the Lexmark printer installer happy (PR-3918471) */ if (tflag == 0 && kludge_tflag && *argv && stat(*argv, &stbuf) < 0 && errno == ENOENT) { - tflag = 1; - fstype = *argv++; - vfslist = makevfslist(fstype); + vfslist = makevfslist(*argv++); } mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); @@ -443,28 +440,28 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp) char * avail_str; if (++timesthrough == 1) { - mwp->mntfrom = imax(mwp->mntfrom, strlen("Filesystem")); + mwp->mntfrom = imax(mwp->mntfrom, (int)strlen("Filesystem")); if (hflag) { header = " Size"; - mwp->total = mwp->used = mwp->avail = strlen(header); + mwp->total = mwp->used = mwp->avail = (int)strlen(header); } else { header = getbsize(&headerlen, &blocksize); mwp->total = imax(mwp->total, headerlen); } - mwp->used = imax(mwp->used, strlen("Used")); + mwp->used = imax(mwp->used, (int)strlen("Used")); if (COMPAT_MODE("bin/df", "unix2003") && !hflag) { avail_str = "Available"; } else { avail_str = "Avail"; } - mwp->avail = imax(mwp->avail, strlen(avail_str)); + mwp->avail = imax(mwp->avail, (int)strlen(avail_str)); (void)printf("%-*s %*s %*s %*s Capacity", mwp->mntfrom, "Filesystem", mwp->total, header, mwp->used, "Used", mwp->avail, avail_str); if (iflag) { - mwp->iused = imax(mwp->iused, strlen(" iused")); - mwp->ifree = imax(mwp->ifree, strlen("ifree")); + mwp->iused = imax(mwp->iused, (int)strlen(" iused")); + mwp->ifree = imax(mwp->ifree, (int)strlen("ifree")); (void)printf(" %*s %*s %%iused", mwp->iused - 2, "iused", mwp->ifree, "ifree"); } @@ -503,8 +500,8 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp) if (iflag) { inodes = sfsp->f_files; used = inodes - sfsp->f_ffree; - (void)printf(" %*llu %*lu %4.0f%% ", mwp->iused, used, - mwp->ifree, (unsigned long)sfsp->f_ffree, inodes == 0 ? 100.0 : + (void)printf(" %*llu %*llu %4.0f%% ", mwp->iused, used, + mwp->ifree, sfsp->f_ffree, inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0); } else (void)printf(" "); @@ -524,21 +521,21 @@ update_maxwidths(struct maxwidths *mwp, struct statfs *sfsp) if (blocksize == 0) getbsize(&dummy, &blocksize); - mwp->mntfrom = imax(mwp->mntfrom, strlen(sfsp->f_mntfromname)); - mwp->total = imax(mwp->total, longwidth(fsbtoblk(sfsp->f_blocks, + mwp->mntfrom = imax(mwp->mntfrom, (int)strlen(sfsp->f_mntfromname)); + mwp->total = imax(mwp->total, int64width(fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize, sfsp->f_mntonname))); if (sfsp->f_blocks >= sfsp->f_bfree) - mwp->used = imax(mwp->used, longwidth(fsbtoblk(sfsp->f_blocks - + mwp->used = imax(mwp->used, int64width(fsbtoblk(sfsp->f_blocks - sfsp->f_bfree, sfsp->f_bsize, blocksize, sfsp->f_mntonname))); - mwp->avail = imax(mwp->avail, longwidth(fsbtoblk(sfsp->f_bavail, + mwp->avail = imax(mwp->avail, int64width(fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize, sfsp->f_mntonname))); - mwp->iused = imax(mwp->iused, longwidth((unsigned)(sfsp->f_files - sfsp->f_ffree))); - mwp->ifree = imax(mwp->ifree, longwidth((unsigned)(sfsp->f_ffree))); + mwp->iused = imax(mwp->iused, int64width(sfsp->f_files - sfsp->f_ffree)); + mwp->ifree = imax(mwp->ifree, int64width(sfsp->f_ffree)); } /* Return the width in characters of the specified long. */ int -longwidth(long long val) +int64width(int64_t val) { int len; @@ -582,9 +579,9 @@ makenetvfslist(void) mib[0] = CTL_VFS; mib[1] = VFS_GENERIC; mib[2] = VFS_MAXTYPENUM; miblen=sizeof(maxvfsconf); - if (sysctl(mib, (unsigned int)(sizeof(mib) / sizeof(mib[0])), + if (sysctl(mib, 3, &maxvfsconf, &miblen, NULL, 0)) { - warnx("sysctl failed"); + warn("sysctl failed"); return (NULL); } @@ -611,6 +608,7 @@ makenetvfslist(void) if (!(vfc.vfc_flags & MNT_LOCAL)) { listptr[cnt++] = strdup(vfc.vfc_name); if (listptr[cnt-1] == NULL) { + free(listptr); warnx("malloc failed"); return (NULL); }