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> |
| 25 | #include <linux/udf_fs.h> |
| 26 | #include <linux/buffer_head.h> |
| 27 | |
| 28 | #include "udf_i.h" |
| 29 | #include "udf_sb.h" |
| 30 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 31 | static void extent_trunc(struct inode *inode, struct extent_position *epos, |
| 32 | kernel_lb_addr eloc, int8_t etype, uint32_t elen, |
| 33 | uint32_t nelen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | kernel_lb_addr neloc = { 0, 0 }; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 36 | int last_block = |
| 37 | (elen + inode->i_sb->s_blocksize - |
| 38 | 1) >> inode->i_sb->s_blocksize_bits; |
| 39 | int first_block = |
| 40 | (nelen + inode->i_sb->s_blocksize - |
| 41 | 1) >> inode->i_sb->s_blocksize_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 43 | if (nelen) { |
| 44 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
| 45 | udf_free_blocks(inode->i_sb, inode, eloc, 0, |
| 46 | last_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | etype = (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 48 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | neloc = eloc; |
| 50 | nelen = (etype << 30) | nelen; |
| 51 | } |
| 52 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 53 | if (elen != nelen) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 54 | udf_write_aext(inode, epos, neloc, nelen, 0); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 55 | if (last_block - first_block > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | if (etype == (EXT_RECORDED_ALLOCATED >> 30)) |
| 57 | mark_inode_dirty(inode); |
| 58 | |
| 59 | if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 60 | udf_free_blocks(inode->i_sb, inode, eloc, |
| 61 | first_block, |
| 62 | last_block - first_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Truncate the last extent to match i_size. This function assumes |
| 69 | * that preallocation extent is already truncated. |
| 70 | */ |
| 71 | void udf_truncate_tail_extent(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 73 | struct extent_position epos = { NULL, 0, {0, 0} }; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 74 | kernel_lb_addr eloc; |
| 75 | uint32_t elen, nelen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | uint64_t lbcount = 0; |
| 77 | int8_t etype = -1, netype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | int adsize; |
| 79 | |
| 80 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB || |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 81 | inode->i_size == UDF_I_LENEXTENTS(inode)) |
| 82 | return; |
| 83 | /* Are we going to delete the file anyway? */ |
| 84 | if (inode->i_nlink == 0) |
| 85 | return; |
| 86 | |
| 87 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) |
| 88 | adsize = sizeof(short_ad); |
| 89 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) |
| 90 | adsize = sizeof(long_ad); |
| 91 | else |
| 92 | BUG(); |
| 93 | |
| 94 | /* Find the last extent in the file */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 95 | while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) { |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 96 | etype = netype; |
| 97 | lbcount += elen; |
| 98 | if (lbcount > inode->i_size) { |
| 99 | if (lbcount - inode->i_size >= inode->i_sb->s_blocksize) |
| 100 | printk(KERN_WARNING |
| 101 | "udf_truncate_tail_extent(): Too long " |
| 102 | "extent after EOF in inode %u: i_size: " |
| 103 | "%Ld lbcount: %Ld extent %u+%u\n", |
| 104 | (unsigned)inode->i_ino, |
| 105 | (long long)inode->i_size, |
| 106 | (long long)lbcount, |
| 107 | (unsigned)eloc.logicalBlockNum, |
| 108 | (unsigned)elen); |
| 109 | nelen = elen - (lbcount - inode->i_size); |
| 110 | epos.offset -= adsize; |
| 111 | extent_trunc(inode, &epos, eloc, etype, elen, nelen); |
| 112 | epos.offset += adsize; |
| 113 | if (udf_next_aext(inode, &epos, &eloc, &elen, 1) != -1) |
| 114 | printk(KERN_ERR "udf_truncate_tail_extent(): " |
| 115 | "Extent after EOF in inode %u.\n", |
| 116 | (unsigned)inode->i_ino); |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | /* This inode entry is in-memory only and thus we don't have to mark |
| 121 | * the inode dirty */ |
| 122 | UDF_I_LENEXTENTS(inode) = inode->i_size; |
| 123 | brelse(epos.bh); |
| 124 | } |
| 125 | |
| 126 | void udf_discard_prealloc(struct inode *inode) |
| 127 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 128 | struct extent_position epos = { NULL, 0, {0, 0} }; |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 129 | kernel_lb_addr eloc; |
| 130 | uint32_t elen; |
| 131 | uint64_t lbcount = 0; |
| 132 | int8_t etype = -1, netype; |
| 133 | int adsize; |
| 134 | |
| 135 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB || |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 136 | inode->i_size == UDF_I_LENEXTENTS(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) |
| 140 | adsize = sizeof(short_ad); |
| 141 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) |
| 142 | adsize = sizeof(long_ad); |
| 143 | else |
| 144 | adsize = 0; |
| 145 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 146 | epos.block = UDF_I_LOCATION(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 148 | /* Find the last extent in the file */ |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 149 | while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | etype = netype; |
| 151 | lbcount += elen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 153 | if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) { |
| 154 | epos.offset -= adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | lbcount -= elen; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 156 | extent_trunc(inode, &epos, eloc, etype, elen, 0); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 157 | if (!epos.bh) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 158 | UDF_I_LENALLOC(inode) = |
| 159 | epos.offset - udf_file_entry_alloc_offset(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | mark_inode_dirty(inode); |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 161 | } else { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 162 | struct allocExtDesc *aed = |
| 163 | (struct allocExtDesc *)(epos.bh->b_data); |
| 164 | aed->lengthAllocDescs = |
| 165 | cpu_to_le32(epos.offset - |
| 166 | sizeof(struct allocExtDesc)); |
| 167 | if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) |
| 168 | || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 169 | udf_update_tag(epos.bh->b_data, epos.offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | else |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 171 | udf_update_tag(epos.bh->b_data, |
| 172 | sizeof(struct allocExtDesc)); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 173 | mark_buffer_dirty_inode(epos.bh, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
Jan Kara | 74584ae | 2007-06-16 10:16:14 -0700 | [diff] [blame] | 176 | /* This inode entry is in-memory only and thus we don't have to mark |
| 177 | * the inode dirty */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | UDF_I_LENEXTENTS(inode) = lbcount; |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 179 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 182 | void udf_truncate_extents(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 184 | struct extent_position epos; |
| 185 | kernel_lb_addr eloc, neloc = { 0, 0 }; |
| 186 | uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | int8_t etype; |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 188 | struct super_block *sb = inode->i_sb; |
| 189 | sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 190 | loff_t byte_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | int adsize; |
| 192 | |
| 193 | if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT) |
| 194 | adsize = sizeof(short_ad); |
| 195 | else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG) |
| 196 | adsize = sizeof(long_ad); |
| 197 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 198 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 200 | etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 201 | byte_offset = |
| 202 | (offset << sb->s_blocksize_bits) + |
| 203 | (inode->i_size & (sb->s_blocksize - 1)); |
| 204 | if (etype != -1) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 205 | epos.offset -= adsize; |
| 206 | extent_trunc(inode, &epos, eloc, etype, elen, byte_offset); |
| 207 | epos.offset += adsize; |
Jan Kara | 60448b1 | 2007-05-08 00:35:13 -0700 | [diff] [blame] | 208 | if (byte_offset) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 209 | lenalloc = epos.offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 211 | lenalloc = epos.offset - adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 213 | if (!epos.bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | lenalloc -= udf_file_entry_alloc_offset(inode); |
| 215 | else |
| 216 | lenalloc -= sizeof(struct allocExtDesc); |
| 217 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 218 | while ((etype = |
| 219 | udf_current_aext(inode, &epos, &eloc, &elen, |
| 220 | 0)) != -1) { |
| 221 | if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 222 | udf_write_aext(inode, &epos, neloc, nelen, 0); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 223 | if (indirect_ext_len) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 224 | /* We managed to free all extents in the |
| 225 | * indirect extent - free it too */ |
| 226 | if (!epos.bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | BUG(); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 228 | udf_free_blocks(sb, inode, epos.block, |
| 229 | 0, indirect_ext_len); |
| 230 | } else { |
| 231 | if (!epos.bh) { |
| 232 | UDF_I_LENALLOC(inode) = |
| 233 | lenalloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | mark_inode_dirty(inode); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 235 | } else { |
| 236 | struct allocExtDesc *aed = |
| 237 | (struct allocExtDesc |
| 238 | *)(epos.bh->b_data); |
| 239 | aed->lengthAllocDescs = |
| 240 | cpu_to_le32(lenalloc); |
| 241 | if (!UDF_QUERY_FLAG |
| 242 | (sb, UDF_FLAG_STRICT) |
| 243 | || UDF_SB_UDFREV(sb) >= |
| 244 | 0x0201) |
| 245 | udf_update_tag(epos.bh-> |
| 246 | b_data, |
| 247 | lenalloc |
| 248 | + |
| 249 | sizeof |
| 250 | (struct |
| 251 | allocExtDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | else |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 253 | udf_update_tag(epos.bh-> |
| 254 | b_data, |
| 255 | sizeof |
| 256 | (struct |
| 257 | allocExtDesc)); |
| 258 | mark_buffer_dirty_inode(epos.bh, |
| 259 | inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 262 | brelse(epos.bh); |
| 263 | epos.offset = sizeof(struct allocExtDesc); |
| 264 | epos.block = eloc; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 265 | epos.bh = |
| 266 | udf_tread(sb, |
| 267 | udf_get_lb_pblock(sb, eloc, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (elen) |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 269 | indirect_ext_len = (elen + |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 270 | sb->s_blocksize - |
| 271 | 1) >> sb-> |
| 272 | s_blocksize_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 274 | indirect_ext_len = 1; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 275 | } else { |
| 276 | extent_trunc(inode, &epos, eloc, etype, elen, |
| 277 | 0); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 278 | epos.offset += adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 282 | if (indirect_ext_len) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 283 | if (!epos.bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | BUG(); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 285 | udf_free_blocks(sb, inode, epos.block, 0, |
| 286 | indirect_ext_len); |
| 287 | } else { |
| 288 | if (!epos.bh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | UDF_I_LENALLOC(inode) = lenalloc; |
| 290 | mark_inode_dirty(inode); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 291 | } else { |
| 292 | struct allocExtDesc *aed = |
| 293 | (struct allocExtDesc *)(epos.bh->b_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | aed->lengthAllocDescs = cpu_to_le32(lenalloc); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 295 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) |
| 296 | || UDF_SB_UDFREV(sb) >= 0x0201) |
| 297 | udf_update_tag(epos.bh->b_data, |
| 298 | lenalloc + |
| 299 | sizeof(struct |
| 300 | allocExtDesc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | else |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 302 | udf_update_tag(epos.bh->b_data, |
| 303 | sizeof(struct |
| 304 | allocExtDesc)); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 305 | mark_buffer_dirty_inode(epos.bh, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 308 | } else if (inode->i_size) { |
| 309 | if (byte_offset) { |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 310 | kernel_long_ad extent; |
| 311 | |
Jan Kara | 00a2b0f | 2006-08-15 13:56:26 +0200 | [diff] [blame] | 312 | /* |
| 313 | * OK, there is not extent covering inode->i_size and |
| 314 | * no extent above inode->i_size => truncate is |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 315 | * extending the file by 'offset' blocks. |
Jan Kara | 00a2b0f | 2006-08-15 13:56:26 +0200 | [diff] [blame] | 316 | */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 317 | if ((!epos.bh |
| 318 | && epos.offset == |
| 319 | udf_file_entry_alloc_offset(inode)) || (epos.bh |
| 320 | && epos. |
| 321 | offset == |
| 322 | sizeof |
| 323 | (struct |
| 324 | allocExtDesc))) |
| 325 | { |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 326 | /* File has no extents at all or has empty last |
| 327 | * indirect extent! Create a fake extent... */ |
| 328 | extent.extLocation.logicalBlockNum = 0; |
| 329 | extent.extLocation.partitionReferenceNum = 0; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 330 | extent.extLength = |
| 331 | EXT_NOT_RECORDED_NOT_ALLOCATED; |
| 332 | } else { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 333 | epos.offset -= adsize; |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 334 | etype = udf_next_aext(inode, &epos, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 335 | &extent.extLocation, |
| 336 | &extent.extLength, 0); |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 337 | extent.extLength |= etype << 30; |
Jan Kara | 00a2b0f | 2006-08-15 13:56:26 +0200 | [diff] [blame] | 338 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame^] | 339 | udf_extend_file(inode, &epos, &extent, |
| 340 | offset + |
| 341 | ((inode-> |
| 342 | i_size & (sb->s_blocksize - 1)) != |
| 343 | 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | UDF_I_LENEXTENTS(inode) = inode->i_size; |
| 347 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 348 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |