Created
June 11, 2026 10:39
-
-
Save iTrooz/e1a6e63e0be4efee7863d447b9b72efc to your computer and use it in GitHub Desktop.
FUSE void directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # https://gist.github.com/iTrooz/e1a6e63e0be4efee7863d447b9b72efc/edit | |
| # Creates a "void" directory in selected folder. This directory will absorbs all writes, and always show as empty. Like /dev/null, but as a folder | |
| # Must be run as root | |
| import pyfuse3 | |
| import trio | |
| import errno | |
| import stat | |
| class VoidFS(pyfuse3.Operations): | |
| async def getattr(self, inode, ctx=None): | |
| entry = pyfuse3.EntryAttributes() | |
| if inode == pyfuse3.ROOT_INODE: | |
| entry.st_mode = (stat.S_IFDIR | 0o777) | |
| entry.st_size = 0 | |
| else: | |
| entry.st_mode = (stat.S_IFREG | 0o777) | |
| entry.st_size = 0 | |
| entry.st_atime_ns = 0 | |
| entry.st_mtime_ns = 0 | |
| entry.st_ctime_ns = 0 | |
| entry.st_gid = 0 | |
| entry.st_uid = 0 | |
| entry.st_ino = inode | |
| return entry | |
| async def lookup(self, parent_inode, name, ctx=None): | |
| return await self.getattr(inode=2) # any file "exists" | |
| async def opendir(self, inode, ctx): | |
| return inode | |
| async def readdir(self, fh, start_id, token): | |
| return # always empty | |
| async def open(self, inode, flags, ctx): | |
| return pyfuse3.FileInfo(fh=inode) | |
| async def create(self, parent_inode, name, mode, flags, ctx): | |
| entry = await self.getattr(inode=2) | |
| return (pyfuse3.FileInfo(fh=2), entry) | |
| async def write(self, fh, offset, buf): | |
| return len(buf) # discard | |
| async def setattr(self, inode, attr, fields, fh, ctx): | |
| return await self.getattr(inode) | |
| if __name__ == '__main__': | |
| import sys | |
| if len(sys.argv) != 2: | |
| print(f"Usage: {sys.argv[0]} <mountpoint>") | |
| sys.exit(1) | |
| pyfuse3.init(VoidFS(), sys.argv[1], ['fsname=voidfs', 'allow_other']) | |
| try: | |
| trio.run(pyfuse3.main) | |
| except KeyboardInterrupt: | |
| pass | |
| finally: | |
| pyfuse3.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment