fs/ext3/inode.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext3/super.c | 4 ++ 2 files changed, 85 insertions(+) --- linux-2.5.73/fs/ext3/inode.c~ext3-san-jdike-2.5.73 2003-06-22 12:32:58.000000000 -0600 +++ linux-2.5.73-braam/fs/ext3/inode.c 2003-06-30 12:19:21.000000000 -0600 @@ -2945,3 +2945,84 @@ int ext3_change_inode_journal_flag(struc return err; } + +/* for each block: 1 ind + 1 dind + 1 tind + * for each block: 3 bitmap blocks + * for each block: 3 group descriptor blocks + * i inode block + * 1 superblock + * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quote files + * ((1+1+1) * 3 * nblocks) + 1 + 1 + 2 * EXT3_SINGLEDATA_TRANS_BLOCKS + * + * XXX assuming: + * (1) fs logic block size == page size + * (2) ext3 in writeback mode + */ +static inline int ext3_san_write_trans_blocks(int nblocks) +{ + int ret; + + ret = (1 + 1 + 1) * 3 * nblocks + 1 + 1; + +#ifdef CONFIG_QUOTA + ret += 2 * EXT3_SINGLEDATA_TRANS_BLOCKS; +#endif + + return ret; +} + +/* Alloc blocks for an inode, while don't create any buffer/page + * for data I/O; set the inode size if file is extended. + * + * @inode: target inode + * @blocks: array of logic block number + * @nblocks: how many blocks need be alloced + * @newsize: new filesize we should set + * + * return: 0 success, otherwise failed + * (*blocks) contains physical block number alloced + * + * XXX this assume the fs block size == page size + */ +int ext3_prep_san_write(struct inode *inode, long *blocks, + int nblocks, loff_t newsize) +{ + handle_t *handle; + struct buffer_head bh_tmp; + int needed_blocks; + int i, ret = 0, ret2; + + needed_blocks = ext3_san_write_trans_blocks(nblocks); + + lock_kernel(); + handle = ext3_journal_start(inode, needed_blocks); + if (IS_ERR(handle)) { + unlock_kernel(); + return PTR_ERR(handle); + } + unlock_kernel(); + + /* alloc blocks one by one */ + for (i = 0; i < nblocks; i++) { + ret = ext3_get_block_handle(handle, inode, blocks[i], + &bh_tmp, 1, 1); + if (ret) + break; + + blocks[i] = bh_tmp.b_blocknr; + } + + /* set inode size if needed */ + if (!ret && (newsize > inode->i_size)) { + inode->i_size = newsize; + ext3_mark_inode_dirty(handle, inode); + } + + lock_kernel(); + ret2 = ext3_journal_stop(handle); + unlock_kernel(); + + if (!ret) + ret = ret2; + return ret; +} --- linux-2.5.73/fs/ext3/super.c~ext3-san-jdike-2.5.73 2003-06-22 12:33:16.000000000 -0600 +++ linux-2.5.73-braam/fs/ext3/super.c 2003-06-30 12:16:36.000000000 -0600 @@ -2080,6 +2080,10 @@ static void __exit exit_ext3_fs(void) exit_ext3_xattr(); } +int ext3_prep_san_write(struct inode *inode, long *blocks, + int nblocks, loff_t newsize); +EXPORT_SYMBOL(ext3_prep_san_write); + MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions"); MODULE_LICENSE("GPL"); _