123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384letmagic="littlefs"(* for whatever bonkers reason, the major/minor versions
* are big-endian, not little-endian like everything else,
* even though they're not part of a tag and the functions writing
* them in the reference implementations are little-endian functions --
* they're defined as full hex values and then written nibble-by-nibble *)letversion=(2,0)(* major = 2, minor = 0 *)letname_length_max=32l(* apparently this is limited to 1022 *)letfile_size_max=2147483647l(* according to lfs.h in littlefs reference implementation, this is the largest value that will not cause problems with functions that take signed 32-bit integers *)letfile_attribute_size_max=1022l(* reference implementation comments on this limit *)typesuperblock={version_minor:Cstruct.uint16;version_major:Cstruct.uint16;block_size:Cstruct.uint32;block_count:Cstruct.uint32;name_length_max:Cstruct.uint32;file_size_max:Cstruct.uint32;file_attribute_size_max:Cstruct.uint32;}[%%cstructtypesuperblock={version_minor:uint16_t;version_major:uint16_t;block_size:uint32_t;block_count:uint32_t;name_length_max:uint32_t;file_size_max:uint32_t;file_attribute_size_max:uint32_t;}[@@little_endian]]letparsecs={version_minor=get_superblock_version_minorcs;version_major=get_superblock_version_majorcs;block_size=get_superblock_block_sizecs;block_count=get_superblock_block_countcs;name_length_max=get_superblock_name_length_maxcs;file_size_max=get_superblock_file_size_maxcs;file_attribute_size_max=get_superblock_file_attribute_size_maxcs;}letinto_cstructcssb=set_superblock_version_minorcssb.version_minor;set_superblock_version_majorcssb.version_major;set_superblock_block_sizecssb.block_size;set_superblock_block_countcssb.block_count;set_superblock_name_length_maxcssb.name_length_max;set_superblock_file_size_maxcssb.file_size_max;set_superblock_file_attribute_size_maxcssb.file_attribute_size_maxletto_cstructsb=letcs=Cstruct.createsizeof_superblockininto_cstructcssb;csletname=lettag=Tag.({valid=true;type3=LFS_TYPE_NAME,0xff;id=0;length=8;})in(tag,Cstruct.of_stringmagic)letinline_structblock_sizeblock_count=letentry={version_major=(fstversion);version_minor=(sndversion);block_size;block_count;name_length_max;file_size_max;file_attribute_size_max;}andtag=Tag.({valid=true;type3=LFS_TYPE_STRUCT,0x01;id=0;length=sizeof_superblock;})in(tag,to_cstructentry)