2023-08-22 11:15:46 -04:00
|
|
|
import errno
|
|
|
|
import os as os
|
2023-02-23 18:53:59 -05:00
|
|
|
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.VfsFat
|
2023-02-23 18:53:59 -05:00
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
|
|
|
class RAMFS:
|
|
|
|
SEC_SIZE = 512
|
|
|
|
|
|
|
|
def __init__(self, blocks):
|
|
|
|
self.data = bytearray(blocks * self.SEC_SIZE)
|
|
|
|
|
|
|
|
def readblocks(self, n, buf):
|
|
|
|
# print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
|
|
|
for i in range(len(buf)):
|
|
|
|
buf[i] = self.data[n * self.SEC_SIZE + i]
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def writeblocks(self, n, buf):
|
|
|
|
# print("writeblocks(%s, %x)" % (n, id(buf)))
|
|
|
|
for i in range(len(buf)):
|
|
|
|
self.data[n * self.SEC_SIZE + i] = buf[i]
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def ioctl(self, op, arg):
|
|
|
|
# print("ioctl(%d, %r)" % (op, arg))
|
|
|
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
|
|
|
return len(self.data) // self.SEC_SIZE
|
|
|
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
|
|
|
return self.SEC_SIZE
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
bdev = RAMFS(50)
|
|
|
|
except MemoryError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
2023-08-22 11:15:46 -04:00
|
|
|
os.VfsFat.mkfs(bdev)
|
|
|
|
vfs = os.VfsFat(bdev)
|
|
|
|
os.mount(vfs, "/ramdisk")
|
|
|
|
os.chdir("/ramdisk")
|
2023-02-23 18:53:59 -05:00
|
|
|
|
2023-02-24 15:23:59 -05:00
|
|
|
vfs.label = "labelæ"
|
|
|
|
# This label would normally be LABELÆ but our limited upper casing does "LABELæ"
|
|
|
|
print(vfs.label)
|
|
|
|
|
2023-02-23 18:53:59 -05:00
|
|
|
# Check ASCII case-insensitivity
|
2023-02-24 15:23:59 -05:00
|
|
|
vfs.mkdir("fooaz")
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.listdir(""))
|
2023-02-24 15:23:59 -05:00
|
|
|
vfs.rmdir("fOOAZ")
|
|
|
|
|
|
|
|
# Check ASCII case-insensitivity for long names (8+ characters)
|
|
|
|
vfs.mkdir("123456789fooaz")
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.listdir(""))
|
2023-02-24 15:23:59 -05:00
|
|
|
vfs.rmdir("123456789fOOAZ")
|
2023-02-23 18:53:59 -05:00
|
|
|
|
|
|
|
# Characters outside of a-z are case sensitive.
|
|
|
|
vfs.mkdir("extended_æ")
|
2023-08-22 11:15:46 -04:00
|
|
|
print(os.listdir(""))
|
2023-02-24 15:23:59 -05:00
|
|
|
# Normally this would work ok. With our limited uppercasing, it won't.
|
2023-02-23 18:53:59 -05:00
|
|
|
try:
|
|
|
|
vfs.rmdir("extended_Æ")
|
|
|
|
except OSError as e:
|
2023-08-22 11:15:46 -04:00
|
|
|
print(e.errno == errno.ENOENT)
|
2023-02-24 15:23:59 -05:00
|
|
|
|
2023-02-23 18:53:59 -05:00
|
|
|
vfs.rmdir("extended_æ")
|
|
|
|
|
|
|
|
# Emoji test for fun.
|
|
|
|
vfs.mkdir("emoji_😀")
|
|
|
|
vfs.rmdir("emoji_😀")
|