Skip to content

Commit f63afdb

Browse files
author
Tao Ma
committed
ocfs2: make __ocfs2_page_mkwrite handle file end properly.
__ocfs2_page_mkwrite now is broken in handling file end. 1. the last page should be the page contains i_size - 1. 2. the len in the last page is also calculated wrong. So change them accordingly. Acked-by: Mark Fasheh <mfasheh@suse.com> Signed-off-by: Tao Ma <tao.ma@oracle.com>
1 parent f5ce5a0 commit f63afdb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/ocfs2/mmap.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ static int __ocfs2_page_mkwrite(struct inode *inode, struct buffer_head *di_bh,
7474
/*
7575
* Another node might have truncated while we were waiting on
7676
* cluster locks.
77+
* We don't check size == 0 before the shift. This is borrowed
78+
* from do_generic_file_read.
7779
*/
78-
last_index = size >> PAGE_CACHE_SHIFT;
79-
if (page->index > last_index) {
80+
last_index = (size - 1) >> PAGE_CACHE_SHIFT;
81+
if (unlikely(!size || page->index > last_index)) {
8082
ret = -EINVAL;
8183
goto out;
8284
}
@@ -107,7 +109,7 @@ static int __ocfs2_page_mkwrite(struct inode *inode, struct buffer_head *di_bh,
107109
* because the "write" would invalidate their data.
108110
*/
109111
if (page->index == last_index)
110-
len = size & ~PAGE_CACHE_MASK;
112+
len = ((size - 1) & ~PAGE_CACHE_MASK) + 1;
111113

112114
ret = ocfs2_write_begin_nolock(mapping, pos, len, 0, &locked_page,
113115
&fsdata, di_bh, page);

0 commit comments

Comments
 (0)