2017-03-13 10:42:02 +00:00
|
|
|
# test VFS functionality without any particular filesystem type
|
|
|
|
|
|
|
|
try:
|
2018-06-06 04:24:09 +01:00
|
|
|
import uos
|
2017-03-13 10:42:02 +00:00
|
|
|
uos.mount
|
|
|
|
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:
|
|
|
|
def __init__(self, id):
|
|
|
|
self.id = id
|
|
|
|
def mount(self, readonly, mkfs):
|
|
|
|
print(self.id, 'mount', readonly, mkfs)
|
|
|
|
def umount(self):
|
|
|
|
print(self.id, 'umount')
|
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)])
|
2017-03-13 10:42:02 +00:00
|
|
|
def chdir(self, dir):
|
|
|
|
print(self.id, 'chdir', dir)
|
2017-03-14 05:07:30 +00:00
|
|
|
def getcwd(self):
|
|
|
|
print(self.id, 'getcwd')
|
|
|
|
return 'dir%d' % self.id
|
|
|
|
def mkdir(self, path):
|
|
|
|
print(self.id, 'mkdir', path)
|
|
|
|
def remove(self, path):
|
|
|
|
print(self.id, 'remove', path)
|
|
|
|
def rename(self, old_path, new_path):
|
|
|
|
print(self.id, 'rename', old_path, new_path)
|
|
|
|
def rmdir(self, path):
|
|
|
|
print(self.id, 'rmdir', path)
|
|
|
|
def stat(self, path):
|
|
|
|
print(self.id, 'stat', path)
|
|
|
|
return (self.id,)
|
|
|
|
def statvfs(self, path):
|
|
|
|
print(self.id, 'statvfs', path)
|
|
|
|
return (self.id,)
|
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:
|
|
|
|
uos.umount('/')
|
|
|
|
except OSError:
|
|
|
|
pass
|
2017-03-14 11:08:37 +00:00
|
|
|
for path in uos.listdir('/'):
|
|
|
|
uos.umount('/' + path)
|
|
|
|
|
2017-03-14 05:07:30 +00:00
|
|
|
# stat root dir
|
|
|
|
print(uos.stat('/'))
|
|
|
|
|
2017-06-11 13:56:27 +01:00
|
|
|
# statvfs root dir; verify that f_namemax has a sensible size
|
|
|
|
print(uos.statvfs('/')[9] >= 32)
|
2017-06-07 06:17:45 +01:00
|
|
|
|
2017-03-14 05:07:30 +00:00
|
|
|
# getcwd when in root dir
|
|
|
|
print(uos.getcwd())
|
|
|
|
|
2017-03-13 10:42:02 +00:00
|
|
|
# basic mounting and listdir
|
|
|
|
uos.mount(Filesystem(1), '/test_mnt')
|
|
|
|
print(uos.listdir())
|
|
|
|
|
2017-05-05 14:35:49 +01:00
|
|
|
# ilistdir
|
|
|
|
i = uos.ilistdir()
|
|
|
|
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
|
|
|
|
print(uos.listdir('test_mnt'))
|
|
|
|
print(uos.listdir('/test_mnt'))
|
|
|
|
|
|
|
|
# mounting another filesystem
|
|
|
|
uos.mount(Filesystem(2), '/test_mnt2', readonly=True)
|
|
|
|
print(uos.listdir())
|
|
|
|
print(uos.listdir('/test_mnt2'))
|
|
|
|
|
2017-03-14 05:07:30 +00:00
|
|
|
# mounting over an existing mount point
|
|
|
|
try:
|
|
|
|
uos.mount(Filesystem(3), '/test_mnt2')
|
|
|
|
except OSError:
|
|
|
|
print('OSError')
|
|
|
|
|
|
|
|
# mkdir of a mount point
|
|
|
|
try:
|
|
|
|
uos.mkdir('/test_mnt')
|
|
|
|
except OSError:
|
|
|
|
print('OSError')
|
|
|
|
|
|
|
|
# rename across a filesystem
|
|
|
|
try:
|
|
|
|
uos.rename('/test_mnt/a', '/test_mnt2/b')
|
|
|
|
except OSError:
|
|
|
|
print('OSError')
|
|
|
|
|
|
|
|
# delegating to mounted filesystem
|
2017-03-13 10:42:02 +00:00
|
|
|
uos.chdir('test_mnt')
|
|
|
|
print(uos.listdir())
|
2017-03-14 05:07:30 +00:00
|
|
|
print(uos.getcwd())
|
|
|
|
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'))
|
2017-03-13 10:42:02 +00:00
|
|
|
open('test_file')
|
|
|
|
open('test_file', 'wb')
|
|
|
|
|
|
|
|
# umount
|
|
|
|
uos.umount('/test_mnt')
|
|
|
|
uos.umount('/test_mnt2')
|
2017-03-14 05:07:30 +00:00
|
|
|
|
|
|
|
# umount a non-existent mount point
|
|
|
|
try:
|
|
|
|
uos.umount('/test_mnt')
|
|
|
|
except OSError:
|
|
|
|
print('OSError')
|
2017-03-10 06:43:49 +00:00
|
|
|
|
|
|
|
# root dir
|
|
|
|
uos.mount(Filesystem(3), '/')
|
2017-06-07 06:17:45 +01:00
|
|
|
print(uos.stat('/'))
|
|
|
|
print(uos.statvfs('/'))
|
2017-03-10 06:43:49 +00:00
|
|
|
print(uos.listdir())
|
|
|
|
open('test')
|
|
|
|
|
|
|
|
uos.mount(Filesystem(4), '/mnt')
|
|
|
|
print(uos.listdir())
|
|
|
|
print(uos.listdir('/mnt'))
|
|
|
|
uos.chdir('/mnt')
|
|
|
|
print(uos.listdir())
|
|
|
|
|
|
|
|
# chdir to a subdir within root-mounted vfs, and then listdir
|
|
|
|
uos.chdir('/subdir')
|
|
|
|
print(uos.listdir())
|
|
|
|
uos.chdir('/')
|
|
|
|
|
|
|
|
uos.umount('/')
|
|
|
|
print(uos.listdir('/'))
|
|
|
|
uos.umount('/mnt')
|