From ddc558f1ec9014e023abdd2878c7bc4b9a0777bb Mon Sep 17 00:00:00 2001 From: szaka Date: Mon, 27 Mar 2006 21:14:56 +0000 Subject: [PATCH] libntfs: add ntfs_index_root_get() which reads the index root of an attribute --- ChangeLog | 2 ++ include/ntfs/index.h | 2 ++ libntfs/index.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ ntfsprogs/ntfsinfo.c | 41 ++------------------------------------- 4 files changed, 52 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a420b34..6b3c45e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ xx/xx/2006 - 1.13.1-WIP allocation entries. (Szaka) - libntfs: add ntfs_attr_readall() which reads the entire data from an ntfs attribute. (Szaka) + - libntfs: add ntfs_index_root_get() which reads the index root of + an attribute. (Szaka) 27/02/2006 - 1.13.0 - Lots and lots and lots of fixes and enhancements. diff --git a/include/ntfs/index.h b/include/ntfs/index.h index c34da33d..4789bbff 100644 --- a/include/ntfs/index.h +++ b/include/ntfs/index.h @@ -101,6 +101,8 @@ extern int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, MFT_REF mref); extern int ntfs_index_rm(ntfs_index_context *ictx); +extern INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr); + /** * ntfs_index_entry_mark_dirty - mark an index entry dirty * @ictx: ntfs index context describing the index entry diff --git a/libntfs/index.c b/libntfs/index.c index 015e18af..4de1da4b 100644 --- a/libntfs/index.c +++ b/libntfs/index.c @@ -928,3 +928,49 @@ INDEX_ENTRY * ntfs_ie_remove_name(INDEX_ENTRY *ie) #endif /* NTFS_RICH */ +/** + * ntfs_index_root_get - read the index root of an attribute + * @ni: open ntfs inode in which the ntfs attribute resides + * @attr: attribute for which we want its index root + * + * This function will read the related index root an ntfs attribute. + * + * On success a buffer is allocated with the content of the index root + * and which needs to be freed when it's not needed anymore. + * + * On error NULL is returned with errno set to the error code. + */ +INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr) +{ + ntfs_attr_search_ctx *ctx; + ntfschar *name; + INDEX_ROOT *root = NULL; + + name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)); + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) { + ntfs_log_perror("ntfs_get_search_ctx failed"); + return NULL; + } + + if (ntfs_attr_lookup(AT_INDEX_ROOT, name, attr->name_length, 0, 0, NULL, + 0, ctx)) { + ntfs_log_perror("ntfs_attr_lookup failed"); + goto out; + } + + root = malloc(sizeof(INDEX_ROOT)); + if (!root) { + ntfs_log_perror("malloc failed"); + goto out; + } + + *root = *((INDEX_ROOT *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset))); +out: + ntfs_attr_put_search_ctx(ctx); + return root; +} + + diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 2780b6e5..2c4cecca 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -72,6 +72,7 @@ #include "attrib.h" #include "layout.h" #include "inode.h" +#include "index.h" #include "utils.h" #include "security.h" #include "mst.h" @@ -1551,44 +1552,6 @@ static void ntfs_dump_attr_index_root(ATTR_RECORD *attr, ntfs_inode *ni) ntfs_dump_index_entries(entry, type)); } -/** - * get_index_root() - * - * determine size, type and the collation rule of INDX record - */ -static INDEX_ROOT *get_index_root(ntfs_inode *ni, ATTR_RECORD *attr) -{ - ntfs_attr_search_ctx *ctx; - ntfschar *name; - INDEX_ROOT *root = NULL; - - name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)); - - ctx = ntfs_attr_get_search_ctx(ni, NULL); - if (!ctx) { - ntfs_log_perror("ntfs_get_search_ctx failed"); - return NULL; - } - - if (ntfs_attr_lookup(AT_INDEX_ROOT, name, attr->name_length, 0, 0, NULL, - 0, ctx)) { - ntfs_log_perror("ntfs_attr_lookup failed"); - goto out; - } - - root = malloc(sizeof(INDEX_ROOT)); - if (!root) { - ntfs_log_perror("malloc failed"); - goto out; - } - - *root = *((INDEX_ROOT *)((u8 *)ctx->attr + - le16_to_cpu(ctx->attr->value_offset))); -out: - ntfs_attr_put_search_ctx(ctx); - return root; -} - /** * ntfs_dump_attr_index_allocation() * @@ -1608,7 +1571,7 @@ static void ntfs_dump_index_allocation(ATTR_RECORD *attr, ntfs_inode *ni) u32 name_len; s64 data_size; - index_root = get_index_root(ni, attr); + index_root = ntfs_index_root_get(ni, attr); if (!index_root) { ntfs_log_perror("Failed to read $INDEX_ROOT attribute"); return;