Skip to content

Commit

Permalink
Added write_buf handler
Browse files Browse the repository at this point in the history
Fixes issue libfuse#15.

--HG--
extra : rebase_source : 93f3297384cbeb267e6744bf3950086f5a23b38d
extra : amend_source : 48751816f440353c633fff37e99bed52d339d01f
extra : histedit_source : 4868081666a2fdc05537c6c01e694ce94e7bf80c%2Ce15d95112226542e5e6924877a0c2f45e8d54da6
  • Loading branch information
Nikratio committed Sep 4, 2015
1 parent c4a2c68 commit 852d975
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/handlers.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,24 @@ cdef void fuse_write (fuse_req_t req, fuse_ino_t ino, const_char *buf,
if ret != 0:
log.error('fuse_write(): fuse_reply_* failed with %s', strerror(-ret))

cdef void fuse_write_buf(fuse_req_t req, fuse_ino_t ino, fuse_bufvec *bufv,
off_t off, fuse_file_info *fi) with gil:
cdef int ret
cdef size_t len_

try:
buf = PyBytes_from_bufvec(bufv)
with lock:
len_ = operations.write(fi.fh, off, buf)
ret = fuse_reply_write(req, len_)
except FUSEError as e:
ret = fuse_reply_err(req, e.errno)
except:
ret = handle_exc(req)

if ret != 0:
log.error('fuse_write_buf(): fuse_reply_* failed with %s', strerror(-ret))

cdef void fuse_flush (fuse_req_t req, fuse_ino_t ino, fuse_file_info *fi) with gil:
cdef int ret

Expand Down
2 changes: 1 addition & 1 deletion src/llfuse.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ from posix.time cimport clock_gettime, CLOCK_REALTIME, timespec
from cpython.bytes cimport (PyBytes_AsStringAndSize, PyBytes_FromStringAndSize,
PyBytes_AsString, PyBytes_FromString)
from cpython.buffer cimport (PyObject_GetBuffer, PyBuffer_Release,
PyBUF_CONTIG_RO)
PyBUF_CONTIG_RO, PyBUF_CONTIG)
cimport cpython.exc
cimport cython
from cpython.version cimport PY_MAJOR_VERSION
Expand Down
29 changes: 28 additions & 1 deletion src/misc.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ cdef void init_fuse_ops():
fuse_ops.removexattr = fuse_removexattr
fuse_ops.access = fuse_access
fuse_ops.create = fuse_create

ASSIGN_FUSE29(fuse_ops.forget_multi, &fuse_forget_multi)
ASSIGN_FUSE29(fuse_ops.write_buf, &fuse_write_buf)

cdef make_fuse_args(args, fuse_args* f_args):
cdef char* arg
Expand Down Expand Up @@ -514,3 +514,30 @@ cdef class NotifyRequest:
cdef char attr_only
cdef object name
cdef int kind

cdef PyBytes_from_bufvec(fuse_bufvec *src):
cdef Py_buffer pybuf
cdef fuse_bufvec dst
cdef size_t len_
cdef ssize_t res

len_ = fuse_buf_size(src) - src.off
buf = bytearray(len_)
PyObject_GetBuffer(buf, &pybuf, PyBUF_CONTIG)
try:
dst.count = 1
dst.idx = 0
dst.off = 0
dst.buf[0].mem = pybuf.buf
dst.buf[0].size = len_
dst.buf[0].flags = 0
res = fuse_buf_copy(&dst, src, 0)
if res < 0:
raise OSError(errno.errno, 'fuse_buf_copy failed with '
+ strerror(errno.errno))
elif <size_t> res < len_:
return memoryview(buf)[:-len_]
else:
return buf
finally:
PyBuffer_Release(&pybuf)

0 comments on commit 852d975

Please sign in to comment.