2022-12-05 06:06:31

by [email protected]

[permalink] [raw]
Subject: [PATCH v1 6/6] exfat: reuse exfat_find_location() to simplify exfat_get_dentry_set()

In exfat_get_dentry_set(), part of the code is the same as
exfat_find_location(), reuse exfat_find_location() to simplify
exfat_get_dentry_set().

Code refinement, no functional changes.

Signed-off-by: Yuezhang Mo <[email protected]>
Reviewed-by: Andy Wu <[email protected]>
Reviewed-by: Aoyama Wataru <[email protected]>
---
fs/exfat/dir.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 8121a7e073bc..834c0e634250 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -818,7 +818,7 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
unsigned int type)
{
int ret, i, num_bh;
- unsigned int off, byte_offset, clu = 0;
+ unsigned int off;
sector_t sec;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_dentry *ep;
@@ -831,27 +831,16 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
return -EIO;
}

- byte_offset = EXFAT_DEN_TO_B(entry);
- ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu);
+ ret = exfat_find_location(sb, p_dir, entry, &sec, &off);
if (ret)
return ret;

memset(es, 0, sizeof(*es));
es->sb = sb;
es->modified = false;
-
- /* byte offset in cluster */
- byte_offset = EXFAT_CLU_OFFSET(byte_offset, sbi);
-
- /* byte offset in sector */
- off = EXFAT_BLK_OFFSET(byte_offset, sb);
es->start_off = off;
es->bh = es->__bh;

- /* sector offset in cluster */
- sec = EXFAT_B_TO_BLK(byte_offset, sb);
- sec += exfat_cluster_to_sector(sbi, clu);
-
bh = sb_bread(sb, sec);
if (!bh)
return -EIO;
@@ -878,6 +867,8 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
for (i = 1; i < num_bh; i++) {
/* get the next sector */
if (exfat_is_last_sector_in_cluster(sbi, sec)) {
+ int clu = exfat_sector_to_cluster(sbi, sec);
+
if (p_dir->flags == ALLOC_NO_FAT_CHAIN)
clu++;
else if (exfat_get_next_cluster(sb, &clu))
--
2.25.1


2022-12-12 03:39:40

by Sungjong Seo

[permalink] [raw]
Subject: Re: [PATCH v1 6/6] exfat: reuse exfat_find_location() to simplify exfat_get_dentry_set()

Hi. Yuezhang,

On 12/5/22 14:10, [email protected] wrote:
> In exfat_get_dentry_set(), part of the code is the same as
> exfat_find_location(), reuse exfat_find_location() to simplify
> exfat_get_dentry_set().
>
> Code refinement, no functional changes.
>
> Signed-off-by: Yuezhang Mo <[email protected]>
> Reviewed-by: Andy Wu <[email protected]>
> Reviewed-by: Aoyama Wataru <[email protected]>
> ---
> fs/exfat/dir.c | 17 ++++-------------
> 1 file changed, 4 insertions(+), 13 deletions(-)
>
> diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
> index 8121a7e073bc..834c0e634250 100644
> --- a/fs/exfat/dir.c
> +++ b/fs/exfat/dir.c
> @@ -818,7 +818,7 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
> unsigned int type)
> {
> int ret, i, num_bh;
> - unsigned int off, byte_offset, clu = 0;
> + unsigned int off;
> sector_t sec;
> struct exfat_sb_info *sbi = EXFAT_SB(sb);
> struct exfat_dentry *ep;
> @@ -831,27 +831,16 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
> return -EIO;
> }
>
> - byte_offset = EXFAT_DEN_TO_B(entry);
> - ret = exfat_walk_fat_chain(sb, p_dir, byte_offset, &clu);
> + ret = exfat_find_location(sb, p_dir, entry, &sec, &off);
> if (ret)
> return ret;
>
> memset(es, 0, sizeof(*es));
> es->sb = sb;
> es->modified = false;
> -
> - /* byte offset in cluster */
> - byte_offset = EXFAT_CLU_OFFSET(byte_offset, sbi);
> -
> - /* byte offset in sector */
> - off = EXFAT_BLK_OFFSET(byte_offset, sb);
> es->start_off = off;
> es->bh = es->__bh;
>
> - /* sector offset in cluster */
> - sec = EXFAT_B_TO_BLK(byte_offset, sb);
> - sec += exfat_cluster_to_sector(sbi, clu);
> -
> bh = sb_bread(sb, sec);
> if (!bh)
> return -EIO;
> @@ -878,6 +867,8 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es,
> for (i = 1; i < num_bh; i++) {
> /* get the next sector */
> if (exfat_is_last_sector_in_cluster(sbi, sec)) {
> + int clu = exfat_sector_to_cluster(sbi, sec);
> +
'clu' should be defined as 'unsigned int'.
However, as of now, exfat_sector_to_cluster() seems to be unused
function and to return wrong type 'int'. So it should be fixed prior to
this patch.

Could you send patchset again includes the fix?

> if (p_dir->flags == ALLOC_NO_FAT_CHAIN)
> clu++;
> else if (exfat_get_next_cluster(sb, &clu))