udf: Fix unalloc space handling in udf_update_inode

Writing of inode holding unallocated space info was broken because we first
cleared the buffer and after that checked whether it contains a tag meaning the
block holds unallocated space information.  Fix the problem by checking
appropriate in memory flag instead.

Also cleanup the function a bit along the way - most importantly lock buffer
when modifying its contents, check for buffer_write_io_error instead of
!buffer_uptodate, etc..

Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
Jan Kara 2010-01-08 16:46:29 +01:00
parent 57d54889cd
commit aae917cd18
1 changed files with 14 additions and 14 deletions

View File

@ -1412,16 +1412,16 @@ static int udf_update_inode(struct inode *inode, int do_sync)
udf_get_lb_pblock(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
&iinfo->i_location, 0)); &iinfo->i_location, 0));
if (!bh) { if (!bh) {
udf_debug("bread failure\n"); udf_debug("getblk failure\n");
return -EIO; return -ENOMEM;
} }
memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); lock_buffer(bh);
memset(bh->b_data, 0, inode->i_sb->s_blocksize);
fe = (struct fileEntry *)bh->b_data; fe = (struct fileEntry *)bh->b_data;
efe = (struct extendedFileEntry *)bh->b_data; efe = (struct extendedFileEntry *)bh->b_data;
if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) { if (iinfo->i_use) {
struct unallocSpaceEntry *use = struct unallocSpaceEntry *use =
(struct unallocSpaceEntry *)bh->b_data; (struct unallocSpaceEntry *)bh->b_data;
@ -1429,20 +1429,18 @@ static int udf_update_inode(struct inode *inode, int do_sync)
memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
iinfo->i_ext.i_data, inode->i_sb->s_blocksize - iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
sizeof(struct unallocSpaceEntry)); sizeof(struct unallocSpaceEntry));
use->descTag.tagIdent = cpu_to_le16(TAG_IDENT_USE);
use->descTag.tagLocation =
cpu_to_le32(iinfo->i_location.logicalBlockNum);
crclen = sizeof(struct unallocSpaceEntry) + crclen = sizeof(struct unallocSpaceEntry) +
iinfo->i_lenAlloc - sizeof(struct tag); iinfo->i_lenAlloc - sizeof(struct tag);
use->descTag.tagLocation = cpu_to_le32(
iinfo->i_location.
logicalBlockNum);
use->descTag.descCRCLength = cpu_to_le16(crclen); use->descTag.descCRCLength = cpu_to_le16(crclen);
use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use + use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
sizeof(struct tag), sizeof(struct tag),
crclen)); crclen));
use->descTag.tagChecksum = udf_tag_checksum(&use->descTag); use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
mark_buffer_dirty(bh); goto out;
brelse(bh);
return err;
} }
if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
@ -1597,18 +1595,20 @@ static int udf_update_inode(struct inode *inode, int do_sync)
fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number); fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
fe->descTag.tagLocation = cpu_to_le32( fe->descTag.tagLocation = cpu_to_le32(
iinfo->i_location.logicalBlockNum); iinfo->i_location.logicalBlockNum);
crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc - crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc - sizeof(struct tag);
sizeof(struct tag);
fe->descTag.descCRCLength = cpu_to_le16(crclen); fe->descTag.descCRCLength = cpu_to_le16(crclen);
fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(struct tag), fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(struct tag),
crclen)); crclen));
fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag); fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
out:
unlock_buffer(bh);
/* write the data blocks */ /* write the data blocks */
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
if (do_sync) { if (do_sync) {
sync_dirty_buffer(bh); sync_dirty_buffer(bh);
if (buffer_req(bh) && !buffer_uptodate(bh)) { if (buffer_write_io_error(bh)) {
printk(KERN_WARNING "IO error syncing udf inode " printk(KERN_WARNING "IO error syncing udf inode "
"[%s:%08lx]\n", inode->i_sb->s_id, "[%s:%08lx]\n", inode->i_sb->s_id,
inode->i_ino); inode->i_ino);