2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB.
10 #include "fuse_misc.h"
11 #include "fuse_lowlevel.h"
21 struct fuse_chan
*prevch
;
22 struct fuse_session
*prevse
;
23 fuse_processor_t proc
;
27 static void mt_session_proc(void *data
, const char *buf
, size_t len
,
30 struct procdata
*pd
= (struct procdata
*) data
;
31 struct fuse_cmd
*cmd
= *(struct fuse_cmd
**) buf
;
35 pd
->proc(pd
->f
, cmd
, pd
->data
);
38 static void mt_session_exit(void *data
, int val
)
40 struct procdata
*pd
= (struct procdata
*) data
;
42 fuse_session_exit(pd
->prevse
);
44 fuse_session_reset(pd
->prevse
);
47 static int mt_session_exited(void *data
)
49 struct procdata
*pd
= (struct procdata
*) data
;
50 return fuse_session_exited(pd
->prevse
);
53 static int mt_chan_receive(struct fuse_chan
**chp
, char *buf
, size_t size
)
56 struct procdata
*pd
= (struct procdata
*) fuse_chan_data(*chp
);
58 assert(size
>= sizeof(cmd
));
60 cmd
= fuse_read_cmd(pd
->f
);
64 *(struct fuse_cmd
**) buf
= cmd
;
69 int fuse_loop_mt_proc(struct fuse
*f
, fuse_processor_t proc
, void *data
)
73 struct fuse_session
*prevse
= fuse_get_session(f
);
74 struct fuse_session
*se
;
75 struct fuse_chan
*prevch
= fuse_session_next_chan(prevse
, NULL
);
77 struct fuse_session_ops sop
= {
78 .exit
= mt_session_exit
,
79 .exited
= mt_session_exited
,
80 .process
= mt_session_proc
,
82 struct fuse_chan_ops cop
= {
83 .receive
= mt_chan_receive
,
92 se
= fuse_session_new(&sop
, &pd
);
96 ch
= fuse_chan_new(&cop
, fuse_chan_fd(prevch
),
97 sizeof(struct fuse_cmd
*), &pd
);
99 fuse_session_destroy(se
);
102 fuse_session_add_chan(se
, ch
);
103 res
= fuse_session_loop_mt(se
);
104 fuse_session_destroy(se
);
108 int fuse_loop_mt(struct fuse
*f
)
113 return fuse_session_loop_mt(fuse_get_session(f
));
116 FUSE_SYMVER(".symver fuse_loop_mt_proc,__fuse_loop_mt@");