Re: [PATCH 1/1] ext4: detect directories in ext4fs_exists()
On Tue, Feb 20, 2024 at 12:54:23PM +0100, Heinrich Schuchardt wrote: > While fat_exists() reports directories and files as existing > ext4fs_exists() only recognizes files. This lead to errors > when using systemd-boot with an ext4 file-system. > > Change ext4fs_exists() to find any type of inode: > files, directories, symbolic links. > > Fixes: a1596438a689 ("ext4fs ls load support") > Signed-off-by: Heinrich Schuchardt Applied to u-boot/next, thanks! -- Tom signature.asc Description: PGP signature
Re: [PATCH 1/1] ext4: detect directories in ext4fs_exists()
On 20/02/2024 11:54, Heinrich Schuchardt wrote: > While fat_exists() reports directories and files as existing > ext4fs_exists() only recognizes files. This lead to errors > when using systemd-boot with an ext4 file-system. > > Change ext4fs_exists() to find any type of inode: > files, directories, symbolic links. > > Fixes: a1596438a689 ("ext4fs ls load support") > Signed-off-by: Heinrich Schuchardt This doesn't entirely fix systemd-boot, the fs_get_size() call still winds up in ext4fs_open() which fails because it's a directory... I poked around to see if I could get this working but it seems like it won't be simple :/ This is still a valid bugfix though, even if it doesn't totally fix the issue. Reviwed-by: Caleb Connolly > --- > I still need to figure out a good test. Currently 'xxd' is the only command > invoking fs_exists(). > --- > fs/ext4/ext4_common.c | 5 ++--- > fs/ext4/ext4_common.h | 2 ++ > fs/ext4/ext4fs.c | 11 +++ > 3 files changed, 11 insertions(+), 7 deletions(-) > > diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c > index ea9b92298ba..365c5147c4b 100644 > --- a/fs/ext4/ext4_common.c > +++ b/fs/ext4/ext4_common.c > @@ -2214,9 +2214,8 @@ static char *ext4fs_read_symlink(struct ext2fs_node > *node) > return symlink; > } > > -static int ext4fs_find_file1(const char *currpath, > - struct ext2fs_node *currroot, > - struct ext2fs_node **currfound, int *foundtype) > +int ext4fs_find_file1(const char *currpath, struct ext2fs_node *currroot, > + struct ext2fs_node **currfound, int *foundtype) > { > char fpath[strlen(currpath) + 1]; > char *name = fpath; > diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h > index 504c708b064..84500e990aa 100644 > --- a/fs/ext4/ext4_common.h > +++ b/fs/ext4/ext4_common.h > @@ -54,6 +54,8 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, > loff_t len, >char *buf, loff_t *actread); > int ext4fs_find_file(const char *path, struct ext2fs_node *rootnode, > struct ext2fs_node **foundnode, int expecttype); > +int ext4fs_find_file1(const char *currpath, struct ext2fs_node *currroot, > + struct ext2fs_node **currfound, int *foundtype); > int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name, > struct ext2fs_node **fnode, int *ftype); > > diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c > index 3b12ec54fa2..b1359d14909 100644 > --- a/fs/ext4/ext4fs.c > +++ b/fs/ext4/ext4fs.c > @@ -208,11 +208,14 @@ int ext4fs_ls(const char *dirname) > > int ext4fs_exists(const char *filename) > { > - loff_t file_len; > - int ret; > + struct ext2fs_node *dirnode = NULL; > + int filetype; > > - ret = ext4fs_open(filename, _len); > - return ret == 0; > + if (!filename) > + return 0; > + > + return ext4fs_find_file1(filename, _root->diropen, , > + ); > } > > int ext4fs_size(const char *filename, loff_t *size) -- // Caleb (they/them)
[PATCH 1/1] ext4: detect directories in ext4fs_exists()
While fat_exists() reports directories and files as existing ext4fs_exists() only recognizes files. This lead to errors when using systemd-boot with an ext4 file-system. Change ext4fs_exists() to find any type of inode: files, directories, symbolic links. Fixes: a1596438a689 ("ext4fs ls load support") Signed-off-by: Heinrich Schuchardt --- I still need to figure out a good test. Currently 'xxd' is the only command invoking fs_exists(). --- fs/ext4/ext4_common.c | 5 ++--- fs/ext4/ext4_common.h | 2 ++ fs/ext4/ext4fs.c | 11 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index ea9b92298ba..365c5147c4b 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -2214,9 +2214,8 @@ static char *ext4fs_read_symlink(struct ext2fs_node *node) return symlink; } -static int ext4fs_find_file1(const char *currpath, -struct ext2fs_node *currroot, -struct ext2fs_node **currfound, int *foundtype) +int ext4fs_find_file1(const char *currpath, struct ext2fs_node *currroot, + struct ext2fs_node **currfound, int *foundtype) { char fpath[strlen(currpath) + 1]; char *name = fpath; diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h index 504c708b064..84500e990aa 100644 --- a/fs/ext4/ext4_common.h +++ b/fs/ext4/ext4_common.h @@ -54,6 +54,8 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, loff_t len, char *buf, loff_t *actread); int ext4fs_find_file(const char *path, struct ext2fs_node *rootnode, struct ext2fs_node **foundnode, int expecttype); +int ext4fs_find_file1(const char *currpath, struct ext2fs_node *currroot, + struct ext2fs_node **currfound, int *foundtype); int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name, struct ext2fs_node **fnode, int *ftype); diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index 3b12ec54fa2..b1359d14909 100644 --- a/fs/ext4/ext4fs.c +++ b/fs/ext4/ext4fs.c @@ -208,11 +208,14 @@ int ext4fs_ls(const char *dirname) int ext4fs_exists(const char *filename) { - loff_t file_len; - int ret; + struct ext2fs_node *dirnode = NULL; + int filetype; - ret = ext4fs_open(filename, _len); - return ret == 0; + if (!filename) + return 0; + + return ext4fs_find_file1(filename, _root->diropen, , +); } int ext4fs_size(const char *filename, loff_t *size) -- 2.43.0