2016-10-25 06:14:38 -04:00
|
|
|
import sys
|
|
|
|
import uerrno
|
2017-01-26 23:34:36 -05:00
|
|
|
try:
|
|
|
|
import uos_vfs as uos
|
|
|
|
except ImportError:
|
|
|
|
import uos
|
2016-10-25 06:14:38 -04:00
|
|
|
try:
|
|
|
|
uos.VfsFat
|
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
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 04:55:05 -05:00
|
|
|
bdev = RAMFS_OLD(50)
|
2016-10-25 06:14:38 -04:00
|
|
|
except MemoryError:
|
|
|
|
print("SKIP")
|
|
|
|
sys.exit()
|
|
|
|
|
2017-01-26 23:34:36 -05:00
|
|
|
uos.VfsFat.mkfs(bdev)
|
|
|
|
vfs = uos.VfsFat(bdev)
|
|
|
|
uos.mount(vfs, "/ramdisk")
|
2016-10-25 06:14:38 -04:00
|
|
|
|
|
|
|
# file io
|
|
|
|
with vfs.open("file.txt", "w") as f:
|
|
|
|
f.write("hello!")
|
|
|
|
|
|
|
|
print(vfs.listdir())
|
|
|
|
|
|
|
|
with vfs.open("file.txt", "r") as f:
|
|
|
|
print(f.read())
|
|
|
|
|
|
|
|
vfs.remove("file.txt")
|
|
|
|
print(vfs.listdir())
|