Create and mount RAM file system fails

Hello all,

  1. My goal is: I want to create a file system in RAM, for long term storge
  2. My actions are:

I tried to follow the instructions from : https://mongoose-os.com/docs/mongoose-os/api/drivers/vfs-common.md

Here is my code:

#define FS_PATH             "/mnt"
#define FS_TYPE             "RAM"
#define FS_SIZE             65536 
#define FS_ERASE_BYTE       0
#define FS_FILL_BYTE        0
#define FS_FLASH_CHECK      0


/** Creates and mountes a file system*/
void init_filesystem()
{      
    bool ret_val = false;   
    char *fs_address = malloc(FS_SIZE);
    char ram_dev_opts[128];
    char ram_fs_opts[128];
   
    // Register fielsystem type and make it available for use in mkfs and mount. 
    ret_val = mgos_vfs_dev_ram_init();
    if(!ret_val){
        LOG(LL_ERROR, ("Filesystem could not be registered. Aborting."));
        return;
    }
    
    

    sprintf(ram_dev_opts, "{addr: %d, size: %d, erase_byte: %d, fill_byte: %d, flash_check: %d}", (int32_t) fs_address, FS_SIZE, FS_ERASE_BYTE, FS_FILL_BYTE, FS_FLASH_CHECK);
    sprintf(ram_fs_opts, "{addr: %d, size: %d}", (int32_t) fs_address, FS_SIZE);

    //  Create the filesystem.
    ret_val = mgos_vfs_mkfs(MGOS_VFS_DEV_TYPE_RAM, ram_dev_opts, "LFS", ram_fs_opts);
    if(!ret_val){
        LOG(LL_ERROR, ("Filesystem could not be created. Aborting."));
        return;
    }

    // Mount the filesystem
    ret_val = mgos_vfs_mount(FS_PATH, MGOS_VFS_DEV_TYPE_RAM, ram_dev_opts, "LFS", ram_fs_opts);
    if(!ret_val){
        LOG(LL_ERROR, ("Filesystem could not be mounted. Aborting."));
        return;
    }
}
  1. The result I see is:
mgos_vfs_dev_ram.c:82   65536 bytes @ 0x3ffc85a8, eb 0x00, fb 0x00, fc no
[Jul  9 17:50:48.690] mgos_vfs.c:101          Create LFS (dev 0x3ffc84f4, opts {addr: 1073513896, size: 65536})
[Jul  9 17:50:48.699] mgos_vfs_lfs.c:248      size 65536 rs 64 ps 64 bs 4096 => 0
[Jul  9 17:50:48.704] mgos_vfs_dev.c:203       refs 0
[Jul  9 17:50:48.708] mgos_vfs_dev_ram.c:82   65536 bytes @ 0x3ffc85a8, eb 0x00, fb 0x00, fc no
[Jul  9 17:50:48.714] mgos_vfs.c:148          /mnt: LFS @ , opts {addr: 1073513896, size: 65536}
[Jul  9 17:50:48.721] lfs error:966: Corrupted dir pair at 0 1
[Jul  9 17:50:48.725] mgos_vfs_lfs.c:224      size 65536 rs 64 ps 64 bs 4096 => -84
[Jul  9 17:50:48.730] mgos_vfs.c:156          FS LFS {addr: 1073513896, size: 65536}: mount failed
[Jul  9 17:50:48.738] mgos_vfs_dev.c:203       refs 0
[Jul  9 17:50:48.741] filesystem.c:38         Filesystem could not be mounted. Aborting.
  1. My expectation & question is:
    I would like to get some instruction on how a RAM file system must be correctly created. I clearly get some stuff wrong.

Thank you

Hello.
I have the same issue. Found that mgos_vfs_mount inside creates device again and call mgos_vfs_dev_create_int → dev->ops->open(dev, opts) → mgos_vfs_dev_ram_open.
mgos_vfs_dev_ram_open call memset(dd->data, fb, dd->size); As a result clean memory.

To resolve this you can:

  1. Fix this memset.

  2. Or create device manually and use it to make filesystem and mount device:

     // Create device
     mgos_vfs_dev_ram_init();
     struct mgos_vfs_dev *dev = mgos_vfs_dev_create(MGOS_VFS_DEV_TYPE_RAM, ram_dev_opts);
     
     // Create FS
     mgos_vfs_fs_lfs_init();
     sprintf(ram_fs_opts, "{size: %d, bs: %d, is: %d}", FS_SIZE, FS_BLOCK_SIZE, FS_READ_SIZE);
     mgos_vfs_mkfs_dev(dev, MGOS_VFS_FS_TYPE_LFS, ram_fs_opts);
     
     // Mount
     mgos_vfs_mount_dev(FS_PATH, dev, MGOS_VFS_FS_TYPE_LFS, ram_fs_opts);
     
     // Clouse
     mgos_vfs_dev_close(dev);