patch-2.4.6 linux/fs/udf/truncate.c

Next file: linux/fs/udf/udf_i.h
Previous file: linux/fs/udf/symlink.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.5/linux/fs/udf/truncate.c linux/fs/udf/truncate.c
@@ -7,7 +7,7 @@
  * CONTACTS
  *	E-mail regarding any portion of the Linux UDF file system should be
  *	directed to the development team mailing list (run by majordomo):
- *		linux_udf@hootie.lvld.hp.com
+ *		linux_udf@hpesjro.fc.hp.com
  *
  * COPYRIGHT
  *	This file is distributed under the terms of the GNU General Public
@@ -33,7 +33,7 @@
 #include "udf_sb.h"
 
 static void extent_trunc(struct inode * inode, lb_addr bloc, int extoffset,
-	lb_addr eloc, Uint8 etype, Uint32 elen, struct buffer_head **bh, Uint32 nelen)
+	lb_addr eloc, Uint8 etype, Uint32 elen, struct buffer_head *bh, Uint32 nelen)
 {
 	lb_addr neloc = { 0, 0 };
 	int blocks = inode->i_sb->s_blocksize / 512;
@@ -62,7 +62,7 @@
 	}
 }
 
-void udf_trunc(struct inode * inode)
+void udf_truncate_extents(struct inode * inode)
 {
 	lb_addr bloc, eloc, neloc = { 0, 0 };
 	Uint32 extoffset, elen, offset, nelen = 0, lelen = 0, lenalloc;
@@ -79,12 +79,11 @@
 		adsize = 0;
 
 	etype = inode_bmap(inode, first_block, &bloc, &extoffset, &eloc, &elen, &offset, &bh);
-	offset = (offset << inode->i_sb->s_blocksize_bits) |
-		(inode->i_size & (inode->i_sb->s_blocksize - 1));
+	offset += (inode->i_size & (inode->i_sb->s_blocksize - 1));
 	if (etype != -1)
 	{
 		extoffset -= adsize;
-		extent_trunc(inode, bloc, extoffset, eloc, etype, elen, &bh, offset);
+		extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, offset);
 		extoffset += adsize;
 
 		if (offset)
@@ -101,7 +100,7 @@
 		{
 			if (etype == EXTENT_NEXT_EXTENT_ALLOCDECS)
 			{
-				udf_write_aext(inode, bloc, &extoffset, neloc, nelen, &bh, 0);
+				udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 0);
 				extoffset = 0;
 				if (lelen)
 				{
@@ -122,9 +121,12 @@
 					{
 						struct AllocExtDesc *aed = (struct AllocExtDesc *)(bh->b_data);
 						aed->lengthAllocDescs = cpu_to_le32(lenalloc);
-						udf_update_tag(bh->b_data, lenalloc +
-							sizeof(struct AllocExtDesc));
-						mark_buffer_dirty(bh);
+						if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
+							udf_update_tag(bh->b_data, lenalloc +
+								sizeof(struct AllocExtDesc));
+						else
+							udf_update_tag(bh->b_data, sizeof(struct AllocExtDesc));
+						mark_buffer_dirty_inode(bh, inode);
 					}
 				}
 
@@ -140,7 +142,7 @@
 			}
 			else
 			{
-				extent_trunc(inode, bloc, extoffset, eloc, etype, elen, &bh, 0);
+				extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, 0);
 				extoffset += adsize;
 			}
 		}
@@ -164,9 +166,12 @@
 			{
 				struct AllocExtDesc *aed = (struct AllocExtDesc *)(bh->b_data);
 				aed->lengthAllocDescs = cpu_to_le32(lenalloc);
-				udf_update_tag(bh->b_data, lenalloc +
-					sizeof(struct AllocExtDesc));
-				mark_buffer_dirty(bh);
+				if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
+					udf_update_tag(bh->b_data, lenalloc +
+						sizeof(struct AllocExtDesc));
+				else
+					udf_update_tag(bh->b_data, sizeof(struct AllocExtDesc));
+				mark_buffer_dirty_inode(bh, inode);
 			}
 		}
 	}
@@ -180,7 +185,7 @@
 			{
 				extoffset -= adsize;
 				elen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) | (elen + offset);
-				udf_write_aext(inode, bloc, &extoffset, eloc, elen, &bh, 0);
+				udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 0);
 			}
 			else if (etype == EXTENT_NOT_RECORDED_ALLOCATED)
 			{
@@ -189,7 +194,7 @@
 				nelen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) |
 					((elen + offset + inode->i_sb->s_blocksize - 1) &
 					~(inode->i_sb->s_blocksize - 1));
-				udf_write_aext(inode, bloc, &extoffset, neloc, nelen, &bh, 1);
+				udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 1);
 				udf_add_aext(inode, &bloc, &extoffset, eloc, (etype << 30) | elen, &bh, 1);
 			}
 			else
@@ -200,7 +205,7 @@
 					elen = (EXTENT_RECORDED_ALLOCATED << 30) |
 						((elen + inode->i_sb->s_blocksize - 1) &
 						~(inode->i_sb->s_blocksize - 1));
-					udf_write_aext(inode, bloc, &extoffset, eloc, elen, &bh, 1);
+					udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 1);
 				}
 				memset(&eloc, 0x00, sizeof(lb_addr));
 				elen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) | offset;
@@ -208,40 +213,7 @@
 			}
 		}
 	}
+	UDF_I_LENEXTENTS(inode) = inode->i_size;
 
 	udf_release_data(bh);
-}
-
-void udf_truncate(struct inode * inode)
-{
-	int err;
-
-	if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
-			S_ISLNK(inode->i_mode)))
-		return;
-	if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
-		return;
-
-	if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
-	{
-		if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
-			inode->i_size))
-		{
-			udf_expand_file_adinicb(inode, inode->i_size, &err);
-			if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
-			{
-				inode->i_size = UDF_I_LENALLOC(inode);
-				return;
-			}
-			else
-				udf_trunc(inode);
-		}
-		else
-			UDF_I_LENALLOC(inode) = inode->i_size;
-	}
-	else
-		udf_trunc(inode);
-
-	inode->i_mtime = inode->i_ctime = CURRENT_TIME;
-	mark_inode_dirty(inode);
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)