logo

utils-std

Collection of commonly available Unix tools
commit: 19e81ca6d0509ae84ce310655f2be2a7093798e4
parent 6931046faab892405d9b2727a1ab27402ede4456
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 10 Mar 2024 14:02:47 +0100

cmd/df: Add -l option

Diffstat:

Mcmd/df.18++++++--
Mcmd/df.c30++++++++++++++++++++++++++++--
2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/cmd/df.1 b/cmd/df.1 @@ -9,7 +9,7 @@ .Nd display mounted filesystems usage .Sh SYNOPSIS .Nm -.Op Fl ahPkT +.Op Fl ahlPkT .Op Fl x Ar mnt_type .Sh DESCRIPTION .Nm @@ -27,6 +27,8 @@ Display all mounted filesystems, otherwise deduplicates filesystems and skips ones with a blocksize of zero. .It Fl h Print human readable sizes. +.It Fl l +Exclude known remote filesystems. .It Fl P POSIX Formatting, prints in blocks of 512 when .It Fl k @@ -51,7 +53,9 @@ For example lacks getting a list of filesystems as argument to be compliant with the .St -p1003.1-2008 specification. +.Fl l +and .Fl x -is a GNU extension. +are GNU extensions. .Sh AUTHORS .An Haelwenn (lanodan) Monnier Aq Mt contact@hacktivis.me diff --git a/cmd/df.c b/cmd/df.c @@ -18,6 +18,15 @@ #include <sys/statvfs.h> #include <unistd.h> // getopt +// Grabbed from OpenRC rc-functions.sh +// clang-format off +static const char *net_fs_list[] = { + "afs", "ceph", "cifs", "coda", "davfs", "fuse", "fuse.glusterfs", + "fuse.sshfs", "gfs", "glusterfs", "lustre", "ncpfs", "nfs", "nfs4", + "ocfs2", "shfs", "smbfs" +}; +// clang-format on + size_t forced_bsize = 0; // Replaces control characters and whitespaces with '?' in-place (no allocation) @@ -31,13 +40,13 @@ static_escape(char *str) int main(int argc, char *argv[]) { - bool opt_P = false, opt_h = false, opt_a = false, opt_T = false; + bool opt_P = false, opt_h = false, opt_a = false, opt_T = false, opt_l = false; size_t excluded_count = 0; int fs_col_width = 20; char *excluded[4096]; int c = EOF; - while((c = getopt(argc, argv, ":ahPkTx:")) != EOF) + while((c = getopt(argc, argv, ":ahlPkTx:")) != EOF) { switch(c) { @@ -56,6 +65,9 @@ main(int argc, char *argv[]) opt_h = true; fs_col_width = 30; break; + case 'l': + opt_l = true; + break; case 'T': opt_T = true; break; @@ -186,6 +198,20 @@ main(int argc, char *argv[]) if(exclude) continue; } + if(opt_l) + { + bool remote = false; + + for(size_t i = 0; i < sizeof(net_fs_list) / sizeof(char *); i++) + if(strcmp(net_fs_list[i], mntent->mnt_type) == 0) + { + remote = true; + break; + } + + if(remote) continue; + } + // Needs to be done after calling statvfs(3) and stat(3) static_escape(mntent->mnt_fsname); static_escape(mntent->mnt_dir);