fs/fat: replace magic numbers with macros from <uapi/linux/msdos_fs.h>
PATCH 1/1 fs/fat: replace magic numbers with macros from <uapi/linux/msdos_fs.h>
Signed-off-by Alexander Kuleshov <[email protected]>
--- fs/fat/fatent.c | 8 ++++---- include/uapi/linux/msdos_fs.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-)
fs/fat/fatent.c +4 -4
@@ -129,7 +129,7 @@ static int fat12_ent_get(struct fat_entry *fatent) next = (*ent12_p[1 ] <<8 ) | *ent12_p[0 ];spin_unlock (&fat12_entry_lock); - next &=0x0fff ; + next &=EOF_FAT12 ;if (next >=BAD_FAT12 ) next =FAT_ENT_EOF ;return next;
@@ -146,7 +146,7 @@ static int fat16_ent_get(struct fat_entry *fatent)static int fat32_ent_get (struct fat_entry *fatent) { -int next =le32_to_cpu (*fatent->u.ent32_p) &0x0fffffff ; +int next =le32_to_cpu (*fatent->u.ent32_p) &EOF_FAT32 ;WARN_ON ((unsigned long )fatent->u.ent32_p & (4 -1 ));if (next >=BAD_FAT32 ) next =FAT_ENT_EOF ;
@@ -186,8 +186,8 @@ static void fat16_ent_put(struct fat_entry *fatent, int new)static void fat32_ent_put (struct fat_entry *fatent,int new) { -WARN_ON (new &0xf0000000 ); - new |=le32_to_cpu (*fatent->u.ent32_p) & ~0x0fffffff ; +WARN_ON (new &FAT_FREE_CLUSTER ); + new |=le32_to_cpu (*fatent->u.ent32_p) & ~EOF_FAT32 ; *fatent->u.ent32_p =cpu_to_le32 (new);mark_buffer_dirty_inode (fatent->bhs[0 ], fatent->fat_inode); }
include/uapi/linux/msdos_fs.h +3 -0
@@ -58,6 +58,9 @@#define FAT_FIRST_ENT (s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \ MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x)) +/* indicates that a cluster is free */ +#define FAT_FREE_CLUSTER 0xf0000000 +/* start of data cluster's entry (number of reserved clusters) */ #define FAT_START_ENT 2
Signature · 1 line
2.3.0.80.g18d0fec
OGAWA Hirofumi
maintainerAlexander Kuleshov <[email protected]> writes:
Those are not EOF, those are mask. For example, EOF_FAT12 can be 0xff8 (some old drivers did this really).
And 0xf0000000 means ~0x0fffffff, not free cluster (because FAT32 is 28bits actually).
Quoted 52 lines
Signed-off-by Alexander Kuleshov <[email protected]>--- fs/fat/fatent.c | 8 ++++---- include/uapi/linux/msdos_fs.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-)fs/fat/fatent.c +4
-4@@ -129,7 +129,7 @@ static int fat12_ent_get(struct fat_entry *fatent) next = (*ent12_p[1 ] <<8 ) | *ent12_p[0 ];spin_unlock (&fat12_entry_lock); - next &=0x0fff ; + next &=EOF_FAT12 ;if (next >=BAD_FAT12 ) next =FAT_ENT_EOF ;return next;@@ -146,7 +146,7 @@ static int fat16_ent_get(struct fat_entry *fatent)static int fat32_ent_get (struct fat_entry *fatent) { -int next =le32_to_cpu (*fatent->u.ent32_p) &0x0fffffff ; +int next =le32_to_cpu (*fatent->u.ent32_p) &EOF_FAT32 ;WARN_ON ((unsigned long )fatent->u.ent32_p & (4 -1 ));if (next >=BAD_FAT32 ) next =FAT_ENT_EOF ;@@ -186,8 +186,8 @@ static void fat16_ent_put(struct fat_entry *fatent, int new)static void fat32_ent_put (struct fat_entry *fatent,int new) { -WARN_ON (new &0xf0000000 ); - new |=le32_to_cpu (*fatent->u.ent32_p) & ~0x0fffffff ; +WARN_ON (new &FAT_FREE_CLUSTER ); + new |=le32_to_cpu (*fatent->u.ent32_p) & ~EOF_FAT32 ; *fatent->u.ent32_p =cpu_to_le32 (new);mark_buffer_dirty_inode (fatent->bhs[0 ], fatent->fat_inode); }include/uapi/linux/msdos_fs.h +3
-0@@ -58,6 +58,9 @@#define FAT_FIRST_ENT (s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \ MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x)) +/* indicates that a cluster is free */ +#define FAT_FREE_CLUSTER 0xf0000000 +/* start of data cluster's entry (number of reserved clusters) */ #define FAT_START_ENT 2
Signature · 1 line
OGAWA Hirofumi <[email protected]>