diff -rup -X dontdiff linux/fs/buffer.c linux.patched/fs/buffer.c --- linux/fs/buffer.c Mon Nov 19 14:14:27 2001 +++ linux.patched/fs/buffer.c Mon Nov 19 14:15:07 2001 @@ -1758,6 +1758,46 @@ int block_read_full_page(struct page *pa return 0; } +int generic_cont_expand(struct inode *inode, loff_t size) +{ + struct address_space *mapping = inode->i_mapping; + struct page *page; + unsigned long index, offset, limit; + int err; + + limit = current->rlim[RLIMIT_FSIZE].rlim_cur; + if (limit != RLIM_INFINITY) { + if (size > limit) { + send_sig(SIGXFSZ, current, 0); + size = limit; + } + } + offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */ + + /* ugh. in prepare/commit_write, if from==to==start of block, we + ** skip the prepare. make sure we never send an offset for the start + ** of a block + */ + if ((offset & (inode->i_sb->s_blocksize - 1)) == 0) { + offset++ ; + } + index = size >> PAGE_CACHE_SHIFT; + err = -ENOMEM; + page = grab_cache_page(mapping, index); + if (!page) + goto out; + err = mapping->a_ops->prepare_write(NULL, page, offset, offset); + if (!err) { + err = mapping->a_ops->commit_write(NULL, page, offset, offset); + } + UnlockPage(page); + page_cache_release(page); + if (err > 0) + err = 0; +out: + return err; +} + /* * For moronic filesystems that do not allow holes in file. * We may have to extend the file. diff -rup -X dontdiff linux/fs/reiserfs/file.c linux.patched/fs/reiserfs/file.c --- linux/fs/reiserfs/file.c Sat Oct 13 01:20:42 2001 +++ linux.patched/fs/reiserfs/file.c Mon Nov 19 14:15:07 2001 @@ -100,6 +100,13 @@ static int reiserfs_setattr(struct dentr if (inode_items_version(inode) == ITEM_VERSION_1 && attr->ia_size > MAX_NON_LFS) return -EFBIG ; + + /* fill in hole pointers in the expanding truncate case. */ + if (attr->ia_size > inode->i_size) { + error = generic_cont_expand(inode, attr->ia_size) ; + if (error) + return error ; + } } error = inode_change_ok(inode, attr) ; diff -rup -X dontdiff linux/fs/reiserfs/inode.c linux.patched/fs/reiserfs/inode.c --- linux/fs/reiserfs/inode.c Wed Oct 31 02:11:34 2001 +++ linux.patched/fs/reiserfs/inode.c Mon Nov 19 14:15:07 2001 @@ -1995,7 +1995,7 @@ static int reiserfs_commit_write(struct /* we test for O_SYNC here so we can commit the transaction ** for any packed tails the file might have had */ - if (f->f_flags & O_SYNC) { + if (f && f->f_flags & O_SYNC) { lock_kernel() ; reiserfs_commit_for_inode(inode) ; unlock_kernel(); diff -rup -X dontdiff linux/include/linux/fs.h linux.patched/include/linux/fs.h --- linux/include/linux/fs.h Mon Nov 19 14:14:30 2001 +++ linux.patched/include/linux/fs.h Mon Nov 19 14:15:07 2001 @@ -1380,6 +1380,7 @@ extern int block_read_full_page(struct p extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*); extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*, unsigned long *); +extern int generic_cont_expand(struct inode *inode, loff_t size) ; extern int block_commit_write(struct page *page, unsigned from, unsigned to); extern int block_sync_page(struct page *); diff -rup -X dontdiff linux/kernel/ksyms.c linux.patched/kernel/ksyms.c --- linux/kernel/ksyms.c Tue Nov 6 00:40:59 2001 +++ linux.patched/kernel/ksyms.c Mon Nov 19 14:15:07 2001 @@ -203,6 +203,7 @@ EXPORT_SYMBOL(block_write_full_page); EXPORT_SYMBOL(block_read_full_page); EXPORT_SYMBOL(block_prepare_write); EXPORT_SYMBOL(block_sync_page); +EXPORT_SYMBOL(generic_cont_expand); EXPORT_SYMBOL(cont_prepare_write); EXPORT_SYMBOL(generic_commit_write); EXPORT_SYMBOL(block_truncate_page); .