aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fat
diff options
context:
space:
mode:
authorSteven J. Magnani <steve@digidescorp.com>2012-07-30 17:42:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:19 -0400
commita943ed71c9171fb5e3b256e8022bbedff95cc826 (patch)
treee4b3a997bac0a802677557dbc52e5a55fb526a28 /fs/fat
parent497d48bd27ec1c44b4600e8e98a776188f2e11f2 (diff)
fat: accessors for msdos_dir_entry 'start' fields
Simplify code by providing accessor functions for the directory entry start cluster fields. Signed-off-by: Steven J. Magnani <steve@digidescorp.com> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/fat')
-rw-r--r--fs/fat/fat.h15
-rw-r--r--fs/fat/inode.c12
-rw-r--r--fs/fat/namei_msdos.c11
-rw-r--r--fs/fat/namei_vfat.c11
4 files changed, 24 insertions, 25 deletions
diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index fc35c5c69136..2deeeb86f331 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -217,6 +217,21 @@ static inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len)
217#endif 217#endif
218} 218}
219 219
220static inline int fat_get_start(const struct msdos_sb_info *sbi,
221 const struct msdos_dir_entry *de)
222{
223 int cluster = le16_to_cpu(de->start);
224 if (sbi->fat_bits == 32)
225 cluster |= (le16_to_cpu(de->starthi) << 16);
226 return cluster;
227}
228
229static inline void fat_set_start(struct msdos_dir_entry *de, int cluster)
230{
231 de->start = cpu_to_le16(cluster);
232 de->starthi = cpu_to_le16(cluster >> 16);
233}
234
220static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len) 235static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len)
221{ 236{
222#ifdef __BIG_ENDIAN 237#ifdef __BIG_ENDIAN
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 0038b32cb362..05e897fe9866 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -369,10 +369,7 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
369 inode->i_op = sbi->dir_ops; 369 inode->i_op = sbi->dir_ops;
370 inode->i_fop = &fat_dir_operations; 370 inode->i_fop = &fat_dir_operations;
371 371
372 MSDOS_I(inode)->i_start = le16_to_cpu(de->start); 372 MSDOS_I(inode)->i_start = fat_get_start(sbi, de);
373 if (sbi->fat_bits == 32)
374 MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
375
376 MSDOS_I(inode)->i_logstart = MSDOS_I(inode)->i_start; 373 MSDOS_I(inode)->i_logstart = MSDOS_I(inode)->i_start;
377 error = fat_calc_dir_size(inode); 374 error = fat_calc_dir_size(inode);
378 if (error < 0) 375 if (error < 0)
@@ -385,9 +382,7 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
385 inode->i_mode = fat_make_mode(sbi, de->attr, 382 inode->i_mode = fat_make_mode(sbi, de->attr,
386 ((sbi->options.showexec && !is_exec(de->name + 8)) 383 ((sbi->options.showexec && !is_exec(de->name + 8))
387 ? S_IRUGO|S_IWUGO : S_IRWXUGO)); 384 ? S_IRUGO|S_IWUGO : S_IRWXUGO));
388 MSDOS_I(inode)->i_start = le16_to_cpu(de->start); 385 MSDOS_I(inode)->i_start = fat_get_start(sbi, de);
389 if (sbi->fat_bits == 32)
390 MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
391 386
392 MSDOS_I(inode)->i_logstart = MSDOS_I(inode)->i_start; 387 MSDOS_I(inode)->i_logstart = MSDOS_I(inode)->i_start;
393 inode->i_size = le32_to_cpu(de->size); 388 inode->i_size = le32_to_cpu(de->size);
@@ -613,8 +608,7 @@ retry:
613 else 608 else
614 raw_entry->size = cpu_to_le32(inode->i_size); 609 raw_entry->size = cpu_to_le32(inode->i_size);
615 raw_entry->attr = fat_make_attrs(inode); 610 raw_entry->attr = fat_make_attrs(inode);
616 raw_entry->start = cpu_to_le16(MSDOS_I(inode)->i_logstart); 611 fat_set_start(raw_entry, MSDOS_I(inode)->i_logstart);
617 raw_entry->starthi = cpu_to_le16(MSDOS_I(inode)->i_logstart >> 16);
618 fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time, 612 fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
619 &raw_entry->date, NULL); 613 &raw_entry->date, NULL);
620 if (sbi->options.isvfat) { 614 if (sbi->options.isvfat) {
diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 70d993a93805..b0e12bf9f4a1 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -246,8 +246,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
246 de.ctime_cs = 0; 246 de.ctime_cs = 0;
247 de.time = time; 247 de.time = time;
248 de.date = date; 248 de.date = date;
249 de.start = cpu_to_le16(cluster); 249 fat_set_start(&de, cluster);
250 de.starthi = cpu_to_le16(cluster >> 16);
251 de.size = 0; 250 de.size = 0;
252 251
253 err = fat_add_entries(dir, &de, 1, sinfo); 252 err = fat_add_entries(dir, &de, 1, sinfo);
@@ -530,9 +529,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
530 mark_inode_dirty(old_inode); 529 mark_inode_dirty(old_inode);
531 530
532 if (update_dotdot) { 531 if (update_dotdot) {
533 int start = MSDOS_I(new_dir)->i_logstart; 532 fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
534 dotdot_de->start = cpu_to_le16(start);
535 dotdot_de->starthi = cpu_to_le16(start >> 16);
536 mark_buffer_dirty_inode(dotdot_bh, old_inode); 533 mark_buffer_dirty_inode(dotdot_bh, old_inode);
537 if (IS_DIRSYNC(new_dir)) { 534 if (IS_DIRSYNC(new_dir)) {
538 err = sync_dirty_buffer(dotdot_bh); 535 err = sync_dirty_buffer(dotdot_bh);
@@ -572,9 +569,7 @@ error_dotdot:
572 corrupt = 1; 569 corrupt = 1;
573 570
574 if (update_dotdot) { 571 if (update_dotdot) {
575 int start = MSDOS_I(old_dir)->i_logstart; 572 fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
576 dotdot_de->start = cpu_to_le16(start);
577 dotdot_de->starthi = cpu_to_le16(start >> 16);
578 mark_buffer_dirty_inode(dotdot_bh, old_inode); 573 mark_buffer_dirty_inode(dotdot_bh, old_inode);
579 corrupt |= sync_dirty_buffer(dotdot_bh); 574 corrupt |= sync_dirty_buffer(dotdot_bh);
580 } 575 }
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 6cc480652433..6a6d8c0715a1 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -651,8 +651,7 @@ shortname:
651 de->time = de->ctime = time; 651 de->time = de->ctime = time;
652 de->date = de->cdate = de->adate = date; 652 de->date = de->cdate = de->adate = date;
653 de->ctime_cs = time_cs; 653 de->ctime_cs = time_cs;
654 de->start = cpu_to_le16(cluster); 654 fat_set_start(de, cluster);
655 de->starthi = cpu_to_le16(cluster >> 16);
656 de->size = 0; 655 de->size = 0;
657out_free: 656out_free:
658 __putname(uname); 657 __putname(uname);
@@ -965,9 +964,7 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
965 mark_inode_dirty(old_inode); 964 mark_inode_dirty(old_inode);
966 965
967 if (update_dotdot) { 966 if (update_dotdot) {
968 int start = MSDOS_I(new_dir)->i_logstart; 967 fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
969 dotdot_de->start = cpu_to_le16(start);
970 dotdot_de->starthi = cpu_to_le16(start >> 16);
971 mark_buffer_dirty_inode(dotdot_bh, old_inode); 968 mark_buffer_dirty_inode(dotdot_bh, old_inode);
972 if (IS_DIRSYNC(new_dir)) { 969 if (IS_DIRSYNC(new_dir)) {
973 err = sync_dirty_buffer(dotdot_bh); 970 err = sync_dirty_buffer(dotdot_bh);
@@ -1009,9 +1006,7 @@ error_dotdot:
1009 corrupt = 1; 1006 corrupt = 1;
1010 1007
1011 if (update_dotdot) { 1008 if (update_dotdot) {
1012 int start = MSDOS_I(old_dir)->i_logstart; 1009 fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
1013 dotdot_de->start = cpu_to_le16(start);
1014 dotdot_de->starthi = cpu_to_le16(start >> 16);
1015 mark_buffer_dirty_inode(dotdot_bh, old_inode); 1010 mark_buffer_dirty_inode(dotdot_bh, old_inode);
1016 corrupt |= sync_dirty_buffer(dotdot_bh); 1011 corrupt |= sync_dirty_buffer(dotdot_bh);
1017 } 1012 }