mirror of
https://gitee.com/openharmony/third_party_littlefs
synced 2025-02-13 19:59:50 +00:00
![Christopher Haster](/assets/img/avatar_default.png)
This is only an issue in the weird case that are worn down block is left in the odd state of not being able to change the data that resides on the block. That being said, this does pop up often when simulating wear on block devices. Currently, directory commits checked if the write succeeded by crcing the block to avoid the additional RAM cost for another buffer. However, before this commit, directory commits just checked if the block crc was valid, rather than comparing to the expected crc. This would usually work, unless the block was stuck in a state with valid crc. The fix is to simply compare with the expected crc to find errors.
118 lines
2.5 KiB
Bash
Executable File
118 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eu
|
|
|
|
echo "=== Corrupt tests ==="
|
|
|
|
NAMEMULT=64
|
|
FILEMULT=1
|
|
|
|
lfs_mktree() {
|
|
tests/test.py ${1:-} << TEST
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 1; i < 10; i++) {
|
|
for (int j = 0; j < $NAMEMULT; j++) {
|
|
buffer[j] = '0'+i;
|
|
}
|
|
buffer[$NAMEMULT] = '\0';
|
|
lfs_mkdir(&lfs, (char*)buffer) => 0;
|
|
|
|
buffer[$NAMEMULT] = '/';
|
|
for (int j = 0; j < $NAMEMULT; j++) {
|
|
buffer[j+$NAMEMULT+1] = '0'+i;
|
|
}
|
|
buffer[2*$NAMEMULT+1] = '\0';
|
|
lfs_file_open(&lfs, &file[0], (char*)buffer,
|
|
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
|
|
|
size = $NAMEMULT;
|
|
for (int j = 0; j < i*$FILEMULT; j++) {
|
|
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
}
|
|
|
|
lfs_file_close(&lfs, &file[0]) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
TEST
|
|
}
|
|
|
|
lfs_chktree() {
|
|
tests/test.py ${1:-} << TEST
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 1; i < 10; i++) {
|
|
for (int j = 0; j < $NAMEMULT; j++) {
|
|
buffer[j] = '0'+i;
|
|
}
|
|
buffer[$NAMEMULT] = '\0';
|
|
lfs_stat(&lfs, (char*)buffer, &info) => 0;
|
|
info.type => LFS_TYPE_DIR;
|
|
|
|
buffer[$NAMEMULT] = '/';
|
|
for (int j = 0; j < $NAMEMULT; j++) {
|
|
buffer[j+$NAMEMULT+1] = '0'+i;
|
|
}
|
|
buffer[2*$NAMEMULT+1] = '\0';
|
|
lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0;
|
|
|
|
size = $NAMEMULT;
|
|
for (int j = 0; j < i*$FILEMULT; j++) {
|
|
lfs_file_read(&lfs, &file[0], rbuffer, size) => size;
|
|
memcmp(buffer, rbuffer, size) => 0;
|
|
}
|
|
|
|
lfs_file_close(&lfs, &file[0]) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
TEST
|
|
}
|
|
|
|
echo "--- Sanity check ---"
|
|
rm -rf blocks
|
|
lfs_mktree
|
|
lfs_chktree
|
|
|
|
echo "--- Block corruption ---"
|
|
for i in {0..33}
|
|
do
|
|
rm -rf blocks
|
|
mkdir blocks
|
|
ln -s /dev/zero blocks/$(printf '%x' $i)
|
|
lfs_mktree
|
|
lfs_chktree
|
|
done
|
|
|
|
echo "--- Block persistance ---"
|
|
for i in {0..33}
|
|
do
|
|
rm -rf blocks
|
|
mkdir blocks
|
|
lfs_mktree
|
|
chmod a-w blocks/$(printf '%x' $i)
|
|
lfs_mktree
|
|
lfs_chktree
|
|
done
|
|
|
|
echo "--- Big region corruption ---"
|
|
rm -rf blocks
|
|
mkdir blocks
|
|
for i in {2..255}
|
|
do
|
|
ln -s /dev/zero blocks/$(printf '%x' $i)
|
|
done
|
|
lfs_mktree
|
|
lfs_chktree
|
|
|
|
echo "--- Alternating corruption ---"
|
|
rm -rf blocks
|
|
mkdir blocks
|
|
for i in {2..511..2}
|
|
do
|
|
ln -s /dev/zero blocks/$(printf '%x' $i)
|
|
done
|
|
lfs_mktree
|
|
lfs_chktree
|
|
|
|
echo "--- Results ---"
|
|
tests/stats.py
|