Skip to content

Commit

Permalink
toy ls implementation for virtualfs
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 10, 2023
1 parent bc7ef69 commit cddd03d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion rose/virtualfs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import errno
import os
import stat
import subprocess

import fuse
Expand All @@ -8,7 +11,25 @@


class VirtualFS(fuse.Fuse): # type: ignore
pass
def getattr(self, path: str) -> fuse.Stat | int:
if path[1:] == "some_dir" or path in ["..", "/"]:
st_mode = stat.S_IFDIR | 0o755
elif path[1:] == "some_file":
st_mode = stat.S_IFREG | 0o644
else:
return -errno.ENOENT

return fuse.Stat(
st_nlink=1,
st_mode=st_mode,
st_uid=os.getuid(),
st_gid=os.getgid(),
)

def readdir(self, path: str, _):
if path == "/":
for name in [".", "..", "some_file", "some_dir"]:
yield fuse.Direntry(name)


def mount_virtualfs(c: Config) -> None:
Expand Down

0 comments on commit cddd03d

Please sign in to comment.