コード例 #1
0
ファイル: hello_ll.c プロジェクト: nuxleus/Nuxleus.Extf
int main(int argc, char *argv[])
{
    struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
    char *mountpoint;
    int err = -1;
    int fd;

    if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 &&
        (fd = fuse_mount(mountpoint, &args)) != -1) {
        struct fuse_session *se;

        se = fuse_lowlevel_new(&args, &hello_ll_oper, sizeof(hello_ll_oper),
                               NULL);
        if (se != NULL) {
            if (fuse_set_signal_handlers(se) != -1) {
                struct fuse_chan *ch = fuse_kern_chan_new(fd);
                if (ch != NULL) {
                    fuse_session_add_chan(se, ch);
                    err = fuse_session_loop(se);
                }
                fuse_remove_signal_handlers(se);
            }
            fuse_session_destroy(se);
        }
        close(fd);
    }
    fuse_unmount(mountpoint);
    fuse_opt_free_args(&args);

    return err ? 1 : 0;
}
コード例 #2
0
static struct fuse_chan *fuse_mount_common(const char *mountpoint,
					   struct fuse_args *args)
{
	struct fuse_chan *ch;
	int fd;

	/*
	 * Make sure file descriptors 0, 1 and 2 are open, otherwise chaos
	 * would ensue.
	 */
	do {
		fd = open("/dev/null", O_RDWR);
		if (fd > 2)
			close(fd);
	} while (fd >= 0 && fd <= 2);

	fd = fuse_mount_compat25(mountpoint, args);
	if (fd == -1)
		return NULL;

	ch = fuse_kern_chan_new(fd);
	if (!ch)
		fuse_kern_unmount(mountpoint, fd);

	return ch;
}
コード例 #3
0
// Do a mount for helper_thread()
static void helper_thread_mount(mount_t * m)
{
	Dprintf("%s(\"%s\")\n", __FUNCTION__, m->fstitch_path);

	if ((m->channel_fd = fuse_mount(m->mountpoint, &m->args)) == -1)
	{
		fprintf(stderr, "%s(): fuse_mount(\"%s\") failed. (Does the mountpoint exist?)\n", __FUNCTION__, m->mountpoint);
		return;
	}

	if (!(m->session = fuse_lowlevel_new(&m->args, ops, ops_len, m)))
	{
		fprintf(stderr, "%s(): fuse_lowlevel_new() failed\n", __FUNCTION__);
		return;
	}

	if (!(m->channel = fuse_kern_chan_new(m->channel_fd)))
	{
		fprintf(stderr, "%s(): fuse_kern_chan_new() failed\n", __FUNCTION__);
		return;
	}

	fuse_session_add_chan(m->session, m->channel);

	if (fuse_chan_bufsize(m->channel) != fuse_serve_mount_chan_bufsize())
		fprintf(stderr, "bufsizes differ!\n");

	m->mounted = 1;

	printf("Mounted \"%s\" from %s\n", m->fstitch_path, modman_name_cfs(m->cfs));
}
コード例 #4
0
static int mount_root(int argc, char ** argv)
{
	Dprintf("%s()\n", __FUNCTION__);

	if (!(root = calloc(1, sizeof(*root))))
		return -ENOMEM;

	// We can't use FUSE_ARGS_INIT() here so assert we are initing the
	// whole structure
	static_assert(sizeof(root->args) == sizeof(argc) + sizeof(argv) + sizeof(int));
	root->args.argc = argc;
	root->args.argv = argv;
	root->args.allocated = 0;

	if (!(root->fstitch_path = strdup("")))
		return -ENOMEM;

	if (!(root->parents = hash_map_create()))
		return -ENOMEM;

	root->cfs = NULL; // set later via fuse_serve_mount_set_root()

	if (fuse_parse_cmdline(&root->args, &root->mountpoint, NULL, NULL) == -1)
	{
		fprintf(stderr, "%s(): fuse_parse_cmdline() failed\n", __FUNCTION__);
		return -1;
	}

	if ((root->channel_fd = fuse_mount(root->mountpoint, &root->args)) == -1)
	{
		fprintf(stderr, "%s():%d: fuse_mount(\"%s\") failed\n", __FUNCTION__, __LINE__, root->mountpoint);
		return -1;
	}

	if (!(root->session = fuse_lowlevel_new(&root->args, ops, ops_len, root)))
	{
		fprintf(stderr, "%s(): fuse_lowlevel_new() failed\n", __FUNCTION__);
		return -1;
	}

	if (!(root->channel = fuse_kern_chan_new(root->channel_fd)))
	{
		fprintf(stderr, "%s(): fuse_kern_chan_new() failed\n", __FUNCTION__);
		return -1;
	}

	fuse_session_add_chan(root->session, root->channel);

	mounts_insert(root);

	root->mounted = 1;

	return 0;
}
コード例 #5
0
ファイル: ll.c プロジェクト: ksperling/squashfuse
static sqfs_err sqfs_ll_mount(sqfs_ll_chan *ch, const char *mountpoint,
		struct fuse_args *args) {
	#ifdef HAVE_NEW_FUSE_UNMOUNT
		ch->ch = fuse_mount(mountpoint, args);
	#else
		ch->fd = fuse_mount(mountpoint, args);
		if (ch->fd == -1)
			return SQFS_ERR;
		ch->ch = fuse_kern_chan_new(ch->fd);
	#endif
	return ch->ch ? SQFS_OK : SQFS_ERR;
}
コード例 #6
0
ファイル: helper.c プロジェクト: rolivia/OS-Project
static struct fuse_chan *fuse_mount_common(const char *mountpoint,
                                           struct fuse_args *args)
{
    struct fuse_chan *ch;
    int fd = fuse_mount_compat25(mountpoint, args);
    if (fd == -1)
        return NULL;

    ch = fuse_kern_chan_new(fd);
    if (!ch)
        fuse_kern_unmount(mountpoint, fd);

    return ch;
}
コード例 #7
0
struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[],
					 const struct cuse_info *ci,
					 const struct cuse_lowlevel_ops *clop,
					 int *multithreaded, void *userdata)
{
	const char *devname = "/dev/cuse";
	static const struct fuse_opt kill_subtype_opts[] = {
		FUSE_OPT_KEY("subtype=",  FUSE_OPT_KEY_DISCARD),
		FUSE_OPT_END
	};
	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
	struct fuse_session *se;
	struct fuse_chan *ch;
	int fd;
	int foreground;
	int res;

	res = fuse_parse_cmdline(&args, NULL, multithreaded, &foreground);
	if (res == -1)
		goto err_args;

	res = fuse_opt_parse(&args, NULL, kill_subtype_opts, NULL);
	if (res == -1)
		goto err_args;

	/*
	 * Make sure file descriptors 0, 1 and 2 are open, otherwise chaos
	 * would ensue.
	 */
	do {
		fd = open("/dev/null", O_RDWR);
		if (fd > 2)
			close(fd);
	} while (fd >= 0 && fd <= 2);

	se = cuse_lowlevel_new(&args, ci, clop, userdata);
	fuse_opt_free_args(&args);
	if (se == NULL)
		goto err_args;

	fd = open(devname, O_RDWR);
	if (fd == -1) {
		if (errno == ENODEV || errno == ENOENT)
			fprintf(stderr, "cuse: device not found, try 'modprobe cuse' first\n");
		else
			fprintf(stderr, "cuse: failed to open %s: %s\n",
				devname, strerror(errno));
		goto err_se;
	}

	ch = fuse_kern_chan_new(fd);
	if (!ch) {
		close(fd);
		goto err_se;
	}

	fuse_session_add_chan(se, ch);

	res = fuse_set_signal_handlers(se);
	if (res == -1)
		goto err_se;

	res = fuse_daemonize(foreground);
	if (res == -1)
		goto err_sig;

	return se;

err_sig:
	fuse_remove_signal_handlers(se);
err_se:
	fuse_session_destroy(se);
err_args:
	fuse_opt_free_args(&args);
	return NULL;
}