diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index ea005468..9367b56a 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3302,10 +3302,9 @@ int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) /* Find place in MFT record where attribute will be moved. */ a = ctx->attr; nctx = ntfs_attr_get_search_ctx(ni, NULL); - if (!nctx) { - ntfs_log_trace("Couldn't obtain search context.\n"); + if (!nctx) return -1; - } + /* * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for * attribute in @ni->mrec, not any extent inode in case if @ni is base @@ -4160,10 +4159,8 @@ retry: base_ni = na->ni; ctx = ntfs_attr_get_search_ctx(base_ni, NULL); - if (!ctx) { - ntfs_log_trace("Couldn't get search context.\n"); + if (!ctx) return -1; - } /* Fill attribute records with new mapping pairs. */ stop_vcn = 0; @@ -4524,10 +4521,9 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) /* Get the first attribute record. */ ctx = ntfs_attr_get_search_ctx(na->ni, NULL); - if (!ctx) { - ntfs_log_trace("Couldn't get attribute search context.\n"); + if (!ctx) return -1; - } + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, 0, NULL, 0, ctx)) { err = errno; @@ -4709,7 +4705,6 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) ctx = ntfs_attr_get_search_ctx(na->ni, NULL); if (!ctx) { err = errno; - ntfs_log_perror("Failed to get search context"); if (na->allocated_size == org_alloc_size) { errno = err; return -1; diff --git a/libntfs-3g/attrlist.c b/libntfs-3g/attrlist.c index 33cb3e27..9c62f316 100644 --- a/libntfs-3g/attrlist.c +++ b/libntfs-3g/attrlist.c @@ -145,7 +145,6 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; - ntfs_log_trace("Failed to obtain attribute search context.\n"); goto err_out; } if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*) diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index 383d27fb..227ce53a 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -433,10 +433,8 @@ static INDEX_ROOT *ntfs_ir_lookup(ntfs_inode *ni, ntfschar *name, ntfs_log_trace("Entering\n"); *ctx = ntfs_attr_get_search_ctx(ni, NULL); - if (!*ctx) { - ntfs_log_perror("Failed to get $INDEX_ROOT search context"); + if (!*ctx) return NULL; - } if (ntfs_attr_lookup(AT_INDEX_ROOT, name, name_len, CASE_SENSITIVE, 0, NULL, 0, *ctx)) { diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index fee01873..7bf90348 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -814,7 +814,6 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) ctx = ntfs_attr_get_search_ctx(ni, NULL); if (!ctx) { err = errno; - ntfs_log_trace("Couldn't get search context.\n"); goto err_out; } /* Walk through all attributes. */ @@ -997,12 +996,8 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size) return 0; ctx = ntfs_attr_get_search_ctx(ni, NULL); - if (!ctx) { - err = errno; - ntfs_log_trace("Failed to get attribute search context.\n"); - errno = err; + if (!ctx) return -1; - } /* * Chkdsk complain if $STANDARD_INFORMATION is not in the base MFT diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index d9cc3bc9..900a284b 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -656,10 +656,9 @@ static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) * (non-terminator) runlist element of mft bitmap. */ ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); - if (!ctx) { - ntfs_log_error("Failed to get search context.\n"); + if (!ctx) goto undo_alloc; - } + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { ntfs_log_error("Failed to find last attribute extent of " @@ -808,10 +807,9 @@ static int ntfs_mft_bitmap_extend_initialized(ntfs_volume *vol) mftbmp_na = vol->mftbmp_na; ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); - if (!ctx) { - ntfs_log_error("Failed to get search context.\n"); + if (!ctx) return -1; - } + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " @@ -844,10 +842,9 @@ static int ntfs_mft_bitmap_extend_initialized(ntfs_volume *vol) err = EIO; /* Try to recover from the error. */ ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); - if (!ctx) { - ntfs_log_error("Failed to get search context.%s\n", es); + if (!ctx) goto err_out; - } + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " @@ -969,10 +966,9 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) ; /* Update the attribute record as well. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); - if (!ctx) { - ntfs_log_error("Failed to get search context.\n"); + if (!ctx) goto undo_alloc; - } + if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { ntfs_log_error("Failed to find last attribute extent of " @@ -1159,10 +1155,9 @@ static int ntfs_mft_record_init(ntfs_volume *vol, s64 size) /* Update the mft data attribute record to reflect the new sizes. */ ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); - if (!ctx) { - ntfs_log_error("Failed to get search context.\n"); + if (!ctx) goto undo_data_init; - } + if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Failed to find first attribute extent of " diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index b2f30c4b..d8f9c9bd 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -219,10 +219,9 @@ static int ntfs_mft_load(ntfs_volume *vol) goto io_error_exit; } ctx = ntfs_attr_get_search_ctx(vol->mft_ni, NULL); - if (!ctx) { - ntfs_log_perror("Failed to allocate attribute search context"); + if (!ctx) goto error_exit; - } + if (p2n(ctx->attr) < p2n(mb) || (char*)ctx->attr > (char*)mb + vol->mft_record_size) { ntfs_log_error("$MFT is corrupt.\n"); @@ -964,11 +963,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags) } /* Get a search context for the $Volume/$VOLUME_INFORMATION lookup. */ ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); - if (!ctx) { - ntfs_log_debug(FAILED); - ntfs_log_perror("Failed to allocate attribute search context"); + if (!ctx) goto error_exit; - } + /* Find the $VOLUME_INFORMATION attribute. */ if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { @@ -1461,10 +1458,9 @@ int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags) } /* Get a pointer to the volume information attribute. */ ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); - if (!ctx) { - ntfs_log_perror("Failed to allocate attribute search context"); + if (!ctx) return -1; - } + if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { ntfs_log_error("Attribute $VOLUME_INFORMATION was not found "