summaryrefslogtreecommitdiff
path: root/lib/fuse_lowlevel.c
diff options
context:
space:
mode:
authorZim <zezeozue@google.com>2019-11-09 07:09:39 +0000
committerZim <zezeozue@google.com>2019-11-09 09:05:39 +0000
commitc4a783b4356f5340de28e5f5f54b7e6f5a8164f8 (patch)
tree2266ef295e53b754c75570a830cba11af37391d2 /lib/fuse_lowlevel.c
parenta7f7e5f075a360cde99ebe4a5360447a3339fda2 (diff)
Update to libfuse 3.8.0
The latest release allows a custom logger Bug: 135341433 Test: adb shell ls /sdcard with persist.sys.fuse Change-Id: Iaa8a2bb7b6da3f364fba41b443527a998a26549f
Diffstat (limited to 'lib/fuse_lowlevel.c')
-rw-r--r--lib/fuse_lowlevel.c123
1 files changed, 74 insertions, 49 deletions
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index b9f128f..f2d7038 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -150,7 +150,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_session *se)
req = (struct fuse_req *) calloc(1, sizeof(struct fuse_req));
if (req == NULL) {
- fprintf(stderr, "fuse: failed to allocate request\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate request\n");
} else {
req->se = se;
req->ctr = 1;
@@ -170,15 +170,15 @@ static int fuse_send_msg(struct fuse_session *se, struct fuse_chan *ch,
out->len = iov_length(iov, count);
if (se->debug) {
if (out->unique == 0) {
- fprintf(stderr, "NOTIFY: code=%d length=%u\n",
+ fuse_log(FUSE_LOG_DEBUG, "NOTIFY: code=%d length=%u\n",
out->error, out->len);
} else if (out->error) {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_DEBUG,
" unique: %llu, error: %i (%s), outsize: %i\n",
(unsigned long long) out->unique, out->error,
strerror(-out->error), out->len);
} else {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_DEBUG,
" unique: %llu, success, outsize: %i\n",
(unsigned long long) out->unique, out->len);
}
@@ -207,7 +207,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
struct fuse_out_header out;
if (error <= -1000 || error > 0) {
- fprintf(stderr, "fuse: bad error value: %i\n", error);
+ fuse_log(FUSE_LOG_ERR, "fuse: bad error value: %i\n", error);
error = -ERANGE;
}
@@ -285,7 +285,7 @@ size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
dirent->off = off;
dirent->namelen = namelen;
dirent->type = (stbuf->st_mode & S_IFMT) >> 12;
- strncpy(dirent->name, name, namelen);
+ memcpy(dirent->name, name, namelen);
memset(dirent->name + namelen, 0, entlen_padded - entlen);
return entlen_padded;
@@ -378,7 +378,7 @@ size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
dirent->off = off;
dirent->namelen = namelen;
dirent->type = (e->attr.st_mode & S_IFMT) >> 12;
- strncpy(dirent->name, name, namelen);
+ memcpy(dirent->name, name, namelen);
memset(dirent->name + namelen, 0, entlen_padded - entlen);
return entlen_padded;
@@ -601,11 +601,11 @@ static int read_back(int fd, char *buf, size_t len)
res = read(fd, buf, len);
if (res == -1) {
- fprintf(stderr, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
+ fuse_log(FUSE_LOG_ERR, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
return -EIO;
}
if (res != len) {
- fprintf(stderr, "fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
+ fuse_log(FUSE_LOG_ERR, "fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
return -EIO;
}
return 0;
@@ -714,7 +714,7 @@ static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
if (res != headerlen) {
res = -EIO;
- fprintf(stderr, "fuse: short vmsplice to pipe: %u/%zu\n", res,
+ fuse_log(FUSE_LOG_ERR, "fuse: short vmsplice to pipe: %u/%zu\n", res,
headerlen);
goto clear_pipe;
}
@@ -807,7 +807,7 @@ static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
out->len = headerlen + len;
if (se->debug) {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_DEBUG,
" unique: %llu, success, outsize: %i (splice)\n",
(unsigned long long) out->unique, out->len);
}
@@ -826,7 +826,7 @@ static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
}
if (res != out->len) {
res = -EIO;
- fprintf(stderr, "fuse: short splice from pipe: %u/%u\n",
+ fuse_log(FUSE_LOG_ERR, "fuse: short splice from pipe: %u/%u\n",
res, out->len);
goto clear_pipe;
}
@@ -1065,6 +1065,16 @@ int fuse_reply_poll(fuse_req_t req, unsigned revents)
return send_reply_ok(req, &arg, sizeof(arg));
}
+int fuse_reply_lseek(fuse_req_t req, off_t off)
+{
+ struct fuse_lseek_out arg;
+
+ memset(&arg, 0, sizeof(arg));
+ arg.offset = off;
+
+ return send_reply_ok(req, &arg, sizeof(arg));
+}
+
static void do_lookup(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
{
char *name = (char *) inarg;
@@ -1396,7 +1406,7 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
sizeof(struct fuse_write_in);
}
if (bufv.buf[0].size < arg->size) {
- fprintf(stderr, "fuse: do_write_buf: buffer size too small\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: do_write_buf: buffer size too small\n");
fuse_reply_err(req, EIO);
goto out;
}
@@ -1724,7 +1734,7 @@ static void do_interrupt(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
(void) nodeid;
if (se->debug)
- fprintf(stderr, "INTERRUPT: %llu\n",
+ fuse_log(FUSE_LOG_DEBUG, "INTERRUPT: %llu\n",
(unsigned long long) arg->unique);
req->u.i.unique = arg->unique;
@@ -1867,6 +1877,20 @@ static void do_copy_file_range(fuse_req_t req, fuse_ino_t nodeid_in, const void
fuse_reply_err(req, ENOSYS);
}
+static void do_lseek(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
+{
+ struct fuse_lseek_in *arg = (struct fuse_lseek_in *) inarg;
+ struct fuse_file_info fi;
+
+ memset(&fi, 0, sizeof(fi));
+ fi.fh = arg->fh;
+
+ if (req->se->op.lseek)
+ req->se->op.lseek(req, nodeid, arg->offset, arg->whence, &fi);
+ else
+ fuse_reply_err(req, ENOSYS);
+}
+
static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
{
struct fuse_init_in *arg = (struct fuse_init_in *) inarg;
@@ -1877,10 +1901,10 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
(void) nodeid;
if (se->debug) {
- fprintf(stderr, "INIT: %u.%u\n", arg->major, arg->minor);
+ fuse_log(FUSE_LOG_DEBUG, "INIT: %u.%u\n", arg->major, arg->minor);
if (arg->major == 7 && arg->minor >= 6) {
- fprintf(stderr, "flags=0x%08x\n", arg->flags);
- fprintf(stderr, "max_readahead=0x%08x\n",
+ fuse_log(FUSE_LOG_DEBUG, "flags=0x%08x\n", arg->flags);
+ fuse_log(FUSE_LOG_DEBUG, "max_readahead=0x%08x\n",
arg->max_readahead);
}
}
@@ -1894,7 +1918,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
outarg.minor = FUSE_KERNEL_MINOR_VERSION;
if (arg->major < 7) {
- fprintf(stderr, "fuse: unsupported protocol version: %u.%u\n",
+ fuse_log(FUSE_LOG_ERR, "fuse: unsupported protocol version: %u.%u\n",
arg->major, arg->minor);
fuse_reply_err(req, EPROTO);
return;
@@ -1991,7 +2015,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
se->conn.time_gran = 1;
if (bufsize < FUSE_MIN_READ_BUFFER) {
- fprintf(stderr, "fuse: warning: buffer size too small: %zu\n",
+ fuse_log(FUSE_LOG_ERR, "fuse: warning: buffer size too small: %zu\n",
bufsize);
bufsize = FUSE_MIN_READ_BUFFER;
}
@@ -2005,7 +2029,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
se->op.init(se->userdata, &se->conn);
if (se->conn.want & (~se->conn.capable)) {
- fprintf(stderr, "fuse: error: filesystem requested capabilities "
+ fuse_log(FUSE_LOG_ERR, "fuse: error: filesystem requested capabilities "
"0x%x that are not supported by kernel, aborting.\n",
se->conn.want & (~se->conn.capable));
fuse_reply_err(req, EPROTO);
@@ -2016,7 +2040,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
unsigned max_read_mo = get_max_read(se->mo);
if (se->conn.max_read != max_read_mo) {
- fprintf(stderr, "fuse: error: init() and fuse_session_new() "
+ fuse_log(FUSE_LOG_ERR, "fuse: error: init() and fuse_session_new() "
"requested different maximum read size (%u vs %u)\n",
se->conn.max_read, max_read_mo);
fuse_reply_err(req, EPROTO);
@@ -2080,16 +2104,16 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
outarg.time_gran = se->conn.time_gran;
if (se->debug) {
- fprintf(stderr, " INIT: %u.%u\n", outarg.major, outarg.minor);
- fprintf(stderr, " flags=0x%08x\n", outarg.flags);
- fprintf(stderr, " max_readahead=0x%08x\n",
+ fuse_log(FUSE_LOG_DEBUG, " INIT: %u.%u\n", outarg.major, outarg.minor);
+ fuse_log(FUSE_LOG_DEBUG, " flags=0x%08x\n", outarg.flags);
+ fuse_log(FUSE_LOG_DEBUG, " max_readahead=0x%08x\n",
outarg.max_readahead);
- fprintf(stderr, " max_write=0x%08x\n", outarg.max_write);
- fprintf(stderr, " max_background=%i\n",
+ fuse_log(FUSE_LOG_DEBUG, " max_write=0x%08x\n", outarg.max_write);
+ fuse_log(FUSE_LOG_DEBUG, " max_background=%i\n",
outarg.max_background);
- fprintf(stderr, " congestion_threshold=%i\n",
+ fuse_log(FUSE_LOG_DEBUG, " congestion_threshold=%i\n",
outarg.congestion_threshold);
- fprintf(stderr, " time_gran=%u\n",
+ fuse_log(FUSE_LOG_DEBUG, " time_gran=%u\n",
outarg.time_gran);
}
if (arg->minor < 5)
@@ -2326,7 +2350,7 @@ static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq,
sizeof(struct fuse_notify_retrieve_in);
if (bufv.buf[0].size < arg->size) {
- fprintf(stderr, "fuse: retrieve reply: buffer size too small\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: retrieve reply: buffer size too small\n");
fuse_reply_none(req);
goto out;
}
@@ -2471,6 +2495,7 @@ static struct {
[FUSE_READDIRPLUS] = { do_readdirplus, "READDIRPLUS"},
[FUSE_RENAME2] = { do_rename2, "RENAME2" },
[FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" },
+ [FUSE_LSEEK] = { do_lseek, "LSEEK" },
[CUSE_INIT] = { cuse_lowlevel_init, "CUSE_INIT" },
};
@@ -2489,11 +2514,11 @@ static int fuse_ll_copy_from_pipe(struct fuse_bufvec *dst,
{
ssize_t res = fuse_buf_copy(dst, src, 0);
if (res < 0) {
- fprintf(stderr, "fuse: copy from pipe: %s\n", strerror(-res));
+ fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: %s\n", strerror(-res));
return res;
}
if ((size_t)res < fuse_buf_size(dst)) {
- fprintf(stderr, "fuse: copy from pipe: short read\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: short read\n");
return -1;
}
return 0;
@@ -2525,7 +2550,7 @@ void fuse_session_process_buf_int(struct fuse_session *se,
mbuf = malloc(tmpbuf.buf[0].size);
if (mbuf == NULL) {
- fprintf(stderr, "fuse: failed to allocate header\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate header\n");
goto clear_pipe;
}
tmpbuf.buf[0].mem = mbuf;
@@ -2540,7 +2565,7 @@ void fuse_session_process_buf_int(struct fuse_session *se,
}
if (se->debug) {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_DEBUG,
"unique: %llu, opcode: %s (%i), nodeid: %llu, insize: %zu, pid: %u\n",
(unsigned long long) in->unique,
opname((enum fuse_opcode) in->opcode), in->opcode,
@@ -2757,7 +2782,7 @@ int fuse_session_receive_buf_int(struct fuse_session *se, struct fuse_buf *buf,
}
if (res < sizeof(struct fuse_in_header)) {
- fprintf(stderr, "short splice from fuse device\n");
+ fuse_log(FUSE_LOG_ERR, "short splice from fuse device\n");
return -EIO;
}
@@ -2780,7 +2805,7 @@ int fuse_session_receive_buf_int(struct fuse_session *se, struct fuse_buf *buf,
if (!buf->mem) {
buf->mem = malloc(se->bufsize);
if (!buf->mem) {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_ERR,
"fuse: failed to allocate read buffer\n");
return -ENOMEM;
}
@@ -2791,13 +2816,13 @@ int fuse_session_receive_buf_int(struct fuse_session *se, struct fuse_buf *buf,
res = fuse_buf_copy(&dst, &src, 0);
if (res < 0) {
- fprintf(stderr, "fuse: copy from pipe: %s\n",
+ fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: %s\n",
strerror(-res));
fuse_ll_clear_pipe(se);
return res;
}
if (res < tmpbuf.size) {
- fprintf(stderr, "fuse: copy from pipe: short read\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: short read\n");
fuse_ll_clear_pipe(se);
return -EIO;
}
@@ -2817,7 +2842,7 @@ fallback:
if (!buf->mem) {
buf->mem = malloc(se->bufsize);
if (!buf->mem) {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_ERR,
"fuse: failed to allocate read buffer\n");
return -ENOMEM;
}
@@ -2849,7 +2874,7 @@ restart:
return -err;
}
if ((size_t) res < sizeof(struct fuse_in_header)) {
- fprintf(stderr, "short read on fuse device\n");
+ fuse_log(FUSE_LOG_ERR, "short read on fuse device\n");
return -EIO;
}
@@ -2867,18 +2892,18 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
struct mount_opts *mo;
if (sizeof(struct fuse_lowlevel_ops) < op_size) {
- fprintf(stderr, "fuse: warning: library too old, some operations may not work\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: warning: library too old, some operations may not work\n");
op_size = sizeof(struct fuse_lowlevel_ops);
}
if (args->argc == 0) {
- fprintf(stderr, "fuse: empty argv passed to fuse_session_new().\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: empty argv passed to fuse_session_new().\n");
return NULL;
}
se = (struct fuse_session *) calloc(1, sizeof(struct fuse_session));
if (se == NULL) {
- fprintf(stderr, "fuse: failed to allocate fuse object\n");
+ fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate fuse object\n");
goto out1;
}
se->fd = -1;
@@ -2904,19 +2929,19 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
if(args->argc == 1 &&
args->argv[0][0] == '-') {
- fprintf(stderr, "fuse: warning: argv[0] looks like an option, but "
+ fuse_log(FUSE_LOG_ERR, "fuse: warning: argv[0] looks like an option, but "
"will be ignored\n");
} else if (args->argc != 1) {
int i;
- fprintf(stderr, "fuse: unknown option(s): `");
+ fuse_log(FUSE_LOG_ERR, "fuse: unknown option(s): `");
for(i = 1; i < args->argc-1; i++)
- fprintf(stderr, "%s ", args->argv[i]);
- fprintf(stderr, "%s'\n", args->argv[i]);
+ fuse_log(FUSE_LOG_ERR, "%s ", args->argv[i]);
+ fuse_log(FUSE_LOG_ERR, "%s'\n", args->argv[i]);
goto out4;
}
if (se->debug)
- fprintf(stderr, "FUSE library version: %s\n", PACKAGE_VERSION);
+ fuse_log(FUSE_LOG_DEBUG, "FUSE library version: %s\n", PACKAGE_VERSION);
se->bufsize = FUSE_MAX_MAX_PAGES * getpagesize() +
FUSE_BUFFER_HEADER_SIZE;
@@ -2929,7 +2954,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
if (err) {
- fprintf(stderr, "fuse: failed to create thread specific key: %s\n",
+ fuse_log(FUSE_LOG_ERR, "fuse: failed to create thread specific key: %s\n",
strerror(err));
goto out5;
}
@@ -2976,7 +3001,7 @@ int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
fd = fuse_mnt_parse_fuse_fd(mountpoint);
if (fd != -1) {
if (fcntl(fd, F_GETFD) == -1) {
- fprintf(stderr,
+ fuse_log(FUSE_LOG_ERR,
"fuse: Invalid file descriptor /dev/fd/%u\n",
fd);
return -1;