The search direction, either *forward* or *backward*.
*-e*, *--evaluate*::
-Convert all tags (LABEL, UUID, PARTUUID or PARTLABEL) to the corresponding device names.
+Convert all tags (LABEL, UUID, PARTUUID, or PARTLABEL) to the corresponding device names for the SOURCE column. It's an unusual situation, but the same tag may be duplicated (used for more devices). For this purpose, there is SOURCES (pl.) column. This column displays by multi-line cell all devices where the tag is detected by libblkid. This option makes sense for fstab only.
*-F*, *--tab-file* _path_::
Search in an alternative file. If used with *--fstab*, *--mtab* or *--kernel*, then it overrides the default paths. If specified more than once, then tree-like output is disabled (see the *--list* option).
#ifdef HAVE_LIBUDEV
# include <libudev.h>
#endif
+#include <blkid.h>
#include <libmount.h>
#include <libsmartcols.h>
#include "xalloc.h"
#include "optutils.h"
#include "mangle.h"
+#include "buffer.h"
#include "findmnt.h"
COL_PROPAGATION,
COL_SIZE,
COL_SOURCE,
+ COL_SOURCES,
COL_TARGET,
COL_TID,
COL_USED,
[COL_PASSNO] = { "PASSNO", 1, SCOLS_FL_RIGHT, N_("pass number on parallel fsck(8) [fstab only]") },
[COL_PROPAGATION] = { "PROPAGATION", 0.10, 0, N_("VFS propagation flags") },
[COL_SIZE] = { "SIZE", 5, SCOLS_FL_RIGHT, N_("filesystem size") },
+ [COL_SOURCES] = { "SOURCES", 0.25, SCOLS_FL_WRAP, N_("all possible source devices [fstab only]") },
[COL_SOURCE] = { "SOURCE", 0.25, SCOLS_FL_NOEXTREMES, N_("source device") },
[COL_TARGET] = { "TARGET", 0.30, SCOLS_FL_TREE| SCOLS_FL_NOEXTREMES, N_("mountpoint") },
[COL_TID] = { "TID", 4, SCOLS_FL_RIGHT, N_("task ID") },
static char *get_data(struct libmnt_fs *fs, int num)
{
char *str = NULL;
+ const char *t = NULL, *v = NULL;
int col_id = get_column_id(num);
switch (col_id) {
+ case COL_SOURCES:
+ /* print all devices with the same tag (LABEL, UUID) */
+ if ((flags & FL_EVALUATE) &&
+ mnt_fs_get_tag(fs, &t, &v) == 0) {
+ blkid_dev_iterate iter;
+ blkid_dev dev;
+ blkid_cache cache = NULL;
+ struct ul_buffer buf = UL_INIT_BUFFER;
+ int i = 0;
+
+ if (blkid_get_cache(&cache, NULL) < 0)
+ break;
+
+ blkid_probe_all(cache);
+
+ iter = blkid_dev_iterate_begin(cache);
+ blkid_dev_set_search(iter, t, v);
+ while (blkid_dev_next(iter, &dev) == 0) {
+ dev = blkid_verify(cache, dev);
+ if (!dev)
+ continue;
+ if (i != 0)
+ ul_buffer_append_data(&buf, "\n", 1);
+ ul_buffer_append_string(&buf, blkid_dev_devname(dev));
+ i++;
+ }
+ blkid_dev_iterate_end(iter);
+ str = ul_buffer_get_data(&buf, NULL, NULL);
+ break;
+ }
+ /* fallthrough */
case COL_SOURCE:
{
const char *root = mnt_fs_get_root(fs);
free(cn);
break;
}
+
case COL_TARGET:
if (mnt_fs_get_target(fs))
str = xstrdup(mnt_fs_get_target(fs));
warn(_("failed to allocate output column"));
goto leave;
}
-
+ /* multi-line cells (now used for SOURCES) */
+ if (fl & SCOLS_FL_WRAP) {
+ scols_column_set_wrapfunc(cl,
+ scols_wrapnl_chunksize,
+ scols_wrapnl_nextchunk,
+ NULL);
+ scols_column_set_safechars(cl, "\n");
+ }
if (flags & FL_JSON) {
switch (id) {
case COL_SIZE:
scols_column_set_json_type(cl, SCOLS_JSON_BOOLEAN);
break;
default:
- scols_column_set_json_type(cl, SCOLS_JSON_STRING);
+ if (fl & SCOLS_FL_WRAP)
+ scols_column_set_json_type(cl, SCOLS_JSON_ARRAY_STRING);
+ else
+ scols_column_set_json_type(cl, SCOLS_JSON_STRING);
break;
}
}