libntfs: add ntfs_index_root_get() which reads the index root of an attribute

edge.strict_endians
szaka 2006-03-27 21:14:56 +00:00
parent a8e6766e43
commit ddc558f1ec
4 changed files with 52 additions and 39 deletions

View File

@ -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.

View File

@ -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

View File

@ -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;
}

View File

@ -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;