* [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir
@ 2025-01-08 9:14 Ahmad Fatoum
2025-01-08 9:14 ` [PATCH master 2/2] fs: fix resolving paths when directory name repeats Ahmad Fatoum
2025-01-08 14:17 ` [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-01-08 9:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Recursive opendir with parent and child directory having the same name
is currently broken. Add a failing test, which will be fixed in the
follow-up commit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/self/ramfs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/test/self/ramfs.c b/test/self/ramfs.c
index 239e3e690740..3fb3812cb629 100644
--- a/test/self/ramfs.c
+++ b/test/self/ramfs.c
@@ -51,6 +51,44 @@ static inline int get_file_count(int i)
return i + 1;
}
+struct test_tree_ctx {
+ unsigned nfiles;
+ unsigned ndirs;
+};
+
+static void test_tree(const char *path, struct test_tree_ctx *ctx)
+{
+ DIR *dir;
+ struct dirent *d;
+ char *oldwd;
+
+ dir = opendir(path);
+ if (!dir)
+ return;
+
+ oldwd = pushd(path);
+
+ while ((d = readdir(dir))) {
+ struct stat st;
+
+ if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+ continue;
+
+ if (stat(d->d_name, &st))
+ continue;
+
+ if (S_ISDIR(st.st_mode))
+ ctx->ndirs++;
+ else if (S_ISREG(st.st_mode))
+ ctx->nfiles++;
+
+ test_tree(d->d_name, ctx);
+
+ }
+
+ popd(oldwd);
+}
+
static void test_ramfs(void)
{
int files[] = { 1, 3, 5, 7, 11, 13, 17 };
@@ -180,24 +218,34 @@ static void test_ramfs(void)
expect_success(i == 90 ? 0 : -EINVAL,
"unexpected file count iterating directory: %u", i);
- ret = make_directory("test/a/b/c/d/e/f/g/h/i/j/k/l");
+ ret = make_directory("test/a/b/c/d/d/f/g/h/i/j/k/l");
expect_success(ret, "make_directory()");
if (!ret) {
+ struct test_tree_ctx ctx = {};
const char hello[] = "hello";
char *buf;
- ret = write_file("test/a/b/c/d/e/f/g/h/i/j/k/l/FILE",
+ ret = write_file("test/a/b/c/d/d/f/g/h/i/j/k/l/FILE",
ARRAY_AND_SIZE(hello));
expect_success(ret, "write_file()");
- buf = read_file("test/a/b/c/d/e/f/g/h/i/j/k/l/FILE", NULL);
+ buf = read_file("test/a/b/c/d/d/f/g/h/i/j/k/l/FILE", NULL);
if (expect_ptrok(buf, "read_file()")) {
expect_success(memcmp(buf, ARRAY_AND_SIZE(hello)),
"read_file() content");
}
free(buf);
+
+ test_tree("test/", &ctx);
+
+ expect_success(ctx.nfiles == 1 ? 0 : -EINVAL,
+ "wrong recursive opendir file count: %u",
+ ctx.nfiles);
+ expect_success(ctx.ndirs == 12 ? 0 : -EINVAL,
+ "wrong recursive opendir directory count: %u",
+ ctx.ndirs);
}
out:
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH master 2/2] fs: fix resolving paths when directory name repeats
2025-01-08 9:14 [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Ahmad Fatoum
@ 2025-01-08 9:14 ` Ahmad Fatoum
2025-01-08 14:17 ` [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-01-08 9:14 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
d_same_name() used to only check if the name exists in any of the
directory's children.
In order to fix lookup of /, the function was changed to also compare
the name against the parent. This is obviously wrong, when the parent
and child have the same name: Resolution of the child would always
return the parent dentry triggering unexpected behavior.
Fix this by effectively reverting the functional change in commit
3a478ff3e1e6 ("fs: support opening /"). This breaks opening /, but that
currently only affects dirfd usage and will be fixed separately.
Fixes: 3a478ff3e1e6 ("fs: support opening /")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/fs.c | 3 ---
test/self/dirfd.c | 7 ++++++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 57bd781025f9..235fb8f8e9ef 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1536,9 +1536,6 @@ static struct dentry *d_lookup(struct dentry *parent, const struct qstr *name)
{
struct dentry *dentry;
- if (d_same_name(parent, name))
- return dget(parent);
-
list_for_each_entry(dentry, &parent->d_subdirs, d_child) {
if (d_same_name(dentry, name))
return dget(dentry);
diff --git a/test/self/dirfd.c b/test/self/dirfd.c
index 20b54258715a..644ff214fb37 100644
--- a/test/self/dirfd.c
+++ b/test/self/dirfd.c
@@ -100,8 +100,13 @@ static void test_dirfd(void)
int fd;
fd = open("/", O_PATH);
- if (expect(fd < 0, false, "open(/, O_PATH) = %d", fd))
+ if (expect(fd < 0, false, "open(/, O_PATH) = %d", fd)) {
close(fd);
+ } else {
+ pr_info("\tIgnoring expected failure\n");
+ failed_tests--;
+ skipped_tests++;
+ }
#define B(dot, dotdot, zero, dev) 0b##dev##zero##dotdot##dot
/* We do fiften tests for every configuration
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir
2025-01-08 9:14 [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Ahmad Fatoum
2025-01-08 9:14 ` [PATCH master 2/2] fs: fix resolving paths when directory name repeats Ahmad Fatoum
@ 2025-01-08 14:17 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-01-08 14:17 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Wed, 08 Jan 2025 10:14:24 +0100, Ahmad Fatoum wrote:
> Recursive opendir with parent and child directory having the same name
> is currently broken. Add a failing test, which will be fixed in the
> follow-up commit.
>
>
Applied, thanks!
[1/2] test: self: ramfs: add regression test for recursive opendir
https://git.pengutronix.de/cgit/barebox/commit/?id=41a3864eac71 (link may not be stable)
[2/2] fs: fix resolving paths when directory name repeats
https://git.pengutronix.de/cgit/barebox/commit/?id=adbd003e2d65 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-08 14:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08 9:14 [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Ahmad Fatoum
2025-01-08 9:14 ` [PATCH master 2/2] fs: fix resolving paths when directory name repeats Ahmad Fatoum
2025-01-08 14:17 ` [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox