irori / js-fatfs

JavaScript/TypeScript bindings for the FatFs library.
https://www.npmjs.com/package/js-fatfs
Other
4 stars 1 forks source link

Is there a way to use the `MKFS_PARM` struct? #3

Closed acheronfail closed 5 months ago

acheronfail commented 5 months ago

I'm trying to use f_mkfs as documented here: http://elm-chan.org/fsw/ff/doc/mkfs.html

I need to set some specific options with MKFS_PARM (namely the fmt, n_fat and au_size fields). As far as I can tell, fs-fatfs doesn't expose the MKFS_PARM struct? It does expose the f_mkfs function though.

blitzbrian commented 5 months ago

I got it somewhat working using this:

function makeFileSystem(ff: FatFsTypes.FatFs) {
    const work = ff.malloc(FatFs.FF_MAX_SS);

    const fmt = (FatFs.FM_SFD | FatFs.FM_ANY) & 0xff;
    const n_fat = (1 & 0xff) << 8;
    const align = (0 & 0xffff) << 16;
    const n_root = (0 & 0xffff) << 32;
    const au_size = (0 & 0xffffffff) << 48;

    const flags = ff.malloc(8);

    console.log(fmt | n_fat | align | n_root | au_size);

    ff.setValue(flags, fmt | n_fat | align | n_root | au_size, "*");

    ff.f_mkfs("", flags, work, FatFs.FF_MAX_SS);
    ff.free(work);
}
irori commented 5 months ago

In v0.2.0, f_mkfs() accepts opt parameter of type MkfsParams, like this:

    const ff = await FatFs.create({ ... });
    const opts = { fmt: FatFs.FM_FAT, n_fat: 1, align: 0, n_root: 0, au_size: 4096 };
    ff.f_mkfs('', opts, work, FatFs.FF_MAX_SS);
acheronfail commented 5 months ago

Absolutely phenomenal work @irori thank you so much!