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