コード例 #1
0
    async def statfs(self, ctx):
        """Get file system statistics
        *ctx* will be a `RequestContext` instance.
        The method must return an appropriately filled `StatvfsData` instance.

        See https://linux.die.net/man/2/statvfs
        and https://github.com/libfuse/pyfuse3/blob/1730558574361bf7b05b1be2a228a0443deca088/examples/tmpfs.py#L323
        """

        stats = pyfuse3.StatvfsData()
        stats.f_bsize = 512
        stats.f_frsize = 512

        size_sum = 0
        for inodes in self.data.nodes:
            size_sum += self.data.nodes[inodes].size

        stats.f_blocks = size_sum // stats.f_frsize
        stats.f_bfree = max(size_sum // stats.f_frsize, 1024)
        stats.f_bavail = stats.f_bfree

        count = len(self.data.nodes)
        stats.f_files = count

        stats.f_ffree = max(count, 200)
        stats.f_favail = stats.f_ffree

        # Filemanagers need maximum file name length to create dir or file.
        stats.f_namemax = 100

        return stats
コード例 #2
0
ファイル: mount.py プロジェクト: Derkades/eclipfs
    async def statfs(self, ctx: pyfuse3.RequestContext):
        (success, response) = api.get('statFilesystem')
        if not success:
            raise FUSEError(errno.EREMOTEIO)

        stat_ = pyfuse3.StatvfsData()

        # stat_.f_bsize = config.CHUNKSIZE
        # stat_.f_frsize = config.CHUNKSIZE
        stat_.f_bsize = 1_000_000
        stat_.f_frsize = 1_000_000

        used_blocks = response['used'] // stat_.f_bsize
        free_blocks = response['free'] // stat_.f_bsize
        total_blocks = used_blocks + free_blocks

        stat_.f_blocks = total_blocks
        stat_.f_bfree = free_blocks
        stat_.f_bavail = stat_.f_bfree

        stat_.f_files = 0
        stat_.f_ffree = 0
        stat_.f_favail = stat_.f_ffree

        return stat_
コード例 #3
0
    async def statfs(self, ctx):
        stats = self.db.get_stats()

        # base it off free memory
        if self.db_path == ':memory:':
            memfree = self._memfree()
            f_bfree = memfree >> self.blkshft
            f_bsize = self.blksize
            f_bavail = f_bfree
            f_ffree = f_bfree
            f_favail = f_ffree

        # base it of free disk
        else:
            real = os.statvfs(self.db_path)
            f_bfree = real.f_bfree
            f_bsize = real.f_bsize
            f_bavail = real.f_bavail
            f_ffree = real.f_ffree
            f_favail = real.f_favail

        ours = pyfuse3.StatvfsData()
        ours.f_bsize = self.blksize
        ours.f_frsize = self.blksize
        ours.f_blocks = stats['f_blocks']
        ours.f_files = stats['f_files']
        ours.f_bfree = (f_bfree * f_bsize) >> self.blkshft
        ours.f_bavail = (f_bavail * f_bsize) >> self.blkshft
        ours.f_ffree = f_ffree
        ours.f_favail = f_favail
        # just set it (theres no real limit)
        ours.f_namemax = 255
        return ours
コード例 #4
0
 async def statfs(self, ctx):
     root = self._inode_path_map[pyfuse3.ROOT_INODE]
     stat_ = pyfuse3.StatvfsData()
     try:
         statfs = os.statvfs(root)
     except OSError as exc:
         raise FUSEError(exc.errno)
     for attr in ('f_bsize', 'f_frsize', 'f_blocks', 'f_bfree', 'f_bavail',
                  'f_files', 'f_ffree', 'f_favail'):
         setattr(stat_, attr, getattr(statfs, attr))
     stat_.f_namemax = statfs.f_namemax - (len(root) + 1)
     return stat_
コード例 #5
0
ファイル: operations.py プロジェクト: EGA-archive/crypt4ghfs
 async def statfs(self, ctx):
     LOG.info('Getting statfs')
     s = pyfuse3.StatvfsData()
     try:
         statfs = os.statvfs(self.rootdir)
     except OSError as exc:
         raise FUSEError(exc.errno)
     for attr in ('f_bsize', 'f_frsize', 'f_blocks', 'f_bfree', 'f_bavail',
                  'f_files', 'f_ffree', 'f_favail'):
         setattr(s, attr, getattr(statfs, attr))
     #s.f_namemax = statfs.f_namemax - (len(self.rootdir)+1)
     return s
コード例 #6
0
def test_copy():

    for obj in (pyfuse3.SetattrFields(), pyfuse3.RequestContext()):
        pytest.raises(PicklingError, copy, obj)

    for (inst, attr) in ((pyfuse3.EntryAttributes(), 'st_mode'),
                         (pyfuse3.StatvfsData(), 'f_files')):
        setattr(inst, attr, 42)
        inst_copy = copy(inst)
        assert getattr(inst, attr) == getattr(inst_copy, attr)

    inst = pyfuse3.FUSEError(10)
    assert inst.errno == copy(inst).errno
コード例 #7
0
ファイル: mnt.py プロジェクト: xuze1993/bdfs
    async def statfs(self, ctx):
        stat_ = pyfuse3.StatvfsData()
        quota = self.fs.quota()
        stat_.f_bsize = 512  # 块大小
        stat_.f_frsize = 512  # 碎片块大小
        size = quota.total
        stat_.f_blocks = size // stat_.f_frsize  # 块总数
        stat_.f_bfree = quota.free // stat_.f_bsize  # 剩余块数
        stat_.f_bavail = stat_.f_bfree  # 非特权用户可使用的块数

        inodes = quota.free / 512
        stat_.f_files = inodes  # 索引节点总数
        stat_.f_ffree = max(inodes, 100)  # 可产生索引节点数
        stat_.f_favail = stat_.f_ffree  # 非特权用户可产生索引节点数
        return stat_
コード例 #8
0
ファイル: bashfs.py プロジェクト: wottan32/bashfs
    async def statfs(self, ctx):
        stat_ = pyfuse3.StatvfsData()

        stat_.f_bsize = 512
        stat_.f_frsize = 512

        stat_.f_blocks = 0
        stat_.f_bfree = 20
        stat_.f_bavail = 20

        thing = len(self._inode_map)
        stat_.f_files = thing
        stat_.f_ffree = thing + 2
        stat_.f_favail = thing + 2

        return stat_
コード例 #9
0
    async def statfs(self, ctx):
        stat_ = pyfuse3.StatvfsData()

        stat_.f_bsize = 512
        stat_.f_frsize = 512

        size = self.get_row('SELECT SUM(size) FROM inodes')[0]
        stat_.f_blocks = size // stat_.f_frsize
        stat_.f_bfree = max(size // stat_.f_frsize, 1024)
        stat_.f_bavail = stat_.f_bfree

        inodes = self.get_row('SELECT COUNT(id) FROM inodes')[0]
        stat_.f_files = inodes
        stat_.f_ffree = max(inodes, 100)
        stat_.f_favail = stat_.f_ffree

        return stat_
コード例 #10
0
ファイル: vfsops.py プロジェクト: Phahou/wolfs
	async def statfs(self, ctx):
		"""Easisest function to get a entrypoint into the code (not many df calls all around)"""
		self.embed_active = not self.embed_active
		root = self.vfs.inode_to_path(pyfuse3.ROOT_INODE)
		stat_ = pyfuse3.StatvfsData()
		try:
			statfs = os.statvfs(root)
		except OSError as exc:
			raise FUSEError(exc.errno)
		for attr in ('f_bsize', 'f_frsize', 'f_blocks', 'f_bfree', 'f_bavail',
					 'f_files', 'f_ffree', 'f_favail'):
			setattr(stat_, attr, getattr(statfs, attr))
		stat_.f_namemax = statfs.f_namemax - (len(root.__str__()) + 1)
		print(Col.bg(f'RAM-Usage: of _inode_path_map: {self.vfs.getRamUsage()} | ' +
					 f'elements: {str(len(self.vfs._inode_path_map))}'))
		self.disk.printSummary()
		return stat_
コード例 #11
0
    async def statfs(self, ctx):
        log.debug('started')

        stat_ = pyfuse3.StatvfsData()

        # Get number of blocks & inodes
        blocks = self.db.get_val("SELECT COUNT(id) FROM objects")
        inodes = self.db.get_val("SELECT COUNT(id) FROM inodes")
        size = self.db.get_val('SELECT SUM(size) FROM blocks')

        if size is None:
            size = 0

        # file system block size, i.e. the minimum amount of space that can
        # be allocated. This doesn't make much sense for S3QL, so we just
        # return the average size of stored blocks.
        stat_.f_frsize = max(4096, size // blocks) if blocks != 0 else 4096

        # This should actually be the "preferred block size for doing IO.  However, `df` incorrectly
        # interprets f_blocks, f_bfree and f_bavail in terms of f_bsize rather than f_frsize as it
        # should (according to statvfs(3)), so the only way to return correct values *and* have df
        # print something sensible is to set f_bsize and f_frsize to the same value. (cf.
        # http://bugs.debian.org/671490)
        stat_.f_bsize = stat_.f_frsize

        # size of fs in f_frsize units. Since backend is supposed to be unlimited,
        # always return a half-full filesystem, but at least 1 TB)
        fs_size = max(2 * size, 1024**4)

        stat_.f_blocks = fs_size // stat_.f_frsize
        stat_.f_bfree = (fs_size - size) // stat_.f_frsize
        stat_.f_bavail = stat_.f_bfree  # free for non-root

        total_inodes = max(2 * inodes, 1000000)
        stat_.f_files = total_inodes
        stat_.f_ffree = total_inodes - inodes
        stat_.f_favail = total_inodes - inodes  # free for non-root

        return stat_