const char *type = mnt_fs_get_fstype(fs);
const char *src = mnt_fs_get_source(fs);
const char *optstr = mnt_fs_get_options(fs);
+ char *xsrc;
if (type && pattern && !mnt_match_fstype(type, pattern))
continue;
- /* TODO: print loop backing file instead of device name */
-
- printf ("%s on %s", src ? : "none", mnt_fs_get_target(fs));
+ xsrc = mnt_pretty_path(src, cache);
+ printf ("%s on %s", xsrc, mnt_fs_get_target(fs));
if (type)
printf (" type %s", type);
if (optstr)
printf (" [%s]", lb);
}
fputc('\n', stdout);
+ free(xsrc);
}
mnt_free_cache(cache);
#include "canonicalize.h"
#include "mountP.h"
+#include "loopdev.h"
/*
* Canonicalized (resolved) paths & tags cache
* @path: "native" path
* @cache: cache for results or NULL
*
+ * Converts path:
+ * - to the absolute path
+ * - /dev/dm-N to /dev/mapper/<name>
+ *
* Returns: absolute path or NULL in case of error. The result has to be
* deallocated by free() if @cache is NULL.
*/
return NULL;
}
+/**
+ * mnt_pretty_path:
+ * @path: any path
+ * @cache: NULL or pointer to the cache
+ *
+ * Converts path:
+ * - to the absolute path
+ * - /dev/dm-N to /dev/mapper/<name>
+ * - /dev/loopN to the loop backing filename
+ * - empty path (NULL) to 'none'
+ *
+ * Returns: new allocated string with path, result has to be always deallocated
+ * by free().
+ */
+char *mnt_pretty_path(const char *path, struct libmnt_cache *cache)
+{
+ char *pretty = mnt_resolve_path(path, cache);
+
+ if (!pretty)
+ return strdup("none");
+
+ /* users assume backing file name rather than /dev/loopN in
+ * output if the device has been initialized by mount(8).
+ */
+ if (strncmp(pretty, "/dev/loop", 9) == 0) {
+ struct loopdev_cxt lc;
+
+ loopcxt_init(&lc, 0);
+ loopcxt_set_device(&lc, pretty);
+
+ if (loopcxt_is_autoclear(&lc)) {
+ char *tmp = loopcxt_get_backing_file(&lc);
+ if (tmp) {
+ if (!cache)
+ free(pretty); /* not cached, deallocate */
+ return tmp; /* return backing file */
+ }
+ }
+ loopcxt_deinit(&lc);
+
+ }
+
+ /* don't return pointer to the cache, allocate a new string */
+ return cache ? strdup(pretty) : pretty;
+}
+
/**
* mnt_resolve_tag:
* @token: tag name
struct libmnt_cache *cache);
extern char *mnt_resolve_spec(const char *spec, struct libmnt_cache *cache);
+extern char *mnt_pretty_path(const char *path, struct libmnt_cache *cache);
+
/* optstr.c */
extern int mnt_optstr_next_option(char **optstr, char **name, size_t *namesz,
char **value, size_t *valuesz);