libntfs: add ntfs_attr_readall() which reads the entire data from an attribute

edge.strict_endians
szaka 2006-03-27 20:01:36 +00:00
parent b7aee150a4
commit 9b801db7c8
4 changed files with 64 additions and 34 deletions

View File

@ -7,8 +7,10 @@ xx/xx/2006 - 1.13.1-WIP
in $Bitmap (useful to find potentially corrupted files). (Szaka)
- mkntfs: set the physical drive and the extended boot signature to
0x80 in the Extended BPB which are needed to boot from disk. (Szaka)
- ntfsinfo: fix two freed memory usage when dumping $SDS and index
- ntfsinfo: fix two freed memory usages when dumping $SDS and index
allocation entries. (Szaka)
- libntfs: add ntfs_attr_readall() which reads the entire data
from an ntfs attribute. (Szaka)
27/02/2006 - 1.13.0 - Lots and lots and lots of fixes and enhancements.

View File

@ -270,6 +270,9 @@ extern s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count,
extern s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count,
const void *b);
extern void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type,
ntfschar *name, u32 name_len, s64 *data_size);
extern s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos,
const s64 bk_cnt, const u32 bk_size, void *dst);
extern s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos,

View File

@ -4992,3 +4992,54 @@ int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize)
ntfs_inode_update_time(na->ni);
return ret;
}
/**
* ntfs_attr_readall - read the entire data from an ntfs attribute
* @ni: open ntfs inode in which the ntfs attribute resides
* @type: attribute type
* @name: attribute name in little endian Unicode or AT_UNNAMED or NULL
* @name_len: length of attribute @name in Unicode characters (if @name given)
* @data_size: if non-NULL then store here the data size
*
* This function will read the entire content of an ntfs attribute.
* If @name is AT_UNNAMED then look specifically for an unnamed attribute.
* If @name is NULL then the attribute could be either named or not.
* In both those cases @name_len is not used at all.
*
* On success a buffer is allocated with the content of the attribute
* and which needs to be freed when it's not needed anymore. If the
* @data_size parameter is non-NULL then the data size is set there.
*
* On error NULL is returned with errno set to the error code.
*/
void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type,
ntfschar *name, u32 name_len, s64 *data_size)
{
ntfs_attr *na;
void *data, *ret = NULL;
s64 size;
na = ntfs_attr_open(ni, type, name, name_len);
if (!na) {
ntfs_log_perror("ntfs_attr_open failed");
return NULL;
}
data = malloc(na->data_size);
if (!data) {
ntfs_log_perror("malloc failed");
goto out;
}
size = ntfs_attr_pread(na, 0, na->data_size, data);
if (size != na->data_size) {
ntfs_log_perror("ntfs_attr_pread failed");
free(data);
goto out;
}
ret = data;
if (data_size)
*data_size = size;
out:
ntfs_attr_close(na);
return ret;
}

View File

@ -1069,37 +1069,6 @@ static void ntfs_dump_sds_entry(SECURITY_DESCRIPTOR_HEADER *sds)
ntfs_dump_security_descriptor(sd, "\t");
}
static void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type,
ntfschar *name, u32 name_len, s64 *data_size)
{
ntfs_attr *na;
void *data, *ret = NULL;
s64 size;
na = ntfs_attr_open(ni, type, name, name_len);
if (!na) {
ntfs_log_perror("ntfs_attr_open failed");
return NULL;
}
data = malloc(na->data_size);
if (!data) {
ntfs_log_perror("malloc failed");
goto out;
}
size = ntfs_attr_pread(na, 0, na->data_size, data);
if (size != na->data_size) {
ntfs_log_perror("ntfs_attr_pread failed");
free(data);
goto out;
}
ret = data;
if (data_size)
*data_size = size;
out:
ntfs_attr_close(na);
return ret;
}
static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni)
{
@ -1125,8 +1094,10 @@ static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni)
return;
sd = sds = ntfs_attr_readall(ni, AT_DATA, name, name_len, &data_size);
if (!sd)
if (!sd) {
ntfs_log_perror("ntfs_attr_readall failed");
return;
}
/*
* FIXME: The right way is based on the indexes, so we couldn't
* miss real entries. For now, dump until it makes sense.
@ -1650,12 +1621,15 @@ static void ntfs_dump_index_allocation(ATTR_RECORD *attr, ntfs_inode *ni)
name_len = attr->name_length;
byte = bitmap = ntfs_attr_readall(ni, AT_BITMAP, name, name_len, NULL);
if (!byte)
if (!byte) {
ntfs_log_perror("ntfs_attr_readall failed");
return;
}
tmp_alloc = allocation = ntfs_attr_readall(ni, AT_INDEX_ALLOCATION,
name, name_len, &data_size);
if (!tmp_alloc) {
ntfs_log_perror("ntfs_attr_readall failed");
free(bitmap);
return;
}