littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
5.25k stars 804 forks source link

why t1_buf is sample of t2_buf at sometime? #961

Open c377870675 opened 8 months ago

c377870675 commented 8 months ago
# define TEST_FALSH_LEN     1000
uint8_t w_tbuf[TEST_FALSH_LEN];
uint8_t t1_tbuf[TEST_FALSH_LEN];
uint8_t t2_tbuf[TEST_FALSH_LEN];

lfs_file_t fd = {0};
    int ret = 0;
    int i = 0;
    for(i= 0;i<TEST_FALSH_LEN;i++)
    {
        w_tbuf[i] = i&0xf;
    }
    ret = lfs_file_open(&lfs,&fd,"3.txt",LFS_O_CREAT|LFS_O_RDWR);
    ret =  lfs_file_write(&lfs,&fd,w_tbuf,sizeof(w_tbuf));
    ret =  lfs_file_close(&lfs,&fd);

    for(i= 0;i<TEST_FALSH_LEN;i++)
    {
        w_tbuf[i] = (i+1)&0xf;
    }
    ret = lfs_file_open(&lfs,&fd,"3.bin",LFS_O_CREAT|LFS_O_RDWR);
    ret =  lfs_file_write(&lfs,&fd,w_tbuf,sizeof(w_tbuf));
    ret =  lfs_file_close(&lfs,&fd);

    ret = lfs_file_open(&lfs,&fd,"3.txt",LFS_O_RDONLY);
    ret =  lfs_file_read(&lfs,&fd,t1_tbuf,sizeof(t1_tbuf));
    ret = lfs_file_close(&lfs,&fd);

    ret = lfs_file_open(&lfs,&fd,"3.bin",LFS_O_RDONLY);
    ret =  lfs_file_read(&lfs,&fd,t2_tbuf,sizeof(t2_tbuf));
    ret = lfs_file_close(&lfs,&fd);