hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/fs/udf/inode.c
....@@ -45,20 +45,27 @@
4545
4646 #define EXTENT_MERGE_SIZE 5
4747
48
+#define FE_MAPPED_PERMS (FE_PERM_U_READ | FE_PERM_U_WRITE | FE_PERM_U_EXEC | \
49
+ FE_PERM_G_READ | FE_PERM_G_WRITE | FE_PERM_G_EXEC | \
50
+ FE_PERM_O_READ | FE_PERM_O_WRITE | FE_PERM_O_EXEC)
51
+
52
+#define FE_DELETE_PERMS (FE_PERM_U_DELETE | FE_PERM_G_DELETE | \
53
+ FE_PERM_O_DELETE)
54
+
4855 static umode_t udf_convert_permissions(struct fileEntry *);
4956 static int udf_update_inode(struct inode *, int);
5057 static int udf_sync_inode(struct inode *inode);
5158 static int udf_alloc_i_data(struct inode *inode, size_t size);
5259 static sector_t inode_getblk(struct inode *, sector_t, int *, int *);
53
-static int8_t udf_insert_aext(struct inode *, struct extent_position,
54
- struct kernel_lb_addr, uint32_t);
60
+static int udf_insert_aext(struct inode *, struct extent_position,
61
+ struct kernel_lb_addr, uint32_t);
5562 static void udf_split_extents(struct inode *, int *, int, udf_pblk_t,
5663 struct kernel_long_ad *, int *);
5764 static void udf_prealloc_extents(struct inode *, int, int,
5865 struct kernel_long_ad *, int *);
5966 static void udf_merge_extents(struct inode *, struct kernel_long_ad *, int *);
60
-static void udf_update_extents(struct inode *, struct kernel_long_ad *, int,
61
- int, struct extent_position *);
67
+static int udf_update_extents(struct inode *, struct kernel_long_ad *, int,
68
+ int, struct extent_position *);
6269 static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
6370
6471 static void __udf_clear_extent_cache(struct inode *inode)
....@@ -150,8 +157,8 @@
150157 truncate_inode_pages_final(&inode->i_data);
151158 invalidate_inode_buffers(inode);
152159 clear_inode(inode);
153
- kfree(iinfo->i_ext.i_data);
154
- iinfo->i_ext.i_data = NULL;
160
+ kfree(iinfo->i_data);
161
+ iinfo->i_data = NULL;
155162 udf_clear_extent_cache(inode);
156163 if (want_delete) {
157164 udf_free_inode(inode);
....@@ -191,10 +198,9 @@
191198 return mpage_readpage(page, udf_get_block);
192199 }
193200
194
-static int udf_readpages(struct file *file, struct address_space *mapping,
195
- struct list_head *pages, unsigned nr_pages)
201
+static void udf_readahead(struct readahead_control *rac)
196202 {
197
- return mpage_readpages(mapping, pages, nr_pages, udf_get_block);
203
+ mpage_readahead(rac, udf_get_block);
198204 }
199205
200206 static int udf_write_begin(struct file *file, struct address_space *mapping,
....@@ -230,7 +236,7 @@
230236
231237 const struct address_space_operations udf_aops = {
232238 .readpage = udf_readpage,
233
- .readpages = udf_readpages,
239
+ .readahead = udf_readahead,
234240 .writepage = udf_writepage,
235241 .writepages = udf_writepages,
236242 .write_begin = udf_write_begin,
....@@ -278,14 +284,14 @@
278284 kaddr = kmap_atomic(page);
279285 memset(kaddr + iinfo->i_lenAlloc, 0x00,
280286 PAGE_SIZE - iinfo->i_lenAlloc);
281
- memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr,
287
+ memcpy(kaddr, iinfo->i_data + iinfo->i_lenEAttr,
282288 iinfo->i_lenAlloc);
283289 flush_dcache_page(page);
284290 SetPageUptodate(page);
285291 kunmap_atomic(kaddr);
286292 }
287293 down_write(&iinfo->i_data_sem);
288
- memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0x00,
294
+ memset(iinfo->i_data + iinfo->i_lenEAttr, 0x00,
289295 iinfo->i_lenAlloc);
290296 iinfo->i_lenAlloc = 0;
291297 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
....@@ -303,8 +309,7 @@
303309 lock_page(page);
304310 down_write(&iinfo->i_data_sem);
305311 kaddr = kmap_atomic(page);
306
- memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr,
307
- inode->i_size);
312
+ memcpy(iinfo->i_data + iinfo->i_lenEAttr, kaddr, inode->i_size);
308313 kunmap_atomic(kaddr);
309314 unlock_page(page);
310315 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
....@@ -392,8 +397,7 @@
392397 }
393398 mark_buffer_dirty_inode(dbh, inode);
394399
395
- memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0,
396
- iinfo->i_lenAlloc);
400
+ memset(iinfo->i_data + iinfo->i_lenEAttr, 0, iinfo->i_lenAlloc);
397401 iinfo->i_lenAlloc = 0;
398402 eloc.logicalBlockNum = *block;
399403 eloc.partitionReferenceNum =
....@@ -434,6 +438,12 @@
434438 iinfo->i_next_alloc_goal++;
435439 }
436440
441
+ /*
442
+ * Block beyond EOF and prealloc extents? Just discard preallocation
443
+ * as it is not useful and complicates things.
444
+ */
445
+ if (((loff_t)block) << inode->i_blkbits >= iinfo->i_lenExtents)
446
+ udf_discard_prealloc(inode);
437447 udf_clear_extent_cache(inode);
438448 phys = inode_getblk(inode, block, &err, &new);
439449 if (!phys)
....@@ -483,8 +493,6 @@
483493 uint32_t add;
484494 int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
485495 struct super_block *sb = inode->i_sb;
486
- struct kernel_lb_addr prealloc_loc = {};
487
- uint32_t prealloc_len = 0;
488496 struct udf_inode_info *iinfo;
489497 int err;
490498
....@@ -505,19 +513,6 @@
505513 ~(sb->s_blocksize - 1);
506514 }
507515
508
- /* Last extent are just preallocated blocks? */
509
- if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
510
- EXT_NOT_RECORDED_ALLOCATED) {
511
- /* Save the extent so that we can reattach it to the end */
512
- prealloc_loc = last_ext->extLocation;
513
- prealloc_len = last_ext->extLength;
514
- /* Mark the extent as a hole */
515
- last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
516
- (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
517
- last_ext->extLocation.logicalBlockNum = 0;
518
- last_ext->extLocation.partitionReferenceNum = 0;
519
- }
520
-
521516 /* Can we merge with the previous extent? */
522517 if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
523518 EXT_NOT_RECORDED_NOT_ALLOCATED) {
....@@ -530,8 +525,10 @@
530525 }
531526
532527 if (fake) {
533
- udf_add_aext(inode, last_pos, &last_ext->extLocation,
534
- last_ext->extLength, 1);
528
+ err = udf_add_aext(inode, last_pos, &last_ext->extLocation,
529
+ last_ext->extLength, 1);
530
+ if (err < 0)
531
+ goto out_err;
535532 count++;
536533 } else {
537534 struct kernel_lb_addr tmploc;
....@@ -545,7 +542,7 @@
545542 * more extents, we may need to enter possible following
546543 * empty indirect extent.
547544 */
548
- if (new_block_bytes || prealloc_len)
545
+ if (new_block_bytes)
549546 udf_next_aext(inode, last_pos, &tmploc, &tmplen, 0);
550547 }
551548
....@@ -565,7 +562,7 @@
565562 err = udf_add_aext(inode, last_pos, &last_ext->extLocation,
566563 last_ext->extLength, 1);
567564 if (err)
568
- return err;
565
+ goto out_err;
569566 count++;
570567 }
571568 if (new_block_bytes) {
....@@ -574,22 +571,11 @@
574571 err = udf_add_aext(inode, last_pos, &last_ext->extLocation,
575572 last_ext->extLength, 1);
576573 if (err)
577
- return err;
574
+ goto out_err;
578575 count++;
579576 }
580577
581578 out:
582
- /* Do we have some preallocated blocks saved? */
583
- if (prealloc_len) {
584
- err = udf_add_aext(inode, last_pos, &prealloc_loc,
585
- prealloc_len, 1);
586
- if (err)
587
- return err;
588
- last_ext->extLocation = prealloc_loc;
589
- last_ext->extLength = prealloc_len;
590
- count++;
591
- }
592
-
593579 /* last_pos should point to the last written extent... */
594580 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
595581 last_pos->offset -= sizeof(struct short_ad);
....@@ -599,19 +585,28 @@
599585 return -EIO;
600586
601587 return count;
588
+out_err:
589
+ /* Remove extents we've created so far */
590
+ udf_clear_extent_cache(inode);
591
+ udf_truncate_extents(inode);
592
+ return err;
602593 }
603594
604595 /* Extend the final block of the file to final_block_len bytes */
605596 static void udf_do_extend_final_block(struct inode *inode,
606597 struct extent_position *last_pos,
607598 struct kernel_long_ad *last_ext,
608
- uint32_t final_block_len)
599
+ uint32_t new_elen)
609600 {
610
- struct super_block *sb = inode->i_sb;
611601 uint32_t added_bytes;
612602
613
- added_bytes = final_block_len -
614
- (last_ext->extLength & (sb->s_blocksize - 1));
603
+ /*
604
+ * Extent already large enough? It may be already rounded up to block
605
+ * size...
606
+ */
607
+ if (new_elen <= (last_ext->extLength & UDF_EXTENT_LENGTH_MASK))
608
+ return;
609
+ added_bytes = new_elen - (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
615610 last_ext->extLength += added_bytes;
616611 UDF_I(inode)->i_lenExtents += added_bytes;
617612
....@@ -628,12 +623,12 @@
628623 int8_t etype;
629624 struct super_block *sb = inode->i_sb;
630625 sector_t first_block = newsize >> sb->s_blocksize_bits, offset;
631
- unsigned long partial_final_block;
626
+ loff_t new_elen;
632627 int adsize;
633628 struct udf_inode_info *iinfo = UDF_I(inode);
634629 struct kernel_long_ad extent;
635630 int err = 0;
636
- int within_final_block;
631
+ bool within_last_ext;
637632
638633 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
639634 adsize = sizeof(struct short_ad);
....@@ -642,8 +637,17 @@
642637 else
643638 BUG();
644639
640
+ /*
641
+ * When creating hole in file, just don't bother with preserving
642
+ * preallocation. It likely won't be very useful anyway.
643
+ */
644
+ udf_discard_prealloc(inode);
645
+
645646 etype = inode_bmap(inode, first_block, &epos, &eloc, &elen, &offset);
646
- within_final_block = (etype != -1);
647
+ within_last_ext = (etype != -1);
648
+ /* We don't expect extents past EOF... */
649
+ WARN_ON_ONCE(within_last_ext &&
650
+ elen > ((loff_t)offset + 1) << inode->i_blkbits);
647651
648652 if ((!epos.bh && epos.offset == udf_file_entry_alloc_offset(inode)) ||
649653 (epos.bh && epos.offset == sizeof(struct allocExtDesc))) {
....@@ -659,19 +663,17 @@
659663 extent.extLength |= etype << 30;
660664 }
661665
662
- partial_final_block = newsize & (sb->s_blocksize - 1);
666
+ new_elen = ((loff_t)offset << inode->i_blkbits) |
667
+ (newsize & (sb->s_blocksize - 1));
663668
664669 /* File has extent covering the new size (could happen when extending
665670 * inside a block)?
666671 */
667
- if (within_final_block) {
672
+ if (within_last_ext) {
668673 /* Extending file within the last file block */
669
- udf_do_extend_final_block(inode, &epos, &extent,
670
- partial_final_block);
674
+ udf_do_extend_final_block(inode, &epos, &extent, new_elen);
671675 } else {
672
- loff_t add = ((loff_t)offset << sb->s_blocksize_bits) |
673
- partial_final_block;
674
- err = udf_do_extend_file(inode, &epos, &extent, add);
676
+ err = udf_do_extend_file(inode, &epos, &extent, new_elen);
675677 }
676678
677679 if (err < 0)
....@@ -693,7 +695,7 @@
693695 struct kernel_lb_addr eloc, tmpeloc;
694696 int c = 1;
695697 loff_t lbcount = 0, b_off = 0;
696
- udf_pblk_t newblocknum, newblock;
698
+ udf_pblk_t newblocknum, newblock = 0;
697699 sector_t offset = 0;
698700 int8_t etype;
699701 struct udf_inode_info *iinfo = UDF_I(inode);
....@@ -772,10 +774,11 @@
772774 goto out_free;
773775 }
774776
775
- /* Are we beyond EOF? */
777
+ /* Are we beyond EOF and preallocated extent? */
776778 if (etype == -1) {
777779 int ret;
778780 loff_t hole_len;
781
+
779782 isBeyondEOF = true;
780783 if (count) {
781784 if (c)
....@@ -795,25 +798,22 @@
795798 ret = udf_do_extend_file(inode, &prev_epos, laarr, hole_len);
796799 if (ret < 0) {
797800 *err = ret;
798
- newblock = 0;
799801 goto out_free;
800802 }
801803 c = 0;
802804 offset = 0;
803805 count += ret;
804
- /* We are not covered by a preallocated extent? */
805
- if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
806
- EXT_NOT_RECORDED_ALLOCATED) {
807
- /* Is there any real extent? - otherwise we overwrite
808
- * the fake one... */
809
- if (count)
810
- c = !c;
811
- laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
812
- inode->i_sb->s_blocksize;
813
- memset(&laarr[c].extLocation, 0x00,
814
- sizeof(struct kernel_lb_addr));
815
- count++;
816
- }
806
+ /*
807
+ * Is there any real extent? - otherwise we overwrite the fake
808
+ * one...
809
+ */
810
+ if (count)
811
+ c = !c;
812
+ laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
813
+ inode->i_sb->s_blocksize;
814
+ memset(&laarr[c].extLocation, 0x00,
815
+ sizeof(struct kernel_lb_addr));
816
+ count++;
817817 endnum = c + 1;
818818 lastblock = 1;
819819 } else {
....@@ -860,7 +860,6 @@
860860 goal, err);
861861 if (!newblocknum) {
862862 *err = -ENOSPC;
863
- newblock = 0;
864863 goto out_free;
865864 }
866865 if (isBeyondEOF)
....@@ -886,7 +885,9 @@
886885 /* write back the new extents, inserting new extents if the new number
887886 * of extents is greater than the old number, and deleting extents if
888887 * the new number of extents is less than the old number */
889
- udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
888
+ *err = udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
889
+ if (*err < 0)
890
+ goto out_free;
890891
891892 newblock = udf_get_pblock(inode->i_sb, newblocknum,
892893 iinfo->i_location.partitionReferenceNum, 0);
....@@ -1090,23 +1091,8 @@
10901091 blocksize - 1) >> blocksize_bits)))) {
10911092
10921093 if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
1093
- (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
1094
- blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
1095
- lip1->extLength = (lip1->extLength -
1096
- (li->extLength &
1097
- UDF_EXTENT_LENGTH_MASK) +
1098
- UDF_EXTENT_LENGTH_MASK) &
1099
- ~(blocksize - 1);
1100
- li->extLength = (li->extLength &
1101
- UDF_EXTENT_FLAG_MASK) +
1102
- (UDF_EXTENT_LENGTH_MASK + 1) -
1103
- blocksize;
1104
- lip1->extLocation.logicalBlockNum =
1105
- li->extLocation.logicalBlockNum +
1106
- ((li->extLength &
1107
- UDF_EXTENT_LENGTH_MASK) >>
1108
- blocksize_bits);
1109
- } else {
1094
+ (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
1095
+ blocksize - 1) <= UDF_EXTENT_LENGTH_MASK) {
11101096 li->extLength = lip1->extLength +
11111097 (((li->extLength &
11121098 UDF_EXTENT_LENGTH_MASK) +
....@@ -1169,21 +1155,30 @@
11691155 }
11701156 }
11711157
1172
-static void udf_update_extents(struct inode *inode, struct kernel_long_ad *laarr,
1173
- int startnum, int endnum,
1174
- struct extent_position *epos)
1158
+static int udf_update_extents(struct inode *inode, struct kernel_long_ad *laarr,
1159
+ int startnum, int endnum,
1160
+ struct extent_position *epos)
11751161 {
11761162 int start = 0, i;
11771163 struct kernel_lb_addr tmploc;
11781164 uint32_t tmplen;
1165
+ int err;
11791166
11801167 if (startnum > endnum) {
11811168 for (i = 0; i < (startnum - endnum); i++)
11821169 udf_delete_aext(inode, *epos);
11831170 } else if (startnum < endnum) {
11841171 for (i = 0; i < (endnum - startnum); i++) {
1185
- udf_insert_aext(inode, *epos, laarr[i].extLocation,
1186
- laarr[i].extLength);
1172
+ err = udf_insert_aext(inode, *epos,
1173
+ laarr[i].extLocation,
1174
+ laarr[i].extLength);
1175
+ /*
1176
+ * If we fail here, we are likely corrupting the extent
1177
+ * list and leaking blocks. At least stop early to
1178
+ * limit the damage.
1179
+ */
1180
+ if (err < 0)
1181
+ return err;
11871182 udf_next_aext(inode, epos, &laarr[i].extLocation,
11881183 &laarr[i].extLength, 1);
11891184 start++;
....@@ -1195,6 +1190,7 @@
11951190 udf_write_aext(inode, epos, &laarr[i].extLocation,
11961191 laarr[i].extLength, 1);
11971192 }
1193
+ return 0;
11981194 }
11991195
12001196 struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block,
....@@ -1259,7 +1255,7 @@
12591255 if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
12601256 down_write(&iinfo->i_data_sem);
12611257 udf_clear_extent_cache(inode);
1262
- memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr + newsize,
1258
+ memset(iinfo->i_data + iinfo->i_lenEAttr + newsize,
12631259 0x00, bsize - newsize -
12641260 udf_file_entry_alloc_offset(inode));
12651261 iinfo->i_lenAlloc = newsize;
....@@ -1274,8 +1270,10 @@
12741270 truncate_setsize(inode, newsize);
12751271 down_write(&iinfo->i_data_sem);
12761272 udf_clear_extent_cache(inode);
1277
- udf_truncate_extents(inode);
1273
+ err = udf_truncate_extents(inode);
12781274 up_write(&iinfo->i_data_sem);
1275
+ if (err)
1276
+ return err;
12791277 }
12801278 update_time:
12811279 inode->i_mtime = inode->i_ctime = current_time(inode);
....@@ -1395,6 +1393,7 @@
13951393 ret = -EIO;
13961394 goto out;
13971395 }
1396
+ iinfo->i_hidden = hidden_inode;
13981397 iinfo->i_unique = 0;
13991398 iinfo->i_lenEAttr = 0;
14001399 iinfo->i_lenExtents = 0;
....@@ -1408,7 +1407,7 @@
14081407 sizeof(struct extendedFileEntry));
14091408 if (ret)
14101409 goto out;
1411
- memcpy(iinfo->i_ext.i_data,
1410
+ memcpy(iinfo->i_data,
14121411 bh->b_data + sizeof(struct extendedFileEntry),
14131412 bs - sizeof(struct extendedFileEntry));
14141413 } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) {
....@@ -1417,7 +1416,7 @@
14171416 ret = udf_alloc_i_data(inode, bs - sizeof(struct fileEntry));
14181417 if (ret)
14191418 goto out;
1420
- memcpy(iinfo->i_ext.i_data,
1419
+ memcpy(iinfo->i_data,
14211420 bh->b_data + sizeof(struct fileEntry),
14221421 bs - sizeof(struct fileEntry));
14231422 } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
....@@ -1430,7 +1429,7 @@
14301429 sizeof(struct unallocSpaceEntry));
14311430 if (ret)
14321431 goto out;
1433
- memcpy(iinfo->i_ext.i_data,
1432
+ memcpy(iinfo->i_data,
14341433 bh->b_data + sizeof(struct unallocSpaceEntry),
14351434 bs - sizeof(struct unallocSpaceEntry));
14361435 return 0;
....@@ -1461,6 +1460,8 @@
14611460 else
14621461 inode->i_mode = udf_convert_permissions(fe);
14631462 inode->i_mode &= ~sbi->s_umask;
1463
+ iinfo->i_extraPerms = le32_to_cpu(fe->permissions) & ~FE_MAPPED_PERMS;
1464
+
14641465 read_unlock(&sbi->s_cred_lock);
14651466
14661467 link_count = le16_to_cpu(fe->fileLinkCount);
....@@ -1488,6 +1489,8 @@
14881489 iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
14891490 iinfo->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs);
14901491 iinfo->i_checkpoint = le32_to_cpu(fe->checkpoint);
1492
+ iinfo->i_streamdir = 0;
1493
+ iinfo->i_lenStreams = 0;
14911494 } else {
14921495 inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
14931496 (inode->i_sb->s_blocksize_bits - 9);
....@@ -1501,6 +1504,16 @@
15011504 iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
15021505 iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs);
15031506 iinfo->i_checkpoint = le32_to_cpu(efe->checkpoint);
1507
+
1508
+ /* Named streams */
1509
+ iinfo->i_streamdir = (efe->streamDirectoryICB.extLength != 0);
1510
+ iinfo->i_locStreamdir =
1511
+ lelb_to_cpu(efe->streamDirectoryICB.extLocation);
1512
+ iinfo->i_lenStreams = le64_to_cpu(efe->objectSize);
1513
+ if (iinfo->i_lenStreams >= inode->i_size)
1514
+ iinfo->i_lenStreams -= inode->i_size;
1515
+ else
1516
+ iinfo->i_lenStreams = 0;
15041517 }
15051518 inode->i_generation = iinfo->i_unique;
15061519
....@@ -1597,8 +1610,8 @@
15971610 static int udf_alloc_i_data(struct inode *inode, size_t size)
15981611 {
15991612 struct udf_inode_info *iinfo = UDF_I(inode);
1600
- iinfo->i_ext.i_data = kmalloc(size, GFP_KERNEL);
1601
- if (!iinfo->i_ext.i_data)
1613
+ iinfo->i_data = kmalloc(size, GFP_KERNEL);
1614
+ if (!iinfo->i_data)
16021615 return -ENOMEM;
16031616 return 0;
16041617 }
....@@ -1620,6 +1633,23 @@
16201633 ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
16211634
16221635 return mode;
1636
+}
1637
+
1638
+void udf_update_extra_perms(struct inode *inode, umode_t mode)
1639
+{
1640
+ struct udf_inode_info *iinfo = UDF_I(inode);
1641
+
1642
+ /*
1643
+ * UDF 2.01 sec. 3.3.3.3 Note 2:
1644
+ * In Unix, delete permission tracks write
1645
+ */
1646
+ iinfo->i_extraPerms &= ~FE_DELETE_PERMS;
1647
+ if (mode & 0200)
1648
+ iinfo->i_extraPerms |= FE_PERM_U_DELETE;
1649
+ if (mode & 0020)
1650
+ iinfo->i_extraPerms |= FE_PERM_G_DELETE;
1651
+ if (mode & 0002)
1652
+ iinfo->i_extraPerms |= FE_PERM_O_DELETE;
16231653 }
16241654
16251655 int udf_write_inode(struct inode *inode, struct writeback_control *wbc)
....@@ -1672,7 +1702,7 @@
16721702
16731703 use->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
16741704 memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
1675
- iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
1705
+ iinfo->i_data, inode->i_sb->s_blocksize -
16761706 sizeof(struct unallocSpaceEntry));
16771707 use->descTag.tagIdent = cpu_to_le16(TAG_IDENT_USE);
16781708 crclen = sizeof(struct unallocSpaceEntry);
....@@ -1694,16 +1724,17 @@
16941724 ((inode->i_mode & 0070) << 2) |
16951725 ((inode->i_mode & 0700) << 4);
16961726
1697
- udfperms |= (le32_to_cpu(fe->permissions) &
1698
- (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
1699
- FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
1700
- FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
1727
+ udfperms |= iinfo->i_extraPerms;
17011728 fe->permissions = cpu_to_le32(udfperms);
17021729
17031730 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 0)
17041731 fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
1705
- else
1706
- fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1732
+ else {
1733
+ if (iinfo->i_hidden)
1734
+ fe->fileLinkCount = cpu_to_le16(0);
1735
+ else
1736
+ fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
1737
+ }
17071738
17081739 fe->informationLength = cpu_to_le64(inode->i_size);
17091740
....@@ -1741,7 +1772,7 @@
17411772
17421773 if (iinfo->i_efe == 0) {
17431774 memcpy(bh->b_data + sizeof(struct fileEntry),
1744
- iinfo->i_ext.i_data,
1775
+ iinfo->i_data,
17451776 inode->i_sb->s_blocksize - sizeof(struct fileEntry));
17461777 fe->logicalBlocksRecorded = cpu_to_le64(lb_recorded);
17471778
....@@ -1760,11 +1791,21 @@
17601791 crclen = sizeof(struct fileEntry);
17611792 } else {
17621793 memcpy(bh->b_data + sizeof(struct extendedFileEntry),
1763
- iinfo->i_ext.i_data,
1794
+ iinfo->i_data,
17641795 inode->i_sb->s_blocksize -
17651796 sizeof(struct extendedFileEntry));
1766
- efe->objectSize = cpu_to_le64(inode->i_size);
1797
+ efe->objectSize =
1798
+ cpu_to_le64(inode->i_size + iinfo->i_lenStreams);
17671799 efe->logicalBlocksRecorded = cpu_to_le64(lb_recorded);
1800
+
1801
+ if (iinfo->i_streamdir) {
1802
+ struct long_ad *icb_lad = &efe->streamDirectoryICB;
1803
+
1804
+ icb_lad->extLocation =
1805
+ cpu_to_lelb(iinfo->i_locStreamdir);
1806
+ icb_lad->extLength =
1807
+ cpu_to_le32(inode->i_sb->s_blocksize);
1808
+ }
17681809
17691810 udf_adjust_time(iinfo, inode->i_atime);
17701811 udf_adjust_time(iinfo, inode->i_mtime);
....@@ -1864,8 +1905,13 @@
18641905 if (!inode)
18651906 return ERR_PTR(-ENOMEM);
18661907
1867
- if (!(inode->i_state & I_NEW))
1908
+ if (!(inode->i_state & I_NEW)) {
1909
+ if (UDF_I(inode)->i_hidden != hidden_inode) {
1910
+ iput(inode);
1911
+ return ERR_PTR(-EFSCORRUPTED);
1912
+ }
18681913 return inode;
1914
+ }
18691915
18701916 memcpy(&UDF_I(inode)->i_location, ino, sizeof(struct kernel_lb_addr));
18711917 err = udf_read_inode(inode, hidden_inode);
....@@ -1939,10 +1985,10 @@
19391985
19401986 __udf_add_aext(inode, &nepos, &cp_loc, cp_len, 1);
19411987 udf_write_aext(inode, epos, &nepos.block,
1942
- sb->s_blocksize | EXT_NEXT_EXTENT_ALLOCDECS, 0);
1988
+ sb->s_blocksize | EXT_NEXT_EXTENT_ALLOCDESCS, 0);
19431989 } else {
19441990 __udf_add_aext(inode, epos, &nepos.block,
1945
- sb->s_blocksize | EXT_NEXT_EXTENT_ALLOCDECS, 0);
1991
+ sb->s_blocksize | EXT_NEXT_EXTENT_ALLOCDESCS, 0);
19461992 }
19471993
19481994 brelse(epos->bh);
....@@ -2046,7 +2092,7 @@
20462092 struct udf_inode_info *iinfo = UDF_I(inode);
20472093
20482094 if (!epos->bh)
2049
- ptr = iinfo->i_ext.i_data + epos->offset -
2095
+ ptr = iinfo->i_data + epos->offset -
20502096 udf_file_entry_alloc_offset(inode) +
20512097 iinfo->i_lenEAttr;
20522098 else
....@@ -2101,7 +2147,7 @@
21012147 unsigned int indirections = 0;
21022148
21032149 while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
2104
- (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
2150
+ (EXT_NEXT_EXTENT_ALLOCDESCS >> 30)) {
21052151 udf_pblk_t block;
21062152
21072153 if (++indirections > UDF_MAX_INDIR_EXTS) {
....@@ -2138,7 +2184,7 @@
21382184 if (!epos->bh) {
21392185 if (!epos->offset)
21402186 epos->offset = udf_file_entry_alloc_offset(inode);
2141
- ptr = iinfo->i_ext.i_data + epos->offset -
2187
+ ptr = iinfo->i_data + epos->offset -
21422188 udf_file_entry_alloc_offset(inode) +
21432189 iinfo->i_lenEAttr;
21442190 alen = udf_file_entry_alloc_offset(inode) +
....@@ -2179,12 +2225,13 @@
21792225 return etype;
21802226 }
21812227
2182
-static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
2183
- struct kernel_lb_addr neloc, uint32_t nelen)
2228
+static int udf_insert_aext(struct inode *inode, struct extent_position epos,
2229
+ struct kernel_lb_addr neloc, uint32_t nelen)
21842230 {
21852231 struct kernel_lb_addr oeloc;
21862232 uint32_t oelen;
21872233 int8_t etype;
2234
+ int err;
21882235
21892236 if (epos.bh)
21902237 get_bh(epos.bh);
....@@ -2194,10 +2241,10 @@
21942241 neloc = oeloc;
21952242 nelen = (etype << 30) | oelen;
21962243 }
2197
- udf_add_aext(inode, &epos, &neloc, nelen, 1);
2244
+ err = udf_add_aext(inode, &epos, &neloc, nelen, 1);
21982245 brelse(epos.bh);
21992246
2200
- return (nelen >> 30);
2247
+ return err;
22012248 }
22022249
22032250 int8_t udf_delete_aext(struct inode *inode, struct extent_position epos)