Ejemplo n.º 1
0
/* reallocates its first arg */
char *append_opt(char *s, const char *opt, const char *val)
{
	if (!opt)
		return s;
	if (!s) {
		if (!val)
			return xstrdup(opt);		/* opt */

		return xstrconcat3(NULL, opt, val);	/* opt=val */
	}
	if (!val)
		return xstrconcat3(s, ",", opt);	/* s,opt */

	return xstrconcat4(s, ",", opt, val);		/* s,opt=val */
}
Ejemplo n.º 2
0
static void parse_options(int argc, char *argv[], struct mount_options *opts)
{
	int c, show_version_only = 0;

	while ((c = getopt(argc, argv, "fvnt:o:rwV")) != EOF) {
		switch (c) {
		case 'f':
			fake++;
			break;
		case 'v':
			verbose++;
			break;
		case 'n':
			nomtab++;
			break;
		case 't':
			opts->fstype = optarg;
			break;
		case 'o':
			if (opts->opts)
				opts->opts = xstrconcat3(opts->opts, ",",
							 optarg);
			else
				opts->opts = xstrdup(optarg);
			break;
		case 'r':
			readonly++;
			break;
		case 'w':
			readwrite++;
			break;
		case 'V':
			show_version_only++;
			break;
		default:
			break;
		}
	}

	if (show_version_only) {
		show_version();
		exit(0);
	}

	parse_opts(opts->opts, &opts->flags, &opts->extra_opts);
}
Ejemplo n.º 3
0
/*
 * For local mounts, add heartbeat=none.
 * For userspace clusterstack, add cluster_stack=xxxx.
 * For o2cb with local heartbeat, add heartbeat=local.
 * For o2cb with global heartbeat, add heartbeat=global.
 */
static errcode_t add_mount_options(ocfs2_filesys *fs,
				   struct o2cb_cluster_desc *cluster,
				   char **optstr)
{
	char *add, *extra = NULL;
	char stackstr[strlen(OCFS2_CLUSTER_STACK_ARG) + OCFS2_STACK_LABEL_LEN + 1];
	struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);

	if (ocfs2_mount_local(fs) || ocfs2_is_hard_readonly(fs)) {
		add = OCFS2_HB_NONE;
		goto addit;
	}

	if (cluster->c_stack &&
	    strcmp(cluster->c_stack, OCFS2_CLASSIC_CLUSTER_STACK)) {
		snprintf(stackstr, sizeof(stackstr), "%s%s",
			 OCFS2_CLUSTER_STACK_ARG, cluster->c_stack);
		add = stackstr;
		goto addit;
	}

	if (ocfs2_cluster_o2cb_global_heartbeat(sb)) {
		add = OCFS2_HB_GLOBAL;
		goto addit;
	}

	add = OCFS2_HB_LOCAL;

addit:
	if (*optstr && *(*optstr))
		extra = xstrconcat3(*optstr, ",", add);
	else
		extra = xstrndup(add, strlen(add));

	if (!extra)
		return OCFS2_ET_NO_MEMORY;

	*optstr = extra;

	return 0;
}
Ejemplo n.º 4
0
/**
 * Program entry point
 *
 * @param argc count of command line arguments
 * @param argv array of NUL-terminated C strings containing command line arguments
 * @return program exit status
 */
int main(int argc, char *argv[])
{
	char *source, *target, *text_options;
	int c, mnt_err;

	(void)setlocale(LC_ALL, "");

	progname = basename(argv[0]);

	if (argv[1] && argv[1][0] == '-') {
		if(argv[1][1] == 'V')
			printf("%s ("PACKAGE_STRING")\n", progname);
		else
			mount_usage();
		exit(EX_SUCCESS);
	}

	if (argc < 3) {
		mount_usage();
		exit(EX_USAGE);
	}

	source = argv[1];
	target = argv[2];

	mnt_err = EX_USAGE;
	text_options = NULL;
	readonly = false;
	sloppy = false;
	fake = false;
	argv[2] = argv[0]; /* so that getopt error messages are correct */
	while ((c = getopt_long(argc - 2, argv + 2, fedfs_opts,
				fedfs_longopts, NULL)) != -1) {
		switch (c) {
		case 'f':
			fake = true;
			break;
		case 'n':
			++nomtab;
			break;
		case 'o':
			/* Ugh. */
			if (text_options != NULL)
				text_options = xstrconcat3(text_options, ",", optarg);
			else
				text_options = strdup(optarg);
			if (text_options == NULL) {
				fprintf(stderr, _("%s: No memory\n"), progname);
				goto out;
			}
			break;
		case 'r':
			readonly = true;
			break;
		case 's':
			sloppy = true;
			break;
		case 'v':
			++verbose;
			break;
		case 'V':
			printf("%s: ("PACKAGE_STRING")\n", progname);
			mnt_err = EX_SUCCESS;
			goto out;
		case 'w':
			readonly = false;
			break;
		case 'h':
		default:
			mount_usage();
			goto out;
		}
	}

	/* Extra non-option words at the end are bogus...  */
	if (optind != argc - 2) {
		mount_usage();
		goto out;
	}

	if (getuid() != 0 && geteuid() != 0) {
		fprintf(stderr, _("%s: Not installed setuid - "
			    "\"user\" FedFS mounts are not supported\n"), progname);
		mnt_err = EX_FAIL;
		goto out;
	}

	mnt_err = try_mount(source, target, text_options);

out:
	free(text_options);
	exit(mnt_err);
}