From 31a807d4fd55aa0ae4b12e0f19a97f96d25b2255 Mon Sep 17 00:00:00 2001 From: szaka Date: Sun, 22 Mar 2009 13:32:34 +0000 Subject: [PATCH] enlarge INDEX_ROOT if ATTRIBUTE_LIST addition will be avoidable --- libntfs-3g/attrib.c | 8 ++++++++ libntfs-3g/index.c | 14 +++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index c0cac743..d5a43578 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3400,6 +3400,14 @@ int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size) "(%u > %u)\n", new_muse, alloc_size); return -1; } + + if (a->type == AT_INDEX_ROOT && new_size > attr_size && + new_muse + 120 > alloc_size) { + errno = ENOSPC; + ntfs_log_trace("Too big INDEX_ROOT (%u > %u)\n", + new_muse, alloc_size); + return -1; + } /* Move attributes following @a to their new location. */ memmove((u8 *)a + new_size, (u8 *)a + attr_size, diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index f759b17d..acd6394c 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -1228,12 +1228,16 @@ static int ntfs_ir_make_space(ntfs_index_context *icx, int data_size) int ret; ntfs_log_trace("Entering\n"); + + ret = ntfs_ir_truncate(icx, data_size); + if (ret == STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT) { - ret = ntfs_ir_reparent(icx); - if (ret == STATUS_OK) - ret = STATUS_KEEP_SEARCHING; - else - ntfs_log_perror("Failed to nodify INDEX_ROOT"); + ret = ntfs_ir_reparent(icx); + if (ret == STATUS_OK) + ret = STATUS_KEEP_SEARCHING; + else + ntfs_log_perror("Failed to nodify INDEX_ROOT"); + } return ret; }