Skip to content

Commit

Permalink
NTFS: In fs/ntfs/dir.c, use i_size_read() once and then the cached value
Browse files Browse the repository at this point in the history
      afterwards.

Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
  • Loading branch information
AntonAltaparmakov committed May 5, 2005
1 parent 3676367 commit 206f9f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions fs/ntfs/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ ToDo/Notes:
- Use i_size_read() in fs/ntfs/compress.c at the start of the read and
use the cached value afterwards. Cache the initialized_size in the
same way and protect access to the two sizes using the size_lock.
- Use i_size_read() in fs/ntfs/dir.c once and then use the cached
value afterwards.

2.1.22 - Many bug and race fixes and error handling improvements.

Expand Down
13 changes: 7 additions & 6 deletions fs/ntfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ static inline int ntfs_filldir(ntfs_volume *vol, loff_t fpos,
static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
s64 ia_pos, ia_start, prev_ia_pos, bmp_pos;
loff_t fpos;
loff_t fpos, i_size;
struct inode *bmp_vi, *vdir = filp->f_dentry->d_inode;
struct super_block *sb = vdir->i_sb;
ntfs_inode *ndir = NTFS_I(vdir);
Expand All @@ -1122,7 +1122,8 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
vdir->i_ino, fpos);
rc = err = 0;
/* Are we at end of dir yet? */
if (fpos >= vdir->i_size + vol->mft_record_size)
i_size = i_size_read(vdir);
if (fpos >= i_size + vol->mft_record_size)
goto done;
/* Emulate . and .. for all directories. */
if (!fpos) {
Expand Down Expand Up @@ -1264,7 +1265,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
bmp_mapping = bmp_vi->i_mapping;
/* Get the starting bitmap bit position and sanity check it. */
bmp_pos = ia_pos >> ndir->itype.index.block_size_bits;
if (unlikely(bmp_pos >> 3 >= bmp_vi->i_size)) {
if (unlikely(bmp_pos >> 3 >= i_size_read(bmp_vi))) {
ntfs_error(sb, "Current index allocation position exceeds "
"index bitmap size.");
goto err_out;
Expand Down Expand Up @@ -1301,7 +1302,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
goto get_next_bmp_page;
}
/* If we have reached the end of the bitmap, we are done. */
if (unlikely(((bmp_pos + cur_bmp_pos) >> 3) >= vdir->i_size))
if (unlikely(((bmp_pos + cur_bmp_pos) >> 3) >= i_size))
goto unm_EOD;
ia_pos = (bmp_pos + cur_bmp_pos) <<
ndir->itype.index.block_size_bits;
Expand Down Expand Up @@ -1441,7 +1442,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
ntfs_unmap_page(bmp_page);
EOD:
/* We are finished, set fpos to EOD. */
fpos = vdir->i_size + vol->mft_record_size;
fpos = i_size + vol->mft_record_size;
abort:
kfree(name);
done:
Expand Down Expand Up @@ -1495,7 +1496,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
static int ntfs_dir_open(struct inode *vi, struct file *filp)
{
if (sizeof(unsigned long) < 8) {
if (vi->i_size > MAX_LFS_FILESIZE)
if (i_size_read(vi) > MAX_LFS_FILESIZE)
return -EFBIG;
}
return 0;
Expand Down

0 comments on commit 206f9f3

Please sign in to comment.