Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] ksmbd: make __dir_empty() compatible with POSIX
       [not found] <CGME20240903051932epcas1p31c823baa892d8dc3f3e2ed8e1c073250@epcas1p3.samsung.com>
@ 2024-09-03  5:19 ` Hobin Woo
  2024-09-03  5:45   ` Steve French
       [not found]   ` <CAKYAXd_zBESXWJ+CubrDBd0u_i9h=CimJ=6E_DxtfNLTXxRPgA@mail.gmail.com>
  0 siblings, 2 replies; 4+ messages in thread
From: Hobin Woo @ 2024-09-03  5:19 UTC (permalink / raw)
  To: linux-cifs
  Cc: linkinjeon, sfrench, senozhatsky, tom, sj1557.seo, kiras.lee,
	Hobin Woo

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 set the dirent_count to 2, if the first entry is not a dot.

Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
---
 fs/smb/server/vfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 9e859ba010cf..bb836fa0aaa6 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -1115,6 +1115,8 @@ 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);
+	if (offset == 0 && !(namlen == 1 && name[0] == '.'))
+		buf->dirent_count = 2;
 	buf->dirent_count++;
 
 	return buf->dirent_count <= 2;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ksmbd: make __dir_empty() compatible with POSIX
  2024-09-03  5:19 ` [PATCH] ksmbd: make __dir_empty() compatible with POSIX Hobin Woo
@ 2024-09-03  5:45   ` Steve French
  2024-09-03  5:53     ` Hobin Woo
       [not found]   ` <CAKYAXd_zBESXWJ+CubrDBd0u_i9h=CimJ=6E_DxtfNLTXxRPgA@mail.gmail.com>
  1 sibling, 1 reply; 4+ messages in thread
From: Steve French @ 2024-09-03  5:45 UTC (permalink / raw)
  To: Hobin Woo
  Cc: linux-cifs, linkinjeon, sfrench, senozhatsky, tom, sj1557.seo,
	kiras.lee

Is there an example where you have seen an fs not report . and .. ?

On Tue, Sep 3, 2024 at 12:19 AM Hobin Woo <hobin.woo@samsung.com> wrote:
>
> 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 set the dirent_count to 2, if the first entry is not a dot.
>
> Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
> ---
>  fs/smb/server/vfs.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> index 9e859ba010cf..bb836fa0aaa6 100644
> --- a/fs/smb/server/vfs.c
> +++ b/fs/smb/server/vfs.c
> @@ -1115,6 +1115,8 @@ 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);
> +       if (offset == 0 && !(namlen == 1 && name[0] == '.'))
> +               buf->dirent_count = 2;
>         buf->dirent_count++;
>
>         return buf->dirent_count <= 2;
> --
> 2.43.0
>
>


-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] ksmbd: make __dir_empty() compatible with POSIX
  2024-09-03  5:45   ` Steve French
