Skip to content

Commit

Permalink
fat: introduce a helper fat_get_blknr_offset()
Browse files Browse the repository at this point in the history
Introduce helper function to get the block number and offset for a given
i_pos value.  Use it in __fat_write_inode() now and later on in nfs.c

Signed-off-by: Namjae Jeon <[email protected]>
Signed-off-by: Ravishankar N <[email protected]>
Signed-off-by: Amit Sahrawat <[email protected]>
Acked-by: OGAWA Hirofumi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
namjaejeon authored and torvalds committed Apr 30, 2013
1 parent f21735d commit e22a444
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions fs/fat/fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus)
+ sbi->data_start;
}

static inline void fat_get_blknr_offset(struct msdos_sb_info *sbi,
loff_t i_pos, sector_t *blknr, int *offset)
{
*blknr = i_pos >> sbi->dir_per_block_bits;
*offset = i_pos & (sbi->dir_per_block - 1);
}

static inline loff_t fat_i_pos_read(struct msdos_sb_info *sbi,
struct inode *inode)
{
Expand Down
9 changes: 5 additions & 4 deletions fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ static int __fat_write_inode(struct inode *inode, int wait)
struct buffer_head *bh;
struct msdos_dir_entry *raw_entry;
loff_t i_pos;
int err;
sector_t blocknr;
int err, offset;

if (inode->i_ino == MSDOS_ROOT_INO)
return 0;
Expand All @@ -672,7 +673,8 @@ static int __fat_write_inode(struct inode *inode, int wait)
if (!i_pos)
return 0;

bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits);
fat_get_blknr_offset(sbi, i_pos, &blocknr, &offset);
bh = sb_bread(sb, blocknr);
if (!bh) {
fat_msg(sb, KERN_ERR, "unable to read inode block "
"for updating (i_pos %lld)", i_pos);
Expand All @@ -685,8 +687,7 @@ static int __fat_write_inode(struct inode *inode, int wait)
goto retry;
}

raw_entry = &((struct msdos_dir_entry *) (bh->b_data))
[i_pos & (sbi->dir_per_block - 1)];
raw_entry = &((struct msdos_dir_entry *) (bh->b_data))[offset];
if (S_ISDIR(inode->i_mode))
raw_entry->size = 0;
else
Expand Down

0 comments on commit e22a444

Please sign in to comment.