^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * index.c - NTFS kernel index handling. Part of the Linux-NTFS project.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2004-2005 Anton Altaparmakov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "aops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "collate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "index.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "ntfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * ntfs_index_ctx_get - allocate and initialize a new index context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * @idx_ni: ntfs index inode with which to initialize the context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Allocate a new index context, initialize it with @idx_ni and return it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Return NULL if allocation failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Locking: Caller must hold i_mutex on the index inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *idx_ni)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ntfs_index_context *ictx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ictx = kmem_cache_alloc(ntfs_index_ctx_cache, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (ictx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *ictx = (ntfs_index_context){ .idx_ni = idx_ni };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return ictx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * ntfs_index_ctx_put - release an index context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * @ictx: index context to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Release the index context @ictx, releasing all associated resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Locking: Caller must hold i_mutex on the index inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void ntfs_index_ctx_put(ntfs_index_context *ictx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (ictx->entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (ictx->is_in_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (ictx->actx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ntfs_attr_put_search_ctx(ictx->actx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (ictx->base_ni)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unmap_mft_record(ictx->base_ni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct page *page = ictx->page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) BUG_ON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ntfs_unmap_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) kmem_cache_free(ntfs_index_ctx_cache, ictx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * ntfs_index_lookup - find a key in an index and return its index entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @key: [IN] key for which to search in the index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * @key_len: [IN] length of @key in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * @ictx: [IN/OUT] context describing the index and the returned entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * Before calling ntfs_index_lookup(), @ictx must have been obtained from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * call to ntfs_index_ctx_get().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * Look for the @key in the index specified by the index lookup context @ictx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * ntfs_index_lookup() walks the contents of the index looking for the @key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * If the @key is found in the index, 0 is returned and @ictx is setup to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * describe the index entry containing the matching @key. @ictx->entry is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * index entry and @ictx->data and @ictx->data_len are the index entry data and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * its length in bytes, respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * If the @key is not found in the index, -ENOENT is returned and @ictx is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * setup to describe the index entry whose key collates immediately after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * search @key, i.e. this is the position in the index at which an index entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * with a key of @key would need to be inserted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * If an error occurs return the negative error code and @ictx is left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * untouched.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * When finished with the entry and its data, call ntfs_index_ctx_put() to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * the context and other associated resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * If the index entry was modified, call flush_dcache_index_entry_page()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * immediately after the modification and either ntfs_index_entry_mark_dirty()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * or ntfs_index_entry_write() before the call to ntfs_index_ctx_put() to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * ensure that the changes are written to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Locking: - Caller must hold i_mutex on the index inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * - Each page cache page in the index allocation mapping must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * locked whilst being accessed otherwise we may find a corrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * page due to it being under ->writepage at the moment which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * applies the mst protection fixups before writing out and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * removes them again after the write is complete after which it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * unlocks the page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int ntfs_index_lookup(const void *key, const int key_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ntfs_index_context *ictx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) VCN vcn, old_vcn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) ntfs_inode *idx_ni = ictx->idx_ni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ntfs_volume *vol = idx_ni->vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct super_block *sb = vol->sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ntfs_inode *base_ni = idx_ni->ext.base_ntfs_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) MFT_RECORD *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) INDEX_ROOT *ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) INDEX_ENTRY *ie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) INDEX_ALLOCATION *ia;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u8 *index_end, *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ntfs_attr_search_ctx *actx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct address_space *ia_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int rc, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ntfs_debug("Entering.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) BUG_ON(!NInoAttr(idx_ni));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) BUG_ON(idx_ni->type != AT_INDEX_ALLOCATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) BUG_ON(idx_ni->nr_extents != -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) BUG_ON(!base_ni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) BUG_ON(!key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) BUG_ON(key_len <= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!ntfs_is_collation_rule_supported(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) idx_ni->itype.index.collation_rule)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ntfs_error(sb, "Index uses unsupported collation rule 0x%x. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) "Aborting lookup.", le32_to_cpu(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) idx_ni->itype.index.collation_rule));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* Get hold of the mft record for the index inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) m = map_mft_record(base_ni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (IS_ERR(m)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ntfs_error(sb, "map_mft_record() failed with error code %ld.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) -PTR_ERR(m));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return PTR_ERR(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) actx = ntfs_attr_get_search_ctx(base_ni, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (unlikely(!actx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* Find the index root attribute in the mft record. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) err = ntfs_attr_lookup(AT_INDEX_ROOT, idx_ni->name, idx_ni->name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) CASE_SENSITIVE, 0, NULL, 0, actx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (err == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ntfs_error(sb, "Index root attribute missing in inode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) "0x%lx.", idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* Get to the index root value (it has been verified in read_inode). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ir = (INDEX_ROOT*)((u8*)actx->attr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) le16_to_cpu(actx->attr->data.resident.value_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* The first index entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ie = (INDEX_ENTRY*)((u8*)&ir->index +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) le32_to_cpu(ir->index.entries_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Loop until we exceed valid memory (corruption case) or until we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * reach the last entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Bounds checks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if ((u8*)ie < (u8*)actx->mrec || (u8*)ie +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) sizeof(INDEX_ENTRY_HEADER) > index_end ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) (u8*)ie + le16_to_cpu(ie->length) > index_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) goto idx_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * The last entry cannot contain a key. It can however contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * a pointer to a child node in the B+tree so we just break out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (ie->flags & INDEX_ENTRY_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Further bounds checks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if ((u32)sizeof(INDEX_ENTRY_HEADER) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) le16_to_cpu(ie->key_length) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) le16_to_cpu(ie->data.vi.data_offset) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) (u32)le16_to_cpu(ie->data.vi.data_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) le16_to_cpu(ie->data.vi.data_length) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) le16_to_cpu(ie->length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) goto idx_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* If the keys match perfectly, we setup @ictx and return 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if ((key_len == le16_to_cpu(ie->key_length)) && !memcmp(key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) &ie->key, key_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ir_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ictx->is_in_root = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ictx->ir = ir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ictx->actx = actx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ictx->base_ni = base_ni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ictx->ia = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ictx->page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ictx->entry = ie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ictx->data = (u8*)ie +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) le16_to_cpu(ie->data.vi.data_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ictx->data_len = le16_to_cpu(ie->data.vi.data_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ntfs_debug("Done.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Not a perfect match, need to do full blown collation so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * know which way in the B+tree we have to go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) rc = ntfs_collate(vol, idx_ni->itype.index.collation_rule, key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) key_len, &ie->key, le16_to_cpu(ie->key_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * If @key collates before the key of the current entry, there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * is definitely no such key in this index but we might need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * descend into the B+tree so we just break out of the loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (rc == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * A match should never happen as the memcmp() call should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * cought it, but we still treat it correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) goto ir_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* The keys are not equal, continue the search. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * We have finished with this index without success. Check for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * presence of a child node and if not present setup @ictx and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * -ENOENT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!(ie->flags & INDEX_ENTRY_NODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ntfs_debug("Entry not found.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) goto ir_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) } /* Child node present, descend into it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Consistency check: Verify that an index allocation exists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!NInoIndexAllocPresent(idx_ni)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ntfs_error(sb, "No index allocation attribute but index entry "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) "requires one. Inode 0x%lx is corrupt or "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) "driver bug.", idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Get the starting vcn of the index_block holding the child node. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) ia_mapping = VFS_I(idx_ni)->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * We are done with the index root and the mft record. Release them,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * otherwise we deadlock with ntfs_map_page().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ntfs_attr_put_search_ctx(actx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unmap_mft_record(base_ni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) m = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) actx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) descend_into_child_node:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * Convert vcn to index into the index allocation attribute in units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * of PAGE_SIZE and map the page cache page, reading it from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * disk if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) page = ntfs_map_page(ia_mapping, vcn <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) idx_ni->itype.index.vcn_size_bits >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ntfs_error(sb, "Failed to map index page, error %ld.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) -PTR_ERR(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) kaddr = (u8*)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) fast_descend_into_child_node:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* Get to the index allocation block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ia = (INDEX_ALLOCATION*)(kaddr + ((vcn <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) idx_ni->itype.index.vcn_size_bits) & ~PAGE_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Bounds checks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if ((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ntfs_error(sb, "Out of bounds check failed. Corrupt inode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) "0x%lx or driver bug.", idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Catch multi sector transfer fixup errors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (unlikely(!ntfs_is_indx_record(ia->magic))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ntfs_error(sb, "Index record with vcn 0x%llx is corrupt. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) "Corrupt inode 0x%lx. Run chkdsk.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) (long long)vcn, idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (sle64_to_cpu(ia->index_block_vcn) != vcn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) "different from expected VCN (0x%llx). Inode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) "0x%lx is corrupt or driver bug.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) (unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) sle64_to_cpu(ia->index_block_vcn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) (unsigned long long)vcn, idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) idx_ni->itype.index.block_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) ntfs_error(sb, "Index buffer (VCN 0x%llx) of inode 0x%lx has "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) "a size (%u) differing from the index "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) "specified size (%u). Inode is corrupt or "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) "driver bug.", (unsigned long long)vcn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) idx_ni->mft_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) le32_to_cpu(ia->index.allocated_size) + 0x18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) idx_ni->itype.index.block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) index_end = (u8*)ia + idx_ni->itype.index.block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (index_end > kaddr + PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) ntfs_error(sb, "Index buffer (VCN 0x%llx) of inode 0x%lx "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) "crosses page boundary. Impossible! Cannot "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) "access! This is probably a bug in the "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) "driver.", (unsigned long long)vcn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (index_end > (u8*)ia + idx_ni->itype.index.block_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of inode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) "0x%lx exceeds maximum size.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) (unsigned long long)vcn, idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* The first index entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ie = (INDEX_ENTRY*)((u8*)&ia->index +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) le32_to_cpu(ia->index.entries_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * Iterate similar to above big loop but applied to index buffer, thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * loop until we exceed valid memory (corruption case) or until we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * reach the last entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* Bounds checks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if ((u8*)ie < (u8*)ia || (u8*)ie +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) sizeof(INDEX_ENTRY_HEADER) > index_end ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) (u8*)ie + le16_to_cpu(ie->length) > index_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) ntfs_error(sb, "Index entry out of bounds in inode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) "0x%lx.", idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * The last entry cannot contain a key. It can however contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * a pointer to a child node in the B+tree so we just break out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (ie->flags & INDEX_ENTRY_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* Further bounds checks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if ((u32)sizeof(INDEX_ENTRY_HEADER) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) le16_to_cpu(ie->key_length) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) le16_to_cpu(ie->data.vi.data_offset) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) (u32)le16_to_cpu(ie->data.vi.data_offset) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) le16_to_cpu(ie->data.vi.data_length) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) le16_to_cpu(ie->length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ntfs_error(sb, "Index entry out of bounds in inode "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) "0x%lx.", idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* If the keys match perfectly, we setup @ictx and return 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if ((key_len == le16_to_cpu(ie->key_length)) && !memcmp(key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) &ie->key, key_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) ia_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ictx->is_in_root = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) ictx->actx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ictx->base_ni = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ictx->ia = ia;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ictx->page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * Not a perfect match, need to do full blown collation so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * know which way in the B+tree we have to go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) rc = ntfs_collate(vol, idx_ni->itype.index.collation_rule, key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) key_len, &ie->key, le16_to_cpu(ie->key_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * If @key collates before the key of the current entry, there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * is definitely no such key in this index but we might need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * descend into the B+tree so we just break out of the loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (rc == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * A match should never happen as the memcmp() call should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * cought it, but we still treat it correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) goto ia_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* The keys are not equal, continue the search. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * We have finished with this index buffer without success. Check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * the presence of a child node and if not present return -ENOENT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!(ie->flags & INDEX_ENTRY_NODE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ntfs_debug("Entry not found.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) goto ia_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ntfs_error(sb, "Index entry with child node found in a leaf "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) "node in inode 0x%lx.", idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) goto unm_err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Child node present, descend into it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) old_vcn = vcn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (vcn >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * If vcn is in the same page cache page as old_vcn we recycle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * the mapped page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (old_vcn << vol->cluster_size_bits >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) PAGE_SHIFT == vcn <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) vol->cluster_size_bits >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) goto fast_descend_into_child_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ntfs_unmap_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) goto descend_into_child_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ntfs_error(sb, "Negative child node vcn in inode 0x%lx.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) idx_ni->mft_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) unm_err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) ntfs_unmap_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (actx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ntfs_attr_put_search_ctx(actx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) unmap_mft_record(base_ni);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) idx_err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) ntfs_error(sb, "Corrupt index. Aborting lookup.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }