os.VfsFat.mkfs failed with RAM Block Device size < 50 sectors

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
bhcuong2008
Posts: 14
Joined: Sun May 30, 2021 7:38 am

os.VfsFat.mkfs failed with RAM Block Device size < 50 sectors

Post by bhcuong2008 » Tue Jun 08, 2021 9:16 am

Hi,

I tried the example in section "Custom Block Device" at below link to study MPY filesystem. I change number of sectors, from 1, 10, 20, 30, 40. All mkfs failed with error

Code: Select all

OSError: [Errno 5] EIO
. From 50 is ok. I dont know why. I try on MPY 1.15, ESP32 port.

https://docs.micropython.org/en/latest/ ... ystem.html

Code: Select all

class RAMBlockDev:
    def __init__(self, block_size, num_blocks):
        self.block_size = block_size
        self.data = bytearray(block_size * num_blocks)

    def readblocks(self, block_num, buf):
        for i in range(len(buf)):
            buf[i] = self.data[block_num * self.block_size + i]

    def writeblocks(self, block_num, buf):
        for i in range(len(buf)):
            self.data[block_num * self.block_size + i] = buf[i]

    def ioctl(self, op, arg):
        if op == 4: # get number of blocks
            return len(self.data) // self.block_size
        if op == 5: # get block size
            return self.block_size

import os

bdev = RAMBlockDev(512, 50)
os.VfsFat.mkfs(bdev)
os.mount(bdev, '/ramdisk')
Has anyone faced this issue?
Many thanks.

bhcuong2008
Posts: 14
Joined: Sun May 30, 2021 7:38 am

Re: os.VfsFat.mkfs failed with RAM Block Device size < 50 sectors

Post by bhcuong2008 » Thu Jun 10, 2021 5:42 pm

After creating RAM disk successfully, I create a file to test import as below. But import gives ENOENT (file not found). But I could read the file by opening and reading it. So what problem with import :roll:

Code: Select all

>>> f1 = open('/ramdisk/test.py', 'w')
>>> f1.write('print("Hello")\n')
15
>>> f1.close()
>>> 
>>> os.listdir('/ramdisk')
['test.py']
>>> os.chdir('ramdisk')
>>> import test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] ENOENT
>>> f1 = open('test.py')
>>> f1.read()
'print("Hello")\n'
>>> 

bhcuong2008
Posts: 14
Joined: Sun May 30, 2021 7:38 am

Re: os.VfsFat.mkfs failed with RAM Block Device size < 50 sectors

Post by bhcuong2008 » Fri Jun 11, 2021 4:55 am

For import to run, after traceback, I found the problem. It needs to enable MICROPY_READER_VFS. It solved now.

Post Reply