Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv7324/ntfstools
Modified Files:
mkntfs.c ntfsdump_logfile.c
Log Message:
Remove find_first_attr and make all users use get_attr_search_ctx + find_attr instead.
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -U2 -r1.60 -r1.61
--- mkntfs.c 12 Mar 2002 22:11:02 -0000 1.60
+++ mkntfs.c 14 Apr 2002 15:26:24 -0000 1.61
@@ -110,4 +110,5 @@
#include "disk_io.h"
#include "attrib.h"
+#include "bitmap.h"
extern const unsigned char attrdef_ntfs12_array[2400];
@@ -1183,5 +1184,5 @@
const char *val, const __s64 val_len)
{
- attr_search_context ctx;
+ attr_search_context *ctx;
ATTR_RECORD *a;
__u16 hdr_size;
@@ -1208,26 +1209,27 @@
uname = NULL;
/* Check if the attribute is already there. */
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- if (find_first_attr(type, uname, name_len, ic, upcase, upcase_len,
- NULL, 0, &ctx)) {
- if (uname)
- free(uname);
- return -EEXIST;
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ Eprintf("Failed to allocate attribute search context.\n");
+ err = -ENOMEM;
+ goto err_out;
+ }
+ if (find_attr(type, uname, name_len, ic, upcase, upcase_len, NULL, 0,
+ ctx)) {
+ err = -EEXIST;
+ goto err_out;
}
- a = ctx.attr;
+ a = ctx->attr;
if (flags & ATTR_COMPRESSION_MASK) {
Eprintf("Compressed attributes not supported yet.\n");
// FIXME: Compress attribute into a temporary buffer, set
// val accordingly and save the compressed size.
- if (uname)
- free(uname);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
if (flags & (ATTR_IS_ENCRYPTED || ATTR_IS_SPARSE)) {
Eprintf("Encrypted/sparse attributes not supported yet.\n");
- if (uname)
- free(uname);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
if (flags & ATTR_COMPRESSION_MASK) {
@@ -1254,7 +1256,6 @@
if (highest_vcn * opt.cluster_size < val_len) {
Eprintf("BUG: Allocated size is smaller than data size!\n");
- if (uname)
- free(uname);
- return -EINVAL;
+ err = -EINVAL;
+ goto err_out;
}
err = make_room_for_attribute(m, (char*)a, asize);
@@ -1274,7 +1275,6 @@
// FIXME: the check for needing extension records should be
// earlier on as it is very quick: asize > m->bytes_allocated?
- if (uname)
- free(uname);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
#ifdef DEBUG
@@ -1283,7 +1283,5 @@
"record(): make_room_for_attribute() returned "
"error: EINVAL!\n");
- if (uname)
- free(uname);
- return err;
+ goto err_out;
}
#endif
@@ -1339,4 +1337,7 @@
"error %i.\n", err < 0 ? err : bw);
}
+err_out:
+ if (ctx)
+ put_attr_search_ctx(ctx);
if (uname)
free(uname);
@@ -1350,5 +1351,5 @@
const ATTR_FLAGS flags, const char *val, const __s64 val_len)
{
- attr_search_context ctx;
+ attr_search_context *ctx;
ATTR_RECORD *a;
__u16 hdr_size;
@@ -1375,26 +1376,27 @@
uname = NULL;
/* Check if the attribute is already there. */
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- if (find_first_attr(type, uname, name_len, ic, upcase, upcase_len,
- NULL, 0, &ctx)) {
- if (uname)
- free(uname);
- return -EEXIST;
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ Eprintf("Failed to allocate attribute search context.\n");
+ err = -ENOMEM;
+ goto err_out;
+ }
+ if (find_attr(type, uname, name_len, ic, upcase, upcase_len, NULL, 0,
+ ctx)) {
+ err = -EEXIST;
+ goto err_out;
}
- a = ctx.attr;
+ a = ctx->attr;
if (flags & ATTR_COMPRESSION_MASK) {
Eprintf("Compressed attributes not supported yet.\n");
// FIXME: Compress attribute into a temporary buffer, set
// val accordingly and save the compressed size.
- if (uname)
- free(uname);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
if (flags & (ATTR_IS_ENCRYPTED || ATTR_IS_SPARSE)) {
Eprintf("Encrypted/sparse attributes not supported yet.\n");
- if (uname)
- free(uname);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
if (val_len) {
@@ -1402,10 +1404,8 @@
opt.cluster_size - 1) / opt.cluster_size);
if (!rl) {
- err = errno;
+ err = -errno;
Eprintf("Failed to allocate scattered clusters: %s\n",
- strerror(err));
- if (uname)
- free(uname);
- return -err;
+ strerror(-err));
+ goto err_out;
}
} else
@@ -1444,9 +1444,6 @@
// FIXME: the check for needing extension records should be
// earlier on as it is very quick: asize > m->bytes_allocated?
- if (uname)
- free(uname);
- if (rl)
- free(rl);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
#ifdef DEBUG
@@ -1455,9 +1452,5 @@
"mft_record(): make_room_for_attribute() "
"returned error: EINVAL!\n");
- if (uname)
- free(uname);
- if (rl)
- free(rl);
- return err;
+ goto err_out;
}
#endif
@@ -1515,4 +1508,7 @@
"error %i.\n", err < 0 ? err : bw);
}
+err_out:
+ if (ctx)
+ put_attr_search_ctx(ctx);
if (uname)
free(uname);
@@ -1529,5 +1525,5 @@
const char *val, const __u32 val_len)
{
- attr_search_context ctx;
+ attr_search_context *ctx;
ATTR_RECORD *a;
int asize, err, i;
@@ -1547,13 +1543,16 @@
uname = NULL;
/* Check if the attribute is already there. */
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- if (find_first_attr(type, uname, name_len, ic, upcase, upcase_len,
- val, val_len, &ctx)) {
- if (uname)
- free(uname);
- return -EEXIST;
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ Eprintf("Failed to allocate attribute search context.\n");
+ err = -ENOMEM;
+ goto err_out;
+ }
+ if (find_attr(type, uname, name_len, ic, upcase, upcase_len, val,
+ val_len, ctx)) {
+ err = -EEXIST;
+ goto err_out;
}
- a = ctx.attr;
+ a = ctx->attr;
/* sizeof(resident attribute record header) == 24 */
asize = (24 + (name_len + 7 & ~7) + val_len) + 7 & ~7;
@@ -1574,7 +1573,6 @@
// FIXME: the check for needing extension records should be
// earlier on as it is very quick: asize > m->bytes_allocated?
- if (uname)
- free(uname);
- return -ENOTSUP;
+ err = -ENOTSUP;
+ goto err_out;
}
#ifdef DEBUG
@@ -1583,7 +1581,5 @@
"record(): make_room_for_attribute() returned "
"error: EINVAL!\n");
- if (uname)
- free(uname);
- return err;
+ goto err_out;
}
#endif
@@ -1603,9 +1599,12 @@
if (name_len)
memcpy((char*)a + 24, uname, name_len << 1);
+err_out:
+ if (ctx)
+ put_attr_search_ctx(ctx);
if (uname)
free(uname);
if (val_len)
memcpy((char*)a + le16_to_cpu(a->value_offset), val, val_len);
- return 0;
+ return err;
}
@@ -1657,5 +1656,5 @@
const FILE_NAME_TYPE_FLAGS file_name_type)
{
- attr_search_context ctx;
+ attr_search_context *ctx;
STANDARD_INFORMATION *si;
FILE_NAME_ATTR *fn;
@@ -1663,24 +1662,33 @@
/* Check if the attribute is already there. */
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- if (!find_first_attr($STANDARD_INFORMATION, NULL, 0, 0, NULL, 0,
- NULL, 0, &ctx)) {
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ Eprintf("Failed to allocate attribute search context.\n");
+ return -ENOMEM;
+ }
+ if (!find_attr($STANDARD_INFORMATION, NULL, 0, 0, NULL, 0, NULL, 0,
+ ctx)) {
Eprintf("BUG: Standard information attribute not present in "
"file record\n");
+ put_attr_search_ctx(ctx);
return -EINVAL;
}
- si = (STANDARD_INFORMATION*)((char*)ctx.attr +
- le16_to_cpu(ctx.attr->value_offset));
+ si = (STANDARD_INFORMATION*)((char*)ctx->attr +
+ le16_to_cpu(ctx->attr->value_offset));
i = (strlen(file_name) + 1) * sizeof(uchar_t);
fn_size = sizeof(FILE_NAME_ATTR) + i;
fn = (FILE_NAME_ATTR*)malloc(fn_size);
- if (!fn)
+ if (!fn) {
+ put_attr_search_ctx(ctx);
return -errno;
+ }
fn->parent_directory = parent_dir;
+
fn->creation_time = si->creation_time;
fn->last_data_change_time = si->last_data_change_time;
fn->last_mft_change_time = si->last_mft_change_time;
fn->last_access_time = si->last_access_time;
+ put_attr_search_ctx(ctx);
+
fn->allocated_size = cpu_to_le64(allocated_size);
fn->data_size = cpu_to_le64(data_size);
@@ -2012,9 +2020,9 @@
INDEX_ALLOCATION **index)
{
- attr_search_context ctx;
+ attr_search_context *ctx;
ATTR_RECORD *a;
INDEX_ROOT *r;
INDEX_ENTRY *re, *ae;
- INDEX_ALLOCATION *ia_val;
+ INDEX_ALLOCATION *ia_val = NULL;
uchar_t *uname;
char bmp[8];
@@ -2035,15 +2043,22 @@
uname = NULL;
/* Find the index root attribute. */
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- err = find_first_attr($INDEX_ROOT, uname, name_len, ic, upcase,
- upcase_len, NULL, 0, &ctx);
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ Eprintf("Failed to allocate attribute search context.\n");
+ return -ENOMEM;
+ }
+ err = find_attr($INDEX_ROOT, uname, name_len, ic, upcase, upcase_len,
+ NULL, 0, ctx);
if (uname)
free(uname);
- if (!err)
- return -ENOTDIR;
- a = ctx.attr;
- if (a->non_resident || a->flags)
- return -EINVAL;
+ if (!err) {
+ err = -ENOTDIR;
+ goto err_out;
+ }
+ a = ctx->attr;
+ if (a->non_resident || a->flags) {
+ err = -EINVAL;
+ goto err_out;
+ }
r = (INDEX_ROOT*)((char*)a + le16_to_cpu(a->value_offset));
re_end = (char*)r + le32_to_cpu(a->value_length);
@@ -2052,13 +2067,15 @@
index_block_size = le32_to_cpu(r->index_block_size);
memset(bmp, 0, sizeof(bmp));
- ntfs_set_bit(&bmp, 0ULL, 1);
+ ntfs_set_bit(bmp, 0ULL, 1);
/* Bitmap has to be at least 8 bytes in size. */
err = add_attr_bitmap(m, name, name_len, ic, upcase, upcase_len,
(char*)&bmp, sizeof(bmp));
if (err)
- return err;
+ goto err_out;
ia_val = calloc(1, index_block_size);
- if (!ia_val)
- return -errno;
+ if (!ia_val) {
+ err = -errno;
+ goto err_out;
+ }
/* Setup header. */
ia_val->magic = magic_INDX;
@@ -2118,6 +2135,5 @@
// TODO: Remove the added bitmap!
// Revert index root from index allocation.
- free(ia_val);
- return err;
+ goto err_out;
}
/* Set VCN pointer to 0LL. */
@@ -2128,18 +2144,23 @@
Eprintf("pre_write_mst_fixup() failed in "
"upgrade_to_large_index.\n");
- free(ia_val);
- return -EINVAL;
+ err = -EINVAL;
+ goto err_out;
}
err = add_attr_index_alloc(m, name, name_len, ic, upcase, upcase_len,
(char*)ia_val, index_block_size);
- __post_read_mst_fixup((NTFS_RECORD*)ia_val, index_block_size);
+ post_write_mst_fixup((NTFS_RECORD*)ia_val);
if (err) {
// TODO: Remove the added bitmap!
// Revert index root from index allocation.
- free(ia_val);
- return err;
+ goto err_out;
}
*index = ia_val;
return 0;
+err_out:
+ if (ctx)
+ put_attr_search_ctx(ctx);
+ if (ia_val)
+ free(ia_val);
+ return err;
}
@@ -2712,5 +2733,5 @@
ATTR_RECORD *a;
MFT_REF root_ref;
- attr_search_context ctx;
+ attr_search_context *ctx;
char *sd;
NTFS_BOOT_SECTOR *bs;
@@ -3250,15 +3271,19 @@
opt.upcase, opt.upcase_len, &index_block);
if (!err) {
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx)
+ err_exit("Failed to allocate attribute search "
+ "context: %s\n", strerror(errno));
/* There is exactly one file name so this is ok. */
- if (!find_first_attr($FILE_NAME, NULL, 0, 0, NULL, 0, NULL, 0,
- &ctx))
+ if (!find_attr($FILE_NAME, NULL, 0, 0, NULL, 0, NULL, 0, ctx)) {
+ put_attr_search_ctx(ctx);
err_exit("BUG: $FILE_NAME attribute not found.\n");
- a = ctx.attr;
+ }
+ a = ctx->attr;
err = insert_file_link_in_dir_index(index_block, root_ref,
(FILE_NAME_ATTR*)((char*)a +
le16_to_cpu(a->value_offset)),
le32_to_cpu(a->value_length));
+ put_attr_search_ctx(ctx);
}
if (err)
@@ -3597,16 +3622,25 @@
err_exit("Not enough memory to allocate internal buffer.\n");;
j = stoucs(ustr, "$I30", i);
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- if (!find_first_attr($INDEX_ALLOCATION, ustr, j, IGNORE_CASE,
- opt.upcase, opt.upcase_len, NULL, 0, &ctx))
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx)
+ err_exit("Failed to allocate attribute search context: %s\n",
+ strerror(errno));
+ if (!find_attr($INDEX_ALLOCATION, ustr, j, IGNORE_CASE, opt.upcase,
+ opt.upcase_len, NULL, 0, ctx)) {
+ put_attr_search_ctx(ctx);
err_exit("BUG: $INDEX_ALLOCATION attribute not found.\n");
- a = ctx.attr;
+ }
+ a = ctx->attr;
rl_index = decompress_run_list(a);
- if (!rl_index)
+ if (!rl_index) {
+ put_attr_search_ctx(ctx);
err_exit("Failed to decompress run list of $INDEX_ALLOCATION "
"attribute.\n");
- if (sle64_to_cpu(a->initialized_size) < i)
+ }
+ if (sle64_to_cpu(a->initialized_size) < i) {
+ put_attr_search_ctx(ctx);
err_exit("BUG: $INDEX_ALLOCATION attribute too short.\n");
+ }
+ put_attr_search_ctx(ctx);
i = sizeof(INDEX_BLOCK) - sizeof(INDEX_HEADER) +
le32_to_cpu(index_block->index.allocated_size);
@@ -3619,14 +3653,19 @@
err_exit("Error writing $INDEX_ALLOCATION.\n");
/* No more changes to @index_block below here so no need for fixup: */
- // __post_read_mst_fixup((NTFS_RECORD*)index_block, i);
+ // post_write_mst_fixup((NTFS_RECORD*)index_block);
Vprintf("Syncing $Bitmap.\n");
m = (MFT_RECORD*)(buf + 6 * opt.mft_record_size);
- memset(&ctx, 0, sizeof(ctx));
- ctx.mrec = m;
- if (!find_first_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, &ctx))
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx)
+ err_exit("Failed to allocate attribute search context: %s\n",
+ strerror(errno));
+ if (!find_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, ctx)) {
+ put_attr_search_ctx(ctx);
err_exit("BUG: $DATA attribute not found.\n");
- a = ctx.attr;
+ }
+ a = ctx->attr;
if (a->non_resident) {
rl = decompress_run_list(a);
+ put_attr_search_ctx(ctx);
if (!rl)
err_exit("decompress_run_list() failed\n");
@@ -3636,7 +3675,9 @@
err_exit("%s\n", lw == -1 ? strerror(errno) :
"unknown error");
- } else
+ } else {
memcpy((char*)a + le16_to_cpu(a->value_offset), lcn_bitmap,
le32_to_cpu(a->value_length));
+ put_attr_search_ctx(ctx);
+ }
/*
* No need to sync $MFT/$BITMAP as that has never been modified since
Index: ntfsdump_logfile.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsdump_logfile.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -U2 -r1.12 -r1.13
--- ntfsdump_logfile.c 6 Dec 2001 01:14:52 -0000 1.12
+++ ntfsdump_logfile.c 14 Apr 2002 15:26:24 -0000 1.13
@@ -67,4 +67,5 @@
unsigned char *lfd = NULL;
ntfs_volume *vol = NULL;
+ attr_search_context *ctx = NULL;
RESTART_PAGE_HEADER *rph;
RESTART_AREA *rr;
@@ -75,5 +76,4 @@
int i, lps, client;
MFT_REF mref;
- attr_search_context ctx;
char zero[4096];
@@ -123,5 +123,4 @@
}
/* Read in $LogFile. */
- memset(&ctx, 0, sizeof(attr_search_context));
*(__u64*)&mref = FILE_$LogFile;
if (__read_file_record(vol, &mref, &m, NULL)) {
@@ -129,7 +128,11 @@
goto error_exit;
}
- ctx.mrec = m;
+ ctx = get_attr_search_ctx(NULL, m);
+ if (!ctx) {
+ perror("Failed to allocate attribute search context");
+ goto error_exit;
+ }
/* Find the $DATA attribute of the $LogFile. */
- if (!find_first_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, &ctx)) {
+ if (!find_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, ctx)) {
fprintf(stderr, "Error: Attribute $DATA was not found in" \
"$LogFile!\n");
@@ -353,4 +356,6 @@
if (lfd)
free(lfd);
+ if (ctx)
+ put_attr_search_ctx(ctx);
if (m)
free(m);
|