New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subsys: fs: Implementation of ext2 file system #55152
Conversation
4e8c956
to
05815c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave the test a try with a microsd card on a bl5340_dvk_cpuapp and the results were interesting. Tests seemed to run OK until the test that writes an 8MB file and then truncates it - the 8MB write took minutes. Then when the test was finished I moved the card back to the PC to check it and it has used the whole card as the ext2 filesystem (8GB card) without setting up a partition map, so the card's old partition map of a single fat32 partition is still present.
Even more interesting is this:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0 7.8M -20M 28M - /tmp/tt
Something does not seem right here.
I opened the test file in nano which said "this file should be read only", tried writing a new file and it caused a kernel panic on my system. |
@nordicjm Thank you for your comments. My implementation doesn't cover changing the GUID partition table. This is why we have to manually specify the sector where to start looking for the ext2 filesystem or where to create it. I think that implementation of maintaining GPT won’t be a part of this PR. I will update the description to include this information. I will take a look at the problem that you have discovered. Although I know why you got kernel panic, and I will change it as soon as possible. This is due to the flag set by default in the |
9fca75a
to
d42db2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems better but still not right. Modified fatfs sample to use ext2 instead, output (of 8GB card) whereby the zephyr app formats it, I've then created 2 files from a PC:
*** Booting Zephyr OS build zephyr-v3.3.0-1082-gd42db2a1d8c4 ***
[00:00:00.449,340] <inf> sd: Maximum SD clock is under 25MHz, using clock of 8000000Hz
[00:00:00.449,859] <inf> main: Block count 15126528
Sector size 512
Memory Size(MB) 7386
Disk mounted.
Listing dir /SD: ...
[DIR ] lost+found
[FILE] file1 (size = 10)
[FILE] file2 (size = 16736)
However, switch to a PC:
/dev/mmcblk0 7.8M 20K 7.8M 1% /tmp/qq
7.8MB?
Forgot that the limit is 8MB for 1k blocks from the original post
Also:
e2fsck -f /dev/mmcblk0
e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #0 (7919, counted=7918).
Fix<y>? no
Padding at end of block bitmap is not set. Fix<y>? no
ext2: ********** WARNING: Filesystem still has errors **********
ext2: 13/1984 files (7.7% non-contiguous), 274/8192 blocks
This does not look good
Made a filesystem from the PC:
But does not:
Tried again using:
But this just seems to give this:
So how can we actually use this? |
@nordicjm Thank you. The first problem that you have described I have discovered and I am working on it. Actually I have used this implementation already to read some files stored on SD card in Zephyr. I will look at the second problem you have described. |
3336e94
to
32a57bd
Compare
@nordicjm Hi, I have created a sample to allow you to run my implementation as I was doing it. I hope it will work now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*** Booting Zephyr OS build zephyr-v3.3.0-1086-g32a57bd0efc0 ***rt
[00:00:00.288,757] <inf> sd: Maximum SD clock is under 25MHz, using clock of 8000000Hz
Mounted filesystem at '/ext'
total blocks: 32768
free blocks: 30711
block size: 4096
frag size: 4096
[00:00:00.390,594] <err> fs: directory open error (-20)
[00:00:00.396,423] <err> main: Error while listing directory: -20
Using the provided command for formatting and limiting partition size.
@nordicjm Could you give me some more information? Unfortunately I can't reproduce it in my setup (I have made all the steps once again and everything works fine for me). I will add some more logging messages to see what happens. (You can turn it on by setting P.S. Huge thank you for your effort. |
@nordicjm I can see what might cause the problem. You have the inode size set to 256. I haven't mentioned it, but implementation assumes that inodes has size 128. |
I ran the command as your instructions say, can you update it with a fully working example? |
Yes, I will do that and also add check into my implementation to show error when filesystem with wrong config is used. I have assumed the size of inode, because different inode sizes are supported only in ext4. |
f5feb24
to
6344aee
Compare
Make test_fs_dirops test common. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Use test_fs_dirops in ext2 tests. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Introduce fs_sync function Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Make test_fs_basic test common. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Use test_fs_basic test in ext2 tests. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Changes: - Add fs::sync function - Make correct file system in mkfs - Add few assertions to ensure that all assumptions are correct Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Remove 'lost+found' dir in test that expects empty layout of directory. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Changes: - Added few assertions to check if some assumptions are correct - Fix removing blocks during trucate and inode removal - Clear entry in inode table after inode has been removed Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Create tests specific for ext2 implementation. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Added funtion that takes specified action when file system corruption is detected. Possible actions are: do nothing, make mount point read-only, panic. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Fix the behavior when data should be written to storage device. Now all writes are done directly to disk_access layer (where it might possibly be cached). Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Sample for FAT fs is reworked to run also with Ext2 file system Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
- `ext2_file` and `ext2_dir` merged into one struct and allocated from dedicated slab - `ext2_inode` allocated from dedicated slab - `ext2_disk_dentry` allocated from heap (because their size is not constant) - `ext2_bgroup` and `ext2_disk_superblock` statically allocated Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
This commits changes how data on the disk is accessed. There are disk structures which are packed and their fields are stored in little endian byte order. To use data in the program structures it has to be translated from little endian to cpu endianness. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
Add information about new support for ext2 and modified fs sample. Signed-off-by: Franciszek Zdobylak <fzdobylak@antmicro.com>
@de-nordic @peter-mitsis Could you take a look and approve if you still agree with all the changes? |
@peter-mitsis sorry for pinging again, but could you take a look? :) Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the lateness--I thought I had given it a +1, but apparently missed that crucial step.
This PR adds implementation of ext2 file system to Zephyr.
It allows mounting file systems from different disks (accessed by disk_access interface).
Features:
Current limitations:
CONFIG_EXT2_DISK_STARTING_SECTOR
. It also means that GPT won’t be updated if a new file system is created.This supersedes #52895