2017-01-27 04:34:36 +00:00
|
|
|
try:
|
2022-08-18 07:57:45 +01:00
|
|
|
import errno
|
|
|
|
import os
|
2017-01-27 04:34:36 +00:00
|
|
|
except ImportError:
|
2017-02-14 22:56:22 +00:00
|
|
|
print("SKIP")
|
2017-06-10 18:14:16 +01:00
|
|
|
raise SystemExit
|
2017-02-14 22:56:22 +00:00
|
|
|
|
2016-10-25 11:14:38 +01:00
|
|
|
try:
|
2022-08-18 07:57:45 +01:00
|
|
|
os.VfsFat
|
2016-10-25 11:14:38 +01:00
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
2017-06-10 18:14:16 +01:00
|
|
|
raise SystemExit
|
2016-10-25 11:14:38 +01:00
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
|
2016-10-25 11:14:38 +01:00
|
|
|
class RAMFS_OLD:
|
|
|
|
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]
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
def sync(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def count(self):
|
|
|
|
return len(self.data) // self.SEC_SIZE
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
2017-01-24 09:55:05 +00:00
|
|
|
bdev = RAMFS_OLD(50)
|
2016-10-25 11:14:38 +01:00
|
|
|
except MemoryError:
|
|
|
|
print("SKIP")
|
2017-06-10 18:14:16 +01:00
|
|
|
raise SystemExit
|
2016-10-25 11:14:38 +01:00
|
|
|
|
2022-08-18 07:57:45 +01:00
|
|
|
os.VfsFat.mkfs(bdev)
|
|
|
|
vfs = os.VfsFat(bdev)
|
|
|
|
os.mount(vfs, "/ramdisk")
|
2016-10-25 11:14:38 +01:00
|
|
|
|
|
|
|
# file io
|
|
|
|
with vfs.open("file.txt", "w") as f:
|
|
|
|
f.write("hello!")
|
|
|
|
|
2017-05-05 14:35:49 +01:00
|
|
|
print(list(vfs.ilistdir()))
|
2016-10-25 11:14:38 +01:00
|
|
|
|
|
|
|
with vfs.open("file.txt", "r") as f:
|
|
|
|
print(f.read())
|
|
|
|
|
|
|
|
vfs.remove("file.txt")
|
2017-05-05 14:35:49 +01:00
|
|
|
print(list(vfs.ilistdir()))
|