1''' 2llfuse.pxy 3 4Copyright © 2013 Nikolaus Rath <Nikolaus.org> 5 6This file is part of Python-LLFUSE. This work may be distributed under 7the terms of the GNU LGPL. 8''' 9 10cdef extern from "llfuse.h": 11 int PLATFORM 12 enum: 13 PLATFORM_LINUX 14 PLATFORM_BSD 15 PLATFORM_DARWIN 16 17########### 18# C IMPORTS 19########### 20 21from fuse_lowlevel cimport * 22from pthread cimport * 23from posix.stat cimport struct_stat, S_IFMT, S_IFDIR, S_IFREG 24from posix.types cimport mode_t, dev_t, off_t 25from libc.stdint cimport uint32_t 26from libc.stdlib cimport const_char 27from libc cimport stdlib, string, errno, dirent 28from libc.errno cimport ETIMEDOUT, EPROTO, EINVAL, EPERM, ENOMSG, ENOATTR 29from posix.unistd cimport getpid 30from posix.time cimport timespec 31from posix.signal cimport (sigemptyset, sigaddset, SIG_BLOCK, SIG_SETMASK, 32 siginfo_t, sigaction_t, sigaction, SA_SIGINFO) 33from cpython.bytes cimport (PyBytes_AsStringAndSize, PyBytes_FromStringAndSize, 34 PyBytes_AsString, PyBytes_FromString, PyBytes_AS_STRING) 35from cpython.buffer cimport (PyObject_GetBuffer, PyBuffer_Release, 36 PyBUF_CONTIG_RO, PyBUF_CONTIG) 37cimport cpython.exc 38cimport cython 39from cpython.version cimport PY_MAJOR_VERSION 40from libc cimport signal 41 42 43###################### 44# EXTERNAL DEFINITIONS 45###################### 46 47cdef extern from "lock.h" nogil: 48 int acquire(double timeout) nogil 49 int release() nogil 50 int c_yield(int count) nogil 51 int init_lock() nogil 52 53cdef extern from "macros.c" nogil: 54 long GET_BIRTHTIME(struct_stat* buf) 55 long GET_ATIME_NS(struct_stat* buf) 56 long GET_CTIME_NS(struct_stat* buf) 57 long GET_MTIME_NS(struct_stat* buf) 58 long GET_BIRTHTIME_NS(struct_stat* buf) 59 60 void SET_BIRTHTIME(struct_stat* buf, long val) 61 void SET_ATIME_NS(struct_stat* buf, long val) 62 void SET_CTIME_NS(struct_stat* buf, long val) 63 void SET_MTIME_NS(struct_stat* buf, long val) 64 void SET_BIRTHTIME_NS(struct_stat* buf, long val) 65 66 void ASSIGN_DARWIN(void*, void*) 67 void ASSIGN_NOT_DARWIN(void*, void*) 68 69 enum: 70 NOTIFY_INVAL_INODE 71 NOTIFY_INVAL_ENTRY 72 73cdef extern from "xattr.h" nogil: 74 int setxattr_p (char *path, char *name, 75 void *value, int size, int namespace) 76 77 ssize_t getxattr_p (char *path, char *name, 78 void *value, int size, int namespace) 79 80 enum: 81 EXTATTR_NAMESPACE_SYSTEM 82 EXTATTR_NAMESPACE_USER 83 XATTR_CREATE 84 XATTR_REPLACE 85 XATTR_NOFOLLOW 86 XATTR_NODEFAULT 87 XATTR_NOSECURITY 88 89cdef extern from "gettime.h" nogil: 90 int gettime_realtime(timespec *tp) 91 92cdef extern from *: 93 # Missing in the Cython provided libc/errno.pxd: 94 enum: 95 EDEADLK 96 97cdef extern from "Python.h" nogil: 98 void PyEval_InitThreads() 99 int PY_SSIZE_T_MAX 100 101# Actually passed as -D to cc (and defined in setup.py) 102cdef extern from *: 103 char* LLFUSE_VERSION 104 105################ 106# PYTHON IMPORTS 107################ 108 109import os 110import logging 111import sys 112import os.path 113import threading 114from pickle import PicklingError 115 116if PY_MAJOR_VERSION < 3: 117 from Queue import Queue 118 import contextlib2 as contextlib 119 str_t = bytes 120else: 121 from queue import Queue 122 str_t = str 123 import contextlib 124 125################## 126# GLOBAL VARIABLES 127################## 128 129log = logging.getLogger("llfuse") 130fse = sys.getfilesystemencoding() 131 132cdef object operations 133cdef object mountpoint_b 134cdef fuse_session* session = NULL 135cdef fuse_chan* channel = NULL 136cdef fuse_lowlevel_ops fuse_ops 137cdef object exc_info 138cdef int exit_reason 139cdef pthread_mutex_t exc_info_mutex 140 141init_lock() 142lock = Lock.__new__(Lock) 143lock_released = NoLockManager.__new__(NoLockManager) 144 145cdef object _notify_queue 146_notify_queue = Queue(maxsize=1000) 147 148# Exported for access from Python code 149# (in the Cython source, we want ENOATTR to refer 150# to the C constant, not a Python object) 151ROOT_INODE = FUSE_ROOT_ID 152__version__ = LLFUSE_VERSION.decode('utf-8') 153globals()['ENOATTR'] = ENOATTR 154 155####################### 156# FUSE REQUEST HANDLERS 157####################### 158 159include "operations.pxi" 160include "handlers.pxi" 161 162#################### 163# INTERNAL FUNCTIONS 164#################### 165 166include "misc.pxi" 167 168#################### 169# FUSE API FUNCTIONS 170#################### 171 172include "fuse_api.pxi" 173