async def create(self, vnode_parent, name, mode, flags, ctx): path = self.vm.make_path(self.vm[vnode_parent].path, os.fsdecode(name)) if path in self.vm and self.vm[path].virtual: raise pyfuse3.FUSEError( errno.EACCES ) # Permission denied, since pseudo file should not be created. if not self.auditor.ask_writable(path): _opslog.info( 'Creating to PATH <{}> is not permitted.'.format(path)) raise pyfuse3.FUSEError(errno.EACCES) # Permission denied if self.auditor.ask_discard(path): try: fd = FD(os.open('/dev/null', flags & ~os.O_CREAT)) except OSError as exc: raise pyfuse3.FUSEError(exc.errno) self.vinfo_null.open_vnode(fd) _acslog.info('CREATE-FAKE: {}'.format(path)) return pyfuse3.FileInfo(fh=fd), self._getattr(self.vinfo_null) vinfo = self.vm.create_vinfo() try: fd = FD(os.open(path, flags | os.O_CREAT | os.O_TRUNC, mode)) except OSError as exc: raise pyfuse3.FUSEError(exc.errno) vinfo.add_path(path) vinfo.open_vnode(FD(fd)) _acslog.info('CREATE: {}'.format(path)) return pyfuse3.FileInfo(fh=fd), self._getattr(vinfo)
async def open(self, inode, flags, ctx): self.autenticado(ctx) self.lastContextt = ctx if not self.autenticadoB: raise FUSEError(1) fdt = os.open(self._inode_to_path(inode), os.O_RDONLY) os.lseek(fdt, 0, 0) buffe = os.read(fdt,os.stat(self._inode_to_path(inode)).st_size) self.backupFile = buffe os.close(fdt) if inode in self._inode_fd_map: print("AKI") fd = self._inode_fd_map[inode] print("Foi buscar o File descriptor " + str(fd) ) self._fd_open_count[fd] += 1 return pyfuse3.FileInfo(fh=fd) assert flags & os.O_CREAT == 0 try: fd = os.open(self._inode_to_path(inode), flags) print("Abriu o file descriptor " + str(fd)) except OSError as exc: raise FUSEError(exc.errno) self._inode_fd_map[inode] = fd self._fd_inode_map[fd] = inode self._fd_open_count[fd] = 1 return pyfuse3.FileInfo(fh=fd)
async def open(self, inode: int, flags: int, ctx): # return early for already opened fd print(f'open({inode}, {flags}, {ctx})') if self.vfs.already_open(inode): fd = self.vfs._inode_fd_map[inode] self.vfs._fd_open_count[fd] += 1 print(Col.by(f'open: (fd, inode): ({fd}, {inode})')) return pyfuse3.FileInfo(fh=fd) # disable creation handling here assert flags & os.O_CREAT == 0 try: f: Path = self._inode_to_path(inode) info: FileInfo = self.vfs._inode_path_map[inode] # fetch file from remote if not in cache already if not f.exists(): f_src = self.disk.toSrcPath(f) # self.remote.makeAvailable() self.__fetchFile(f_src, info.entry.st_size) # File is in Cache now fd: int = os.open(f, flags) info.updateEntry(fd=fd) except OSError as exc: raise FUSEError(exc.errno) self.vfs._inode_fd_map[inode] = fd self.vfs._fd_inode_map[fd] = inode self.vfs._fd_open_count[fd] = 1 return pyfuse3.FileInfo(fh=fd)
async def open(self, inode, flags, ctx): if inode in self._inode_fd_map: fd = self._inode_fd_map[inode] self._fd_open_count[fd] += 1 return pyfuse3.FileInfo(fh=fd) assert flags & os.O_CREAT == 0 file_path = self._inode_to_path(inode) try: fd = os.open(file_path, flags) except OSError as exc: raise FUSEError(exc.errno) try: fobj = FileObject(file_path) self._fileobject_map[fd] = fobj self._fileobject_path_map[file_path] = fobj except NotCompressedFile: # If file is not compressed, treat it as general case pass self._inode_fd_map[inode] = fd self._fd_inode_map[fd] = inode self._fd_open_count[fd] = 1 return pyfuse3.FileInfo(fh=fd)
async def open(self, inode, flags, ctx): LOG.info('open with flags %s', flags2str(flags)) # We don't allow to append or open in RW mode if (flags & os.O_RDWR or flags & os.O_APPEND): raise pyfuse3.FUSEError(errno.EPERM) # Get the underlying path path = self.add_extension(self._inode_to_path(inode)) # If we create the file if (flags & os.O_WRONLY): # Sanity check: Since we must have one of O_RDWR/O_RDONLY/O_WRONLY if flags & os.O_RDONLY: raise pyfuse3.FUSEError(errno.EINVAL) attrs = self._getattr(path, no_extension=True) # We enforce truncation fd = await self._create(path, attrs.st_mode, flags | os.O_TRUNC | os.O_CLOEXEC) return pyfuse3.FileInfo(fh=fd) # we are reading a file try: dec = FileDecryptor(path, flags, self.keys) fd = dec.fd self._fd2cryptors[fd] = dec LOG.debug('added fd %d to map', fd) except OSError as exc: LOG.error('OSError opening %s: %s', path, exc) raise FUSEError(exc.errno) except Exception as exc: LOG.error('Error opening %s: %s', path, exc) raise FUSEError(errno.EACCES) return pyfuse3.FileInfo(fh=fd)
async def open(self, inode, flags, ctx): if __debug__: # print('Debug OFF') pass else: print('Debug ON') print("open") if inode in self._inode_fd_map: fd = self._inode_fd_map[inode] if __debug__: # print('Debug OFF') pass else: print('Debug ON') print("fd:", fd) self._fd_open_count[fd] += 1 return pyfuse3.FileInfo(fh=fd) assert flags & os.O_CREAT == 0 try: fd = os.open(self._inode_to_path(inode), flags) if __debug__: # print('Debug OFF') pass else: print('Debug ON') print("fd2:", fd) except OSError as exc: raise FUSEError(exc.errno) self._inode_fd_map[inode] = fd self._fd_inode_map[fd] = inode self._fd_open_count[fd] = 1 return pyfuse3.FileInfo(fh=fd)
async def open(self, vnode, flags, ctx): vinfo = self.vm[vnode] _acslog.debug('OPEN: {}'.format(vinfo.path)) if vinfo.virtual: fd = FD(os.open('/dev/null', flags)) # reserve file descriptor number vinfo.open_vnode(fd, '/dev/null', flags, discard=False) return pyfuse3.FileInfo(fh=fd) elif self.auditor.ask_discard(vinfo.path): try: # open with readonly mode fd = FD( os.open( vinfo.path, flags & ~(os.O_TRUNC | os.O_RDWR | os.O_WRONLY) | os.O_RDONLY)) except OSError as exc: raise pyfuse3.FUSEError(exc.errno) vinfo.open_vnode(fd, vinfo.path, flags & ~(os.O_TRUNC | os.O_RDWR | os.O_WRONLY) | os.O_RDONLY, discard=True) return pyfuse3.FileInfo(fh=fd) else: if flags & os.O_RDWR and not (self.auditor.ask_writable( vinfo.path) and self.auditor.ask_readable(vinfo.path)): _opslog.info( 'Reading and writing to PATH <{}> is not permitted.'. format(vinfo.path)) raise pyfuse3.FUSEError(errno.EACCES) # Permission denied if flags & os.O_WRONLY and not self.auditor.ask_writable( vinfo.path): _opslog.info('Writing to PATH <{}> is not permitted.'.format( vinfo.path)) raise pyfuse3.FUSEError(errno.EACCES) # Permission denied if not flags & (os.O_RDWR | os.O_WRONLY ) and not self.auditor.ask_readable(vinfo.path): _opslog.info('Reading from PATH <{}> is not permitted.'.format( vinfo.path)) raise pyfuse3.FUSEError(errno.EACCES) # Permission denied try: fd = FD(os.open(vinfo.path, flags)) except OSError as exc: raise pyfuse3.FUSEError(exc.errno) # Record accessed files; if flags & os.O_RDWR: self.stat_path_open_rw.add(vinfo.path) elif flags & os.O_WRONLY: self.stat_path_open_w.add(vinfo.path) else: self.stat_path_open_r.add(vinfo.path) vinfo.open_vnode(fd, vinfo.path, flags, discard=False) return pyfuse3.FileInfo(fh=fd)
async def open(self, inode, flags, ctx): if inode in self._inode_fd_map: fd = self._inode_fd_map[inode] self._fd_open_count[fd] += 1 return pyfuse3.FileInfo(fh=fd) assert flags & os.O_CREAT == 0 try: fd = os.open(self._inode_to_path(inode), flags) except OSError as exc: raise FUSEError(exc.errno) self._inode_fd_map[inode] = fd self._fd_inode_map[fd] = inode self._fd_open_count[fd] = 1 return pyfuse3.FileInfo(fh=fd)
async def open(self, id_, flags, ctx): log.debug('started with %d', id_) if ((flags & os.O_RDWR or flags & os.O_WRONLY) and (self.failsafe or self.inodes[id_].locked)): raise FUSEError(errno.EPERM) return pyfuse3.FileInfo(fh=id_, keep_cache=True)
async def open(self, inode, flags, ctx): # Yeah, unused arguments #pylint: disable=W0613 self.inode_open_count[inode] += 1 # Use inodes as a file handles return pyfuse3.FileInfo(fh=inode)
async def open(self, inode, flags, ctx): """Open a inode *inode* with *flags*. *ctx* will be a `RequestContext` instance. *flags* will be a bitwise or of the open flags described in the :manpage:`open(2)` manpage and defined in the `os` module (with the exception of ``O_CREAT``, ``O_EXCL``, ``O_NOCTTY`` and ``O_TRUNC``) This method must return a `FileInfo` instance. The `FileInfo.fh` field must contain an integer file handle, which will be passed to the `read`, `write`, `flush`, `fsync` and `release` methods to identify the open file. The `FileInfo` instance may also have relevant configuration attributes set; see the `FileInfo` documentation for more information. """ # TODO: Add permission handling to nodes. assert flags & os.O_CREAT == 0 self.log.debug(stat.filemode(flags)) self.log.debug(stat.S_IMODE(flags)) if (flags & os.O_TRUNC) != 0: self.log.warning("Truncating data of inode: %d", inode) self.data.nodes[inode].data = "" if not (flags & os.O_RDWR or flags & os.O_RDONLY or flags & os.O_WRONLY or flags & os.O_APPEND): self.log.error("False permission.") self.log.debug("read write: %d", flags & os.O_RDWR) self.log.debug("read only: %d", flags & os.O_RDONLY) self.log.debug("read write: %d", flags & os.O_WRONLY) self.log.debug("append: %d", flags & os.O_APPEND) self.log.debug("whole flags: %s", oct(flags)) # raise pyfuse3.FUSEError(errno.EPERM) self.data.try_increase_op_count(inode) return pyfuse3.FileInfo(fh=inode)
async def create(self, inode_p, name, mode, flags, ctx): LOG.info('create in %d with name %s | mode %o | flags (%d): %s', inode_p, name, mode, flags, flags2str(flags)) name = self.add_extension(fsdecode(name)) path = os.path.join(self._inode_to_path(inode_p), name) fd = await self._create(path, mode, flags | os.O_CREAT | os.O_TRUNC | os.O_CLOEXEC) return (pyfuse3.FileInfo(fh=fd), self._getattr(path))
async def open(self, inode: int, _flags: int, _ctx: pyfuse3.RequestContext) -> pyfuse3.FileInfo: """ Open an inode and return a unique file handle """ # Re-use inode as file handle self.logger.debug("open(inode=%d)", inode) entry = self.inode2entry(inode) return pyfuse3.FileInfo(fh=inode, **entry.file_info_attrs)
async def open(self, inode, flags, ctx=None): inode_obj = self.inode[inode] fh_obj = await inode_obj.acquire() fi = pyfuse3.FileInfo() fi.fh = self.fh.allocate(fh_obj) fi.direct_io = True fi.keep_cache = False fi.nonseekable = False return fi
async def create(self, inode_parent, name, mode, flags, ctx): file = File(name, inode_parent, None, False) self.files.add_file(file) self.write_timer.start() return ( pyfuse3.FileInfo(fh=file.inode), self.files.getattr_from_file(file) )
async def create(self, folder_inode, bname, mode, flags, ctx): self.logger.debug("create: %s %s %s %s", folder_inode, bname, mode, flags) entry = await self._create_entry(folder_inode, bname, mode, ctx) grid_in = self._create_grid_in(entry) self.active_inodes[entry.inode] += 1 self.active_writes[entry.inode] = grid_in return (pyfuse3.FileInfo(fh=entry.inode), await self._gen_attr(entry))
async def open(self, inode, flags, ctx): if inode not in self._files: raise pyfuse3.FUSEError(errno.ENOENT) logvfs.info("open(%s)", self._files[inode].fname) if flags & os.O_RDWR or flags & os.O_WRONLY: logvfs.info("error: readonly") raise pyfuse3.FUSEError(errno.EPERM) return pyfuse3.FileInfo(fh=inode)
async def open(self, inode, flags, ctx): path = self._get_node(inode).make_path(self.separator) l.debug("open: %r", path) file_handle = next(self._file_generator) proc = await trio.open_process(self.argv_prefix + [path.decode()], stdout=subprocess.PIPE, stdin=subprocess.PIPE) self._proc_map[file_handle] = proc return pyfuse3.FileInfo(fh=file_handle, direct_io=True, keep_cache=False, nonseekable=True)
async def create(self, inode_p, name, mode, flags, ctx): path = os.path.join(self._inode_to_path(inode_p), fsdecode(name)) try: fd = os.open(path, flags | os.O_CREAT | os.O_TRUNC) except OSError as exc: raise FUSEError(exc.errno) attr = self._getattr(fd=fd) self._add_path(attr.st_ino, path) self._inode_fd_map[attr.st_ino] = fd self._fd_inode_map[fd] = attr.st_ino self._fd_open_count[fd] = 1 return (pyfuse3.FileInfo(fh=fd), attr)
async def open(self, inode, flags, ctx): self.logger.debug("open: %s %s", inode, flags) # Do not allow writes to a existing file if flags & os.O_WRONLY: raise pyfuse3.FUSEError(errno.EACCES) # Deny if write mode and filesystem is mounted as read-only #if flags & (os.O_RDWR | os.O_CREAT | os.O_WRONLY | os.O_APPEND) and self._readonly: # raise pyfuse3.FUSWERROR(errno.EPERM) self.active_inodes[inode] += 1 return pyfuse3.FileInfo(fh=inode)
async def open(self, inode, flags, ctx): logger.debug(f'open() called for inode {inode}') if inode in self._inode_to_fd: fd = self._inode_to_fd[inode] self._fd_to_open_count[fd] += 1 return pyfuse3.FileInfo(fh=fd) else: asset = self._inode_to_asset[inode] if not asset: raise FUSEError(errno.ENOENT) try: fd = os.open(asset.original_path(self.photo_library.path), flags) except OSError as err: raise FUSEError(err.errno) self._inode_to_fd[inode] = fd self._fd_to_inode[fd] = inode self._fd_to_open_count[fd] = 1 return pyfuse3.FileInfo(fh=fd)
async def create(self, inode_p, name, mode, flags, ctx): path = self._get_temp_directory() + fsdecode(name) try: if os.path.exists(path): os.remove(path) fd = os.open(path, flags | os.O_CREAT | os.O_TRUNC) except OSError as exc: raise FUSEError(exc.errno) attr = self._getattr(fd=fd) self._add_path(attr.st_ino, path) self._inode_fd_map[attr.st_ino] = fd self._fd_inode_map[fd] = attr.st_ino self._fd_open_count[fd] = 1 self._degoo_path[attr.st_ino] = self._inode_to_path(inode_p, fullpath=True) return pyfuse3.FileInfo(fh=fd, direct_io=True), attr
async def create(self, inode_p: int, name: bytes, mode, flags, ctx: pyfuse3.RequestContext): """ Create a file with permissions mode and open it with flags ctx will be a RequestContext instance. The method must return a tuple of the form (fi, attr), where fi is a FileInfo instance handle like the one returned by open and attr is an EntryAttributes instance with the attributes of the newly created directory entry. (Successful) execution of this handler increases the lookup count for the returned inode by one. """ inode_info = Inode.by_mkfile(inode_p, name.decode()) fh = self._obtain_file_handle_nofetch(inode_info) return (pyfuse3.FileInfo(fh=fh), self._getattr(inode_info, ctx))
async def create(self, id_p, name, mode, flags, ctx): log.debug('started with id_p=%d, %s', id_p, name) if self.failsafe: raise FUSEError(errno.EPERM) try: id_ = self.db.get_val( "SELECT inode FROM contents_v WHERE name=? AND parent_inode=?", (name, id_p)) except NoSuchRowError: inode = self._create(id_p, name, mode, ctx) else: await self.open(id_, flags, ctx) inode = self.inodes[id_] self.open_inodes[inode.id] += 1 return (pyfuse3.FileInfo(fh=inode.id), inode.entry_attributes())
async def open(self, id_, flags, ctx): log.debug('started with %d', id_) if ((flags & os.O_RDWR or flags & os.O_WRONLY) and (self.failsafe or self.inodes[id_].locked)): raise FUSEError(errno.EPERM) if flags & os.O_TRUNC: if not (flags & os.O_RDWR or flags & os.O_WRONLY): # behaviour is not defined in POSIX, we opt for an error raise FUSEError(errno.EINVAL) attr = await self.getattr(id_, ctx) if stat.S_ISREG(attr.st_mode): attr.st_mtime_ns = time_ns() attr.st_size = 0 await self.setattr(id_, attr, _TruncSetattrFields, None, ctx) elif stat.S_ISFIFO(attr.st_mode) or stat.S_ISBLK(attr.st_mode): # silently ignore O_TRUNC when FIFO or terminal block device pass else: # behaviour is not defined in POSIX, we opt for an error raise FUSEError(errno.EINVAL) return pyfuse3.FileInfo(fh=id_, keep_cache=True)
async def open(self, inode: int, flags, ctx: pyfuse3.RequestContext): """ Open a inode inode with flags. ctx will be a RequestContext instance. flags will be a bitwise or of the open flags described in the open(2) manpage and defined in the os module (with the exception of O_CREAT, O_EXCL, O_NOCTTY and O_TRUNC) This method must return a FileInfo instance. The FileInfo.fh field must contain an integer file handle, which will be passed to the read, write, flush, fsync and release methods to identify the open file. The FileInfo instance may also have relevant configuration attributes set; see the FileInfo documentation for more information. """ log.debug('open inode %s flags %s', inode, flags) # Make sure the inode exists and is a file (fh, info) = self._obtain_file_handle(inode) if info.is_dir(): self._release_file_handle(fh) raise (FUSEError(errno.EISDIR)) # Error: Is a directory return pyfuse3.FileInfo(fh=fh)
async def create(self, folder_inode, bname, mode, flags, ctx): self.logger.debug("create: %s %s %s %s", folder_inode, bname, mode, flags) if folder_inode != pyfuse3.ROOT_INODE: raise pyfuse3.FUSEError(errno.EINVAL) filename = bname.decode(self._filename_encoding, 'replace') grid_in = self.gridfs.new_file(filename=filename, metadata={ 'uid': ctx.uid, 'gid': ctx.gid, 'mode': mode }) inode = self._last_inode self._last_inode += 1 self.id2inode[grid_in._id] = inode self.inode2id[inode] = grid_in._id self.active_inodes[inode] += 1 self.active_writes[inode] = grid_in return (pyfuse3.FileInfo(fh=inode), await self._getattr(grid_in, inode))
async def open(self, inode, flags, ctx): if inode not in self.files_by_inode: raise pyfuse3.FUSEError(errno.ENOENT) if flags & os.O_RDWR or flags & os.O_WRONLY: raise pyfuse3.FUSEError(errno.EACCES) return pyfuse3.FileInfo(fh=inode)
async def open(self, inode, flags, ctx): if inode != self.hello_inode: raise pyfuse3.FUSEError(errno.ENOENT) if flags & os.O_RDWR or flags & os.O_WRONLY: raise pyfuse3.FUSEError(errno.EPERM) return pyfuse3.FileInfo(fh=inode)
async def create(self, inode_parent, name, mode, flags, ctx): #pylint: disable=W0612 entry = await self._create(inode_parent, name, mode, ctx) self.inode_open_count[entry.st_ino] += 1 return (pyfuse3.FileInfo(fh=entry.st_ino), entry)