circuitpython/tests/extmod/vfs_fat_oldproto.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.2 KiB
Python
Raw Normal View History

try:
2017-02-14 17:56:22 -05:00
import uerrno
import uos
except ImportError:
2017-02-14 17:56:22 -05:00
print("SKIP")
raise SystemExit
2017-02-14 17:56:22 -05:00
try:
uos.VfsFat
except AttributeError:
print("SKIP")
raise SystemExit
2021-03-15 09:57:36 -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)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
return 0
def writeblocks(self, n, buf):
2021-03-15 09:57:36 -04:00
# 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 sync(self):
pass
def count(self):
return len(self.data) // self.SEC_SIZE
try:
bdev = RAMFS_OLD(50)
except MemoryError:
print("SKIP")
raise SystemExit
uos.VfsFat.mkfs(bdev)
vfs = uos.VfsFat(bdev)
uos.mount(vfs, "/ramdisk")
# file io
with vfs.open("file.txt", "w") as f:
f.write("hello!")
print(list(vfs.ilistdir()))
with vfs.open("file.txt", "r") as f:
print(f.read())
vfs.remove("file.txt")
print(list(vfs.ilistdir()))