2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPL.
6 See the file COPYING.LIB.
10 #include "fuse_lowlevel.h"
20 struct fuse_chan
*prevch
;
21 struct fuse_session
*prevse
;
22 fuse_processor_t proc
;
26 static void mt_session_proc(void *data
, const char *buf
, size_t len
,
29 struct procdata
*pd
= (struct procdata
*) data
;
30 struct fuse_cmd
*cmd
= *(struct fuse_cmd
**) buf
;
34 pd
->proc(pd
->f
, cmd
, pd
->data
);
37 static void mt_session_exit(void *data
, int val
)
39 struct procdata
*pd
= (struct procdata
*) data
;
41 fuse_session_exit(pd
->prevse
);
43 fuse_session_reset(pd
->prevse
);
46 static int mt_session_exited(void *data
)
48 struct procdata
*pd
= (struct procdata
*) data
;
49 return fuse_session_exited(pd
->prevse
);
52 static int mt_chan_receive(struct fuse_chan
**chp
, char *buf
, size_t size
)
55 struct procdata
*pd
= (struct procdata
*) fuse_chan_data(*chp
);
57 assert(size
>= sizeof(cmd
));
59 cmd
= fuse_read_cmd(pd
->f
);
63 *(struct fuse_cmd
**) buf
= cmd
;
68 static int mt_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[],
71 struct procdata
*pd
= (struct procdata
*) fuse_chan_data(ch
);
72 return fuse_chan_send(pd
->prevch
, iov
, count
);
75 int fuse_loop_mt_proc(struct fuse
*f
, fuse_processor_t proc
, void *data
)
79 struct fuse_session
*prevse
= fuse_get_session(f
);
80 struct fuse_session
*se
;
81 struct fuse_chan
*prevch
= fuse_session_next_chan(prevse
, NULL
);
83 struct fuse_session_ops sop
= {
84 .exit
= mt_session_exit
,
85 .exited
= mt_session_exited
,
86 .process
= mt_session_proc
,
88 struct fuse_chan_ops cop
= {
89 .receive
= mt_chan_receive
,
99 se
= fuse_session_new(&sop
, &pd
);
103 ch
= fuse_chan_new(&cop
, fuse_chan_fd(prevch
), sizeof(struct fuse_cmd
*),
106 fuse_session_destroy(se
);
109 fuse_session_add_chan(se
, ch
);
110 res
= fuse_session_loop_mt(se
);
111 fuse_session_destroy(se
);
115 int fuse_loop_mt(struct fuse
*f
)
120 return fuse_session_loop_mt(fuse_get_session(f
));
123 __asm__(".symver fuse_loop_mt_proc,__fuse_loop_mt@");