Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU LGPL. |
| 6 | See the file COPYING.LIB |
| 7 | */ |
| 8 | |
| 9 | #include "fuse_lowlevel.h" |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
Miklos Szeredi | 5d9ce36 | 2006-03-01 12:10:13 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 14 | |
| 15 | int fuse_session_loop(struct fuse_session *se) |
| 16 | { |
| 17 | int res = 0; |
| 18 | struct fuse_chan *ch = fuse_session_next_chan(se, NULL); |
| 19 | size_t bufsize = fuse_chan_bufsize(ch); |
| 20 | char *buf = (char *) malloc(bufsize); |
| 21 | if (!buf) { |
| 22 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
| 23 | return -1; |
| 24 | } |
| 25 | |
| 26 | while (!fuse_session_exited(se)) { |
Miklos Szeredi | 8d975f6 | 2006-03-17 15:56:05 +0000 | [diff] [blame] | 27 | struct fuse_chan *tmpch = ch; |
| 28 | res = fuse_chan_recv(&tmpch, buf, bufsize); |
Miklos Szeredi | 5d9ce36 | 2006-03-01 12:10:13 +0000 | [diff] [blame] | 29 | if (res == -EINTR) |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 30 | continue; |
Miklos Szeredi | 5d9ce36 | 2006-03-01 12:10:13 +0000 | [diff] [blame] | 31 | if (res <= 0) |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 32 | break; |
Miklos Szeredi | 8d975f6 | 2006-03-17 15:56:05 +0000 | [diff] [blame] | 33 | fuse_session_process(se, buf, res, tmpch); |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | free(buf); |
| 37 | fuse_session_reset(se); |
Miklos Szeredi | 5d9ce36 | 2006-03-01 12:10:13 +0000 | [diff] [blame] | 38 | return res < 0 ? -1 : 0; |
Miklos Szeredi | a148242 | 2005-08-14 23:00:27 +0000 | [diff] [blame] | 39 | } |