aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/bmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/bmap.c')
-rw-r--r--fs/gfs2/bmap.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 5e411d5f4697..6f482809d1a3 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -71,11 +71,13 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
71 71
72 if (!PageUptodate(page)) { 72 if (!PageUptodate(page)) {
73 void *kaddr = kmap(page); 73 void *kaddr = kmap(page);
74 u64 dsize = i_size_read(inode);
75
76 if (dsize > (dibh->b_size - sizeof(struct gfs2_dinode)))
77 dsize = dibh->b_size - sizeof(struct gfs2_dinode);
74 78
75 memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), 79 memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize);
76 ip->i_disksize); 80 memset(kaddr + dsize, 0, PAGE_CACHE_SIZE - dsize);
77 memset(kaddr + ip->i_disksize, 0,
78 PAGE_CACHE_SIZE - ip->i_disksize);
79 kunmap(page); 81 kunmap(page);
80 82
81 SetPageUptodate(page); 83 SetPageUptodate(page);
@@ -1038,13 +1040,15 @@ static int trunc_start(struct gfs2_inode *ip, u64 size)
1038 goto out; 1040 goto out;
1039 1041
1040 if (gfs2_is_stuffed(ip)) { 1042 if (gfs2_is_stuffed(ip)) {
1043 u64 dsize = size + sizeof(struct gfs2_dinode);
1041 ip->i_disksize = size; 1044 ip->i_disksize = size;
1042 ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; 1045 ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
1043 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 1046 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1044 gfs2_dinode_out(ip, dibh->b_data); 1047 gfs2_dinode_out(ip, dibh->b_data);
1045 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + size); 1048 if (dsize > dibh->b_size)
1049 dsize = dibh->b_size;
1050 gfs2_buffer_clear_tail(dibh, dsize);
1046 error = 1; 1051 error = 1;
1047
1048 } else { 1052 } else {
1049 if (size & (u64)(sdp->sd_sb.sb_bsize - 1)) 1053 if (size & (u64)(sdp->sd_sb.sb_bsize - 1))
1050 error = gfs2_block_truncate_page(ip->i_inode.i_mapping); 1054 error = gfs2_block_truncate_page(ip->i_inode.i_mapping);
@@ -1240,13 +1244,12 @@ int gfs2_file_dealloc(struct gfs2_inode *ip)
1240 * @ip: the file being written to 1244 * @ip: the file being written to
1241 * @offset: the offset to write to 1245 * @offset: the offset to write to
1242 * @len: the number of bytes being written 1246 * @len: the number of bytes being written
1243 * @alloc_required: set to 1 if an alloc is required, 0 otherwise
1244 * 1247 *
1245 * Returns: errno 1248 * Returns: 1 if an alloc is required, 0 otherwise
1246 */ 1249 */
1247 1250
1248int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset, 1251int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
1249 unsigned int len, int *alloc_required) 1252 unsigned int len)
1250{ 1253{
1251 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1254 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1252 struct buffer_head bh; 1255 struct buffer_head bh;
@@ -1254,26 +1257,23 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
1254 u64 lblock, lblock_stop, size; 1257 u64 lblock, lblock_stop, size;
1255 u64 end_of_file; 1258 u64 end_of_file;
1256 1259
1257 *alloc_required = 0;
1258
1259 if (!len) 1260 if (!len)
1260 return 0; 1261 return 0;
1261 1262
1262 if (gfs2_is_stuffed(ip)) { 1263 if (gfs2_is_stuffed(ip)) {
1263 if (offset + len > 1264 if (offset + len >
1264 sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) 1265 sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode))
1265 *alloc_required = 1; 1266 return 1;
1266 return 0; 1267 return 0;
1267 } 1268 }
1268 1269
1269 *alloc_required = 1;
1270 shift = sdp->sd_sb.sb_bsize_shift; 1270 shift = sdp->sd_sb.sb_bsize_shift;
1271 BUG_ON(gfs2_is_dir(ip)); 1271 BUG_ON(gfs2_is_dir(ip));
1272 end_of_file = (ip->i_disksize + sdp->sd_sb.sb_bsize - 1) >> shift; 1272 end_of_file = (ip->i_disksize + sdp->sd_sb.sb_bsize - 1) >> shift;
1273 lblock = offset >> shift; 1273 lblock = offset >> shift;
1274 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift; 1274 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift;
1275 if (lblock_stop > end_of_file) 1275 if (lblock_stop > end_of_file)
1276 return 0; 1276 return 1;
1277 1277
1278 size = (lblock_stop - lblock) << shift; 1278 size = (lblock_stop - lblock) << shift;
1279 do { 1279 do {
@@ -1281,12 +1281,11 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
1281 bh.b_size = size; 1281 bh.b_size = size;
1282 gfs2_block_map(&ip->i_inode, lblock, &bh, 0); 1282 gfs2_block_map(&ip->i_inode, lblock, &bh, 0);
1283 if (!buffer_mapped(&bh)) 1283 if (!buffer_mapped(&bh))
1284 return 0; 1284 return 1;
1285 size -= bh.b_size; 1285 size -= bh.b_size;
1286 lblock += (bh.b_size >> ip->i_inode.i_blkbits); 1286 lblock += (bh.b_size >> ip->i_inode.i_blkbits);
1287 } while(size > 0); 1287 } while(size > 0);
1288 1288
1289 *alloc_required = 0;
1290 return 0; 1289 return 0;
1291} 1290}
1292 1291