diff options
author | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-02 21:22:02 -0700 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-02 21:24:43 -0700 |
commit | b082a001c7b11e3cf1d1b53470cb229284bc61cd (patch) | |
tree | 3fc9db1eb1295a61e099ec451e6664228341168f /lib/fuse_lowlevel.c | |
parent | ba12a8f7e315950e840e942de8c2d36dc78dddf7 (diff) | |
download | libfuse-b082a001c7b11e3cf1d1b53470cb229284bc61cd.tar.gz |
Merged fuse_session.c into fuse_lowlevel.c
This distinction no longer makes sens. fuse_lowlevel.c already contains
several session related functions, and fuse_session.c contains various
stuff that is more related to the channel interface.
Diffstat (limited to 'lib/fuse_lowlevel.c')
-rw-r--r-- | lib/fuse_lowlevel.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index 8ccc733..368ac71 100644 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -3055,3 +3055,97 @@ int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]) return -ENOSYS; } #endif + +void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch) +{ + assert(se->ch == NULL); + assert(ch->se == NULL); + se->ch = ch; + ch->se = se; +} + +void fuse_session_remove_chan(struct fuse_chan *ch) +{ + struct fuse_session *se = ch->se; + if (se) { + assert(se->ch == ch); + se->ch = NULL; + ch->se = NULL; + } +} + +struct fuse_chan *fuse_session_chan(struct fuse_session *se) +{ + return se->ch; +} + +int fuse_chan_clearfd(struct fuse_chan *ch) +{ + int fd = ch->fd; + ch->fd = -1; + return fd; +} + +void fuse_session_exit(struct fuse_session *se) +{ + se->exited = 1; +} + +void fuse_session_reset(struct fuse_session *se) +{ + se->exited = 0; +} + +int fuse_session_exited(struct fuse_session *se) +{ + return se->exited; +} + +struct fuse_chan *fuse_chan_new(int fd) +{ + struct fuse_chan *ch = (struct fuse_chan *) malloc(sizeof(*ch)); + if (ch == NULL) { + fprintf(stderr, "fuse: failed to allocate channel\n"); + return NULL; + } + + memset(ch, 0, sizeof(*ch)); + ch->fd = fd; + ch->ctr = 1; + fuse_mutex_init(&ch->lock); + + return ch; +} + +struct fuse_session *fuse_chan_session(struct fuse_chan *ch) +{ + return ch->se; +} + +struct fuse_chan *fuse_chan_get(struct fuse_chan *ch) +{ + assert(ch->ctr > 0); + pthread_mutex_lock(&ch->lock); + ch->ctr++; + pthread_mutex_unlock(&ch->lock); + + return ch; +} + +void fuse_chan_put(struct fuse_chan *ch) +{ + if (ch) { + pthread_mutex_lock(&ch->lock); + ch->ctr--; + if (!ch->ctr) { + pthread_mutex_unlock(&ch->lock); + fuse_session_remove_chan(ch); + fuse_chan_close(ch); + pthread_mutex_destroy(&ch->lock); + free(ch); + } else { + pthread_mutex_unlock(&ch->lock); + } + + } +} |