Add support for symlink creation in EXT4
Subsystems (2)
v2 cover Add support for symlink creation in EXT4
This series adds support for the creation of symbolic links on ext4 file-systems.
The motivation behind this work is to have the ability to "do" the job of update-alternatives in u-boot.
Firmware on TI's platform are usually managed with update-alternatives and are thus targeted by a symbolic link. In some situations we need the ability to select an alternate firmware before the linux kernel is started so that when a early driver needing the firmware comes up, it can be fed the firmware of our choice.
Tested on a am57xx_evm, using a EXT4 partition on external SDcard. The filesystem can be checked later with: fsck.ext4 -f <dev>
usage example:
=> ln mmc 0:2 zImage /boot/the_linux_kernel
Changes in v2:
- Prevent write access if metadata checksum is enabled
- Add a FS integrity check at the end of the FS tests
- Fix issue in ext4fs_delete_file() when target in not stored in an allocated block
- Added python tests for symlinks under sandbox
Jean-Jacques Hiblot (7):
fs: ext4: do not allow writes if metadata checksum is active
test: fs: disable the metadata checksums on ext4 filesystems
test: fs: run fsck after on fs image after the tests are run
fs: ext4: constify the buffer passed to write functions
fs: ext4: Add support for the creation of symbolic links
fs: Add a new command to create symbolic links
test: fs: Added tests for symlinks
cmd/fs.c | 14 +++ fs/ext4/ext4_common.c | 4 +- fs/ext4/ext4_common.h | 2 +- fs/ext4/ext4_write.c | 76 ++++++++++++---- fs/fs.c | 44 +++++++++ include/ext4fs.h | 6 +- include/fs.h | 2 + test/py/tests/test_fs/conftest.py | 91 +++++++++++++++++++ test/py/tests/test_fs/fstest_defs.py | 3 + test/py/tests/test_fs/test_symlink.py | 125 ++++++++++++++++++++++++++ 10 files changed, 345 insertions(+), 22 deletions(-) create mode 100644 test/py/tests/test_fs/test_symlink.py
Signature · 1 line
2.17.1
PATCH v2 1/7 fs: ext4: do not allow writes if metadata checksum is active
u-boot does not supports updating the metadata chacksums
---
Changes in v2:
- Prevent write access if metadata checksum is enabled
fs/ext4/ext4_write.c | 12 ++++++++++-- include/ext4fs.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-)
fs/ext4/ext4_write.c +10 -2
@@ -858,12 +858,19 @@ int ext4fs_write(const char *fname, unsigned char *buffer, g_parent_inode =zalloc (fs->inodesz);if (!g_parent_inode) - goto fail; + goto fail_ext4fs_init;if (ext4fs_init () !=0 ) {printf ("error in File System init\n" ); -return -1 ; + goto fail_ext4fs_init; + } + +if (le32_to_cpu (fs->sb->feature_ro_compat) & +EXT4_FEATURE_RO_COMPAT_METADATA_CSUM ) { +printf ("u-boot doesn't support updating the metadata checksums yet\n" ); + goto fail; } + inodes_per_block = fs->blksz / fs->inodesz; parent_inodeno =ext4fs_get_parent_inode_num (fname, filename,F_FILE );if (parent_inodeno ==-1 )
@@ -990,6 +997,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer,return 0 ; fail:ext4fs_deinit (); +fail_ext4fs_init:free (inode_buffer);free (g_parent_inode);free (temp_ptr);
include/ext4fs.h +1 -0
@@ -32,6 +32,7 @@#define EXT4_EXTENTS_FL 0x00080000/* Inode uses extents */ #define EXT4_EXT_MAGIC 0xf30a#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 +#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080#define EXT4_INDIRECT_BLOCKS 12
Signature · 1 line
2.17.1
PATCH v2 1/7 fs: ext4: do not allow writes if metadata checksum is active
Quoted 4 lines · Jean-Jacques Hiblot
u-boot does not supports updating the metadata chacksums
Signed-off-by Jean-Jacques Hiblot <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/7496ccb1/attachment.sig>
PATCH v2 1/7 fs: ext4: do not allow writes if metadata checksum is active
In reply to Jean-Jacques HiblotQuoted 29 lines · Jean-Jacques Hiblot
u-boot does not supports updating the metadata chacksums
Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2:
- Prevent write access if metadata checksum is enabledfs/ext4/ext4_write.c | 12 ++++++++++-- include/ext4fs.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-)fs/ext4/ext4_write.c +3
-2@@ -858,12 +858,19 @@ int ext4fs_write(const char *fname, unsigned char *buffer, g_parent_inode =zalloc (fs->inodesz);if (!g_parent_inode) - goto fail; + goto fail_ext4fs_init;if (ext4fs_init () !=0 ) {printf ("error in File System init\n" ); -return -1 ; + goto fail_ext4fs_init; + }
fs/ext4/ext4_write.c int ext4fs_write(const char *fname, unsigned char *buffer, · line 876
Quoted 10 lines
fs/ext4/ext4_write.c +6
-0+ +if (le32_to_cpu (fs->sb->feature_ro_compat) & +EXT4_FEATURE_RO_COMPAT_METADATA_CSUM ) { +printf ("u-boot doesn't support updating the metadata checksums yet\n" ); + goto fail; } + inodes_per_block = fs->blksz / fs->inodesz; parent_inodeno =ext4fs_get_parent_inode_num (fname, filename,F_FILE );if (parent_inodeno ==-1 )
I'm following up to myself on this one as, Ugh. To repeat myself from a while back:
commit 6f94ab6656ceffb3f2a972c8de4c554502b6f2b7
Author: Tom Rini <[email protected]> Date: Fri Jul 22 17:59:11 2016 -0400
ext4: Refuse to mount filesystems with 64bit feature set
With e2fsprogs after 1.43 the 64bit and metadata_csum features are enabled by default. The metadata_csum feature changes how ext4_group_desc->bg_checksum is calculated, which would break write support. The 64bit feature however introduces changes such that it cannot be read by implementations that do not support it. Since we do not support this, we must not mount it.
Which means that starting way back then I should have also done something to say we cannot write to these new images either. It's good and important to finally catch this failure now. I suspect it's however going to start to be an unexpected problem. Have you any idea how much work would go in to supporting the metadata_csum feature? Thanks again!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/a86c6b0a/attachment.sig>
PATCH v2 1/7 fs: ext4: do not allow writes if metadata checksum is active
Quoted 63 lines · Tom Rini
Quoted 29 lines · Jean-Jacques Hiblot
u-boot does not supports updating the metadata chacksums
Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2:
- Prevent write access if metadata checksum is enabledfs/ext4/ext4_write.c | 12 ++++++++++-- include/ext4fs.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-)fs/ext4/ext4_write.c +3
-2@@ -858,12 +858,19 @@ int ext4fs_write(const char *fname, unsigned char *buffer, g_parent_inode =zalloc (fs->inodesz);if (!g_parent_inode) - goto fail; + goto fail_ext4fs_init;if (ext4fs_init () !=0 ) {printf ("error in File System init\n" ); -return -1 ; + goto fail_ext4fs_init; + }fs/ext4/ext4_write.c int ext4fs_write(const char *fname, unsigned char *buffer, · line 876
Quoted 10 lines
fs/ext4/ext4_write.c +6
-0+ +if (le32_to_cpu (fs->sb->feature_ro_compat) & +EXT4_FEATURE_RO_COMPAT_METADATA_CSUM ) { +printf ("u-boot doesn't support updating the metadata checksums yet\n" ); + goto fail; } + inodes_per_block = fs->blksz / fs->inodesz; parent_inodeno =ext4fs_get_parent_inode_num (fname, filename,F_FILE );if (parent_inodeno ==-1 )I'm following up to myself on this one as, Ugh. To repeat myself from a while back:
commit6f94ab6656ceffb3f2a972c8de4c554502b6f2b7Author: Tom Rini <[email protected]> Date: Fri Jul 22 17:59:11 2016 -0400ext4: Refuse to mount filesystems with 64bit feature set
With e2fsprogs after 1.43 the 64bit and
metadata_csumfeatures are enabled by default. Themetadata_csumfeature changes howext4_group_desc->bg_checksumis calculated, which would break write support. The 64bit feature however introduces changes such that it cannot be read by implementations that do not support it. Since we do not support this, we must not mount it.Cc Stephen Warren <[email protected]>Cc Simon Glass <[email protected]>Cc Lukasz Majewski <[email protected]>Cc Stefan Roese <[email protected]>Reported-by Andrew Bradford <[email protected]>Signed-off-by Tom Rini <[email protected]>
Quoted 5 lines
Which means that starting way back then I should have also done something to say we cannot write to these new images either. It's good and important to finally catch this failure now. I suspect it's however going to start to be an unexpected problem. Have you any idea how much work would go in to supporting the
metadata_csumfeature? Thanks again!
I had a look and this is going to be a non-trivial job. The ext4 code is showing its age. And then there would be another couple of flags to handle too like journal checksuming, and then also hashtree dirs.
There are a couple of ext4 libs out there (I'm thinking of lwext4 or e2fsprogs) that do a much better job at handling the compatible/incompatible/read-only flags. I wonder if we wouldn't be better off adapting one of them than fixing the current implementation.
JJ
Quoted 1 line
PATCH v2 2/7 test: fs: disable the metadata checksums on ext4 filesystems
In reply to Jean-Jacques HiblotIf the metadata checksums are enabled, all write operations will fail.
---
Changes in v2: None
test/py/tests/test_fs/conftest.py | 2 ++ 1 file changed, 2 insertions(+)
test/py/tests/test_fs/conftest.py +2 -0
@@ -143,6 +143,8 @@ def mk_fs(config, fs_type, size, id): mkfs_opt = '-F 16' elif fs_type == 'fat32': mkfs_opt = '-F 32' + elif fs_type == 'ext4': + mkfs_opt = '-O ^metadata_csum' else: mkfs_opt = ''
Signature · 1 line
2.17.1
PATCH v2 2/7 test: fs: disable the metadata checksums on ext4 filesystems
Quoted 3 lines · Jean-Jacques Hiblot
If the metadata checksums are enabled, all write operations will fail.
Signed-off-by Jean-Jacques Hiblot <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/d2d225c3/attachment.sig>
PATCH v2 3/7 test: fs: run fsck after on fs image after the tests are run
In reply to Jean-Jacques HiblotThis is to check the integrity of the FS after the test operations. This is useful to make sure that the operations are implemented properly, and are not going to create silent corruptions.
Currently only the integrity of EXT4 filesystems is checked.
---
Changes in v2:
- Add a FS integrity check at the end of the FS tests
test/py/tests/test_fs/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)
test/py/tests/test_fs/conftest.py +13 -0
@@ -216,6 +216,15 @@ def mount_fs(fs_type, device, mount_point): except CalledProcessError: raise + +def fsck(img, fs_type): + try: + if fs_type == 'ext4': + check_call('fsck.ext4 -n -f %s' % img, shell=True) + except CalledProcessError: + raise + + def umount_fs(mount_point): """Unmount a volume.
@@ -336,6 +345,7 @@ def fs_obj_basic(request, u_boot_config): yield [fs_ubtype, fs_img, md5val] finally: umount_fs(mount_dir) + fsck(fs_img, fs_type) call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True)
@@ -423,6 +433,7 @@ def fs_obj_ext(request, u_boot_config): yield [fs_ubtype, fs_img, md5val] finally: umount_fs(mount_dir) + fsck(fs_img, fs_type) call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True)
@@ -457,6 +468,7 @@ def fs_obj_mkdir(request, u_boot_config): else: yield [fs_ubtype, fs_img] finally: + fsck(fs_img, fs_type) if fs_img: call('rm -f %s' % fs_img, shell=True)
@@ -522,6 +534,7 @@ def fs_obj_unlink(request, u_boot_config): yield [fs_ubtype, fs_img] finally: umount_fs(mount_dir) + fsck(fs_img, fs_type) call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True)
Signature · 1 line
2.17.1
PATCH v2 3/7 test: fs: run fsck after on fs image after the tests are run
Quoted 22 lines · Jean-Jacques Hiblot
This is to check the integrity of the FS after the test operations. This is useful to make sure that the operations are implemented properly, and are not going to create silent corruptions.
Currently only the integrity of EXT4 filesystems is checked.Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2:
- Add a FS integrity check at the end of the FS teststest/py/tests/test_fs/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)test/py/tests/test_fs/conftest.py +0
-0@@ -216,6 +216,15 @@ def mount_fs(fs_type, device, mount_point): except CalledProcessError: raise
test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point): · line 227
Quoted 10 lines
test/py/tests/test_fs/conftest.py +9
-0+ +def fsck(img, fs_type): + try: + if fs_type == 'ext4': + check_call('fsck.ext4 -n -f %s' % img, shell=True) + except CalledProcessError: + raise + +
Why don't we just call 'fsck -f -n ...' and check all filesystems? Force and "make no changes" are both general fsck options and not filesystem specific. And if we're messing up FAT as part of the tests we should know that now :)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/f02b6f9d/attachment.sig>
PATCH v2 3/7 test: fs: run fsck after on fs image after the tests are run
Quoted 36 lines · Tom Rini
Quoted 22 lines · Jean-Jacques Hiblot
This is to check the integrity of the FS after the test operations. This is useful to make sure that the operations are implemented properly, and are not going to create silent corruptions.
Currently only the integrity of EXT4 filesystems is checked.Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2:
- Add a FS integrity check at the end of the FS teststest/py/tests/test_fs/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)test/py/tests/test_fs/conftest.py +0
-0@@ -216,6 +216,15 @@ def mount_fs(fs_type, device, mount_point): except CalledProcessError: raisetest/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point): · line 227
Quoted 10 lines
test/py/tests/test_fs/conftest.py +9
-0+ +def fsck(img, fs_type): + try: + if fs_type == 'ext4': + check_call('fsck.ext4 -n -f %s' % img, shell=True) + except CalledProcessError: + raise + +Why don't we just call 'fsck -f -n ...' and check all filesystems?
Quoted 1 line
Force and "make no changes" are both general fsck options and not
Strange. those options do not appear in the help or manpage.
I'll switch to fsck in the next version
Quoted 4 lines
filesystem specific. And if we're messing up FAT as part of the tests we should know that now :)
PATCH v2 3/7 test: fs: run fsck after on fs image after the tests are run
Quoted 37 lines · Jean-Jacques Hiblot
Quoted 34 lines · Tom Rini
Quoted 21 lines · Jean-Jacques Hiblot
This is to check the integrity of the FS after the test operations. This is useful to make sure that the operations are implemented properly, and are not going to create silent corruptions.
Currently only the integrity of EXT4 filesystems is checked.Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2:
- Add a FS integrity check at the end of the FS teststest/py/tests/test_fs/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)test/py/tests/test_fs/conftest.py +0
-0@@ -216,6 +216,15 @@ def mount_fs(fs_type, device, mount_point): except CalledProcessError:test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point): · line 226
Quoted 10 lines
test/py/tests/test_fs/conftest.py +9
-0raise + +def fsck(img, fs_type): + try: + if fs_type == 'ext4': + check_call('fsck.ext4 -n -f %s' % img, shell=True) + except CalledProcessError: + raise + +Why don't we just call 'fsck -f -n ...' and check all filesystems?
Quoted 5 lines
Quoted 1 line
Force and "make no changes" are both general fsck options and not
Strange. those options do not appear in the help or manpage.
I'll switch to fsck in the next version
Ugh, I take it back and blame myself. You can't just do /sbin/fsck --help and get something like I expected but didn't read closely enough to see it was plumbing down to fsck.ext4. So what you have above is right and the it falls on me to add a patch to fsck.vfat or so later.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/20675ca6/attachment.sig>
PATCH v2 3/7 test: fs: run fsck after on fs image after the tests are run
In reply to Tom RiniQuoted 25 lines · Tom Rini
Quoted 23 lines · Jean-Jacques Hiblot
This is to check the integrity of the FS after the test operations. This is useful to make sure that the operations are implemented properly, and are not going to create silent corruptions.
Currently only the integrity of EXT4 filesystems is checked.Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2:
- Add a FS integrity check at the end of the FS teststest/py/tests/test_fs/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)test/py/tests/test_fs/conftest.py +0
-0@@ -216,6 +216,15 @@ def mount_fs(fs_type, device, mount_point): except CalledProcessError: raise
Quoted 13 lines
test/py/tests/test_fs/conftest.py def mount_fs(fs_type, device, mount_point): · line 227
Quoted 9 lines
test/py/tests/test_fs/conftest.py +9
-0+ +def fsck(img, fs_type): + try: + if fs_type == 'ext4': + check_call('fsck.ext4 -n -f %s' % img, shell=True) + except CalledProcessError: + raise + +Why don't we just call 'fsck -f -n ...' and check all filesystems? Force and "make no changes" are both general fsck options and not filesystem specific. And if we're messing up FAT as part of the tests we should know that now :)
When I tried to enable fsck on all FS, I discovered that calling fsck() at this point won't work.
This is because of the "life-cycle" of pytest fixtures works. How it is done today makes failure report unreliable (the error is reported for the test after the failed one).
I'll try to come up with something but it'll take some time to get used to pytest. Meanwhile I'll drop this from the series.
JJ
Quoted 1 line
PATCH v2 4/7 fs: ext4: constify the buffer passed to write functions
In reply to Jean-Jacques HiblotThere is no need to modify the buffer passed to ext4fs_write_file(). The memset() has no utility there, and comes probably from the equivalent ext4fs_read_file() function.
---
Changes in v2: None
fs/ext4/ext4_common.c | 2 +- fs/ext4/ext4_common.h | 2 +- fs/ext4/ext4_write.c | 11 +++++------ include/ext4fs.h | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-)
fs/ext4/ext4_common.c +1 -1
@@ -190,7 +190,7 @@ uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n)return res; } -void put_ext4 (uint64_t off,void *buf,uint32_t size) +void put_ext4 (u64 off,const void *buf,u32 size) {uint64_t startblock;uint64_t remainder;
fs/ext4/ext4_common.h +1 -1
@@ -72,7 +72,7 @@ int ext4fs_iget(int inode_no, struct ext2_inode *inode);void ext4fs_allocate_blocks (struct ext2_inode *file_inode,unsigned int total_remaining_blocks,unsigned int *total_no_of_block); -void put_ext4 (uint64_t off,void *buf,uint32_t size); +void put_ext4 (u64 off,const void *buf,u32 size);struct ext2_block_group *ext4fs_get_group_descriptor (const struct ext_filesystem *fs,uint32_t bg_idx); uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg,
fs/ext4/ext4_write.c +5 -6
@@ -752,7 +752,7 @@ void ext4fs_deinit(void)* contigous sectors as ext4fs_read_file */ static int ext4fs_write_file (struct ext2_inode *file_inode, -int pos,unsigned int len,char *buf) +int pos,unsigned int len,const char *buf) {int i;int blockcnt;
@@ -764,7 +764,7 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,int delayed_start =0 ;int delayed_extent =0 ;int delayed_next =0 ; -char *delayed_buf =NULL ; +const char *delayed_buf =NULL ;/* Adjust len so it we can't read past the end of the file. */ if (len > filesize)
@@ -816,7 +816,6 @@ static int ext4fs_write_file(struct ext2_inode *file_inode, (uint32_t) delayed_extent); previous_block_number =-1 ; } -memset (buf,0 , fs->blksz - skipfirst); } buf += fs->blksz - skipfirst; }
@@ -830,8 +829,8 @@ static int ext4fs_write_file(struct ext2_inode *file_inode,return len; } -int ext4fs_write (const char *fname,unsigned char *buffer, -unsigned long sizebytes) +int ext4fs_write (const char *fname,const char *buffer, +unsigned long sizebytes) {int ret =0 ;struct ext2_inode *file_inode =NULL ;
@@ -950,7 +949,7 @@ int ext4fs_write(const char *fname, unsigned char *buffer,if (ext4fs_put_metadata (temp_ptr, itable_blkno)) goto fail;/* copy the file content into data blocks */ -if (ext4fs_write_file (file_inode,0 , sizebytes, (char *)buffer) ==-1 ) { +if (ext4fs_write_file (file_inode,0 , sizebytes, buffer) ==-1 ) {printf ("Error in copying content\n" );/* FIXME: Deallocate data blocks */ goto fail;
include/ext4fs.h +1 -1
@@ -128,7 +128,7 @@ extern int gindex;int ext4fs_init (void );void ext4fs_deinit (void );int ext4fs_filename_unlink (char *filename); -int ext4fs_write (const char *fname,unsigned char *buffer, +int ext4fs_write (const char *fname,const char *buffer,unsigned long sizebytes);int ext4_write_file (const char *filename,void *buf,loff_t offset,loff_t len,loff_t *actwrite);
Signature · 1 line
2.17.1
PATCH v2 4/7 fs: ext4: constify the buffer passed to write functions
Quoted 3 lines · Jean-Jacques Hiblot
There is no need to modify the buffer passed to
ext4fs_write_file(). Thememset()has no utility there, and comes probably from the equivalentext4fs_read_file()function.
Can you please clarify the commit message a little? I assume if we re-worded the second sentence to this, it would still be correct:
The memset() call is not required here and was likely copied from the equivalent part of the ext4fs_read_file() function where we do need it.
And if not, can you please explain why we don't need memset? Thanks!
Quoted 29 lines
Signed-off-by Jean-Jacques Hiblot <[email protected]>---
Changes in v2: None
fs/ext4/ext4_common.c | 2 +- fs/ext4/ext4_common.h | 2 +- fs/ext4/ext4_write.c | 11 +++++------ include/ext4fs.h | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-)fs/ext4/ext4_common.c +1
-1@@ -190,7 +190,7 @@ uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n)return res; } -void put_ext4 (uint64_t off,void *buf,uint32_t size) +void put_ext4 (u64 off,const void *buf,u32 size) {uint64_t startblock;uint64_t remainder;fs/ext4/ext4_common.h +0
-0
fs/ext4/ext4_common.h int ext4fs_iget(int inode_no, struct ext2_inode *inode); · line 78
Quoted 8 lines
fs/ext4/ext4_common.h +1
-1@@ -72,7 +72,7 @@ int ext4fs_iget(int inode_no, struct ext2_inode *inode);void ext4fs_allocate_blocks (struct ext2_inode *file_inode,unsigned int total_remaining_blocks,unsigned int *total_no_of_block); -void put_ext4 (uint64_t off,void *buf,uint32_t size); +void put_ext4 (u64 off,const void *buf,u32 size);struct ext2_block_group *ext4fs_get_group_descriptor (const struct ext_filesystem *fs,uint32_t bg_idx); uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg,
Since the rest of the function is using uintXX_t not uXX can you please just change to const?
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/1efef7b4/attachment.sig>
PATCH v2 5/7 fs: ext4: Add support for the creation of symbolic links
In reply to Jean-Jacques HiblotRe-use the functions used to write/create a file, to support creation of a symbolic link.
The difference with a regular file are small:
- The inode mode is flagged with S_IFLNK instead of S_IFREG
- The ext2_dirent's filetype is FILETYPE_SYMLINK instead of FILETYPE_REG
- Instead of storing the content of a file in allocated blocks, the path to the target is stored. And if the target's path is short enough, no block is allocated and the target's path is stored in ext2_inode.b.symlink
As with regulars files, if a file/symlink with the same name exits, it is unlinked first and then re-created.
---
Changes in v2:
- Fix issue in ext4fs_delete_file() when target in not stored in an allocated block
fs/ext4/ext4_common.c | 2 +- fs/ext4/ext4_write.c | 55 +++++++++++++++++++++++++++++++++++-------- include/ext4fs.h | 3 ++- 3 files changed, 48 insertions(+), 12 deletions(-)
fs/ext4/ext4_common.c +1 -1
@@ -607,7 +607,7 @@ restart_read: dir->direntlen =cpu_to_le16 (fs->blksz - totalbytes); dir->namelen =strlen (filename); - dir->filetype =FILETYPE_REG ;/* regular file */ + dir->filetype = file_type; temp_dir = (char *)dir; temp_dir = temp_dir +sizeof (struct ext2_dirent );memcpy (temp_dir, filename,strlen (filename));
fs/ext4/ext4_write.c +45 -10
119 lines not on this page · raw message
include/ext4fs.h +2 -1
@@ -129,9 +129,10 @@ int ext4fs_init(void);void ext4fs_deinit (void );int ext4fs_filename_unlink (char *filename);int ext4fs_write (const char *fname,const char *buffer, -unsigned long sizebytes); +unsigned long sizebytes,int type);int ext4_write_file (const char *filename,void *buf,loff_t offset,loff_t len,loff_t *actwrite); +int ext4fs_create_link (const char *target,const char *fname);#endif struct ext_filesystem *get_fs (void );
Signature · 1 line
2.17.1
PATCH v2 5/7 fs: ext4: Add support for the creation of symbolic links
Quoted 9 lines · Jean-Jacques Hiblot
Re-use the functions used to write/create a file, to support creation of a symbolic link.
The difference with a regular file are small:
- The inode mode is flagged withS_IFLNKinstead ofS_IFREG
- The ext2_dirent's filetype isFILETYPE_SYMLINKinstead ofFILETYPE_REG
- Instead of storing the content of a file in allocated blocks, the path to the target is stored. And if the target's path is short enough, no block is allocated and the target's path is stored in ext2_inode.b.symlink
Quoted 5 lines
As with regulars files, if a file/symlink with the same name exits, it is unlinked first and then re-created.
Signed-off-by Jean-Jacques Hiblot <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/4859ce47/attachment.sig>
PATCH v2 6/7 fs: Add a new command to create symbolic links
In reply to Jean-Jacques HiblotThe command line is:
ln <interface> <dev[:part]> target linkname
Currently symbolic links are supported only in ext4 and only if the option CMD_EXT4_WRITE is enabled.
---
Changes in v2: None
cmd/fs.c | 14 ++++++++++++++ fs/fs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 2 ++ 3 files changed, 60 insertions(+)
cmd/fs.c +14 -0
@@ -74,6 +74,20 @@ U_BOOT_CMD( " device type 'interface' instance 'dev'." ) +static int do_ln_wrapper (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +return do_ln (cmdtp, flag, argc, argv,FS_TYPE_ANY ); +} + +U_BOOT_CMD ( + ln,5 ,1 , do_ln_wrapper, +"Create a symbolic link" , +"<interface> <dev[:part]> target linkname\n" +" - create a symbolic link to 'target' with the name 'linkname' on\n" +" device type 'interface' instance 'dev'." +) +static int do_fstype_wrapper (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {
fs/fs.c +44 -0
103 lines not on this page · raw message
include/fs.h +2 -0
@@ -191,6 +191,8 @@ int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype);int do_mkdir (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[],int fstype); +int do_ln (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[], +int fstype);/* * Determine the UUID of the specified filesystem and print it. Optionally it is
Signature · 1 line
2.17.1
PATCH v2 6/7 fs: Add a new command to create symbolic links
Quoted 7 lines · Jean-Jacques Hiblot
The command line is:
ln <interface> <dev[:part]> target linknameCurrently symbolic links are supported only in ext4 and only if the option
CMD_EXT4_WRITEis enabled.Signed-off-by Jean-Jacques Hiblot <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/e3ad0de1/attachment.sig>
PATCH v2 7/7 test: fs: Added tests for symlinks
In reply to Jean-Jacques HiblotTest cases are:
1) basic link creation, verify it can be followed
2) chained links, verify it can be followed
3) replace exiting file a with a link, and a link with a link. verify it can be followed
4) create a broken link, verify it can't be followed
---
Changes in v2:
- Added python tests for symlinks under sandbox
test/py/tests/test_fs/conftest.py | 76 ++++++++++++++++ test/py/tests/test_fs/fstest_defs.py | 3 + test/py/tests/test_fs/test_symlink.py | 125 ++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 test/py/tests/test_fs/test_symlink.py
test/py/tests/test_fs/conftest.py +76 -0
@@ -13,6 +13,7 @@ supported_fs_basic = ['fat16', 'fat32', 'ext4'] supported_fs_ext = ['fat16', 'fat32'] supported_fs_mkdir = ['fat16', 'fat32'] supported_fs_unlink = ['fat16', 'fat32'] +supported_fs_symlink = ['ext4'] # # Filesystem test specific setup
@@ -48,6 +49,7 @@ def pytest_configure(config): global supported_fs_ext global supported_fs_mkdir global supported_fs_unlink + global supported_fs_symlink def intersect(listA, listB): return [x for x in listA if x in listB]
@@ -59,6 +61,7 @@ def pytest_configure(config): supported_fs_ext = intersect(supported_fs, supported_fs_ext) supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir) supported_fs_unlink = intersect(supported_fs, supported_fs_unlink) + supported_fs_symlink = intersect(supported_fs, supported_fs_symlink) def pytest_generate_tests(metafunc): """Parametrize fixtures, fs_obj_xxx
@@ -84,6 +87,9 @@ def pytest_generate_tests(metafunc): if 'fs_obj_unlink' in metafunc.fixturenames: metafunc.parametrize('fs_obj_unlink', supported_fs_unlink, indirect=True, scope='module') + if 'fs_obj_symlink' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_symlink', supported_fs_symlink, + indirect=True, scope='module') # # Helper functions
@@ -538,3 +544,73 @@ def fs_obj_unlink(request, u_boot_config): call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True) + +# +# Fixture for symlink fs test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 + at pytest.yield_fixture() +def fs_obj_symlink(request, u_boot_config): + """Set up a file system to be used in symlink fs test. + + Args: + request: Pytest request object. + u_boot_config: U-boot configuration. + + Return: + A fixture for basic fs test, i.e. a triplet of file system type, + volume file name and a list of MD5 hashes. + """ + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + small_file = mount_dir + '/' + SMALL_FILE + medium_file = mount_dir + '/' + MEDIUM_FILE + + try: + + # 3GiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') + + # Mount the image so we can populate it. + check_call('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Create a subdirectory. + check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + + # Create a small file in this image. + check_call('dd if=/dev/urandom of=%s bs=1M count=1' + % small_file, shell=True) + + # Create a medium file in this image. + check_call('dd if=/dev/urandom of=%s bs=10M count=1' + % medium_file, shell=True) + + # Generate the md5sums of reads that we will test against small file + out = check_output( + 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' + % small_file, shell=True) + md5val = [out.split()[0]] + out = check_output( + 'dd if=%s bs=10M skip=0 count=1 2> /dev/null | md5sum' + % medium_file, shell=True) + md5val.extend([out.split()[0]]) + + umount_fs(mount_dir) + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img, md5val] + finally: + umount_fs(mount_dir) + fsck(fs_img, fs_type) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True)
test/py/tests/test_fs/fstest_defs.py +3 -0
@@ -6,6 +6,9 @@ MIN_FILE='testfile' # $SMALL_FILE is the name of the 1MB file in the file system image SMALL_FILE='1MB.file' +# $MEDIUM_FILE is the name of the 10MB file in the file system image +MEDIUM_FILE='10MB.file' + # $BIG_FILE is the name of the 2.5GB file in the file system image BIG_FILE='2.5GB.file'
test/py/tests/test_fs/test_symlink.py new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 7/7 test: fs: Added tests for symlinks
Quoted 9 lines · Jean-Jacques Hiblot
Test cases are:
1) basic link creation, verify it can be followed
2) chained links, verify it can be followed
3) replace exiting file a with a link, and a link with a link. verify it can be followed
4) create a broken link, verify it can't be followedSigned-off-by Jean-Jacques Hiblot <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190201/46734e92/attachment.sig>