Codebase list python-fuse / 77cf25f
New upstream version 1.0.0 Sébastien Delafond 4 years ago
8 changed file(s) with 135 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
00 build
11 dist
22 fuse_python.egg-info
3 __pycache__
4 *.pyc
5 *.so
1010
1111 hello.py by Andrew Straw <strawman@astraw.com>
1212 threading related code cleaned up by Miklos Szeredi <miklos@szeredi.hu>
13 IOCTL support by Cédric Carrée
13 IOCTL support by Cédric Carrée
14 poll support by David Lechner <david@lechnology.com>
9595
9696 def __init__(self, *args, **kw):
9797 Fuse.__init__(self, *args, **kw)
98 self.buf = ""
98 self.buf = b""
9999
100100 def resize(self, new_size):
101101 old_size = len(self.buf)
105105 if new_size < old_size:
106106 self.buf = self.buf[0:new_size]
107107 else:
108 self.buf = self.buf + "\x00" * (new_size - old_size)
108 self.buf = self.buf + b"\x00" * (new_size - old_size)
109109
110110 return 0
111111
2121 fuse.fuse_python_api = (0, 2)
2222
2323 hello_path = '/hello'
24 hello_str = 'Hello World!\n'
24 hello_str = b'Hello World!\n'
2525
2626 class MyStat(fuse.Stat):
2727 def __init__(self):
7171 size = slen - offset
7272 buf = hello_str[offset:offset+size]
7373 else:
74 buf = ''
74 buf = b''
7575 return buf
7676
7777 def main():
2828
2929
3030 def flag2mode(flags):
31 md = {os.O_RDONLY: 'r', os.O_WRONLY: 'w', os.O_RDWR: 'w+'}
31 md = {os.O_RDONLY: 'rb', os.O_WRONLY: 'wb', os.O_RDWR: 'wb+'}
3232 m = md[flags & (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)]
3333
3434 if flags | os.O_APPEND:
2222 from os import environ
2323 import re
2424 from fuseparts import __version__
25 from fuseparts._fuse import main, FuseGetContext, FuseInvalidate
25 from fuseparts._fuse import main, FuseGetContext, FuseInvalidate, FuseNotifyPoll
2626 from fuseparts._fuse import FuseError, FuseAPIVersion
2727 from fuseparts.subbedopts import SubOptsHive, SubbedOptFormatter
2828 from fuseparts.subbedopts import SubbedOptIndentedFormatter, SubbedOptParse
644644 'statfs', 'fsync', 'create', 'opendir', 'releasedir', 'fsyncdir',
645645 'flush', 'fgetattr', 'ftruncate', 'getxattr', 'listxattr',
646646 'setxattr', 'removexattr', 'access', 'lock', 'utimens', 'bmap',
647 'fsinit', 'fsdestroy', 'ioctl']
647 'fsinit', 'fsdestroy', 'ioctl', 'poll']
648648
649649 fusage = "%prog [mountpoint] [options]"
650650
791791
792792 def Invalidate(self, path):
793793 return FuseInvalidate(self, path)
794
795 def NotifyPoll(self, pollhandle):
796 return FuseNotifyPoll(pollhandle)
794797
795798 def fuseoptref(cls):
796799 """
0 __version__ = "0.3.1"
0 __version__ = "1.0.0"
2727 #include <Python.h>
2828 #include <fuse.h>
2929 #include <sys/ioctl.h>
30 #ifndef _UAPI_ASM_GENERIC_IOCTL_H
31 /* Essential IOCTL definitions from Linux /include/uapi/asm-generic/ioctl.h
32 to fix compilation errors on FreeBSD
33 Mikhail Zakharov <zmey20000@thoo.com> 2018.10.22 */
34
35 #define _IOC_NRBITS 8
36 #define _IOC_TYPEBITS 8
37
38 #ifndef _IOC_SIZEBITS
39 # define _IOC_SIZEBITS 14
40 #endif
41
42 #ifndef _IOC_DIRBITS
43 # define _IOC_DIRBITS 2
44 #endif
45
46 #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
47 #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
48
49 #define _IOC_NRSHIFT 0
50 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
51 #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
52 #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
53
54 #ifndef _IOC_NONE
55 # define _IOC_NONE 0U
56 #endif
57
58 #ifndef _IOC_WRITE
59 # define _IOC_WRITE 1U
60 #endif
61
62 #ifndef _IOC_READ
63 # define _IOC_READ 2U
64 #endif
65
66 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
67 #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
68 #endif
3069
3170
3271 #ifndef FUSE_VERSION
5796 *releasedir_cb=NULL, *fsyncdir_cb=NULL, *flush_cb=NULL, *ftruncate_cb=NULL,
5897 *fgetattr_cb=NULL, *getxattr_cb=NULL, *listxattr_cb=NULL, *setxattr_cb=NULL,
5998 *removexattr_cb=NULL, *access_cb=NULL, *lock_cb = NULL, *utimens_cb = NULL,
60 *bmap_cb = NULL, *fsinit_cb=NULL, *fsdestroy_cb = NULL, *ioctl_cb = NULL;
99 *bmap_cb = NULL, *fsinit_cb=NULL, *fsdestroy_cb = NULL, *ioctl_cb = NULL,
100 *poll_cb = NULL;
61101
62102
63103 static PyObject *Py_FuseError;
516556 PROLOGUE( PYO_CALLWITHFI(fi, read_cb, snK, path, s, off) )
517557 #endif
518558
559
560 #if PY_MAJOR_VERSION >= 3
561 if(PyBytes_Check(v)) {
562 if(PyBytes_Size(v) > s)
563 goto OUT_DECREF;
564 memcpy(buf, PyBytes_AsString(v), PyBytes_Size(v));
565 ret = PyBytes_Size(v);
566 }
567 #else
519568 if(PyString_Check(v)) {
520569 if(PyString_Size(v) > s)
521570 goto OUT_DECREF;
522571 memcpy(buf, PyString_AsString(v), PyString_Size(v));
523572 ret = PyString_Size(v);
524573 }
574 #endif
525575
526576 EPILOGUE
527577 }
535585 write_func(const char *path, const char *buf, size_t t, off_t off)
536586 #endif
537587 {
588 #if PY_MAJOR_VERSION >= 3
589 PROLOGUE( PYO_CALLWITHFI(fi, write_cb, sy#K, path, buf, t, off) )
590 #else
538591 PROLOGUE( PYO_CALLWITHFI(fi, write_cb, ss#K, path, buf, t, off) )
592 #endif
539593 EPILOGUE
540594 }
541595
9901044 }
9911045 EPILOGUE
9921046 }
1047
1048 static const char pollhandle_name[] = "pollhandle";
1049
1050 static void
1051 pollhandle_destructor(PyObject *p)
1052 {
1053 struct fuse_pollhandle *ph;
1054
1055 ph = PyCapsule_GetPointer(p, pollhandle_name);
1056 fuse_pollhandle_destroy(ph);
1057 }
1058
1059 static int
1060 poll_func(const char *path, struct fuse_file_info *fi,
1061 struct fuse_pollhandle *ph, unsigned *reventsp)
1062 {
1063 PyObject *pollhandle = Py_None;
1064
1065 if (ph)
1066 pollhandle = PyCapsule_New(ph, pollhandle_name, pollhandle_destructor);
1067
1068 PROLOGUE(PYO_CALLWITHFI(fi, poll_cb, sO, path, pollhandle));
1069
1070 OUT_DECREF:
1071 Py_DECREF(v);
1072 OUT:
1073 if (ph)
1074 Py_DECREF(pollhandle);
1075
1076 PYUNLOCK();
1077
1078 if (ret > 0) {
1079 *reventsp = ret;
1080 ret = 0;
1081 }
1082
1083 return ret;
1084 }
9931085 #endif
9941086
9951087 static int
10351127 "create", "opendir", "releasedir", "fsyncdir", "flush",
10361128 "ftruncate", "fgetattr", "getxattr", "listxattr", "setxattr",
10371129 "removexattr", "access", "lock", "utimens", "bmap",
1038 "fsinit", "fsdestroy", "ioctl", "fuse_args", "multithreaded", NULL
1130 "fsinit", "fsdestroy", "ioctl", "poll", "fuse_args",
1131 "multithreaded", NULL
10391132 };
10401133
10411134 memset(&op, 0, sizeof(op));
10421135
10431136 if (!PyArg_ParseTupleAndKeywords(args, kw,
1044 "|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOi",
1137 "|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOi",
10451138 kwlist, &getattr_cb, &readlink_cb,
10461139 &readdir_cb, &mknod_cb, &mkdir_cb,
10471140 &unlink_cb, &rmdir_cb, &symlink_cb,
10571150 &removexattr_cb, &access_cb,
10581151 &lock_cb, &utimens_cb, &bmap_cb,
10591152 &fsinit_cb, &fsdestroy_cb, &ioctl_cb,
1060 &fargseq, &multithreaded))
1153 &poll_cb, &fargseq, &multithreaded))
10611154 return NULL;
10621155
10631156 #define DO_ONE_ATTR_AS(fname, pyname) \
11191212 #endif
11201213 #if FUSE_VERSION >= 28
11211214 DO_ONE_ATTR(ioctl);
1215 DO_ONE_ATTR(poll);
11221216 #endif
11231217
11241218 #undef DO_ONE_ATTR
12811375 return favers;
12821376 }
12831377
1378 static const char FuseNotifyPoll__doc__[] = "Notify IO readiness event.";
1379
1380 static PyObject *
1381 FuseNotifyPoll(PyObject *self, PyObject *arg)
1382 {
1383 struct fuse_pollhandle *ph;
1384 int ret;
1385
1386 ph = PyCapsule_GetPointer(arg, pollhandle_name);
1387 if (!ph) {
1388 PyErr_SetString(PyExc_TypeError,
1389 "pollhandle is not a FUSE poll handle");
1390 return NULL;
1391 }
1392
1393 ret = fuse_notify_poll(ph);
1394
1395 return PyInt_FromLong(ret);
1396 }
1397
12841398 static PyMethodDef Fuse_methods[] = {
12851399 {"main", (PyCFunction)Fuse_main, METH_VARARGS|METH_KEYWORDS},
12861400 {"FuseGetContext", (PyCFunction)FuseGetContext, METH_VARARGS, FuseGetContext__doc__},
12871401 {"FuseInvalidate", (PyCFunction)FuseInvalidate, METH_VARARGS, FuseInvalidate__doc__},
12881402 {"FuseAPIVersion", (PyCFunction)FuseAPIVersion, METH_NOARGS, FuseAPIVersion__doc__},
1403 {"FuseNotifyPoll", (PyCFunction)FuseNotifyPoll, METH_O, FuseNotifyPoll__doc__},
12891404 {NULL, NULL} /* sentinel */
12901405 };
12911406