2017-01-26 23:34:36 -05:00
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
import errno
|
|
|
|
import os
|
2017-01-26 23:34:36 -05:00
|
|
|
except ImportError:
|
2017-02-14 17:56:22 -05:00
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2017-02-14 17:56:22 -05:00
|
|
|
|
2016-10-25 06:14:38 -04:00
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
os.VfsFat
|
2016-10-25 06:14:38 -04:00
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2016-10-25 06:14:38 -04:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2016-10-25 06:14:38 -04:00
|
|
|
class RAMFS_OLD:
|
|
|
|
SEC_SIZE = 512
|
|
|
|
|
|
|
|
def __init__(self, blocks):
|
|
|
|
self.data = bytearray(blocks * self.SEC_SIZE)
|
|
|
|
|
|
|
|
def readblocks(self, n, buf):
|
2021-03-15 09:57:36 -04:00
|
|
|
# print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
|
2016-10-25 06:14:38 -04:00
|
|
|
for i in range(len(buf)):
|
|
|
|
buf[i] = self.data[n * self.SEC_SIZE + i]
|
2018-06-14 21:02:12 -04:00
|
|
|
return 0
|
2016-10-25 06:14:38 -04:00
|
|
|
|
|
|
|
def writeblocks(self, n, buf):
|
2021-03-15 09:57:36 -04:00
|
|
|
# print("writeblocks(%s, %x)" % (n, id(buf)))
|
2016-10-25 06:14:38 -04:00
|
|
|
for i in range(len(buf)):
|
|
|
|
self.data[n * self.SEC_SIZE + i] = buf[i]
|
2018-06-14 21:02:12 -04:00
|
|
|
return 0
|
2016-10-25 06:14:38 -04:00
|
|
|
|
|
|
|
def sync(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def count(self):
|
|
|
|
return len(self.data) // self.SEC_SIZE
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
2017-01-24 04:55:05 -05:00
|
|
|
bdev = RAMFS_OLD(50)
|
2016-10-25 06:14:38 -04:00
|
|
|
except MemoryError:
|
|
|
|
print("SKIP")
|
2017-06-10 13:14:16 -04:00
|
|
|
raise SystemExit
|
2016-10-25 06:14:38 -04:00
|
|
|
|
2023-08-22 11:15:46 -04:00
|
|
|
os.VfsFat.mkfs(bdev)
|
|
|
|
vfs = os.VfsFat(bdev)
|
|
|
|
os.mount(vfs, "/ramdisk")
|
2016-10-25 06:14:38 -04:00
|
|
|
|
|
|
|
# file io
|
|
|
|
with vfs.open("file.txt", "w") as f:
|
|
|
|
f.write("hello!")
|
|
|
|
|
2017-05-05 09:35:49 -04:00
|
|
|
print(list(vfs.ilistdir()))
|
2016-10-25 06:14:38 -04:00
|
|
|
|
|
|
|
with vfs.open("file.txt", "r") as f:
|
|
|
|
print(f.read())
|
|
|
|
|
|
|
|
vfs.remove("file.txt")
|
2017-05-05 09:35:49 -04:00
|
|
|
print(list(vfs.ilistdir()))
|