#include "format-util.h"
#include "fs-util.h"
#include "fstab-util.h"
+#include "libmount-util.h"
#include "main-func.h"
#include "mount-util.h"
#include "mountpoint-util.h"
}
static int find_mount_points(const char *what, char ***list) {
- _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
+ _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
+ _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
_cleanup_strv_free_ char **l = NULL;
size_t bufsize = 0, n = 0;
+ int r;
assert(what);
assert(list);
/* Returns all mount points obtained from /proc/self/mountinfo in *list,
* and the number of mount points as return value. */
- proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
- if (!proc_self_mountinfo)
- return log_error_errno(errno, "Can't open /proc/self/mountinfo: %m");
+ r = libmount_parse(NULL, NULL, &table, &iter);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse /proc/self/mountinfo: %m");
for (;;) {
- _cleanup_free_ char *path = NULL, *where = NULL, *dev = NULL;
- int r;
+ struct libmnt_fs *fs;
+ const char *source, *target;
- r = fscanf(proc_self_mountinfo,
- "%*s " /* (1) mount id */
- "%*s " /* (2) parent id */
- "%*s " /* (3) major:minor */
- "%*s " /* (4) root */
- "%ms " /* (5) mount point */
- "%*s" /* (6) mount options */
- "%*[^-]" /* (7) optional fields */
- "- " /* (8) separator */
- "%*s " /* (9) file system type */
- "%ms" /* (10) mount source */
- "%*s" /* (11) mount options 2 */
- "%*[^\n]", /* some rubbish at the end */
- &path, &dev);
- if (r != 2) {
- if (r == EOF)
- break;
-
- continue;
- }
+ r = mnt_table_next_fs(table, iter, &fs);
+ if (r == 1)
+ break;
+ if (r < 0)
+ return log_error_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
- if (!streq(what, dev))
+ source = mnt_fs_get_source(fs);
+ target = mnt_fs_get_target(fs);
+ if (!source || !target)
continue;
- r = cunescape(path, UNESCAPE_RELAX, &where);
- if (r < 0)
+ if (!path_equal(source, what))
continue;
/* one extra slot is needed for the terminating NULL */
- if (!GREEDY_REALLOC(l, bufsize, n + 2))
+ if (!GREEDY_REALLOC0(l, bufsize, n + 2))
return log_oom();
- l[n++] = TAKE_PTR(where);
+ l[n] = strdup(target);
+ if (!l[n])
+ return log_oom();
+ n++;
}
- if (!GREEDY_REALLOC(l, bufsize, n + 1))
+ if (!GREEDY_REALLOC0(l, bufsize, n + 1))
return log_oom();
- l[n] = NULL;
*list = TAKE_PTR(l);
-
return n;
}
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
+ log_show_color(true);
log_parse_environment();
log_open();
if (arg_action == ACTION_UMOUNT)
return action_umount(bus, argc, argv);
- if (!path_is_normalized(arg_mount_what)) {
+ if ((!arg_mount_type || !fstype_is_network(arg_mount_type))
+ && !path_is_normalized(arg_mount_what)) {
log_error("Path contains non-normalized components: %s", arg_mount_what);
return -EINVAL;
}