2017-03-13 06:42:02 -04:00
|
|
|
# test VFS functionality without any particular filesystem type
|
|
|
|
|
|
|
|
try:
|
2018-06-05 23:24:09 -04:00
|
|
|
import uos
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
uos.mount
|
|
|
|
except (ImportError, AttributeError):
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2017-03-13 06:42:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Filesystem:
|
|
|
|
def __init__(self, id):
|
|
|
|
self.id = id
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def mount(self, readonly, mkfs):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "mount", readonly, mkfs)
|
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def umount(self):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "umount")
|
|
|
|
|
2017-05-05 09:35:49 -04:00
|
|
|
def ilistdir(self, dir):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "ilistdir", dir)
|
|
|
|
return iter([("a%d" % self.id, 0, 0)])
|
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def chdir(self, dir):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "chdir", dir)
|
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def getcwd(self):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "getcwd")
|
|
|
|
return "dir%d" % self.id
|
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def mkdir(self, path):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "mkdir", path)
|
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def remove(self, path):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "remove", path)
|
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def rename(self, old_path, new_path):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "rename", old_path, new_path)
|
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def rmdir(self, path):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "rmdir", path)
|
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def stat(self, path):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "stat", path)
|
2017-03-14 01:07:30 -04:00
|
|
|
return (self.id,)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def statvfs(self, path):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "statvfs", path)
|
2017-03-14 01:07:30 -04:00
|
|
|
return (self.id,)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def open(self, file, mode):
|
2020-03-22 22:26:08 -04:00
|
|
|
print(self.id, "open", file, mode)
|
2017-03-13 06:42:02 -04:00
|
|
|
|
|
|
|
|
2017-03-14 07:08:37 -04:00
|
|
|
# first we umount any existing mount points the target may have
|
2017-05-09 01:50:40 -04:00
|
|
|
try:
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.umount("/")
|
2017-05-09 01:50:40 -04:00
|
|
|
except OSError:
|
|
|
|
pass
|
2020-03-22 22:26:08 -04:00
|
|
|
for path in uos.listdir("/"):
|
|
|
|
uos.umount("/" + path)
|
2017-03-14 07:08:37 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
# stat root dir
|
2020-03-22 22:26:08 -04:00
|
|
|
print(uos.stat("/"))
|
2017-03-14 01:07:30 -04:00
|
|
|
|
2017-06-11 08:56:27 -04:00
|
|
|
# statvfs root dir; verify that f_namemax has a sensible size
|
2020-03-22 22:26:08 -04:00
|
|
|
print(uos.statvfs("/")[9] >= 32)
|
2017-06-07 01:17:45 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
# getcwd when in root dir
|
|
|
|
print(uos.getcwd())
|
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
# basic mounting and listdir
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mount(Filesystem(1), "/test_mnt")
|
2017-03-13 06:42:02 -04:00
|
|
|
print(uos.listdir())
|
|
|
|
|
2017-05-05 09:35:49 -04:00
|
|
|
# ilistdir
|
|
|
|
i = uos.ilistdir()
|
|
|
|
print(next(i))
|
|
|
|
try:
|
|
|
|
next(i)
|
|
|
|
except StopIteration:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("StopIteration")
|
2017-05-05 09:35:49 -04:00
|
|
|
try:
|
|
|
|
next(i)
|
|
|
|
except StopIteration:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("StopIteration")
|
2017-05-05 09:35:49 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
# referencing the mount point in different ways
|
2020-03-22 22:26:08 -04:00
|
|
|
print(uos.listdir("test_mnt"))
|
|
|
|
print(uos.listdir("/test_mnt"))
|
2017-03-13 06:42:02 -04:00
|
|
|
|
|
|
|
# mounting another filesystem
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mount(Filesystem(2), "/test_mnt2", readonly=True)
|
2017-03-13 06:42:02 -04:00
|
|
|
print(uos.listdir())
|
2020-03-22 22:26:08 -04:00
|
|
|
print(uos.listdir("/test_mnt2"))
|
2017-03-13 06:42:02 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
# mounting over an existing mount point
|
|
|
|
try:
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mount(Filesystem(3), "/test_mnt2")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("OSError")
|
2017-03-14 01:07:30 -04:00
|
|
|
|
|
|
|
# mkdir of a mount point
|
|
|
|
try:
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mkdir("/test_mnt")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("OSError")
|
2017-03-14 01:07:30 -04:00
|
|
|
|
|
|
|
# rename across a filesystem
|
|
|
|
try:
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.rename("/test_mnt/a", "/test_mnt2/b")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("OSError")
|
2017-03-14 01:07:30 -04:00
|
|
|
|
|
|
|
# delegating to mounted filesystem
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.chdir("test_mnt")
|
2017-03-13 06:42:02 -04:00
|
|
|
print(uos.listdir())
|
2017-03-14 01:07:30 -04:00
|
|
|
print(uos.getcwd())
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mkdir("test_dir")
|
|
|
|
uos.remove("test_file")
|
|
|
|
uos.rename("test_file", "test_file2")
|
|
|
|
uos.rmdir("test_dir")
|
|
|
|
print(uos.stat("test_file"))
|
|
|
|
print(uos.statvfs("/test_mnt"))
|
|
|
|
open("test_file")
|
|
|
|
open("test_file", "wb")
|
2017-03-13 06:42:02 -04:00
|
|
|
|
|
|
|
# umount
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.umount("/test_mnt")
|
|
|
|
uos.umount("/test_mnt2")
|
2017-03-14 01:07:30 -04:00
|
|
|
|
|
|
|
# umount a non-existent mount point
|
|
|
|
try:
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.umount("/test_mnt")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
2020-03-22 22:26:08 -04:00
|
|
|
print("OSError")
|
2017-03-10 01:43:49 -05:00
|
|
|
|
|
|
|
# root dir
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mount(Filesystem(3), "/")
|
|
|
|
print(uos.stat("/"))
|
|
|
|
print(uos.statvfs("/"))
|
2017-03-10 01:43:49 -05:00
|
|
|
print(uos.listdir())
|
2020-03-22 22:26:08 -04:00
|
|
|
open("test")
|
2017-03-10 01:43:49 -05:00
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.mount(Filesystem(4), "/mnt")
|
2017-03-10 01:43:49 -05:00
|
|
|
print(uos.listdir())
|
2020-03-22 22:26:08 -04:00
|
|
|
print(uos.listdir("/mnt"))
|
|
|
|
uos.chdir("/mnt")
|
2017-03-10 01:43:49 -05:00
|
|
|
print(uos.listdir())
|
|
|
|
|
|
|
|
# chdir to a subdir within root-mounted vfs, and then listdir
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.chdir("/subdir")
|
2017-03-10 01:43:49 -05:00
|
|
|
print(uos.listdir())
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.chdir("/")
|
2017-03-10 01:43:49 -05:00
|
|
|
|
2020-03-22 22:26:08 -04:00
|
|
|
uos.umount("/")
|
|
|
|
print(uos.listdir("/"))
|
|
|
|
uos.umount("/mnt")
|