aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>2005-10-30 18:03:49 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-10-30 20:37:32 -0500
commit451cbaa1c328082832a8fbcc427cd4416c602c5a (patch)
tree139c3d33d0cf3f9eba214c504e4173f54c6cf66d
parent4e57b6817880946a3a78d5d8cad1ace363f7e449 (diff)
[PATCH] fat: cleanup and optimization of checksum
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--fs/fat/dir.c10
-rw-r--r--fs/vfat/namei.c3
-rw-r--r--include/linux/msdos_fs.h11
3 files changed, 14 insertions, 10 deletions
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 895049b2ac9c..204d8614406f 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -263,7 +263,6 @@ parse_record:
263 unsigned char id; 263 unsigned char id;
264 unsigned char slot; 264 unsigned char slot;
265 unsigned char slots; 265 unsigned char slots;
266 unsigned char sum;
267 unsigned char alias_checksum; 266 unsigned char alias_checksum;
268 267
269 if (!unicode) { 268 if (!unicode) {
@@ -317,9 +316,7 @@ parse_long:
317 goto parse_long; 316 goto parse_long;
318 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME)) 317 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME))
319 continue; 318 continue;
320 for (sum = 0, i = 0; i < 11; i++) 319 if (fat_checksum(de->name) != alias_checksum)
321 sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i];
322 if (sum != alias_checksum)
323 nr_slots = 0; 320 nr_slots = 0;
324 } 321 }
325 322
@@ -479,7 +476,6 @@ GetNew:
479 unsigned char id; 476 unsigned char id;
480 unsigned char slot; 477 unsigned char slot;
481 unsigned char slots; 478 unsigned char slots;
482 unsigned char sum;
483 unsigned char alias_checksum; 479 unsigned char alias_checksum;
484 480
485 if (!unicode) { 481 if (!unicode) {
@@ -534,9 +530,7 @@ ParseLong:
534 goto ParseLong; 530 goto ParseLong;
535 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME)) 531 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME))
536 goto RecEnd; 532 goto RecEnd;
537 for (sum = 0, i = 0; i < 11; i++) 533 if (fat_checksum(de->name) != alias_checksum)
538 sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i];
539 if (sum != alias_checksum)
540 long_slots = 0; 534 long_slots = 0;
541 } 535 }
542 536
diff --git a/fs/vfat/namei.c b/fs/vfat/namei.c
index 1c6f6b57ef1c..467346b123d9 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,
621 } 621 }
622 622
623 /* build the entry of long file name */ 623 /* build the entry of long file name */
624 for (cksum = i = 0; i < 11; i++) 624 cksum = fat_checksum(msdos_name);
625 cksum = (((cksum&1)<<7)|((cksum&0xfe)>>1)) + msdos_name[i];
626 625
627 *nr_slots = usize / 13; 626 *nr_slots = usize / 13;
628 for (ps = slots, i = *nr_slots; i > 0; i--, ps++) { 627 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 9a3d27257984..941da5c016a0 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)
282 MSDOS_I(inode)->i_attrs; 282 MSDOS_I(inode)->i_attrs;
283} 283}
284 284
285static inline unsigned char fat_checksum(const __u8 *name)
286{
287 unsigned char s = name[0];
288 s = (s<<7) + (s>>1) + name[1]; s = (s<<7) + (s>>1) + name[2];
289 s = (s<<7) + (s>>1) + name[3]; s = (s<<7) + (s>>1) + name[4];
290 s = (s<<7) + (s>>1) + name[5]; s = (s<<7) + (s>>1) + name[6];
291 s = (s<<7) + (s>>1) + name[7]; s = (s<<7) + (s>>1) + name[8];
292 s = (s<<7) + (s>>1) + name[9]; s = (s<<7) + (s>>1) + name[10];
293 return s;
294}
295
285static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) 296static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus)
286{ 297{
287 return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus 298 return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus