Using littlefs - what is the sych function about?

0

The sync function is called once, in the function at the end of this post. Since the file has been written I do not understand synch's purpose. My only supposition is "I suppose synch is to invalidate all the caches so they aren't re-written?" I have searched a lot for example code. is anyone knowledgeable or even a explanation of file syncing may help. Thank you. Here is the function that calls it:

static int lfs_bd_flush(lfs_t *lfs,
    lfs_cache_t *pcache, lfs_cache_t *rcache, bool validate) {
if (pcache->block != 0xffffffff && pcache->block != 0xfffffffe) {
    LFS_ASSERT(pcache->block < lfs->cfg->block_count);
    lfs_size_t diff = lfs_alignup(pcache->size, lfs->cfg->prog_size);
    int err = lfs->cfg->prog(lfs->cfg, pcache->block,
            pcache->off, pcache->buffer, diff);
    if (err) {
        return err;
    }

    if (validate) {
        // check data on disk
        lfs_cache_drop(lfs, rcache);
        int res = lfs_bd_cmp(lfs,
                NULL, rcache, diff,
                pcache->block, pcache->off, pcache->buffer, diff);
        if (res < 0) {
            return res;
        }

        if (res != LFS_CMP_EQ) {
            return LFS_ERR_CORRUPT;
        }
    }

    lfs_cache_zero(lfs, pcache);
}

return 0;

}

synchronization
filesystems

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0