what file system
what file system
Does the latest micropython (1.17.0, 2021-09-02) use FAT or LittleFS? Is there a sys or os cmd that might tell me?
Re: what file system
You can have either files system on the flash of your device, depding on how you initialize it. AFAIK, the default is LittleFS. Damien once made a little script that checks the file system:
Code: Select all
"""
Dump info about a filesystem.
"""
import sys, struct
def pr(addr, label, data):
if type(data) == bytes or type(data) == bytearray:
data = ':'.join('%02x' % b for b in data)
print('%04x %-32s %s' % (addr, label, data))
def decode_bootsec_fat(b):
print('FAT filesystem')
pr(0, 'jump', b[0:3])
pr(3, 'OEM name', str(b[3:11], 'ascii'))
pr(11, 'sector size (bytes)', struct.unpack_from('<H', b, 11)[0])
pr(13, 'cluster size (sectors)', struct.unpack_from('<B', b, 13)[0])
pr(14, 'reserved area (sectors)', struct.unpack_from('<H', b, 14)[0])
pr(16, 'number of FATs', struct.unpack_from('<B', b, 16)[0])
pr(17, 'size of root dir area', struct.unpack_from('<H', b, 17)[0])
pr(19, 'volume size (sectors)', struct.unpack_from('<H', b, 19)[0])
pr(21, 'media descsriptor', hex(struct.unpack_from('<B', b, 21)[0]))
pr(22, 'FAT size (sectors)', struct.unpack_from('<H', b, 22)[0])
pr(24, 'track size (sectors)', struct.unpack_from('<H', b, 24)[0])
pr(26, 'number of heads', struct.unpack_from('<H', b, 26)[0])
pr(28, 'volume offset (sectors)', struct.unpack_from('<L', b, 28)[0])
pr(32, 'volume size (32-bit) (sectors)', struct.unpack_from('<I', b, 32)[0])
pr(36, 'physical drive number', struct.unpack_from('<B', b, 36)[0])
pr(37, 'error flag', hex(struct.unpack_from('<B', b, 37)[0]))
pr(38, 'extended boot signature', hex(struct.unpack_from('<B', b, 38)[0]))
pr(39, 'volume serial number', hex(struct.unpack_from('<L', b, 39)[0]))
pr(43, 'volume label', str(b[43:51], 'ascii'))
pr(54, 'filesystem type', str(b[54:62], 'ascii'))
pr(510, 'signature', hex(struct.unpack_from('<H', b, 510)[0]))
def decode_bootsec_lfs1(b):
print("Littlefs v1 filesystem")
pr(24, "type", struct.unpack_from("<I", b, 24)[0])
pr(25, "elen", struct.unpack_from("<I", b, 25)[0])
pr(26, "alen", struct.unpack_from("<I", b, 26)[0])
pr(27, "nlen", struct.unpack_from("<I", b, 27)[0])
pr(28, "block_size", struct.unpack_from("<I", b, 28)[0])
pr(32, "block_count", struct.unpack_from("<I", b, 32)[0])
pr(36, "version", hex(struct.unpack_from("<I", b, 36)[0]))
pr(40, "magic", str(b[40:40 + 8], 'ascii'))
def decode_bootsec_lfs2(b):
print("Littlefs v2 filesystem")
pr(8, "magic", str(b[8:8 + 8], "ascii"))
pr(20, "version", hex(struct.unpack_from("<I", b, 20)[0]))
pr(24, "block_size", struct.unpack_from("<I", b, 24)[0])
pr(28, "block_count", struct.unpack_from("<I", b, 28)[0])
pr(32, "name_max", struct.unpack_from("<I", b, 32)[0])
pr(36, "file_max", struct.unpack_from("<I", b, 36)[0])
pr(40, "attr_max", struct.unpack_from("<I", b, 40)[0])
def decode_bootsec(b):
if b[40:48] == b"littlefs":
decode_bootsec_lfs1(b)
elif b[8:16] == b"littlefs":
decode_bootsec_lfs2(b)
else:
decode_bootsec_fat(b)
def main():
if sys.platform == 'pyboard':
import pyb
#sd = pyb.SDCard()
sd = pyb.Flash(start=0)
bootsec = bytearray(512)
sd.readblocks(0, bootsec)
elif sys.platform in ('esp8266', 'esp32'):
import esp
bootsec = bytearray(512)
esp.flash_read(esp.flash_user_start(), bootsec)
else:
with open(sys.argv[1], 'rb') as f:
bootsec = f.read(512)
decode_bootsec(bootsec)
main()
Re: what file system
Tnx Rob, Mr. George's script confirms LittleFS. Couple of quick questions if I may:
1) The 2Mb of flash on this Lolin D32 is plenty for my 300 line micropython programs but the 100kb of ram is proving a bottle neck. Is there a way to make a bit more ram available for user code from micropython?
2) I quite liked using nvs_get & nvs_set on pycom devices. Is there a way to access the NVS lib from upython 1.17.0 ?
1) The 2Mb of flash on this Lolin D32 is plenty for my 300 line micropython programs but the 100kb of ram is proving a bottle neck. Is there a way to make a bit more ram available for user code from micropython?
2) I quite liked using nvs_get & nvs_set on pycom devices. Is there a way to access the NVS lib from upython 1.17.0 ?
Re: what file system
Damien's script returned... UnicodeError:
Does my MicroPython v1.17-805-g7b1d10d69-dirty... use FAT or LittleFS?
I made no changes from default.
If FAT wich one is used 12,16,32 and what cluster size is it set to.
I need to know the folder capacity I will have.
Will be logging 1 file a day for >4yrs ~3Kb per file
Code: Select all
FAT filesystem
0000 jump ff:ff:ff
♦Traceback (most recent call last):
File "<stdin>", line 85, in <module>
File "<stdin>", line 83, in main
File "<stdin>", line 67, in decode_bootsec
File "<stdin>", line 16, in decode_bootsec_fat
UnicodeError:
♦>
MicroPython v1.17-805-g7b1d10d69-dirty on 2022-04-11; 4MB/OTA/SPIram module with ESP32
Type "help()" for more information.
>>>
>>>
Does my MicroPython v1.17-805-g7b1d10d69-dirty... use FAT or LittleFS?
I made no changes from default.
If FAT wich one is used 12,16,32 and what cluster size is it set to.
I need to know the folder capacity I will have.
Will be logging 1 file a day for >4yrs ~3Kb per file
Last edited by PM-TPI on Wed Jul 20, 2022 5:59 pm, edited 1 time in total.
Re: what file system
KJM wrote: ↑Tue Jan 18, 2022 9:19 pmTnx Rob, Mr. George's script confirms LittleFS. Couple of quick questions if I may:
1) The 2Mb of flash on this Lolin D32 is plenty for my 300 line micropython programs but the 100kb of ram is proving a bottle neck. Is there a way to make a bit more ram available for user code from micropython?
2) I quite liked using nvs_get & nvs_set on pycom devices. Is there a way to access the NVS lib from upython 1.17.0 ?
- With the D32, you can't expand the RAM. The D32 Pro comes with 4 MB of (slightly slower) PSRAM.
- yes: please see Non-Volatile Storage
Re: what file system
You can get the capacity of the file system with:I need to know the folder capacity I will have.
import os
os.statvfs("")
Which returns a tuple with the the first [0] (and second) being the block size, the third [2] being the number of blocks an the 4th [3] being the number of free blocks. When formatted as FAT, it is FAT12.
Re: what file system
I am using a 2GB SD
sooo....
32768KB * 60469 = 1 981 448 192 ~ 2GB
and all that is usable?
I will have 1 .csv file ~ 5KB, and 1 .txt file ~1KB each day
2GB/6KB = 333K pair of files...
Is this correct?
5yr of files would be 3650
so am I good to go?
sooo....
Code: Select all
>>>uos.statvfs('/sd/data')
(32768, 32768, 60469, 60463, 60463, 0, 0, 0, 0, 255)
and all that is usable?
I will have 1 .csv file ~ 5KB, and 1 .txt file ~1KB each day
2GB/6KB = 333K pair of files...
Is this correct?
5yr of files would be 3650
so am I good to go?
Re: what file system
If you have a 2 GB card you can use it up to that space. The 2GB card will most likely by FAT32, if (since) you formatted it on a PC.
Re: what file system
Never formatted cards...
We have units mfg in China
https://www.thermcoproducts.com/SmartLO ... C-DDL.html
looked to see what it says in format... FAT(default) w/allocation unit size = 32KB
and Windows property says FAT
I wish FAT were more specific FAT12 FAT16 FAT32
Even in micropython doc's just says FAT
Can FAT32 cards be Used ???
This came about when we purchased data loggers that used the root for files... we hit 512 files DONE.
I am trying to make sure we have no storage issues.
We have units mfg in China
https://www.thermcoproducts.com/SmartLO ... C-DDL.html
looked to see what it says in format... FAT(default) w/allocation unit size = 32KB
and Windows property says FAT
I wish FAT were more specific FAT12 FAT16 FAT32
Even in micropython doc's just says FAT
Can FAT32 cards be Used ???
This came about when we purchased data loggers that used the root for files... we hit 512 files DONE.
I am trying to make sure we have no storage issues.
Re: what file system
In general, FAT32 cards can be used with MicroPython. The internal flash, when sued as file storage, is formatted as FAT12. SDCards are usually formatted as FAT32.