2017-03-13 06:42:02 -04:00
|
|
|
# test VFS functionality without any particular filesystem type
|
|
|
|
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
import os
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount
|
2017-03-13 06:42:02 -04:00
|
|
|
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:
|
2020-05-27 22:50:44 -04:00
|
|
|
def __init__(self, id, fail=0):
|
2017-03-13 06:42:02 -04:00
|
|
|
self.id = id
|
2020-05-27 22:50:44 -04:00
|
|
|
self.fail = fail
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def mount(self, readonly, mkfs):
|
|
|
|
print(self.id, "mount", readonly, mkfs)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def umount(self):
|
|
|
|
print(self.id, "umount")
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-05-05 09:35:49 -04:00
|
|
|
def ilistdir(self, dir):
|
|
|
|
print(self.id, "ilistdir", dir)
|
|
|
|
return iter([("a%d" % self.id, 0, 0)])
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def chdir(self, dir):
|
|
|
|
print(self.id, "chdir", dir)
|
2020-05-27 22:50:44 -04:00
|
|
|
if self.fail:
|
|
|
|
raise OSError(self.fail)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def getcwd(self):
|
|
|
|
print(self.id, "getcwd")
|
|
|
|
return "dir%d" % self.id
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def mkdir(self, path):
|
|
|
|
print(self.id, "mkdir", path)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def remove(self, path):
|
|
|
|
print(self.id, "remove", path)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def rename(self, old_path, new_path):
|
|
|
|
print(self.id, "rename", old_path, new_path)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def rmdir(self, path):
|
|
|
|
print(self.id, "rmdir", path)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def stat(self, path):
|
|
|
|
print(self.id, "stat", path)
|
|
|
|
return (self.id,)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
def statvfs(self, path):
|
|
|
|
print(self.id, "statvfs", path)
|
|
|
|
return (self.id,)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
def open(self, file, mode):
|
|
|
|
print(self.id, "open", file, mode)
|
|
|
|
|
|
|
|
|
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:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.umount("/")
|
2017-05-09 01:50:40 -04:00
|
|
|
except OSError:
|
|
|
|
pass
|
2023-08-22 11:15:46 -04:00
|
|
|
for path in os.listdir("/"):
|
|
|
|
os.umount("/" + path)
|
2017-03-14 07:08:37 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
# stat root dir
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.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
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.statvfs("/")[9] >= 32)
|
2017-06-07 01:17:45 -04:00
|
|
|
|
2017-03-14 01:07:30 -04:00
|
|
|
# getcwd when in root dir
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.getcwd())
|
2017-03-14 01:07:30 -04:00
|
|
|
|
2020-09-22 01:05:00 -04: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:
|
2023-08-22 11:15:46 -04:00
|
|
|
getattr(os, func)(arg)
|
2020-09-22 01:05:00 -04:00
|
|
|
except OSError:
|
|
|
|
print(func, arg, "OSError")
|
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
# basic mounting and listdir
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount(Filesystem(1), "/test_mnt")
|
|
|
|
print(os.listdir())
|
2017-03-13 06:42:02 -04:00
|
|
|
|
2017-05-05 09:35:49 -04:00
|
|
|
# ilistdir
|
2023-08-22 11:15:46 -04:00
|
|
|
i = os.ilistdir()
|
2017-05-05 09:35:49 -04:00
|
|
|
print(next(i))
|
|
|
|
try:
|
|
|
|
next(i)
|
|
|
|
except StopIteration:
|
|
|
|
print("StopIteration")
|
|
|
|
try:
|
|
|
|
next(i)
|
|
|
|
except StopIteration:
|
|
|
|
print("StopIteration")
|
|
|
|
|
2017-03-13 06:42:02 -04:00
|
|
|
# referencing the mount point in different ways
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.listdir("test_mnt"))
|
|
|
|
print(os.listdir("/test_mnt"))
|
2017-03-13 06:42:02 -04:00
|
|
|
|
|
|
|
# mounting another filesystem
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount(Filesystem(2), "/test_mnt2", readonly=True)
|
|
|
|
print(os.listdir())
|
|
|
|
print(os.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:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount(Filesystem(3), "/test_mnt2")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
|
|
|
print("OSError")
|
|
|
|
|
|
|
|
# mkdir of a mount point
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mkdir("/test_mnt")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
|
|
|
print("OSError")
|
|
|
|
|
|
|
|
# rename across a filesystem
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.rename("/test_mnt/a", "/test_mnt2/b")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
|
|
|
print("OSError")
|
|
|
|
|
|
|
|
# delegating to mounted filesystem
|
2023-08-22 11:15:46 -04: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 06:42:02 -04:00
|
|
|
open("test_file")
|
|
|
|
open("test_file", "wb")
|
|
|
|
|
|
|
|
# umount
|
2023-08-22 11:15:46 -04:00
|
|
|
os.umount("/test_mnt")
|
|
|
|
os.umount("/test_mnt2")
|
2017-03-14 01:07:30 -04:00
|
|
|
|
|
|
|
# umount a non-existent mount point
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.umount("/test_mnt")
|
2017-03-14 01:07:30 -04:00
|
|
|
except OSError:
|
|
|
|
print("OSError")
|
2017-03-10 01:43:49 -05:00
|
|
|
|
|
|
|
# root dir
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount(Filesystem(3), "/")
|
|
|
|
print(os.stat("/"))
|
|
|
|
print(os.statvfs("/"))
|
|
|
|
print(os.listdir())
|
2017-03-10 01:43:49 -05:00
|
|
|
open("test")
|
|
|
|
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount(Filesystem(4), "/mnt")
|
|
|
|
print(os.listdir())
|
|
|
|
print(os.listdir("/mnt"))
|
|
|
|
os.chdir("/mnt")
|
|
|
|
print(os.listdir())
|
2017-03-10 01:43:49 -05:00
|
|
|
|
|
|
|
# chdir to a subdir within root-mounted vfs, and then listdir
|
2023-08-22 11:15:46 -04:00
|
|
|
os.chdir("/subdir")
|
|
|
|
print(os.listdir())
|
|
|
|
os.chdir("/")
|
2017-03-10 01:43:49 -05:00
|
|
|
|
2023-08-22 11:15:46 -04:00
|
|
|
os.umount("/")
|
|
|
|
print(os.listdir("/"))
|
|
|
|
os.umount("/mnt")
|
2020-05-27 22:50:44 -04:00
|
|
|
|
|
|
|
# chdir to a non-existent mount point (current directory should remain unchanged)
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.chdir("/foo")
|
2020-05-27 22:50:44 -04:00
|
|
|
except OSError:
|
|
|
|
print("OSError")
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.getcwd())
|
2020-05-27 22:50:44 -04:00
|
|
|
|
|
|
|
# chdir to a non-existent subdirectory in a mounted filesystem
|
2023-08-22 11:15:46 -04:00
|
|
|
os.mount(Filesystem(5, 1), "/mnt")
|
2020-05-27 22:50:44 -04:00
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.chdir("/mnt/subdir")
|
2020-05-27 22:50:44 -04:00
|
|
|
except OSError:
|
|
|
|
print("OSError")
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.getcwd())
|