vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have noticed lack of -m option in OpenBSD's df(1) long time ago, but I could live without it.. until now. So here's a SIMPLE patch to add it. Now `df -m` reports numbers in megabytes, which can be more readable than sectors/kilobytes and has better "resolution" than -h which usually reports numbers in gigabytes to fit the 4 char limit. Why no -g option? Cause the weather was too sunny today and my disk has only 40 gigs ;-) I've looked how netbsd and freebsd do it - well, both do it differently and more complicated than our df(1), and rewriting this would be against KISS rule. So no -g for now. I think this patch isn't bloat and it will make our lives better. Am I right? This is my first diff against OpenBSD src, so any feedback is appreciated. -- ..: Jakub G3azik, ..: too geek to live, too leet to die ;-) ..: email & jabber: zytek<at>nuxi.pl Index: df.1 ================================================== ================= RCS file: /cvs/src/bin/df/df.1,v retrieving revision 1.38 diff -u -r1.38 df.1 --- df.1 3 Feb 2007 22:58:24 -0000 1.38 +++ df.1 17 Apr 2007 09:58:18 -0000 @@ -38,7 +38,7 @@ .Nd display free disk space .Sh SYNOPSIS .Nm df -.Op Fl hiklnP +.Op Fl hiklmnP .Op Fl t Ar type .Oo .Op Ar file | file_system @@ -83,7 +83,9 @@ By default, all sizes are reported in 512-byte block counts. The .Fl k -option causes the numbers to be reported in kilobyte counts. +option causes the numbers to be reported in kilobyte (1024-byte) counts. +.It Fl m +Same as above, but in megabyte (1048576-byte) counts. .It Fl l Display statistics only about mounted file systems with the .Dv MNT_LOCAL Index: df.c ================================================== ================= RCS file: /cvs/src/bin/df/df.c,v retrieving revision 1.46 diff -u -r1.46 df.c --- df.c 29 Oct 2006 19:20:01 -0000 1.46 +++ df.c 17 Apr 2007 09:58:18 -0000 @@ -81,7 +81,7 @@ extern int ffs_df(int, char *, struct statfs *); extern int e2fs_df(int, char *, struct statfs *); -int hflag, iflag, kflag, lflag, nflag, Pflag; +int hflag, iflag, kflag, lflag, mflag, nflag, Pflag; char **typelist = NULL; int @@ -94,22 +94,26 @@ int width, maxwidth; char *mntpt; - while ((ch = getopt(argc, argv, "hiklnPt:")) != -1) + while ((ch = getopt(argc, argv, "hiklmnPt:")) != -1) switch (ch) { case 'h': hflag = 1; - kflag = 0; + kflag = mflag = 0; break; case 'i': iflag = 1; break; case 'k': kflag = 1; - hflag = 0; + mflag = hflag = 0; break; case 'l': lflag = 1; break; + case 'm': + mflag = 1; + kflag = hflag = 0; + break; case 'n': nflag = 1; break; @@ -371,7 +375,11 @@ (void)printf("%-*.*s %s Used Avail Capacity", maxwidth, maxwidth, "Filesystem", header); } else { - if (kflag) { + if (mflag) { + blocksize = 1048576; + header = "1M-blocks"; + headerlen = strlen(header); + } else if (kflag) { blocksize = 1024; header = "1K-blocks"; headerlen = strlen(header); @@ -403,7 +411,10 @@ long used, avail; double percentused; - if (kflag) { + if (mflag) { + blocksize = 1048576; + blockstr = "1048576-blocks"; + } else if (kflag) { blocksize = 1024; blockstr = "1024-blocks"; } else { @@ -474,7 +485,7 @@ usage(void) { (void)fprintf(stderr, - "usage: %s [-hiklnP] [-t type] [[file | file_system] ...]\n", + "usage: %s [-hiklnmP] [-t type] [[file | file_system] ...]\n", __progname); exit(1); } |