示例#1
0
static int check_is_root(const char *object)
{
	int ret;
	u8 fsid[BTRFS_FSID_SIZE];
	u8 fsid2[BTRFS_FSID_SIZE];
	char *tmp = NULL;
	char *rp;

	rp = realpath(object, NULL);
	if (!rp) {
		ret = -errno;
		goto out;
	}
	if (!strcmp(rp, "/")) {
		ret = 0;
		goto out;
	}

	tmp = malloc(strlen(object) + 5);
	if (!tmp) {
		ret = -ENOMEM;
		goto out;
	}
	strcpy(tmp, object);
	if (tmp[strlen(tmp) - 1] != '/')
		strcat(tmp, "/");
	strcat(tmp, "..");

	ret = get_fsid(object, fsid, 0);
	if (ret < 0) {
		errno = -ret;
		error("get_fsid for %s failed: %m", object);
		goto out;
	}

	ret = get_fsid(tmp, fsid2, 1);
	if (ret == -ENOTTY) {
		ret = 0;
		goto out;
	} else if (ret == -ENOTDIR) {
		ret = 1;
		goto out;
	} else if (ret < 0) {
		errno = -ret;
		error("get_fsid for %s failed: %m", tmp);
		goto out;
	}

	if (memcmp(fsid, fsid2, BTRFS_FSID_SIZE)) {
		ret = 0;
		goto out;
	}

	ret = 1;

out:
	free(tmp);
	free(rp);
	return ret;
}
示例#2
0
static int check_is_root(const char *object)
{
	int ret;
	u8 fsid[BTRFS_FSID_SIZE];
	u8 fsid2[BTRFS_FSID_SIZE];
	char *tmp;

	tmp = malloc(strlen(object) + 5);
	if (!tmp) {
		ret = -ENOMEM;
		goto out;
	}
	strcpy(tmp, object);
	if (tmp[strlen(tmp) - 1] != '/')
		strcat(tmp, "/");
	strcat(tmp, "..");

	ret = get_fsid(object, fsid, 0);
	if (ret < 0) {
		fprintf(stderr, "ERROR: get_fsid for %s failed. %s\n", object,
				strerror(-ret));
		goto out;
	}

	ret = get_fsid(tmp, fsid2, 1);
	if (ret == -ENOTTY) {
		ret = 0;
		goto out;
	} else if (ret == -ENOTDIR) {
		ret = 1;
		goto out;
	} else if (ret < 0) {
		fprintf(stderr, "ERROR: get_fsid for %s failed. %s\n", tmp,
			strerror(-ret));
		goto out;
	}

	if (memcmp(fsid, fsid2, BTRFS_FSID_SIZE)) {
		ret = 0;
		goto out;
	}

	ret = 1;

out:
	free(tmp);
	return ret;
}
static int check_btrfs_object(const char *object)
{
	int ret;
	u8 fsid[BTRFS_FSID_SIZE];

	ret = get_fsid(object, fsid, 0);
	if (ret < 0)
		ret = 0;
	else
		ret = 1;
	return ret;
}
示例#4
0
static int zfsfuse_share(
	sa_handle_t libzfs_sharehdl,
	sa_group_t group, sa_share_t share, char *mountpoint,
	char  *prot, zprop_source_t sourcetype,
	char *shareopts, char *sourcestr, char *zfs_name) {
    if (!strcmp(prot,"nfs")) {
	char buff[2048];
	int fsid = get_fsid(mountpoint);
	if (strcmp(shareopts,"on")) {
	    /* handle shareopts
	     * the new syntax should be
	     * host1:options host2:options ... */
	    char *s = shareopts-1;
	    int ret = SA_OK;
	    while (s = strchr(s+1,':')) {
		*s = 0;
		char *hostname = shareopts;
		char opts[1024];
		char *e = strchr(s+1,' ');
		if (e) *e = 0;
		strcpy(opts,s+1);
		if (*opts == 0)
		    strcpy(opts,"ro");
		if (!strstr(opts,"fsid="))
		    sprintf(&opts[strlen(opts)],",fsid=%d",fsid);
		if (!strstr(opts,"subtree_check"))
		    strcat(opts,",no_subtree_check");
		sprintf(buff,"exportfs -o %s '%s:%s'",opts,hostname,mountpoint);
		if (system(buff) != 0) {
		    printf("%s returned an error\n",buff);
		    ret = SA_CONFIG_ERR;
		}
		if (e) {
		    do {
			e++;
		    } while (*e == ' ');
		    s = shareopts = e;
		} else
		    break;
	    }
	    return ret;
	} 
	sprintf(buff,"exportfs -o fsid=%d,no_subtree_check '*:%s'",fsid,mountpoint);
	int ret = system(buff);
	if (ret == 0) return SA_OK;
	printf("%s -> %d\n",buff,ret);
	return SA_CONFIG_ERR;
    }
    printf("protocol %s not supported yet\n",prot);
    return SA_CONFIG_ERR;
}