int main(const int argc, const char* argv[]) { if (argc == 2) { if (strcmp(argv[1], "--verbose") == 0) { verbose_mode = 1; } } prepare(); clearSupplementaryGroups(); selfCheck(); struct libmnt_table* mt = mnt_new_table_from_file("/opt/xware_desktop/mounts"); if (mt == NULL) { fprintf(stderr, "mnt_new_table_from_file failed.\n"); exit(EXIT_FAILURE); } struct libmnt_iter* itr = mnt_new_iter(MNT_ITER_FORWARD); struct libmnt_fs* fs = NULL; while(1) { int tmp = mnt_table_find_next_fs(mt, itr, &matchAll, NULL, &fs); if (tmp < 0) { // error fprintf(stderr, "mnt_table_find_next_fs failed.\n"); break; } else { if (tmp == 1) { // reach EOF break; } const char* target = mnt_fs_get_target(fs); if (target == NULL) { fprintf(stderr, "mnt_fs_get_target failed.\n"); } else { printf("%s%s%s\n", BOLD, target, NOSTYLE); printf("================================\n"); if (checkDirXPermissions(target)) { checkTargetDirPermissions(target); } printf("\n"); } } } printf("%s", NOSTYLE); mnt_free_fs(fs); mnt_free_iter(itr); mnt_free_table(mt); return 0; }
/* * This function works like mnt_resolve_tag(), but it's able to read UUiD/LABEL * from regular swap files too (according to entries in /proc/swaps). Note that * mnt_resolve_tag() and mnt_resolve_spec() works with system visible block * devices only. */ static char *swapoff_resolve_tag(const char *name, const char *value, struct libmnt_cache *cache) { char *path; struct libmnt_table *tb; struct libmnt_iter *itr; struct libmnt_fs *fs; /* this is usual case for block devices (and it's really fast as it uses * udev /dev/disk/by-* symlinks by default */ path = mnt_resolve_tag(name, value, cache); if (path) return path; /* try regular files from /proc/swaps */ tb = get_swaps(); if (!tb) return NULL; itr = mnt_new_iter(MNT_ITER_BACKWARD); if (!itr) err(EXIT_FAILURE, _("failed to initialize libmount iterator")); while (tb && mnt_table_next_fs(tb, itr, &fs) == 0) { blkid_probe pr = NULL; const char *src = mnt_fs_get_source(fs); const char *type = mnt_fs_get_swaptype(fs); const char *data = NULL; if (!src || !type || strcmp(type, "file") != 0) continue; pr = get_swap_prober(src); if (!pr) continue; blkid_probe_lookup_value(pr, name, &data, NULL); if (data && strcmp(data, value) == 0) path = xstrdup(src); blkid_free_probe(pr); if (path) break; } mnt_free_iter(itr); return path; }
static int get_debugfs(char **path) { struct libmnt_context *cxt; struct libmnt_table *tb; struct libmnt_iter *itr = NULL; struct libmnt_fs *fs; int found = 0, ret; cxt = mnt_new_context(); if (!cxt) err(EXIT_FAILURE, "libmount context allocation failed"); itr = mnt_new_iter(MNT_ITER_FORWARD); if (!itr) err(EXIT_FAILURE, "failed to initialize libmount iterator"); if (mnt_context_get_mtab(cxt, &tb)) err(EXIT_FAILURE, "failed to read mtab"); while (mnt_table_next_fs(tb, itr, &fs) == 0) { const char *type = mnt_fs_get_fstype(fs); if (!strcmp(type, "debugfs")) { found = 1; break; } } if (found) { ret = asprintf(path, "%s/gpio", mnt_fs_get_target(fs)); if (ret < 0) err(EXIT_FAILURE, "failed to format string"); } mnt_free_iter(itr); mnt_free_context(cxt); if (!found) return -1; return 0; }
static int swapoff_all(void) { int status = 0; struct libmnt_table *tb; struct libmnt_fs *fs; struct libmnt_iter *itr = mnt_new_iter(MNT_ITER_BACKWARD); if (!itr) err(EXIT_FAILURE, _("failed to initialize libmount iterator")); /* * In case /proc/swaps exists, unswap stuff listed there. We are quiet * but report errors in status. Errors might mean that /proc/swaps * exists as ordinary file, not in procfs. do_swapoff() exits * immediately on EPERM. */ tb = get_swaps(); while (tb && mnt_table_find_next_fs(tb, itr, match_swap, NULL, &fs) == 0) status |= do_swapoff(mnt_fs_get_source(fs), QUIET, CANONIC); /* * Unswap stuff mentioned in /etc/fstab. Probably it was unmounted * already, so errors are not bad. Doing swapoff -a twice should not * give error messages. */ tb = get_fstab(); mnt_reset_iter(itr, MNT_ITER_FORWARD); while (tb && mnt_table_find_next_fs(tb, itr, match_swap, NULL, &fs) == 0) { if (!is_active_swap(mnt_fs_get_source(fs))) do_swapoff(mnt_fs_get_source(fs), QUIET, !CANONIC); } mnt_free_iter(itr); return status; }
static inline void mnt_free_iterp(struct libmnt_iter **itr) { if (*itr) mnt_free_iter(*itr); *itr=NULL; }