Re: Human readable df
On Mon, 29 Nov 1999, Chris Piazza wrote: For what it's worth, I'd ported this a few months back (file dated Aug 28), but forgot about it :-). Here's the patch updated for -current, anyway. If a "me too" will help get this committed, here 'tis. I can do the math in my head, but I'd rather save the neurons for something more useful. I wouldn't even mind seeing this as the default, but someone would probably gripe... Doug -- "Welcome to the desert of the real." - Laurence Fishburne as Morpheus, "The Matrix" To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
On Mon, Nov 29, 1999 at 11:57:48PM -0700, Warner Losh wrote: Note, this uses the "traditional computer science SI extention" units. Where M == 1 20, G == 1 30, etc. Disk drive manufacturers use the real SI units where M == 10 ^ 6, G == 10 ^ 9, Some implimentations of ``df -h'' use "-h" for base 2, and "-H" for SI units. I believe Mike Haro's additions supports both. Same for ``du'' of course. -- -- David([EMAIL PROTECTED]) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
On Mon, Nov 29, 1999 at 10:37:08PM -0800, Kris Kennaway wrote: Here's a patch to add -h flag to df to produce human readable output. This makes it easier to read if the disk is big. You should submit this as a PR so it doesn't fall through the cracks (although it looks like Chris might take care of it, he seems to like adding options to commands :-) Mike Haro has this ready to commit in -CURRENT for quite some time. I've been pushing him to get it in 4.0-R. Please send any patches etc, to [EMAIL PROTECTED] so he can merge all the good ideas into one commit. -- David([EMAIL PROTECTED]) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
Stephen McKay wrote in list.freebsd-hackers: On Tuesday, 30th November 1999, Warner Losh wrote: FilesystemSize UsedAvail Capacity Mounted on /dev/da0s1a 62.0M 31.0M 26.1M54% / /dev/da0s1e 192M 167M 9.22M95% /usr /dev/da0s1d 61.4M 11.3M 45.2M20% /var /dev/da0s1f 288M 247M 18.4M93% /usr/local /dev/da0s1g 2.17G 1.88G 122M94% /home procfs 4.00K 4.00K 0B 100% /proc /dev/sd1a 990M 376M 534M41% /jaz /dev/da2s4c 1.94G 1.72G 68.0M96% /hawk /dev/da3s4a 3.93G 1.95G 1.67G54% /u Add a 'df -h' if you like, but to me this looks like an unreadable jumble of letters and digits. FWIW, I agree whole-heartedly. I think -k output is much more readable than the above, because you have an immediate "visual" overview of the sizes. What I'd like to have would be an option that inserts thousands separators ("," or whatever your locale settings say) into the default display: Filesystem1K-blocksUsed Avail Capacity Mounted on /dev/da0s1a 105,893 5,117 97,600 5%/foo /dev/da0s1e 139,172 261138,911 1%/bar /dev/da0s1d 17,641,178 15,931,150 1,710,028 91%/bar/baz /dev/da0s1f 262,133 167,310 86,960 66%/mumble /dev/da0s1g 17,641,178 16,462,303 1,178,875 94%/laber /dev/da0s1h 8,782,097 4,605,191 4,176,906 53%/fasel mfs:33 297,663 2297,661 0%/tmp procfs4 4 0100%/proc This would be esay to implement and improves readability a lot, IMO. I'd send-pr a patch, if there's a chance that it will be comitted (I'd suggest "-s" for "separators"). Or does this start to get feeping creaturism...? Regards Oliver -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:[EMAIL PROTECTED]) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
In message 19991129230436.A6501@badmofo [EMAIL PROTECTED] writes: : [badmofo@/home/matt] df -h : FilesystemSize UsedAvail Capacity Mounted on : /dev/wd0s1a 722M20M 644M 3% / : /dev/wd0s2h 9.9G 4.4G 4.8G48% /usr : procfs4.0K 4.0K 0B 100% /proc This also looks a lot like what the SVR4 dfspace program produced. dfspace was simply an awk script that prettied up the output of df. Not that I'm against the patch - would such prettying up better be done outside of df itself (to follow the UNIX tools-built-on-tools philosophy...) maybe? maybe not? Just a thought - Dave Rivers - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
Stephen McKay [EMAIL PROTECTED] write On Tuesday, 30th November 1999, Warner Losh wrote: FilesystemSize UsedAvail Capacity Mounted on /dev/da0s1a 62.0M 31.0M 26.1M54% / /dev/da0s1e 192M 167M 9.22M95% /usr /dev/da0s1d 61.4M 11.3M 45.2M20% /var /dev/da0s1f 288M 247M 18.4M93% /usr/local /dev/da0s1g 2.17G 1.88G 122M94% /home procfs 4.00K 4.00K 0B 100% /proc /dev/sd1a 990M 376M 534M41% /jaz /dev/da2s4c 1.94G 1.72G 68.0M96% /hawk /dev/da3s4a 3.93G 1.95G 1.67G54% /u Add a 'df -h' if you like, but to me this looks like an unreadable jumble of letters and digits. Which adds to my logic of not putting this in df itself, there will always be someone (for many valid reasons) that wants something else. I'd suggest going the dfspace route - then users have an example of something that parses the df output they can choose for themselves. I just checked on the Solaris box here, /etc/dfspace isn't there... I know it was there on my old ISC 3.2 box; and I recall making it work on FreeBSD. But, it was copyright ATT, so I simply can't post it. The way it works is to (honoring the block size correctly) skip the first few lines of df (the normal heading) and then grab all the following `table' if you will. With that information in hand, it can format things anyway it needed. - Dave Rivers - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
On Tue, 30 Nov 1999, Warner Losh wrote: FilesystemSize UsedAvail Capacity Mounted on /dev/da0s1a 62.0M 31.0M 26.1M54% / Previously the three size column were right-aligned with the headers, and the percentiage was centered under 'Capacity', I hope we can keep that consistant. Thanks, -- - bill fumerola - [EMAIL PROTECTED] - BF1560 - computer horizons corp - - ph:(800) 252-2421 - [EMAIL PROTECTED] - [EMAIL PROTECTED] - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
Oliver Fromme wrote: What I'd like to have would be an option that inserts thousands separators ("," or whatever your locale settings say) into the default display: Filesystem1K-blocksUsed Avail Capacity Mounted on /dev/da0s1a 105,893 5,117 97,600 5%/foo /dev/da0s1e 139,172 261138,911 1%/bar I'd send-pr a patch, if there's a chance that it will be comitted (I'd suggest "-s" for "separators"). Or does this start to get feeping creaturism...? Don't forget to correctly i18n the separators. Talk about feeping creaturism. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC [EMAIL PROTECTED] http://softweyr.com/ To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
In the last episode (Nov 30), Stephen McKay said: If anything, I want a 'df -m' option that does this: Filesystem 1M-blocks Used Avail Capacity Mounted on /dev/da0s1a 62 31 2654% / /dev/da0s1e192167 995% /usr /dev/da0s1d 61 11 4520% /var /dev/da0s1f288247 1893% /usr/local /dev/da0s1g 2170 188012294% /home procfs 0 0 0 100% /proc /dev/sd1a 99037653441% /jaz /dev/da2s4c 1940 1720 6896% /hawk /dev/da3s4a 3930 1950 167054% /u Just set BLOCKSIZE to your preferred unit. $ BLOCKSIZE=1M df Filesystem 1M-blocks UsedAvail Capacity Mounted on /dev/da2s2a 7893 759 650210%/ /dev/da0s1e 5116140922 614687%/io3 /dev/da1s1e 4399732111 836679%/io4 procfs 000 100%/proc ( / is 7.8 gig, /io3 is 51 gig ) -- Dan Nelson [EMAIL PROTECTED] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
On Tuesday, 30th November 1999, Dan Nelson wrote: In the last episode (Nov 30), Stephen McKay said: If anything, I want a 'df -m' option that does this: [snip] Just set BLOCKSIZE to your preferred unit. $ BLOCKSIZE=1M df Filesystem 1M-blocks UsedAvail Capacity Mounted on /dev/da2s2a 7893 759 650210%/ /dev/da0s1e 5116140922 614687%/io3 /dev/da1s1e 4399732111 836679%/io4 procfs 000 100%/proc I knew this; I just assumed it was well known. In the same way you could use "BLOCKSIZE=1K df" instead of "df -k". But you don't because there's a convenient command option. Similarly, I'd rather use "df -m". I think it's a low impact solution that will scale to "df -g" in the future. Personally, I think "df -h" as proposed is not useful, but I've given up arguing against additional options that other people like. And to Thomas: I've used dfspace before on ISC Unix, but never really liked it. I prefer df to do what I want. Am I greedy? :-) Stephen. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
Stephen McKay [EMAIL PROTECTED] wrote: And to Thomas: I've used dfspace before on ISC Unix, but never really liked it. I prefer df to do what I want. Am I greedy? :-) Not at all - it just seems to me the question should be asked, that's all. Since not a single person agreed - it seems it has been answered as well :-) - Dave R. - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
On Mon, Nov 29, 1999 at 11:04:36PM -0500, [EMAIL PROTECTED] wrote: Not sure if -hackers is the place for this, but here goes. Here's a patch to add -h flag to df to produce human readable output. This makes it easier to read if the disk is big. Example: [badmofo@/home/matt] df -h FilesystemSize UsedAvail Capacity Mounted on /dev/wd0s1a 722M20M 644M 3% / /dev/wd0s2h 9.9G 4.4G 4.8G48% /usr procfs4.0K 4.0K 0B 100% /proc Code merged from OpenBSD and added to FreeBSD-STABLE. [patch snipped] For what it's worth, I'd ported this a few months back (file dated Aug 28), but forgot about it :-). Here's the patch updated for -current, anyway. Index: df.1 === RCS file: /home/ncvs/src/bin/df/df.1,v retrieving revision 1.17 diff -u -r1.17 df.1 --- df.11999/11/01 04:57:42 1.17 +++ df.11999/11/30 05:38:47 @@ -40,7 +40,7 @@ .Nd display free disk space .Sh SYNOPSIS .Nm df -.Op Fl aikn +.Op Fl ahikmn .Op Fl t Ar type .Op Ar file | Ar filesystem ... .Sh DESCRIPTION @@ -62,6 +62,10 @@ .It Fl a Show all mount points, including those that were mounted with the MNT_IGNORE flag. +.It Fl h +"Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, +Gigabyte, Terabyte, Petabyte, Exabyte in order to reduce the number of +digits to four or less. .It Fl i Include statistics on the number of free inodes. .It Fl k Index: df.c === RCS file: /home/ncvs/src/bin/df/df.c,v retrieving revision 1.22 diff -u -r1.22 df.c --- df.c1999/11/01 04:57:43 1.22 +++ df.c1999/11/30 05:38:47 @@ -59,21 +59,27 @@ #include err.h #include errno.h #include fcntl.h +#include math.h #include stdio.h #include stdlib.h #include string.h #include unistd.h +typedef enum { NONE = 0, KILO, MEGA, GIGA, TERA, PETA /* , EXA */ } unit_t; + int checkvfsname __P((const char *, char **)); char **makevfslist __P((char *)); long regetmntinfo __P((struct statfs **, long, char **)); int bread __P((off_t, void *, int)); char*getmntpt __P((char *)); +void prthuman __P((struct statfs *, long)); +void prthumanval __P((double)); void prtstat __P((struct statfs *, int)); int ufs_df __P((char *, int)); +unit_t unit_adjust __P((double *)); void usage __P((void)); -intaflag = 0, iflag, nflag; +intaflag = 0, hflag, iflag, nflag; struct ufs_args mdev; int @@ -88,11 +94,14 @@ char *mntpt, *mntpath, **vfslist; vfslist = NULL; - while ((ch = getopt(argc, argv, "aiknt:")) != -1) + while ((ch = getopt(argc, argv, "ahiknt:")) != -1) switch (ch) { case 'a': aflag = 1; break; + case 'h': + hflag = 1; + break; case 'i': iflag = 1; break; @@ -249,6 +258,68 @@ } /* + * Output in "human-readable" format. Uses 3 digits max and puts + * unit suffixes at the end. Makes output compact and easy to read, + * especially on huge disks. + * + */ + +unit_t +unit_adjust(val) + double *val; +{ + double abval; + unit_t unit; + + abval = fabs(*val); + if (abval 1024) + unit = NONE; + else if (abval 1048576ULL) { + unit = KILO; + *val /= 1024; + } else if (abval 1073741824ULL) { + unit = MEGA; + *val /= 1048576; + } else if (abval 1099511627776ULL) { + unit = GIGA; + *val /= 1073741824ULL; + } else if (abval 1125899906842624ULL) { + unit = TERA; + *val /= 1099511627776ULL; + } else if (abval 1152921504606846976ULL) { + unit = PETA; + *val /= 1125899906842624ULL; + } + return (unit); +} + +void +prthuman(sfsp, used) + struct statfs *sfsp; + long used; +{ + prthumanval((double)(sfsp-f_blocks) * (double)(sfsp-f_bsize)); + prthumanval((double)(used) * (double)(sfsp-f_bsize)); + prthumanval((double)(sfsp-f_bavail) * (double)(sfsp-f_bsize)); +} + +void +prthumanval(bytes) + double bytes; +{ + unit_t unit; + + unit = unit_adjust(bytes); + + if (bytes == 0) + (void)printf(" 0B"); + else if (bytes 10) + (void)printf(" %5.0f%c", bytes, "BKMGTPE"[unit]); + else + (void)printf(" %5.1f%c", bytes, "BKMGTPE"[unit]); +} + +/* * Convert statfs returned filesystem size into BLOCKSIZE units. * Attempts to avoid overflow for large filesystems. */ @@ -272,9 +343,16 @@ if (maxwidth 11) maxwidth = 11; if (++timesthrough == 1) { - header = getbsize(headerlen,
Re: Human readable df
On Mon, Nov 29, 1999 at 09:39:53PM -0800, Chris Piazza wrote: Oops, plus the usage change which I forgot (of course). @@ -382,6 +463,6 @@ usage() { (void)fprintf(stderr, - "usage: df [-aikn] [-t type] [file | filesystem ...]\n"); + "usage: df [-ahikn] [-t type] [file | filesystem ...]\n"); exit(1); } -Chris -- [EMAIL PROTECTED] [EMAIL PROTECTED] Abbotsford, BC, Canada To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
On Mon, 29 Nov 1999 [EMAIL PROTECTED] wrote: Not sure if -hackers is the place for this, but here goes. Here's a patch to add -h flag to df to produce human readable output. This makes it easier to read if the disk is big. You should submit this as a PR so it doesn't fall through the cracks (although it looks like Chris might take care of it, he seems to like adding options to commands :-) Kris To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
In message [EMAIL PROTECTED] Warner Losh writes: : It also appears that this patch ignores blocksize, but maybe that's : something that I've missed somehow... Never mind this comment. It was my mistake. Warner To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message
Re: Human readable df
Here's a slightly better patch. It tries harder to fill up the 5 digit field with as many sig figs as possible (always up to 3). It uses better constants for things than the magic numbers of the first patch. I've not tried to patch the man page yet. Also patched where the gross use of "BKMGTP"[unit], the disorder in the prototypes. I also fixed it so that disk larger then 1000Pbytes are displayed in petabytes rather than bytes like the old code. I think this looks a little better than the orignial patch singe it now gives the same resolution of data for each file system. I experimented with setting the throttle from 1000.00 the previous unit to 2000.00 the previous unit to give it a more multi-meter look and to give higher resolution around 1 which would give you a more linear amount of data (taken as the log of the rounding error), but that didn't look as good, so I left it on the cutting room floor. I also experimented with a format that looked like /dev/da0s1e 192.M 167.M 9.22M95% /usr but that too didn't look good to my eye, even though it was more pedantically correct from a sigfig point of view (since 200M means there is one sig fig, while 200.M means two, at least in the sig fig system I learned in high school). Here's the output FilesystemSize UsedAvail Capacity Mounted on /dev/da0s1a 62.0M 31.0M 26.1M54% / /dev/da0s1e 192M 167M 9.22M95% /usr /dev/da0s1d 61.4M 11.3M 45.2M20% /var /dev/da0s1f 288M 247M 18.4M93% /usr/local /dev/da0s1g 2.17G 1.88G 122M94% /home procfs 4.00K 4.00K 0B 100% /proc /dev/sd1a 990M 376M 534M41% /jaz /dev/da2s4c 1.94G 1.72G 68.0M96% /hawk /dev/da3s4a 3.93G 1.95G 1.67G54% /u Warner P.S. I thought of doing a -H as well that used real SI units rather than the traditional CS si-ish units, but thought better of it. I also didn't use the new ki, Mi, et al either since that would just make the display look wrong to my eye (I was also unsure of their exact spelling :-). Index: df.c === RCS file: /home/imp/FreeBSD/CVS/src/bin/df/df.c,v retrieving revision 1.22 diff -u -r1.22 df.c --- df.c1999/11/01 04:57:43 1.22 +++ df.c1999/11/30 07:19:07 @@ -59,21 +59,28 @@ #include err.h #include errno.h #include fcntl.h +#include math.h #include stdio.h #include stdlib.h #include string.h #include unistd.h -int checkvfsname __P((const char *, char **)); -char **makevfslist __P((char *)); -long regetmntinfo __P((struct statfs **, long, char **)); +typedef enum { NONE = 0, KILO, MEGA, GIGA, TERA, PETA /* , EXA */ } unit_t; +const char *unit_string = "BKMGTP"; + int bread __P((off_t, void *, int)); +int checkvfsname __P((const char *, char **)); char*getmntpt __P((char *)); +char **makevfslist __P((char *)); +void prthuman __P((struct statfs *, long)); +void prthumanval __P((double)); void prtstat __P((struct statfs *, int)); +long regetmntinfo __P((struct statfs **, long, char **)); int ufs_df __P((char *, int)); +unit_t unit_adjust __P((double *)); void usage __P((void)); -intaflag = 0, iflag, nflag; +intaflag = 0, iflag, nflag, hflag; struct ufs_args mdev; int @@ -88,11 +95,14 @@ char *mntpt, *mntpath, **vfslist; vfslist = NULL; - while ((ch = getopt(argc, argv, "aiknt:")) != -1) + while ((ch = getopt(argc, argv, "ahiknt:")) != -1) switch (ch) { case 'a': aflag = 1; break; + case 'h': + hflag = 1; + break; case 'i': iflag = 1; break; @@ -272,20 +282,26 @@ if (maxwidth 11) maxwidth = 11; if (++timesthrough == 1) { - header = getbsize(headerlen, blocksize); - (void)printf("%-*.*s %s UsedAvail Capacity", + if(hflag) + header = " Size"; + else + header = getbsize(headerlen, blocksize); + (void)printf("%-*.*s %s UsedAvail Capacity", maxwidth, maxwidth, "Filesystem", header); if (iflag) (void)printf(" iused ifree %%iused"); - (void)printf(" Mounted on\n"); + (void)printf(" Mounted on\n"); } (void)printf("%-*.*s", maxwidth, maxwidth, sfsp-f_mntfromname); used = sfsp-f_blocks - sfsp-f_bfree; availblks = sfsp-f_bavail + used; - (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)); + if(hflag) +