Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NTFS: - Set the ntfs_inode->allocated_size to the real allocated size in the mft record for resident attributes (fs/ntfs/inode.c). - Small readability cleanup to use "a" instead of "ctx->attr" everywhere (fs/ntfs/inode.c).

Signed-off-by: Anton Altaparmakov <aia21@cantab.net>

+174 -174
+4
fs/ntfs/ChangeLog
··· 76 76 warning in the do_div() call on sparc32. Thanks to Meelis Roos for 77 77 the report and analysis of the warning. 78 78 - Fix a nasty runlist merge bug when merging two holes. 79 + - Set the ntfs_inode->allocated_size to the real allocated size in the 80 + mft record for resident attributes (fs/ntfs/inode.c). 81 + - Small readability cleanup to use "a" instead of "ctx->attr" 82 + everywhere (fs/ntfs/inode.c). 79 83 80 84 2.1.22 - Many bug and race fixes and error handling improvements. 81 85
+170 -174
fs/ntfs/inode.c
··· 525 525 ntfs_volume *vol = NTFS_SB(vi->i_sb); 526 526 ntfs_inode *ni; 527 527 MFT_RECORD *m; 528 + ATTR_RECORD *a; 528 529 STANDARD_INFORMATION *si; 529 530 ntfs_attr_search_ctx *ctx; 530 531 int err = 0; ··· 634 633 } 635 634 goto unm_err_out; 636 635 } 636 + a = ctx->attr; 637 637 /* Get the standard information attribute value. */ 638 - si = (STANDARD_INFORMATION*)((char*)ctx->attr + 639 - le16_to_cpu(ctx->attr->data.resident.value_offset)); 638 + si = (STANDARD_INFORMATION*)((u8*)a + 639 + le16_to_cpu(a->data.resident.value_offset)); 640 640 641 641 /* Transfer information from the standard information into vi. */ 642 642 /* ··· 676 674 goto skip_attr_list_load; 677 675 ntfs_debug("Attribute list found in inode 0x%lx.", vi->i_ino); 678 676 NInoSetAttrList(ni); 679 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED || 680 - ctx->attr->flags & ATTR_COMPRESSION_MASK || 681 - ctx->attr->flags & ATTR_IS_SPARSE) { 677 + a = ctx->attr; 678 + if (a->flags & ATTR_IS_ENCRYPTED || 679 + a->flags & ATTR_COMPRESSION_MASK || 680 + a->flags & ATTR_IS_SPARSE) { 682 681 ntfs_error(vi->i_sb, "Attribute list attribute is " 683 682 "compressed/encrypted/sparse."); 684 683 goto unm_err_out; 685 684 } 686 685 /* Now allocate memory for the attribute list. */ 687 - ni->attr_list_size = (u32)ntfs_attr_size(ctx->attr); 686 + ni->attr_list_size = (u32)ntfs_attr_size(a); 688 687 ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size); 689 688 if (!ni->attr_list) { 690 689 ntfs_error(vi->i_sb, "Not enough memory to allocate " ··· 693 690 err = -ENOMEM; 694 691 goto unm_err_out; 695 692 } 696 - if (ctx->attr->non_resident) { 693 + if (a->non_resident) { 697 694 NInoSetAttrListNonResident(ni); 698 - if (ctx->attr->data.non_resident.lowest_vcn) { 695 + if (a->data.non_resident.lowest_vcn) { 699 696 ntfs_error(vi->i_sb, "Attribute list has non " 700 697 "zero lowest_vcn."); 701 698 goto unm_err_out; ··· 705 702 * exclusive access to the inode at this time. 706 703 */ 707 704 ni->attr_list_rl.rl = ntfs_mapping_pairs_decompress(vol, 708 - ctx->attr, NULL); 705 + a, NULL); 709 706 if (IS_ERR(ni->attr_list_rl.rl)) { 710 707 err = PTR_ERR(ni->attr_list_rl.rl); 711 708 ni->attr_list_rl.rl = NULL; ··· 716 713 /* Now load the attribute list. */ 717 714 if ((err = load_attribute_list(vol, &ni->attr_list_rl, 718 715 ni->attr_list, ni->attr_list_size, 719 - sle64_to_cpu(ctx->attr->data. 720 - non_resident.initialized_size)))) { 716 + sle64_to_cpu(a->data.non_resident. 717 + initialized_size)))) { 721 718 ntfs_error(vi->i_sb, "Failed to load " 722 719 "attribute list attribute."); 723 720 goto unm_err_out; 724 721 } 725 - } else /* if (!ctx.attr->non_resident) */ { 726 - if ((u8*)ctx->attr + le16_to_cpu( 727 - ctx->attr->data.resident.value_offset) + 728 - le32_to_cpu( 729 - ctx->attr->data.resident.value_length) > 722 + } else /* if (!a->non_resident) */ { 723 + if ((u8*)a + le16_to_cpu(a->data.resident.value_offset) 724 + + le32_to_cpu( 725 + a->data.resident.value_length) > 730 726 (u8*)ctx->mrec + vol->mft_record_size) { 731 727 ntfs_error(vi->i_sb, "Corrupt attribute list " 732 728 "in inode."); 733 729 goto unm_err_out; 734 730 } 735 731 /* Now copy the attribute list. */ 736 - memcpy(ni->attr_list, (u8*)ctx->attr + le16_to_cpu( 737 - ctx->attr->data.resident.value_offset), 732 + memcpy(ni->attr_list, (u8*)a + le16_to_cpu( 733 + a->data.resident.value_offset), 738 734 le32_to_cpu( 739 - ctx->attr->data.resident.value_length)); 735 + a->data.resident.value_length)); 740 736 } 741 737 } 742 738 skip_attr_list_load: ··· 748 746 struct inode *bvi; 749 747 ntfs_inode *bni; 750 748 INDEX_ROOT *ir; 751 - char *ir_end, *index_end; 749 + u8 *ir_end, *index_end; 752 750 753 751 /* It is a directory, find index root attribute. */ 754 752 ntfs_attr_reinit_search_ctx(ctx); ··· 764 762 } 765 763 goto unm_err_out; 766 764 } 765 + a = ctx->attr; 767 766 /* Set up the state. */ 768 - if (unlikely(ctx->attr->non_resident)) { 767 + if (unlikely(a->non_resident)) { 769 768 ntfs_error(vol->sb, "$INDEX_ROOT attribute is not " 770 769 "resident."); 771 770 goto unm_err_out; 772 771 } 773 772 /* Ensure the attribute name is placed before the value. */ 774 - if (unlikely(ctx->attr->name_length && 775 - (le16_to_cpu(ctx->attr->name_offset) >= 776 - le16_to_cpu(ctx->attr->data.resident. 777 - value_offset)))) { 773 + if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= 774 + le16_to_cpu(a->data.resident.value_offset)))) { 778 775 ntfs_error(vol->sb, "$INDEX_ROOT attribute name is " 779 776 "placed after the attribute value."); 780 777 goto unm_err_out; ··· 784 783 * encrypted. However index root cannot be both compressed and 785 784 * encrypted. 786 785 */ 787 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) 786 + if (a->flags & ATTR_COMPRESSION_MASK) 788 787 NInoSetCompressed(ni); 789 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED) { 790 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 788 + if (a->flags & ATTR_IS_ENCRYPTED) { 789 + if (a->flags & ATTR_COMPRESSION_MASK) { 791 790 ntfs_error(vi->i_sb, "Found encrypted and " 792 791 "compressed attribute."); 793 792 goto unm_err_out; 794 793 } 795 794 NInoSetEncrypted(ni); 796 795 } 797 - if (ctx->attr->flags & ATTR_IS_SPARSE) 796 + if (a->flags & ATTR_IS_SPARSE) 798 797 NInoSetSparse(ni); 799 - ir = (INDEX_ROOT*)((char*)ctx->attr + le16_to_cpu( 800 - ctx->attr->data.resident.value_offset)); 801 - ir_end = (char*)ir + le32_to_cpu( 802 - ctx->attr->data.resident.value_length); 803 - if (ir_end > (char*)ctx->mrec + vol->mft_record_size) { 798 + ir = (INDEX_ROOT*)((u8*)a + 799 + le16_to_cpu(a->data.resident.value_offset)); 800 + ir_end = (u8*)ir + le32_to_cpu(a->data.resident.value_length); 801 + if (ir_end > (u8*)ctx->mrec + vol->mft_record_size) { 804 802 ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is " 805 803 "corrupt."); 806 804 goto unm_err_out; 807 805 } 808 - index_end = (char*)&ir->index + 806 + index_end = (u8*)&ir->index + 809 807 le32_to_cpu(ir->index.index_length); 810 808 if (index_end > ir_end) { 811 809 ntfs_error(vi->i_sb, "Directory index is corrupt."); ··· 891 891 "attribute."); 892 892 goto unm_err_out; 893 893 } 894 - if (!ctx->attr->non_resident) { 894 + a = ctx->attr; 895 + if (!a->non_resident) { 895 896 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " 896 897 "is resident."); 897 898 goto unm_err_out; ··· 901 900 * Ensure the attribute name is placed before the mapping pairs 902 901 * array. 903 902 */ 904 - if (unlikely(ctx->attr->name_length && 905 - (le16_to_cpu(ctx->attr->name_offset) >= 906 - le16_to_cpu(ctx->attr->data.non_resident. 907 - mapping_pairs_offset)))) { 903 + if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= 904 + le16_to_cpu( 905 + a->data.non_resident.mapping_pairs_offset)))) { 908 906 ntfs_error(vol->sb, "$INDEX_ALLOCATION attribute name " 909 907 "is placed after the mapping pairs " 910 908 "array."); 911 909 goto unm_err_out; 912 910 } 913 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED) { 911 + if (a->flags & ATTR_IS_ENCRYPTED) { 914 912 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " 915 913 "is encrypted."); 916 914 goto unm_err_out; 917 915 } 918 - if (ctx->attr->flags & ATTR_IS_SPARSE) { 916 + if (a->flags & ATTR_IS_SPARSE) { 919 917 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " 920 918 "is sparse."); 921 919 goto unm_err_out; 922 920 } 923 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 921 + if (a->flags & ATTR_COMPRESSION_MASK) { 924 922 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " 925 923 "is compressed."); 926 924 goto unm_err_out; 927 925 } 928 - if (ctx->attr->data.non_resident.lowest_vcn) { 926 + if (a->data.non_resident.lowest_vcn) { 929 927 ntfs_error(vi->i_sb, "First extent of " 930 928 "$INDEX_ALLOCATION attribute has non " 931 929 "zero lowest_vcn."); 932 930 goto unm_err_out; 933 931 } 934 - vi->i_size = sle64_to_cpu( 935 - ctx->attr->data.non_resident.data_size); 932 + vi->i_size = sle64_to_cpu(a->data.non_resident.data_size); 936 933 ni->initialized_size = sle64_to_cpu( 937 - ctx->attr->data.non_resident.initialized_size); 934 + a->data.non_resident.initialized_size); 938 935 ni->allocated_size = sle64_to_cpu( 939 - ctx->attr->data.non_resident.allocated_size); 936 + a->data.non_resident.allocated_size); 940 937 /* 941 938 * We are done with the mft record, so we release it. Otherwise 942 939 * we would deadlock in ntfs_attr_iget(). ··· 1012 1013 ntfs_error(vi->i_sb, "$DATA attribute is missing."); 1013 1014 goto unm_err_out; 1014 1015 } 1016 + a = ctx->attr; 1015 1017 /* Setup the state. */ 1016 - if (ctx->attr->non_resident) { 1018 + if (a->non_resident) { 1017 1019 NInoSetNonResident(ni); 1018 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 1020 + if (a->flags & ATTR_COMPRESSION_MASK) { 1019 1021 NInoSetCompressed(ni); 1020 1022 if (vol->cluster_size > 4096) { 1021 1023 ntfs_error(vi->i_sb, "Found " ··· 1026 1026 vol->cluster_size); 1027 1027 goto unm_err_out; 1028 1028 } 1029 - if ((ctx->attr->flags & ATTR_COMPRESSION_MASK) 1029 + if ((a->flags & ATTR_COMPRESSION_MASK) 1030 1030 != ATTR_IS_COMPRESSED) { 1031 1031 ntfs_error(vi->i_sb, "Found " 1032 1032 "unknown compression method or " ··· 1034 1034 goto unm_err_out; 1035 1035 } 1036 1036 ni->itype.compressed.block_clusters = 1U << 1037 - ctx->attr->data.non_resident. 1037 + a->data.non_resident. 1038 1038 compression_unit; 1039 - if (ctx->attr->data.non_resident. 1040 - compression_unit != 4) { 1039 + if (a->data.non_resident.compression_unit != 1040 + 4) { 1041 1041 ntfs_error(vi->i_sb, "Found " 1042 1042 "nonstandard compression unit " 1043 1043 "(%u instead of 4). Cannot " 1044 1044 "handle this.", 1045 - ctx->attr->data.non_resident. 1045 + a->data.non_resident. 1046 1046 compression_unit); 1047 1047 err = -EOPNOTSUPP; 1048 1048 goto unm_err_out; 1049 1049 } 1050 1050 ni->itype.compressed.block_size = 1U << ( 1051 - ctx->attr->data.non_resident. 1051 + a->data.non_resident. 1052 1052 compression_unit + 1053 1053 vol->cluster_size_bits); 1054 1054 ni->itype.compressed.block_size_bits = ffs( 1055 1055 ni->itype.compressed.block_size) - 1; 1056 1056 } 1057 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED) { 1058 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 1057 + if (a->flags & ATTR_IS_ENCRYPTED) { 1058 + if (a->flags & ATTR_COMPRESSION_MASK) { 1059 1059 ntfs_error(vi->i_sb, "Found encrypted " 1060 1060 "and compressed data."); 1061 1061 goto unm_err_out; 1062 1062 } 1063 1063 NInoSetEncrypted(ni); 1064 1064 } 1065 - if (ctx->attr->flags & ATTR_IS_SPARSE) 1065 + if (a->flags & ATTR_IS_SPARSE) 1066 1066 NInoSetSparse(ni); 1067 - if (ctx->attr->data.non_resident.lowest_vcn) { 1067 + if (a->data.non_resident.lowest_vcn) { 1068 1068 ntfs_error(vi->i_sb, "First extent of $DATA " 1069 1069 "attribute has non zero " 1070 1070 "lowest_vcn."); ··· 1072 1072 } 1073 1073 /* Setup all the sizes. */ 1074 1074 vi->i_size = sle64_to_cpu( 1075 - ctx->attr->data.non_resident.data_size); 1075 + a->data.non_resident.data_size); 1076 1076 ni->initialized_size = sle64_to_cpu( 1077 - ctx->attr->data.non_resident. 1078 - initialized_size); 1077 + a->data.non_resident.initialized_size); 1079 1078 ni->allocated_size = sle64_to_cpu( 1080 - ctx->attr->data.non_resident. 1081 - allocated_size); 1082 - if (NInoCompressed(ni)) { 1079 + a->data.non_resident.allocated_size); 1080 + if (NInoCompressed(ni)) 1083 1081 ni->itype.compressed.size = sle64_to_cpu( 1084 - ctx->attr->data.non_resident. 1082 + a->data.non_resident. 1085 1083 compressed_size); 1086 - } 1087 1084 } else { /* Resident attribute. */ 1088 - /* 1089 - * Make all sizes equal for simplicity in read code 1090 - * paths. FIXME: Need to keep this in mind when 1091 - * converting to non-resident attribute in write code 1092 - * path. (Probably only affects truncate().) 1093 - */ 1094 - vi->i_size = ni->initialized_size = ni->allocated_size = 1095 - le32_to_cpu( 1096 - ctx->attr->data.resident.value_length); 1085 + /* Setup all the sizes. */ 1086 + vi->i_size = ni->initialized_size = le32_to_cpu( 1087 + a->data.resident.value_length); 1088 + ni->allocated_size = le32_to_cpu(a->length) - 1089 + le16_to_cpu( 1090 + a->data.resident.value_offset); 1091 + if (vi->i_size > ni->allocated_size) { 1092 + ntfs_error(vi->i_sb, "Resident data attribute " 1093 + "is corrupt (size exceeds " 1094 + "allocation)."); 1095 + goto unm_err_out; 1096 + } 1097 1097 } 1098 1098 no_data_attr_special_case: 1099 1099 /* We are done with the mft record, so we release it. */ ··· 1169 1169 ntfs_volume *vol = NTFS_SB(vi->i_sb); 1170 1170 ntfs_inode *ni, *base_ni; 1171 1171 MFT_RECORD *m; 1172 + ATTR_RECORD *a; 1172 1173 ntfs_attr_search_ctx *ctx; 1173 1174 int err = 0; 1174 1175 ··· 1204 1203 err = -ENOMEM; 1205 1204 goto unm_err_out; 1206 1205 } 1207 - 1208 1206 /* Find the attribute. */ 1209 1207 err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len, 1210 1208 CASE_SENSITIVE, 0, NULL, 0, ctx); 1211 1209 if (unlikely(err)) 1212 1210 goto unm_err_out; 1213 - 1214 - if (!ctx->attr->non_resident) { 1211 + a = ctx->attr; 1212 + if (!a->non_resident) { 1215 1213 /* Ensure the attribute name is placed before the value. */ 1216 - if (unlikely(ctx->attr->name_length && 1217 - (le16_to_cpu(ctx->attr->name_offset) >= 1218 - le16_to_cpu(ctx->attr->data.resident. 1219 - value_offset)))) { 1214 + if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= 1215 + le16_to_cpu(a->data.resident.value_offset)))) { 1220 1216 ntfs_error(vol->sb, "Attribute name is placed after " 1221 1217 "the attribute value."); 1222 1218 goto unm_err_out; 1223 1219 } 1224 - if (NInoMstProtected(ni) || ctx->attr->flags) { 1220 + if (NInoMstProtected(ni) || a->flags) { 1225 1221 ntfs_error(vi->i_sb, "Found mst protected attribute " 1226 1222 "or attribute with non-zero flags but " 1227 1223 "the attribute is resident. Please " ··· 1226 1228 "linux-ntfs-dev@lists.sourceforge.net"); 1227 1229 goto unm_err_out; 1228 1230 } 1229 - /* 1230 - * Resident attribute. Make all sizes equal for simplicity in 1231 - * read code paths. 1232 - */ 1233 - vi->i_size = ni->initialized_size = ni->allocated_size = 1234 - le32_to_cpu(ctx->attr->data.resident.value_length); 1231 + /* Resident attribute. Setup all the sizes. */ 1232 + vi->i_size = ni->initialized_size = le32_to_cpu( 1233 + a->data.resident.value_length); 1234 + ni->allocated_size = le32_to_cpu(a->length) - 1235 + le16_to_cpu(a->data.resident.value_offset); 1236 + if (vi->i_size > ni->allocated_size) { 1237 + ntfs_error(vi->i_sb, "Resident data attribute is " 1238 + "corrupt (size exceeds allocation)."); 1239 + goto unm_err_out; 1240 + } 1235 1241 } else { 1236 1242 NInoSetNonResident(ni); 1237 1243 /* 1238 1244 * Ensure the attribute name is placed before the mapping pairs 1239 1245 * array. 1240 1246 */ 1241 - if (unlikely(ctx->attr->name_length && 1242 - (le16_to_cpu(ctx->attr->name_offset) >= 1243 - le16_to_cpu(ctx->attr->data.non_resident. 1244 - mapping_pairs_offset)))) { 1247 + if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= 1248 + le16_to_cpu( 1249 + a->data.non_resident.mapping_pairs_offset)))) { 1245 1250 ntfs_error(vol->sb, "Attribute name is placed after " 1246 1251 "the mapping pairs array."); 1247 1252 goto unm_err_out; 1248 1253 } 1249 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 1254 + if (a->flags & ATTR_COMPRESSION_MASK) { 1250 1255 if (NInoMstProtected(ni)) { 1251 1256 ntfs_error(vi->i_sb, "Found mst protected " 1252 1257 "attribute but the attribute " ··· 1278 1277 vol->cluster_size); 1279 1278 goto unm_err_out; 1280 1279 } 1281 - if ((ctx->attr->flags & ATTR_COMPRESSION_MASK) 1282 - != ATTR_IS_COMPRESSED) { 1280 + if ((a->flags & ATTR_COMPRESSION_MASK) != 1281 + ATTR_IS_COMPRESSED) { 1283 1282 ntfs_error(vi->i_sb, "Found unknown " 1284 1283 "compression method."); 1285 1284 goto unm_err_out; 1286 1285 } 1287 1286 ni->itype.compressed.block_clusters = 1U << 1288 - ctx->attr->data.non_resident. 1289 - compression_unit; 1290 - if (ctx->attr->data.non_resident.compression_unit != 1291 - 4) { 1287 + a->data.non_resident.compression_unit; 1288 + if (a->data.non_resident.compression_unit != 4) { 1292 1289 ntfs_error(vi->i_sb, "Found nonstandard " 1293 1290 "compression unit (%u instead " 1294 1291 "of 4). Cannot handle this.", 1295 - ctx->attr->data.non_resident. 1292 + a->data.non_resident. 1296 1293 compression_unit); 1297 1294 err = -EOPNOTSUPP; 1298 1295 goto unm_err_out; 1299 1296 } 1300 1297 ni->itype.compressed.block_size = 1U << ( 1301 - ctx->attr->data.non_resident. 1302 - compression_unit + 1298 + a->data.non_resident.compression_unit + 1303 1299 vol->cluster_size_bits); 1304 1300 ni->itype.compressed.block_size_bits = ffs( 1305 - ni->itype.compressed.block_size) - 1; 1301 + ni->itype.compressed.block_size) - 1; 1306 1302 } 1307 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED) { 1308 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 1309 - ntfs_error(vi->i_sb, "Found encrypted " 1310 - "and compressed data."); 1303 + if (a->flags & ATTR_IS_ENCRYPTED) { 1304 + if (a->flags & ATTR_COMPRESSION_MASK) { 1305 + ntfs_error(vi->i_sb, "Found encrypted and " 1306 + "compressed data."); 1311 1307 goto unm_err_out; 1312 1308 } 1313 1309 if (NInoMstProtected(ni)) { ··· 1318 1320 } 1319 1321 NInoSetEncrypted(ni); 1320 1322 } 1321 - if (ctx->attr->flags & ATTR_IS_SPARSE) { 1323 + if (a->flags & ATTR_IS_SPARSE) { 1322 1324 if (NInoMstProtected(ni)) { 1323 1325 ntfs_error(vi->i_sb, "Found mst protected " 1324 1326 "attribute but the attribute " ··· 1330 1332 } 1331 1333 NInoSetSparse(ni); 1332 1334 } 1333 - if (ctx->attr->data.non_resident.lowest_vcn) { 1335 + if (a->data.non_resident.lowest_vcn) { 1334 1336 ntfs_error(vi->i_sb, "First extent of attribute has " 1335 1337 "non-zero lowest_vcn."); 1336 1338 goto unm_err_out; 1337 1339 } 1338 1340 /* Setup all the sizes. */ 1339 - vi->i_size = sle64_to_cpu( 1340 - ctx->attr->data.non_resident.data_size); 1341 + vi->i_size = sle64_to_cpu(a->data.non_resident.data_size); 1341 1342 ni->initialized_size = sle64_to_cpu( 1342 - ctx->attr->data.non_resident.initialized_size); 1343 + a->data.non_resident.initialized_size); 1343 1344 ni->allocated_size = sle64_to_cpu( 1344 - ctx->attr->data.non_resident.allocated_size); 1345 - if (NInoCompressed(ni)) { 1345 + a->data.non_resident.allocated_size); 1346 + if (NInoCompressed(ni)) 1346 1347 ni->itype.compressed.size = sle64_to_cpu( 1347 - ctx->attr->data.non_resident. 1348 - compressed_size); 1349 - } 1348 + a->data.non_resident.compressed_size); 1350 1349 } 1351 1350 1352 1351 /* Setup the operations for this attribute inode. */ ··· 1432 1437 ntfs_inode *ni, *base_ni, *bni; 1433 1438 struct inode *bvi; 1434 1439 MFT_RECORD *m; 1440 + ATTR_RECORD *a; 1435 1441 ntfs_attr_search_ctx *ctx; 1436 1442 INDEX_ROOT *ir; 1437 1443 u8 *ir_end, *index_end; ··· 1474 1478 "missing."); 1475 1479 goto unm_err_out; 1476 1480 } 1481 + a = ctx->attr; 1477 1482 /* Set up the state. */ 1478 - if (unlikely(ctx->attr->non_resident)) { 1483 + if (unlikely(a->non_resident)) { 1479 1484 ntfs_error(vol->sb, "$INDEX_ROOT attribute is not resident."); 1480 1485 goto unm_err_out; 1481 1486 } 1482 1487 /* Ensure the attribute name is placed before the value. */ 1483 - if (unlikely(ctx->attr->name_length && 1484 - (le16_to_cpu(ctx->attr->name_offset) >= 1485 - le16_to_cpu(ctx->attr->data.resident. 1486 - value_offset)))) { 1488 + if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= 1489 + le16_to_cpu(a->data.resident.value_offset)))) { 1487 1490 ntfs_error(vol->sb, "$INDEX_ROOT attribute name is placed " 1488 1491 "after the attribute value."); 1489 1492 goto unm_err_out; 1490 1493 } 1491 1494 /* Compressed/encrypted/sparse index root is not allowed. */ 1492 - if (ctx->attr->flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED | 1495 + if (a->flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED | 1493 1496 ATTR_IS_SPARSE)) { 1494 1497 ntfs_error(vi->i_sb, "Found compressed/encrypted/sparse index " 1495 1498 "root attribute."); 1496 1499 goto unm_err_out; 1497 1500 } 1498 - ir = (INDEX_ROOT*)((u8*)ctx->attr + 1499 - le16_to_cpu(ctx->attr->data.resident.value_offset)); 1500 - ir_end = (u8*)ir + le32_to_cpu(ctx->attr->data.resident.value_length); 1501 + ir = (INDEX_ROOT*)((u8*)a + le16_to_cpu(a->data.resident.value_offset)); 1502 + ir_end = (u8*)ir + le32_to_cpu(a->data.resident.value_length); 1501 1503 if (ir_end > (u8*)ctx->mrec + vol->mft_record_size) { 1502 1504 ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is corrupt."); 1503 1505 goto unm_err_out; ··· 1568 1574 "$INDEX_ALLOCATION attribute."); 1569 1575 goto unm_err_out; 1570 1576 } 1571 - if (!ctx->attr->non_resident) { 1577 + if (!a->non_resident) { 1572 1578 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " 1573 1579 "resident."); 1574 1580 goto unm_err_out; ··· 1576 1582 /* 1577 1583 * Ensure the attribute name is placed before the mapping pairs array. 1578 1584 */ 1579 - if (unlikely(ctx->attr->name_length && (le16_to_cpu( 1580 - ctx->attr->name_offset) >= le16_to_cpu( 1581 - ctx->attr->data.non_resident.mapping_pairs_offset)))) { 1585 + if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= 1586 + le16_to_cpu( 1587 + a->data.non_resident.mapping_pairs_offset)))) { 1582 1588 ntfs_error(vol->sb, "$INDEX_ALLOCATION attribute name is " 1583 1589 "placed after the mapping pairs array."); 1584 1590 goto unm_err_out; 1585 1591 } 1586 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED) { 1592 + if (a->flags & ATTR_IS_ENCRYPTED) { 1587 1593 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " 1588 1594 "encrypted."); 1589 1595 goto unm_err_out; 1590 1596 } 1591 - if (ctx->attr->flags & ATTR_IS_SPARSE) { 1597 + if (a->flags & ATTR_IS_SPARSE) { 1592 1598 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is sparse."); 1593 1599 goto unm_err_out; 1594 1600 } 1595 - if (ctx->attr->flags & ATTR_COMPRESSION_MASK) { 1601 + if (a->flags & ATTR_COMPRESSION_MASK) { 1596 1602 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " 1597 1603 "compressed."); 1598 1604 goto unm_err_out; 1599 1605 } 1600 - if (ctx->attr->data.non_resident.lowest_vcn) { 1606 + if (a->data.non_resident.lowest_vcn) { 1601 1607 ntfs_error(vi->i_sb, "First extent of $INDEX_ALLOCATION " 1602 1608 "attribute has non zero lowest_vcn."); 1603 1609 goto unm_err_out; 1604 1610 } 1605 - vi->i_size = sle64_to_cpu(ctx->attr->data.non_resident.data_size); 1611 + vi->i_size = sle64_to_cpu(a->data.non_resident.data_size); 1606 1612 ni->initialized_size = sle64_to_cpu( 1607 - ctx->attr->data.non_resident.initialized_size); 1608 - ni->allocated_size = sle64_to_cpu( 1609 - ctx->attr->data.non_resident.allocated_size); 1613 + a->data.non_resident.initialized_size); 1614 + ni->allocated_size = sle64_to_cpu(a->data.non_resident.allocated_size); 1610 1615 /* 1611 1616 * We are done with the mft record, so we release it. Otherwise 1612 1617 * we would deadlock in ntfs_attr_iget(). ··· 1709 1716 struct buffer_head *bh; 1710 1717 ntfs_inode *ni; 1711 1718 MFT_RECORD *m = NULL; 1712 - ATTR_RECORD *attr; 1719 + ATTR_RECORD *a; 1713 1720 ntfs_attr_search_ctx *ctx; 1714 1721 unsigned int i, nr_blocks; 1715 1722 int err; ··· 1806 1813 1807 1814 ntfs_debug("Attribute list attribute found in $MFT."); 1808 1815 NInoSetAttrList(ni); 1809 - if (ctx->attr->flags & ATTR_IS_ENCRYPTED || 1810 - ctx->attr->flags & ATTR_COMPRESSION_MASK || 1811 - ctx->attr->flags & ATTR_IS_SPARSE) { 1816 + a = ctx->attr; 1817 + if (a->flags & ATTR_IS_ENCRYPTED || 1818 + a->flags & ATTR_COMPRESSION_MASK || 1819 + a->flags & ATTR_IS_SPARSE) { 1812 1820 ntfs_error(sb, "Attribute list attribute is " 1813 1821 "compressed/encrypted/sparse. Not " 1814 1822 "allowed. $MFT is corrupt. You should " ··· 1817 1823 goto put_err_out; 1818 1824 } 1819 1825 /* Now allocate memory for the attribute list. */ 1820 - ni->attr_list_size = (u32)ntfs_attr_size(ctx->attr); 1826 + ni->attr_list_size = (u32)ntfs_attr_size(a); 1821 1827 ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size); 1822 1828 if (!ni->attr_list) { 1823 1829 ntfs_error(sb, "Not enough memory to allocate buffer " 1824 1830 "for attribute list."); 1825 1831 goto put_err_out; 1826 1832 } 1827 - if (ctx->attr->non_resident) { 1833 + if (a->non_resident) { 1828 1834 NInoSetAttrListNonResident(ni); 1829 - if (ctx->attr->data.non_resident.lowest_vcn) { 1835 + if (a->data.non_resident.lowest_vcn) { 1830 1836 ntfs_error(sb, "Attribute list has non zero " 1831 1837 "lowest_vcn. $MFT is corrupt. " 1832 1838 "You should run chkdsk."); ··· 1834 1840 } 1835 1841 /* Setup the runlist. */ 1836 1842 ni->attr_list_rl.rl = ntfs_mapping_pairs_decompress(vol, 1837 - ctx->attr, NULL); 1843 + a, NULL); 1838 1844 if (IS_ERR(ni->attr_list_rl.rl)) { 1839 1845 err = PTR_ERR(ni->attr_list_rl.rl); 1840 1846 ni->attr_list_rl.rl = NULL; ··· 1846 1852 /* Now load the attribute list. */ 1847 1853 if ((err = load_attribute_list(vol, &ni->attr_list_rl, 1848 1854 ni->attr_list, ni->attr_list_size, 1849 - sle64_to_cpu(ctx->attr->data. 1855 + sle64_to_cpu(a->data. 1850 1856 non_resident.initialized_size)))) { 1851 1857 ntfs_error(sb, "Failed to load attribute list " 1852 1858 "attribute with error code %i.", ··· 1854 1860 goto put_err_out; 1855 1861 } 1856 1862 } else /* if (!ctx.attr->non_resident) */ { 1857 - if ((u8*)ctx->attr + le16_to_cpu( 1858 - ctx->attr->data.resident.value_offset) + 1863 + if ((u8*)a + le16_to_cpu( 1864 + a->data.resident.value_offset) + 1859 1865 le32_to_cpu( 1860 - ctx->attr->data.resident.value_length) > 1866 + a->data.resident.value_length) > 1861 1867 (u8*)ctx->mrec + vol->mft_record_size) { 1862 1868 ntfs_error(sb, "Corrupt attribute list " 1863 1869 "attribute."); 1864 1870 goto put_err_out; 1865 1871 } 1866 1872 /* Now copy the attribute list. */ 1867 - memcpy(ni->attr_list, (u8*)ctx->attr + le16_to_cpu( 1868 - ctx->attr->data.resident.value_offset), 1873 + memcpy(ni->attr_list, (u8*)a + le16_to_cpu( 1874 + a->data.resident.value_offset), 1869 1875 le32_to_cpu( 1870 - ctx->attr->data.resident.value_length)); 1876 + a->data.resident.value_length)); 1871 1877 } 1872 1878 /* The attribute list is now setup in memory. */ 1873 1879 /* ··· 1933 1939 ntfs_attr_reinit_search_ctx(ctx); 1934 1940 1935 1941 /* Now load all attribute extents. */ 1936 - attr = NULL; 1942 + a = NULL; 1937 1943 next_vcn = last_vcn = highest_vcn = 0; 1938 1944 while (!(err = ntfs_attr_lookup(AT_DATA, NULL, 0, 0, next_vcn, NULL, 0, 1939 1945 ctx))) { 1940 1946 runlist_element *nrl; 1941 1947 1942 1948 /* Cache the current attribute. */ 1943 - attr = ctx->attr; 1949 + a = ctx->attr; 1944 1950 /* $MFT must be non-resident. */ 1945 - if (!attr->non_resident) { 1951 + if (!a->non_resident) { 1946 1952 ntfs_error(sb, "$MFT must be non-resident but a " 1947 1953 "resident extent was found. $MFT is " 1948 1954 "corrupt. Run chkdsk."); 1949 1955 goto put_err_out; 1950 1956 } 1951 1957 /* $MFT must be uncompressed and unencrypted. */ 1952 - if (attr->flags & ATTR_COMPRESSION_MASK || 1953 - attr->flags & ATTR_IS_ENCRYPTED || 1954 - attr->flags & ATTR_IS_SPARSE) { 1958 + if (a->flags & ATTR_COMPRESSION_MASK || 1959 + a->flags & ATTR_IS_ENCRYPTED || 1960 + a->flags & ATTR_IS_SPARSE) { 1955 1961 ntfs_error(sb, "$MFT must be uncompressed, " 1956 1962 "non-sparse, and unencrypted but a " 1957 1963 "compressed/sparse/encrypted extent " ··· 1965 1971 * as we have exclusive access to the inode at this time and we 1966 1972 * are a mount in progress task, too. 1967 1973 */ 1968 - nrl = ntfs_mapping_pairs_decompress(vol, attr, ni->runlist.rl); 1974 + nrl = ntfs_mapping_pairs_decompress(vol, a, ni->runlist.rl); 1969 1975 if (IS_ERR(nrl)) { 1970 1976 ntfs_error(sb, "ntfs_mapping_pairs_decompress() " 1971 1977 "failed with error code %ld. $MFT is " ··· 1976 1982 1977 1983 /* Are we in the first extent? */ 1978 1984 if (!next_vcn) { 1979 - if (attr->data.non_resident.lowest_vcn) { 1985 + if (a->data.non_resident.lowest_vcn) { 1980 1986 ntfs_error(sb, "First extent of $DATA " 1981 1987 "attribute has non zero " 1982 1988 "lowest_vcn. $MFT is corrupt. " ··· 1985 1991 } 1986 1992 /* Get the last vcn in the $DATA attribute. */ 1987 1993 last_vcn = sle64_to_cpu( 1988 - attr->data.non_resident.allocated_size) 1994 + a->data.non_resident.allocated_size) 1989 1995 >> vol->cluster_size_bits; 1990 1996 /* Fill in the inode size. */ 1991 1997 vi->i_size = sle64_to_cpu( 1992 - attr->data.non_resident.data_size); 1993 - ni->initialized_size = sle64_to_cpu(attr->data. 1994 - non_resident.initialized_size); 1998 + a->data.non_resident.data_size); 1999 + ni->initialized_size = sle64_to_cpu( 2000 + a->data.non_resident.initialized_size); 1995 2001 ni->allocated_size = sle64_to_cpu( 1996 - attr->data.non_resident.allocated_size); 2002 + a->data.non_resident.allocated_size); 1997 2003 /* 1998 2004 * Verify the number of mft records does not exceed 1999 2005 * 2^32 - 1. ··· 2050 2056 } 2051 2057 2052 2058 /* Get the lowest vcn for the next extent. */ 2053 - highest_vcn = sle64_to_cpu(attr->data.non_resident.highest_vcn); 2059 + highest_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn); 2054 2060 next_vcn = highest_vcn + 1; 2055 2061 2056 2062 /* Only one extent or error, which we catch below. */ ··· 2059 2065 2060 2066 /* Avoid endless loops due to corruption. */ 2061 2067 if (next_vcn < sle64_to_cpu( 2062 - attr->data.non_resident.lowest_vcn)) { 2068 + a->data.non_resident.lowest_vcn)) { 2063 2069 ntfs_error(sb, "$MFT has corrupt attribute list " 2064 2070 "attribute. Run chkdsk."); 2065 2071 goto put_err_out; ··· 2070 2076 "$MFT is corrupt. Run chkdsk."); 2071 2077 goto put_err_out; 2072 2078 } 2073 - if (!attr) { 2079 + if (!a) { 2074 2080 ntfs_error(sb, "$MFT/$DATA attribute not found. $MFT is " 2075 2081 "corrupt. Run chkdsk."); 2076 2082 goto put_err_out; ··· 2312 2318 ntfs_volume *vol = ni->vol; 2313 2319 ntfs_attr_search_ctx *ctx; 2314 2320 MFT_RECORD *m; 2321 + ATTR_RECORD *a; 2315 2322 const char *te = " Leaving file length out of sync with i_size."; 2316 2323 int err; 2317 2324 ··· 2349 2354 vi->i_ino, err); 2350 2355 goto err_out; 2351 2356 } 2357 + a = ctx->attr; 2352 2358 /* If the size has not changed there is nothing to do. */ 2353 - if (ntfs_attr_size(ctx->attr) == i_size_read(vi)) 2359 + if (ntfs_attr_size(a) == i_size_read(vi)) 2354 2360 goto done; 2355 2361 // TODO: Implement the truncate... 2356 2362 ntfs_error(vi->i_sb, "Inode size has changed but this is not " 2357 2363 "implemented yet. Resetting inode size to old value. " 2358 2364 " This is most likely a bug in the ntfs driver!"); 2359 - i_size_write(vi, ntfs_attr_size(ctx->attr)); 2365 + i_size_write(vi, ntfs_attr_size(a)); 2360 2366 done: 2361 2367 ntfs_attr_put_search_ctx(ctx); 2362 2368 unmap_mft_record(ni);