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_lowlevel.h"
11 #include "fuse_lowlevel_compat.h"
20 struct fuse_session_ops op
;
30 struct fuse_chan_ops op
;
32 struct fuse_session
*se
;
41 struct fuse_session
*fuse_session_new(struct fuse_session_ops
*op
, void *data
)
43 struct fuse_session
*se
= (struct fuse_session
*) malloc(sizeof(*se
));
45 fprintf(stderr
, "fuse: failed to allocate session\n");
49 memset(se
, 0, sizeof(*se
));
56 void fuse_session_add_chan(struct fuse_session
*se
, struct fuse_chan
*ch
)
58 assert(se
->ch
== NULL
);
59 assert(ch
->se
== NULL
);
64 void fuse_session_remove_chan(struct fuse_chan
*ch
)
66 struct fuse_session
*se
= ch
->se
;
74 struct fuse_chan
*fuse_session_next_chan(struct fuse_session
*se
,
77 assert(ch
== NULL
|| ch
== se
->ch
);
84 void fuse_session_process(struct fuse_session
*se
, const char *buf
, size_t len
,
87 se
->op
.process(se
->data
, buf
, len
, ch
);
90 void fuse_session_destroy(struct fuse_session
*se
)
93 se
->op
.destroy(se
->data
);
95 fuse_chan_destroy(se
->ch
);
99 void fuse_session_exit(struct fuse_session
*se
)
102 se
->op
.exit(se
->data
, 1);
106 void fuse_session_reset(struct fuse_session
*se
)
109 se
->op
.exit(se
->data
, 0);
113 int fuse_session_exited(struct fuse_session
*se
)
116 return se
->op
.exited(se
->data
);
121 static struct fuse_chan
*fuse_chan_new_common(struct fuse_chan_ops
*op
, int fd
,
122 size_t bufsize
, void *data
)
124 struct fuse_chan
*ch
= (struct fuse_chan
*) malloc(sizeof(*ch
));
126 fprintf(stderr
, "fuse: failed to allocate channel\n");
130 memset(ch
, 0, sizeof(*ch
));
133 ch
->bufsize
= bufsize
;
139 struct fuse_chan
*fuse_chan_new(struct fuse_chan_ops
*op
, int fd
,
140 size_t bufsize
, void *data
)
142 return fuse_chan_new_common(op
, fd
, bufsize
, data
);
145 int fuse_chan_fd(struct fuse_chan
*ch
)
150 size_t fuse_chan_bufsize(struct fuse_chan
*ch
)
155 void *fuse_chan_data(struct fuse_chan
*ch
)
160 struct fuse_session
*fuse_chan_session(struct fuse_chan
*ch
)
165 int fuse_chan_recv(struct fuse_chan
**chp
, char *buf
, size_t size
)
167 struct fuse_chan
*ch
= *chp
;
169 return ch
->op
.receive(chp
, buf
, size
);
173 int fuse_chan_receive(struct fuse_chan
*ch
, char *buf
, size_t size
)
177 res
= fuse_chan_recv(&ch
, buf
, size
);
178 return res
>= 0 ? res
: (res
!= -EINTR
&& res
!= -EAGAIN
) ? -1 : 0;
180 #endif /* __SOLARIS__ */
182 int fuse_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[], size_t count
)
184 return ch
->op
.send(ch
, iov
, count
);
187 void fuse_chan_destroy(struct fuse_chan
*ch
)
189 fuse_session_remove_chan(ch
);