diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 895049b2ac9cb65fd58af857e719bc7d8d03115e..204d8614406f9cd18efe2f660ebb1142e66d01f5 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -263,7 +263,6 @@ int fat_search_long(struct inode *inode, const unsigned char *name, unsigned char id; unsigned char slot; unsigned char slots; - unsigned char sum; unsigned char alias_checksum; if (!unicode) { @@ -317,9 +316,7 @@ int fat_search_long(struct inode *inode, const unsigned char *name, goto parse_long; if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME)) continue; - for (sum = 0, i = 0; i < 11; i++) - sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i]; - if (sum != alias_checksum) + if (fat_checksum(de->name) != alias_checksum) nr_slots = 0; } @@ -479,7 +476,6 @@ static int fat_readdirx(struct inode *inode, struct file *filp, void *dirent, unsigned char id; unsigned char slot; unsigned char slots; - unsigned char sum; unsigned char alias_checksum; if (!unicode) { @@ -534,9 +530,7 @@ static int fat_readdirx(struct inode *inode, struct file *filp, void *dirent, goto ParseLong; if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME)) goto RecEnd; - for (sum = 0, i = 0; i < 11; i++) - sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i]; - if (sum != alias_checksum) + if (fat_checksum(de->name) != alias_checksum) long_slots = 0; } diff --git a/fs/vfat/namei.c b/fs/vfat/namei.c index 1c6f6b57ef1cfcd29f7931ef41a11f23632e41b7..467346b123d9ed8c4ca567e062255af7ba85741b 100644 --- a/fs/vfat/namei.c +++ b/fs/vfat/namei.c @@ -621,8 +621,7 @@ static int vfat_build_slots(struct inode *dir, const unsigned char *name, } /* build the entry of long file name */ - for (cksum = i = 0; i < 11; i++) - cksum = (((cksum&1)<<7)|((cksum&0xfe)>>1)) + msdos_name[i]; + cksum = fat_checksum(msdos_name); *nr_slots = usize / 13; for (ps = slots, i = *nr_slots; i > 0; i--, ps++) { diff --git a/include/linux/msdos_fs.h b/include/linux/msdos_fs.h index 9a3d2725798439e2a745bca4f564f89228e77ae3..941da5c016a01e1434d3291fe1ec466c16adbb45 100644 --- a/include/linux/msdos_fs.h +++ b/include/linux/msdos_fs.h @@ -282,6 +282,17 @@ static inline u8 fat_attr(struct inode *inode) MSDOS_I(inode)->i_attrs; } +static inline unsigned char fat_checksum(const __u8 *name) +{ + unsigned char s = name[0]; + s = (s<<7) + (s>>1) + name[1]; s = (s<<7) + (s>>1) + name[2]; + s = (s<<7) + (s>>1) + name[3]; s = (s<<7) + (s>>1) + name[4]; + s = (s<<7) + (s>>1) + name[5]; s = (s<<7) + (s>>1) + name[6]; + s = (s<<7) + (s>>1) + name[7]; s = (s<<7) + (s>>1) + name[8]; + s = (s<<7) + (s>>1) + name[9]; s = (s<<7) + (s>>1) + name[10]; + return s; +} + static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) { return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus