예제 #1
0
파일: utils.c 프로젝트: yaccz/util-linux
static int get_filesystems(const char *filename, char ***filesystems, const char *pattern)
{
	int rc = 0;
	FILE *f;
	char line[128];

	f = fopen(filename, "r");
	if (!f)
		return 1;

	DBG(UTILS, mnt_debug("reading filesystems list from: %s", filename));

	while (fgets(line, sizeof(line), f)) {
		char name[sizeof(line)];

		if (*line == '#' || strncmp(line, "nodev", 5) == 0)
			continue;
		if (sscanf(line, " %128[^\n ]\n", name) != 1)
			continue;
		if (strcmp(name, "*") == 0) {
			rc = 1;
			break;		/* end of the /etc/filesystems */
		}
		if (pattern && !mnt_match_fstype(name, pattern))
			continue;
		rc = add_filesystem(filesystems, name);
		if (rc)
			break;
	}

	fclose(f);
	return rc;
}
예제 #2
0
파일: utils.c 프로젝트: yaccz/util-linux
int test_match_fstype(struct libmnt_test *ts, int argc, char *argv[])
{
	char *type = argv[1];
	char *pattern = argv[2];

	printf("%s\n", mnt_match_fstype(type, pattern) ? "MATCH" : "NOT-MATCH");
	return 0;
}
예제 #3
0
파일: fs.c 프로젝트: tcdog001/autelan
/**
 * mnt_fs_match_fstype:
 * @fs: filesystem
 * @types: filesystem name or comma delimited list of filesystems
 *
 * For more details see mnt_match_fstype().
 *
 * Returns: 1 if @fs type is matching to @types else 0. The function returns
 * 0 when types is NULL.
 */
int mnt_fs_match_fstype(mnt_fs *fs, const char *types)
{
	return mnt_match_fstype(fs->fstype, types);
}
예제 #4
0
static int umount_main(struct libmnt_context *cxt, int argc, char **argv)
{
	int rc, c;
	char *spec = NULL, *opts = NULL;
	int ret = EX_FAIL;

	static const struct option longopts[] = {
		{ "force", 0, 0, 'f' },
		{ "help", 0, 0, 'h' },
		{ "no-mtab", 0, 0, 'n' },
		{ "verbose", 0, 0, 'v' },
		{ "read-only", 0, 0, 'r' },
		{ "lazy", 0, 0, 'l' },
		{ "types", 1, 0, 't' },
		{ NULL, 0, 0, 0 }
	};

	mnt_context_init_helper(cxt, MNT_ACT_UMOUNT, 0);

	while ((c = getopt_long (argc, argv, "fvnrlh", longopts, NULL)) != -1) {

		rc = mnt_context_helper_setopt(cxt, c, optarg);
		if (rc == 0)		/* valid option */
			continue;
		if (rc < 0)		/* error (probably ENOMEM) */
			goto err;
					/* rc==1 means unknow option */
		umount_usage();
		return EX_USAGE;
	}

	if (optind < argc)
		spec = argv[optind++];

	if (!spec || (*spec != '/' && strchr(spec,':') == NULL)) {
		nfs_error(_("%s: no mount point provided"), progname);
		return EX_USAGE;
	}

	if (mnt_context_set_target(cxt, spec))
		goto err;

	/* read mtab/fstab, evaluate permissions, etc. */
	rc = mnt_context_prepare_umount(cxt);
	if (rc) {
		nfs_error(_("%s: failed to prepare umount: %s\n"),
					progname, strerror(-rc));
		goto err;
	}

	if (mnt_context_get_fstype(cxt) &&
	    !mnt_match_fstype(mnt_context_get_fstype(cxt), "nfs,nfs4")) {

		nfs_error(_("%s: %s: is not an NFS filesystem"), progname, spec);
		ret = EX_USAGE;
		goto err;
	}

	opts = retrieve_mount_options(mnt_context_get_fs(cxt));

	if (!mnt_context_is_lazy(cxt)) {
		if (opts) {
			/* we have full FS description (e.g. from mtab or /proc) */
			switch (is_vers4(cxt)) {
			case 0:
				/* We ignore the error from nfs_umount23.
				 * If the actual umount succeeds (in del_mtab),
				 * we don't want to signal an error, as that
				 * could cause /sbin/mount to retry!
				 */
				nfs_umount23(mnt_context_get_source(cxt), opts);
				break;
			case 1:			/* unknown */
				break;
			default:		/* error */
				goto err;
			}
		} else
			/* strange, no entry in mtab or /proc not mounted */
			nfs_umount23(spec, "tcp,v3");
	}

	ret = EX_FILEIO;
	rc = mnt_context_do_umount(cxt);	/* call umount(2) syscall */
	mnt_context_finalize_mount(cxt);	/* mtab update */

	if (rc && !mnt_context_get_status(cxt)) {
		/* mnt_context_do_umount() returns errno if umount(2) failed */
		umount_error(rc, spec);
		goto err;
	}
	ret = EX_SUCCESS;
err:
	free(opts);
	return ret;
}