fs: ext4: use fs_ls_generic
Now that opendir, readir, closedir are implemented for ext4 we can use fs_ls_generic() for implementing the ls command. Adjust the unit tests: * fs_ls_generic() produces more spaces between file size and name. * The ext4 specific message "** Can not find directory. **\n" is not written anymore. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:

committed by
Tom Rini

parent
8b1d6fcc90
commit
29e5a2e959
@@ -2137,35 +2137,6 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
|
|||||||
*fnode = fdiro;
|
*fnode = fdiro;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (fdiro->inode_read == 0) {
|
|
||||||
status = ext4fs_read_inode(dir->data,
|
|
||||||
le32_to_cpu(
|
|
||||||
dirent.inode),
|
|
||||||
&fdiro->inode);
|
|
||||||
if (status == 0) {
|
|
||||||
free(fdiro);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
fdiro->inode_read = 1;
|
|
||||||
}
|
|
||||||
switch (type) {
|
|
||||||
case FILETYPE_DIRECTORY:
|
|
||||||
printf("<DIR> ");
|
|
||||||
break;
|
|
||||||
case FILETYPE_SYMLINK:
|
|
||||||
printf("<SYM> ");
|
|
||||||
break;
|
|
||||||
case FILETYPE_REG:
|
|
||||||
printf(" ");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("< ? > ");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
printf("%10u %s\n",
|
|
||||||
le32_to_cpu(fdiro->inode.size),
|
|
||||||
filename);
|
|
||||||
}
|
}
|
||||||
free(fdiro);
|
free(fdiro);
|
||||||
}
|
}
|
||||||
|
@@ -201,29 +201,6 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ext4fs_ls(const char *dirname)
|
|
||||||
{
|
|
||||||
struct ext2fs_node *dirnode = NULL;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
if (dirname == NULL)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
status = ext4fs_find_file(dirname, &ext4fs_root->diropen, &dirnode,
|
|
||||||
FILETYPE_DIRECTORY);
|
|
||||||
if (status != 1) {
|
|
||||||
printf("** Can not find directory. **\n");
|
|
||||||
if (dirnode)
|
|
||||||
ext4fs_free_node(dirnode, &ext4fs_root->diropen);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ext4fs_iterate_dir(dirnode, NULL, NULL, NULL);
|
|
||||||
ext4fs_free_node(dirnode, &ext4fs_root->diropen);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp)
|
int ext4fs_opendir(const char *dirname, struct fs_dir_stream **dirsp)
|
||||||
{
|
{
|
||||||
struct ext4_dir_stream *dirs;
|
struct ext4_dir_stream *dirs;
|
||||||
|
2
fs/fs.c
2
fs/fs.c
@@ -220,7 +220,7 @@ static struct fstype_info fstypes[] = {
|
|||||||
.null_dev_desc_ok = false,
|
.null_dev_desc_ok = false,
|
||||||
.probe = ext4fs_probe,
|
.probe = ext4fs_probe,
|
||||||
.close = ext4fs_close,
|
.close = ext4fs_close,
|
||||||
.ls = ext4fs_ls,
|
.ls = fs_ls_generic,
|
||||||
.exists = ext4fs_exists,
|
.exists = ext4fs_exists,
|
||||||
.size = ext4fs_size,
|
.size = ext4fs_size,
|
||||||
.read = ext4_read_file,
|
.read = ext4_read_file,
|
||||||
|
@@ -488,7 +488,7 @@ def test_env_ext4(state_test_env):
|
|||||||
assert 'Loading Environment from EXT4... OK' in response
|
assert 'Loading Environment from EXT4... OK' in response
|
||||||
|
|
||||||
response = c.run_command('ext4ls host 0:0')
|
response = c.run_command('ext4ls host 0:0')
|
||||||
assert '8192 uboot.env' in response
|
assert '8192 uboot.env' in response
|
||||||
|
|
||||||
response = c.run_command('env info')
|
response = c.run_command('env info')
|
||||||
assert 'env_valid = valid' in response
|
assert 'env_valid = valid' in response
|
||||||
|
@@ -33,10 +33,7 @@ class TestFsBasic(object):
|
|||||||
# In addition, test with a nonexistent directory to see if we crash.
|
# In addition, test with a nonexistent directory to see if we crash.
|
||||||
output = u_boot_console.run_command(
|
output = u_boot_console.run_command(
|
||||||
'%sls host 0:0 invalid_d' % fs_type)
|
'%sls host 0:0 invalid_d' % fs_type)
|
||||||
if fs_type == 'ext4':
|
assert('' == output)
|
||||||
assert('Can not find directory' in output)
|
|
||||||
else:
|
|
||||||
assert('' == output)
|
|
||||||
|
|
||||||
def test_fs2(self, u_boot_console, fs_obj_basic):
|
def test_fs2(self, u_boot_console, fs_obj_basic):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user