Implement directory listing (ls) for the ext4l filesystem driver. This includes path resolution with symlink following (limited to 8 levels to prevent loops). Add ext4l_ls() which uses ext4_lookup() for path resolution and ext4_readdir() for directory enumeration. The dir_context actor callback formats and prints each directory entry. Export ext4_lookup() from namei.c and add declarations to ext4.h. Add test_ls to the Python test suite, which creates a test file using debugfs and verifies it appears in the directory listing with the correct size. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Cover-letter: ext4l: Add support for listing directoties (Part H) This series adds directory-listing support to the ext4l filesystem driver. It exports a few required functions from the Linux ext4 code, fixes the dir_emit() stub to properly call the actor callback, and implements ext4l_ls() with path resolution and symlink following. END Signed-off-by: Simon Glass <simon.glass@canonical.com>
111 lines
3.2 KiB
C
111 lines
3.2 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Tests for ext4l filesystem (Linux ext4 port)
|
|
*
|
|
* Copyright 2025 Canonical Ltd
|
|
* Written by Simon Glass <simon.glass@canonical.com>
|
|
*/
|
|
|
|
#include <command.h>
|
|
#include <env.h>
|
|
#include <ext4l.h>
|
|
#include <fs.h>
|
|
#include <fs_legacy.h>
|
|
#include <u-boot/uuid.h>
|
|
#include <test/test.h>
|
|
#include <test/ut.h>
|
|
#include <test/fs.h>
|
|
|
|
#define EXT4L_ARG_IMAGE 0 /* fs_image: path to filesystem image */
|
|
|
|
/**
|
|
* fs_test_ext4l_probe_norun() - Test probing an ext4l filesystem
|
|
*
|
|
* This test verifies that the ext4l driver can successfully probe and
|
|
* mount an ext4 filesystem image.
|
|
*
|
|
* Arguments:
|
|
* fs_image: Path to the ext4 filesystem image
|
|
*/
|
|
static int fs_test_ext4l_probe_norun(struct unit_test_state *uts)
|
|
{
|
|
const char *fs_image = ut_str(EXT4L_ARG_IMAGE);
|
|
|
|
ut_assertnonnull(fs_image);
|
|
ut_assertok(run_commandf("host bind 0 %s", fs_image));
|
|
ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY));
|
|
|
|
return 0;
|
|
}
|
|
FS_TEST_ARGS(fs_test_ext4l_probe_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL,
|
|
{ "fs_image", UT_ARG_STR });
|
|
|
|
/**
|
|
* fs_test_ext4l_msgs_norun() - Test ext4l_msgs env var output
|
|
*
|
|
* This test verifies that setting ext4l_msgs=y causes mount messages
|
|
* to be printed when probing an ext4 filesystem.
|
|
*
|
|
* Arguments:
|
|
* fs_image: Path to the ext4 filesystem image
|
|
*/
|
|
static int fs_test_ext4l_msgs_norun(struct unit_test_state *uts)
|
|
{
|
|
const char *fs_image = ut_str(EXT4L_ARG_IMAGE);
|
|
char uuid_str[UUID_STR_LEN + 1];
|
|
u8 uuid[16];
|
|
|
|
ut_assertnonnull(fs_image);
|
|
ut_assertok(env_set("ext4l_msgs", "y"));
|
|
console_record_reset_enable();
|
|
ut_assertok(run_commandf("host bind 0 %s", fs_image));
|
|
ut_assertok(fs_set_blk_dev("host", "0", FS_TYPE_ANY));
|
|
|
|
/* Get the UUID and clear the env var now we have the output */
|
|
ut_assertok(ext4l_get_uuid(uuid));
|
|
uuid_bin_to_str(uuid, uuid_str, UUID_STR_FORMAT_STD);
|
|
ut_assertok(env_set("ext4l_msgs", NULL));
|
|
|
|
/*
|
|
* Check messages. The probe test runs first and doesn't unmount,
|
|
* so the journal needs recovery. Verify both messages.
|
|
*/
|
|
ut_assert_nextline("EXT4-fs (ext4l_mmc0): recovery complete");
|
|
ut_assert_nextline("EXT4-fs (ext4l_mmc0): mounted filesystem %s r/w with ordered data mode. Quota mode: disabled.",
|
|
uuid_str);
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
}
|
|
FS_TEST_ARGS(fs_test_ext4l_msgs_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL,
|
|
{ "fs_image", UT_ARG_STR });
|
|
|
|
/**
|
|
* fs_test_ext4l_ls_norun() - Test ext4l ls command
|
|
*
|
|
* This test verifies that the ext4l driver can list directory contents.
|
|
*
|
|
* Arguments:
|
|
* fs_image: Path to the ext4 filesystem image
|
|
*/
|
|
static int fs_test_ext4l_ls_norun(struct unit_test_state *uts)
|
|
{
|
|
const char *fs_image = ut_str(EXT4L_ARG_IMAGE);
|
|
|
|
ut_assertnonnull(fs_image);
|
|
ut_assertok(run_commandf("host bind 0 %s", fs_image));
|
|
console_record_reset_enable();
|
|
ut_assertok(run_commandf("ls host 0"));
|
|
/*
|
|
* The Python test adds testfile.txt (12 bytes) to the image.
|
|
* Directory entries appear in hash order which varies between runs.
|
|
* Verify the file entry appears with correct size (12 bytes).
|
|
*/
|
|
ut_assert_skip_to_line(" 12 testfile.txt");
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
}
|
|
FS_TEST_ARGS(fs_test_ext4l_ls_norun, UTF_SCAN_FDT | UTF_CONSOLE | UTF_MANUAL,
|
|
{ "fs_image", UT_ARG_STR });
|