summaryrefslogtreecommitdiffstats
path: root/fs/udf/truncate.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2000-03-07 15:45:24 +0000
committerRalf Baechle <ralf@linux-mips.org>2000-03-07 15:45:24 +0000
commit9f9f3e6e8548a596697778337110a423c384b6f3 (patch)
tree5dd4b290ef532cf5ecb058e1a92cd3435afeac8c /fs/udf/truncate.c
parentd5c9a365ee7d2fded249aa5abfc5e89587583029 (diff)
Merge with Linux 2.3.49.
Diffstat (limited to 'fs/udf/truncate.c')
-rw-r--r--fs/udf/truncate.c101
1 files changed, 75 insertions, 26 deletions
diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c
index f5602dc0e..262a411d6 100644
--- a/fs/udf/truncate.c
+++ b/fs/udf/truncate.c
@@ -32,27 +32,34 @@
#include "udf_i.h"
#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 offset)
+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 neloc = { 0, 0 };
- int nelen = 0;
int blocks = inode->i_sb->s_blocksize / 512;
int last_block = (elen + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
+ int first_block = (nelen + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
- if (offset)
+ if (nelen)
{
- nelen = (etype << 30) |
- (((offset - 1) << inode->i_sb->s_blocksize_bits) +
- (inode->i_size & (inode->i_sb->s_blocksize - 1)));
neloc = eloc;
+ nelen = (etype << 30) | nelen;
+ }
+
+ if (elen != nelen)
+ {
+ udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 0);
+ if (last_block - first_block > 0)
+ {
+ if (etype == EXTENT_RECORDED_ALLOCATED)
+ {
+ inode->i_blocks -= (blocks * (last_block - first_block));
+ mark_inode_dirty(inode);
+ }
+ if (etype != EXTENT_NOT_RECORDED_NOT_ALLOCATED)
+ udf_free_blocks(inode, eloc, first_block, last_block - first_block);
+ }
}
- if (etype == EXTENT_RECORDED_ALLOCATED)
- inode->i_blocks -= (blocks * (last_block - offset));
- udf_write_aext(inode, bloc, extoffset, neloc, nelen, bh, 1);
- mark_inode_dirty(inode);
- if (etype != EXTENT_NOT_RECORDED_NOT_ALLOCATED)
- udf_free_blocks(inode, eloc, offset, last_block - offset);
}
void udf_trunc(struct inode * inode)
@@ -60,7 +67,7 @@ void udf_trunc(struct inode * inode)
lb_addr bloc, eloc, neloc = { 0, 0 };
Uint32 extoffset, elen, offset, nelen = 0, lelen = 0, lenalloc;
int etype;
- int first_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
+ int first_block = inode->i_size >> inode->i_sb->s_blocksize_bits;
struct buffer_head *bh = NULL;
int adsize;
@@ -71,10 +78,14 @@ void udf_trunc(struct inode * inode)
else
adsize = 0;
- if ((etype = inode_bmap(inode, first_block, &bloc, &extoffset, &eloc, &elen, &offset, &bh)) != -1)
+ 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));
+ 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)
lenalloc = extoffset;
@@ -103,11 +114,17 @@ void udf_trunc(struct inode * inode)
else
{
if (!memcmp(&UDF_I_LOCATION(inode), &bloc, sizeof(lb_addr)))
+ {
UDF_I_LENALLOC(inode) = lenalloc;
+ mark_inode_dirty(inode);
+ }
else
{
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, 1);
}
}
@@ -122,7 +139,10 @@ void udf_trunc(struct inode * inode)
lelen = 1;
}
else
- extent_trunc(inode, bloc, &extoffset, eloc, etype, elen, &bh, 0);
+ {
+ extent_trunc(inode, bloc, extoffset, eloc, etype, elen, &bh, 0);
+ extoffset += adsize;
+ }
}
if (lelen)
@@ -136,29 +156,42 @@ void udf_trunc(struct inode * inode)
else
{
if (!memcmp(&UDF_I_LOCATION(inode), &bloc, sizeof(lb_addr)))
+ {
UDF_I_LENALLOC(inode) = lenalloc;
+ mark_inode_dirty(inode);
+ }
else
{
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, 1);
}
}
}
else if (inode->i_size)
{
- char tetype;
-
if (offset)
{
extoffset -= adsize;
- tetype = udf_next_aext(inode, &bloc, &extoffset, &eloc, &elen, &bh, 1);
- if (tetype == EXTENT_NOT_RECORDED_NOT_ALLOCATED)
+ etype = udf_next_aext(inode, &bloc, &extoffset, &eloc, &elen, &bh, 1);
+ if (etype == EXTENT_NOT_RECORDED_NOT_ALLOCATED)
{
extoffset -= adsize;
- elen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) |
- (elen + (offset << inode->i_sb->s_blocksize_bits));
+ elen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) | (elen + offset);
udf_write_aext(inode, bloc, &extoffset, eloc, elen, &bh, 0);
}
+ else if (etype == EXTENT_NOT_RECORDED_ALLOCATED)
+ {
+ lb_addr neloc = { 0, 0 };
+ extoffset -= adsize;
+ 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_add_aext(inode, &bloc, &extoffset, eloc, (etype << 30) | elen, &bh, 1);
+ }
else
{
if (elen & (inode->i_sb->s_blocksize - 1))
@@ -170,8 +203,7 @@ void udf_trunc(struct inode * inode)
udf_write_aext(inode, bloc, &extoffset, eloc, elen, &bh, 1);
}
memset(&eloc, 0x00, sizeof(lb_addr));
- elen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) |
- (offset << inode->i_sb->s_blocksize_bits);
+ elen = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30) | offset;
udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
}
}
@@ -182,6 +214,8 @@ void udf_trunc(struct inode * inode)
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;
@@ -189,7 +223,22 @@ void udf_truncate(struct inode * inode)
return;
if (UDF_I_ALLOCTYPE(inode) == ICB_FLAG_AD_IN_ICB)
- UDF_I_LENALLOC(inode) = inode->i_size;
+ {
+ 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);