2020-11-18 06:24:54

by Daniel Rosenberg

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] f2fs: Handle casefolding with Encryption

On Tue, Nov 17, 2020 at 10:50 AM Eric Biggers <[email protected]> wrote:
>
>
> What is the assignment to dentry_page supposed to be accomplishing? It looks
> like it's meant to pass up errors from f2fs_find_target_dentry(), but it doesn't
> do that.

Woops. Fixed that for the next version.

>
> > @@ -222,14 +250,20 @@ static bool f2fs_match_ci_name(const struct inode *dir, const struct qstr *name,
> > * fall back to treating them as opaque byte sequences.
> > */
> > if (sb_has_strict_encoding(sb) || name->len != entry.len)
> > - return false;
> > - return !memcmp(name->name, entry.name, name->len);
> > + res = 0;
> > + else
> > + res = memcmp(name->name, entry.name, name->len) == 0;
> > + } else {
> > + /* utf8_strncasecmp_folded returns 0 on match */
> > + res = (res == 0);
> > }
>
> The following might be easier to understand:
>
> /*
> * In strict mode, ignore invalid names. In non-strict mode, fall back
> * to treating them as opaque byte sequences.
> */
> if (res < 0 && !sb_has_strict_encoding(sb)) {
> res = name->len == entry.len &&
> memcmp(name->name, entry.name, name->len) == 0;
> } else {
> /* utf8_strncasecmp_folded returns 0 on match */
> res = (res == 0);
> }
>
Thanks, that is a fair bit nicer.

> > @@ -273,10 +308,14 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d,
> > continue;
> > }
> >
> > - if (de->hash_code == fname->hash &&
> > - f2fs_match_name(d->inode, fname, d->filename[bit_pos],
> > - le16_to_cpu(de->name_len)))
> > - goto found;
> > + if (de->hash_code == fname->hash) {
> > + res = f2fs_match_name(d->inode, fname, d->filename[bit_pos],
> > + le16_to_cpu(de->name_len));
> > + if (res < 0)
> > + return ERR_PTR(res);
> > + else if (res)
> > + goto found;
> > + }
>
> Overly long line here. Also 'else if' is unnecessary, just use 'if'.
>
> - Eric
The 0 case is important, since that reflects that the name was not found.
-Daniel