github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/lib/python/fusepy/low-level/llfuse/operations.py (about) 1 ''' 2 $Id: operations.py 47 2010-01-29 17:11:23Z nikratio $ 3 4 Copyright (c) 2010, Nikolaus Rath <Nikolaus@rath.org> 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 8 9 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 * Neither the name of the main author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 ''' 15 16 from __future__ import division, print_function, absolute_import 17 18 from .interface import FUSEError 19 import errno 20 21 class Operations(object): 22 ''' 23 This is a dummy class that just documents the possible methods that 24 a file system may declare. 25 ''' 26 27 # This is a dummy class, so all the methods could of course 28 # be functions 29 #pylint: disable-msg=R0201 30 31 def handle_exc(self, exc): 32 '''Handle exceptions that occured during request processing. 33 34 This method returns nothing and does not raise any exceptions itself. 35 ''' 36 37 pass 38 39 def init(self): 40 '''Initialize operations 41 42 This function has to be called before any request has been received, 43 but after the mountpoint has been set up and the process has 44 daemonized. 45 ''' 46 47 pass 48 49 def destroy(self): 50 '''Clean up operations. 51 52 This method has to be called after the last request has been 53 received, when the file system is about to be unmounted. 54 ''' 55 56 pass 57 58 def check_args(self, fuse_args): 59 '''Review FUSE arguments 60 61 This method checks if the FUSE options `fuse_args` are compatible 62 with the way that the file system operations are implemented. 63 It raises an exception if incompatible options are encountered and 64 silently adds required options if they are missing. 65 ''' 66 67 pass 68 69 def readdir(self, fh, off): 70 '''Read directory entries 71 72 This method returns an iterator over the contents of directory `fh`, 73 starting at entry `off`. The iterator yields tuples of the form 74 ``(name, attr)``, where ``attr` is a dict with keys corresponding to 75 the elements of ``struct stat``. 76 77 Iteration may be stopped as soon as enough elements have been 78 retrieved and does not have to be continued until `StopIteration` 79 is raised. 80 ''' 81 82 raise FUSEError(errno.ENOSYS) 83 84 85 def read(self, fh, off, size): 86 '''Read `size` bytes from `fh` at position `off` 87 88 Unless the file has been opened in direct_io mode or EOF is reached, 89 this function returns exactly `size` bytes. 90 ''' 91 92 raise FUSEError(errno.ENOSYS) 93 94 def link(self, inode, new_parent_inode, new_name): 95 '''Create a hard link. 96 97 Returns a dict with the attributes of the newly created directory 98 entry. The keys are the same as for `lookup`. 99 ''' 100 101 raise FUSEError(errno.ENOSYS) 102 103 def open(self, inode, flags): 104 '''Open a file. 105 106 Returns an (integer) file handle. `flags` is a bitwise or of the open flags 107 described in open(2) and defined in the `os` module (with the exception of 108 ``O_CREAT``, ``O_EXCL``, ``O_NOCTTY`` and ``O_TRUNC``) 109 ''' 110 111 raise FUSEError(errno.ENOSYS) 112 113 def opendir(self, inode): 114 '''Open a directory. 115 116 Returns an (integer) file handle. 117 ''' 118 119 raise FUSEError(errno.ENOSYS) 120 121 122 def mkdir(self, parent_inode, name, mode, ctx): 123 '''Create a directory 124 125 `ctx` must be a context object that contains pid, uid and 126 primary gid of the requesting process. 127 128 Returns a dict with the attributes of the newly created directory 129 entry. The keys are the same as for `lookup`. 130 ''' 131 132 raise FUSEError(errno.ENOSYS) 133 134 def mknod(self, parent_inode, name, mode, rdev, ctx): 135 '''Create (possibly special) file 136 137 `ctx` must be a context object that contains pid, uid and 138 primary gid of the requesting process. 139 140 Returns a dict with the attributes of the newly created directory 141 entry. The keys are the same as for `lookup`. 142 ''' 143 144 raise FUSEError(errno.ENOSYS) 145 146 147 def lookup(self, parent_inode, name): 148 '''Look up a directory entry by name and get its attributes. 149 150 Returns a dict with keys corresponding to the elements in 151 ``struct stat`` and the following additional keys: 152 153 :generation: The inode generation number 154 :attr_timeout: Validity timeout (in seconds) for the attributes 155 :entry_timeout: Validity timeout (in seconds) for the name 156 157 Note also that the ``st_Xtime`` entries support floating point numbers 158 to allow for nano second resolution. 159 160 The returned dict can be modified at will by the caller without 161 influencing the internal state of the file system. 162 163 If the entry does not exist, raises `FUSEError(errno.ENOENT)`. 164 ''' 165 166 raise FUSEError(errno.ENOSYS) 167 168 def listxattr(self, inode): 169 '''Get list of extended attribute names''' 170 171 raise FUSEError(errno.ENOSYS) 172 173 def getattr(self, inode): 174 '''Get attributes for `inode` 175 176 Returns a dict with keys corresponding to the elements in 177 ``struct stat`` and the following additional keys: 178 179 :attr_timeout: Validity timeout (in seconds) for the attributes 180 181 The returned dict can be modified at will by the caller without 182 influencing the internal state of the file system. 183 184 Note that the ``st_Xtime`` entries support floating point numbers 185 to allow for nano second resolution. 186 ''' 187 188 raise FUSEError(errno.ENOSYS) 189 190 def getxattr(self, inode, name): 191 '''Return extended attribute value 192 193 If the attribute does not exist, raises `FUSEError(ENOATTR)` 194 ''' 195 196 raise FUSEError(errno.ENOSYS) 197 198 def access(self, inode, mode, ctx, get_sup_gids): 199 '''Check if requesting process has `mode` rights on `inode`. 200 201 Returns a boolean value. `get_sup_gids` must be a function that 202 returns a list of the supplementary group ids of the requester. 203 204 `ctx` must be a context object that contains pid, uid and 205 primary gid of the requesting process. 206 ''' 207 208 raise FUSEError(errno.ENOSYS) 209 210 def create(self, inode_parent, name, mode, ctx): 211 '''Create a file and open it 212 213 `ctx` must be a context object that contains pid, uid and 214 primary gid of the requesting process. 215 216 Returns a tuple of the form ``(fh, attr)``. `fh` is 217 integer file handle that is used to identify the open file and 218 `attr` is a dict similar to the one returned by `lookup`. 219 ''' 220 221 raise FUSEError(errno.ENOSYS) 222 223 def flush(self, fh): 224 '''Handle close() syscall. 225 226 May be called multiple times for the same open file (e.g. if the file handle 227 has been duplicated). 228 229 If the filesystem supports file locking operations, all locks belonging 230 to the file handle's owner are cleared. 231 ''' 232 233 raise FUSEError(errno.ENOSYS) 234 235 def fsync(self, fh, datasync): 236 '''Flush buffers for file `fh` 237 238 If `datasync` is true, only the user data is flushed (and no meta data). 239 ''' 240 241 raise FUSEError(errno.ENOSYS) 242 243 244 def fsyncdir(self, fh, datasync): 245 '''Flush buffers for directory `fh` 246 247 If the `datasync` is true, then only the directory contents 248 are flushed (and not the meta data about the directory itself). 249 ''' 250 251 raise FUSEError(errno.ENOSYS) 252 253 def readlink(self, inode): 254 '''Return target of symbolic link''' 255 256 raise FUSEError(errno.ENOSYS) 257 258 def release(self, fh): 259 '''Release open file 260 261 This method must be called exactly once for each `open` call. 262 ''' 263 264 raise FUSEError(errno.ENOSYS) 265 266 def releasedir(self, fh): 267 '''Release open directory 268 269 This method must be called exactly once for each `opendir` call. 270 ''' 271 272 raise FUSEError(errno.ENOSYS) 273 274 def removexattr(self, inode, name): 275 '''Remove extended attribute 276 277 If the attribute does not exist, raises FUSEError(ENOATTR) 278 ''' 279 280 raise FUSEError(errno.ENOSYS) 281 282 def rename(self, inode_parent_old, name_old, inode_parent_new, name_new): 283 '''Rename a directory entry''' 284 285 raise FUSEError(errno.ENOSYS) 286 287 def rmdir(self, inode_parent, name): 288 '''Remove a directory''' 289 290 raise FUSEError(errno.ENOSYS) 291 292 def setattr(self, inode, attr): 293 '''Change directory entry attributes 294 295 `attr` must be a dict with keys corresponding to the attributes of 296 ``struct stat``. `attr` may also include a new value for ``st_size`` which 297 means that the file should be truncated or extended. 298 299 Returns a dict with the new attributs of the directory entry, 300 similar to the one returned by `getattr()` 301 ''' 302 303 raise FUSEError(errno.ENOSYS) 304 305 def setxattr(self, inode, name, value): 306 '''Set an extended attribute. 307 308 The attribute may or may not exist already. 309 ''' 310 311 raise FUSEError(errno.ENOSYS) 312 313 def statfs(self): 314 '''Get file system statistics 315 316 Returns a `dict` with keys corresponding to the attributes of 317 ``struct statfs``. 318 ''' 319 320 raise FUSEError(errno.ENOSYS) 321 322 def symlink(self, inode_parent, name, target, ctx): 323 '''Create a symbolic link 324 325 `ctx` must be a context object that contains pid, uid and 326 primary gid of the requesting process. 327 328 Returns a dict with the attributes of the newly created directory 329 entry. The keys are the same as for `lookup`. 330 ''' 331 332 raise FUSEError(errno.ENOSYS) 333 334 def unlink(self, parent_inode, name): 335 '''Remove a (possibly special) file''' 336 337 raise FUSEError(errno.ENOSYS) 338 339 def write(self, fh, off, data): 340 '''Write data into an open file 341 342 Returns the number of bytes written. 343 Unless the file was opened in ``direct_io`` mode, this is always equal to 344 `len(data)`. 345 ''' 346 347 raise FUSEError(errno.ENOSYS) 348