From: Pat LaVarre Subject: Re: [PATCH] fs/udf/inode.c int shift sign extends Date: 16 Dec 2003 09:34:39 -0700 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <1071592479.24947.18.camel@patibmrh9> References: <1071276105.4957.8.camel@patibmrh9> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: linux-fsdevel@vger.kernel.org Return-path: Received: from email-out1.iomega.com ([147.178.1.82]:47845 "EHLO email.iomega.com") by vger.kernel.org with ESMTP id S261879AbTLPQe6 (ORCPT ); Tue, 16 Dec 2003 11:34:58 -0500 To: bfennema@falcon.csc.calpoly.edu In-Reply-To: <1071276105.4957.8.camel@patibmrh9> List-Id: linux-fsdevel.vger.kernel.org Ben F: > Oi. fs/udf/inode.c includes an always-false test: > > int type = laarr[curr].extLength & ~UDF_EXTENT_LENGTH_MASK; > ... > if ((type >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) I mean to say, always false because: a) 2 is not in -2 -1 0 1. b) The implicitly unsigned (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30) is 2. c) The implicitly signed (type >> 30) is in -2 -1 0 1. The following rewrite of this same patch also adds unrelated comments nearby in that same patched source file. These comments I made as I continued the http://udfko.blog-city.com/ kernelnewbie hunt for why udf.ko can't yet write more than 112 fragments per file without offending the Philips udfct_1.0r2/src/udf_tester/udf_test fsck of udf. The comments not enclosed in [square brackets] may be correct and helpful. Pat LaVarre --- linux-2.6.0-test11/fs/udf/inode.c 2003-11-26 13:46:12.000000000 -0700 +++ linux/fs/udf/inode.c 2003-12-16 09:16:45.726567440 -0700 @@ -612,7 +612,7 @@ static void udf_split_extents(struct ino if (offset) { - if ((type >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) + if (type == EXT_NOT_RECORDED_ALLOCATED) { udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset); laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | @@ -629,7 +629,7 @@ static void udf_split_extents(struct ino } laarr[curr].extLocation.logicalBlockNum = newblocknum; - if ((type >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) + if (type == EXT_NOT_RECORDED_NOT_ALLOCATED) laarr[curr].extLocation.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; laarr[curr].extLength = EXT_RECORDED_ALLOCATED | @@ -638,7 +638,7 @@ static void udf_split_extents(struct ino if (blen != offset + 1) { - if ((type >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) + if (type == EXT_NOT_RECORDED_ALLOCATED) laarr[curr].extLocation.logicalBlockNum += (offset + 1); laarr[curr].extLength = type | ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits); @@ -1596,6 +1596,13 @@ udf_iget(struct super_block *sb, lb_addr return inode; } +/* [Wrap udf_write_aext for good reasons which include:] + * + * Construct a new { elen, eloc } AD. + * + * Return (elen << 30) to succeed, else -1. + */ + int8_t udf_add_aext(struct inode *inode, lb_addr *bloc, int *extoffset, lb_addr eloc, uint32_t elen, struct buffer_head **bh, int inc) { @@ -1606,11 +1613,15 @@ int8_t udf_add_aext(struct inode *inode, int8_t etype; uint8_t *ptr; + /* Name the byte past the last AD (in FE else in AED). */ + if (!*bh) ptr = UDF_I_DATA(inode) + *extoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); else ptr = (*bh)->b_data + *extoffset; + /* Count bytes per AD. */ + if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) adsize = sizeof(short_ad); else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) @@ -1618,13 +1629,17 @@ int8_t udf_add_aext(struct inode *inode, else return -1; + /* If less than two more AD fit ... */ + if (*extoffset + (2 * adsize) > inode->i_sb->s_blocksize) { char *sptr, *dptr; struct buffer_head *nbh; int err, loffset; - lb_addr obloc = *bloc; + /* Allot nearby (and zero) a next extent of AD. */ + + lb_addr obloc = *bloc; if (!(bloc->logicalBlockNum = udf_new_block(inode->i_sb, inode, obloc.partitionReferenceNum, obloc.logicalBlockNum, &err))) { @@ -1641,9 +1656,14 @@ int8_t udf_add_aext(struct inode *inode, unlock_buffer(nbh); mark_buffer_dirty_inode(nbh, inode); + /* Link back if affordable. */ + aed = (struct allocExtDesc *)(nbh->b_data); if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); + + /* Move AD before overwrite, else append. */ + if (*extoffset + adsize > inode->i_sb->s_blocksize) { loffset = *extoffset; @@ -1659,7 +1679,6 @@ int8_t udf_add_aext(struct inode *inode, aed->lengthAllocDescs = cpu_to_le32(0); sptr = ptr; *extoffset = sizeof(struct allocExtDesc); - if (*bh) { aed = (struct allocExtDesc *)(*bh)->b_data; @@ -1672,12 +1691,18 @@ int8_t udf_add_aext(struct inode *inode, mark_inode_dirty(inode); } } + + /* Tag the new AED. */ + if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, bloc->logicalBlockNum, sizeof(tag)); else udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, bloc->logicalBlockNum, sizeof(tag)); + + /* Construct an AD to link to next extent of AD. */ + switch (UDF_I_ALLOCTYPE(inode)) { case ICBTAG_FLAG_AD_SHORT: @@ -1700,6 +1725,9 @@ int8_t udf_add_aext(struct inode *inode, break; } } + + /* Switch focus to the new AED. */ + if (*bh) { if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) @@ -1714,8 +1742,12 @@ int8_t udf_add_aext(struct inode *inode, *bh = nbh; } + /* Construct a new { elen, eloc } AD. */ + etype = udf_write_aext(inode, *bloc, extoffset, eloc, elen, *bh, inc); + /* Claim the space occupied by the new AD. */ + if (!*bh) { UDF_I_LENALLOC(inode) += adsize; @@ -1733,15 +1765,24 @@ int8_t udf_add_aext(struct inode *inode, mark_buffer_dirty_inode(*bh, inode); } + /* [Pass back success or failure.] */ + return etype; } +/* Construct a new { elen, eloc } AD. + * + * Return (elen << 30) to succeed, else -1. + */ + int8_t udf_write_aext(struct inode *inode, lb_addr bloc, int *extoffset, lb_addr eloc, uint32_t elen, struct buffer_head *bh, int inc) { int adsize; uint8_t *ptr; + /* Name the byte past the last AD (in FE else in AED). */ + if (!bh) ptr = UDF_I_DATA(inode) + *extoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); else @@ -1750,6 +1791,8 @@ int8_t udf_write_aext(struct inode *inod atomic_inc(&bh->b_count); } + /* Construct AD (and count bytes constructed). */ + switch (UDF_I_ALLOCTYPE(inode)) { case ICBTAG_FLAG_AD_SHORT: @@ -1773,6 +1816,8 @@ int8_t udf_write_aext(struct inode *inod return -1; } + /* [Do something for some good reason.] */ + if (bh) { if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) @@ -1787,8 +1832,13 @@ int8_t udf_write_aext(struct inode *inod else mark_inode_dirty(inode); + /* [Give some definite meaning to the inc parameter.] */ + if (inc) *extoffset += adsize; + + /* [Succeed by returning nonnegative.] */ + return (elen >> 30); }