From: Karel Zak Date: Wed, 24 Nov 2021 11:22:27 +0000 (+0100) Subject: findmnt: add support to print deleted targets X-Git-Tag: v2.38-rc1~149 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4441e511635f3e4116b59a77da1e4ca68552c3cc;p=thirdparty%2Futil-linux.git findmnt: add support to print deleted targets Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.8.adoc b/misc-utils/findmnt.8.adoc index 3a3461f030..7614ec2332 100644 --- a/misc-utils/findmnt.8.adoc +++ b/misc-utils/findmnt.8.adoc @@ -46,6 +46,9 @@ Do not canonicalize paths at all. This option affects the comparing of paths and *-c*, *--canonicalize*:: Canonicalize all printed paths. +*--deleted*:: +Print filesystems where target (mountpoint) is marked as deleted by kernel. + *-D*, *--df*:: Imitate the output of *df*(1). This option is equivalent to *-o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET* but excludes all pseudo filesystems. Use *--all* to print all filesystems. diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 55aa936faf..815203778b 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -53,6 +53,7 @@ enum { COL_ACTION, COL_AVAIL, + COL_DELETED, COL_FREQ, COL_FSROOT, COL_FSTYPE, @@ -99,6 +100,7 @@ struct colinfo { static struct colinfo infos[] = { [COL_ACTION] = { "ACTION", 10, SCOLS_FL_STRICTWIDTH, N_("action detected by --poll") }, [COL_AVAIL] = { "AVAIL", 5, SCOLS_FL_RIGHT, N_("filesystem size available") }, + [COL_DELETED] = { "DELETED", 1, SCOLS_FL_RIGHT, N_("filesystem target marked as deleted") }, [COL_FREQ] = { "FREQ", 1, SCOLS_FL_RIGHT, N_("dump(8) period in days [fstab only]") }, [COL_FSROOT] = { "FSROOT", 0.25, SCOLS_FL_NOEXTREMES, N_("filesystem root") }, [COL_FSTYPE] = { "FSTYPE", 0.10, SCOLS_FL_TRUNC, N_("filesystem type") }, @@ -150,7 +152,7 @@ static int actions[FINDMNT_NACTIONS]; static int nactions; /* global (accessed from findmnt-verify.c too) */ -int flags; +unsigned int flags; int parse_nerrors; struct libmnt_cache *cache; @@ -638,6 +640,9 @@ static char *get_data(struct libmnt_fs *fs, int num) if (!mnt_fs_is_kernel(fs)) xasprintf(&str, "%d", mnt_fs_get_passno(fs)); break; + case COL_DELETED: + str = xstrdup(mnt_fs_is_deleted(fs) ? "1" : "0"); + break; default: break; } @@ -991,6 +996,9 @@ static int match_func(struct libmnt_fs *fs, return rc; } + if ((flags & FL_DELETED) && !mnt_fs_is_deleted(fs)) + return rc; + return !rc; } @@ -1259,6 +1267,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -b, --bytes print sizes in bytes rather than in human readable format\n"), out); fputs(_(" -C, --nocanonicalize don't canonicalize when comparing paths\n"), out); fputs(_(" -c, --canonicalize canonicalize printed paths\n"), out); + fputs(_(" --deleted print filesystems with mountpoint marked as deleted\n"), out); fputs(_(" -D, --df imitate the output of df(1)\n"), out); fputs(_(" -d, --direction direction of search, 'forward' or 'backward'\n"), out); fputs(_(" -e, --evaluate convert tags (LABEL,UUID,PARTUUID,PARTLABEL) \n" @@ -1327,7 +1336,8 @@ int main(int argc, char *argv[]) FINDMNT_OPT_PSEUDO, FINDMNT_OPT_REAL, FINDMNT_OPT_VFS_ALL, - FINDMNT_OPT_SHADOWED + FINDMNT_OPT_SHADOWED, + FINDMNT_OPT_DELETED, }; static const struct option longopts[] = { @@ -1335,6 +1345,7 @@ int main(int argc, char *argv[]) { "ascii", no_argument, NULL, 'a' }, { "bytes", no_argument, NULL, 'b' }, { "canonicalize", no_argument, NULL, 'c' }, + { "deleted", no_argument, NULL, FINDMNT_OPT_DELETED }, { "direction", required_argument, NULL, 'd' }, { "df", no_argument, NULL, 'D' }, { "evaluate", no_argument, NULL, 'e' }, @@ -1553,7 +1564,9 @@ int main(int argc, char *argv[]) case FINDMNT_OPT_SHADOWED: flags |= FL_SHADOWED; break; - + case FINDMNT_OPT_DELETED: + flags |= FL_DELETED; + break; case 'h': usage(); case 'V': @@ -1719,6 +1732,9 @@ int main(int argc, char *argv[]) case COL_TID: scols_column_set_json_type(cl, SCOLS_JSON_NUMBER); break; + case COL_DELETED: + scols_column_set_json_type(cl, SCOLS_JSON_BOOLEAN); + break; default: scols_column_set_json_type(cl, SCOLS_JSON_STRING); break; diff --git a/misc-utils/findmnt.h b/misc-utils/findmnt.h index ed7dea05af..f5d5ac562e 100644 --- a/misc-utils/findmnt.h +++ b/misc-utils/findmnt.h @@ -22,18 +22,19 @@ enum { FL_REAL = (1 << 18), FL_VFS_ALL = (1 << 19), FL_SHADOWED = (1 << 20), + FL_DELETED = (1 << 21), /* basic table settings */ - FL_ASCII = (1 << 21), - FL_RAW = (1 << 22), - FL_NOHEADINGS = (1 << 23), - FL_EXPORT = (1 << 24), - FL_TREE = (1 << 25), - FL_JSON = (1 << 26), + FL_ASCII = (1 << 25), + FL_RAW = (1 << 26), + FL_NOHEADINGS = (1 << 27), + FL_EXPORT = (1 << 28), + FL_TREE = (1 << 29), + FL_JSON = (1 << 30), }; extern struct libmnt_cache *cache; -extern int flags; +extern unsigned int flags; extern int parse_nerrors; extern int is_listall_mode(void);