Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * truncate.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Truncate handling routines for the OSTA-UDF(tm) filesystem. |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * COPYRIGHT |
| 8 | * This file is distributed under the terms of the GNU General Public |
| 9 | * License (GPL). Copies of the GPL can be obtained from: |
| 10 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 11 | * Each contributing author retains all rights to their own work. |
| 12 | * |
| 13 | * (C) 1999-2004 Ben Fennema |
| 14 | * (C) 1999 Stelias Computing Inc |
| 15 | * |
| 16 | * HISTORY |
| 17 | * |
| 18 | * 02/24/99 blf Created. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "udfdecl.h" |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "udf_i.h" |
| 27 | #include "udf_sb.h" |
| 28 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 29 | static void extent_trunc(struct inode *inode, struct extent_position *epos, |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 30 | struct kernel_lb_addr *eloc, int8_t etype, uint32_t elen, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 31 | uint32_t nelen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 33 | struct kernel_lb_addr neloc = {}; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 34 | int last_block = (elen + inode->i_sb->s_blocksize - 1) >> |
| 35 | inode->i_sb->s_blocksize_bits; |
| 36 | int first_block = (nelen + inode->i_sb->s_blocksize - 1) >> |
| 37 | inode->i_sb->s_blocksize_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 39 | if (nelen) { |
| 40 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
| 41 | udf_free_blocks(inode->i_sb, inode, eloc, 0, |
| 42 | last_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 44 | } else |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 45 | neloc = *eloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | nelen = (etype << 30) | nelen; |
| 47 | } |
| 48 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 49 | if (elen != nelen) { |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 50 | udf_write_aext(inode, epos, &neloc, nelen, 0); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 51 | if (last_block - first_block > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | if (etype == (EXT_RECORDED_ALLOCATED >> 30)) |
| 53 | mark_inode_dirty(inode); |
| 54 | |
| 55 | if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 56 | udf_free_blocks(inode->i_sb, inode, eloc, |
| 57 | first_block, |
| 58 | last_block - first_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 63 | /* |
| 64 | * Truncate the last extent to match i_size. This function assumes |
| 65 | * that preallocation extent is already truncated. |
| 66 | */ |
| 67 | void udf_truncate_tail_extent(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 69 | struct extent_position epos = {}; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 70 | struct kernel_lb_addr eloc; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 71 | uint32_t elen, nelen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | uint64_t lbcount = 0; |
| 73 | int8_t etype = -1, netype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | int adsize; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 75 | struct udf_inode_info *iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 77 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB || |
| 78 | inode->i_size == iinfo->i_lenExtents) |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 79 | return; |
| 80 | /* Are we going to delete the file anyway? */ |
| 81 | if (inode->i_nlink == 0) |
| 82 | return; |
| 83 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 84 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 85 | adsize = sizeof(struct short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 86 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 87 | adsize = sizeof(struct long_ad); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 88 | else |
| 89 | BUG(); |
| 90 | |
| 91 | /* Find the last extent in the file */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 92 | while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) { |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 93 | etype = netype; |
| 94 | lbcount += elen; |
| 95 | if (lbcount > inode->i_size) { |
| 96 | if (lbcount - inode->i_size >= inode->i_sb->s_blocksize) |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 97 | udf_warn(inode->i_sb, |
| 98 | "Too long extent after EOF in inode %u: i_size: %lld lbcount: %lld extent %u+%u\n", |
| 99 | (unsigned)inode->i_ino, |
| 100 | (long long)inode->i_size, |
| 101 | (long long)lbcount, |
| 102 | (unsigned)eloc.logicalBlockNum, |
| 103 | (unsigned)elen); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 104 | nelen = elen - (lbcount - inode->i_size); |
| 105 | epos.offset -= adsize; |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 106 | extent_trunc(inode, &epos, &eloc, etype, elen, nelen); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 107 | epos.offset += adsize; |
| 108 | if (udf_next_aext(inode, &epos, &eloc, &elen, 1) != -1) |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 109 | udf_err(inode->i_sb, |
| 110 | "Extent after EOF in inode %u\n", |
| 111 | (unsigned)inode->i_ino); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 112 | break; |
| 113 | } |
| 114 | } |
| 115 | /* This inode entry is in-memory only and thus we don't have to mark |
| 116 | * the inode dirty */ |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 117 | iinfo->i_lenExtents = inode->i_size; |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 118 | brelse(epos.bh); |
| 119 | } |
| 120 | |
| 121 | void udf_discard_prealloc(struct inode *inode) |
| 122 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 123 | struct extent_position epos = { NULL, 0, {0, 0} }; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 124 | struct kernel_lb_addr eloc; |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 125 | uint32_t elen; |
| 126 | uint64_t lbcount = 0; |
| 127 | int8_t etype = -1, netype; |
| 128 | int adsize; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 129 | struct udf_inode_info *iinfo = UDF_I(inode); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 130 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 131 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB || |
| 132 | inode->i_size == iinfo->i_lenExtents) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 135 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 136 | adsize = sizeof(struct short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 137 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 138 | adsize = sizeof(struct long_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | else |
| 140 | adsize = 0; |
| 141 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 142 | epos.block = iinfo->i_location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 144 | /* Find the last extent in the file */ |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 145 | while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | etype = netype; |
| 147 | lbcount += elen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 149 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
| 150 | epos.offset -= adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | lbcount -= elen; |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 152 | extent_trunc(inode, &epos, &eloc, etype, elen, 0); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 153 | if (!epos.bh) { |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 154 | iinfo->i_lenAlloc = |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 155 | epos.offset - |
| 156 | udf_file_entry_alloc_offset(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | mark_inode_dirty(inode); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 158 | } else { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 159 | struct allocExtDesc *aed = |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 160 | (struct allocExtDesc *)(epos.bh->b_data); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 161 | aed->lengthAllocDescs = |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 162 | cpu_to_le32(epos.offset - |
| 163 | sizeof(struct allocExtDesc)); |
| 164 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 165 | UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 166 | udf_update_tag(epos.bh->b_data, epos.offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | else |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 168 | udf_update_tag(epos.bh->b_data, |
| 169 | sizeof(struct allocExtDesc)); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 170 | mark_buffer_dirty_inode(epos.bh, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | } |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 173 | /* This inode entry is in-memory only and thus we don't have to mark |
| 174 | * the inode dirty */ |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 175 | iinfo->i_lenExtents = lbcount; |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 176 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
marcin.slusarz@gmail.com | 456390d | 2008-01-30 22:03:56 +0100 | [diff] [blame] | 179 | static void udf_update_alloc_ext_desc(struct inode *inode, |
| 180 | struct extent_position *epos, |
| 181 | u32 lenalloc) |
| 182 | { |
| 183 | struct super_block *sb = inode->i_sb; |
| 184 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 185 | |
| 186 | struct allocExtDesc *aed = (struct allocExtDesc *) (epos->bh->b_data); |
| 187 | int len = sizeof(struct allocExtDesc); |
| 188 | |
| 189 | aed->lengthAllocDescs = cpu_to_le32(lenalloc); |
| 190 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) || sbi->s_udfrev >= 0x0201) |
| 191 | len += lenalloc; |
| 192 | |
| 193 | udf_update_tag(epos->bh->b_data, len); |
| 194 | mark_buffer_dirty_inode(epos->bh, inode); |
| 195 | } |
| 196 | |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 197 | /* |
| 198 | * Truncate extents of inode to inode->i_size. This function can be used only |
| 199 | * for making file shorter. For making file longer, udf_extend_file() has to |
| 200 | * be used. |
| 201 | */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 202 | void udf_truncate_extents(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 204 | struct extent_position epos; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 205 | struct kernel_lb_addr eloc, neloc = {}; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 206 | uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | int8_t etype; |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 208 | struct super_block *sb = inode->i_sb; |
| 209 | sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 210 | loff_t byte_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | int adsize; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 212 | struct udf_inode_info *iinfo = UDF_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 214 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 215 | adsize = sizeof(struct short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 216 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 217 | adsize = sizeof(struct long_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 219 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 221 | etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 222 | byte_offset = (offset << sb->s_blocksize_bits) + |
| 223 | (inode->i_size & (sb->s_blocksize - 1)); |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 224 | if (etype == -1) { |
| 225 | /* We should extend the file? */ |
| 226 | WARN_ON(byte_offset); |
| 227 | return; |
| 228 | } |
| 229 | epos.offset -= adsize; |
| 230 | extent_trunc(inode, &epos, &eloc, etype, elen, byte_offset); |
| 231 | epos.offset += adsize; |
| 232 | if (byte_offset) |
| 233 | lenalloc = epos.offset; |
| 234 | else |
| 235 | lenalloc = epos.offset - adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 237 | if (!epos.bh) |
| 238 | lenalloc -= udf_file_entry_alloc_offset(inode); |
| 239 | else |
| 240 | lenalloc -= sizeof(struct allocExtDesc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 242 | while ((etype = udf_current_aext(inode, &epos, &eloc, |
| 243 | &elen, 0)) != -1) { |
| 244 | if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { |
| 245 | udf_write_aext(inode, &epos, &neloc, nelen, 0); |
| 246 | if (indirect_ext_len) { |
| 247 | /* We managed to free all extents in the |
| 248 | * indirect extent - free it too */ |
| 249 | BUG_ON(!epos.bh); |
Jan Kara | 17dc59b | 2012-07-09 13:24:21 +0200 | [diff] [blame] | 250 | udf_free_blocks(sb, NULL, &epos.block, |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 251 | 0, indirect_ext_len); |
| 252 | } else if (!epos.bh) { |
| 253 | iinfo->i_lenAlloc = lenalloc; |
| 254 | mark_inode_dirty(inode); |
| 255 | } else |
| 256 | udf_update_alloc_ext_desc(inode, |
| 257 | &epos, lenalloc); |
| 258 | brelse(epos.bh); |
| 259 | epos.offset = sizeof(struct allocExtDesc); |
| 260 | epos.block = eloc; |
| 261 | epos.bh = udf_tread(sb, |
| 262 | udf_get_lb_pblock(sb, &eloc, 0)); |
| 263 | if (elen) |
| 264 | indirect_ext_len = |
| 265 | (elen + sb->s_blocksize - 1) >> |
| 266 | sb->s_blocksize_bits; |
| 267 | else |
| 268 | indirect_ext_len = 1; |
| 269 | } else { |
| 270 | extent_trunc(inode, &epos, &eloc, etype, elen, 0); |
| 271 | epos.offset += adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 274 | |
| 275 | if (indirect_ext_len) { |
| 276 | BUG_ON(!epos.bh); |
Jan Kara | 17dc59b | 2012-07-09 13:24:21 +0200 | [diff] [blame] | 277 | udf_free_blocks(sb, NULL, &epos.block, 0, indirect_ext_len); |
Jan Kara | 7e49b6f | 2010-10-22 00:30:26 +0200 | [diff] [blame] | 278 | } else if (!epos.bh) { |
| 279 | iinfo->i_lenAlloc = lenalloc; |
| 280 | mark_inode_dirty(inode); |
| 281 | } else |
| 282 | udf_update_alloc_ext_desc(inode, &epos, lenalloc); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 283 | iinfo->i_lenExtents = inode->i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 285 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |