|
Kmods SIG |
d83023 |
From 8e69212253d320d4768071086b1111e6ab91d9bd Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
d83023 |
From: Kari Argillander <kari.argillander@gmail.com>
|
|
Kmods SIG |
d83023 |
Date: Thu, 2 Sep 2021 18:40:50 +0300
|
|
Kmods SIG |
d83023 |
Subject: [Backport 8e69212253d3] src: Always use binary search with entry
|
|
Kmods SIG |
d83023 |
search
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
We do not have any reason to keep old linear search in. Before this was
|
|
Kmods SIG |
d83023 |
used for error path or if table was so big that it cannot be allocated.
|
|
Kmods SIG |
d83023 |
Current binary search implementation won't need error path. Remove old
|
|
Kmods SIG |
d83023 |
references to linear entry search.
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
|
|
Kmods SIG |
d83023 |
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
|
|
Kmods SIG |
d83023 |
---
|
|
Kmods SIG |
d83023 |
src/index.c | 50 ++++++------------------------------------------
|
|
Kmods SIG |
d83023 |
src/ntfs.h | 3 ---
|
|
Kmods SIG |
d83023 |
2 files changed, 6 insertions(+), 47 deletions(-)
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
diff --git a/src/index.c b/src/index.c
|
|
Kmods SIG |
d83023 |
index 3ad1ee608e531ea7c7793e691fe706ee0a6c33a4..4f71a91f07d9fc56efe6a80ebf52995e2e9a65de 100644
|
|
Kmods SIG |
d83023 |
--- a/src/index.c
|
|
Kmods SIG |
d83023 |
+++ b/src/index.c
|
|
Kmods SIG |
d83023 |
@@ -671,22 +671,16 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,
|
|
Kmods SIG |
d83023 |
const struct INDEX_HDR *hdr, const void *key,
|
|
Kmods SIG |
d83023 |
size_t key_len, const void *ctx, int *diff)
|
|
Kmods SIG |
d83023 |
{
|
|
Kmods SIG |
d83023 |
- struct NTFS_DE *e;
|
|
Kmods SIG |
d83023 |
+ struct NTFS_DE *e, *found = NULL;
|
|
Kmods SIG |
d83023 |
NTFS_CMP_FUNC cmp = indx->cmp;
|
|
Kmods SIG |
d83023 |
+ int min_idx = 0, mid_idx, max_idx = 0;
|
|
Kmods SIG |
d83023 |
+ int diff2;
|
|
Kmods SIG |
d83023 |
+ int table_size = 8;
|
|
Kmods SIG |
d83023 |
u32 e_size, e_key_len;
|
|
Kmods SIG |
d83023 |
u32 end = le32_to_cpu(hdr->used);
|
|
Kmods SIG |
d83023 |
u32 off = le32_to_cpu(hdr->de_off);
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
-#ifdef NTFS3_INDEX_BINARY_SEARCH
|
|
Kmods SIG |
d83023 |
- struct NTFS_DE *found = NULL;
|
|
Kmods SIG |
d83023 |
- int min_idx = 0, mid_idx, max_idx = 0;
|
|
Kmods SIG |
d83023 |
- int table_size = 8;
|
|
Kmods SIG |
d83023 |
- int diff2;
|
|
Kmods SIG |
d83023 |
u16 offs[128];
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
- if (end > 0x10000)
|
|
Kmods SIG |
d83023 |
- goto next;
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
fill_table:
|
|
Kmods SIG |
d83023 |
if (off + sizeof(struct NTFS_DE) > end)
|
|
Kmods SIG |
d83023 |
return NULL;
|
|
Kmods SIG |
d83023 |
@@ -720,7 +714,8 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,
|
|
Kmods SIG |
d83023 |
return NULL;
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
max_idx = 0;
|
|
Kmods SIG |
d83023 |
- table_size = min(table_size * 2, 128);
|
|
Kmods SIG |
d83023 |
+ table_size = min(table_size * 2,
|
|
Kmods SIG |
d83023 |
+ (int)ARRAY_SIZE(offs));
|
|
Kmods SIG |
d83023 |
goto fill_table;
|
|
Kmods SIG |
d83023 |
}
|
|
Kmods SIG |
d83023 |
} else if (diff2 < 0) {
|
|
Kmods SIG |
d83023 |
@@ -744,39 +739,6 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,
|
|
Kmods SIG |
d83023 |
e = Add2Ptr(hdr, offs[mid_idx]);
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
goto binary_search;
|
|
Kmods SIG |
d83023 |
-#endif
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
-next:
|
|
Kmods SIG |
d83023 |
- /*
|
|
Kmods SIG |
d83023 |
- * Entries index are sorted.
|
|
Kmods SIG |
d83023 |
- * Enumerate all entries until we find entry
|
|
Kmods SIG |
d83023 |
- * that is <= to the search value.
|
|
Kmods SIG |
d83023 |
- */
|
|
Kmods SIG |
d83023 |
- if (off + sizeof(struct NTFS_DE) > end)
|
|
Kmods SIG |
d83023 |
- return NULL;
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- e = Add2Ptr(hdr, off);
|
|
Kmods SIG |
d83023 |
- e_size = le16_to_cpu(e->size);
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- if (e_size < sizeof(struct NTFS_DE) || off + e_size > end)
|
|
Kmods SIG |
d83023 |
- return NULL;
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- off += e_size;
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- e_key_len = le16_to_cpu(e->key_size);
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- *diff = (*cmp)(key, key_len, e + 1, e_key_len, ctx);
|
|
Kmods SIG |
d83023 |
- if (!*diff)
|
|
Kmods SIG |
d83023 |
- return e;
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- if (*diff <= 0)
|
|
Kmods SIG |
d83023 |
- return e;
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
- if (de_is_last(e)) {
|
|
Kmods SIG |
d83023 |
- *diff = 1;
|
|
Kmods SIG |
d83023 |
- return e;
|
|
Kmods SIG |
d83023 |
- }
|
|
Kmods SIG |
d83023 |
- goto next;
|
|
Kmods SIG |
d83023 |
}
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
/*
|
|
Kmods SIG |
d83023 |
diff --git a/src/ntfs.h b/src/ntfs.h
|
|
Kmods SIG |
d83023 |
index 695b684bce20dd4f274884ba9a1022555b47823a..303a162c31587475adb8c3190b16fa451e9616a7 100644
|
|
Kmods SIG |
d83023 |
--- a/src/ntfs.h
|
|
Kmods SIG |
d83023 |
+++ b/src/ntfs.h
|
|
Kmods SIG |
d83023 |
@@ -21,9 +21,6 @@
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
/* TODO: Check 4K MFT record and 512 bytes cluster. */
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
-/* Activate this define to use binary search in indexes. */
|
|
Kmods SIG |
d83023 |
-#define NTFS3_INDEX_BINARY_SEARCH
|
|
Kmods SIG |
d83023 |
-
|
|
Kmods SIG |
d83023 |
/* Check each run for marked clusters. */
|
|
Kmods SIG |
d83023 |
#define NTFS3_CHECK_FREE_CLST
|
|
Kmods SIG |
d83023 |
|
|
Kmods SIG |
d83023 |
--
|
|
Kmods SIG |
d83023 |
2.31.1
|
|
Kmods SIG |
d83023 |
|