@ 2024-09-03  5:53     ` Hobin Woo
  0 siblings, 0 replies; 4+ messages in thread
From: Hobin Woo @ 2024-09-03  5:53 UTC (permalink / raw)
  To: 'Steve French'
  Cc: linux-cifs, linkinjeon, sfrench, senozhatsky, tom, sj1557.seo,
	kiras.lee

Android's FUSE file system, /storage/emulated/<USER>, is an example of this.
https://cs.android.com/android/platform/superproject/main/+/main:packages/providers/MediaProvider/jni/ReaddirHelper.cpp;l=52;drc=01c2d29eeefc2d344794429af3df08c38adfd57f

> -----Original Message-----
> From: Steve French <smfrench@gmail.com>
> Sent: Tuesday, September 3, 2024 2:45 PM
> To: Hobin Woo <hobin.woo@samsung.com>
> Cc: linux-cifs@vger.kernel.org; linkinjeon@kernel.org; sfrench@samba.org;
> senozhatsky@chromium.org; tom@talpey.com; sj1557.seo@samsung.com;
> kiras.lee@samsung.com
> Subject: Re: [PATCH] ksmbd: make __dir_empty() compatible with POSIX
> 
> Is there an example where you have seen an fs not report . and .. ?
> 
> On Tue, Sep 3, 2024 at 12:19 AM Hobin Woo <hobin.woo@samsung.com> wrote:
> >
> > 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 set the dirent_count to 2, if the first entry is not a dot.
> >
> > Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
> > ---
> >  fs/smb/server/vfs.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> > index 9e859ba010cf..bb836fa0aaa6 100644
> > --- a/fs/smb/server/vfs.c
> > +++ b/fs/smb/server/vfs.c
> > @@ -1115,6 +1115,8 @@ 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);
> > +       if (offset == 0 && !(namlen == 1 && name[0] == '.'))
> > +               buf->dirent_count = 2;
> >         buf->dirent_count++;
> >
> >         return buf->dirent_count <= 2;
> > --
> > 2.43.0
> >
> >
> 
> 
> --
> Thanks,
> 
> Steve



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] ksmbd: make __dir_empty() compatible with POSIX
       [not found]     ` <005401dafdc9$18aaee00$4a00ca00$@samsung.com>
@ 2024-09-03  6:33       ` Hobin Woo
  0 siblings, 0 replies; 4+ messages in thread
From: Hobin Woo @ 2024-09-03  6:33 UTC (permalink / raw)
  To: 'Namjae Jeon'
  Cc: 'CIFS', 'Steve French',
	'Sergey Senozhatsky', 'Tom Talpey',
	'Sungjong Seo', '이기성'

> 
> On Tue, Sep 3, 2024 at 2:19 PM Hobin Woo <hobin.woo@samsung.com>
> wrote:
> >
> > 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 set the dirent_count to 2, if the first entry is not a dot.
> >
> > Signed-off-by: Hobin Woo <hobin.woo@samsung.com>
> > ---
> >  fs/smb/server/vfs.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> > index 9e859ba010cf..bb836fa0aaa6 100644
> > --- a/fs/smb/server/vfs.c
> > +++ b/fs/smb/server/vfs.c
> > @@ -1115,6 +1115,8 @@ 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);
> > +       if (offset == 0 && !(namlen == 1 && name[0] == '.'))
> > +               buf->dirent_count = 2;
> How about not counting the dot, dotdot entry? Because the dot, dotdot
> entry is not always at the front.
> and we change the following code together if we do not count them.
Thanks for pointing out.
We should also consider the stop condition. So the v2 code would look like this:
	buf = container_of(ctx, struct ksmbd_readdir_data, ctx);
+       if (!is_dot_dotdot(name, namlen))
+               buf->dirent_count++;

-       return buf->dirent_count <= 2;
+       return !buf->dirent_count;

Thanks.


> 
> diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> index 9e859ba010cf..243bb2f3aa1f 100644
> --- a/fs/smb/server/vfs.c
> +++ b/fs/smb/server/vfs.c
> @@ -1137,7 +1137,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;
> 
> Thanks.
> >         buf->dirent_count++;
> >
> >         return buf->dirent_count <= 2;
> > --
> > 2.43.0
> >
> 




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-03  6:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20240903051932epcas1p31c823baa892d8dc3f3e2ed8e1c073250@epcas1p3.samsung.com>
2024-09-03  5:19 ` [PATCH] ksmbd: make __dir_empty() compatible with POSIX Hobin Woo
2024-09-03  5:45   ` Steve French
2024-09-03  5:53     ` Hobin Woo
     [not found]   ` <CAKYAXd_zBESXWJ+CubrDBd0u_i9h=CimJ=6E_DxtfNLTXxRPgA@mail.gmail.com>
     [not found]     ` <005401dafdc9$18aaee00$4a00ca00$@samsung.com>
2024-09-03  6:33       ` Hobin Woo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox