Skip to content

Commit ca4974c

Browse files
Hobin Woosmfrench
authored andcommitted
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. Cc: [email protected] # v6.1+ Signed-off-by: Hobin Woo <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent ee426bf commit ca4974c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/smb/server/vfs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,10 @@ static bool __dir_empty(struct dir_context *ctx, const char *name, int namlen,
11151115
struct ksmbd_readdir_data *buf;
11161116

11171117
buf = container_of(ctx, struct ksmbd_readdir_data, ctx);
1118-
buf->dirent_count++;
1118+
if (!is_dot_dotdot(name, namlen))
1119+
buf->dirent_count++;
11191120

1120-
return buf->dirent_count <= 2;
1121+
return !buf->dirent_count;
11211122
}
11221123

11231124
/**
@@ -1137,7 +1138,7 @@ int ksmbd_vfs_empty_dir(struct ksmbd_file *fp)
11371138
readdir_data.dirent_count = 0;
11381139

11391140
err = iterate_dir(fp->filp, &readdir_data.ctx);
1140-
if (readdir_data.dirent_count > 2)
1141+
if (readdir_data.dirent_count)
11411142
err = -ENOTEMPTY;
11421143
else
11431144
err = 0;

0 commit comments

Comments
 (0)