From 048a1857be8a847821a603ad077c59a71c213317 Mon Sep 17 00:00:00 2001 From: cha0smaster Date: Sat, 4 Jun 2005 15:20:00 +0000 Subject: [PATCH] Fix some bugs and warnings in code that I commited tonight. --- include/ntfs/index.h | 7 +++++- libntfs/collate.c | 20 +++++++-------- libntfs/index.c | 60 ++++++++++++++++---------------------------- 3 files changed, 38 insertions(+), 49 deletions(-) diff --git a/include/ntfs/index.h b/include/ntfs/index.h index 27fcf719..2093e5c1 100644 --- a/include/ntfs/index.h +++ b/include/ntfs/index.h @@ -31,6 +31,8 @@ /** * @ni: inode containing the @entry described by this context + * @name: name of the which context describes + * @name_len: length of the index name * @entry: index entry (points into @ir or @ia) * @data: index entry data (points into @entry) * @data_len: length in bytes of @data @@ -70,6 +72,8 @@ */ typedef struct { ntfs_inode *ni; + ntfschar *name; + u32 name_len; INDEX_ENTRY *entry; void *data; u16 data_len; @@ -83,7 +87,8 @@ typedef struct { u32 block_size; } ntfs_index_context; -extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni); +extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, + ntfschar *name, u32 name_len); extern void ntfs_index_ctx_put(ntfs_index_context *ictx); extern int ntfs_index_lookup(const void *key, const int key_len, diff --git a/libntfs/collate.c b/libntfs/collate.c index 4da13ef4..8a778ae7 100644 --- a/libntfs/collate.c +++ b/libntfs/collate.c @@ -24,7 +24,7 @@ #include "debug.h" #include "unistr.h" -static int ntfs_collate_binary(ntfs_volume *vol, +static int ntfs_collate_binary(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { @@ -42,7 +42,7 @@ static int ntfs_collate_binary(ntfs_volume *vol, return rc; } -static int ntfs_collate_ntofs_ulong(ntfs_volume *vol, +static int ntfs_collate_ntofs_ulong(ntfs_volume *vol __attribute__((unused)), const void *data1, const int data1_len, const void *data2, const int data2_len) { @@ -51,7 +51,7 @@ static int ntfs_collate_ntofs_ulong(ntfs_volume *vol, ntfs_debug("Entering."); if (data1_len != data2_len || data1_len != 4) { - ntfs_error("data1_len or/and data2_len not equal to 4."); + ntfs_error(, "data1_len or/and data2_len not equal to 4."); return NTFS_COLLATION_ERROR; } d1 = le32_to_cpup(data1); @@ -69,14 +69,14 @@ static int ntfs_collate_ntofs_ulong(ntfs_volume *vol, } static int ntfs_collate_file_name(ntfs_volume *vol, - const void *data1, const int data1_len, - const void *data2, const int data2_len) { + const void *data1, const int data1_len __attribute__((unused)), + const void *data2, const int data2_len __attribute__((unused))){ int rc; - FILE_NAME_ATTR *fn1, *fn2; + const FILE_NAME_ATTR *fn1, *fn2; ntfs_debug("Entering."); - fn1 = (FILE_NAME_ATTR *)data1; - fn2 = (FILE_NAME_ATTR *)data2; + fn1 = (const FILE_NAME_ATTR *)data1; + fn2 = (const FILE_NAME_ATTR *)data2; rc = ntfs_names_collate(fn1->file_name, fn1->file_name_length, fn2->file_name, fn2->file_name_length, NTFS_COLLATION_ERROR, CASE_SENSITIVE, vol->upcase, @@ -127,7 +127,7 @@ int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr, ntfs_debug("Entering."); if (!vol || !data1 || !data2 || data1_len < 0 || data2_len < 0) { - ntfs_error("Invalid arguments passed."); + ntfs_error(, "Invalid arguments passed."); return NTFS_COLLATION_ERROR; } /* @@ -151,6 +151,6 @@ int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr, return ntfs_do_collate0x1[i](vol, data1, data1_len, data2, data2_len); err: - ntfs_error("Unknown collation rule."); + ntfs_error(, "Unknown collation rule."); return NTFS_COLLATION_ERROR; } diff --git a/libntfs/index.c b/libntfs/index.c index 7d6e0c55..9c4919cb 100644 --- a/libntfs/index.c +++ b/libntfs/index.c @@ -29,12 +29,15 @@ /** * ntfs_index_ctx_get - allocate and initialize a new index context - * @idx_ni: ntfs inode with which to initialize the context + * @ni: ntfs inode with which to initialize the context + * @name: name of the which context describes + * @name_len: length of the index name * * Allocate a new index context, initialize it with @ni and return it. * Return NULL if allocation failed. */ -ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni) +ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, + ntfschar *name, u32 name_len) { ntfs_index_context *ictx; @@ -48,7 +51,8 @@ ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni) if (ictx) *ictx = (ntfs_index_context) { .ni = ni, - .ia_dirty = FALSE, + .name = name, + .name_len = name_len }; return ictx; } @@ -144,12 +148,12 @@ int ntfs_index_lookup(const void *key, const int key_len, } /* Find the index root attribute in the mft record. */ - err = ntfs_attr_lookup(AT_INDEX_ROOT, NULL, 0, + err = ntfs_attr_lookup(AT_INDEX_ROOT, ictx->name, ictx->name_len, CASE_SENSITIVE, 0, NULL, 0, actx); if (err) { if (errno == ENOENT) { ntfs_error(sb, "Index root attribute missing in inode " - "0x%lx.", ni->mft_no); + "0x%llx.", ni->mft_no); err = EIO; } else err = errno; @@ -188,14 +192,6 @@ int ntfs_index_lookup(const void *key, const int key_len, */ if (ie->flags & INDEX_ENTRY_END) break; - /* Further bounds checks. */ - if ((u32)sizeof(INDEX_ENTRY_HEADER) + - le16_to_cpu(ie->key_length) > - le16_to_cpu(ie->data_offset) || - (u32)le16_to_cpu(ie->data_offset) + - le16_to_cpu(ie->data_length) > - le16_to_cpu(ie->length)) - goto idx_err_out; /* If the keys match perfectly, we setup @ictx and return 0. */ if ((key_len == le16_to_cpu(ie->key_length)) && !memcmp(key, &ie->key, key_len)) { @@ -205,9 +201,8 @@ ir_done: ictx->ia = NULL; done: ictx->entry = ie; - ictx->data = (u8*)ie + - le16_to_cpu(ie->data_offset); - ictx->data_len = le16_to_cpu(ie->data_length); + ictx->data = (u8*)ie + offsetof(INDEX_ENTRY, key); + ictx->data_len = le16_to_cpu(ie->key_length); ntfs_debug("Done."); if (err) { errno = err; @@ -252,10 +247,11 @@ done: ntfs_attr_put_search_ctx(actx); actx = NULL; /* Open INDEX_ALLOCATION. */ - na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, AT_UNNAMED, 0); + na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, + ictx->name, ictx->name_len); if (!na) { ntfs_error(sb, "No index allocation attribute but index entry " - "requires one. Inode 0x%lx is corrupt or " + "requires one. Inode 0x%llx is corrupt or " "library bug.", ni->mft_no); goto err_out; } @@ -277,21 +273,21 @@ descend_into_child_node: /* Catch multi sector transfer fixup errors. */ if (!ntfs_is_indx_record(ia->magic)) { ntfs_error(sb, "Index record with vcn 0x%llx is corrupt. " - "Corrupt inode 0x%lx. Run chkdsk.", + "Corrupt inode 0x%llx. Run chkdsk.", (long long)vcn, ni->mft_no); goto err_out; } if (sle64_to_cpu(ia->index_block_vcn) != vcn) { ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is " "different from expected VCN (0x%llx). Inode " - "0x%lx is corrupt or driver bug.", + "0x%llx is corrupt or driver bug.", (unsigned long long) sle64_to_cpu(ia->index_block_vcn), (unsigned long long)vcn, ni->mft_no); goto err_out; } if (le32_to_cpu(ia->index.allocated_size) + 0x18 != ictx->block_size) { - ntfs_error(sb, "Index buffer (VCN 0x%llx) of inode 0x%lx has " + ntfs_error(sb, "Index buffer (VCN 0x%llx) of inode 0x%llx has " "a size (%u) differing from the index " "specified size (%u). Inode is corrupt or " "driver bug.", (unsigned long long)vcn, @@ -303,8 +299,8 @@ descend_into_child_node: index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); if (index_end > (u8*)ia + ictx->block_size) { ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of inode " - "0x%lx exceeds maximum size.", - (unsigned long long)vcn, idx_ni->mft_no); + "0x%llx exceeds maximum size.", + (unsigned long long)vcn, ni->mft_no); goto err_out; } /* The first index entry. */ @@ -321,7 +317,7 @@ descend_into_child_node: sizeof(INDEX_ENTRY_HEADER) > index_end || (u8*)ie + le16_to_cpu(ie->length) > index_end) { ntfs_error(sb, "Index entry out of bounds in inode " - "0x%lx.", ni->mft_no); + "0x%llx.", ni->mft_no); goto err_out; } /* @@ -330,17 +326,6 @@ descend_into_child_node: */ if (ie->flags & INDEX_ENTRY_END) break; - /* Further bounds checks. */ - if ((u32)sizeof(INDEX_ENTRY_HEADER) + - le16_to_cpu(ie->key_length) > - le16_to_cpu(ie->data_offset) || - (u32)le16_to_cpu(ie->data_offset) + - le16_to_cpu(ie->data_length) > - le16_to_cpu(ie->length)) { - ntfs_error(sb, "Index entry out of bounds in inode " - "0x%lx.", ni->mft_no); - goto err_out; - } /* If the keys match perfectly, we setup @ictx and return 0. */ if ((key_len == le16_to_cpu(ie->key_length)) && !memcmp(key, &ie->key, key_len)) { @@ -384,14 +369,14 @@ ia_done: } if ((ia->index.flags & NODE_MASK) == LEAF_NODE) { ntfs_error(sb, "Index entry with child node found in a leaf " - "node in inode 0x%lx.", idx_ni->mft_no); + "node in inode 0x%llx.", ni->mft_no); goto err_out; } /* Child node present, descend into it. */ vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8)); if (vcn >= 0) goto descend_into_child_node; - ntfs_error(sb, "Negative child node vcn in inode 0x%lx.", ni->mft_no); + ntfs_error(sb, "Negative child node vcn in inode 0x%llx.", ni->mft_no); err_out: if (na) ntfs_attr_close(na); @@ -407,4 +392,3 @@ idx_err_out: ntfs_error(sb, "Corrupt index. Aborting lookup."); goto err_out; } -