Example #1
0
static int is_mounted(struct libmnt_fs *fs)
{
	int rc;
	const char *src;

	src = mnt_fs_get_source(fs);
	if (!src)
		return 0;
	if (!mntcache)
		mntcache = mnt_new_cache();
	if (!mtab) {
		mtab = mnt_new_table();
		if (!mtab)
			err(FSCK_EX_ERROR, ("failed to initialize libmount table"));
		mnt_table_set_cache(mtab, mntcache);
		mnt_table_parse_mtab(mtab, NULL);
	}

	rc = mnt_table_find_source(mtab, src, MNT_ITER_BACKWARD) ? 1 : 0;
	if (verbose) {
		if (rc)
			printf(_("%s is mounted\n"), src);
		else
			printf(_("%s is not mounted\n"), src);
	}
	return rc;
}
Example #2
0
/*
 * See if device has been mounted by looking in mount table.  If so, set
 * device name and mount point name, and return 1, otherwise return 0.
 */
static int device_get_mountpoint(char **devname, char **mnt)
{
	struct libmnt_fs *fs;
	int rc;

	*mnt = NULL;

	if (!mtab) {
		mtab = mnt_new_table();
		if (!mtab)
			err(EXIT_FAILURE, _("failed to initialize libmount table"));

		cache = mnt_new_cache();
		mnt_table_set_cache(mtab, cache);

		if (p_option)
			rc = mnt_table_parse_file(mtab, _PATH_PROC_MOUNTINFO);
		else
			rc = mnt_table_parse_mtab(mtab, NULL);
		if (rc)
			err(EXIT_FAILURE, _("failed to parse mount table"));
	}

	fs = mnt_table_find_source(mtab, *devname, MNT_ITER_BACKWARD);
	if (!fs) {
		/* maybe 'devname' is mountpoint rather than a real device */
		fs = mnt_table_find_target(mtab, *devname, MNT_ITER_BACKWARD);
		if (fs) {
			free(*devname);
			*devname = xstrdup(mnt_fs_get_source(fs));
		}
	}

	if (fs) {
		*mnt = xstrdup(mnt_fs_get_target(fs));
		/* We'll call umount(), so remove the filesystem from the table
		 * to avoid duplicate results in the next device_get_mountpoint()
		 * call */
		mnt_free_fs(fs);
	}
	return *mnt ? 0 : -1;
}
Example #3
0
/*
 * See if device has been mounted by looking in mount table.  If so, set
 * device name and mount point name, and return 1, otherwise return 0.
 */
static int device_get_mountpoint(char **devname, char **mnt)
{
	struct libmnt_fs *fs;
	int rc;

	*mnt = NULL;

	if (!mtab) {
		struct libmnt_cache *cache;

		mtab = mnt_new_table();
		if (!mtab)
			err(EXIT_FAILURE, _("failed to initialize libmount table"));

		cache = mnt_new_cache();
		mnt_table_set_cache(mtab, cache);
		mnt_unref_cache(cache);

		if (p_option)
			rc = mnt_table_parse_file(mtab, _PATH_PROC_MOUNTINFO);
		else
			rc = mnt_table_parse_mtab(mtab, NULL);
		if (rc)
			err(EXIT_FAILURE, _("failed to parse mount table"));
	}

	fs = mnt_table_find_source(mtab, *devname, MNT_ITER_BACKWARD);
	if (!fs) {
		/* maybe 'devname' is mountpoint rather than a real device */
		fs = mnt_table_find_target(mtab, *devname, MNT_ITER_BACKWARD);
		if (fs) {
			free(*devname);
			*devname = xstrdup(mnt_fs_get_source(fs));
		}
	}

	if (fs)
		*mnt = xstrdup(mnt_fs_get_target(fs));
	return *mnt ? 0 : -1;
}