aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/udf/inode.c')
-rw-r--r--fs/udf/inode.c1494
1 files changed, 766 insertions, 728 deletions
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 5b82e489af78..be6326f449a1 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -51,18 +51,18 @@ static int udf_update_inode(struct inode *, int);
51static void udf_fill_inode(struct inode *, struct buffer_head *); 51static void udf_fill_inode(struct inode *, struct buffer_head *);
52static int udf_alloc_i_data(struct inode *inode, size_t size); 52static int udf_alloc_i_data(struct inode *inode, size_t size);
53static struct buffer_head *inode_getblk(struct inode *, sector_t, int *, 53static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
54 long *, int *); 54 long *, int *);
55static int8_t udf_insert_aext(struct inode *, struct extent_position, 55static int8_t udf_insert_aext(struct inode *, struct extent_position,
56 kernel_lb_addr, uint32_t); 56 kernel_lb_addr, uint32_t);
57static void udf_split_extents(struct inode *, int *, int, int, 57static void udf_split_extents(struct inode *, int *, int, int,
58 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 58 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
59static void udf_prealloc_extents(struct inode *, int, int, 59static void udf_prealloc_extents(struct inode *, int, int,
60 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 60 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
61static void udf_merge_extents(struct inode *, 61static void udf_merge_extents(struct inode *,
62 kernel_long_ad [EXTENT_MERGE_SIZE], int *); 62 kernel_long_ad[EXTENT_MERGE_SIZE], int *);
63static void udf_update_extents(struct inode *, 63static void udf_update_extents(struct inode *,
64 kernel_long_ad [EXTENT_MERGE_SIZE], int, int, 64 kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
65 struct extent_position *); 65 struct extent_position *);
66static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int); 66static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
67 67
68/* 68/*
@@ -81,7 +81,7 @@ static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
81 * 81 *
82 * Called at the last iput() if i_nlink is zero. 82 * Called at the last iput() if i_nlink is zero.
83 */ 83 */
84void udf_delete_inode(struct inode * inode) 84void udf_delete_inode(struct inode *inode)
85{ 85{
86 truncate_inode_pages(&inode->i_data, 0); 86 truncate_inode_pages(&inode->i_data, 0);
87 87
@@ -97,7 +97,7 @@ void udf_delete_inode(struct inode * inode)
97 97
98 unlock_kernel(); 98 unlock_kernel();
99 return; 99 return;
100no_delete: 100 no_delete:
101 clear_inode(inode); 101 clear_inode(inode);
102} 102}
103 103
@@ -132,26 +132,27 @@ static int udf_readpage(struct file *file, struct page *page)
132 return block_read_full_page(page, udf_get_block); 132 return block_read_full_page(page, udf_get_block);
133} 133}
134 134
135static int udf_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to) 135static int udf_prepare_write(struct file *file, struct page *page,
136 unsigned from, unsigned to)
136{ 137{
137 return block_prepare_write(page, from, to, udf_get_block); 138 return block_prepare_write(page, from, to, udf_get_block);
138} 139}
139 140
140static sector_t udf_bmap(struct address_space *mapping, sector_t block) 141static sector_t udf_bmap(struct address_space *mapping, sector_t block)
141{ 142{
142 return generic_block_bmap(mapping,block,udf_get_block); 143 return generic_block_bmap(mapping, block, udf_get_block);
143} 144}
144 145
145const struct address_space_operations udf_aops = { 146const struct address_space_operations udf_aops = {
146 .readpage = udf_readpage, 147 .readpage = udf_readpage,
147 .writepage = udf_writepage, 148 .writepage = udf_writepage,
148 .sync_page = block_sync_page, 149 .sync_page = block_sync_page,
149 .prepare_write = udf_prepare_write, 150 .prepare_write = udf_prepare_write,
150 .commit_write = generic_commit_write, 151 .commit_write = generic_commit_write,
151 .bmap = udf_bmap, 152 .bmap = udf_bmap,
152}; 153};
153 154
154void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err) 155void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
155{ 156{
156 struct page *page; 157 struct page *page;
157 char *kaddr; 158 char *kaddr;
@@ -163,8 +164,7 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
163 /* from now on we have normal address_space methods */ 164 /* from now on we have normal address_space methods */
164 inode->i_data.a_ops = &udf_aops; 165 inode->i_data.a_ops = &udf_aops;
165 166
166 if (!UDF_I_LENALLOC(inode)) 167 if (!UDF_I_LENALLOC(inode)) {
167 {
168 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 168 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
169 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; 169 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
170 else 170 else
@@ -176,19 +176,18 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
176 page = grab_cache_page(inode->i_mapping, 0); 176 page = grab_cache_page(inode->i_mapping, 0);
177 BUG_ON(!PageLocked(page)); 177 BUG_ON(!PageLocked(page));
178 178
179 if (!PageUptodate(page)) 179 if (!PageUptodate(page)) {
180 {
181 kaddr = kmap(page); 180 kaddr = kmap(page);
182 memset(kaddr + UDF_I_LENALLOC(inode), 0x00, 181 memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
183 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode)); 182 PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
184 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 183 memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
185 UDF_I_LENALLOC(inode)); 184 UDF_I_LENALLOC(inode));
186 flush_dcache_page(page); 185 flush_dcache_page(page);
187 SetPageUptodate(page); 186 SetPageUptodate(page);
188 kunmap(page); 187 kunmap(page);
189 } 188 }
190 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00, 189 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
191 UDF_I_LENALLOC(inode)); 190 UDF_I_LENALLOC(inode));
192 UDF_I_LENALLOC(inode) = 0; 191 UDF_I_LENALLOC(inode) = 0;
193 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 192 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
194 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT; 193 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
@@ -201,7 +200,8 @@ void udf_expand_file_adinicb(struct inode * inode, int newsize, int * err)
201 mark_inode_dirty(inode); 200 mark_inode_dirty(inode);
202} 201}
203 202
204struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int *err) 203struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
204 int *err)
205{ 205{
206 int newblock; 206 int newblock;
207 struct buffer_head *dbh = NULL; 207 struct buffer_head *dbh = NULL;
@@ -220,8 +220,7 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
220 else 220 else
221 alloctype = ICBTAG_FLAG_AD_LONG; 221 alloctype = ICBTAG_FLAG_AD_LONG;
222 222
223 if (!inode->i_size) 223 if (!inode->i_size) {
224 {
225 UDF_I_ALLOCTYPE(inode) = alloctype; 224 UDF_I_ALLOCTYPE(inode) = alloctype;
226 mark_inode_dirty(inode); 225 mark_inode_dirty(inode);
227 return NULL; 226 return NULL;
@@ -229,13 +228,14 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
229 228
230 /* alloc block, and copy data to it */ 229 /* alloc block, and copy data to it */
231 *block = udf_new_block(inode->i_sb, inode, 230 *block = udf_new_block(inode->i_sb, inode,
232 UDF_I_LOCATION(inode).partitionReferenceNum, 231 UDF_I_LOCATION(inode).partitionReferenceNum,
233 UDF_I_LOCATION(inode).logicalBlockNum, err); 232 UDF_I_LOCATION(inode).logicalBlockNum, err);
234 233
235 if (!(*block)) 234 if (!(*block))
236 return NULL; 235 return NULL;
237 newblock = udf_get_pblock(inode->i_sb, *block, 236 newblock = udf_get_pblock(inode->i_sb, *block,
238 UDF_I_LOCATION(inode).partitionReferenceNum, 0); 237 UDF_I_LOCATION(inode).partitionReferenceNum,
238 0);
239 if (!newblock) 239 if (!newblock)
240 return NULL; 240 return NULL;
241 dbh = udf_tgetblk(inode->i_sb, newblock); 241 dbh = udf_tgetblk(inode->i_sb, newblock);
@@ -247,16 +247,17 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
247 unlock_buffer(dbh); 247 unlock_buffer(dbh);
248 mark_buffer_dirty_inode(dbh, inode); 248 mark_buffer_dirty_inode(dbh, inode);
249 249
250 sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; 250 sfibh.soffset = sfibh.eoffset =
251 (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
251 sfibh.sbh = sfibh.ebh = NULL; 252 sfibh.sbh = sfibh.ebh = NULL;
252 dfibh.soffset = dfibh.eoffset = 0; 253 dfibh.soffset = dfibh.eoffset = 0;
253 dfibh.sbh = dfibh.ebh = dbh; 254 dfibh.sbh = dfibh.ebh = dbh;
254 while ( (f_pos < size) ) 255 while ((f_pos < size)) {
255 {
256 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 256 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
257 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL); 257 sfi =
258 if (!sfi) 258 udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL,
259 { 259 NULL, NULL);
260 if (!sfi) {
260 brelse(dbh); 261 brelse(dbh);
261 return NULL; 262 return NULL;
262 } 263 }
@@ -266,8 +267,8 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
266 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); 267 dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
267 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); 268 dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
268 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, 269 if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
269 sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) 270 sfi->fileIdent +
270 { 271 le16_to_cpu(sfi->lengthOfImpUse))) {
271 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; 272 UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
272 brelse(dbh); 273 brelse(dbh);
273 return NULL; 274 return NULL;
@@ -275,10 +276,12 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
275 } 276 }
276 mark_buffer_dirty_inode(dbh, inode); 277 mark_buffer_dirty_inode(dbh, inode);
277 278
278 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode)); 279 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0,
280 UDF_I_LENALLOC(inode));
279 UDF_I_LENALLOC(inode) = 0; 281 UDF_I_LENALLOC(inode) = 0;
280 eloc.logicalBlockNum = *block; 282 eloc.logicalBlockNum = *block;
281 eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; 283 eloc.partitionReferenceNum =
284 UDF_I_LOCATION(inode).partitionReferenceNum;
282 elen = inode->i_size; 285 elen = inode->i_size;
283 UDF_I_LENEXTENTS(inode) = elen; 286 UDF_I_LENEXTENTS(inode) = elen;
284 epos.bh = NULL; 287 epos.bh = NULL;
@@ -292,14 +295,14 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
292 return dbh; 295 return dbh;
293} 296}
294 297
295static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_result, int create) 298static int udf_get_block(struct inode *inode, sector_t block,
299 struct buffer_head *bh_result, int create)
296{ 300{
297 int err, new; 301 int err, new;
298 struct buffer_head *bh; 302 struct buffer_head *bh;
299 unsigned long phys; 303 unsigned long phys;
300 304
301 if (!create) 305 if (!create) {
302 {
303 phys = udf_block_map(inode, block); 306 phys = udf_block_map(inode, block);
304 if (phys) 307 if (phys)
305 map_bh(bh_result, inode->i_sb, phys); 308 map_bh(bh_result, inode->i_sb, phys);
@@ -315,10 +318,9 @@ static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head
315 if (block < 0) 318 if (block < 0)
316 goto abort_negative; 319 goto abort_negative;
317 320
318 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) 321 if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) {
319 { 322 UDF_I_NEXT_ALLOC_BLOCK(inode)++;
320 UDF_I_NEXT_ALLOC_BLOCK(inode) ++; 323 UDF_I_NEXT_ALLOC_GOAL(inode)++;
321 UDF_I_NEXT_ALLOC_GOAL(inode) ++;
322 } 324 }
323 325
324 err = 0; 326 err = 0;
@@ -332,29 +334,27 @@ static int udf_get_block(struct inode *inode, sector_t block, struct buffer_head
332 if (new) 334 if (new)
333 set_buffer_new(bh_result); 335 set_buffer_new(bh_result);
334 map_bh(bh_result, inode->i_sb, phys); 336 map_bh(bh_result, inode->i_sb, phys);
335abort: 337 abort:
336 unlock_kernel(); 338 unlock_kernel();
337 return err; 339 return err;
338 340
339abort_negative: 341 abort_negative:
340 udf_warning(inode->i_sb, "udf_get_block", "block < 0"); 342 udf_warning(inode->i_sb, "udf_get_block", "block < 0");
341 goto abort; 343 goto abort;
342} 344}
343 345
344static struct buffer_head * 346static struct buffer_head *udf_getblk(struct inode *inode, long block,
345udf_getblk(struct inode *inode, long block, int create, int *err) 347 int create, int *err)
346{ 348{
347 struct buffer_head dummy; 349 struct buffer_head dummy;
348 350
349 dummy.b_state = 0; 351 dummy.b_state = 0;
350 dummy.b_blocknr = -1000; 352 dummy.b_blocknr = -1000;
351 *err = udf_get_block(inode, block, &dummy, create); 353 *err = udf_get_block(inode, block, &dummy, create);
352 if (!*err && buffer_mapped(&dummy)) 354 if (!*err && buffer_mapped(&dummy)) {
353 {
354 struct buffer_head *bh; 355 struct buffer_head *bh;
355 bh = sb_getblk(inode->i_sb, dummy.b_blocknr); 356 bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
356 if (buffer_new(&dummy)) 357 if (buffer_new(&dummy)) {
357 {
358 lock_buffer(bh); 358 lock_buffer(bh);
359 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize); 359 memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
360 set_buffer_uptodate(bh); 360 set_buffer_uptodate(bh);
@@ -368,12 +368,12 @@ udf_getblk(struct inode *inode, long block, int create, int *err)
368 368
369/* Extend the file by 'blocks' blocks, return the number of extents added */ 369/* Extend the file by 'blocks' blocks, return the number of extents added */
370int udf_extend_file(struct inode *inode, struct extent_position *last_pos, 370int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
371 kernel_long_ad *last_ext, sector_t blocks) 371 kernel_long_ad * last_ext, sector_t blocks)
372{ 372{
373 sector_t add; 373 sector_t add;
374 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 374 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
375 struct super_block *sb = inode->i_sb; 375 struct super_block *sb = inode->i_sb;
376 kernel_lb_addr prealloc_loc = {0, 0}; 376 kernel_lb_addr prealloc_loc = { 0, 0 };
377 int prealloc_len = 0; 377 int prealloc_len = 0;
378 378
379 /* The previous extent is fake and we should not extend by anything 379 /* The previous extent is fake and we should not extend by anything
@@ -383,28 +383,32 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
383 /* Round the last extent up to a multiple of block size */ 383 /* Round the last extent up to a multiple of block size */
384 if (last_ext->extLength & (sb->s_blocksize - 1)) { 384 if (last_ext->extLength & (sb->s_blocksize - 1)) {
385 last_ext->extLength = 385 last_ext->extLength =
386 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) | 386 (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
387 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) + 387 (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
388 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); 388 sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
389 UDF_I_LENEXTENTS(inode) = 389 UDF_I_LENEXTENTS(inode) =
390 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) & 390 (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
391 ~(sb->s_blocksize - 1); 391 ~(sb->s_blocksize - 1);
392 } 392 }
393 /* Last extent are just preallocated blocks? */ 393 /* Last extent are just preallocated blocks? */
394 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) { 394 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
395 EXT_NOT_RECORDED_ALLOCATED) {
395 /* Save the extent so that we can reattach it to the end */ 396 /* Save the extent so that we can reattach it to the end */
396 prealloc_loc = last_ext->extLocation; 397 prealloc_loc = last_ext->extLocation;
397 prealloc_len = last_ext->extLength; 398 prealloc_len = last_ext->extLength;
398 /* Mark the extent as a hole */ 399 /* Mark the extent as a hole */
399 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 400 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
400 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK); 401 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
401 last_ext->extLocation.logicalBlockNum = 0; 402 last_ext->extLocation.logicalBlockNum = 0;
402 last_ext->extLocation.partitionReferenceNum = 0; 403 last_ext->extLocation.partitionReferenceNum = 0;
403 } 404 }
404 /* Can we merge with the previous extent? */ 405 /* Can we merge with the previous extent? */
405 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) { 406 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
406 add = ((1<<30) - sb->s_blocksize - (last_ext->extLength & 407 EXT_NOT_RECORDED_NOT_ALLOCATED) {
407 UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits; 408 add =
409 ((1 << 30) - sb->s_blocksize -
410 (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >> sb->
411 s_blocksize_bits;
408 if (add > blocks) 412 if (add > blocks)
409 add = blocks; 413 add = blocks;
410 blocks -= add; 414 blocks -= add;
@@ -413,40 +417,42 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
413 417
414 if (fake) { 418 if (fake) {
415 udf_add_aext(inode, last_pos, last_ext->extLocation, 419 udf_add_aext(inode, last_pos, last_ext->extLocation,
416 last_ext->extLength, 1); 420 last_ext->extLength, 1);
417 count++; 421 count++;
418 } 422 } else
419 else 423 udf_write_aext(inode, last_pos, last_ext->extLocation,
420 udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1); 424 last_ext->extLength, 1);
421 /* Managed to do everything necessary? */ 425 /* Managed to do everything necessary? */
422 if (!blocks) 426 if (!blocks)
423 goto out; 427 goto out;
424 428
425 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */ 429 /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
426 last_ext->extLocation.logicalBlockNum = 0; 430 last_ext->extLocation.logicalBlockNum = 0;
427 last_ext->extLocation.partitionReferenceNum = 0; 431 last_ext->extLocation.partitionReferenceNum = 0;
428 add = (1 << (30-sb->s_blocksize_bits)) - 1; 432 add = (1 << (30 - sb->s_blocksize_bits)) - 1;
429 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits); 433 last_ext->extLength =
434 EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
430 /* Create enough extents to cover the whole hole */ 435 /* Create enough extents to cover the whole hole */
431 while (blocks > add) { 436 while (blocks > add) {
432 blocks -= add; 437 blocks -= add;
433 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 438 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
434 last_ext->extLength, 1) == -1) 439 last_ext->extLength, 1) == -1)
435 return -1; 440 return -1;
436 count++; 441 count++;
437 } 442 }
438 if (blocks) { 443 if (blocks) {
439 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 444 last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
440 (blocks << sb->s_blocksize_bits); 445 (blocks << sb->s_blocksize_bits);
441 if (udf_add_aext(inode, last_pos, last_ext->extLocation, 446 if (udf_add_aext(inode, last_pos, last_ext->extLocation,
442 last_ext->extLength, 1) == -1) 447 last_ext->extLength, 1) == -1)
443 return -1; 448 return -1;
444 count++; 449 count++;
445 } 450 }
446out: 451 out:
447 /* Do we have some preallocated blocks saved? */ 452 /* Do we have some preallocated blocks saved? */
448 if (prealloc_len) { 453 if (prealloc_len) {
449 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1) 454 if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1)
455 == -1)
450 return -1; 456 return -1;
451 last_ext->extLocation = prealloc_loc; 457 last_ext->extLocation = prealloc_loc;
452 last_ext->extLength = prealloc_len; 458 last_ext->extLength = prealloc_len;
@@ -462,8 +468,8 @@ out:
462 return count; 468 return count;
463} 469}
464 470
465static struct buffer_head * inode_getblk(struct inode * inode, sector_t block, 471static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
466 int *err, long *phys, int *new) 472 int *err, long *phys, int *new)
467{ 473{
468 static sector_t last_block; 474 static sector_t last_block;
469 struct buffer_head *result = NULL; 475 struct buffer_head *result = NULL;
@@ -484,21 +490,18 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
484 prev_epos.block = UDF_I_LOCATION(inode); 490 prev_epos.block = UDF_I_LOCATION(inode);
485 prev_epos.bh = NULL; 491 prev_epos.bh = NULL;
486 cur_epos = next_epos = prev_epos; 492 cur_epos = next_epos = prev_epos;
487 b_off = (loff_t)block << inode->i_sb->s_blocksize_bits; 493 b_off = (loff_t) block << inode->i_sb->s_blocksize_bits;
488 494
489 /* find the extent which contains the block we are looking for. 495 /* find the extent which contains the block we are looking for.
490 alternate between laarr[0] and laarr[1] for locations of the 496 alternate between laarr[0] and laarr[1] for locations of the
491 current extent, and the previous extent */ 497 current extent, and the previous extent */
492 do 498 do {
493 { 499 if (prev_epos.bh != cur_epos.bh) {
494 if (prev_epos.bh != cur_epos.bh)
495 {
496 brelse(prev_epos.bh); 500 brelse(prev_epos.bh);
497 get_bh(cur_epos.bh); 501 get_bh(cur_epos.bh);
498 prev_epos.bh = cur_epos.bh; 502 prev_epos.bh = cur_epos.bh;
499 } 503 }
500 if (cur_epos.bh != next_epos.bh) 504 if (cur_epos.bh != next_epos.bh) {
501 {
502 brelse(cur_epos.bh); 505 brelse(cur_epos.bh);
503 get_bh(next_epos.bh); 506 get_bh(next_epos.bh);
504 cur_epos.bh = next_epos.bh; 507 cur_epos.bh = next_epos.bh;
@@ -512,7 +515,8 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
512 prev_epos.offset = cur_epos.offset; 515 prev_epos.offset = cur_epos.offset;
513 cur_epos.offset = next_epos.offset; 516 cur_epos.offset = next_epos.offset;
514 517
515 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1) 518 if ((etype =
519 udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
516 break; 520 break;
517 521
518 c = !c; 522 c = !c;
@@ -522,10 +526,10 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
522 526
523 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 527 if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
524 pgoal = eloc.logicalBlockNum + 528 pgoal = eloc.logicalBlockNum +
525 ((elen + inode->i_sb->s_blocksize - 1) >> 529 ((elen + inode->i_sb->s_blocksize - 1) >>
526 inode->i_sb->s_blocksize_bits); 530 inode->i_sb->s_blocksize_bits);
527 531
528 count ++; 532 count++;
529 } while (lbcount + elen <= b_off); 533 } while (lbcount + elen <= b_off);
530 534
531 b_off -= lbcount; 535 b_off -= lbcount;
@@ -538,15 +542,13 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
538 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0); 542 udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
539 543
540 /* if the extent is allocated and recorded, return the block 544 /* if the extent is allocated and recorded, return the block
541 if the extent is not a multiple of the blocksize, round up */ 545 if the extent is not a multiple of the blocksize, round up */
542 546
543 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) 547 if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
544 { 548 if (elen & (inode->i_sb->s_blocksize - 1)) {
545 if (elen & (inode->i_sb->s_blocksize - 1))
546 {
547 elen = EXT_RECORDED_ALLOCATED | 549 elen = EXT_RECORDED_ALLOCATED |
548 ((elen + inode->i_sb->s_blocksize - 1) & 550 ((elen + inode->i_sb->s_blocksize - 1) &
549 ~(inode->i_sb->s_blocksize - 1)); 551 ~(inode->i_sb->s_blocksize - 1));
550 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1); 552 etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
551 } 553 }
552 brelse(prev_epos.bh); 554 brelse(prev_epos.bh);
@@ -559,18 +561,17 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
559 561
560 last_block = block; 562 last_block = block;
561 /* Are we beyond EOF? */ 563 /* Are we beyond EOF? */
562 if (etype == -1) 564 if (etype == -1) {
563 {
564 int ret; 565 int ret;
565 566
566 if (count) { 567 if (count) {
567 if (c) 568 if (c)
568 laarr[0] = laarr[1]; 569 laarr[0] = laarr[1];
569 startnum = 1; 570 startnum = 1;
570 } 571 } else {
571 else {
572 /* Create a fake extent when there's not one */ 572 /* Create a fake extent when there's not one */
573 memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr)); 573 memset(&laarr[0].extLocation, 0x00,
574 sizeof(kernel_lb_addr));
574 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED; 575 laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
575 /* Will udf_extend_file() create real extent from a fake one? */ 576 /* Will udf_extend_file() create real extent from a fake one? */
576 startnum = (offset > 0); 577 startnum = (offset > 0);
@@ -590,26 +591,26 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
590 offset = 0; 591 offset = 0;
591 count += ret; 592 count += ret;
592 /* We are not covered by a preallocated extent? */ 593 /* We are not covered by a preallocated extent? */
593 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) { 594 if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
595 EXT_NOT_RECORDED_ALLOCATED) {
594 /* Is there any real extent? - otherwise we overwrite 596 /* Is there any real extent? - otherwise we overwrite
595 * the fake one... */ 597 * the fake one... */
596 if (count) 598 if (count)
597 c = !c; 599 c = !c;
598 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 600 laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
599 inode->i_sb->s_blocksize; 601 inode->i_sb->s_blocksize;
600 memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr)); 602 memset(&laarr[c].extLocation, 0x00,
601 count ++; 603 sizeof(kernel_lb_addr));
602 endnum ++; 604 count++;
605 endnum++;
603 } 606 }
604 endnum = c+1; 607 endnum = c + 1;
605 lastblock = 1; 608 lastblock = 1;
606 } 609 } else {
607 else {
608 endnum = startnum = ((count > 2) ? 2 : count); 610 endnum = startnum = ((count > 2) ? 2 : count);
609 611
610 /* if the current extent is in position 0, swap it with the previous */ 612 /* if the current extent is in position 0, swap it with the previous */
611 if (!c && count != 1) 613 if (!c && count != 1) {
612 {
613 laarr[2] = laarr[0]; 614 laarr[2] = laarr[0];
614 laarr[0] = laarr[1]; 615 laarr[0] = laarr[1];
615 laarr[1] = laarr[2]; 616 laarr[1] = laarr[2];
@@ -617,37 +618,37 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
617 } 618 }
618 619
619 /* if the current block is located in an extent, read the next extent */ 620 /* if the current block is located in an extent, read the next extent */
620 if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) 621 if ((etype =
621 { 622 udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
622 laarr[c+1].extLength = (etype << 30) | elen; 623 laarr[c + 1].extLength = (etype << 30) | elen;
623 laarr[c+1].extLocation = eloc; 624 laarr[c + 1].extLocation = eloc;
624 count ++; 625 count++;
625 startnum ++; 626 startnum++;
626 endnum ++; 627 endnum++;
627 } 628 } else {
628 else {
629 lastblock = 1; 629 lastblock = 1;
630 } 630 }
631 } 631 }
632 632
633 /* if the current extent is not recorded but allocated, get the 633 /* if the current extent is not recorded but allocated, get the
634 block in the extent corresponding to the requested block */ 634 block in the extent corresponding to the requested block */
635 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 635 if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
636 newblocknum = laarr[c].extLocation.logicalBlockNum + offset; 636 newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
637 else /* otherwise, allocate a new block */ 637 else { /* otherwise, allocate a new block */
638 { 638
639 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block) 639 if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
640 goal = UDF_I_NEXT_ALLOC_GOAL(inode); 640 goal = UDF_I_NEXT_ALLOC_GOAL(inode);
641 641
642 if (!goal) 642 if (!goal) {
643 {
644 if (!(goal = pgoal)) 643 if (!(goal = pgoal))
645 goal = UDF_I_LOCATION(inode).logicalBlockNum + 1; 644 goal =
645 UDF_I_LOCATION(inode).logicalBlockNum + 1;
646 } 646 }
647 647
648 if (!(newblocknum = udf_new_block(inode->i_sb, inode, 648 if (!(newblocknum = udf_new_block(inode->i_sb, inode,
649 UDF_I_LOCATION(inode).partitionReferenceNum, goal, err))) 649 UDF_I_LOCATION(inode).
650 { 650 partitionReferenceNum, goal,
651 err))) {
651 brelse(prev_epos.bh); 652 brelse(prev_epos.bh);
652 *err = -ENOSPC; 653 *err = -ENOSPC;
653 return NULL; 654 return NULL;
@@ -656,8 +657,8 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
656 } 657 }
657 658
658 /* if the extent the requsted block is located in contains multiple blocks, 659 /* if the extent the requsted block is located in contains multiple blocks,
659 split the extent into at most three extents. blocks prior to requested 660 split the extent into at most three extents. blocks prior to requested
660 block, requested block, and blocks after requested block */ 661 block, requested block, and blocks after requested block */
661 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum); 662 udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
662 663
663#ifdef UDF_PREALLOCATE 664#ifdef UDF_PREALLOCATE
@@ -669,15 +670,15 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
669 udf_merge_extents(inode, laarr, &endnum); 670 udf_merge_extents(inode, laarr, &endnum);
670 671
671 /* write back the new extents, inserting new extents if the new number 672 /* write back the new extents, inserting new extents if the new number
672 of extents is greater than the old number, and deleting extents if 673 of extents is greater than the old number, and deleting extents if
673 the new number of extents is less than the old number */ 674 the new number of extents is less than the old number */
674 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos); 675 udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
675 676
676 brelse(prev_epos.bh); 677 brelse(prev_epos.bh);
677 678
678 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum, 679 if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
679 UDF_I_LOCATION(inode).partitionReferenceNum, 0))) 680 UDF_I_LOCATION(inode).
680 { 681 partitionReferenceNum, 0))) {
681 return NULL; 682 return NULL;
682 } 683 }
683 *phys = newblock; 684 *phys = newblock;
@@ -694,283 +695,329 @@ static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
694 return result; 695 return result;
695} 696}
696 697
697static void udf_split_extents(struct inode *inode, int *c, int offset, int newblocknum, 698static void udf_split_extents(struct inode *inode, int *c, int offset,
698 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 699 int newblocknum,
700 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
701 int *endnum)
699{ 702{
700 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) || 703 if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
701 (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 704 (laarr[*c].extLength >> 30) ==
702 { 705 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
703 int curr = *c; 706 int curr = *c;
704 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) + 707 int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
705 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 708 inode->i_sb->s_blocksize -
709 1) >> inode->i_sb->s_blocksize_bits;
706 int8_t etype = (laarr[curr].extLength >> 30); 710 int8_t etype = (laarr[curr].extLength >> 30);
707 711
708 if (blen == 1) 712 if (blen == 1) ;
709 ; 713 else if (!offset || blen == offset + 1) {
710 else if (!offset || blen == offset + 1) 714 laarr[curr + 2] = laarr[curr + 1];
711 { 715 laarr[curr + 1] = laarr[curr];
712 laarr[curr+2] = laarr[curr+1]; 716 } else {
713 laarr[curr+1] = laarr[curr]; 717 laarr[curr + 3] = laarr[curr + 1];
714 } 718 laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
715 else 719 }
716 { 720
717 laarr[curr+3] = laarr[curr+1]; 721 if (offset) {
718 laarr[curr+2] = laarr[curr+1] = laarr[curr]; 722 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
719 } 723 udf_free_blocks(inode->i_sb, inode,
720 724 laarr[curr].extLocation, 0,
721 if (offset) 725 offset);
722 { 726 laarr[curr].extLength =
723 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 727 EXT_NOT_RECORDED_NOT_ALLOCATED | (offset <<
724 { 728 inode->
725 udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset); 729 i_sb->
726 laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | 730 s_blocksize_bits);
727 (offset << inode->i_sb->s_blocksize_bits);
728 laarr[curr].extLocation.logicalBlockNum = 0; 731 laarr[curr].extLocation.logicalBlockNum = 0;
729 laarr[curr].extLocation.partitionReferenceNum = 0; 732 laarr[curr].extLocation.partitionReferenceNum =
730 } 733 0;
731 else 734 } else
732 laarr[curr].extLength = (etype << 30) | 735 laarr[curr].extLength = (etype << 30) |
733 (offset << inode->i_sb->s_blocksize_bits); 736 (offset << inode->i_sb->s_blocksize_bits);
734 curr ++; 737 curr++;
735 (*c) ++; 738 (*c)++;
736 (*endnum) ++; 739 (*endnum)++;
737 } 740 }
738 741
739 laarr[curr].extLocation.logicalBlockNum = newblocknum; 742 laarr[curr].extLocation.logicalBlockNum = newblocknum;
740 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 743 if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
741 laarr[curr].extLocation.partitionReferenceNum = 744 laarr[curr].extLocation.partitionReferenceNum =
742 UDF_I_LOCATION(inode).partitionReferenceNum; 745 UDF_I_LOCATION(inode).partitionReferenceNum;
743 laarr[curr].extLength = EXT_RECORDED_ALLOCATED | 746 laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
744 inode->i_sb->s_blocksize; 747 inode->i_sb->s_blocksize;
745 curr ++; 748 curr++;
746 749
747 if (blen != offset + 1) 750 if (blen != offset + 1) {
748 {
749 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 751 if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
750 laarr[curr].extLocation.logicalBlockNum += (offset + 1); 752 laarr[curr].extLocation.logicalBlockNum +=
751 laarr[curr].extLength = (etype << 30) | 753 (offset + 1);
752 ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits); 754 laarr[curr].extLength =
753 curr ++; 755 (etype << 30) | ((blen - (offset + 1)) << inode->
754 (*endnum) ++; 756 i_sb->s_blocksize_bits);
757 curr++;
758 (*endnum)++;
755 } 759 }
756 } 760 }
757} 761}
758 762
759static void udf_prealloc_extents(struct inode *inode, int c, int lastblock, 763static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
760 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 764 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
765 int *endnum)
761{ 766{
762 int start, length = 0, currlength = 0, i; 767 int start, length = 0, currlength = 0, i;
763 768
764 if (*endnum >= (c+1)) 769 if (*endnum >= (c + 1)) {
765 {
766 if (!lastblock) 770 if (!lastblock)
767 return; 771 return;
768 else 772 else
769 start = c; 773 start = c;
770 } 774 } else {
771 else 775 if ((laarr[c + 1].extLength >> 30) ==
772 { 776 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
773 if ((laarr[c+1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) 777 start = c + 1;
774 { 778 length = currlength =
775 start = c+1; 779 (((laarr[c + 1].
776 length = currlength = (((laarr[c+1].extLength & UDF_EXTENT_LENGTH_MASK) + 780 extLength & UDF_EXTENT_LENGTH_MASK) +
777 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 781 inode->i_sb->s_blocksize -
778 } 782 1) >> inode->i_sb->s_blocksize_bits);
779 else 783 } else
780 start = c; 784 start = c;
781 } 785 }
782 786
783 for (i=start+1; i<=*endnum; i++) 787 for (i = start + 1; i <= *endnum; i++) {
784 { 788 if (i == *endnum) {
785 if (i == *endnum)
786 {
787 if (lastblock) 789 if (lastblock)
788 length += UDF_DEFAULT_PREALLOC_BLOCKS; 790 length += UDF_DEFAULT_PREALLOC_BLOCKS;
789 } 791 } else if ((laarr[i].extLength >> 30) ==
790 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) 792 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
791 length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 793 length +=
792 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 794 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
795 inode->i_sb->s_blocksize -
796 1) >> inode->i_sb->s_blocksize_bits);
793 else 797 else
794 break; 798 break;
795 } 799 }
796 800
797 if (length) 801 if (length) {
798 {
799 int next = laarr[start].extLocation.logicalBlockNum + 802 int next = laarr[start].extLocation.logicalBlockNum +
800 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) + 803 (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
801 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 804 inode->i_sb->s_blocksize -
805 1) >> inode->i_sb->s_blocksize_bits);
802 int numalloc = udf_prealloc_blocks(inode->i_sb, inode, 806 int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
803 laarr[start].extLocation.partitionReferenceNum, 807 laarr[start].extLocation.
804 next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length : 808 partitionReferenceNum,
805 UDF_DEFAULT_PREALLOC_BLOCKS) - currlength); 809 next,
806 810 (UDF_DEFAULT_PREALLOC_BLOCKS
807 if (numalloc) 811 >
808 { 812 length ? length :
809 if (start == (c+1)) 813 UDF_DEFAULT_PREALLOC_BLOCKS)
814 - currlength);
815
816 if (numalloc) {
817 if (start == (c + 1))
810 laarr[start].extLength += 818 laarr[start].extLength +=
811 (numalloc << inode->i_sb->s_blocksize_bits); 819 (numalloc << inode->i_sb->s_blocksize_bits);
812 else 820 else {
813 { 821 memmove(&laarr[c + 2], &laarr[c + 1],
814 memmove(&laarr[c+2], &laarr[c+1], 822 sizeof(long_ad) * (*endnum - (c + 1)));
815 sizeof(long_ad) * (*endnum - (c+1))); 823 (*endnum)++;
816 (*endnum) ++; 824 laarr[c + 1].extLocation.logicalBlockNum = next;
817 laarr[c+1].extLocation.logicalBlockNum = next; 825 laarr[c + 1].extLocation.partitionReferenceNum =
818 laarr[c+1].extLocation.partitionReferenceNum = 826 laarr[c].extLocation.partitionReferenceNum;
819 laarr[c].extLocation.partitionReferenceNum; 827 laarr[c + 1].extLength =
820 laarr[c+1].extLength = EXT_NOT_RECORDED_ALLOCATED | 828 EXT_NOT_RECORDED_ALLOCATED | (numalloc <<
821 (numalloc << inode->i_sb->s_blocksize_bits); 829 inode->i_sb->
822 start = c+1; 830 s_blocksize_bits);
831 start = c + 1;
823 } 832 }
824 833
825 for (i=start+1; numalloc && i<*endnum; i++) 834 for (i = start + 1; numalloc && i < *endnum; i++) {
826 { 835 int elen =
827 int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 836 ((laarr[i].
828 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits; 837 extLength & UDF_EXTENT_LENGTH_MASK) +
838 inode->i_sb->s_blocksize -
839 1) >> inode->i_sb->s_blocksize_bits;
829 840
830 if (elen > numalloc) 841 if (elen > numalloc) {
831 {
832 laarr[i].extLength -= 842 laarr[i].extLength -=
833 (numalloc << inode->i_sb->s_blocksize_bits); 843 (numalloc << inode->i_sb->
844 s_blocksize_bits);
834 numalloc = 0; 845 numalloc = 0;
835 } 846 } else {
836 else
837 {
838 numalloc -= elen; 847 numalloc -= elen;
839 if (*endnum > (i+1)) 848 if (*endnum > (i + 1))
840 memmove(&laarr[i], &laarr[i+1], 849 memmove(&laarr[i],
841 sizeof(long_ad) * (*endnum - (i+1))); 850 &laarr[i + 1],
842 i --; 851 sizeof(long_ad) *
843 (*endnum) --; 852 (*endnum - (i + 1)));
853 i--;
854 (*endnum)--;
844 } 855 }
845 } 856 }
846 UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits; 857 UDF_I_LENEXTENTS(inode) +=
858 numalloc << inode->i_sb->s_blocksize_bits;
847 } 859 }
848 } 860 }
849} 861}
850 862
851static void udf_merge_extents(struct inode *inode, 863static void udf_merge_extents(struct inode *inode,
852 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int *endnum) 864 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
865 int *endnum)
853{ 866{
854 int i; 867 int i;
855 868
856 for (i=0; i<(*endnum-1); i++) 869 for (i = 0; i < (*endnum - 1); i++) {
857 { 870 if ((laarr[i].extLength >> 30) ==
858 if ((laarr[i].extLength >> 30) == (laarr[i+1].extLength >> 30)) 871 (laarr[i + 1].extLength >> 30)) {
859 { 872 if (((laarr[i].extLength >> 30) ==
860 if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) || 873 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
861 ((laarr[i+1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) == 874 ||
862 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 875 ((laarr[i + 1].extLocation.logicalBlockNum -
863 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) 876 laarr[i].extLocation.logicalBlockNum) ==
864 { 877 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
865 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 878 inode->i_sb->s_blocksize -
866 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) + 879 1) >> inode->i_sb->s_blocksize_bits))) {
867 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) 880 if (((laarr[i].
868 { 881 extLength & UDF_EXTENT_LENGTH_MASK) +
869 laarr[i+1].extLength = (laarr[i+1].extLength - 882 (laarr[i + 1].
870 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 883 extLength & UDF_EXTENT_LENGTH_MASK) +
871 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1); 884 inode->i_sb->s_blocksize -
872 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + 885 1) & ~UDF_EXTENT_LENGTH_MASK) {
873 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; 886 laarr[i + 1].extLength =
874 laarr[i+1].extLocation.logicalBlockNum = 887 (laarr[i + 1].extLength -
875 laarr[i].extLocation.logicalBlockNum + 888 (laarr[i].
876 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >> 889 extLength &
877 inode->i_sb->s_blocksize_bits); 890 UDF_EXTENT_LENGTH_MASK) +
878 } 891 UDF_EXTENT_LENGTH_MASK) & ~(inode->
879 else 892 i_sb->
880 { 893 s_blocksize
881 laarr[i].extLength = laarr[i+1].extLength + 894 - 1);
882 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 895 laarr[i].extLength =
883 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1)); 896 (laarr[i].
884 if (*endnum > (i+2)) 897 extLength & UDF_EXTENT_FLAG_MASK) +
885 memmove(&laarr[i+1], &laarr[i+2], 898 (UDF_EXTENT_LENGTH_MASK + 1) -
886 sizeof(long_ad) * (*endnum - (i+2))); 899 inode->i_sb->s_blocksize;
887 i --; 900 laarr[i +
888 (*endnum) --; 901 1].extLocation.logicalBlockNum =
902 laarr[i].extLocation.
903 logicalBlockNum +
904 ((laarr[i].
905 extLength &
906 UDF_EXTENT_LENGTH_MASK) >> inode->
907 i_sb->s_blocksize_bits);
908 } else {
909 laarr[i].extLength =
910 laarr[i + 1].extLength +
911 (((laarr[i].
912 extLength &
913 UDF_EXTENT_LENGTH_MASK) +
914 inode->i_sb->s_blocksize -
915 1) & ~(inode->i_sb->s_blocksize -
916 1));
917 if (*endnum > (i + 2))
918 memmove(&laarr[i + 1],
919 &laarr[i + 2],
920 sizeof(long_ad) *
921 (*endnum - (i + 2)));
922 i--;
923 (*endnum)--;
889 } 924 }
890 } 925 }
891 } 926 } else
892 else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) && 927 if (((laarr[i].extLength >> 30) ==
893 ((laarr[i+1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) 928 (EXT_NOT_RECORDED_ALLOCATED >> 30))
894 { 929 && ((laarr[i + 1].extLength >> 30) ==
895 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0, 930 (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
896 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 931 udf_free_blocks(inode->i_sb, inode,
897 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits); 932 laarr[i].extLocation, 0,
933 ((laarr[i].
934 extLength & UDF_EXTENT_LENGTH_MASK) +
935 inode->i_sb->s_blocksize -
936 1) >> inode->i_sb->s_blocksize_bits);
898 laarr[i].extLocation.logicalBlockNum = 0; 937 laarr[i].extLocation.logicalBlockNum = 0;
899 laarr[i].extLocation.partitionReferenceNum = 0; 938 laarr[i].extLocation.partitionReferenceNum = 0;
900 939
901 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 940 if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
902 (laarr[i+1].extLength & UDF_EXTENT_LENGTH_MASK) + 941 (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
903 inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) 942 inode->i_sb->s_blocksize -
904 { 943 1) & ~UDF_EXTENT_LENGTH_MASK) {
905 laarr[i+1].extLength = (laarr[i+1].extLength - 944 laarr[i + 1].extLength =
906 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 945 (laarr[i + 1].extLength -
907 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize-1); 946 (laarr[i].
908 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) + 947 extLength & UDF_EXTENT_LENGTH_MASK) +
909 (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize; 948 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->
949 s_blocksize -
950 1);
951 laarr[i].extLength =
952 (laarr[i].
953 extLength & UDF_EXTENT_FLAG_MASK) +
954 (UDF_EXTENT_LENGTH_MASK + 1) -
955 inode->i_sb->s_blocksize;
956 } else {
957 laarr[i].extLength = laarr[i + 1].extLength +
958 (((laarr[i].
959 extLength & UDF_EXTENT_LENGTH_MASK) +
960 inode->i_sb->s_blocksize -
961 1) & ~(inode->i_sb->s_blocksize - 1));
962 if (*endnum > (i + 2))
963 memmove(&laarr[i + 1], &laarr[i + 2],
964 sizeof(long_ad) * (*endnum -
965 (i + 2)));
966 i--;
967 (*endnum)--;
910 } 968 }
911 else 969 } else if ((laarr[i].extLength >> 30) ==
912 { 970 (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
913 laarr[i].extLength = laarr[i+1].extLength + 971 udf_free_blocks(inode->i_sb, inode,
914 (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) + 972 laarr[i].extLocation, 0,
915 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize-1)); 973 ((laarr[i].
916 if (*endnum > (i+2)) 974 extLength & UDF_EXTENT_LENGTH_MASK) +
917 memmove(&laarr[i+1], &laarr[i+2], 975 inode->i_sb->s_blocksize -
918 sizeof(long_ad) * (*endnum - (i+2))); 976 1) >> inode->i_sb->s_blocksize_bits);
919 i --;
920 (*endnum) --;
921 }
922 }
923 else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
924 {
925 udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
926 ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
927 inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
928 laarr[i].extLocation.logicalBlockNum = 0; 977 laarr[i].extLocation.logicalBlockNum = 0;
929 laarr[i].extLocation.partitionReferenceNum = 0; 978 laarr[i].extLocation.partitionReferenceNum = 0;
930 laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) | 979 laarr[i].extLength =
931 EXT_NOT_RECORDED_NOT_ALLOCATED; 980 (laarr[i].
981 extLength & UDF_EXTENT_LENGTH_MASK) |
982 EXT_NOT_RECORDED_NOT_ALLOCATED;
932 } 983 }
933 } 984 }
934} 985}
935 986
936static void udf_update_extents(struct inode *inode, 987static void udf_update_extents(struct inode *inode,
937 kernel_long_ad laarr[EXTENT_MERGE_SIZE], int startnum, int endnum, 988 kernel_long_ad laarr[EXTENT_MERGE_SIZE],
938 struct extent_position *epos) 989 int startnum, int endnum,
990 struct extent_position *epos)
939{ 991{
940 int start = 0, i; 992 int start = 0, i;
941 kernel_lb_addr tmploc; 993 kernel_lb_addr tmploc;
942 uint32_t tmplen; 994 uint32_t tmplen;
943 995
944 if (startnum > endnum) 996 if (startnum > endnum) {
945 { 997 for (i = 0; i < (startnum - endnum); i++)
946 for (i=0; i<(startnum-endnum); i++)
947 udf_delete_aext(inode, *epos, laarr[i].extLocation, 998 udf_delete_aext(inode, *epos, laarr[i].extLocation,
948 laarr[i].extLength); 999 laarr[i].extLength);
949 } 1000 } else if (startnum < endnum) {
950 else if (startnum < endnum) 1001 for (i = 0; i < (endnum - startnum); i++) {
951 {
952 for (i=0; i<(endnum-startnum); i++)
953 {
954 udf_insert_aext(inode, *epos, laarr[i].extLocation, 1002 udf_insert_aext(inode, *epos, laarr[i].extLocation,
955 laarr[i].extLength); 1003 laarr[i].extLength);
956 udf_next_aext(inode, epos, &laarr[i].extLocation, 1004 udf_next_aext(inode, epos, &laarr[i].extLocation,
957 &laarr[i].extLength, 1); 1005 &laarr[i].extLength, 1);
958 start ++; 1006 start++;
959 } 1007 }
960 } 1008 }
961 1009
962 for (i=start; i<endnum; i++) 1010 for (i = start; i < endnum; i++) {
963 {
964 udf_next_aext(inode, epos, &tmploc, &tmplen, 0); 1011 udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
965 udf_write_aext(inode, epos, laarr[i].extLocation, 1012 udf_write_aext(inode, epos, laarr[i].extLocation,
966 laarr[i].extLength, 1); 1013 laarr[i].extLength, 1);
967 } 1014 }
968} 1015}
969 1016
970struct buffer_head * udf_bread(struct inode * inode, int block, 1017struct buffer_head *udf_bread(struct inode *inode, int block,
971 int create, int * err) 1018 int create, int *err)
972{ 1019{
973 struct buffer_head * bh = NULL; 1020 struct buffer_head *bh = NULL;
974 1021
975 bh = udf_getblk(inode, block, create, err); 1022 bh = udf_getblk(inode, block, create, err);
976 if (!bh) 1023 if (!bh)
@@ -987,56 +1034,51 @@ struct buffer_head * udf_bread(struct inode * inode, int block,
987 return NULL; 1034 return NULL;
988} 1035}
989 1036
990void udf_truncate(struct inode * inode) 1037void udf_truncate(struct inode *inode)
991{ 1038{
992 int offset; 1039 int offset;
993 int err; 1040 int err;
994 1041
995 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1042 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
996 S_ISLNK(inode->i_mode))) 1043 S_ISLNK(inode->i_mode)))
997 return; 1044 return;
998 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) 1045 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
999 return; 1046 return;
1000 1047
1001 lock_kernel(); 1048 lock_kernel();
1002 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1049 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1003 { 1050 if (inode->i_sb->s_blocksize <
1004 if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) + 1051 (udf_file_entry_alloc_offset(inode) + inode->i_size)) {
1005 inode->i_size))
1006 {
1007 udf_expand_file_adinicb(inode, inode->i_size, &err); 1052 udf_expand_file_adinicb(inode, inode->i_size, &err);
1008 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1053 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
1009 {
1010 inode->i_size = UDF_I_LENALLOC(inode); 1054 inode->i_size = UDF_I_LENALLOC(inode);
1011 unlock_kernel(); 1055 unlock_kernel();
1012 return; 1056 return;
1013 } 1057 } else
1014 else
1015 udf_truncate_extents(inode); 1058 udf_truncate_extents(inode);
1016 } 1059 } else {
1017 else
1018 {
1019 offset = inode->i_size & (inode->i_sb->s_blocksize - 1); 1060 offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
1020 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00, inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode)); 1061 memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) +
1062 offset, 0x00,
1063 inode->i_sb->s_blocksize - offset -
1064 udf_file_entry_alloc_offset(inode));
1021 UDF_I_LENALLOC(inode) = inode->i_size; 1065 UDF_I_LENALLOC(inode) = inode->i_size;
1022 } 1066 }
1023 } 1067 } else {
1024 else 1068 block_truncate_page(inode->i_mapping, inode->i_size,
1025 { 1069 udf_get_block);
1026 block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
1027 udf_truncate_extents(inode); 1070 udf_truncate_extents(inode);
1028 } 1071 }
1029 1072
1030 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb); 1073 inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
1031 if (IS_SYNC(inode)) 1074 if (IS_SYNC(inode))
1032 udf_sync_inode (inode); 1075 udf_sync_inode(inode);
1033 else 1076 else
1034 mark_inode_dirty(inode); 1077 mark_inode_dirty(inode);
1035 unlock_kernel(); 1078 unlock_kernel();
1036} 1079}
1037 1080
1038static void 1081static void __udf_read_inode(struct inode *inode)
1039__udf_read_inode(struct inode *inode)
1040{ 1082{
1041 struct buffer_head *bh = NULL; 1083 struct buffer_head *bh = NULL;
1042 struct fileEntry *fe; 1084 struct fileEntry *fe;
@@ -1056,19 +1098,18 @@ __udf_read_inode(struct inode *inode)
1056 */ 1098 */
1057 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident); 1099 bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
1058 1100
1059 if (!bh) 1101 if (!bh) {
1060 {
1061 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n", 1102 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
1062 inode->i_ino); 1103 inode->i_ino);
1063 make_bad_inode(inode); 1104 make_bad_inode(inode);
1064 return; 1105 return;
1065 } 1106 }
1066 1107
1067 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && 1108 if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
1068 ident != TAG_IDENT_USE) 1109 ident != TAG_IDENT_USE) {
1069 { 1110 printk(KERN_ERR
1070 printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n", 1111 "udf: udf_read_inode(ino %ld) failed ident=%d\n",
1071 inode->i_ino, ident); 1112 inode->i_ino, ident);
1072 brelse(bh); 1113 brelse(bh);
1073 make_bad_inode(inode); 1114 make_bad_inode(inode);
1074 return; 1115 return;
@@ -1076,51 +1117,46 @@ __udf_read_inode(struct inode *inode)
1076 1117
1077 fe = (struct fileEntry *)bh->b_data; 1118 fe = (struct fileEntry *)bh->b_data;
1078 1119
1079 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) 1120 if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
1080 {
1081 struct buffer_head *ibh = NULL, *nbh = NULL; 1121 struct buffer_head *ibh = NULL, *nbh = NULL;
1082 struct indirectEntry *ie; 1122 struct indirectEntry *ie;
1083 1123
1084 ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident); 1124 ibh =
1085 if (ident == TAG_IDENT_IE) 1125 udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1,
1086 { 1126 &ident);
1087 if (ibh) 1127 if (ident == TAG_IDENT_IE) {
1088 { 1128 if (ibh) {
1089 kernel_lb_addr loc; 1129 kernel_lb_addr loc;
1090 ie = (struct indirectEntry *)ibh->b_data; 1130 ie = (struct indirectEntry *)ibh->b_data;
1091 1131
1092 loc = lelb_to_cpu(ie->indirectICB.extLocation); 1132 loc = lelb_to_cpu(ie->indirectICB.extLocation);
1093 1133
1094 if (ie->indirectICB.extLength && 1134 if (ie->indirectICB.extLength &&
1095 (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) 1135 (nbh =
1096 { 1136 udf_read_ptagged(inode->i_sb, loc, 0,
1097 if (ident == TAG_IDENT_FE || 1137 &ident))) {
1098 ident == TAG_IDENT_EFE) 1138 if (ident == TAG_IDENT_FE
1099 { 1139 || ident == TAG_IDENT_EFE) {
1100 memcpy(&UDF_I_LOCATION(inode), &loc, sizeof(kernel_lb_addr)); 1140 memcpy(&UDF_I_LOCATION(inode),
1141 &loc,
1142 sizeof(kernel_lb_addr));
1101 brelse(bh); 1143 brelse(bh);
1102 brelse(ibh); 1144 brelse(ibh);
1103 brelse(nbh); 1145 brelse(nbh);
1104 __udf_read_inode(inode); 1146 __udf_read_inode(inode);
1105 return; 1147 return;
1106 } 1148 } else {
1107 else
1108 {
1109 brelse(nbh); 1149 brelse(nbh);
1110 brelse(ibh); 1150 brelse(ibh);
1111 } 1151 }
1112 } 1152 } else
1113 else
1114 brelse(ibh); 1153 brelse(ibh);
1115 } 1154 }
1116 } 1155 } else
1117 else
1118 brelse(ibh); 1156 brelse(ibh);
1119 } 1157 } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
1120 else if (le16_to_cpu(fe->icbTag.strategyType) != 4)
1121 {
1122 printk(KERN_ERR "udf: unsupported strategy type: %d\n", 1158 printk(KERN_ERR "udf: unsupported strategy type: %d\n",
1123 le16_to_cpu(fe->icbTag.strategyType)); 1159 le16_to_cpu(fe->icbTag.strategyType));
1124 brelse(bh); 1160 brelse(bh);
1125 make_bad_inode(inode); 1161 make_bad_inode(inode);
1126 return; 1162 return;
@@ -1143,62 +1179,70 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1143 1179
1144 if (le16_to_cpu(fe->icbTag.strategyType) == 4) 1180 if (le16_to_cpu(fe->icbTag.strategyType) == 4)
1145 UDF_I_STRAT4096(inode) = 0; 1181 UDF_I_STRAT4096(inode) = 0;
1146 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */ 1182 else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
1147 UDF_I_STRAT4096(inode) = 1; 1183 UDF_I_STRAT4096(inode) = 1;
1148 1184
1149 UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK; 1185 UDF_I_ALLOCTYPE(inode) =
1186 le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
1150 UDF_I_UNIQUE(inode) = 0; 1187 UDF_I_UNIQUE(inode) = 0;
1151 UDF_I_LENEATTR(inode) = 0; 1188 UDF_I_LENEATTR(inode) = 0;
1152 UDF_I_LENEXTENTS(inode) = 0; 1189 UDF_I_LENEXTENTS(inode) = 0;
1153 UDF_I_LENALLOC(inode) = 0; 1190 UDF_I_LENALLOC(inode) = 0;
1154 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0; 1191 UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
1155 UDF_I_NEXT_ALLOC_GOAL(inode) = 0; 1192 UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
1156 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) 1193 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
1157 {
1158 UDF_I_EFE(inode) = 1; 1194 UDF_I_EFE(inode) = 1;
1159 UDF_I_USE(inode) = 0; 1195 UDF_I_USE(inode) = 0;
1160 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) 1196 if (udf_alloc_i_data
1161 { 1197 (inode,
1198 inode->i_sb->s_blocksize -
1199 sizeof(struct extendedFileEntry))) {
1162 make_bad_inode(inode); 1200 make_bad_inode(inode);
1163 return; 1201 return;
1164 } 1202 }
1165 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); 1203 memcpy(UDF_I_DATA(inode),
1166 } 1204 bh->b_data + sizeof(struct extendedFileEntry),
1167 else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) 1205 inode->i_sb->s_blocksize -
1168 { 1206 sizeof(struct extendedFileEntry));
1207 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
1169 UDF_I_EFE(inode) = 0; 1208 UDF_I_EFE(inode) = 0;
1170 UDF_I_USE(inode) = 0; 1209 UDF_I_USE(inode) = 0;
1171 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) 1210 if (udf_alloc_i_data
1172 { 1211 (inode,
1212 inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
1173 make_bad_inode(inode); 1213 make_bad_inode(inode);
1174 return; 1214 return;
1175 } 1215 }
1176 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry), inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1216 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
1177 } 1217 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1178 else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) 1218 } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1179 {
1180 UDF_I_EFE(inode) = 0; 1219 UDF_I_EFE(inode) = 0;
1181 UDF_I_USE(inode) = 1; 1220 UDF_I_USE(inode) = 1;
1182 UDF_I_LENALLOC(inode) = 1221 UDF_I_LENALLOC(inode) =
1183 le32_to_cpu( 1222 le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->
1184 ((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs); 1223 lengthAllocDescs);
1185 if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) 1224 if (udf_alloc_i_data
1186 { 1225 (inode,
1226 inode->i_sb->s_blocksize -
1227 sizeof(struct unallocSpaceEntry))) {
1187 make_bad_inode(inode); 1228 make_bad_inode(inode);
1188 return; 1229 return;
1189 } 1230 }
1190 memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); 1231 memcpy(UDF_I_DATA(inode),
1232 bh->b_data + sizeof(struct unallocSpaceEntry),
1233 inode->i_sb->s_blocksize -
1234 sizeof(struct unallocSpaceEntry));
1191 return; 1235 return;
1192 } 1236 }
1193 1237
1194 inode->i_uid = le32_to_cpu(fe->uid); 1238 inode->i_uid = le32_to_cpu(fe->uid);
1195 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb, 1239 if (inode->i_uid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1196 UDF_FLAG_UID_IGNORE)) 1240 UDF_FLAG_UID_IGNORE))
1197 inode->i_uid = UDF_SB(inode->i_sb)->s_uid; 1241 inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
1198 1242
1199 inode->i_gid = le32_to_cpu(fe->gid); 1243 inode->i_gid = le32_to_cpu(fe->gid);
1200 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb, 1244 if (inode->i_gid == -1 || UDF_QUERY_FLAG(inode->i_sb,
1201 UDF_FLAG_GID_IGNORE)) 1245 UDF_FLAG_GID_IGNORE))
1202 inode->i_gid = UDF_SB(inode->i_sb)->s_gid; 1246 inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
1203 1247
1204 inode->i_nlink = le16_to_cpu(fe->fileLinkCount); 1248 inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
@@ -1211,41 +1255,31 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1211 inode->i_mode = udf_convert_permissions(fe); 1255 inode->i_mode = udf_convert_permissions(fe);
1212 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask; 1256 inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
1213 1257
1214 if (UDF_I_EFE(inode) == 0) 1258 if (UDF_I_EFE(inode) == 0) {
1215 {
1216 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) << 1259 inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
1217 (inode->i_sb->s_blocksize_bits - 9); 1260 (inode->i_sb->s_blocksize_bits - 9);
1218 1261
1219 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1262 if (udf_stamp_to_time(&convtime, &convtime_usec,
1220 lets_to_cpu(fe->accessTime)) ) 1263 lets_to_cpu(fe->accessTime))) {
1221 {
1222 inode->i_atime.tv_sec = convtime; 1264 inode->i_atime.tv_sec = convtime;
1223 inode->i_atime.tv_nsec = convtime_usec * 1000; 1265 inode->i_atime.tv_nsec = convtime_usec * 1000;
1224 } 1266 } else {
1225 else
1226 {
1227 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); 1267 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1228 } 1268 }
1229 1269
1230 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1270 if (udf_stamp_to_time(&convtime, &convtime_usec,
1231 lets_to_cpu(fe->modificationTime)) ) 1271 lets_to_cpu(fe->modificationTime))) {
1232 {
1233 inode->i_mtime.tv_sec = convtime; 1272 inode->i_mtime.tv_sec = convtime;
1234 inode->i_mtime.tv_nsec = convtime_usec * 1000; 1273 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1235 } 1274 } else {
1236 else
1237 {
1238 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); 1275 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1239 } 1276 }
1240 1277
1241 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1278 if (udf_stamp_to_time(&convtime, &convtime_usec,
1242 lets_to_cpu(fe->attrTime)) ) 1279 lets_to_cpu(fe->attrTime))) {
1243 {
1244 inode->i_ctime.tv_sec = convtime; 1280 inode->i_ctime.tv_sec = convtime;
1245 inode->i_ctime.tv_nsec = convtime_usec * 1000; 1281 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1246 } 1282 } else {
1247 else
1248 {
1249 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); 1283 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1250 } 1284 }
1251 1285
@@ -1253,65 +1287,51 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1253 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr); 1287 UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
1254 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs); 1288 UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
1255 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode); 1289 offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
1256 } 1290 } else {
1257 else
1258 {
1259 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) << 1291 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
1260 (inode->i_sb->s_blocksize_bits - 9); 1292 (inode->i_sb->s_blocksize_bits - 9);
1261 1293
1262 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1294 if (udf_stamp_to_time(&convtime, &convtime_usec,
1263 lets_to_cpu(efe->accessTime)) ) 1295 lets_to_cpu(efe->accessTime))) {
1264 {
1265 inode->i_atime.tv_sec = convtime; 1296 inode->i_atime.tv_sec = convtime;
1266 inode->i_atime.tv_nsec = convtime_usec * 1000; 1297 inode->i_atime.tv_nsec = convtime_usec * 1000;
1267 } 1298 } else {
1268 else
1269 {
1270 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb); 1299 inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
1271 } 1300 }
1272 1301
1273 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1302 if (udf_stamp_to_time(&convtime, &convtime_usec,
1274 lets_to_cpu(efe->modificationTime)) ) 1303 lets_to_cpu(efe->modificationTime))) {
1275 {
1276 inode->i_mtime.tv_sec = convtime; 1304 inode->i_mtime.tv_sec = convtime;
1277 inode->i_mtime.tv_nsec = convtime_usec * 1000; 1305 inode->i_mtime.tv_nsec = convtime_usec * 1000;
1278 } 1306 } else {
1279 else
1280 {
1281 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb); 1307 inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
1282 } 1308 }
1283 1309
1284 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1310 if (udf_stamp_to_time(&convtime, &convtime_usec,
1285 lets_to_cpu(efe->createTime)) ) 1311 lets_to_cpu(efe->createTime))) {
1286 {
1287 UDF_I_CRTIME(inode).tv_sec = convtime; 1312 UDF_I_CRTIME(inode).tv_sec = convtime;
1288 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000; 1313 UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
1289 } 1314 } else {
1290 else
1291 {
1292 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb); 1315 UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
1293 } 1316 }
1294 1317
1295 if ( udf_stamp_to_time(&convtime, &convtime_usec, 1318 if (udf_stamp_to_time(&convtime, &convtime_usec,
1296 lets_to_cpu(efe->attrTime)) ) 1319 lets_to_cpu(efe->attrTime))) {
1297 {
1298 inode->i_ctime.tv_sec = convtime; 1320 inode->i_ctime.tv_sec = convtime;
1299 inode->i_ctime.tv_nsec = convtime_usec * 1000; 1321 inode->i_ctime.tv_nsec = convtime_usec * 1000;
1300 } 1322 } else {
1301 else
1302 {
1303 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb); 1323 inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
1304 } 1324 }
1305 1325
1306 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID); 1326 UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
1307 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr); 1327 UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
1308 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs); 1328 UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
1309 offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode); 1329 offset =
1330 sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
1310 } 1331 }
1311 1332
1312 switch (fe->icbTag.fileType) 1333 switch (fe->icbTag.fileType) {
1313 { 1334 case ICBTAG_FILE_TYPE_DIRECTORY:
1314 case ICBTAG_FILE_TYPE_DIRECTORY:
1315 { 1335 {
1316 inode->i_op = &udf_dir_inode_operations; 1336 inode->i_op = &udf_dir_inode_operations;
1317 inode->i_fop = &udf_dir_operations; 1337 inode->i_fop = &udf_dir_operations;
@@ -1319,9 +1339,9 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1319 inc_nlink(inode); 1339 inc_nlink(inode);
1320 break; 1340 break;
1321 } 1341 }
1322 case ICBTAG_FILE_TYPE_REALTIME: 1342 case ICBTAG_FILE_TYPE_REALTIME:
1323 case ICBTAG_FILE_TYPE_REGULAR: 1343 case ICBTAG_FILE_TYPE_REGULAR:
1324 case ICBTAG_FILE_TYPE_UNDEF: 1344 case ICBTAG_FILE_TYPE_UNDEF:
1325 { 1345 {
1326 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) 1346 if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
1327 inode->i_data.a_ops = &udf_adinicb_aops; 1347 inode->i_data.a_ops = &udf_adinicb_aops;
@@ -1332,56 +1352,54 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
1332 inode->i_mode |= S_IFREG; 1352 inode->i_mode |= S_IFREG;
1333 break; 1353 break;
1334 } 1354 }
1335 case ICBTAG_FILE_TYPE_BLOCK: 1355 case ICBTAG_FILE_TYPE_BLOCK:
1336 { 1356 {
1337 inode->i_mode |= S_IFBLK; 1357 inode->i_mode |= S_IFBLK;
1338 break; 1358 break;
1339 } 1359 }
1340 case ICBTAG_FILE_TYPE_CHAR: 1360 case ICBTAG_FILE_TYPE_CHAR:
1341 { 1361 {
1342 inode->i_mode |= S_IFCHR; 1362 inode->i_mode |= S_IFCHR;
1343 break; 1363 break;
1344 } 1364 }
1345 case ICBTAG_FILE_TYPE_FIFO: 1365 case ICBTAG_FILE_TYPE_FIFO:
1346 { 1366 {
1347 init_special_inode(inode, inode->i_mode | S_IFIFO, 0); 1367 init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
1348 break; 1368 break;
1349 } 1369 }
1350 case ICBTAG_FILE_TYPE_SOCKET: 1370 case ICBTAG_FILE_TYPE_SOCKET:
1351 { 1371 {
1352 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0); 1372 init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
1353 break; 1373 break;
1354 } 1374 }
1355 case ICBTAG_FILE_TYPE_SYMLINK: 1375 case ICBTAG_FILE_TYPE_SYMLINK:
1356 { 1376 {
1357 inode->i_data.a_ops = &udf_symlink_aops; 1377 inode->i_data.a_ops = &udf_symlink_aops;
1358 inode->i_op = &page_symlink_inode_operations; 1378 inode->i_op = &page_symlink_inode_operations;
1359 inode->i_mode = S_IFLNK|S_IRWXUGO; 1379 inode->i_mode = S_IFLNK | S_IRWXUGO;
1360 break; 1380 break;
1361 } 1381 }
1362 default: 1382 default:
1363 { 1383 {
1364 printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n", 1384 printk(KERN_ERR
1365 inode->i_ino, fe->icbTag.fileType); 1385 "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
1386 inode->i_ino, fe->icbTag.fileType);
1366 make_bad_inode(inode); 1387 make_bad_inode(inode);
1367 return; 1388 return;
1368 } 1389 }
1369 } 1390 }
1370 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1391 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1371 { 1392 struct deviceSpec *dsea = (struct deviceSpec *)
1372 struct deviceSpec *dsea = 1393 udf_get_extendedattr(inode, 12, 1);
1373 (struct deviceSpec *)
1374 udf_get_extendedattr(inode, 12, 1);
1375 1394
1376 if (dsea) 1395 if (dsea) {
1377 { 1396 init_special_inode(inode, inode->i_mode,
1378 init_special_inode(inode, inode->i_mode, MKDEV( 1397 MKDEV(le32_to_cpu
1379 le32_to_cpu(dsea->majorDeviceIdent), 1398 (dsea->majorDeviceIdent),
1380 le32_to_cpu(dsea->minorDeviceIdent))); 1399 le32_to_cpu(dsea->
1400 minorDeviceIdent)));
1381 /* Developer ID ??? */ 1401 /* Developer ID ??? */
1382 } 1402 } else {
1383 else
1384 {
1385 make_bad_inode(inode); 1403 make_bad_inode(inode);
1386 } 1404 }
1387 } 1405 }
@@ -1391,9 +1409,9 @@ static int udf_alloc_i_data(struct inode *inode, size_t size)
1391{ 1409{
1392 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL); 1410 UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
1393 1411
1394 if (!UDF_I_DATA(inode)) 1412 if (!UDF_I_DATA(inode)) {
1395 { 1413 printk(KERN_ERR
1396 printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) no free memory\n", 1414 "udf:udf_alloc_i_data (ino %ld) no free memory\n",
1397 inode->i_ino); 1415 inode->i_ino);
1398 return -ENOMEM; 1416 return -ENOMEM;
1399 } 1417 }
@@ -1401,8 +1419,7 @@ static int udf_alloc_i_data(struct inode *inode, size_t size)
1401 return 0; 1419 return 0;
1402} 1420}
1403 1421
1404static mode_t 1422static mode_t udf_convert_permissions(struct fileEntry *fe)
1405udf_convert_permissions(struct fileEntry *fe)
1406{ 1423{
1407 mode_t mode; 1424 mode_t mode;
1408 uint32_t permissions; 1425 uint32_t permissions;
@@ -1411,12 +1428,12 @@ udf_convert_permissions(struct fileEntry *fe)
1411 permissions = le32_to_cpu(fe->permissions); 1428 permissions = le32_to_cpu(fe->permissions);
1412 flags = le16_to_cpu(fe->icbTag.flags); 1429 flags = le16_to_cpu(fe->icbTag.flags);
1413 1430
1414 mode = (( permissions ) & S_IRWXO) | 1431 mode = ((permissions) & S_IRWXO) |
1415 (( permissions >> 2 ) & S_IRWXG) | 1432 ((permissions >> 2) & S_IRWXG) |
1416 (( permissions >> 4 ) & S_IRWXU) | 1433 ((permissions >> 4) & S_IRWXU) |
1417 (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) | 1434 ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
1418 (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) | 1435 ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
1419 (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0); 1436 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
1420 1437
1421 return mode; 1438 return mode;
1422} 1439}
@@ -1436,7 +1453,7 @@ udf_convert_permissions(struct fileEntry *fe)
1436 * Written, tested, and released. 1453 * Written, tested, and released.
1437 */ 1454 */
1438 1455
1439int udf_write_inode(struct inode * inode, int sync) 1456int udf_write_inode(struct inode *inode, int sync)
1440{ 1457{
1441 int ret; 1458 int ret;
1442 lock_kernel(); 1459 lock_kernel();
@@ -1445,13 +1462,12 @@ int udf_write_inode(struct inode * inode, int sync)
1445 return ret; 1462 return ret;
1446} 1463}
1447 1464
1448int udf_sync_inode(struct inode * inode) 1465int udf_sync_inode(struct inode *inode)
1449{ 1466{
1450 return udf_update_inode(inode, 1); 1467 return udf_update_inode(inode, 1);
1451} 1468}
1452 1469
1453static int 1470static int udf_update_inode(struct inode *inode, int do_sync)
1454udf_update_inode(struct inode *inode, int do_sync)
1455{ 1471{
1456 struct buffer_head *bh = NULL; 1472 struct buffer_head *bh = NULL;
1457 struct fileEntry *fe; 1473 struct fileEntry *fe;
@@ -1464,10 +1480,10 @@ udf_update_inode(struct inode *inode, int do_sync)
1464 int err = 0; 1480 int err = 0;
1465 1481
1466 bh = udf_tread(inode->i_sb, 1482 bh = udf_tread(inode->i_sb,
1467 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0)); 1483 udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode),
1484 0));
1468 1485
1469 if (!bh) 1486 if (!bh) {
1470 {
1471 udf_debug("bread failure\n"); 1487 udf_debug("bread failure\n");
1472 return -EIO; 1488 return -EIO;
1473 } 1489 }
@@ -1477,23 +1493,29 @@ udf_update_inode(struct inode *inode, int do_sync)
1477 fe = (struct fileEntry *)bh->b_data; 1493 fe = (struct fileEntry *)bh->b_data;
1478 efe = (struct extendedFileEntry *)bh->b_data; 1494 efe = (struct extendedFileEntry *)bh->b_data;
1479 1495
1480 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) 1496 if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
1481 {
1482 struct unallocSpaceEntry *use = 1497 struct unallocSpaceEntry *use =
1483 (struct unallocSpaceEntry *)bh->b_data; 1498 (struct unallocSpaceEntry *)bh->b_data;
1484 1499
1485 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1500 use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1486 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry)); 1501 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1487 crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - 1502 UDF_I_DATA(inode),
1488 sizeof(tag); 1503 inode->i_sb->s_blocksize -
1489 use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); 1504 sizeof(struct unallocSpaceEntry));
1505 crclen =
1506 sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) -
1507 sizeof(tag);
1508 use->descTag.tagLocation =
1509 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1490 use->descTag.descCRCLength = cpu_to_le16(crclen); 1510 use->descTag.descCRCLength = cpu_to_le16(crclen);
1491 use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0)); 1511 use->descTag.descCRC =
1512 cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
1492 1513
1493 use->descTag.tagChecksum = 0; 1514 use->descTag.tagChecksum = 0;
1494 for (i=0; i<16; i++) 1515 for (i = 0; i < 16; i++)
1495 if (i != 4) 1516 if (i != 4)
1496 use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i]; 1517 use->descTag.tagChecksum +=
1518 ((uint8_t *) & (use->descTag))[i];
1497 1519
1498 mark_buffer_dirty(bh); 1520 mark_buffer_dirty(bh);
1499 brelse(bh); 1521 brelse(bh);
@@ -1502,20 +1524,21 @@ udf_update_inode(struct inode *inode, int do_sync)
1502 1524
1503 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET)) 1525 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
1504 fe->uid = cpu_to_le32(-1); 1526 fe->uid = cpu_to_le32(-1);
1505 else fe->uid = cpu_to_le32(inode->i_uid); 1527 else
1528 fe->uid = cpu_to_le32(inode->i_uid);
1506 1529
1507 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET)) 1530 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
1508 fe->gid = cpu_to_le32(-1); 1531 fe->gid = cpu_to_le32(-1);
1509 else fe->gid = cpu_to_le32(inode->i_gid); 1532 else
1533 fe->gid = cpu_to_le32(inode->i_gid);
1510 1534
1511 udfperms = ((inode->i_mode & S_IRWXO) ) | 1535 udfperms = ((inode->i_mode & S_IRWXO)) |
1512 ((inode->i_mode & S_IRWXG) << 2) | 1536 ((inode->i_mode & S_IRWXG) << 2) | ((inode->i_mode & S_IRWXU) << 4);
1513 ((inode->i_mode & S_IRWXU) << 4);
1514 1537
1515 udfperms |= (le32_to_cpu(fe->permissions) & 1538 udfperms |= (le32_to_cpu(fe->permissions) &
1516 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR | 1539 (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1517 FE_PERM_G_DELETE | FE_PERM_G_CHATTR | 1540 FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1518 FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); 1541 FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1519 fe->permissions = cpu_to_le32(udfperms); 1542 fe->permissions = cpu_to_le32(udfperms);
1520 1543
1521 if (S_ISDIR(inode->i_mode)) 1544 if (S_ISDIR(inode->i_mode))
@@ -1525,26 +1548,24 @@ udf_update_inode(struct inode *inode, int do_sync)
1525 1548
1526 fe->informationLength = cpu_to_le64(inode->i_size); 1549 fe->informationLength = cpu_to_le64(inode->i_size);
1527 1550
1528 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 1551 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
1529 {
1530 regid *eid; 1552 regid *eid;
1531 struct deviceSpec *dsea = 1553 struct deviceSpec *dsea = (struct deviceSpec *)
1532 (struct deviceSpec *) 1554 udf_get_extendedattr(inode, 12, 1);
1533 udf_get_extendedattr(inode, 12, 1);
1534 1555
1535 if (!dsea) 1556 if (!dsea) {
1536 {
1537 dsea = (struct deviceSpec *) 1557 dsea = (struct deviceSpec *)
1538 udf_add_extendedattr(inode, 1558 udf_add_extendedattr(inode,
1539 sizeof(struct deviceSpec) + 1559 sizeof(struct deviceSpec) +
1540 sizeof(regid), 12, 0x3); 1560 sizeof(regid), 12, 0x3);
1541 dsea->attrType = cpu_to_le32(12); 1561 dsea->attrType = cpu_to_le32(12);
1542 dsea->attrSubtype = 1; 1562 dsea->attrSubtype = 1;
1543 dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) + 1563 dsea->attrLength =
1544 sizeof(regid)); 1564 cpu_to_le32(sizeof(struct deviceSpec) +
1565 sizeof(regid));
1545 dsea->impUseLength = cpu_to_le32(sizeof(regid)); 1566 dsea->impUseLength = cpu_to_le32(sizeof(regid));
1546 } 1567 }
1547 eid = (regid *)dsea->impUse; 1568 eid = (regid *) dsea->impUse;
1548 memset(eid, 0, sizeof(regid)); 1569 memset(eid, 0, sizeof(regid));
1549 strcpy(eid->ident, UDF_ID_DEVELOPER); 1570 strcpy(eid->ident, UDF_ID_DEVELOPER);
1550 eid->identSuffix[0] = UDF_OS_CLASS_UNIX; 1571 eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
@@ -1553,12 +1574,13 @@ udf_update_inode(struct inode *inode, int do_sync)
1553 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode)); 1574 dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
1554 } 1575 }
1555 1576
1556 if (UDF_I_EFE(inode) == 0) 1577 if (UDF_I_EFE(inode) == 0) {
1557 { 1578 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
1558 memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct fileEntry)); 1579 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
1559 fe->logicalBlocksRecorded = cpu_to_le64( 1580 fe->logicalBlocksRecorded =
1560 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> 1581 cpu_to_le64((inode->i_blocks +
1561 (inode->i_sb->s_blocksize_bits - 9)); 1582 (1 << (inode->i_sb->s_blocksize_bits - 9)) -
1583 1) >> (inode->i_sb->s_blocksize_bits - 9));
1562 1584
1563 if (udf_time_to_stamp(&cpu_time, inode->i_atime)) 1585 if (udf_time_to_stamp(&cpu_time, inode->i_atime))
1564 fe->accessTime = cpu_to_lets(cpu_time); 1586 fe->accessTime = cpu_to_lets(cpu_time);
@@ -1575,31 +1597,34 @@ udf_update_inode(struct inode *inode, int do_sync)
1575 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode)); 1597 fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
1576 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE); 1598 fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
1577 crclen = sizeof(struct fileEntry); 1599 crclen = sizeof(struct fileEntry);
1578 } 1600 } else {
1579 else 1601 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1580 { 1602 UDF_I_DATA(inode),
1581 memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode), inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry)); 1603 inode->i_sb->s_blocksize -
1604 sizeof(struct extendedFileEntry));
1582 efe->objectSize = cpu_to_le64(inode->i_size); 1605 efe->objectSize = cpu_to_le64(inode->i_size);
1583 efe->logicalBlocksRecorded = cpu_to_le64( 1606 efe->logicalBlocksRecorded = cpu_to_le64((inode->i_blocks +
1584 (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >> 1607 (1 <<
1585 (inode->i_sb->s_blocksize_bits - 9)); 1608 (inode->i_sb->
1609 s_blocksize_bits -
1610 9)) -
1611 1) >> (inode->i_sb->
1612 s_blocksize_bits
1613 - 9));
1586 1614
1587 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec || 1615 if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
1588 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec && 1616 (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
1589 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) 1617 UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) {
1590 {
1591 UDF_I_CRTIME(inode) = inode->i_atime; 1618 UDF_I_CRTIME(inode) = inode->i_atime;
1592 } 1619 }
1593 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec || 1620 if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
1594 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec && 1621 (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
1595 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) 1622 UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) {
1596 {
1597 UDF_I_CRTIME(inode) = inode->i_mtime; 1623 UDF_I_CRTIME(inode) = inode->i_mtime;
1598 } 1624 }
1599 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec || 1625 if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
1600 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec && 1626 (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
1601 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) 1627 UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) {
1602 {
1603 UDF_I_CRTIME(inode) = inode->i_ctime; 1628 UDF_I_CRTIME(inode) = inode->i_ctime;
1604 } 1629 }
1605 1630
@@ -1622,14 +1647,11 @@ udf_update_inode(struct inode *inode, int do_sync)
1622 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE); 1647 efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
1623 crclen = sizeof(struct extendedFileEntry); 1648 crclen = sizeof(struct extendedFileEntry);
1624 } 1649 }
1625 if (UDF_I_STRAT4096(inode)) 1650 if (UDF_I_STRAT4096(inode)) {
1626 {
1627 fe->icbTag.strategyType = cpu_to_le16(4096); 1651 fe->icbTag.strategyType = cpu_to_le16(4096);
1628 fe->icbTag.strategyParameter = cpu_to_le16(1); 1652 fe->icbTag.strategyParameter = cpu_to_le16(1);
1629 fe->icbTag.numEntries = cpu_to_le16(2); 1653 fe->icbTag.numEntries = cpu_to_le16(2);
1630 } 1654 } else {
1631 else
1632 {
1633 fe->icbTag.strategyType = cpu_to_le16(4); 1655 fe->icbTag.strategyType = cpu_to_le16(4);
1634 fe->icbTag.numEntries = cpu_to_le16(1); 1656 fe->icbTag.numEntries = cpu_to_le16(1);
1635 } 1657 }
@@ -1649,13 +1671,13 @@ udf_update_inode(struct inode *inode, int do_sync)
1649 else if (S_ISSOCK(inode->i_mode)) 1671 else if (S_ISSOCK(inode->i_mode))
1650 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET; 1672 fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
1651 1673
1652 icbflags = UDF_I_ALLOCTYPE(inode) | 1674 icbflags = UDF_I_ALLOCTYPE(inode) |
1653 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) | 1675 ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
1654 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) | 1676 ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
1655 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) | 1677 ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
1656 (le16_to_cpu(fe->icbTag.flags) & 1678 (le16_to_cpu(fe->icbTag.flags) &
1657 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID | 1679 ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
1658 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY)); 1680 ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
1659 1681
1660 fe->icbTag.flags = cpu_to_le16(icbflags); 1682 fe->icbTag.flags = cpu_to_le16(icbflags);
1661 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 1683 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
@@ -1663,25 +1685,26 @@ udf_update_inode(struct inode *inode, int do_sync)
1663 else 1685 else
1664 fe->descTag.descVersion = cpu_to_le16(2); 1686 fe->descTag.descVersion = cpu_to_le16(2);
1665 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb)); 1687 fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
1666 fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum); 1688 fe->descTag.tagLocation =
1689 cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
1667 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag); 1690 crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
1668 fe->descTag.descCRCLength = cpu_to_le16(crclen); 1691 fe->descTag.descCRCLength = cpu_to_le16(crclen);
1669 fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0)); 1692 fe->descTag.descCRC =
1693 cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
1670 1694
1671 fe->descTag.tagChecksum = 0; 1695 fe->descTag.tagChecksum = 0;
1672 for (i=0; i<16; i++) 1696 for (i = 0; i < 16; i++)
1673 if (i != 4) 1697 if (i != 4)
1674 fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i]; 1698 fe->descTag.tagChecksum +=
1699 ((uint8_t *) & (fe->descTag))[i];
1675 1700
1676 /* write the data blocks */ 1701 /* write the data blocks */
1677 mark_buffer_dirty(bh); 1702 mark_buffer_dirty(bh);
1678 if (do_sync) 1703 if (do_sync) {
1679 {
1680 sync_dirty_buffer(bh); 1704 sync_dirty_buffer(bh);
1681 if (buffer_req(bh) && !buffer_uptodate(bh)) 1705 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1682 {
1683 printk("IO error syncing udf inode [%s:%08lx]\n", 1706 printk("IO error syncing udf inode [%s:%08lx]\n",
1684 inode->i_sb->s_id, inode->i_ino); 1707 inode->i_sb->s_id, inode->i_ino);
1685 err = -EIO; 1708 err = -EIO;
1686 } 1709 }
1687 } 1710 }
@@ -1689,8 +1712,7 @@ udf_update_inode(struct inode *inode, int do_sync)
1689 return err; 1712 return err;
1690} 1713}
1691 1714
1692struct inode * 1715struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
1693udf_iget(struct super_block *sb, kernel_lb_addr ino)
1694{ 1716{
1695 unsigned long block = udf_get_lb_pblock(sb, ino, 0); 1717 unsigned long block = udf_get_lb_pblock(sb, ino, 0);
1696 struct inode *inode = iget_locked(sb, block); 1718 struct inode *inode = iget_locked(sb, block);
@@ -1707,22 +1729,23 @@ udf_iget(struct super_block *sb, kernel_lb_addr ino)
1707 if (is_bad_inode(inode)) 1729 if (is_bad_inode(inode))
1708 goto out_iput; 1730 goto out_iput;
1709 1731
1710 if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) { 1732 if (ino.logicalBlockNum >=
1733 UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
1711 udf_debug("block=%d, partition=%d out of range\n", 1734 udf_debug("block=%d, partition=%d out of range\n",
1712 ino.logicalBlockNum, ino.partitionReferenceNum); 1735 ino.logicalBlockNum, ino.partitionReferenceNum);
1713 make_bad_inode(inode); 1736 make_bad_inode(inode);
1714 goto out_iput; 1737 goto out_iput;
1715 } 1738 }
1716 1739
1717 return inode; 1740 return inode;
1718 1741
1719 out_iput: 1742 out_iput:
1720 iput(inode); 1743 iput(inode);
1721 return NULL; 1744 return NULL;
1722} 1745}
1723 1746
1724int8_t udf_add_aext(struct inode *inode, struct extent_position *epos, 1747int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
1725 kernel_lb_addr eloc, uint32_t elen, int inc) 1748 kernel_lb_addr eloc, uint32_t elen, int inc)
1726{ 1749{
1727 int adsize; 1750 int adsize;
1728 short_ad *sad = NULL; 1751 short_ad *sad = NULL;
@@ -1732,7 +1755,9 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1732 uint8_t *ptr; 1755 uint8_t *ptr;
1733 1756
1734 if (!epos->bh) 1757 if (!epos->bh)
1735 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1758 ptr =
1759 UDF_I_DATA(inode) + epos->offset -
1760 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1736 else 1761 else
1737 ptr = epos->bh->b_data + epos->offset; 1762 ptr = epos->bh->b_data + epos->offset;
1738 1763
@@ -1743,21 +1768,24 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1743 else 1768 else
1744 return -1; 1769 return -1;
1745 1770
1746 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) 1771 if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
1747 {
1748 char *sptr, *dptr; 1772 char *sptr, *dptr;
1749 struct buffer_head *nbh; 1773 struct buffer_head *nbh;
1750 int err, loffset; 1774 int err, loffset;
1751 kernel_lb_addr obloc = epos->block; 1775 kernel_lb_addr obloc = epos->block;
1752 1776
1753 if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL, 1777 if (!
1754 obloc.partitionReferenceNum, obloc.logicalBlockNum, &err))) 1778 (epos->block.logicalBlockNum =
1755 { 1779 udf_new_block(inode->i_sb, NULL,
1780 obloc.partitionReferenceNum,
1781 obloc.logicalBlockNum, &err))) {
1756 return -1; 1782 return -1;
1757 } 1783 }
1758 if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb, 1784 if (!
1759 epos->block, 0)))) 1785 (nbh =
1760 { 1786 udf_tgetblk(inode->i_sb,
1787 udf_get_lb_pblock(inode->i_sb, epos->block,
1788 0)))) {
1761 return -1; 1789 return -1;
1762 } 1790 }
1763 lock_buffer(nbh); 1791 lock_buffer(nbh);
@@ -1768,144 +1796,142 @@ int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
1768 1796
1769 aed = (struct allocExtDesc *)(nbh->b_data); 1797 aed = (struct allocExtDesc *)(nbh->b_data);
1770 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)) 1798 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
1771 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); 1799 aed->previousAllocExtLocation =
1772 if (epos->offset + adsize > inode->i_sb->s_blocksize) 1800 cpu_to_le32(obloc.logicalBlockNum);
1773 { 1801 if (epos->offset + adsize > inode->i_sb->s_blocksize) {
1774 loffset = epos->offset; 1802 loffset = epos->offset;
1775 aed->lengthAllocDescs = cpu_to_le32(adsize); 1803 aed->lengthAllocDescs = cpu_to_le32(adsize);
1776 sptr = ptr - adsize; 1804 sptr = ptr - adsize;
1777 dptr = nbh->b_data + sizeof(struct allocExtDesc); 1805 dptr = nbh->b_data + sizeof(struct allocExtDesc);
1778 memcpy(dptr, sptr, adsize); 1806 memcpy(dptr, sptr, adsize);
1779 epos->offset = sizeof(struct allocExtDesc) + adsize; 1807 epos->offset = sizeof(struct allocExtDesc) + adsize;
1780 } 1808 } else {
1781 else
1782 {
1783 loffset = epos->offset + adsize; 1809 loffset = epos->offset + adsize;
1784 aed->lengthAllocDescs = cpu_to_le32(0); 1810 aed->lengthAllocDescs = cpu_to_le32(0);
1785 sptr = ptr; 1811 sptr = ptr;
1786 epos->offset = sizeof(struct allocExtDesc); 1812 epos->offset = sizeof(struct allocExtDesc);
1787 1813
1788 if (epos->bh) 1814 if (epos->bh) {
1789 {
1790 aed = (struct allocExtDesc *)epos->bh->b_data; 1815 aed = (struct allocExtDesc *)epos->bh->b_data;
1791 aed->lengthAllocDescs = 1816 aed->lengthAllocDescs =
1792 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1817 cpu_to_le32(le32_to_cpu
1793 } 1818 (aed->lengthAllocDescs) +
1794 else 1819 adsize);
1795 { 1820 } else {
1796 UDF_I_LENALLOC(inode) += adsize; 1821 UDF_I_LENALLOC(inode) += adsize;
1797 mark_inode_dirty(inode); 1822 mark_inode_dirty(inode);
1798 } 1823 }
1799 } 1824 }
1800 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200) 1825 if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
1801 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, 1826 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
1802 epos->block.logicalBlockNum, sizeof(tag)); 1827 epos->block.logicalBlockNum, sizeof(tag));
1803 else 1828 else
1804 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, 1829 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
1805 epos->block.logicalBlockNum, sizeof(tag)); 1830 epos->block.logicalBlockNum, sizeof(tag));
1806 switch (UDF_I_ALLOCTYPE(inode)) 1831 switch (UDF_I_ALLOCTYPE(inode)) {
1807 { 1832 case ICBTAG_FLAG_AD_SHORT:
1808 case ICBTAG_FLAG_AD_SHORT:
1809 { 1833 {
1810 sad = (short_ad *)sptr; 1834 sad = (short_ad *) sptr;
1811 sad->extLength = cpu_to_le32( 1835 sad->extLength =
1812 EXT_NEXT_EXTENT_ALLOCDECS | 1836 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1813 inode->i_sb->s_blocksize); 1837 inode->i_sb->s_blocksize);
1814 sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum); 1838 sad->extPosition =
1839 cpu_to_le32(epos->block.logicalBlockNum);
1815 break; 1840 break;
1816 } 1841 }
1817 case ICBTAG_FLAG_AD_LONG: 1842 case ICBTAG_FLAG_AD_LONG:
1818 { 1843 {
1819 lad = (long_ad *)sptr; 1844 lad = (long_ad *) sptr;
1820 lad->extLength = cpu_to_le32( 1845 lad->extLength =
1821 EXT_NEXT_EXTENT_ALLOCDECS | 1846 cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
1822 inode->i_sb->s_blocksize); 1847 inode->i_sb->s_blocksize);
1823 lad->extLocation = cpu_to_lelb(epos->block); 1848 lad->extLocation = cpu_to_lelb(epos->block);
1824 memset(lad->impUse, 0x00, sizeof(lad->impUse)); 1849 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1825 break; 1850 break;
1826 } 1851 }
1827 } 1852 }
1828 if (epos->bh) 1853 if (epos->bh) {
1829 { 1854 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1830 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1855 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1831 udf_update_tag(epos->bh->b_data, loffset); 1856 udf_update_tag(epos->bh->b_data, loffset);
1832 else 1857 else
1833 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); 1858 udf_update_tag(epos->bh->b_data,
1859 sizeof(struct allocExtDesc));
1834 mark_buffer_dirty_inode(epos->bh, inode); 1860 mark_buffer_dirty_inode(epos->bh, inode);
1835 brelse(epos->bh); 1861 brelse(epos->bh);
1836 } 1862 } else
1837 else
1838 mark_inode_dirty(inode); 1863 mark_inode_dirty(inode);
1839 epos->bh = nbh; 1864 epos->bh = nbh;
1840 } 1865 }
1841 1866
1842 etype = udf_write_aext(inode, epos, eloc, elen, inc); 1867 etype = udf_write_aext(inode, epos, eloc, elen, inc);
1843 1868
1844 if (!epos->bh) 1869 if (!epos->bh) {
1845 {
1846 UDF_I_LENALLOC(inode) += adsize; 1870 UDF_I_LENALLOC(inode) += adsize;
1847 mark_inode_dirty(inode); 1871 mark_inode_dirty(inode);
1848 } 1872 } else {
1849 else
1850 {
1851 aed = (struct allocExtDesc *)epos->bh->b_data; 1873 aed = (struct allocExtDesc *)epos->bh->b_data;
1852 aed->lengthAllocDescs = 1874 aed->lengthAllocDescs =
1853 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); 1875 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
1854 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1876 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1855 udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize)); 1877 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
1878 udf_update_tag(epos->bh->b_data,
1879 epos->offset + (inc ? 0 : adsize));
1856 else 1880 else
1857 udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc)); 1881 udf_update_tag(epos->bh->b_data,
1882 sizeof(struct allocExtDesc));
1858 mark_buffer_dirty_inode(epos->bh, inode); 1883 mark_buffer_dirty_inode(epos->bh, inode);
1859 } 1884 }
1860 1885
1861 return etype; 1886 return etype;
1862} 1887}
1863 1888
1864int8_t udf_write_aext(struct inode *inode, struct extent_position *epos, 1889int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
1865 kernel_lb_addr eloc, uint32_t elen, int inc) 1890 kernel_lb_addr eloc, uint32_t elen, int inc)
1866{ 1891{
1867 int adsize; 1892 int adsize;
1868 uint8_t *ptr; 1893 uint8_t *ptr;
1869 1894
1870 if (!epos->bh) 1895 if (!epos->bh)
1871 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1896 ptr =
1897 UDF_I_DATA(inode) + epos->offset -
1898 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1872 else 1899 else
1873 ptr = epos->bh->b_data + epos->offset; 1900 ptr = epos->bh->b_data + epos->offset;
1874 1901
1875 switch (UDF_I_ALLOCTYPE(inode)) 1902 switch (UDF_I_ALLOCTYPE(inode)) {
1876 { 1903 case ICBTAG_FLAG_AD_SHORT:
1877 case ICBTAG_FLAG_AD_SHORT:
1878 { 1904 {
1879 short_ad *sad = (short_ad *)ptr; 1905 short_ad *sad = (short_ad *) ptr;
1880 sad->extLength = cpu_to_le32(elen); 1906 sad->extLength = cpu_to_le32(elen);
1881 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum); 1907 sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
1882 adsize = sizeof(short_ad); 1908 adsize = sizeof(short_ad);
1883 break; 1909 break;
1884 } 1910 }
1885 case ICBTAG_FLAG_AD_LONG: 1911 case ICBTAG_FLAG_AD_LONG:
1886 { 1912 {
1887 long_ad *lad = (long_ad *)ptr; 1913 long_ad *lad = (long_ad *) ptr;
1888 lad->extLength = cpu_to_le32(elen); 1914 lad->extLength = cpu_to_le32(elen);
1889 lad->extLocation = cpu_to_lelb(eloc); 1915 lad->extLocation = cpu_to_lelb(eloc);
1890 memset(lad->impUse, 0x00, sizeof(lad->impUse)); 1916 memset(lad->impUse, 0x00, sizeof(lad->impUse));
1891 adsize = sizeof(long_ad); 1917 adsize = sizeof(long_ad);
1892 break; 1918 break;
1893 } 1919 }
1894 default: 1920 default:
1895 return -1; 1921 return -1;
1896 } 1922 }
1897 1923
1898 if (epos->bh) 1924 if (epos->bh) {
1899 { 1925 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
1900 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 1926 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) {
1901 { 1927 struct allocExtDesc *aed =
1902 struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data; 1928 (struct allocExtDesc *)epos->bh->b_data;
1903 udf_update_tag(epos->bh->b_data, 1929 udf_update_tag(epos->bh->b_data,
1904 le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc)); 1930 le32_to_cpu(aed->lengthAllocDescs) +
1931 sizeof(struct allocExtDesc));
1905 } 1932 }
1906 mark_buffer_dirty_inode(epos->bh, inode); 1933 mark_buffer_dirty_inode(epos->bh, inode);
1907 } 1934 } else
1908 else
1909 mark_inode_dirty(inode); 1935 mark_inode_dirty(inode);
1910 1936
1911 if (inc) 1937 if (inc)
@@ -1913,21 +1939,24 @@ int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
1913 return (elen >> 30); 1939 return (elen >> 30);
1914} 1940}
1915 1941
1916int8_t udf_next_aext(struct inode *inode, struct extent_position *epos, 1942int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
1917 kernel_lb_addr *eloc, uint32_t *elen, int inc) 1943 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1918{ 1944{
1919 int8_t etype; 1945 int8_t etype;
1920 1946
1921 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) == 1947 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
1922 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) 1948 (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
1923 {
1924 epos->block = *eloc; 1949 epos->block = *eloc;
1925 epos->offset = sizeof(struct allocExtDesc); 1950 epos->offset = sizeof(struct allocExtDesc);
1926 brelse(epos->bh); 1951 brelse(epos->bh);
1927 if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) 1952 if (!
1928 { 1953 (epos->bh =
1954 udf_tread(inode->i_sb,
1955 udf_get_lb_pblock(inode->i_sb, epos->block,
1956 0)))) {
1929 udf_debug("reading block %d failed!\n", 1957 udf_debug("reading block %d failed!\n",
1930 udf_get_lb_pblock(inode->i_sb, epos->block, 0)); 1958 udf_get_lb_pblock(inode->i_sb, epos->block,
1959 0));
1931 return -1; 1960 return -1;
1932 } 1961 }
1933 } 1962 }
@@ -1935,58 +1964,71 @@ int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
1935 return etype; 1964 return etype;
1936} 1965}
1937 1966
1938int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, 1967int8_t udf_current_aext(struct inode * inode, struct extent_position * epos,
1939 kernel_lb_addr *eloc, uint32_t *elen, int inc) 1968 kernel_lb_addr * eloc, uint32_t * elen, int inc)
1940{ 1969{
1941 int alen; 1970 int alen;
1942 int8_t etype; 1971 int8_t etype;
1943 uint8_t *ptr; 1972 uint8_t *ptr;
1944 1973
1945 if (!epos->bh) 1974 if (!epos->bh) {
1946 {
1947 if (!epos->offset) 1975 if (!epos->offset)
1948 epos->offset = udf_file_entry_alloc_offset(inode); 1976 epos->offset = udf_file_entry_alloc_offset(inode);
1949 ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode); 1977 ptr =
1950 alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode); 1978 UDF_I_DATA(inode) + epos->offset -
1951 } 1979 udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
1952 else 1980 alen =
1953 { 1981 udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
1982 } else {
1954 if (!epos->offset) 1983 if (!epos->offset)
1955 epos->offset = sizeof(struct allocExtDesc); 1984 epos->offset = sizeof(struct allocExtDesc);
1956 ptr = epos->bh->b_data + epos->offset; 1985 ptr = epos->bh->b_data + epos->offset;
1957 alen = sizeof(struct allocExtDesc) + le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs); 1986 alen =
1987 sizeof(struct allocExtDesc) +
1988 le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
1989 lengthAllocDescs);
1958 } 1990 }
1959 1991
1960 switch (UDF_I_ALLOCTYPE(inode)) 1992 switch (UDF_I_ALLOCTYPE(inode)) {
1961 { 1993 case ICBTAG_FLAG_AD_SHORT:
1962 case ICBTAG_FLAG_AD_SHORT:
1963 { 1994 {
1964 short_ad *sad; 1995 short_ad *sad;
1965 1996
1966 if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc))) 1997 if (!
1998 (sad =
1999 udf_get_fileshortad(ptr, alen, &epos->offset,
2000 inc)))
1967 return -1; 2001 return -1;
1968 2002
1969 etype = le32_to_cpu(sad->extLength) >> 30; 2003 etype = le32_to_cpu(sad->extLength) >> 30;
1970 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition); 2004 eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
1971 eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum; 2005 eloc->partitionReferenceNum =
1972 *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK; 2006 UDF_I_LOCATION(inode).partitionReferenceNum;
2007 *elen =
2008 le32_to_cpu(sad->
2009 extLength) & UDF_EXTENT_LENGTH_MASK;
1973 break; 2010 break;
1974 } 2011 }
1975 case ICBTAG_FLAG_AD_LONG: 2012 case ICBTAG_FLAG_AD_LONG:
1976 { 2013 {
1977 long_ad *lad; 2014 long_ad *lad;
1978 2015
1979 if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc))) 2016 if (!
2017 (lad =
2018 udf_get_filelongad(ptr, alen, &epos->offset, inc)))
1980 return -1; 2019 return -1;
1981 2020
1982 etype = le32_to_cpu(lad->extLength) >> 30; 2021 etype = le32_to_cpu(lad->extLength) >> 30;
1983 *eloc = lelb_to_cpu(lad->extLocation); 2022 *eloc = lelb_to_cpu(lad->extLocation);
1984 *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; 2023 *elen =
2024 le32_to_cpu(lad->
2025 extLength) & UDF_EXTENT_LENGTH_MASK;
1985 break; 2026 break;
1986 } 2027 }
1987 default: 2028 default:
1988 { 2029 {
1989 udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode)); 2030 udf_debug("alloc_type = %d unsupported\n",
2031 UDF_I_ALLOCTYPE(inode));
1990 return -1; 2032 return -1;
1991 } 2033 }
1992 } 2034 }
@@ -2005,8 +2047,7 @@ udf_insert_aext(struct inode *inode, struct extent_position epos,
2005 if (epos.bh) 2047 if (epos.bh)
2006 get_bh(epos.bh); 2048 get_bh(epos.bh);
2007 2049
2008 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) 2050 while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
2009 {
2010 udf_write_aext(inode, &epos, neloc, nelen, 1); 2051 udf_write_aext(inode, &epos, neloc, nelen, 1);
2011 2052
2012 neloc = oeloc; 2053 neloc = oeloc;
@@ -2017,16 +2058,15 @@ udf_insert_aext(struct inode *inode, struct extent_position epos,
2017 return (nelen >> 30); 2058 return (nelen >> 30);
2018} 2059}
2019 2060
2020int8_t udf_delete_aext(struct inode *inode, struct extent_position epos, 2061int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
2021 kernel_lb_addr eloc, uint32_t elen) 2062 kernel_lb_addr eloc, uint32_t elen)
2022{ 2063{
2023 struct extent_position oepos; 2064 struct extent_position oepos;
2024 int adsize; 2065 int adsize;
2025 int8_t etype; 2066 int8_t etype;
2026 struct allocExtDesc *aed; 2067 struct allocExtDesc *aed;
2027 2068
2028 if (epos.bh) 2069 if (epos.bh) {
2029 {
2030 get_bh(epos.bh); 2070 get_bh(epos.bh);
2031 get_bh(epos.bh); 2071 get_bh(epos.bh);
2032 } 2072 }
@@ -2042,11 +2082,9 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2042 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1) 2082 if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
2043 return -1; 2083 return -1;
2044 2084
2045 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) 2085 while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
2046 {
2047 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1); 2086 udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
2048 if (oepos.bh != epos.bh) 2087 if (oepos.bh != epos.bh) {
2049 {
2050 oepos.block = epos.block; 2088 oepos.block = epos.block;
2051 brelse(oepos.bh); 2089 brelse(oepos.bh);
2052 get_bh(epos.bh); 2090 get_bh(epos.bh);
@@ -2057,45 +2095,44 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2057 memset(&eloc, 0x00, sizeof(kernel_lb_addr)); 2095 memset(&eloc, 0x00, sizeof(kernel_lb_addr));
2058 elen = 0; 2096 elen = 0;
2059 2097
2060 if (epos.bh != oepos.bh) 2098 if (epos.bh != oepos.bh) {
2061 {
2062 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1); 2099 udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
2063 udf_write_aext(inode, &oepos, eloc, elen, 1); 2100 udf_write_aext(inode, &oepos, eloc, elen, 1);
2064 udf_write_aext(inode, &oepos, eloc, elen, 1); 2101 udf_write_aext(inode, &oepos, eloc, elen, 1);
2065 if (!oepos.bh) 2102 if (!oepos.bh) {
2066 {
2067 UDF_I_LENALLOC(inode) -= (adsize * 2); 2103 UDF_I_LENALLOC(inode) -= (adsize * 2);
2068 mark_inode_dirty(inode); 2104 mark_inode_dirty(inode);
2069 } 2105 } else {
2070 else
2071 {
2072 aed = (struct allocExtDesc *)oepos.bh->b_data; 2106 aed = (struct allocExtDesc *)oepos.bh->b_data;
2073 aed->lengthAllocDescs = 2107 aed->lengthAllocDescs =
2074 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2*adsize)); 2108 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2075 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 2109 (2 * adsize));
2076 udf_update_tag(oepos.bh->b_data, oepos.offset - (2*adsize)); 2110 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
2111 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2112 udf_update_tag(oepos.bh->b_data,
2113 oepos.offset - (2 * adsize));
2077 else 2114 else
2078 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); 2115 udf_update_tag(oepos.bh->b_data,
2116 sizeof(struct allocExtDesc));
2079 mark_buffer_dirty_inode(oepos.bh, inode); 2117 mark_buffer_dirty_inode(oepos.bh, inode);
2080 } 2118 }
2081 } 2119 } else {
2082 else
2083 {
2084 udf_write_aext(inode, &oepos, eloc, elen, 1); 2120 udf_write_aext(inode, &oepos, eloc, elen, 1);
2085 if (!oepos.bh) 2121 if (!oepos.bh) {
2086 {
2087 UDF_I_LENALLOC(inode) -= adsize; 2122 UDF_I_LENALLOC(inode) -= adsize;
2088 mark_inode_dirty(inode); 2123 mark_inode_dirty(inode);
2089 } 2124 } else {
2090 else
2091 {
2092 aed = (struct allocExtDesc *)oepos.bh->b_data; 2125 aed = (struct allocExtDesc *)oepos.bh->b_data;
2093 aed->lengthAllocDescs = 2126 aed->lengthAllocDescs =
2094 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize); 2127 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
2095 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201) 2128 adsize);
2096 udf_update_tag(oepos.bh->b_data, epos.offset - adsize); 2129 if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT)
2130 || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
2131 udf_update_tag(oepos.bh->b_data,
2132 epos.offset - adsize);
2097 else 2133 else
2098 udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc)); 2134 udf_update_tag(oepos.bh->b_data,
2135 sizeof(struct allocExtDesc));
2099 mark_buffer_dirty_inode(oepos.bh, inode); 2136 mark_buffer_dirty_inode(oepos.bh, inode);
2100 } 2137 }
2101 } 2138 }
@@ -2105,14 +2142,15 @@ int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
2105 return (elen >> 30); 2142 return (elen >> 30);
2106} 2143}
2107 2144
2108int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *pos, 2145int8_t inode_bmap(struct inode * inode, sector_t block,
2109 kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset) 2146 struct extent_position * pos, kernel_lb_addr * eloc,
2147 uint32_t * elen, sector_t * offset)
2110{ 2148{
2111 loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits; 2149 loff_t lbcount = 0, bcount =
2150 (loff_t) block << inode->i_sb->s_blocksize_bits;
2112 int8_t etype; 2151 int8_t etype;
2113 2152
2114 if (block < 0) 2153 if (block < 0) {
2115 {
2116 printk(KERN_ERR "udf: inode_bmap: block < 0\n"); 2154 printk(KERN_ERR "udf: inode_bmap: block < 0\n");
2117 return -1; 2155 return -1;
2118 } 2156 }
@@ -2122,11 +2160,10 @@ int8_t inode_bmap(struct inode *inode, sector_t block, struct extent_position *p
2122 pos->bh = NULL; 2160 pos->bh = NULL;
2123 *elen = 0; 2161 *elen = 0;
2124 2162
2125 do 2163 do {
2126 { 2164 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) {
2127 if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) 2165 *offset =
2128 { 2166 (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2129 *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
2130 UDF_I_LENEXTENTS(inode) = lbcount; 2167 UDF_I_LENEXTENTS(inode) = lbcount;
2131 return -1; 2168 return -1;
2132 } 2169 }
@@ -2143,12 +2180,13 @@ long udf_block_map(struct inode *inode, sector_t block)
2143 kernel_lb_addr eloc; 2180 kernel_lb_addr eloc;
2144 uint32_t elen; 2181 uint32_t elen;
2145 sector_t offset; 2182 sector_t offset;
2146 struct extent_position epos = { NULL, 0, { 0, 0}}; 2183 struct extent_position epos = { NULL, 0, {0, 0} };
2147 int ret; 2184 int ret;
2148 2185
2149 lock_kernel(); 2186 lock_kernel();
2150 2187
2151 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) 2188 if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
2189 (EXT_RECORDED_ALLOCATED >> 30))
2152 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset); 2190 ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
2153 else 2191 else
2154 ret = 0; 2192 ret = 0;