Lines Matching +full:attribute +full:- +full:set

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * inode.c - NTFS kernel inode handling.
5 * Copyright (c) 2001-2014 Anton Altaparmakov and Tuxera Inc.
31 * ntfs_test_inode - compare two (possibly fake) inodes for equality
35 * Compare the ntfs attribute embedded in the ntfs specific part of the vfs
36 * inode @vi for equality with the ntfs attribute @data.
38 * If searching for the normal file/directory inode, set @na->type to AT_UNUSED.
39 * @na->name and @na->name_len are then ignored.
51 if (vi->i_ino != na->mft_no) in ntfs_test_inode()
57 if (unlikely(na->type != AT_UNUSED)) in ntfs_test_inode()
60 /* A fake inode describing an attribute. */ in ntfs_test_inode()
61 if (ni->type != na->type) in ntfs_test_inode()
63 if (ni->name_len != na->name_len) in ntfs_test_inode()
65 if (na->name_len && memcmp(ni->name, na->name, in ntfs_test_inode()
66 na->name_len * sizeof(ntfschar))) in ntfs_test_inode()
74 * ntfs_init_locked_inode - initialize an inode
78 * Initialize the vfs inode @vi with the values from the ntfs attribute @data in
81 * If initializing the normal file/directory inode, set @na->type to AT_UNUSED.
82 * In that case, @na->name and @na->name_len should be set to NULL and 0,
86 * Return 0 on success and -errno on error.
88 * NOTE: This function runs with the inode->i_lock spin lock held so it is not
96 vi->i_ino = na->mft_no; in ntfs_init_locked_inode()
98 ni->type = na->type; in ntfs_init_locked_inode()
99 if (na->type == AT_INDEX_ALLOCATION) in ntfs_init_locked_inode()
102 ni->name = na->name; in ntfs_init_locked_inode()
103 ni->name_len = na->name_len; in ntfs_init_locked_inode()
106 if (likely(na->type == AT_UNUSED)) { in ntfs_init_locked_inode()
107 BUG_ON(na->name); in ntfs_init_locked_inode()
108 BUG_ON(na->name_len); in ntfs_init_locked_inode()
122 if (na->name_len && na->name != I30) { in ntfs_init_locked_inode()
125 BUG_ON(!na->name); in ntfs_init_locked_inode()
126 i = na->name_len * sizeof(ntfschar); in ntfs_init_locked_inode()
127 ni->name = kmalloc(i + sizeof(ntfschar), GFP_ATOMIC); in ntfs_init_locked_inode()
128 if (!ni->name) in ntfs_init_locked_inode()
129 return -ENOMEM; in ntfs_init_locked_inode()
130 memcpy(ni->name, na->name, i); in ntfs_init_locked_inode()
131 ni->name[na->name_len] = 0; in ntfs_init_locked_inode()
142 * ntfs_iget - obtain a struct inode corresponding to a specific normal inode
171 return ERR_PTR(-ENOMEM); in ntfs_iget()
176 if (vi->i_state & I_NEW) { in ntfs_iget()
184 if (unlikely(err == -ENOMEM)) { in ntfs_iget()
192 * ntfs_attr_iget - obtain a struct inode corresponding to an attribute
193 * @base_vi: vfs base inode containing the attribute
194 * @type: attribute type
195 * @name: Unicode name of the attribute (NULL if unnamed)
198 * Obtain the (fake) struct inode corresponding to the attribute specified by
202 * If the attribute inode is in the cache, it is just returned with an
205 * attribute and fill in the inode structure.
210 * Return the struct inode of the attribute inode on success. Check the return
224 na.mft_no = base_vi->i_ino; in ntfs_attr_iget()
229 vi = iget5_locked(base_vi->i_sb, na.mft_no, ntfs_test_inode, in ntfs_attr_iget()
232 return ERR_PTR(-ENOMEM); in ntfs_attr_iget()
237 if (vi->i_state & I_NEW) { in ntfs_attr_iget()
242 * There is no point in keeping bad attribute inodes around. This also in ntfs_attr_iget()
243 * simplifies things in that we never need to check for bad attribute in ntfs_attr_iget()
254 * ntfs_index_iget - obtain a struct inode corresponding to an index
279 na.mft_no = base_vi->i_ino; in ntfs_index_iget()
284 vi = iget5_locked(base_vi->i_sb, na.mft_no, ntfs_test_inode, in ntfs_index_iget()
287 return ERR_PTR(-ENOMEM); in ntfs_index_iget()
292 if (vi->i_state & I_NEW) { in ntfs_index_iget()
315 ni->state = 0; in ntfs_alloc_big_inode()
334 ni->state = 0; in ntfs_alloc_extent_inode()
344 BUG_ON(ni->page); in ntfs_destroy_extent_inode()
345 if (!atomic_dec_and_test(&ni->count)) in ntfs_destroy_extent_inode()
351 * The attribute runlist lock has separate locking rules from the
352 * normal runlist lock, so split the two lock-classes:
357 * __ntfs_init_inode - initialize ntfs specific part of an inode
363 * NOTE: ni->mft_no, ni->state, ni->type, ni->name, and ni->name_len are left
366 * Return zero on success and -ENOMEM on error.
371 rwlock_init(&ni->size_lock); in __ntfs_init_inode()
372 ni->initialized_size = ni->allocated_size = 0; in __ntfs_init_inode()
373 ni->seq_no = 0; in __ntfs_init_inode()
374 atomic_set(&ni->count, 1); in __ntfs_init_inode()
375 ni->vol = NTFS_SB(sb); in __ntfs_init_inode()
376 ntfs_init_runlist(&ni->runlist); in __ntfs_init_inode()
377 mutex_init(&ni->mrec_lock); in __ntfs_init_inode()
378 ni->page = NULL; in __ntfs_init_inode()
379 ni->page_ofs = 0; in __ntfs_init_inode()
380 ni->attr_list_size = 0; in __ntfs_init_inode()
381 ni->attr_list = NULL; in __ntfs_init_inode()
382 ntfs_init_runlist(&ni->attr_list_rl); in __ntfs_init_inode()
383 lockdep_set_class(&ni->attr_list_rl.lock, in __ntfs_init_inode()
385 ni->itype.index.block_size = 0; in __ntfs_init_inode()
386 ni->itype.index.vcn_size = 0; in __ntfs_init_inode()
387 ni->itype.index.collation_rule = 0; in __ntfs_init_inode()
388 ni->itype.index.block_size_bits = 0; in __ntfs_init_inode()
389 ni->itype.index.vcn_size_bits = 0; in __ntfs_init_inode()
390 mutex_init(&ni->extent_lock); in __ntfs_init_inode()
391 ni->nr_extents = 0; in __ntfs_init_inode()
392 ni->ext.base_ntfs_ino = NULL; in __ntfs_init_inode()
396 * Extent inodes get MFT-mapped in a nested way, while the base inode
410 lockdep_set_class(&ni->mrec_lock, &extent_inode_mrec_lock_key); in ntfs_new_extent_inode()
411 ni->mft_no = mft_no; in ntfs_new_extent_inode()
412 ni->type = AT_UNUSED; in ntfs_new_extent_inode()
413 ni->name = NULL; in ntfs_new_extent_inode()
414 ni->name_len = 0; in ntfs_new_extent_inode()
420 * ntfs_is_extended_system_file - check if a file is in the $Extend directory
421 * @ctx: initialized attribute search context
423 * Search all file name attributes in the inode described by the attribute
430 * -errno: failed to determine if the file is in the $Extend directory
440 nr_links = le16_to_cpu(ctx->mrec->link_count); in ntfs_is_extended_system_file()
446 ATTR_RECORD *attr = ctx->attr; in ntfs_is_extended_system_file()
449 nr_links--; in ntfs_is_extended_system_file()
454 p = (u8*)attr + le32_to_cpu(attr->length); in ntfs_is_extended_system_file()
455 if (p < (u8*)ctx->mrec || (u8*)p > (u8*)ctx->mrec + in ntfs_is_extended_system_file()
456 le32_to_cpu(ctx->mrec->bytes_in_use)) { in ntfs_is_extended_system_file()
458 ntfs_error(ctx->ntfs_ino->vol->sb, "Corrupt file name " in ntfs_is_extended_system_file()
459 "attribute. You should run chkdsk."); in ntfs_is_extended_system_file()
460 return -EIO; in ntfs_is_extended_system_file()
462 if (attr->non_resident) { in ntfs_is_extended_system_file()
463 ntfs_error(ctx->ntfs_ino->vol->sb, "Non-resident file " in ntfs_is_extended_system_file()
465 return -EIO; in ntfs_is_extended_system_file()
467 if (attr->flags) { in ntfs_is_extended_system_file()
468 ntfs_error(ctx->ntfs_ino->vol->sb, "File name with " in ntfs_is_extended_system_file()
471 return -EIO; in ntfs_is_extended_system_file()
473 if (!(attr->data.resident.flags & RESIDENT_ATTR_IS_INDEXED)) { in ntfs_is_extended_system_file()
474 ntfs_error(ctx->ntfs_ino->vol->sb, "Unindexed file " in ntfs_is_extended_system_file()
476 return -EIO; in ntfs_is_extended_system_file()
479 le16_to_cpu(attr->data.resident.value_offset)); in ntfs_is_extended_system_file()
480 p2 = (u8 *)file_name_attr + le32_to_cpu(attr->data.resident.value_length); in ntfs_is_extended_system_file()
483 /* This attribute is ok, but is it in the $Extend directory? */ in ntfs_is_extended_system_file()
484 if (MREF_LE(file_name_attr->parent_directory) == FILE_Extend) in ntfs_is_extended_system_file()
487 if (unlikely(err != -ENOENT)) in ntfs_is_extended_system_file()
490 ntfs_error(ctx->ntfs_ino->vol->sb, "Inode hard link count " in ntfs_is_extended_system_file()
493 return -EIO; in ntfs_is_extended_system_file()
499 * ntfs_read_locked_inode - read an inode from its device
514 * A: i_state has I_NEW set, hence the inode is locked, also
515 * i_count is set to 1, so it is not going to go away
516 * i_flags is set to 0 and we have no business touching it. Only an ioctl()
521 * Return 0 on success and -errno on error. In the error case, the inode will
526 ntfs_volume *vol = NTFS_SB(vi->i_sb); in ntfs_read_locked_inode()
535 ntfs_debug("Entering for i_ino 0x%lx.", vi->i_ino); in ntfs_read_locked_inode()
538 vi->i_uid = vol->uid; in ntfs_read_locked_inode()
539 vi->i_gid = vol->gid; in ntfs_read_locked_inode()
540 vi->i_mode = 0; in ntfs_read_locked_inode()
546 if (vi->i_ino != FILE_MFT) in ntfs_read_locked_inode()
557 err = -ENOMEM; in ntfs_read_locked_inode()
561 if (!(m->flags & MFT_RECORD_IN_USE)) { in ntfs_read_locked_inode()
562 ntfs_error(vi->i_sb, "Inode is not in use!"); in ntfs_read_locked_inode()
565 if (m->base_mft_record) { in ntfs_read_locked_inode()
566 ntfs_error(vi->i_sb, "Inode is an extent inode!"); in ntfs_read_locked_inode()
571 vi->i_generation = ni->seq_no = le16_to_cpu(m->sequence_number); in ntfs_read_locked_inode()
582 set_nlink(vi, le16_to_cpu(m->link_count)); in ntfs_read_locked_inode()
584 * FIXME: Reparse points can have the directory bit set even though in ntfs_read_locked_inode()
591 vi->i_mode |= S_IRWXUGO; in ntfs_read_locked_inode()
592 /* If read-only, no one gets write permissions. */ in ntfs_read_locked_inode()
594 vi->i_mode &= ~S_IWUGO; in ntfs_read_locked_inode()
595 if (m->flags & MFT_RECORD_IS_DIRECTORY) { in ntfs_read_locked_inode()
596 vi->i_mode |= S_IFDIR; in ntfs_read_locked_inode()
598 * Apply the directory permissions mask set in the mount in ntfs_read_locked_inode()
601 vi->i_mode &= ~vol->dmask; in ntfs_read_locked_inode()
603 if (vi->i_nlink > 1) in ntfs_read_locked_inode()
606 vi->i_mode |= S_IFREG; in ntfs_read_locked_inode()
607 /* Apply the file permissions mask set in the mount options. */ in ntfs_read_locked_inode()
608 vi->i_mode &= ~vol->fmask; in ntfs_read_locked_inode()
611 * Find the standard information attribute in the mft record. At this in ntfs_read_locked_inode()
612 * stage we haven't setup the attribute list stuff yet, so this could in ntfs_read_locked_inode()
619 if (err == -ENOENT) { in ntfs_read_locked_inode()
622 * recover mount option is set) by creating a new in ntfs_read_locked_inode()
623 * attribute. in ntfs_read_locked_inode()
625 ntfs_error(vi->i_sb, "$STANDARD_INFORMATION attribute " in ntfs_read_locked_inode()
630 a = ctx->attr; in ntfs_read_locked_inode()
631 /* Get the standard information attribute value. */ in ntfs_read_locked_inode()
632 if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset) in ntfs_read_locked_inode()
633 + le32_to_cpu(a->data.resident.value_length) > in ntfs_read_locked_inode()
634 (u8 *)ctx->mrec + vol->mft_record_size) { in ntfs_read_locked_inode()
635 ntfs_error(vi->i_sb, "Corrupt standard information attribute in inode."); in ntfs_read_locked_inode()
639 le16_to_cpu(a->data.resident.value_offset)); in ntfs_read_locked_inode()
651 vi->i_mtime = ntfs2utc(si->last_data_change_time); in ntfs_read_locked_inode()
657 inode_set_ctime_to_ts(vi, ntfs2utc(si->last_mft_change_time)); in ntfs_read_locked_inode()
662 vi->i_atime = ntfs2utc(si->last_access_time); in ntfs_read_locked_inode()
664 /* Find the attribute list attribute if present. */ in ntfs_read_locked_inode()
668 if (unlikely(err != -ENOENT)) { in ntfs_read_locked_inode()
669 ntfs_error(vi->i_sb, "Failed to lookup attribute list " in ntfs_read_locked_inode()
670 "attribute."); in ntfs_read_locked_inode()
674 if (vi->i_ino == FILE_MFT) in ntfs_read_locked_inode()
676 ntfs_debug("Attribute list found in inode 0x%lx.", vi->i_ino); in ntfs_read_locked_inode()
678 a = ctx->attr; in ntfs_read_locked_inode()
679 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_locked_inode()
680 ntfs_error(vi->i_sb, "Attribute list attribute is " in ntfs_read_locked_inode()
684 if (a->flags & ATTR_IS_ENCRYPTED || in ntfs_read_locked_inode()
685 a->flags & ATTR_IS_SPARSE) { in ntfs_read_locked_inode()
686 if (a->non_resident) { in ntfs_read_locked_inode()
687 ntfs_error(vi->i_sb, "Non-resident attribute " in ntfs_read_locked_inode()
688 "list attribute is encrypted/" in ntfs_read_locked_inode()
692 ntfs_warning(vi->i_sb, "Resident attribute list " in ntfs_read_locked_inode()
693 "attribute in inode 0x%lx is marked " in ntfs_read_locked_inode()
698 "flags and pretend they are not set.", in ntfs_read_locked_inode()
699 vi->i_ino); in ntfs_read_locked_inode()
701 /* Now allocate memory for the attribute list. */ in ntfs_read_locked_inode()
702 ni->attr_list_size = (u32)ntfs_attr_size(a); in ntfs_read_locked_inode()
703 ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size); in ntfs_read_locked_inode()
704 if (!ni->attr_list) { in ntfs_read_locked_inode()
705 ntfs_error(vi->i_sb, "Not enough memory to allocate " in ntfs_read_locked_inode()
706 "buffer for attribute list."); in ntfs_read_locked_inode()
707 err = -ENOMEM; in ntfs_read_locked_inode()
710 if (a->non_resident) { in ntfs_read_locked_inode()
712 if (a->data.non_resident.lowest_vcn) { in ntfs_read_locked_inode()
713 ntfs_error(vi->i_sb, "Attribute list has non " in ntfs_read_locked_inode()
721 ni->attr_list_rl.rl = ntfs_mapping_pairs_decompress(vol, in ntfs_read_locked_inode()
723 if (IS_ERR(ni->attr_list_rl.rl)) { in ntfs_read_locked_inode()
724 err = PTR_ERR(ni->attr_list_rl.rl); in ntfs_read_locked_inode()
725 ni->attr_list_rl.rl = NULL; in ntfs_read_locked_inode()
726 ntfs_error(vi->i_sb, "Mapping pairs " in ntfs_read_locked_inode()
730 /* Now load the attribute list. */ in ntfs_read_locked_inode()
731 if ((err = load_attribute_list(vol, &ni->attr_list_rl, in ntfs_read_locked_inode()
732 ni->attr_list, ni->attr_list_size, in ntfs_read_locked_inode()
733 sle64_to_cpu(a->data.non_resident. in ntfs_read_locked_inode()
735 ntfs_error(vi->i_sb, "Failed to load " in ntfs_read_locked_inode()
736 "attribute list attribute."); in ntfs_read_locked_inode()
739 } else /* if (!a->non_resident) */ { in ntfs_read_locked_inode()
740 if ((u8*)a + le16_to_cpu(a->data.resident.value_offset) in ntfs_read_locked_inode()
742 a->data.resident.value_length) > in ntfs_read_locked_inode()
743 (u8*)ctx->mrec + vol->mft_record_size) { in ntfs_read_locked_inode()
744 ntfs_error(vi->i_sb, "Corrupt attribute list " in ntfs_read_locked_inode()
748 /* Now copy the attribute list. */ in ntfs_read_locked_inode()
749 memcpy(ni->attr_list, (u8*)a + le16_to_cpu( in ntfs_read_locked_inode()
750 a->data.resident.value_offset), in ntfs_read_locked_inode()
752 a->data.resident.value_length)); in ntfs_read_locked_inode()
757 * If an attribute list is present we now have the attribute list value in ntfs_read_locked_inode()
758 * in ntfs_ino->attr_list and it is ntfs_ino->attr_list_size bytes. in ntfs_read_locked_inode()
760 if (S_ISDIR(vi->i_mode)) { in ntfs_read_locked_inode()
766 /* It is a directory, find index root attribute. */ in ntfs_read_locked_inode()
771 if (err == -ENOENT) { in ntfs_read_locked_inode()
772 // FIXME: File is corrupt! Hot-fix with empty in ntfs_read_locked_inode()
773 // index root attribute if recovery option is in ntfs_read_locked_inode()
774 // set. in ntfs_read_locked_inode()
775 ntfs_error(vi->i_sb, "$INDEX_ROOT attribute " in ntfs_read_locked_inode()
780 a = ctx->attr; in ntfs_read_locked_inode()
781 /* Set up the state. */ in ntfs_read_locked_inode()
782 if (unlikely(a->non_resident)) { in ntfs_read_locked_inode()
783 ntfs_error(vol->sb, "$INDEX_ROOT attribute is not " in ntfs_read_locked_inode()
787 /* Ensure the attribute name is placed before the value. */ in ntfs_read_locked_inode()
788 if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= in ntfs_read_locked_inode()
789 le16_to_cpu(a->data.resident.value_offset)))) { in ntfs_read_locked_inode()
790 ntfs_error(vol->sb, "$INDEX_ROOT attribute name is " in ntfs_read_locked_inode()
791 "placed after the attribute value."); in ntfs_read_locked_inode()
800 if (a->flags & ATTR_COMPRESSION_MASK) in ntfs_read_locked_inode()
802 if (a->flags & ATTR_IS_ENCRYPTED) { in ntfs_read_locked_inode()
803 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_locked_inode()
804 ntfs_error(vi->i_sb, "Found encrypted and " in ntfs_read_locked_inode()
805 "compressed attribute."); in ntfs_read_locked_inode()
810 if (a->flags & ATTR_IS_SPARSE) in ntfs_read_locked_inode()
813 le16_to_cpu(a->data.resident.value_offset)); in ntfs_read_locked_inode()
814 ir_end = (u8*)ir + le32_to_cpu(a->data.resident.value_length); in ntfs_read_locked_inode()
815 if (ir_end > (u8*)ctx->mrec + vol->mft_record_size) { in ntfs_read_locked_inode()
816 ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is " in ntfs_read_locked_inode()
820 index_end = (u8*)&ir->index + in ntfs_read_locked_inode()
821 le32_to_cpu(ir->index.index_length); in ntfs_read_locked_inode()
823 ntfs_error(vi->i_sb, "Directory index is corrupt."); in ntfs_read_locked_inode()
826 if (ir->type != AT_FILE_NAME) { in ntfs_read_locked_inode()
827 ntfs_error(vi->i_sb, "Indexed attribute is not " in ntfs_read_locked_inode()
831 if (ir->collation_rule != COLLATION_FILE_NAME) { in ntfs_read_locked_inode()
832 ntfs_error(vi->i_sb, "Index collation rule is not " in ntfs_read_locked_inode()
836 ni->itype.index.collation_rule = ir->collation_rule; in ntfs_read_locked_inode()
837 ni->itype.index.block_size = le32_to_cpu(ir->index_block_size); in ntfs_read_locked_inode()
838 if (ni->itype.index.block_size & in ntfs_read_locked_inode()
839 (ni->itype.index.block_size - 1)) { in ntfs_read_locked_inode()
840 ntfs_error(vi->i_sb, "Index block size (%u) is not a " in ntfs_read_locked_inode()
842 ni->itype.index.block_size); in ntfs_read_locked_inode()
845 if (ni->itype.index.block_size > PAGE_SIZE) { in ntfs_read_locked_inode()
846 ntfs_error(vi->i_sb, "Index block size (%u) > " in ntfs_read_locked_inode()
849 ni->itype.index.block_size, in ntfs_read_locked_inode()
851 err = -EOPNOTSUPP; in ntfs_read_locked_inode()
854 if (ni->itype.index.block_size < NTFS_BLOCK_SIZE) { in ntfs_read_locked_inode()
855 ntfs_error(vi->i_sb, "Index block size (%u) < " in ntfs_read_locked_inode()
858 ni->itype.index.block_size, in ntfs_read_locked_inode()
860 err = -EOPNOTSUPP; in ntfs_read_locked_inode()
863 ni->itype.index.block_size_bits = in ntfs_read_locked_inode()
864 ffs(ni->itype.index.block_size) - 1; in ntfs_read_locked_inode()
866 if (vol->cluster_size <= ni->itype.index.block_size) { in ntfs_read_locked_inode()
867 ni->itype.index.vcn_size = vol->cluster_size; in ntfs_read_locked_inode()
868 ni->itype.index.vcn_size_bits = vol->cluster_size_bits; in ntfs_read_locked_inode()
870 ni->itype.index.vcn_size = vol->sector_size; in ntfs_read_locked_inode()
871 ni->itype.index.vcn_size_bits = vol->sector_size_bits; in ntfs_read_locked_inode()
874 /* Setup the index allocation attribute, even if not present. */ in ntfs_read_locked_inode()
876 ni->type = AT_INDEX_ALLOCATION; in ntfs_read_locked_inode()
877 ni->name = I30; in ntfs_read_locked_inode()
878 ni->name_len = 4; in ntfs_read_locked_inode()
880 if (!(ir->index.flags & LARGE_INDEX)) { in ntfs_read_locked_inode()
882 vi->i_size = ni->initialized_size = in ntfs_read_locked_inode()
883 ni->allocated_size = 0; in ntfs_read_locked_inode()
892 /* Find index allocation attribute. */ in ntfs_read_locked_inode()
897 if (err == -ENOENT) in ntfs_read_locked_inode()
898 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION " in ntfs_read_locked_inode()
899 "attribute is not present but " in ntfs_read_locked_inode()
902 ntfs_error(vi->i_sb, "Failed to lookup " in ntfs_read_locked_inode()
904 "attribute."); in ntfs_read_locked_inode()
907 a = ctx->attr; in ntfs_read_locked_inode()
908 if (!a->non_resident) { in ntfs_read_locked_inode()
909 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " in ntfs_read_locked_inode()
914 * Ensure the attribute name is placed before the mapping pairs in ntfs_read_locked_inode()
917 if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= in ntfs_read_locked_inode()
919 a->data.non_resident.mapping_pairs_offset)))) { in ntfs_read_locked_inode()
920 ntfs_error(vol->sb, "$INDEX_ALLOCATION attribute name " in ntfs_read_locked_inode()
925 if (a->flags & ATTR_IS_ENCRYPTED) { in ntfs_read_locked_inode()
926 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " in ntfs_read_locked_inode()
930 if (a->flags & ATTR_IS_SPARSE) { in ntfs_read_locked_inode()
931 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " in ntfs_read_locked_inode()
935 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_locked_inode()
936 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute " in ntfs_read_locked_inode()
940 if (a->data.non_resident.lowest_vcn) { in ntfs_read_locked_inode()
941 ntfs_error(vi->i_sb, "First extent of " in ntfs_read_locked_inode()
942 "$INDEX_ALLOCATION attribute has non " in ntfs_read_locked_inode()
946 vi->i_size = sle64_to_cpu(a->data.non_resident.data_size); in ntfs_read_locked_inode()
947 ni->initialized_size = sle64_to_cpu( in ntfs_read_locked_inode()
948 a->data.non_resident.initialized_size); in ntfs_read_locked_inode()
949 ni->allocated_size = sle64_to_cpu( in ntfs_read_locked_inode()
950 a->data.non_resident.allocated_size); in ntfs_read_locked_inode()
959 /* Get the index bitmap attribute inode. */ in ntfs_read_locked_inode()
962 ntfs_error(vi->i_sb, "Failed to get bitmap attribute."); in ntfs_read_locked_inode()
969 ntfs_error(vi->i_sb, "$BITMAP attribute is compressed " in ntfs_read_locked_inode()
975 if ((bvi_size << 3) < (vi->i_size >> in ntfs_read_locked_inode()
976 ni->itype.index.block_size_bits)) { in ntfs_read_locked_inode()
977 ntfs_error(vi->i_sb, "Index bitmap too small (0x%llx) " in ntfs_read_locked_inode()
979 bvi_size << 3, vi->i_size); in ntfs_read_locked_inode()
982 /* No longer need the bitmap attribute inode. */ in ntfs_read_locked_inode()
986 vi->i_op = &ntfs_dir_inode_ops; in ntfs_read_locked_inode()
987 vi->i_fop = &ntfs_dir_ops; in ntfs_read_locked_inode()
988 vi->i_mapping->a_ops = &ntfs_mst_aops; in ntfs_read_locked_inode()
993 /* Setup the data attribute, even if not present. */ in ntfs_read_locked_inode()
994 ni->type = AT_DATA; in ntfs_read_locked_inode()
995 ni->name = NULL; in ntfs_read_locked_inode()
996 ni->name_len = 0; in ntfs_read_locked_inode()
998 /* Find first extent of the unnamed data attribute. */ in ntfs_read_locked_inode()
1001 vi->i_size = ni->initialized_size = in ntfs_read_locked_inode()
1002 ni->allocated_size = 0; in ntfs_read_locked_inode()
1003 if (err != -ENOENT) { in ntfs_read_locked_inode()
1004 ntfs_error(vi->i_sb, "Failed to lookup $DATA " in ntfs_read_locked_inode()
1005 "attribute."); in ntfs_read_locked_inode()
1010 * attribute, so we special case it here. in ntfs_read_locked_inode()
1012 if (vi->i_ino == FILE_Secure) in ntfs_read_locked_inode()
1025 // FIXME: File is corrupt! Hot-fix with empty data in ntfs_read_locked_inode()
1026 // attribute if recovery option is set. in ntfs_read_locked_inode()
1027 ntfs_error(vi->i_sb, "$DATA attribute is missing."); in ntfs_read_locked_inode()
1030 a = ctx->attr; in ntfs_read_locked_inode()
1032 if (a->flags & (ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) { in ntfs_read_locked_inode()
1033 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_locked_inode()
1035 if (vol->cluster_size > 4096) { in ntfs_read_locked_inode()
1036 ntfs_error(vi->i_sb, "Found " in ntfs_read_locked_inode()
1042 vol->cluster_size); in ntfs_read_locked_inode()
1045 if ((a->flags & ATTR_COMPRESSION_MASK) in ntfs_read_locked_inode()
1047 ntfs_error(vi->i_sb, "Found unknown " in ntfs_read_locked_inode()
1053 if (a->flags & ATTR_IS_SPARSE) in ntfs_read_locked_inode()
1056 if (a->flags & ATTR_IS_ENCRYPTED) { in ntfs_read_locked_inode()
1058 ntfs_error(vi->i_sb, "Found encrypted and " in ntfs_read_locked_inode()
1064 if (a->non_resident) { in ntfs_read_locked_inode()
1067 if (NInoCompressed(ni) && a->data.non_resident. in ntfs_read_locked_inode()
1069 ntfs_error(vi->i_sb, "Found " in ntfs_read_locked_inode()
1070 "non-standard " in ntfs_read_locked_inode()
1074 a->data.non_resident. in ntfs_read_locked_inode()
1076 err = -EOPNOTSUPP; in ntfs_read_locked_inode()
1079 if (a->data.non_resident.compression_unit) { in ntfs_read_locked_inode()
1080 ni->itype.compressed.block_size = 1U << in ntfs_read_locked_inode()
1081 (a->data.non_resident. in ntfs_read_locked_inode()
1083 vol->cluster_size_bits); in ntfs_read_locked_inode()
1084 ni->itype.compressed.block_size_bits = in ntfs_read_locked_inode()
1085 ffs(ni->itype. in ntfs_read_locked_inode()
1087 block_size) - 1; in ntfs_read_locked_inode()
1088 ni->itype.compressed.block_clusters = in ntfs_read_locked_inode()
1089 1U << a->data. in ntfs_read_locked_inode()
1093 ni->itype.compressed.block_size = 0; in ntfs_read_locked_inode()
1094 ni->itype.compressed.block_size_bits = in ntfs_read_locked_inode()
1096 ni->itype.compressed.block_clusters = in ntfs_read_locked_inode()
1099 ni->itype.compressed.size = sle64_to_cpu( in ntfs_read_locked_inode()
1100 a->data.non_resident. in ntfs_read_locked_inode()
1103 if (a->data.non_resident.lowest_vcn) { in ntfs_read_locked_inode()
1104 ntfs_error(vi->i_sb, "First extent of $DATA " in ntfs_read_locked_inode()
1105 "attribute has non zero " in ntfs_read_locked_inode()
1109 vi->i_size = sle64_to_cpu( in ntfs_read_locked_inode()
1110 a->data.non_resident.data_size); in ntfs_read_locked_inode()
1111 ni->initialized_size = sle64_to_cpu( in ntfs_read_locked_inode()
1112 a->data.non_resident.initialized_size); in ntfs_read_locked_inode()
1113 ni->allocated_size = sle64_to_cpu( in ntfs_read_locked_inode()
1114 a->data.non_resident.allocated_size); in ntfs_read_locked_inode()
1115 } else { /* Resident attribute. */ in ntfs_read_locked_inode()
1116 vi->i_size = ni->initialized_size = le32_to_cpu( in ntfs_read_locked_inode()
1117 a->data.resident.value_length); in ntfs_read_locked_inode()
1118 ni->allocated_size = le32_to_cpu(a->length) - in ntfs_read_locked_inode()
1120 a->data.resident.value_offset); in ntfs_read_locked_inode()
1121 if (vi->i_size > ni->allocated_size) { in ntfs_read_locked_inode()
1122 ntfs_error(vi->i_sb, "Resident data attribute " in ntfs_read_locked_inode()
1135 vi->i_op = &ntfs_file_inode_ops; in ntfs_read_locked_inode()
1136 vi->i_fop = &ntfs_file_ops; in ntfs_read_locked_inode()
1137 vi->i_mapping->a_ops = &ntfs_normal_aops; in ntfs_read_locked_inode()
1139 vi->i_mapping->a_ops = &ntfs_mst_aops; in ntfs_read_locked_inode()
1141 vi->i_mapping->a_ops = &ntfs_compressed_aops; in ntfs_read_locked_inode()
1144 * The number of 512-byte blocks used on disk (for stat). This is in so in ntfs_read_locked_inode()
1146 * special non-resident attributes, but that is how Windows works, too, in ntfs_read_locked_inode()
1151 * sizes of all non-resident attributes present to give us the Linux in ntfs_read_locked_inode()
1154 if (S_ISREG(vi->i_mode) && (NInoCompressed(ni) || NInoSparse(ni))) in ntfs_read_locked_inode()
1155 vi->i_blocks = ni->itype.compressed.size >> 9; in ntfs_read_locked_inode()
1157 vi->i_blocks = ni->allocated_size >> 9; in ntfs_read_locked_inode()
1164 err = -EIO; in ntfs_read_locked_inode()
1170 ntfs_error(vol->sb, "Failed with error code %i. Marking corrupt " in ntfs_read_locked_inode()
1171 "inode 0x%lx as bad. Run chkdsk.", err, vi->i_ino); in ntfs_read_locked_inode()
1173 if (err != -EOPNOTSUPP && err != -ENOMEM) in ntfs_read_locked_inode()
1179 * ntfs_read_locked_attr_inode - read an attribute inode from its base inode
1181 * @vi: attribute inode to read
1184 * attribute inode described by @vi into memory from the base mft record
1188 * reading and looks up the attribute described by @vi before setting up the
1192 * A: i_state has I_NEW set, hence the inode is locked, also
1193 * i_count is set to 1, so it is not going to go away
1195 * Return 0 on success and -errno on error. In the error case, the inode will
1202 ntfs_volume *vol = NTFS_SB(vi->i_sb); in ntfs_read_locked_attr_inode()
1209 ntfs_debug("Entering for i_ino 0x%lx.", vi->i_ino); in ntfs_read_locked_attr_inode()
1217 vi->i_uid = base_vi->i_uid; in ntfs_read_locked_attr_inode()
1218 vi->i_gid = base_vi->i_gid; in ntfs_read_locked_attr_inode()
1219 set_nlink(vi, base_vi->i_nlink); in ntfs_read_locked_attr_inode()
1220 vi->i_mtime = base_vi->i_mtime; in ntfs_read_locked_attr_inode()
1222 vi->i_atime = base_vi->i_atime; in ntfs_read_locked_attr_inode()
1223 vi->i_generation = ni->seq_no = base_ni->seq_no; in ntfs_read_locked_attr_inode()
1225 /* Set inode type to zero but preserve permissions. */ in ntfs_read_locked_attr_inode()
1226 vi->i_mode = base_vi->i_mode & ~S_IFMT; in ntfs_read_locked_attr_inode()
1235 err = -ENOMEM; in ntfs_read_locked_attr_inode()
1238 /* Find the attribute. */ in ntfs_read_locked_attr_inode()
1239 err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len, in ntfs_read_locked_attr_inode()
1243 a = ctx->attr; in ntfs_read_locked_attr_inode()
1244 if (a->flags & (ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) { in ntfs_read_locked_attr_inode()
1245 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_locked_attr_inode()
1247 if ((ni->type != AT_DATA) || (ni->type == AT_DATA && in ntfs_read_locked_attr_inode()
1248 ni->name_len)) { in ntfs_read_locked_attr_inode()
1249 ntfs_error(vi->i_sb, "Found compressed " in ntfs_read_locked_attr_inode()
1250 "non-data or named data " in ntfs_read_locked_attr_inode()
1251 "attribute. Please report " in ntfs_read_locked_attr_inode()
1253 "linux-ntfs-dev@lists." in ntfs_read_locked_attr_inode()
1257 if (vol->cluster_size > 4096) { in ntfs_read_locked_attr_inode()
1258 ntfs_error(vi->i_sb, "Found compressed " in ntfs_read_locked_attr_inode()
1259 "attribute but compression is " in ntfs_read_locked_attr_inode()
1262 vol->cluster_size); in ntfs_read_locked_attr_inode()
1265 if ((a->flags & ATTR_COMPRESSION_MASK) != in ntfs_read_locked_attr_inode()
1267 ntfs_error(vi->i_sb, "Found unknown " in ntfs_read_locked_attr_inode()
1273 * The compressed/sparse flag set in an index root just means in ntfs_read_locked_attr_inode()
1276 if (NInoMstProtected(ni) && ni->type != AT_INDEX_ROOT) { in ntfs_read_locked_attr_inode()
1277 ntfs_error(vi->i_sb, "Found mst protected attribute " in ntfs_read_locked_attr_inode()
1278 "but the attribute is %s. Please " in ntfs_read_locked_attr_inode()
1280 "linux-ntfs-dev@lists.sourceforge.net", in ntfs_read_locked_attr_inode()
1285 if (a->flags & ATTR_IS_SPARSE) in ntfs_read_locked_attr_inode()
1288 if (a->flags & ATTR_IS_ENCRYPTED) { in ntfs_read_locked_attr_inode()
1290 ntfs_error(vi->i_sb, "Found encrypted and compressed " in ntfs_read_locked_attr_inode()
1295 * The encryption flag set in an index root just means to in ntfs_read_locked_attr_inode()
1298 if (NInoMstProtected(ni) && ni->type != AT_INDEX_ROOT) { in ntfs_read_locked_attr_inode()
1299 ntfs_error(vi->i_sb, "Found mst protected attribute " in ntfs_read_locked_attr_inode()
1300 "but the attribute is encrypted. " in ntfs_read_locked_attr_inode()
1302 "to linux-ntfs-dev@lists.sourceforge." in ntfs_read_locked_attr_inode()
1306 if (ni->type != AT_DATA) { in ntfs_read_locked_attr_inode()
1307 ntfs_error(vi->i_sb, "Found encrypted non-data " in ntfs_read_locked_attr_inode()
1308 "attribute."); in ntfs_read_locked_attr_inode()
1313 if (!a->non_resident) { in ntfs_read_locked_attr_inode()
1314 /* Ensure the attribute name is placed before the value. */ in ntfs_read_locked_attr_inode()
1315 if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= in ntfs_read_locked_attr_inode()
1316 le16_to_cpu(a->data.resident.value_offset)))) { in ntfs_read_locked_attr_inode()
1317 ntfs_error(vol->sb, "Attribute name is placed after " in ntfs_read_locked_attr_inode()
1318 "the attribute value."); in ntfs_read_locked_attr_inode()
1322 ntfs_error(vi->i_sb, "Found mst protected attribute " in ntfs_read_locked_attr_inode()
1323 "but the attribute is resident. " in ntfs_read_locked_attr_inode()
1325 "linux-ntfs-dev@lists.sourceforge.net"); in ntfs_read_locked_attr_inode()
1328 vi->i_size = ni->initialized_size = le32_to_cpu( in ntfs_read_locked_attr_inode()
1329 a->data.resident.value_length); in ntfs_read_locked_attr_inode()
1330 ni->allocated_size = le32_to_cpu(a->length) - in ntfs_read_locked_attr_inode()
1331 le16_to_cpu(a->data.resident.value_offset); in ntfs_read_locked_attr_inode()
1332 if (vi->i_size > ni->allocated_size) { in ntfs_read_locked_attr_inode()
1333 ntfs_error(vi->i_sb, "Resident attribute is corrupt " in ntfs_read_locked_attr_inode()
1340 * Ensure the attribute name is placed before the mapping pairs in ntfs_read_locked_attr_inode()
1343 if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= in ntfs_read_locked_attr_inode()
1345 a->data.non_resident.mapping_pairs_offset)))) { in ntfs_read_locked_attr_inode()
1346 ntfs_error(vol->sb, "Attribute name is placed after " in ntfs_read_locked_attr_inode()
1351 if (NInoCompressed(ni) && a->data.non_resident. in ntfs_read_locked_attr_inode()
1353 ntfs_error(vi->i_sb, "Found non-standard " in ntfs_read_locked_attr_inode()
1356 a->data.non_resident. in ntfs_read_locked_attr_inode()
1358 err = -EOPNOTSUPP; in ntfs_read_locked_attr_inode()
1361 if (a->data.non_resident.compression_unit) { in ntfs_read_locked_attr_inode()
1362 ni->itype.compressed.block_size = 1U << in ntfs_read_locked_attr_inode()
1363 (a->data.non_resident. in ntfs_read_locked_attr_inode()
1365 vol->cluster_size_bits); in ntfs_read_locked_attr_inode()
1366 ni->itype.compressed.block_size_bits = in ntfs_read_locked_attr_inode()
1367 ffs(ni->itype.compressed. in ntfs_read_locked_attr_inode()
1368 block_size) - 1; in ntfs_read_locked_attr_inode()
1369 ni->itype.compressed.block_clusters = 1U << in ntfs_read_locked_attr_inode()
1370 a->data.non_resident. in ntfs_read_locked_attr_inode()
1373 ni->itype.compressed.block_size = 0; in ntfs_read_locked_attr_inode()
1374 ni->itype.compressed.block_size_bits = 0; in ntfs_read_locked_attr_inode()
1375 ni->itype.compressed.block_clusters = 0; in ntfs_read_locked_attr_inode()
1377 ni->itype.compressed.size = sle64_to_cpu( in ntfs_read_locked_attr_inode()
1378 a->data.non_resident.compressed_size); in ntfs_read_locked_attr_inode()
1380 if (a->data.non_resident.lowest_vcn) { in ntfs_read_locked_attr_inode()
1381 ntfs_error(vi->i_sb, "First extent of attribute has " in ntfs_read_locked_attr_inode()
1382 "non-zero lowest_vcn."); in ntfs_read_locked_attr_inode()
1385 vi->i_size = sle64_to_cpu(a->data.non_resident.data_size); in ntfs_read_locked_attr_inode()
1386 ni->initialized_size = sle64_to_cpu( in ntfs_read_locked_attr_inode()
1387 a->data.non_resident.initialized_size); in ntfs_read_locked_attr_inode()
1388 ni->allocated_size = sle64_to_cpu( in ntfs_read_locked_attr_inode()
1389 a->data.non_resident.allocated_size); in ntfs_read_locked_attr_inode()
1391 vi->i_mapping->a_ops = &ntfs_normal_aops; in ntfs_read_locked_attr_inode()
1393 vi->i_mapping->a_ops = &ntfs_mst_aops; in ntfs_read_locked_attr_inode()
1395 vi->i_mapping->a_ops = &ntfs_compressed_aops; in ntfs_read_locked_attr_inode()
1396 if ((NInoCompressed(ni) || NInoSparse(ni)) && ni->type != AT_INDEX_ROOT) in ntfs_read_locked_attr_inode()
1397 vi->i_blocks = ni->itype.compressed.size >> 9; in ntfs_read_locked_attr_inode()
1399 vi->i_blocks = ni->allocated_size >> 9; in ntfs_read_locked_attr_inode()
1402 * attribute inode. in ntfs_read_locked_attr_inode()
1405 ni->ext.base_ntfs_ino = base_ni; in ntfs_read_locked_attr_inode()
1406 ni->nr_extents = -1; in ntfs_read_locked_attr_inode()
1416 err = -EIO; in ntfs_read_locked_attr_inode()
1421 ntfs_error(vol->sb, "Failed with error code %i while reading attribute " in ntfs_read_locked_attr_inode()
1424 "Run chkdsk.", err, vi->i_ino, ni->type, ni->name_len, in ntfs_read_locked_attr_inode()
1425 base_vi->i_ino); in ntfs_read_locked_attr_inode()
1427 if (err != -ENOMEM) in ntfs_read_locked_attr_inode()
1433 * ntfs_read_locked_index_inode - read an index inode from its base inode
1446 * Note, index inodes are essentially attribute inodes (NInoAttr() is true)
1447 * with the attribute type set to AT_INDEX_ALLOCATION. Apart from that, they
1450 * for small indices the index allocation attribute might not actually exist.
1451 * However, the index root attribute always exists but this does not need to
1453 * index. Also, like for directories, we need to have an attribute inode for
1454 * the bitmap attribute corresponding to the index allocation attribute and we
1459 * A: i_state has I_NEW set, hence the inode is locked, also
1460 * i_count is set to 1, so it is not going to go away
1462 * Return 0 on success and -errno on error. In the error case, the inode will
1468 ntfs_volume *vol = NTFS_SB(vi->i_sb); in ntfs_read_locked_index_inode()
1478 ntfs_debug("Entering for i_ino 0x%lx.", vi->i_ino); in ntfs_read_locked_index_inode()
1483 vi->i_uid = base_vi->i_uid; in ntfs_read_locked_index_inode()
1484 vi->i_gid = base_vi->i_gid; in ntfs_read_locked_index_inode()
1485 set_nlink(vi, base_vi->i_nlink); in ntfs_read_locked_index_inode()
1486 vi->i_mtime = base_vi->i_mtime; in ntfs_read_locked_index_inode()
1488 vi->i_atime = base_vi->i_atime; in ntfs_read_locked_index_inode()
1489 vi->i_generation = ni->seq_no = base_ni->seq_no; in ntfs_read_locked_index_inode()
1490 /* Set inode type to zero but preserve permissions. */ in ntfs_read_locked_index_inode()
1491 vi->i_mode = base_vi->i_mode & ~S_IFMT; in ntfs_read_locked_index_inode()
1500 err = -ENOMEM; in ntfs_read_locked_index_inode()
1503 /* Find the index root attribute. */ in ntfs_read_locked_index_inode()
1504 err = ntfs_attr_lookup(AT_INDEX_ROOT, ni->name, ni->name_len, in ntfs_read_locked_index_inode()
1507 if (err == -ENOENT) in ntfs_read_locked_index_inode()
1508 ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is " in ntfs_read_locked_index_inode()
1512 a = ctx->attr; in ntfs_read_locked_index_inode()
1513 /* Set up the state. */ in ntfs_read_locked_index_inode()
1514 if (unlikely(a->non_resident)) { in ntfs_read_locked_index_inode()
1515 ntfs_error(vol->sb, "$INDEX_ROOT attribute is not resident."); in ntfs_read_locked_index_inode()
1518 /* Ensure the attribute name is placed before the value. */ in ntfs_read_locked_index_inode()
1519 if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= in ntfs_read_locked_index_inode()
1520 le16_to_cpu(a->data.resident.value_offset)))) { in ntfs_read_locked_index_inode()
1521 ntfs_error(vol->sb, "$INDEX_ROOT attribute name is placed " in ntfs_read_locked_index_inode()
1522 "after the attribute value."); in ntfs_read_locked_index_inode()
1529 if (a->flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED | in ntfs_read_locked_index_inode()
1531 ntfs_error(vi->i_sb, "Found compressed/encrypted/sparse index " in ntfs_read_locked_index_inode()
1532 "root attribute."); in ntfs_read_locked_index_inode()
1535 ir = (INDEX_ROOT*)((u8*)a + le16_to_cpu(a->data.resident.value_offset)); in ntfs_read_locked_index_inode()
1536 ir_end = (u8*)ir + le32_to_cpu(a->data.resident.value_length); in ntfs_read_locked_index_inode()
1537 if (ir_end > (u8*)ctx->mrec + vol->mft_record_size) { in ntfs_read_locked_index_inode()
1538 ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is corrupt."); in ntfs_read_locked_index_inode()
1541 index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length); in ntfs_read_locked_index_inode()
1543 ntfs_error(vi->i_sb, "Index is corrupt."); in ntfs_read_locked_index_inode()
1546 if (ir->type) { in ntfs_read_locked_index_inode()
1547 ntfs_error(vi->i_sb, "Index type is not 0 (type is 0x%x).", in ntfs_read_locked_index_inode()
1548 le32_to_cpu(ir->type)); in ntfs_read_locked_index_inode()
1551 ni->itype.index.collation_rule = ir->collation_rule; in ntfs_read_locked_index_inode()
1553 le32_to_cpu(ir->collation_rule)); in ntfs_read_locked_index_inode()
1554 ni->itype.index.block_size = le32_to_cpu(ir->index_block_size); in ntfs_read_locked_index_inode()
1555 if (!is_power_of_2(ni->itype.index.block_size)) { in ntfs_read_locked_index_inode()
1556 ntfs_error(vi->i_sb, "Index block size (%u) is not a power of " in ntfs_read_locked_index_inode()
1557 "two.", ni->itype.index.block_size); in ntfs_read_locked_index_inode()
1560 if (ni->itype.index.block_size > PAGE_SIZE) { in ntfs_read_locked_index_inode()
1561 ntfs_error(vi->i_sb, "Index block size (%u) > PAGE_SIZE " in ntfs_read_locked_index_inode()
1563 ni->itype.index.block_size, PAGE_SIZE); in ntfs_read_locked_index_inode()
1564 err = -EOPNOTSUPP; in ntfs_read_locked_index_inode()
1567 if (ni->itype.index.block_size < NTFS_BLOCK_SIZE) { in ntfs_read_locked_index_inode()
1568 ntfs_error(vi->i_sb, "Index block size (%u) < NTFS_BLOCK_SIZE " in ntfs_read_locked_index_inode()
1570 ni->itype.index.block_size, NTFS_BLOCK_SIZE); in ntfs_read_locked_index_inode()
1571 err = -EOPNOTSUPP; in ntfs_read_locked_index_inode()
1574 ni->itype.index.block_size_bits = ffs(ni->itype.index.block_size) - 1; in ntfs_read_locked_index_inode()
1576 if (vol->cluster_size <= ni->itype.index.block_size) { in ntfs_read_locked_index_inode()
1577 ni->itype.index.vcn_size = vol->cluster_size; in ntfs_read_locked_index_inode()
1578 ni->itype.index.vcn_size_bits = vol->cluster_size_bits; in ntfs_read_locked_index_inode()
1580 ni->itype.index.vcn_size = vol->sector_size; in ntfs_read_locked_index_inode()
1581 ni->itype.index.vcn_size_bits = vol->sector_size_bits; in ntfs_read_locked_index_inode()
1583 /* Check for presence of index allocation attribute. */ in ntfs_read_locked_index_inode()
1584 if (!(ir->index.flags & LARGE_INDEX)) { in ntfs_read_locked_index_inode()
1586 vi->i_size = ni->initialized_size = ni->allocated_size = 0; in ntfs_read_locked_index_inode()
1595 /* Find index allocation attribute. */ in ntfs_read_locked_index_inode()
1597 err = ntfs_attr_lookup(AT_INDEX_ALLOCATION, ni->name, ni->name_len, in ntfs_read_locked_index_inode()
1600 if (err == -ENOENT) in ntfs_read_locked_index_inode()
1601 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " in ntfs_read_locked_index_inode()
1605 ntfs_error(vi->i_sb, "Failed to lookup " in ntfs_read_locked_index_inode()
1606 "$INDEX_ALLOCATION attribute."); in ntfs_read_locked_index_inode()
1609 a = ctx->attr; in ntfs_read_locked_index_inode()
1610 if (!a->non_resident) { in ntfs_read_locked_index_inode()
1611 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " in ntfs_read_locked_index_inode()
1616 * Ensure the attribute name is placed before the mapping pairs array. in ntfs_read_locked_index_inode()
1618 if (unlikely(a->name_length && (le16_to_cpu(a->name_offset) >= in ntfs_read_locked_index_inode()
1620 a->data.non_resident.mapping_pairs_offset)))) { in ntfs_read_locked_index_inode()
1621 ntfs_error(vol->sb, "$INDEX_ALLOCATION attribute name is " in ntfs_read_locked_index_inode()
1625 if (a->flags & ATTR_IS_ENCRYPTED) { in ntfs_read_locked_index_inode()
1626 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " in ntfs_read_locked_index_inode()
1630 if (a->flags & ATTR_IS_SPARSE) { in ntfs_read_locked_index_inode()
1631 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is sparse."); in ntfs_read_locked_index_inode()
1634 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_locked_index_inode()
1635 ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is " in ntfs_read_locked_index_inode()
1639 if (a->data.non_resident.lowest_vcn) { in ntfs_read_locked_index_inode()
1640 ntfs_error(vi->i_sb, "First extent of $INDEX_ALLOCATION " in ntfs_read_locked_index_inode()
1641 "attribute has non zero lowest_vcn."); in ntfs_read_locked_index_inode()
1644 vi->i_size = sle64_to_cpu(a->data.non_resident.data_size); in ntfs_read_locked_index_inode()
1645 ni->initialized_size = sle64_to_cpu( in ntfs_read_locked_index_inode()
1646 a->data.non_resident.initialized_size); in ntfs_read_locked_index_inode()
1647 ni->allocated_size = sle64_to_cpu(a->data.non_resident.allocated_size); in ntfs_read_locked_index_inode()
1656 /* Get the index bitmap attribute inode. */ in ntfs_read_locked_index_inode()
1657 bvi = ntfs_attr_iget(base_vi, AT_BITMAP, ni->name, ni->name_len); in ntfs_read_locked_index_inode()
1659 ntfs_error(vi->i_sb, "Failed to get bitmap attribute."); in ntfs_read_locked_index_inode()
1666 ntfs_error(vi->i_sb, "$BITMAP attribute is compressed and/or " in ntfs_read_locked_index_inode()
1672 if ((bvi_size << 3) < (vi->i_size >> ni->itype.index.block_size_bits)) { in ntfs_read_locked_index_inode()
1673 ntfs_error(vi->i_sb, "Index bitmap too small (0x%llx) for " in ntfs_read_locked_index_inode()
1675 vi->i_size); in ntfs_read_locked_index_inode()
1681 vi->i_mapping->a_ops = &ntfs_mst_aops; in ntfs_read_locked_index_inode()
1682 vi->i_blocks = ni->allocated_size >> 9; in ntfs_read_locked_index_inode()
1688 ni->ext.base_ntfs_ino = base_ni; in ntfs_read_locked_index_inode()
1689 ni->nr_extents = -1; in ntfs_read_locked_index_inode()
1697 err = -EIO; in ntfs_read_locked_index_inode()
1703 ntfs_error(vi->i_sb, "Failed with error code %i while reading index " in ntfs_read_locked_index_inode()
1704 "inode (mft_no 0x%lx, name_len %i.", err, vi->i_ino, in ntfs_read_locked_index_inode()
1705 ni->name_len); in ntfs_read_locked_index_inode()
1707 if (err != -EOPNOTSUPP && err != -ENOMEM) in ntfs_read_locked_index_inode()
1722 * ntfs_read_inode_mount - special read_inode for mount time use only
1736 * attribute list is actually present in $MFT inode.
1738 * We solve these problems by starting with the $DATA attribute before anything
1751 struct super_block *sb = vi->i_sb; in ntfs_read_inode_mount()
1768 /* Setup the data attribute. It is special as it is mst protected. */ in ntfs_read_inode_mount()
1772 ni->type = AT_DATA; in ntfs_read_inode_mount()
1773 ni->name = NULL; in ntfs_read_inode_mount()
1774 ni->name_len = 0; in ntfs_read_inode_mount()
1779 ni->itype.index.block_size = vol->mft_record_size; in ntfs_read_inode_mount()
1780 ni->itype.index.block_size_bits = vol->mft_record_size_bits; in ntfs_read_inode_mount()
1783 vol->mft_ino = vi; in ntfs_read_inode_mount()
1786 if (vol->mft_record_size > 64 * 1024) { in ntfs_read_inode_mount()
1788 vol->mft_record_size); in ntfs_read_inode_mount()
1791 i = vol->mft_record_size; in ntfs_read_inode_mount()
1792 if (i < sb->s_blocksize) in ntfs_read_inode_mount()
1793 i = sb->s_blocksize; in ntfs_read_inode_mount()
1800 /* Determine the first block of the $MFT/$DATA attribute. */ in ntfs_read_inode_mount()
1801 block = vol->mft_lcn << vol->cluster_size_bits >> in ntfs_read_inode_mount()
1802 sb->s_blocksize_bits; in ntfs_read_inode_mount()
1803 nr_blocks = vol->mft_record_size >> sb->s_blocksize_bits; in ntfs_read_inode_mount()
1814 memcpy((char*)m + (i << sb->s_blocksize_bits), bh->b_data, in ntfs_read_inode_mount()
1815 sb->s_blocksize); in ntfs_read_inode_mount()
1819 if (le32_to_cpu(m->bytes_allocated) != vol->mft_record_size) { in ntfs_read_inode_mount()
1821 le32_to_cpu(m->bytes_allocated), vol->mft_record_size); in ntfs_read_inode_mount()
1826 if (post_read_mst_fixup((NTFS_RECORD*)m, vol->mft_record_size)) { in ntfs_read_inode_mount()
1832 /* Sanity check offset to the first attribute */ in ntfs_read_inode_mount()
1833 if (le16_to_cpu(m->attrs_offset) >= le32_to_cpu(m->bytes_allocated)) { in ntfs_read_inode_mount()
1834 ntfs_error(sb, "Incorrect mft offset to the first attribute %u in superblock.", in ntfs_read_inode_mount()
1835 le16_to_cpu(m->attrs_offset)); in ntfs_read_inode_mount()
1839 /* Need this to sanity check attribute list references to $MFT. */ in ntfs_read_inode_mount()
1840 vi->i_generation = ni->seq_no = le16_to_cpu(m->sequence_number); in ntfs_read_inode_mount()
1843 vi->i_mapping->a_ops = &ntfs_mst_aops; in ntfs_read_inode_mount()
1847 err = -ENOMEM; in ntfs_read_inode_mount()
1851 /* Find the attribute list attribute if present. */ in ntfs_read_inode_mount()
1854 if (unlikely(err != -ENOENT)) { in ntfs_read_inode_mount()
1855 ntfs_error(sb, "Failed to lookup attribute list " in ntfs_read_inode_mount()
1856 "attribute. You should run chkdsk."); in ntfs_read_inode_mount()
1865 ntfs_debug("Attribute list attribute found in $MFT."); in ntfs_read_inode_mount()
1867 a = ctx->attr; in ntfs_read_inode_mount()
1868 if (a->flags & ATTR_COMPRESSION_MASK) { in ntfs_read_inode_mount()
1869 ntfs_error(sb, "Attribute list attribute is " in ntfs_read_inode_mount()
1873 if (a->flags & ATTR_IS_ENCRYPTED || in ntfs_read_inode_mount()
1874 a->flags & ATTR_IS_SPARSE) { in ntfs_read_inode_mount()
1875 if (a->non_resident) { in ntfs_read_inode_mount()
1876 ntfs_error(sb, "Non-resident attribute list " in ntfs_read_inode_mount()
1877 "attribute is encrypted/" in ntfs_read_inode_mount()
1881 ntfs_warning(sb, "Resident attribute list attribute " in ntfs_read_inode_mount()
1887 "flags and pretend they are not set."); in ntfs_read_inode_mount()
1889 /* Now allocate memory for the attribute list. */ in ntfs_read_inode_mount()
1890 ni->attr_list_size = (u32)ntfs_attr_size(a); in ntfs_read_inode_mount()
1891 if (!ni->attr_list_size) { in ntfs_read_inode_mount()
1895 ni->attr_list = ntfs_malloc_nofs(ni->attr_list_size); in ntfs_read_inode_mount()
1896 if (!ni->attr_list) { in ntfs_read_inode_mount()
1898 "for attribute list."); in ntfs_read_inode_mount()
1901 if (a->non_resident) { in ntfs_read_inode_mount()
1903 if (a->data.non_resident.lowest_vcn) { in ntfs_read_inode_mount()
1904 ntfs_error(sb, "Attribute list has non zero " in ntfs_read_inode_mount()
1910 ni->attr_list_rl.rl = ntfs_mapping_pairs_decompress(vol, in ntfs_read_inode_mount()
1912 if (IS_ERR(ni->attr_list_rl.rl)) { in ntfs_read_inode_mount()
1913 err = PTR_ERR(ni->attr_list_rl.rl); in ntfs_read_inode_mount()
1914 ni->attr_list_rl.rl = NULL; in ntfs_read_inode_mount()
1917 -err); in ntfs_read_inode_mount()
1920 /* Now load the attribute list. */ in ntfs_read_inode_mount()
1921 if ((err = load_attribute_list(vol, &ni->attr_list_rl, in ntfs_read_inode_mount()
1922 ni->attr_list, ni->attr_list_size, in ntfs_read_inode_mount()
1923 sle64_to_cpu(a->data. in ntfs_read_inode_mount()
1925 ntfs_error(sb, "Failed to load attribute list " in ntfs_read_inode_mount()
1926 "attribute with error code %i.", in ntfs_read_inode_mount()
1927 -err); in ntfs_read_inode_mount()
1930 } else /* if (!ctx.attr->non_resident) */ { in ntfs_read_inode_mount()
1932 a->data.resident.value_offset) + in ntfs_read_inode_mount()
1934 a->data.resident.value_length) > in ntfs_read_inode_mount()
1935 (u8*)ctx->mrec + vol->mft_record_size) { in ntfs_read_inode_mount()
1936 ntfs_error(sb, "Corrupt attribute list " in ntfs_read_inode_mount()
1937 "attribute."); in ntfs_read_inode_mount()
1940 /* Now copy the attribute list. */ in ntfs_read_inode_mount()
1941 memcpy(ni->attr_list, (u8*)a + le16_to_cpu( in ntfs_read_inode_mount()
1942 a->data.resident.value_offset), in ntfs_read_inode_mount()
1944 a->data.resident.value_length)); in ntfs_read_inode_mount()
1946 /* The attribute list is now setup in memory. */ in ntfs_read_inode_mount()
1958 al_entry = (ATTR_LIST_ENTRY*)ni->attr_list; in ntfs_read_inode_mount()
1959 al_end = (u8*)al_entry + ni->attr_list_size; in ntfs_read_inode_mount()
1962 if ((u8*)al_entry < ni->attr_list || in ntfs_read_inode_mount()
1965 /* Catch the end of the attribute list. */ in ntfs_read_inode_mount()
1968 if (!al_entry->length) in ntfs_read_inode_mount()
1971 le16_to_cpu(al_entry->length) > al_end) in ntfs_read_inode_mount()
1974 le16_to_cpu(al_entry->length)); in ntfs_read_inode_mount()
1975 if (le32_to_cpu(al_entry->type) > le32_to_cpu(AT_DATA)) in ntfs_read_inode_mount()
1977 if (AT_DATA != al_entry->type) in ntfs_read_inode_mount()
1979 /* We want an unnamed attribute. */ in ntfs_read_inode_mount()
1980 if (al_entry->name_length) in ntfs_read_inode_mount()
1983 if (al_entry->lowest_vcn) in ntfs_read_inode_mount()
1986 if (MREF_LE(al_entry->mft_reference) != vi->i_ino) { in ntfs_read_inode_mount()
1992 "linux-ntfs-dev@lists." in ntfs_read_inode_mount()
1997 if (MSEQNO_LE(al_entry->mft_reference) != in ntfs_read_inode_mount()
1998 ni->seq_no) in ntfs_read_inode_mount()
2008 /* Now load all attribute extents. */ in ntfs_read_inode_mount()
2015 /* Cache the current attribute. */ in ntfs_read_inode_mount()
2016 a = ctx->attr; in ntfs_read_inode_mount()
2017 /* $MFT must be non-resident. */ in ntfs_read_inode_mount()
2018 if (!a->non_resident) { in ntfs_read_inode_mount()
2019 ntfs_error(sb, "$MFT must be non-resident but a " in ntfs_read_inode_mount()
2025 if (a->flags & ATTR_COMPRESSION_MASK || in ntfs_read_inode_mount()
2026 a->flags & ATTR_IS_ENCRYPTED || in ntfs_read_inode_mount()
2027 a->flags & ATTR_IS_SPARSE) { in ntfs_read_inode_mount()
2029 "non-sparse, and unencrypted but a " in ntfs_read_inode_mount()
2041 nrl = ntfs_mapping_pairs_decompress(vol, a, ni->runlist.rl); in ntfs_read_inode_mount()
2048 ni->runlist.rl = nrl; in ntfs_read_inode_mount()
2052 if (a->data.non_resident.lowest_vcn) { in ntfs_read_inode_mount()
2054 "attribute has non zero " in ntfs_read_inode_mount()
2059 /* Get the last vcn in the $DATA attribute. */ in ntfs_read_inode_mount()
2061 a->data.non_resident.allocated_size) in ntfs_read_inode_mount()
2062 >> vol->cluster_size_bits; in ntfs_read_inode_mount()
2064 vi->i_size = sle64_to_cpu( in ntfs_read_inode_mount()
2065 a->data.non_resident.data_size); in ntfs_read_inode_mount()
2066 ni->initialized_size = sle64_to_cpu( in ntfs_read_inode_mount()
2067 a->data.non_resident.initialized_size); in ntfs_read_inode_mount()
2068 ni->allocated_size = sle64_to_cpu( in ntfs_read_inode_mount()
2069 a->data.non_resident.allocated_size); in ntfs_read_inode_mount()
2072 * 2^32 - 1. in ntfs_read_inode_mount()
2074 if ((vi->i_size >> vol->mft_record_size_bits) >= in ntfs_read_inode_mount()
2084 * re-read the mft record for $MFT, this time entering in ntfs_read_inode_mount()
2105 "linux-ntfs-dev@lists." in ntfs_read_inode_mount()
2110 return -1; in ntfs_read_inode_mount()
2113 * Re-initialize some specifics about $MFT's inode as in ntfs_read_inode_mount()
2114 * ntfs_read_inode() will have set up the default ones. in ntfs_read_inode_mount()
2116 /* Set uid and gid to root. */ in ntfs_read_inode_mount()
2117 vi->i_uid = GLOBAL_ROOT_UID; in ntfs_read_inode_mount()
2118 vi->i_gid = GLOBAL_ROOT_GID; in ntfs_read_inode_mount()
2120 vi->i_mode = S_IFREG; in ntfs_read_inode_mount()
2122 vi->i_op = &ntfs_empty_inode_ops; in ntfs_read_inode_mount()
2123 vi->i_fop = &ntfs_empty_file_ops; in ntfs_read_inode_mount()
2127 highest_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn); in ntfs_read_inode_mount()
2136 a->data.non_resident.lowest_vcn)) { in ntfs_read_inode_mount()
2137 ntfs_error(sb, "$MFT has corrupt attribute list " in ntfs_read_inode_mount()
2138 "attribute. Run chkdsk."); in ntfs_read_inode_mount()
2142 if (err != -ENOENT) { in ntfs_read_inode_mount()
2143 ntfs_error(sb, "Failed to lookup $MFT/$DATA attribute extent. " in ntfs_read_inode_mount()
2148 ntfs_error(sb, "$MFT/$DATA attribute not found. $MFT is " in ntfs_read_inode_mount()
2152 if (highest_vcn && highest_vcn != last_vcn - 1) { in ntfs_read_inode_mount()
2156 ntfs_debug("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx", in ntfs_read_inode_mount()
2158 (unsigned long long)last_vcn - 1); in ntfs_read_inode_mount()
2169 lockdep_set_class(&ni->runlist.lock, &mft_ni_runlist_lock_key); in ntfs_read_inode_mount()
2170 lockdep_set_class(&ni->mrec_lock, &mft_ni_mrec_lock_key); in ntfs_read_inode_mount()
2175 ntfs_error(sb, "Couldn't find first extent of $DATA attribute in " in ntfs_read_inode_mount()
2176 "attribute list. $MFT is corrupt. Run chkdsk."); in ntfs_read_inode_mount()
2183 return -1; in ntfs_read_inode_mount()
2189 down_write(&ni->runlist.lock); in __ntfs_clear_inode()
2190 if (ni->runlist.rl) { in __ntfs_clear_inode()
2191 ntfs_free(ni->runlist.rl); in __ntfs_clear_inode()
2192 ni->runlist.rl = NULL; in __ntfs_clear_inode()
2194 up_write(&ni->runlist.lock); in __ntfs_clear_inode()
2196 if (ni->attr_list) { in __ntfs_clear_inode()
2197 ntfs_free(ni->attr_list); in __ntfs_clear_inode()
2198 ni->attr_list = NULL; in __ntfs_clear_inode()
2201 down_write(&ni->attr_list_rl.lock); in __ntfs_clear_inode()
2202 if (ni->attr_list_rl.rl) { in __ntfs_clear_inode()
2203 ntfs_free(ni->attr_list_rl.rl); in __ntfs_clear_inode()
2204 ni->attr_list_rl.rl = NULL; in __ntfs_clear_inode()
2206 up_write(&ni->attr_list_rl.lock); in __ntfs_clear_inode()
2208 if (ni->name_len && ni->name != I30) { in __ntfs_clear_inode()
2210 BUG_ON(!ni->name); in __ntfs_clear_inode()
2211 kfree(ni->name); in __ntfs_clear_inode()
2217 ntfs_debug("Entering for inode 0x%lx.", ni->mft_no); in ntfs_clear_extent_inode()
2220 BUG_ON(ni->nr_extents != -1); in ntfs_clear_extent_inode()
2224 if (!is_bad_inode(VFS_I(ni->ext.base_ntfs_ino))) in ntfs_clear_extent_inode()
2225 ntfs_error(ni->vol->sb, "Clearing dirty extent inode! " in ntfs_clear_extent_inode()
2238 * ntfs_evict_big_inode - clean up the ntfs specific part of an inode
2251 truncate_inode_pages_final(&vi->i_data); in ntfs_evict_big_inode()
2262 ntfs_error(vi->i_sb, "Failed to commit dirty inode " in ntfs_evict_big_inode()
2263 "0x%lx. Losing data!", vi->i_ino); in ntfs_evict_big_inode()
2270 if (ni->nr_extents > 0) { in ntfs_evict_big_inode()
2273 for (i = 0; i < ni->nr_extents; i++) in ntfs_evict_big_inode()
2274 ntfs_clear_extent_inode(ni->ext.extent_ntfs_inos[i]); in ntfs_evict_big_inode()
2275 kfree(ni->ext.extent_ntfs_inos); in ntfs_evict_big_inode()
2282 if (ni->nr_extents == -1) { in ntfs_evict_big_inode()
2283 iput(VFS_I(ni->ext.base_ntfs_ino)); in ntfs_evict_big_inode()
2284 ni->nr_extents = 0; in ntfs_evict_big_inode()
2285 ni->ext.base_ntfs_ino = NULL; in ntfs_evict_big_inode()
2288 BUG_ON(ni->page); in ntfs_evict_big_inode()
2289 if (!atomic_dec_and_test(&ni->count)) in ntfs_evict_big_inode()
2295 * ntfs_show_options - show mount options in /proc/mounts
2306 ntfs_volume *vol = NTFS_SB(root->d_sb); in ntfs_show_options()
2309 seq_printf(sf, ",uid=%i", from_kuid_munged(&init_user_ns, vol->uid)); in ntfs_show_options()
2310 seq_printf(sf, ",gid=%i", from_kgid_munged(&init_user_ns, vol->gid)); in ntfs_show_options()
2311 if (vol->fmask == vol->dmask) in ntfs_show_options()
2312 seq_printf(sf, ",umask=0%o", vol->fmask); in ntfs_show_options()
2314 seq_printf(sf, ",fmask=0%o", vol->fmask); in ntfs_show_options()
2315 seq_printf(sf, ",dmask=0%o", vol->dmask); in ntfs_show_options()
2317 seq_printf(sf, ",nls=%s", vol->nls_map->charset); in ntfs_show_options()
2325 if (on_errors_arr[i].val & vol->on_errors) in ntfs_show_options()
2328 seq_printf(sf, ",mft_zone_multiplier=%i", vol->mft_zone_multiplier); in ntfs_show_options()
2338 * ntfs_truncate - called when the i_size of an ntfs inode is changed
2349 * or attribute inode as well as that @vi is a base inode.
2351 * Returns 0 on success or -errno on error.
2353 * Called with ->i_mutex held.
2361 ntfs_volume *vol = ni->vol; in ntfs_truncate()
2368 ntfs_debug("Entering for inode 0x%lx.", vi->i_ino); in ntfs_truncate()
2370 BUG_ON(S_ISDIR(vi->i_mode)); in ntfs_truncate()
2372 BUG_ON(ni->nr_extents < 0); in ntfs_truncate()
2376 * safe to mess with the attribute runlist and sizes. in ntfs_truncate()
2378 down_write(&ni->runlist.lock); in ntfs_truncate()
2382 base_ni = ni->ext.base_ntfs_ino; in ntfs_truncate()
2386 ntfs_error(vi->i_sb, "Failed to map mft record for inode 0x%lx " in ntfs_truncate()
2387 "(error code %d).%s", vi->i_ino, err, te); in ntfs_truncate()
2394 ntfs_error(vi->i_sb, "Failed to allocate a search context for " in ntfs_truncate()
2396 vi->i_ino, te); in ntfs_truncate()
2397 err = -ENOMEM; in ntfs_truncate()
2400 err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len, in ntfs_truncate()
2403 if (err == -ENOENT) { in ntfs_truncate()
2404 ntfs_error(vi->i_sb, "Open attribute is missing from " in ntfs_truncate()
2406 "Run chkdsk.%s", vi->i_ino, te); in ntfs_truncate()
2407 err = -EIO; in ntfs_truncate()
2409 ntfs_error(vi->i_sb, "Failed to lookup attribute in " in ntfs_truncate()
2411 vi->i_ino, err, te); in ntfs_truncate()
2414 m = ctx->mrec; in ntfs_truncate()
2415 a = ctx->attr; in ntfs_truncate()
2417 * The i_size of the vfs inode is the new size for the attribute value. in ntfs_truncate()
2420 /* The current size of the attribute value is the old size. */ in ntfs_truncate()
2424 new_alloc_size = (new_size + vol->cluster_size - 1) & in ntfs_truncate()
2425 ~(s64)vol->cluster_size_mask; in ntfs_truncate()
2429 read_lock_irqsave(&ni->size_lock, flags); in ntfs_truncate()
2430 old_alloc_size = ni->allocated_size; in ntfs_truncate()
2431 read_unlock_irqrestore(&ni->size_lock, flags); in ntfs_truncate()
2436 size_change = -1; in ntfs_truncate()
2437 if (new_size - old_size >= 0) { in ntfs_truncate()
2443 alloc_change = -1; in ntfs_truncate()
2444 if (new_alloc_size - old_alloc_size >= 0) { in ntfs_truncate()
2457 err = ntfs_attr_size_bounds_check(vol, ni->type, new_size); in ntfs_truncate()
2459 if (err == -ERANGE) { in ntfs_truncate()
2460 ntfs_error(vol->sb, "Truncate would cause the " in ntfs_truncate()
2462 "for its attribute type " in ntfs_truncate()
2464 vi->i_ino, in ntfs_truncate()
2467 le32_to_cpu(ni->type)); in ntfs_truncate()
2468 err = -EFBIG; in ntfs_truncate()
2470 ntfs_error(vol->sb, "Inode 0x%lx has unknown " in ntfs_truncate()
2471 "attribute type 0x%x. " in ntfs_truncate()
2473 vi->i_ino, in ntfs_truncate()
2474 le32_to_cpu(ni->type)); in ntfs_truncate()
2475 err = -EIO; in ntfs_truncate()
2483 ntfs_warning(vi->i_sb, "Changes in inode size are not " in ntfs_truncate()
2487 err = -EOPNOTSUPP; in ntfs_truncate()
2490 if (a->non_resident) in ntfs_truncate()
2493 /* Resize the attribute record to best fit the new attribute size. */ in ntfs_truncate()
2494 if (new_size < vol->mft_record_size && in ntfs_truncate()
2497 flush_dcache_mft_record_page(ctx->ntfs_ino); in ntfs_truncate()
2498 mark_mft_record_dirty(ctx->ntfs_ino); in ntfs_truncate()
2499 write_lock_irqsave(&ni->size_lock, flags); in ntfs_truncate()
2501 ni->allocated_size = le32_to_cpu(a->length) - in ntfs_truncate()
2502 le16_to_cpu(a->data.resident.value_offset); in ntfs_truncate()
2505 * necessary data clearing in the attribute record. When the in ntfs_truncate()
2531 ni->initialized_size = new_size; in ntfs_truncate()
2532 write_unlock_irqrestore(&ni->size_lock, flags); in ntfs_truncate()
2535 /* If the above resize failed, this must be an attribute extension. */ in ntfs_truncate()
2539 * ntfs_attr_make_non_resident(). This could be optimised by try- in ntfs_truncate()
2548 up_write(&ni->runlist.lock); in ntfs_truncate()
2550 * Not enough space in the mft record, try to make the attribute in ntfs_truncate()
2551 * non-resident and if successful restart the truncation process. in ntfs_truncate()
2557 * Could not make non-resident. If this is due to this not being in ntfs_truncate()
2558 * permitted for this attribute type or there not being enough space, in ntfs_truncate()
2559 * try to make other attributes non-resident. Otherwise fail. in ntfs_truncate()
2561 if (unlikely(err != -EPERM && err != -ENOSPC)) { in ntfs_truncate()
2562 ntfs_error(vol->sb, "Cannot truncate inode 0x%lx, attribute " in ntfs_truncate()
2564 "resident to non-resident attribute failed " in ntfs_truncate()
2565 "with error code %i.", vi->i_ino, in ntfs_truncate()
2566 (unsigned)le32_to_cpu(ni->type), err); in ntfs_truncate()
2567 if (err != -ENOMEM) in ntfs_truncate()
2568 err = -EIO; in ntfs_truncate()
2572 if (err == -ENOSPC) in ntfs_truncate()
2573 ntfs_error(vol->sb, "Not enough space in the mft record/on " in ntfs_truncate()
2574 "disk for the non-resident attribute value. " in ntfs_truncate()
2576 else /* if (err == -EPERM) */ in ntfs_truncate()
2577 ntfs_error(vol->sb, "This attribute type may not be " in ntfs_truncate()
2578 "non-resident. This case is not implemented " in ntfs_truncate()
2580 err = -EOPNOTSUPP; in ntfs_truncate()
2583 // TODO: Attempt to make other attributes non-resident. in ntfs_truncate()
2587 * Both the attribute list attribute and the standard information in ntfs_truncate()
2588 * attribute must remain in the base inode. Thus, if this is one of in ntfs_truncate()
2592 if (ni->type == AT_ATTRIBUTE_LIST || in ntfs_truncate()
2593 ni->type == AT_STANDARD_INFORMATION) { in ntfs_truncate()
2596 err = -EOPNOTSUPP; in ntfs_truncate()
2601 // TODO: Attempt to move this attribute to an extent mft record, but in ntfs_truncate()
2602 // only if it is not already the only attribute in an mft record in in ntfs_truncate()
2604 err = -EOPNOTSUPP; in ntfs_truncate()
2607 /* There is nothing we can do to make enough space. )-: */ in ntfs_truncate()
2613 highest_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn); in ntfs_truncate()
2615 old_alloc_size >> vol->cluster_size_bits > in ntfs_truncate()
2618 * This attribute has multiple extents. Not yet in ntfs_truncate()
2621 ntfs_error(vol->sb, "Cannot truncate inode 0x%lx, " in ntfs_truncate()
2622 "attribute type 0x%x, because the " in ntfs_truncate()
2623 "attribute is highly fragmented (it " in ntfs_truncate()
2626 vi->i_ino, in ntfs_truncate()
2627 (unsigned)le32_to_cpu(ni->type)); in ntfs_truncate()
2628 err = -EOPNOTSUPP; in ntfs_truncate()
2638 * Make the valid size smaller (i_size is already up-to-date). in ntfs_truncate()
2640 write_lock_irqsave(&ni->size_lock, flags); in ntfs_truncate()
2641 if (new_size < ni->initialized_size) { in ntfs_truncate()
2642 ni->initialized_size = new_size; in ntfs_truncate()
2643 a->data.non_resident.initialized_size = in ntfs_truncate()
2646 a->data.non_resident.data_size = cpu_to_sle64(new_size); in ntfs_truncate()
2647 write_unlock_irqrestore(&ni->size_lock, flags); in ntfs_truncate()
2648 flush_dcache_mft_record_page(ctx->ntfs_ino); in ntfs_truncate()
2649 mark_mft_record_dirty(ctx->ntfs_ino); in ntfs_truncate()
2675 * attribute truncate case. To do this, we simply drop in ntfs_truncate()
2681 up_write(&ni->runlist.lock); in ntfs_truncate()
2683 size_change > 0 ? new_size : -1, -1); in ntfs_truncate()
2696 vol->cluster_size_bits, -1, ctx); in ntfs_truncate()
2697 m = ctx->mrec; in ntfs_truncate()
2698 a = ctx->attr; in ntfs_truncate()
2700 ntfs_error(vol->sb, "Failed to release cluster(s) (error code " in ntfs_truncate()
2707 err = ntfs_rl_truncate_nolock(vol, &ni->runlist, in ntfs_truncate()
2708 new_alloc_size >> vol->cluster_size_bits); in ntfs_truncate()
2711 * longer valid, we cannot resize the attribute record or build the in ntfs_truncate()
2716 ntfs_error(vol->sb, "Failed to %s (error code %li).%s", in ntfs_truncate()
2718 "restore attribute search context" : in ntfs_truncate()
2719 "truncate attribute runlist", in ntfs_truncate()
2721 err = -EIO; in ntfs_truncate()
2725 mp_size = ntfs_get_size_for_mapping_pairs(vol, ni->runlist.rl, 0, -1); in ntfs_truncate()
2727 ntfs_error(vol->sb, "Cannot shrink allocation of inode 0x%lx, " in ntfs_truncate()
2728 "attribute type 0x%x, because determining the " in ntfs_truncate()
2730 "code %i.%s", vi->i_ino, in ntfs_truncate()
2731 (unsigned)le32_to_cpu(ni->type), mp_size, es); in ntfs_truncate()
2732 err = -EIO; in ntfs_truncate()
2736 * Shrink the attribute record for the new mapping pairs array. Note, in ntfs_truncate()
2737 * this cannot fail since we are making the attribute smaller thus by in ntfs_truncate()
2741 le16_to_cpu(a->data.non_resident.mapping_pairs_offset)); in ntfs_truncate()
2744 * Generate the mapping pairs array directly into the attribute record. in ntfs_truncate()
2747 le16_to_cpu(a->data.non_resident.mapping_pairs_offset), in ntfs_truncate()
2748 mp_size, ni->runlist.rl, 0, -1, NULL); in ntfs_truncate()
2750 ntfs_error(vol->sb, "Cannot shrink allocation of inode 0x%lx, " in ntfs_truncate()
2751 "attribute type 0x%x, because building the " in ntfs_truncate()
2753 vi->i_ino, (unsigned)le32_to_cpu(ni->type), in ntfs_truncate()
2755 err = -EIO; in ntfs_truncate()
2759 a->data.non_resident.highest_vcn = cpu_to_sle64((new_alloc_size >> in ntfs_truncate()
2760 vol->cluster_size_bits) - 1); in ntfs_truncate()
2761 write_lock_irqsave(&ni->size_lock, flags); in ntfs_truncate()
2762 ni->allocated_size = new_alloc_size; in ntfs_truncate()
2763 a->data.non_resident.allocated_size = cpu_to_sle64(new_alloc_size); in ntfs_truncate()
2766 ni->itype.compressed.size -= nr_freed << in ntfs_truncate()
2767 vol->cluster_size_bits; in ntfs_truncate()
2768 BUG_ON(ni->itype.compressed.size < 0); in ntfs_truncate()
2769 a->data.non_resident.compressed_size = cpu_to_sle64( in ntfs_truncate()
2770 ni->itype.compressed.size); in ntfs_truncate()
2771 vi->i_blocks = ni->itype.compressed.size >> 9; in ntfs_truncate()
2774 vi->i_blocks = new_alloc_size >> 9; in ntfs_truncate()
2775 write_unlock_irqrestore(&ni->size_lock, flags); in ntfs_truncate()
2790 a->data.non_resident.data_size = cpu_to_sle64(new_size); in ntfs_truncate()
2792 flush_dcache_mft_record_page(ctx->ntfs_ino); in ntfs_truncate()
2793 mark_mft_record_dirty(ctx->ntfs_ino); in ntfs_truncate()
2797 up_write(&ni->runlist.lock); in ntfs_truncate()
2800 /* normally ->truncate shouldn't update ctime or mtime, in ntfs_truncate()
2810 if (!timespec64_equal(&VFS_I(base_ni)->i_mtime, &now) || in ntfs_truncate()
2814 VFS_I(base_ni)->i_mtime = now; in ntfs_truncate()
2826 old_size = -1; in ntfs_truncate()
2828 if (err != -ENOMEM && err != -EOPNOTSUPP) in ntfs_truncate()
2830 if (err != -EOPNOTSUPP) in ntfs_truncate()
2839 up_write(&ni->runlist.lock); in ntfs_truncate()
2844 if (err != -ENOMEM && err != -EOPNOTSUPP) in ntfs_truncate()
2846 if (err != -EOPNOTSUPP) in ntfs_truncate()
2854 * ntfs_truncate_vfs - wrapper for ntfs_truncate() that has no return value
2868 * ntfs_setattr - called from notify_change() when an attribute is being changed
2880 * Called with ->i_mutex held.
2887 unsigned int ia_valid = attr->ia_valid; in ntfs_setattr()
2894 ntfs_warning(vi->i_sb, "Changes in user/group/mode are not " in ntfs_setattr()
2896 err = -EOPNOTSUPP; in ntfs_setattr()
2900 if (attr->ia_size != i_size_read(vi)) { in ntfs_setattr()
2907 ntfs_warning(vi->i_sb, "Changes in inode size " in ntfs_setattr()
2912 err = -EOPNOTSUPP; in ntfs_setattr()
2914 truncate_setsize(vi, attr->ia_size); in ntfs_setattr()
2928 vi->i_atime = attr->ia_atime; in ntfs_setattr()
2930 vi->i_mtime = attr->ia_mtime; in ntfs_setattr()
2932 inode_set_ctime_to_ts(vi, attr->ia_ctime); in ntfs_setattr()
2939 * __ntfs_write_inode - write out a dirty inode
2954 * Return 0 on success and -errno on error.
2967 vi->i_ino); in __ntfs_write_inode()
2969 * Dirty attribute inodes are written via their real inodes so just in __ntfs_write_inode()
2984 /* Update the access times in the standard information attribute. */ in __ntfs_write_inode()
2987 err = -ENOMEM; in __ntfs_write_inode()
2996 si = (STANDARD_INFORMATION*)((u8*)ctx->attr + in __ntfs_write_inode()
2997 le16_to_cpu(ctx->attr->data.resident.value_offset)); in __ntfs_write_inode()
2999 nt = utc2ntfs(vi->i_mtime); in __ntfs_write_inode()
3000 if (si->last_data_change_time != nt) { in __ntfs_write_inode()
3002 "new = 0x%llx", vi->i_ino, (long long) in __ntfs_write_inode()
3003 sle64_to_cpu(si->last_data_change_time), in __ntfs_write_inode()
3005 si->last_data_change_time = nt; in __ntfs_write_inode()
3009 if (si->last_mft_change_time != nt) { in __ntfs_write_inode()
3011 "new = 0x%llx", vi->i_ino, (long long) in __ntfs_write_inode()
3012 sle64_to_cpu(si->last_mft_change_time), in __ntfs_write_inode()
3014 si->last_mft_change_time = nt; in __ntfs_write_inode()
3017 nt = utc2ntfs(vi->i_atime); in __ntfs_write_inode()
3018 if (si->last_access_time != nt) { in __ntfs_write_inode()
3020 "new = 0x%llx", vi->i_ino, in __ntfs_write_inode()
3021 (long long)sle64_to_cpu(si->last_access_time), in __ntfs_write_inode()
3023 si->last_access_time = nt; in __ntfs_write_inode()
3027 * If we just modified the standard information attribute we need to in __ntfs_write_inode()
3036 * written out as mark_ntfs_record_dirty() will only set I_DIRTY_PAGES in __ntfs_write_inode()
3038 * re-invoked because of it which in turn is ok since the dirtied mft in __ntfs_write_inode()
3043 flush_dcache_mft_record_page(ctx->ntfs_ino); in __ntfs_write_inode()
3044 if (!NInoTestSetDirty(ctx->ntfs_ino)) in __ntfs_write_inode()
3045 mark_ntfs_record_dirty(ctx->ntfs_ino->page, in __ntfs_write_inode()
3046 ctx->ntfs_ino->page_ofs); in __ntfs_write_inode()
3053 mutex_lock(&ni->extent_lock); in __ntfs_write_inode()
3054 if (ni->nr_extents > 0) { in __ntfs_write_inode()
3055 ntfs_inode **extent_nis = ni->ext.extent_ntfs_inos; in __ntfs_write_inode()
3058 ntfs_debug("Writing %i extent inodes.", ni->nr_extents); in __ntfs_write_inode()
3059 for (i = 0; i < ni->nr_extents; i++) { in __ntfs_write_inode()
3067 if (!err || err == -ENOMEM) in __ntfs_write_inode()
3074 if (!err || err == -ENOMEM) in __ntfs_write_inode()
3080 mutex_unlock(&ni->extent_lock); in __ntfs_write_inode()
3089 if (err == -ENOMEM) { in __ntfs_write_inode()
3090 ntfs_warning(vi->i_sb, "Not enough memory to write inode. " in __ntfs_write_inode()
3095 ntfs_error(vi->i_sb, "Failed (error %i): Run chkdsk.", -err); in __ntfs_write_inode()
3096 NVolSetErrors(ni->vol); in __ntfs_write_inode()