BACKPORT: FROMGIT: ksmbd: make __dir_empty() compatible with POSIX

Some file systems may not provide dot (.) and dot-dot (..) as they are
optional in POSIX. ksmbd can misjudge emptiness of a directory in those
file systems, since it assumes there are always at least two entries:
dot and dot-dot.
Just don't count dot and dot-dot.

(cherry picked from commit 154a03dac54fb49e4068b58a1005eb2bd02a5dc4
 https://github.com/smfrench/smb3-kernel.git ksmbd-for-next-next)
[hobin: Replace non-present helper in fs/smb/server/vfs.c ]
Change-Id: I0fd226dd3f287f6ff7ef12c5e9f0a986f75b59b1
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
This commit is contained in:
Hobin Woo 2024-09-04 13:36:35 +09:00 committed by Treehugger Robot
parent 59a0888e3c
commit 63aeacfc81

View File

@ -1110,9 +1110,11 @@ static bool __dir_empty(struct dir_context *ctx, const char *name, int namlen,
struct ksmbd_readdir_data *buf;
buf = container_of(ctx, struct ksmbd_readdir_data, ctx);
buf->dirent_count++;
if (!(name[0] == '.' && (namlen < 2 ||
(namlen == 2 && name[1] == '.'))))
buf->dirent_count++;
return buf->dirent_count <= 2;
return !buf->dirent_count;
}
/**
@ -1132,7 +1134,7 @@ int ksmbd_vfs_empty_dir(struct ksmbd_file *fp)
readdir_data.dirent_count = 0;
err = iterate_dir(fp->filp, &readdir_data.ctx);
if (readdir_data.dirent_count > 2)
if (readdir_data.dirent_count)
err = -ENOTEMPTY;
else
err = 0;