8000 Some file stats don't make sense with littlefs · Issue #59 · oyama/pico-vfs · GitHub
[go: up one dir, main page]

Skip to content
Some file stats don't make sense with littlefs #59
@Slion

Description

@Slion

I've setup my file system as follow:

#include <stdio.h>
#include <string.h>
#include <hardware/clocks.h>
#include <hardware/flash.h>
#include <pico/filesystem.h>
#include <pico/filesystem/blockdevice/flash.h>
#include <pico/filesystem/blockdevice/sd.h>
#include <pico/filesystem/filesystem/fat.h>
#include <pico/filesystem/filesystem/littlefs.h>
#include <pico/btstack_flash_bank.h>

bool fs_init(void)
{
    // Don't overwrite btstack storage
    size_t eof = PICO_FLASH_BANK_STORAGE_OFFSET;
    size_t size = FLASH_SECTOR_SIZE * 10u;
    blockdevice_t *flash = blockdevice_flash_create(eof-size, size);
    filesystem_t *lfs = filesystem_littlefs_create(500, 16);

    int err = fs_mount("/", lfs, flash);
    if (err!=0)
    {
        printf("Formatting FS\n");
        fs_format(lfs,flash);
        err = fs_mount("/", lfs, flash);
    }

    printf("fs_mount: %d :%s\n", err, fs_strerror(err));

    return true;
}

Then I'm doing some basic tests and printing some of that file stats:

    // Setup our file system
    fs_init();

    // Test our file system
    struct stat stats;
    auto fileName = "/HELLO.TXT";
    if (stat(fileName, &stats) == 0)
    {
        printf("File size / block / blocks: %d / %d / %d\n",stats.st_size, stats.st_blksize, stats.st_blocks);
        // File exists
        FILE * f = fopen (fileName, "rb");
        char content[64];
        fread(content,1,stats.st_size,f);
        fclose(f);
        printf("File content: %s\n",content);
    }
    else
    {
        // File does not exists yet
        FILE *fp = fopen(fileName, "w");
        fprintf(fp, "Hello World!\n");
        fclose(fp);
    }

Here is the output I get:

File size / block / blocks: 13 / 536885040 / 268614845
File content: Hello World!

Block size and block don't make sense to me. Could it be they are not correct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0