> This helper is used to lookup empty dentry set. If there are no enough > empty dentries at the input location, this helper will return the number > of dentries that need to be skipped for the next lookup. > > Signed-off-by: Yuezhang Mo <Yuezhang.Mo@xxxxxxxx> > Reviewed-by: Andy Wu <Andy.Wu@xxxxxxxx> > Reviewed-by: Aoyama Wataru <wataru.aoyama@xxxxxxxx> > --- > fs/exfat/dir.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ > fs/exfat/exfat_fs.h | 3 ++ > 2 files changed, 80 insertions(+) > > diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index > cea9231d2fda..a5c8cd19aca6 100644 > --- a/fs/exfat/dir.c > +++ b/fs/exfat/dir.c > @@ -950,6 +950,83 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache > *es, > return -EIO; > } > > +static int exfat_validate_empty_dentry_set(struct exfat_entry_set_cache > +*es) { > + struct exfat_dentry *ep; > + struct buffer_head *bh; > + int i, off; > + bool unused_hit = false; > + > + for (i = 0; i < es->num_entries; i++) { > + ep = exfat_get_dentry_cached(es, i); > + if (ep->type == EXFAT_UNUSED) > + unused_hit = true; > + else if (IS_EXFAT_DELETED(ep->type)) { Although it violates the specification for a deleted entry to follow an unused entry, some exFAT implementations could work like this. Therefore, to improve compatibility, why don't we allow this? I believe there will be no functional problem even if this is allowed. > + if (unused_hit) > + goto out; > + } else { > + if (unused_hit) > + goto out; Label "out" does not look like an error situation. Let's use "out_err" instead of "out". > + > + i++; > + goto count_skip_entries; > + } > + } > + > + return 0;