Commit 451cbaa1c328082832a8fbcc427cd4416c602c5a

Authored by OGAWA Hirofumi
Committed by Linus Torvalds
1 parent 4e57b68178

[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>

Showing 3 changed files with 14 additions and 10 deletions Side-by-side Diff

... ... @@ -263,7 +263,6 @@
263 263 unsigned char id;
264 264 unsigned char slot;
265 265 unsigned char slots;
266   - unsigned char sum;
267 266 unsigned char alias_checksum;
268 267  
269 268 if (!unicode) {
... ... @@ -317,9 +316,7 @@
317 316 goto parse_long;
318 317 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME))
319 318 continue;
320   - for (sum = 0, i = 0; i < 11; i++)
321   - sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i];
322   - if (sum != alias_checksum)
  319 + if (fat_checksum(de->name) != alias_checksum)
323 320 nr_slots = 0;
324 321 }
325 322  
... ... @@ -479,7 +476,6 @@
479 476 unsigned char id;
480 477 unsigned char slot;
481 478 unsigned char slots;
482   - unsigned char sum;
483 479 unsigned char alias_checksum;
484 480  
485 481 if (!unicode) {
... ... @@ -534,9 +530,7 @@
534 530 goto ParseLong;
535 531 if (IS_FREE(de->name) || (de->attr & ATTR_VOLUME))
536 532 goto RecEnd;
537   - for (sum = 0, i = 0; i < 11; i++)
538   - sum = (((sum&1)<<7)|((sum&0xfe)>>1)) + de->name[i];
539   - if (sum != alias_checksum)
  533 + if (fat_checksum(de->name) != alias_checksum)
540 534 long_slots = 0;
541 535 }
542 536  
... ... @@ -621,8 +621,7 @@
621 621 }
622 622  
623 623 /* build the entry of long file name */
624   - for (cksum = i = 0; i < 11; i++)
625   - cksum = (((cksum&1)<<7)|((cksum&0xfe)>>1)) + msdos_name[i];
  624 + cksum = fat_checksum(msdos_name);
626 625  
627 626 *nr_slots = usize / 13;
628 627 for (ps = slots, i = *nr_slots; i > 0; i--, ps++) {
include/linux/msdos_fs.h
... ... @@ -282,6 +282,17 @@
282 282 MSDOS_I(inode)->i_attrs;
283 283 }
284 284  
  285 +static 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 +
285 296 static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus)
286 297 {
287 298 return ((sector_t)clus - FAT_START_ENT) * sbi->sec_per_clus