def getattr(self, inode, ctx=None): if inode not in self.inodes: raise llfuse.FUSEError(errno.ENOENT) e = self.inodes[inode] entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 entry.entry_timeout = 0 entry.attr_timeout = e.time_to_next_poll() if e.allow_attr_cache else 0 entry.st_mode = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH if isinstance(e, Directory): entry.st_mode |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | stat.S_IFDIR else: entry.st_mode |= stat.S_IFREG if isinstance(e, FuseArvadosFile): entry.st_mode |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if self.enable_write and e.writable(): entry.st_mode |= stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH entry.st_nlink = 1 entry.st_uid = self.uid entry.st_gid = self.gid entry.st_rdev = 0 entry.st_size = e.size() entry.st_blksize = 512 entry.st_blocks = (entry.st_size // 512) + 1 if hasattr(entry, 'st_atime_ns'): # llfuse >= 0.42 entry.st_atime_ns = int(e.atime() * 1000000000) entry.st_mtime_ns = int(e.mtime() * 1000000000) entry.st_ctime_ns = int(e.mtime() * 1000000000) else: # llfuse < 0.42 entry.st_atime = int(e.atime) entry.st_mtime = int(e.mtime) entry.st_ctime = int(e.mtime) return entry
def _getattr(self, entry): attrs = llfuse.EntryAttributes() attrs.st_ino = entry.inode attrs.st_rdev = 0 attrs.generation = 0 attrs.entry_timeout = 300 attrs.attr_timeout = 300 if type(entry) is Dir: nlink = 2 if entry is not self.root else 1 size = 5 for name, child in entry.children.items(): size += len(name) + 1 if type(child) is Dir: nlink += 1 attrs.st_mode = stat.S_IFDIR | 0o555 attrs.st_nlink = nlink attrs.st_size = size else: attrs.st_nlink = 1 attrs.st_mode = stat.S_IFREG | 0o444 attrs.st_size = entry.size arch_st = self.arch_st attrs.st_uid = arch_st.st_uid attrs.st_gid = arch_st.st_gid attrs.st_blksize = arch_st.st_blksize attrs.st_blocks = 1 + ( (attrs.st_size - 1) // attrs.st_blksize) if attrs.st_size != 0 else 0 if HAS_STAT_NS: attrs.st_atime_ns = arch_st.st_atime_ns attrs.st_mtime_ns = arch_st.st_mtime_ns attrs.st_ctime_ns = arch_st.st_ctime_ns else: attrs.st_atime_ns = int(arch_st.st_atime * 1000) attrs.st_mtime_ns = int(arch_st.st_mtime * 1000) attrs.st_ctime_ns = int(arch_st.st_ctime * 1000) return attrs
def test_truncate(self): len_ = int(2.7 * self.max_obj_size) data = self.random_data(len_) attr = llfuse.EntryAttributes() (fh, inode) = self.server.create(ROOT_INODE, self.newname(), self.file_mode(), os.O_RDWR, Ctx()) self.server.write(fh, 0, data) attr.st_size = len_ // 2 self.server.setattr(inode.id, attr) self.assertTrue(self.server.read(fh, 0, len_) == data[:len_ // 2]) attr.st_size = len_ self.server.setattr(inode.id, attr) self.assertTrue( self.server.read(fh, 0, len_) == data[:len_ // 2] + b'\0' * (len_ // 2)) self.server.release(fh) self.server.forget([(inode.id, 1)]) self.fsck()
def getattr(self, inode, ctx=None): entry = llfuse.EntryAttributes() pfile = self._get_phantom_file_from_inode(inode) log.debug("getattr for %d is %s" % (inode, pfile)) if pfile is None: raise llfuse.FUSEError(errno.ENOENT) elif pfile.is_dir(): entry.st_mode = self._directory_mode elif pfile.is_symlink(): entry.st_mode = self._symlink_mode else: entry.st_mode = self._file_mode entry.st_size = pfile.filesize entry.st_atime_ns = self._stamp entry.st_ctime_ns = self._stamp entry.st_mtime_ns = self._stamp entry.st_gid = os.getgid() entry.st_uid = os.getuid() entry.st_ino = inode return entry
def getattr(self, inode, ctx=None): entry = llfuse.EntryAttributes() if inode == llfuse.ROOT_INODE: entry.st_mode = (stat.S_IFDIR | 0o755) entry.st_size = 0 elif inode == self.hello_inode: entry.st_mode = (stat.S_IFREG | 0o644) entry.st_size = len(self.hello_data) else: raise llfuse.FUSEError(errno.ENOENT) stamp = int(1438467123.985654 * 1e9) entry.st_atime_ns = stamp entry.st_ctime_ns = stamp entry.st_mtime_ns = stamp entry.st_gid = os.getgid() entry.st_uid = os.getuid() entry.st_ino = inode return entry
def _make_attr(self): statvfs = do_os(os.statvfs, self._root) now = time.time() attr = llfuse.EntryAttributes() # pylint: disable=no-member attr.st_ino = llfuse.ROOT_INODE attr.generation = 0 # used if inodes change after restart attr.entry_timeout = 300 attr.attr_timeout = 300 attr.st_mode = 0o777 | stat.S_IFDIR attr.st_nlink = 1 # Fix for subdirectories? attr.st_uid = do_os(os.getpid) attr.st_gid = do_os(os.getgid) attr.st_size = 4096 attr.st_blksize = statvfs.f_bsize attr.st_blocks = 1 attr.st_atime = now attr.st_ctime = now attr.st_mtime = now return attr
def test_rounding(): # Incorrect division previously resulted in rounding errors for # all dates. entry = llfuse.EntryAttributes() # Approximately 100 years, ending in 999 secs = 100 * 365 * 24 * 3600 + 999 nanos = _NANOS_PER_SEC - 1 total = secs * _NANOS_PER_SEC + nanos entry.st_atime_ns = total entry.st_ctime_ns = total entry.st_mtime_ns = total # Birthtime skipped -- only valid under BSD and OSX #entry.st_birthtime_ns = total assert entry.st_atime_ns == total assert entry.st_ctime_ns == total assert entry.st_mtime_ns == total
def getattr(self, inode, ctx=None): item = self.get_item(inode) entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 entry.entry_timeout = 300 entry.attr_timeout = 300 entry.st_mode = item.mode & ~self.umask entry.st_nlink = item.get('nlink', 1) entry.st_uid = self.uid_forced if self.uid_forced is not None else item.uid if item.uid >= 0 else self.default_uid entry.st_gid = self.gid_forced if self.gid_forced is not None else item.gid if item.gid >= 0 else self.default_gid entry.st_rdev = item.get('rdev', 0) entry.st_size = item.get_size() entry.st_blksize = 512 entry.st_blocks = (entry.st_size + entry.st_blksize - 1) // entry.st_blksize # note: older archives only have mtime (not atime nor ctime) entry.st_mtime_ns = mtime_ns = item.mtime entry.st_atime_ns = item.get('atime', mtime_ns) entry.st_ctime_ns = item.get('ctime', mtime_ns) entry.st_birthtime_ns = item.get('birthtime', mtime_ns) return entry
def test_rounding(): # Incorrect division previously resulted in rounding errors for # all dates. entry = llfuse.EntryAttributes() # Approximately 67 years, ending in 999. # Note: 67 years were chosen to avoid y2038 issues (1970 + 67 = 2037). # Testing these is **not** in scope of this test. secs = 67 * 365 * 24 * 3600 + 999 nanos = _NANOS_PER_SEC - 1 total = secs * _NANOS_PER_SEC + nanos entry.st_atime_ns = total entry.st_ctime_ns = total entry.st_mtime_ns = total # Birthtime skipped -- only valid under BSD and OSX #entry.st_birthtime_ns = total assert entry.st_atime_ns == total assert entry.st_ctime_ns == total assert entry.st_mtime_ns == total
def getattr(self, inode): entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 entry.entry_timeout = 300 entry.attr_timeout = 300 entry.st_mode = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) entry.st_nlink = 1 entry.st_uid = 1000 entry.st_gid = 1000 entry.st_rdev = 0 try: pg = pywikibot.Page(self.site, title=self.map.inv[inode]) self.existent += 1 entry.st_size = len(pg.text.encode("utf-8")) entry.st_mtime = pg.editTime().timestamp() entry.st_ctime = pg.oldest_revision.timestamp.timestamp() except KeyError: log.debug( "tried getting inode {}, it does not exist".format(inode)) self.nonexistent += 1 entry.st_size = 0 entry.st_mtime = 0 entry.st_ctime = 0 if inode == llfuse.ROOT_INODE: log.debug("getattr root") entry.st_mode |= stat.S_IFDIR self.st_nlink = 1 + self.nonexistent + self.existent else: entry.st_mode |= stat.S_IFREG entry.st_blksize = 512 entry.st_blocks = 1 entry.st_atime = 0 return entry
def getattr(self, inode): row = self.get_row('SELECT * FROM inodes WHERE id=?', (inode,)) entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 entry.entry_timeout = 300 entry.attr_timeout = 300 entry.st_mode = row['mode'] entry.st_nlink = self.get_row("SELECT COUNT(inode) FROM contents WHERE inode=?", (inode,))[0] entry.st_uid = row['uid'] entry.st_gid = row['gid'] entry.st_rdev = row['rdev'] entry.st_size = row['size'] entry.st_blksize = 512 entry.st_blocks = 1 entry.st_atime = row['atime'] entry.st_mtime = row['mtime'] entry.st_ctime = row['ctime'] return entry
def _getattr(self, path=None, fd=None): assert fd is None or path is None assert not(fd is None and path is None) try: if fd is None: stat = os.lstat(path) else: stat = os.fstat(fd) except OSError as exc: raise FUSEError(exc.errno) entry = llfuse.EntryAttributes() for attr in ('st_ino', 'st_mode', 'st_nlink', 'st_uid', 'st_gid', 'st_rdev', 'st_size', 'st_atime_ns', 'st_mtime_ns', 'st_ctime_ns'): setattr(entry, attr, getattr(stat, attr)) entry.generation = 0 entry.entry_timeout = 5 entry.attr_timeout = 5 entry.st_blksize = 512 entry.st_blocks = ((entry.st_size+entry.st_blksize-1) // entry.st_blksize) return entry
def getattr(self, inode, ctx=None): entry = llfuse.EntryAttributes() if inode == llfuse.ROOT_INODE: entry.st_mode = (stat.S_IFDIR | 0o755) entry.st_size = 0 elif inode < len(self.inode_list): try: entry.st_mode = (stat.S_IFREG | 0o644) entry.st_size = remote.RemoteFile(self.inode_list[inode], block_size=self.block_size).length else: raise llfuse.FUSEError(errno.ENOENT) stamp = int(1438467123.985654 * 1e9) entry.st_atime_ns = stamp entry.st_ctime_ns = stamp entry.st_mtime_ns = stamp entry.st_gid = os.getgid() entry.st_uid = os.getuid() entry.st_ino = inode return entry
def getattr(self, inode, ctx=None): ppath = self.inode_path[inode] entity = self._flistmeta.getDirOrFile(ppath) entityAcl = self._flistmeta.aciCollection.get(entity['aclkey']).dbobj entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 entry.entry_timeout = 300 entry.attr_timeout = 300 entry.st_mode = entityAcl.mode entry.st_uid = pwd.getpwnam(entityAcl.uname).pw_uid entry.st_gid = grp.getgrnam(entityAcl.gname).gr_gid entry.st_size = entity['size'] entry.st_blksize = 4096 entry.st_blocks = 0 if entity['size'] == 0 else int(((entity['size'] - 1) / entry.st_blksize + 1)) * 8 entry.st_atime_ns = int(time() * 1e9) entry.st_mtime_ns = entity["modificationTime"] * 1e9 entry.st_ctime_ns = entity["creationTime"] * 1e9 return entry
def getattr(self, inode): if inode not in self.inodes: raise llfuse.FUSEError(errno.ENOENT) e = self.inodes[inode] entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 entry.entry_timeout = 60 entry.attr_timeout = 60 entry.st_mode = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH if isinstance(e, Directory): entry.st_mode |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | stat.S_IFDIR else: entry.st_mode |= stat.S_IFREG if isinstance(e, FuseArvadosFile): entry.st_mode |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH if self.enable_write and e.writable(): entry.st_mode |= stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH entry.st_nlink = 1 entry.st_uid = self.uid entry.st_gid = self.gid entry.st_rdev = 0 entry.st_size = e.size() entry.st_blksize = 512 entry.st_blocks = (entry.st_size / 512) + 1 entry.st_atime = int(e.atime()) entry.st_mtime = int(e.mtime()) entry.st_ctime = int(e.mtime()) return entry
def test_setattr(self): (fh, inode) = self.server.create(ROOT_INODE, self.newname(), 0o641, os.O_RDWR, Ctx()) self.server.release(fh) inode_old = self.server.getattr(inode.id).copy() attr = llfuse.EntryAttributes() attr.st_mode = self.file_mode() attr.st_uid = randint(0, 2**32) attr.st_gid = randint(0, 2**32) attr.st_atime = randint(0, 2**32) / 10**6 attr.st_mtime = randint(0, 2**32) / 10**6 safe_sleep(CLOCK_GRANULARITY) self.server.setattr(inode.id, attr) inode_new = self.server.getattr(inode.id) self.assertGreater(inode_new.ctime, inode_old.ctime) for key in attr.__slots__: if getattr(attr, key) is not None: self.assertEqual(getattr(attr, key), getattr(inode_new, key)) self.server.forget([(inode.id, 1)]) self.fsck()
def test_entry_res(): a = llfuse.EntryAttributes() val = 1000.2735 a.st_atime_ns = val * 1e9 assert a.st_atime_ns / 1e9 == val