1 year, 7 months ago.

File closing in littlefs

Hi All,

I'm new to file system, I tried to mount LittleFS on my serial flash. I'm able to mount littleFS, open file, write and read. But once I tried to close it, it never coming out from the close API.

lfs_t lfs; lfs_file_t file;

int Fileerr2; mount the filesystem int Fileerr = lfs_mount(&lfs, &cfg);

reformat if we can't mount the filesystem this should only happen on the first boot if (Fileerr) { Fileerr2= lfs_format(&lfs, &cfg); lfs_mount(&lfs, &cfg);

} if (Fileerr2) { printf("File not mounted\n"); }

/* open the file in read/write mode or create it if doesn't exists */ int l_i32_error = lfs_file_opencfg(&lfs, &file, "boot_count", LFS_O_RDWR | LFS_O_CREAT, &file_cfg);

Fileerr2 = lfs_file_open(&lfs, &file, "boot_count", LFS_O_RDWR | LFS_O_CREAT);

Fileerr2 = lfs_file_read(&lfs, &file, &boot_count, sizeof(boot_count)); boot_count = 10; lfs_file_rewind(&lfs, &file); Fileerr2 = lfs_file_write(&lfs, &file, &boot_count, 256); sizeof(boot_count) boot_count = 0; lfs_file_rewind(&lfs, &file); Fileerr2 = lfs_file_read(&lfs, &file, &boot_count,256 );sizeof(boot_count) remember the storage is not updated until the file is closed successfully

Fileerr2 = lfs_file_close(&lfs, &file);

release any resources we were using Fileerr2 = lfs_unmount(&lfs);

print the boot count printf("boot_count: %d\n", boot_count);

Please let me know what I miss here.

Thanks, Basava.

Be the first to answer this question.