Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: "Hobin Woo" <hobin.woo@samsung.com>
To: "'Namjae Jeon'" <linkinjeon@kernel.org>
Cc: 'CIFS' <linux-cifs@vger.kernel.org>,
	"'Steve French'" <sfrench@samba.org>,
	"'Sergey Senozhatsky'" <senozhatsky@chromium.org>,
	"'Tom Talpey'" <tom@talpey.com>,
	"'Sungjong Seo'" <sj1557.seo@samsung.com>,
	'이기성' <kiras.lee@samsung.com>
Subject: RE: [PATCH] ksmbd: make __dir_empty() compatible with POSIX
Date: Tue, 3 Sep 2024 15:33:02 +0900	[thread overview]
Message-ID: <005501dafdcb$20ada410$6208ec30$@samsung.com> (raw)
In-Reply-To: <005401dafdc9$18aaee00$4a00ca00$@samsung.com>

> 
> 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
> >
> 




      parent reply	other threads:[~2024-09-03  6:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='005501dafdcb$20ada410$6208ec30$@samsung.com' \
    --to=hobin.woo@samsung.com \
    --cc=kiras.lee@samsung.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=sfrench@samba.org \
    --cc=sj1557.seo@samsung.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox