1111 Copyright (C) 2006-2007 Csaba Henk <csaba.henk@creo.hu>
1212*/
1313
14+ /*
15+ * Local Variables:
16+ * indent-tabs-mode: t
17+ * c-basic-offset: 8
18+ * End:
19+ * Changed by David McNab (david@rebirthing.co.nz) to work with recent pythons.
20+ * Namely, replacing PyTuple_* with PySequence_*, and checking numerical values
21+ * with both PyInt_Check and PyLong_Check.
22+ */
23+
1424#ifndef FUSE_VERSION
1525#ifndef FUSE_MAKE_VERSION
1626#define FUSE_MAKE_VERSION (maj , min ) ((maj) * 10 + (min))
@@ -33,7 +43,8 @@ static PyObject *getattr_cb=NULL, *readlink_cb=NULL, *readdir_cb=NULL,
3343 * statfs_cb = NULL , * fsync_cb = NULL , * create_cb = NULL , * opendir_cb = NULL ,
3444 * releasedir_cb = NULL , * fsyncdir_cb = NULL , * flush_cb = NULL , * ftruncate_cb = NULL ,
3545 * fgetattr_cb = NULL , * getxattr_cb = NULL , * listxattr_cb = NULL , * setxattr_cb = NULL ,
36- * removexattr_cb = NULL , * access_cb = NULL , * fsinit_cb = NULL , * fsdestroy_cb = NULL ;
46+ * removexattr_cb = NULL , * access_cb = NULL , * lock_cb = NULL , * fsinit_cb = NULL ,
47+ * fsdestroy_cb = NULL ;
3748
3849static PyObject * Py_FuseError ;
3950static PyInterpreterState * interp ;
@@ -161,16 +172,6 @@ fi_to_py(struct fuse_file_info *fi)
161172#define fetchattr (st , attr ) \
162173 fetchattr_nam(st, attr, #attr)
163174
164- /*
165- * Local Variables:
166- * indent-tabs-mode: t
167- * c-basic-offset: 8
168- * End:
169- * Changed by David McNab (david@rebirthing.co.nz) to work with recent pythons.
170- * Namely, replacing PyTuple_* with PySequence_*, and checking numerical values
171- * with both PyInt_Check and PyLong_Check.
172- */
173-
174175#define fetchattr_soft (st , attr ) \
175176 pytmp = PyObject_GetAttrString(v, #attr); \
176177 if (pytmp == Py_None) { \
@@ -181,6 +182,11 @@ fi_to_py(struct fuse_file_info *fi)
181182 py2attr(st, attr); \
182183 }
183184
185+ /*
186+ * Following macros are only for getattr-alikes, we undef them after
187+ * the getattr type functions.
188+ */
189+
184190#define fetchattr_soft_d (st , attr , defa ) \
185191 fetchattr_soft(st, attr) else st->attr = defa
186192
@@ -243,7 +249,6 @@ fgetattr_func(const char *path, struct stat *st, struct fuse_file_info *fi)
243249}
244250#endif
245251
246- #undef fetchattr_soft
247252#undef fetchattr_soft_d
248253#undef FETCH_STAT_DATA
249254
@@ -776,6 +781,55 @@ fsdestroy_func(void *param)
776781}
777782#endif
778783
784+ static inline PyObject *
785+ lock_func_i (const char * path , struct fuse_file_info * fi , int cmd ,
786+ struct flock * lock )
787+ {
788+ PyObject * pyargs , * pykw = NULL , * v = NULL ;
789+
790+ pyargs =
791+ fi_to_py (fi ) ?
792+ Py_BuildValue ("(siKO)" , path , cmd , fi -> lock_owner , fi_to_py (fi )) :
793+ Py_BuildValue ("(siK)" , path , cmd , fi -> lock_owner );
794+ if (! pyargs )
795+ goto out ;
796+
797+ pykw = Py_BuildValue ("{sisKsKsi}" ,
798+ "l_type" , lock -> l_type ,
799+ "l_start" , lock -> l_start ,
800+ "l_len" , lock -> l_len ,
801+ "l_pid" , lock -> l_pid );
802+ if (! pykw )
803+ goto out ;
804+
805+ v = PyObject_Call (lock_cb , pyargs , pykw );
806+
807+ out :
808+ Py_XDECREF (pyargs );
809+ Py_XDECREF (pykw );
810+
811+ return v ;
812+ }
813+
814+ static int
815+ lock_func (const char * path , struct fuse_file_info * fi , int cmd ,
816+ struct flock * lock )
817+ {
818+ PyObject * pytmp ;
819+ unsigned long long ctmp ;
820+
821+ PROLOGUE ( lock_func_i (path , fi , cmd , lock ) )
822+
823+ fetchattr_soft (lock , l_type );
824+ fetchattr_soft (lock , l_start );
825+ fetchattr_soft (lock , l_len );
826+ fetchattr_soft (lock , l_pid );
827+
828+ ret = 0 ;
829+
830+ EPILOGUE
831+ }
832+
779833static int
780834pyfuse_loop_mt (struct fuse * f )
781835{
@@ -817,14 +871,14 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
817871 "open" , "read" , "write" , "release" , "statfs" , "fsync" ,
818872 "create" , "opendir" , "releasedir" , "fsyncdir" , "flush" ,
819873 "ftruncate" , "fgetattr" , "getxattr" , "listxattr" , "setxattr" ,
820- "removexattr" , "access" , "fsinit " , "fsdestroy " , "fuse_args " ,
821- "multithreaded" , NULL
874+ "removexattr" , "access" , "lock " , "fsinit " , "fsdestroy " ,
875+ "fuse_args" , " multithreaded" , NULL
822876 };
823877
824878 memset (& op , 0 , sizeof (op ));
825879
826880 if (!PyArg_ParseTupleAndKeywords (args , kw ,
827- "|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOi " ,
881+ "|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOi " ,
828882 kwlist , & getattr_cb , & readlink_cb ,
829883 & readdir_cb , & mknod_cb , & mkdir_cb ,
830884 & unlink_cb , & rmdir_cb , & symlink_cb ,
@@ -837,7 +891,7 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
837891 & flush_cb , & ftruncate_cb ,
838892 & fgetattr_cb , & getxattr_cb ,
839893 & listxattr_cb , & setxattr_cb ,
840- & removexattr_cb , & access_cb ,
894+ & removexattr_cb , & access_cb , & lock_cb ,
841895 & fsinit_cb , & fsdestroy_cb ,
842896 & fargseq , & multithreaded ))
843897 return NULL ;
@@ -890,6 +944,9 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
890944 DO_ONE_ATTR (access );
891945 DO_ONE_ATTR (create );
892946#endif
947+ #if FUSE_VERSION >= 26
948+ DO_ONE_ATTR (lock );
949+ #endif
893950#if FUSE_VERSION >= 23
894951 DO_ONE_ATTR_AS (init , fsinit );
895952 DO_ONE_ATTR_AS (destroy , fsdestroy );
0 commit comments