dfc-2.5.0/0000755000175000001440000000000011736667055011322 5ustar robinusersdfc-2.5.0/src/0000755000175000001440000000000011736666772012116 5ustar robinusersdfc-2.5.0/src/dfc.c0000644000175000001440000004110111736666712013005 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * dfc.c * * (C) 2012 - Hahling Robin * * Displays free disk space in an elegant manner. */ /* What works for FreeBSD works for MacOS */ #ifndef __linux__ #define BSD #endif #define _BSD_SOURCE #ifdef __linux #define _POSIX_C_SOURCE 2 #define _XOPEN_SOURCE 500 #endif #define STRMAXLEN 24 #include #include #include #include #include #ifdef __linux__ #include #endif #include #include #include #include #ifdef BSD #include #include #endif #include "dfc.h" int main(int argc, char *argv[]) { struct list queue; int ch; unsigned int width; char *fsfilter = NULL; char *subopts; char *value; char *unit_opts[] = { #define H 0 "h", #define B 1 "b", #define K 2 "k", #define M 3 "m", #define G 4 "g", #define T 5 "t", #define P 6 "p", #define E 7 "e", #define Z 8 "z", #define Y 9 "y", NULL }; char *color_opts[] = { #define CALWAYS 0 "always", #define CNEVER 1 "never", #define CAUTO 2 "auto", NULL }; /* default value for those globals */ cflag = 1; /* color enabled by default */ /* * Now use -u option for choosing the size (b, k, m, etc.) * When using the flag, should specifie the unit used (h is default). * Have a look at unit_opts for the possible values. */ unitflag = 'h'; while ((ch = getopt(argc, argv, "abc:fhimnost:Tu:vwW")) != -1) { switch (ch) { case 'a': aflag = 1; break; case 'b': bflag = 1; break; case 'c': subopts = optarg; while (*subopts) { switch (getsubopt(&subopts, color_opts, &value)) { case CALWAYS: cflag = 2; break; case CNEVER: cflag = 0; break; case CAUTO: cflag = 1; break; case -1: (void)fprintf(stderr, "-c: illegal sub option %s\n", subopts); return EXIT_FAILURE; /* NOTREACHED */ } } break; case 'f': fflag = 1; break; case 'h': hflag = 1; break; case 'i': iflag = 1; break; case 'm': mflag = 1; break; case 'n': nflag = 1; break; case 'o': oflag = 1; break; case 's': sflag = 1; break; case 't': tflag = 1; fsfilter = strdup(optarg); break; case 'T': Tflag = 1; break; case 'u': uflag = 1; subopts = optarg; while (*subopts) { switch (getsubopt(&subopts, unit_opts, &value)) { case H: unitflag = 'h'; break; case B: unitflag = 'b'; break; case K: unitflag = 'k'; break; case M: unitflag = 'm'; break; case G: unitflag = 'g'; break; case T: unitflag = 't'; break; case P: unitflag = 'p'; break; case E: unitflag = 'e'; break; case Z: unitflag = 'z'; break; case Y: unitflag = 'y'; break; case -1: (void)fprintf(stderr, "-u: illegal sub option %s\n", subopts); return EXIT_FAILURE; /* NOTREACHED */ } } break; case 'v': vflag = 1; break; case 'w': wflag = 1; break; case 'W': Wflag = 1; break; case '?': default: usage(EXIT_FAILURE); /* NOTREACHED */ } } if (hflag) usage(EXIT_SUCCESS); /* NOTREACHED */ if (vflag) { (void)printf("dfc %s\n", VERSION); return EXIT_SUCCESS; /* NOTREACHED */ } width = getttywidth(); /* if fd is not a terminal and color mode is not "always", disable color */ if (width == 0 && cflag != 2) cflag = 0; /* cannot display all information if tty is too narrow */ if (!fflag) { if (width < 151) { if (oflag) { Tflag = 0; bflag = 1; } } if (width < 125) oflag = 0; if (width < 81) { bflag = 1; Tflag = 0; } } /* initializes the queue */ init_queue(&queue); /* fetch information about the currently mounted filesystems */ fetch_info(&queue); /* actually displays the info we have got */ disp(&queue, fsfilter); return EXIT_SUCCESS; /* NOTREACHED */ } /* * Display usage. * param: status --> status code (EXIT_SUCCESS, EXIT_FAILURE, ...) */ void usage(int status) { if (status != 0) (void)fputs("Try dfc -h for more information\n", stderr); else { /* 2 fputs because string length limit is 509 */ (void)fputs("Usage: dfc [OPTIONS(S)] [-c WHEN] [-u UNIT]" "[-t FILESYSTEM]\n" "Available options:\n" "\t-a\tprint all fs from mtab\n" "\t-b\tdo not show the graph bar\n" "\t-c\tchoose color mode. Read the manpage\n" "\t\tfor details\n", stdout); (void)fputs( "\t-f\tdisable auto-adjust mode (force display)\n" "\t-h\tprint this message\n" "\t-i\tinfo about inodes\n" "\t-m\tuse metric (SI unit)\n" "\t-n\tdo not print header\n" "\t-o\tshow mount flags\n" "\t-s\tsum the total usage\n" "\t-t\tfilter filesystems. Read the manpage\n" "\t\tfor details\n" "\t-T\tshow filesystem type\n" "\t-u\tchoose the unit in which\n" "\t\tto show the values. Read the manpage\n" "\t\tfor details\n" "\t-v\tprint program version\n" "\t-w\tuse a wider bar\n" "\t-W\twide filename (un truncate)\n", stdout); } exit(status); /* NOTREACHED */ } /* * fetch information from getmntent and statvfs and store it into the queue * @lst: queue in which to store information */ void fetch_info(struct list *lst) { FILE *mtab; struct fsmntinfo *fmi; #ifdef __linux__ struct mntent *entbuf; struct statvfs vfsbuf; #else int nummnt; struct statfs *entbuf; struct statfs vfsbuf, **fs; #endif /* init fsmntinfo */ if ((fmi = malloc(sizeof(struct fsmntinfo))) == NULL) { (void)fputs("Error while allocating memory to fmi", stderr); exit(EXIT_FAILURE); /* NOTREACHED */ } *fmi = fmi_init(); #ifdef __linux__ /* open mtab file */ if ((mtab = fopen("/etc/mtab", "r")) == NULL) { perror("Error while opening mtab file "); exit(EXIT_FAILURE); /* NOTREACHED */ } /* loop to get infos from all the mounted fs */ while ((entbuf = getmntent(mtab)) != NULL) { /* get infos from statvfs */ if (statvfs(entbuf->mnt_dir, &vfsbuf) == -1) { /* permission denied for this one -> show warning */ if (errno == EACCES) { (void)fprintf(stderr, "WARNING: %s was skipped " "because it cannot be stated", entbuf->mnt_dir); perror(" "); } else { (void)fprintf(stderr, "Error while stating %s", entbuf->mnt_dir); perror(" "); exit(EXIT_FAILURE); /* NOTREACHED */ } } else { #else if ((nummnt = getmntinfo(&entbuf, MNT_WAIT)) <= 0) err(EXIT_FAILURE, "Error while getting the list of mountpoints"); /* NOTREACHED */ for (fs = &entbuf; nummnt--; (*fs)++) { vfsbuf = **fs; #endif #ifdef __linux__ /* infos from getmntent */ if (Wflag) { /* Wflag to avoid name truncation */ if ((fmi->fsname = strdup(entbuf->mnt_fsname)) == NULL) { fmi->fsname = "unknown"; } if ((fmi->dir = strdup(entbuf->mnt_dir)) == NULL) { fmi->dir = "unknown"; } } else { if ((fmi->fsname = strdup(shortenstr( entbuf->mnt_fsname, STRMAXLEN))) == NULL) { fmi->fsname = "unknown"; } if ((fmi->dir = strdup(shortenstr(entbuf->mnt_dir, STRMAXLEN))) == NULL) { fmi->dir = "unknown"; } } if ((fmi->type = strdup(shortenstr(entbuf->mnt_type, 12))) == NULL) { fmi->type = "unknown"; } if ((fmi->opts = strdup(entbuf->mnt_opts)) == NULL) { fmi->opts = "none"; } #else if (Wflag) { /* Wflag to avoid name truncation */ if ((fmi->fsname = strdup( entbuf->f_mntfromname)) == NULL) { fmi->fsname = "unknown"; } if ((fmi->dir = strdup(( entbuf->f_mntonname ))) == NULL) { fmi->dir = "unknown"; } } else { if ((fmi->fsname = strdup(shortenstr( entbuf->f_mntfromname, STRMAXLEN))) == NULL) { fmi->fsname = "unknown"; } if ((fmi->dir = strdup(shortenstr( entbuf->f_mntonname, STRMAXLEN))) == NULL) { fmi->dir = "unknown"; } } if ((fmi->type = strdup(shortenstr( entbuf->f_fstypename, 12))) == NULL) { fmi->type = "unknown"; } #ifdef __MACH__ /* TODO: implement feature for MacOS */ fmi->opts = "sorry, not implemented yet on MacOS..."; #else if ((fmi->opts = statfs_flags_to_str(entbuf)) == NULL) { fmi->opts = "none"; } #endif /* __MACH__ */ #endif /* infos from statvfs */ fmi->bsize = vfsbuf.f_bsize; #ifdef __linux__ fmi->frsize = vfsbuf.f_frsize; #else /* *BSD do not have frsize */ fmi->frsize = 0; #endif fmi->blocks = vfsbuf.f_blocks; fmi->bfree = vfsbuf.f_bfree; fmi->bavail = vfsbuf.f_bavail; fmi->files = vfsbuf.f_files; fmi->ffree = vfsbuf.f_ffree; #ifdef __linux__ fmi->favail = vfsbuf.f_favail; #else /* *BSD do not have favail */ fmi->favail = 0; #endif /* pointer to the next element */ fmi->next = NULL; /* enqueue the element into the queue */ enqueue(lst, *fmi); /* adjust longest for the queue */ if ((!aflag && fmi->blocks > 0) || aflag) { lst->fsmaxlen = imax((int)strlen(fmi->fsname), lst->fsmaxlen); lst->dirmaxlen = imax((int)strlen(fmi->dir), lst->dirmaxlen); lst->typemaxlen = imax((int)strlen(fmi->type), lst->typemaxlen); } } #ifdef __linux__ } /* we need to close the mtab file now */ if (fclose(mtab) == EOF) perror("Could not close mtab file "); #endif } /* * Converts the argument to the correct unit * TODO: pretty crapy function... should do it in a smart way! * Plus there probably is some roundings errors... * Need to clean this crap ASAP * @n: number to convert */ double cvrt(double n) { switch (unitflag) { case 'b': return n; /* NOTREACHED */ case 'e': if (mflag) /* 1000^6 */ return n / 1000000000000000000.0; /* NOTREACHED */ else /* 1024^6 */ return n / 1152921504606846976.0; /* NOTREACHED */ case 'g': if (mflag) /* 1000^3 */ return n / 1000000000.0; /* NOTREACHED */ else /* 1024^3 */ return n / 1073741824.0; /* NOTREACHED */ case 'k': if (mflag) return n / 1000.0; /* NOTREACHED */ else return n / 1024.0; /* NOTREACHED */ case 'm': if (mflag) /* 1000^2 */ return n / 1000000.0; /* NOTREACHED */ else /* 1024^2 */ return n / 1048576.0; /* NOTREACHED */ case 'p': if (mflag) /* 1000^5 */ return n / 1000000000000000.0; /* NOTREACHED */ else /* 1024^5 */ return n / 1125899906842624.0; /* NOTREACHED */ case 't': if (mflag) /* 1000^4 */ return n / 1000000000000.0; /* NOTREACHED */ else /* 1024^4 */ return n / 1099511627776.0; /* NOTREACHED */ case 'y': if (mflag) /* 1000^8 */ return n / 1000000000000000000000000.0; /* NOTREACHED */ else /* 1024^8 */ return n / 1208925819614629174706176.0; /* NOTREACHED */ case 'z': if (mflag) /* 1000^7 */ return n / 1000000000000000000000.0; /* NOTREACHED */ else /* 1024^7 */ return n / 1180591620717411303424.0; /* NOTREACHED */ } /* should not be able to reach this point but just in case... */ return n; /* NOTREACHED */ } /* * convert to human readable format and print the result * @n: number to convert and print * @perct: percentage (useful when using colors) */ void humanize(double n, double perct) { int i = 0; double divider = 1024.0; /* when using SI unit... */ if (mflag) divider = 1000.0; while ((n >= 1000) && (i < 8)) { n /= divider; i++; } change_color(perct); if ( i == 0) (void)printf("%9.f", n); else (void)printf("%9.1f", n); reset_color(); switch (i) { case 0: /* bytes */ (void)printf("B"); break; case 1: /* Kio or Ko */ (void)printf("K"); break; case 2: /* Mio or Mo */ (void)printf("M"); break; case 3: /* Gio or Go*/ (void)printf("G"); break; case 4: /* Tio or To*/ (void)printf("T"); break; case 5: /* Pio or Po*/ (void)printf("P"); break; case 6: /* Eio or Eo*/ (void)printf("E"); break; case 7: /* Zio or Zo*/ (void)printf("Z"); break; case 8: /* Yio or Yo*/ (void)printf("Y"); break; } } /* does not work on Mac OS */ #ifdef __FreeBSD__ /* * Turn the f_flags member of the given struct statfs to a human-readable string * of the form "opt1,opt2..." * Returns NULL if an error occurred. * @s: struct statfs * to parse. */ char * statfs_flags_to_str(struct statfs *s) { uint64_t flags = s->f_flags; size_t bufsize = 128; char *buffer = malloc(bufsize); if (!buffer) { (void)fprintf(stderr, "Could not retrieve mount flags for %s\n", s->f_mntonname); return NULL; /* NOTREACHED */ } buffer[0] = '\0'; /* Comparing flags to all possible flags, in the same order as mount -p */ if (flags & MNT_RDONLY) { if (strlcat(buffer, "ro", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ } else { if (strlcat(buffer, "rw", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ } if (flags & MNT_SYNCHRONOUS) if (strlcat(buffer, ",sync", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NOEXEC) if (strlcat(buffer, ",noexec", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NOSUID) if (strlcat(buffer, ",nosuid", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_UNION) if (strlcat(buffer, ",union", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_ASYNC) if (strlcat(buffer, ",async", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NOATIME) if (strlcat(buffer, ",noatime", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NOCLUSTERR) if (strlcat(buffer, ",noclusterr", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NOCLUSTERW) if (strlcat(buffer, ",noclusterw", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NOSYMFOLLOW) if (strlcat(buffer, ",nosymfollow", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_SUIDDIR) if (strlcat(buffer, ",suiddir", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_MULTILABEL) if (strlcat(buffer, ",multilabel", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_ACLS) if (strlcat(buffer, ",acls", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ if (flags & MNT_NFS4ACLS) if (strlcat(buffer, ",nfsv4acls", bufsize) >= bufsize) goto truncated; /* NOTREACHED */ return buffer; /* NOTREACHED */ truncated: (void)fprintf(stderr, "Truncating mount options for %s\n", s->f_mntonname); return buffer; /* NOTREACHED */ } #endif /* __FreeBSD__ */ dfc-2.5.0/src/util.h0000644000175000001440000000336411736666712013244 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef H_UTIL #define H_UTIL /* * util.h * * Util functions */ #include "extern.h" /* function declaration */ int imax(int a, int b); char* shortenstr(char *str, int len); unsigned int getttywidth(void); #endif /* ndef UTIL_H */ dfc-2.5.0/src/list.h0000644000175000001440000000576411736666712013250 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef H_LIST #define H_LIST /* * list.h * * list structure */ /* * structure needed to store informations about mounted fs * It should contain brut datas. * Later on, we would need to compute those infos: * unsigned long bused; used blocks * double prct_used; usage of fs in percent * double prct_free; free space of fs in percent */ struct fsmntinfo { /* infos to get from getmntent(3) */ char *fsname; /* name of mounted file system */ char *dir; /* file system path prefix */ char *type; /* mount type */ char *opts; /* mount options (see mntent.h) */ /* infos to get from statvfs(3) */ unsigned long bsize; /* file system block size */ unsigned long frsize; /* fragment size */ unsigned long blocks; /* size of fs in frsize unit */ unsigned long bfree; /* # of free blocks */ unsigned long bavail; /* # of available blocks */ unsigned long files; /* # of inodes */ unsigned long ffree; /* # of free inodes */ unsigned long favail; /* # of available inodes */ /* pointer to the next element of the list */ struct fsmntinfo *next; }; /* list structure to store fsmntinfo */ struct list { struct fsmntinfo *head; struct fsmntinfo *tail; int fsmaxlen; /* should be the size of the longest fsname */ int dirmaxlen; /* same for dir */ int typemaxlen; /* same for type */ }; /* function declaration */ void init_queue(struct list *lst); int is_empty(struct list lst); int enqueue(struct list *lst, struct fsmntinfo elt); struct fsmntinfo fmi_init(void); #endif /* ndef LIST_H */ dfc-2.5.0/src/disp.h0000644000175000001440000000404311736666712013221 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef H_DISP #define H_DISP /* * disp.h * * Header for disp.c */ #include "extern.h" #include "list.h" #include "util.h" #include "dfc.h" /* function declaration */ void disp(struct list *lst, char *fsfilter); void disp_header(struct list *lst); void disp_sum(struct list *lst, double stot, double utot, double ftot, double ifitot, double ifatot); void disp_bar(double perct); void disp_at(double n, double perct); void disp_perct(double perct); void change_color(double perct); void reset_color(void); #endif /* ndef DISP_H */ dfc-2.5.0/src/disp.c0000644000175000001440000002231111736666712013212 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * disp.c * * Display functions */ #define _BSD_SOURCE #include #include #include #include "disp.h" /* * Actually displays infos in nice manner * @lst: queue containing all required information * @fsfilter: fstype to filter (can be nothing) */ void disp(struct list *lst, char *fsfilter) { struct fsmntinfo *p = NULL; int i, n; int skip = 1; int nm = 0; double perctused, size, avail, used; double stot, atot, utot, ifitot, ifatot; char *stropt; char *strtmp; stot = atot = utot = ifitot = ifatot = n = 0; /* activate negative matching? */ if (tflag) { if (fsfilter[0] == '-') { nm = 1; skip = 0; fsfilter++; } } /* legend on top */ if (!nflag) disp_header(lst); if (lst->fsmaxlen < 11) lst->fsmaxlen = 11; p = lst->head; while (p != NULL) { if (!aflag) { /* skip (pseudo)devices (which have a size of 0 usually) */ if (p->blocks == 0) { p = p->next; continue; /*NOTREACHED */ } } /* apply fsfiltering */ if (tflag) { if ((strtmp = strdup(fsfilter)) == NULL) { (void)fprintf(stderr, "cannot duplicate " "fsfilter\n"); exit(EXIT_FAILURE); /* NOTREACHED */ } stropt = strtok(fsfilter, ","); while (stropt != NULL) { if (strcmp(p->type, stropt) == 0) { if (nm) skip = 1; else skip = 0; } stropt = strtok(NULL, ","); } /* strtok modifies fsfilter so give back its value */ fsfilter = strdup(strtmp); if (skip) { if (nm) skip = 0; p = p->next; continue; /* NOTREACHED */ } else { if (!nm) skip = 1; } } /* filesystem */ (void)printf("%s", p->fsname); for (i = (int)strlen(p->fsname); i < lst->fsmaxlen + 1; i++) (void)printf(" "); /* type */ if (Tflag) { (void)printf("%s", p->type); for (i = (int)strlen(p->type); i < lst->typemaxlen + 1; i++) (void)printf(" "); } #ifdef __linux__ size = (double)p->blocks *(double)p->frsize; avail = (double)p->bavail * (double)p->frsize; used = size - avail; #else size = p->bsize * p->blocks; avail = p->bsize * p->bavail; used = p->bsize * (p->blocks - p->bfree); #endif /* calculate the % used */ if ((int)size == 0) perctused = 100.0; else perctused = (used / size) * 100.0; if (sflag) { stot += size; atot += avail; utot += used; } if (!bflag) disp_bar(perctused); /* %used */ disp_perct(perctused); /* format to requested format */ if (uflag) { size = cvrt(size); avail = cvrt(avail); } /* avail and total */ disp_at(avail, perctused); disp_at(size, perctused); /* info about inodes */ if (iflag) { ifitot += (double)p->files; ifatot += (double)p->favail; (void)printf("%9ldk", p->files / 1000); (void)printf("%9ldk", p->favail / 1000); } /* mounted on */ (void)printf(" %s", p->dir); /* info about mount option */ if (oflag) { for (i = (int)strlen(p->dir); i < imax(lst->dirmaxlen + 1, 11); i++) (void)printf(" "); (void)printf("%s\n", p->opts); } else (void)printf("\n"); p = p->next; } if (sflag) disp_sum(lst, stot, atot, utot, ifitot, ifatot); } /* * Display header * @lst: queue containing the information */ void disp_header(struct list *lst) { int i; int barinc = 5; /* use blue when color option is triggered */ if (cflag) (void)printf("\033[;34m"); (void)printf("FILESYSTEM "); for (i = 11; i < lst->fsmaxlen; i++) (void)printf(" "); if (Tflag) { (void)printf(" TYPE"); if (lst->typemaxlen > 5) for (i = 5; i < lst->typemaxlen + 1; i++) (void)printf(" "); else lst->typemaxlen = 5; } /* option to display a wider bar */ if (wflag) { barinc = 35; } if (!bflag) { (void)printf(" (=) USED"); for (i = 0; i < (barinc + 1); i++) (void)printf(" "); (void)printf("FREE (-) "); } (void)printf("%%USED"); if (unitflag == 'k') (void)printf(" "); else if (unitflag == 'b') (void)printf(" "); else (void)printf(" "); (void)printf("AVAILABLE"); if (unitflag == 'k') (void)printf(" "); else if (unitflag == 'm') (void)printf(" "); else if (unitflag == 'b') (void)printf(" "); else (void)printf(" "); (void)printf("TOTAL"); if (iflag) { (void)printf(" #INODES"); (void)printf(" AV.INODES"); } (void)printf(" MOUNTED ON "); if (oflag) { for (i = 10; i < lst->dirmaxlen; i++) (void)printf(" "); (void)printf("MOUNT OPTIONS\n"); } else (void)printf("\n"); reset_color(); } /* * display the sum (used when -s option is triggered) * @lst: queue containing the information * @stot: size total * @utot: */ void disp_sum(struct list *lst, double stot, double atot, double utot, double ifitot, double ifatot) { int i,j; double ptot = 0; if ((int)stot == 0) ptot = 100.0; else ptot = (utot / stot) * 100.0; (void)printf("SUM:"); j = lst->fsmaxlen + 1; if (Tflag) j += lst->typemaxlen + 1; for (i = 4; i < j; i++) (void)printf(" "); if (!bflag) disp_bar(ptot); disp_perct(ptot); if (uflag) { stot = cvrt(stot); atot = cvrt(atot); } disp_at(atot, ptot); disp_at(stot, ptot); if (ifitot && ifatot) { (void)printf("%9.fk", ifitot / 1000); (void)printf("%9.fk", ifatot / 1000); } (void)printf("\n"); } /* * Display nice usage bar * @perct: percentage value */ void disp_bar(double perct) { int i, j; int barinc = 5; /* option to display a wider bar */ if (wflag) { barinc = 2; } /* used (*) */ (void)printf("["); if (!cflag) { for (i = 0; i < perct; i += barinc) (void)printf("="); for (j = i; j < 100; j += barinc) (void)printf("-"); } else { /* color */ /* green */ (void)printf("\033[;32m"); for (i = 0; (i < 50) && (i < perct); i += barinc) (void)printf("="); /* yellow */ (void)printf("\033[;33m"); for (; (i < 75) && (i < perct); i += barinc) (void)printf("="); /* red */ (void)printf("\033[;31m"); for (; (i < 100) && (i < perct); i += barinc) (void)printf("="); reset_color(); for (j = i; j < 100; j += barinc) (void)printf("-"); } (void)printf("] "); } /* * Display available and total correctly formated * TODO: men... this is really UGLY! Just figure out something!! * @n: number to print * @perct: percentage (useful for finding which color to use) */ void disp_at(double n, double perct) { change_color(perct); /* available and total */ switch (unitflag) { case 'h': humanize(n, perct); return; /* NOTREACHED */ case 'b': (void)printf("%15.f", n); reset_color(); (void)printf("B"); return; /* NOTREACHED */ case 'k': (void)printf("%10.f", n); reset_color(); (void)printf("K"); return; /* NOTREACHED */ } (void)printf("%9.1f", n); reset_color(); switch (unitflag) { case 'm': (void)printf("M"); break; case 'g': (void)printf("G"); break; case 't': (void)printf("T"); break; case 'p': (void)printf("P"); break; case 'e': (void)printf("E"); break; case 'z': (void)printf("Z"); break; case 'y': (void)printf("Y"); break; } } /* * Display percentage * @perct: percentage */ void disp_perct(double perct) { if (!cflag) { (void)printf("%3.f%%", perct); } else { if (perct < 50.0) /* green */ (void)printf("\033[;32m"); else if (perct < 75.0) /* yellow */ (void)printf("\033[;33m"); else /* red */ (void)printf("\033[;31m"); (void)printf("%3.f", perct); reset_color(); (void)printf("%%"); } } /* * Change color according to perct * @perct: percentage */ void change_color(double perct) { if (cflag) { if (perct < 50.0) /* green */ (void)printf("\033[;32m"); else if (perct < 75.0) /* yellow */ (void)printf("\033[;33m"); else /* red */ (void)printf("\033[;31m"); } } /* * Reset color attribute to default */ void reset_color(void) { if (cflag) (void)printf("\033[;m"); } dfc-2.5.0/src/util.c0000644000175000001440000000542311736666712013235 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * util.c * * Various util functions */ #include #include #include #include #include #include "util.h" /* * Return the longest of the two parameters */ int imax(int a, int b) { return (a > b ? a : b); /* NOTREACHED */ } /* * Shorten the input string to the specified length * @str: string to shorten * @len: the length the new string should be */ char * shortenstr(char *str, int len) { int i = 0; int slen = (int)strlen(str); if (slen < len + 1) return str; /* NOTREACHED */ while (i++ < (slen - len)) str++; str[0] = '+'; return str; /* NOTREACHED */ } /* * Get the width of tty and return it. * Return 0 if stdout is not a tty. */ unsigned int getttywidth(void) { unsigned int width = 0; #ifdef TIOCGSIZE struct ttysize win; #elif defined(TIOCGWINSZ) struct winsize win; #endif if (!isatty(STDOUT_FILENO)) return 0; /* NOTREACHED */ #ifdef TIOCGSIZE if (ioctl(STDOUT_FILENO, TIOCGSIZE, &win) == 0) #ifdef __MACH__ width = win.ts_cols; #else width = win.ws_col; #endif #elif defined(TIOCGWINSZ) if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0) #ifdef __MACH__ width = win.ts_cols; #else width = win.ws_col; #endif #endif return width == 0 ? 80 : width; /* NOTREACHED */ } dfc-2.5.0/src/extern.h0000644000175000001440000000350411736666712013570 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef H_EXTERN #define H_EXTERN /* * extern.h * * Globals and dfc version declaration */ #define VERSION "2.5.0" /* set flags for options */ int aflag, bflag, cflag, fflag, hflag, iflag, mflag, nflag, oflag, sflag, tflag, uflag, vflag, wflag; int Tflag, Wflag; char unitflag; #endif /* ndef EXTERN_H */ dfc-2.5.0/src/dfc.h0000644000175000001440000000374211736666712013023 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef H_DFC #define H_DFC /* * dfc.h * * header file for dfc.c */ #include "extern.h" #include "list.h" #include "disp.h" #include "util.h" /* function declaration */ void usage(int status); void fetch_info(struct list *lst); double cvrt(double n); void humanize(double n, double perct); #ifdef __FreeBSD__ /* avoid struct statfs declared inside parameter list warning */ struct statfs; char * statfs_flags_to_str(struct statfs *s); #endif #endif /* ndef DFC_H */ dfc-2.5.0/src/list.c0000644000175000001440000000606611736666712013237 0ustar robinusers/* * Copyright (c) 2012, Robin Hahling * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1 Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2 Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4 Neither the name of the author nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * list.c * * Manipulate list */ #include #include #include "list.h" /* * Initializes a queue structure * @lst: queue pointer */ void init_queue(struct list *lst) { lst->head = NULL; lst->tail = NULL; lst->fsmaxlen = -1; lst->dirmaxlen = -1; lst->typemaxlen = -1; } /* * Checks if a queue is empty * @lst: queue * Returns: * --> 1 (true) if the queue is empty * --> 0 if not */ int is_empty(struct list lst) { if (lst.head == NULL) return 1; /* NOTREACHED */ else return 0; /* NOTREACHED */ } /* * Enqueues an element into a queue * @lst: queue pointer * @elt: element * Returns: * --> -1 on error * --> 0 on sucess */ int enqueue(struct list *lst, struct fsmntinfo fmi) { struct fsmntinfo *new_fmi = malloc(sizeof(struct fsmntinfo)); if (new_fmi == NULL) { (void)fputs("Error while allocating memory to fmi", stderr); return -1; /* NOTREACHED */ } /* initialize the new element to be inserted in the queue */ *new_fmi = fmi; if (is_empty((*lst))) lst->head = new_fmi; else lst->tail->next = new_fmi; lst->tail = new_fmi; return 0; /* NOTREACHED */ } /* * Inits an fsmntinfo to some defaults values * Returns: * --> fsmntinfo that has been initialized */ struct fsmntinfo fmi_init(void) { struct fsmntinfo fmi; fmi.fsname = "unknown"; fmi.dir = "unknown"; fmi.type = "unknown"; fmi.opts = "none"; fmi.bsize = 0; fmi.frsize = 0; fmi.blocks = 0; fmi.bfree = 0; fmi.bavail = 0; fmi.files = 0; fmi.ffree = 0; fmi.favail = 0; fmi.next = NULL; return fmi; /* NOTREACHED */ } dfc-2.5.0/Makefile0000644000175000001440000000170611736666712012765 0ustar robinusersCC ?= gcc CFLAGS ?= -O2 -std=c89 LDFLAGS += CFDEBUG = -g3 -pedantic -Wall -Wunused-parameter -Wlong-long\ -Wsign-conversion -Wconversion -Wimplicit-function-declaration SRC = src MAN = man EXEC = dfc SRCS= ${SRC}/dfc.c \ ${SRC}/disp.c \ ${SRC}/list.c \ ${SRC}/util.c OBJS= ${SRCS:.c=.o} .PATH: ${SRC} PREFIX?=/usr/local BINDIR=${PREFIX}/bin MANDIR=${PREFIX}/man all: ${EXEC} .c.o: ${CC} ${CFLAGS} -o $@ -c $< ${EXEC}: ${OBJS} ${CC} ${LDFLAGS} -o ${EXEC} ${OBJS} install-main: dfc test -d ${DESTDIR}${BINDIR} || mkdir -p ${DESTDIR}${BINDIR} install -m755 dfc ${DESTDIR}${BINDIR}/dfc install-data: ${MAN}/dfc.1 test -d ${DESTDIR}${MANDIR}/man1 || mkdir -p ${DESTDIR}${MANDIR}/man1 install -m644 ${MAN}/dfc.1 ${DESTDIR}${MANDIR}/man1/dfc.1 install: all install-main install-data debug: ${EXEC} debug: CC += ${CFDEBUG} clean: rm -rf ${SRC}/*.o mrproper: clean rm ${EXEC} .PHONY: all clean mrproper install install-main install-data dfc-2.5.0/AUTHORS0000644000175000001440000000026611736666712012375 0ustar robinusersAUTHOR: - Robin Hahling CONTRIBUTORS: - Baptiste Daroussin - Cyril Roelandt - Kevin Gillieron - Matthieu Le Jeune - Sylvain Laperche dfc-2.5.0/man/0000755000175000001440000000000011736666712012074 5ustar robinusersdfc-2.5.0/man/dfc.10000644000175000001440000000703511736666712012717 0ustar robinusers.TH dfc 1 "April 3, 2012" "version 2.5.0" "USER COMMANDS" .SH NAME dfc \- display file system space usage using graph and colors .SH SYNOPSIS .B dfc [OPTION(S)] [-c WHEN] [-u UNIT] [-t FILESYSTEM] .SH DESCRIPTION dfc(1) is a tool similar to df(1) except that it is able to show a graph along with the data and is able to use color (color mode is "color-auto" by default but you can change this with "-c" option). The available size correspond to the space available to a user point of view and not from root's perspective (ie: use f_bavail instead of f_bfree). In the same idea, used space is computed simply by substracting the available space from the total size. Without any argument, size is displayed in human readable format. Be aware that when using human-readable format, there might be some rounding when computing the size. If you want maximum precision, use the "-u" option and choose the unit. dfc(1) also has a built in feature that makes the output auto adjust based on terminal width. If you want to override this behavior, use the "-f" option. .SH OPTIONS .TP \-a Show information about all file systems found in the mtab file. .TP \-b Do not show the graph bar. .TP \-c [WHEN] Choose color mode where WHEN is one of the following sub-option: "always": Color will always be used, no matter what stdout is. "auto": This is default when "-c" is not activated. Color is used only if "stdout" is a terminal. For instance, color will be disabled with this option if you pipe the output of dfc(1) into another command. "never": Color will never be used. .TP \-f Override auto-adjust behavior by forcing information to be displayed. You probably do not want to activate this option but choice is yours. This option may be useful if you pipe the output of dfc(1) though. .TP \-h Show a short help text. .TP \-i Show information about inodes. .TP \-m Use SI units (metric) (ie: size is computed using powers of 10 instead of powers of 2). .TP \-n Do not print header. .TP \-o Show mount options. .TP \-s Sum the total usage. .TP \-t [FILESYSTEM] Allows you to perform filtering on file system type. FILESYSTEM could take any known file system value. For instance, "ext4", "ufs", "tmpfs", "reiserfs", etc. Multiple selection on file system is also possible. In this case, FILESYSTEM needs to be comma separated (without spaces). For instance, if you want to filter "ext4" and "tmpfs", you would use the following: dfc -t ext4,tmpfs You can also use negative matching to filter the output. To do so, you just need to prepend a "-" to FILESYSTEM. In the following example, dfc(1) will display all file system type except those mentionned: dfc -t -rootfs,tmpfs .TP \-T Show filesystem type. .TP \-u [UNIT] Show size using unit specified. UNIT can take one of the following value: "h": Human readable (default when not using "-u" option). "b": Show bytes. "k": Show size using Kio. "m": Show size using Mio. "g": Show size using Gio. "t": Show size using Tio. "p": Show size using Pio. "e": Show size using Eio. "z": Show size using Zio. "y": Show size using Yio. NOTE: When using "-u" option along with "-m" option, those suboptions are replaced by their SI counterparts. .TP \-v Print dfc(1) version and exit. .TP \-w Use a wider bar. .TP \-W Wide path name (avoid truncation of file name). May require a larger display. .SH BUGS If you find one, please contact the author and explain what you encounter. .SH AUTHORS Robin Hahling (robin.hahling (at) gw-computing.net) .SH COPYRIGHT Copyright \(co 2012 Robin Hahling .SH LICENSE 3 Clauses BSD .SH SEE ALSO df(1), du(1) dfc-2.5.0/LICENSE0000644000175000001440000000272111736666712012330 0ustar robinusersCopyright (c) 2012, Robin Hahling All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 4 Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. dfc-2.5.0/README0000644000175000001440000000052411736666712012202 0ustar robinusersdfc is a simple tool that display file system usage BUILD simply use make: make RUN Once built, you can run it by typing: ./dfc see ./dfc -h for options and usage INSTALL By default, it will be installed in /usr/local/bin. As root, type: make install If you want to override this, change the prefix like so: make PREFIX=/usr install dfc-2.5.0/HACKING0000644000175000001440000000064511736666712012315 0ustar robinusersPatches are welcome! Just keep in mind the following: - keep the same coding style - your patch must improve dfc in one way or another If this is OK, you can send it via email to the author: Robin Hahling: OR, better solution, register to the official website: http://projects.gw-computing.net/projects/dfc and add an issue with your patch attached. Thanks for making dfc better!