2015-02-18 19:13:12

by Alexander Kuleshov

[permalink] [raw]
Subject: [PATCH] fs/fat: remove fat12_ent_blocknr and use fat_ent_blocknr instead

There is only one difference between fat12_ent_blocknr and fat_ent_blocknr
functions in bytes calculation. Let's add bits checking to fat_ent_blocknr
instead code duplication.

Signed-off-by: Alexander Kuleshov <[email protected]>
---
fs/fat/fatent.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index 260705c..314ab50 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -21,21 +21,16 @@ struct fatent_operations {

static DEFINE_SPINLOCK(fat12_entry_lock);

-static void fat12_ent_blocknr(struct super_block *sb, int entry,
- int *offset, sector_t *blocknr)
-{
- struct msdos_sb_info *sbi = MSDOS_SB(sb);
- int bytes = entry + (entry >> 1);
- WARN_ON(entry < FAT_START_ENT || sbi->max_cluster <= entry);
- *offset = bytes & (sb->s_blocksize - 1);
- *blocknr = sbi->fat_start + (bytes >> sb->s_blocksize_bits);
-}
-
static void fat_ent_blocknr(struct super_block *sb, int entry,
int *offset, sector_t *blocknr)
{
struct msdos_sb_info *sbi = MSDOS_SB(sb);
- int bytes = (entry << sbi->fatent_shift);
+ int bytes;
+
+ if (sbi->fat_bits == 12)
+ bytes = entry + (entry >> 1);
+ else
+ bytes = (entry << sbi->fatent_shift);
WARN_ON(entry < FAT_START_ENT || sbi->max_cluster <= entry);
*offset = bytes & (sb->s_blocksize - 1);
*blocknr = sbi->fat_start + (bytes >> sb->s_blocksize_bits);
@@ -250,7 +245,7 @@ static int fat32_ent_next(struct fat_entry *fatent)
}

static struct fatent_operations fat12_ops = {
- .ent_blocknr = fat12_ent_blocknr,
+ .ent_blocknr = fat_ent_blocknr,
.ent_set_ptr = fat12_ent_set_ptr,
.ent_bread = fat12_ent_bread,
.ent_get = fat12_ent_get,
--
2.3.0.80.g18d0fec


2015-02-18 19:23:06

by OGAWA Hirofumi

[permalink] [raw]
Subject: Re: [PATCH] fs/fat: remove fat12_ent_blocknr and use fat_ent_blocknr instead

Alexander Kuleshov <[email protected]> writes:

> There is only one difference between fat12_ent_blocknr and fat_ent_blocknr
> functions in bytes calculation. Let's add bits checking to fat_ent_blocknr
> instead code duplication.

I guess, fat12 (very small volume size) is uncommon to be used now, and
there is no way to switch fat12 <= fat16/fat32 at runtime. It is why has
special handler, i.e. avoid overhead to fat16/fat32 by fat12 code.

Thanks.
--
OGAWA Hirofumi <[email protected]>

2015-02-18 19:49:23

by Alexander Kuleshov

[permalink] [raw]
Subject: Re: [PATCH] fs/fat: remove fat12_ent_blocknr and use fat_ent_blocknr instead

> I guess, fat12 (very small volume size) is uncommon to be used now, and
> there is no way to switch fat12 <= fat16/fat32 at runtime. It is why has
> special handler, i.e. avoid overhead to fat16/fat32 by fat12 code.

Understand. Thank you for explanation.