add tabulated logging for the most common ntfs_mft_* functions
parent
a6d8c6b1a6
commit
5dbdb30df8
119
libntfs-3g/mft.c
119
libntfs-3g/mft.c
|
@ -472,7 +472,10 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
u8 *buf, *byte;
|
||||
unsigned int size;
|
||||
u8 pass, b;
|
||||
int ret = -1;
|
||||
|
||||
ntfs_log_enter("Entering\n");
|
||||
|
||||
mftbmp_na = vol->mftbmp_na;
|
||||
/*
|
||||
* Set the end of the pass making sure we do not overflow the mft
|
||||
|
@ -496,13 +499,13 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
/* This happens on a freshly formatted volume. */
|
||||
if (data_pos >= pass_end) {
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
pass_start = data_pos;
|
||||
buf = ntfs_malloc(PAGE_SIZE);
|
||||
if (!buf)
|
||||
return -1;
|
||||
goto leave;
|
||||
|
||||
ntfs_log_debug("Starting bitmap search: pass %u, pass_start 0x%llx, "
|
||||
"pass_end 0x%llx, data_pos 0x%llx.\n", pass,
|
||||
|
@ -523,7 +526,7 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
if (ll < 0) {
|
||||
ntfs_log_perror("Failed to read $MFT bitmap");
|
||||
free(buf);
|
||||
return -1;
|
||||
goto leave;
|
||||
}
|
||||
ntfs_log_debug("Read 0x%llx bytes.\n", (long long)ll);
|
||||
/* If we read at least one byte, search @buf for a zero bit. */
|
||||
|
@ -541,11 +544,13 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
byte = buf + (bit >> 3);
|
||||
if (*byte == 0xff)
|
||||
continue;
|
||||
|
||||
/* Note: ffz() result must be zero based. */
|
||||
b = ntfs_ffz((unsigned long)*byte);
|
||||
if (b < 8 && b >= (bit & 7)) {
|
||||
free(buf);
|
||||
return data_pos + (bit & ~7ull) + b;
|
||||
ret = data_pos + (bit & ~7ull) + b;
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
ntfs_log_debug("After inner for loop: size 0x%x, "
|
||||
|
@ -580,21 +585,15 @@ static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
/* No free mft records in currently initialized mft bitmap. */
|
||||
free(buf);
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
leave:
|
||||
ntfs_log_leave("\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_mft_bitmap_extend_allocation - extend mft bitmap attribute by a cluster
|
||||
* @vol: volume on which to extend the mft bitmap attribute
|
||||
*
|
||||
* Extend the mft bitmap attribute on the ntfs volume @vol by one cluster.
|
||||
*
|
||||
* Note: Only changes allocated_size, i.e. does not touch initialized_size or
|
||||
* data_size.
|
||||
*
|
||||
* Return 0 on success and -1 on error with errno set to the error code.
|
||||
* ntfs_mft_bitmap_extend_allocation_i - see ntfs_mft_bitmap_extend_allocation
|
||||
*/
|
||||
static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol)
|
||||
static int ntfs_mft_bitmap_extend_allocation_i(ntfs_volume *vol)
|
||||
{
|
||||
LCN lcn;
|
||||
s64 ll = 0; /* silence compiler warning */
|
||||
|
@ -778,6 +777,26 @@ undo_alloc:
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_mft_bitmap_extend_allocation - extend mft bitmap attribute by a cluster
|
||||
* @vol: volume on which to extend the mft bitmap attribute
|
||||
*
|
||||
* Extend the mft bitmap attribute on the ntfs volume @vol by one cluster.
|
||||
*
|
||||
* Note: Only changes allocated_size, i.e. does not touch initialized_size or
|
||||
* data_size.
|
||||
*
|
||||
* Return 0 on success and -1 on error with errno set to the error code.
|
||||
*/
|
||||
static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ntfs_log_enter("Entering\n");
|
||||
ret = ntfs_mft_bitmap_extend_allocation_i(vol);
|
||||
ntfs_log_leave("\n");
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* ntfs_mft_bitmap_extend_initialized - extend mft bitmap initialized data
|
||||
* @vol: volume on which to extend the mft bitmap attribute
|
||||
|
@ -896,10 +915,12 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
|
|||
MFT_RECORD *m = NULL; /* silence compiler warning */
|
||||
ATTR_RECORD *a = NULL; /* silence compiler warning */
|
||||
int err, mp_size;
|
||||
int ret = -1;
|
||||
u32 old_alen = 0; /* silence compiler warning */
|
||||
BOOL mp_rebuilt = FALSE;
|
||||
|
||||
ntfs_log_debug("Extending mft data allocation.\n");
|
||||
ntfs_log_enter("Extending mft data allocation.\n");
|
||||
|
||||
mft_na = vol->mft_na;
|
||||
/*
|
||||
* Determine the preferred allocation location, i.e. the last lcn of
|
||||
|
@ -908,13 +929,15 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
|
|||
*/
|
||||
rl = ntfs_attr_find_vcn(mft_na,
|
||||
(mft_na->allocated_size - 1) >> vol->cluster_size_bits);
|
||||
|
||||
if (!rl || !rl->length || rl->lcn < 0) {
|
||||
ntfs_log_error("Failed to determine last allocated "
|
||||
"cluster of mft data attribute.\n");
|
||||
if (rl)
|
||||
errno = EIO;
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
lcn = rl->lcn + rl->length;
|
||||
ntfs_log_debug("Last lcn of mft data attribute is 0x%llx.\n", (long long)lcn);
|
||||
/* Minimum allocation is one mft record worth of clusters. */
|
||||
|
@ -925,18 +948,16 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
|
|||
nr = vol->mft_record_size << 4 >> vol->cluster_size_bits;
|
||||
if (!nr)
|
||||
nr = min_nr;
|
||||
ntfs_log_debug("Trying mft data allocation with default cluster count "
|
||||
"%lli.\n", (long long)nr);
|
||||
|
||||
old_last_vcn = rl[1].vcn;
|
||||
do {
|
||||
rl2 = ntfs_cluster_alloc(vol, old_last_vcn, nr, lcn, MFT_ZONE);
|
||||
if (rl2)
|
||||
break;
|
||||
if (errno != ENOSPC || nr == min_nr) {
|
||||
ntfs_log_perror("Failed to allocate the minimal "
|
||||
"number of clusters (%lli) for the "
|
||||
"mft data attribute.\n", (long long)nr);
|
||||
return -1;
|
||||
ntfs_log_perror("Failed to allocate (%lld) clusters "
|
||||
"for $MFT", (long long)nr);
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* There is not enough space to do the allocation, but there
|
||||
|
@ -947,6 +968,9 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
|
|||
ntfs_log_debug("Retrying mft data allocation with minimal cluster "
|
||||
"count %lli.\n", (long long)nr);
|
||||
} while (1);
|
||||
|
||||
ntfs_log_debug("Allocated %lli clusters.\n", nr);
|
||||
|
||||
rl = ntfs_runlists_merge(mft_na->rl, rl2);
|
||||
if (!rl) {
|
||||
err = errno;
|
||||
|
@ -957,10 +981,10 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
|
|||
"from the mft data attribute.%s\n", es);
|
||||
free(rl2);
|
||||
errno = err;
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
mft_na->rl = rl;
|
||||
ntfs_log_debug("Allocated %lli clusters.\n", nr);
|
||||
|
||||
/* Find the last run in the new runlist. */
|
||||
for (; rl[1].length; rl++)
|
||||
;
|
||||
|
@ -1046,7 +1070,11 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
|
|||
/* Ensure the changes make it to disk. */
|
||||
ntfs_inode_mark_dirty(ctx->ntfs_ino);
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
return 0;
|
||||
ret = 0;
|
||||
out:
|
||||
ntfs_log_leave("\n");
|
||||
return ret;
|
||||
|
||||
restore_undo_alloc:
|
||||
err = errno;
|
||||
ntfs_attr_reinit_search_ctx(ctx);
|
||||
|
@ -1061,7 +1089,7 @@ restore_undo_alloc:
|
|||
* base attribute extent which chkdsk should be able to fix.
|
||||
*/
|
||||
errno = err;
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
m = ctx->mrec;
|
||||
a = ctx->attr;
|
||||
|
@ -1090,7 +1118,7 @@ undo_alloc:
|
|||
if (ctx)
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
errno = err;
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1101,7 +1129,7 @@ static int ntfs_mft_record_init(ntfs_volume *vol, s64 size)
|
|||
s64 old_data_initialized, old_data_size;
|
||||
ntfs_attr_search_ctx *ctx;
|
||||
|
||||
ntfs_log_trace("Entering\n");
|
||||
ntfs_log_enter("Entering\n");
|
||||
|
||||
/* NOTE: Caller must sanity check vol, vol->mft_na and vol->mftbmp_na */
|
||||
|
||||
|
@ -1186,13 +1214,12 @@ static int ntfs_mft_record_init(ntfs_volume *vol, s64 size)
|
|||
// BUG_ON(mft_na->data_size > mft_na->allocated_size);
|
||||
|
||||
/* Sync MFT to minimize data loss if there won't be clean unmount. */
|
||||
if (ntfs_inode_sync(mft_na->ni)) {
|
||||
ntfs_log_error("Failed to sync $MFT.");
|
||||
if (ntfs_inode_sync(mft_na->ni))
|
||||
goto undo_data_init;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
ntfs_log_leave("\n");
|
||||
return ret;
|
||||
|
||||
undo_data_init:
|
||||
|
@ -1289,19 +1316,19 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
s64 ll, bit;
|
||||
ntfs_attr *mft_na, *mftbmp_na;
|
||||
MFT_RECORD *m;
|
||||
ntfs_inode *ni;
|
||||
ntfs_inode *ni = NULL;
|
||||
int err;
|
||||
u16 seq_no, usn;
|
||||
|
||||
if (base_ni)
|
||||
ntfs_log_trace("Entering (allocating an extent mft record for "
|
||||
"base mft record 0x%llx).\n",
|
||||
(long long)base_ni->mft_no);
|
||||
ntfs_log_enter("Entering (allocating an extent mft record for "
|
||||
"base mft record %lld).\n",
|
||||
(long long)base_ni->mft_no);
|
||||
else
|
||||
ntfs_log_trace("Entering (allocating a base mft record).\n");
|
||||
ntfs_log_enter("Entering (allocating a base mft record)\n");
|
||||
if (!vol || !vol->mft_na || !vol->mftbmp_na) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
mft_na = vol->mft_na;
|
||||
|
@ -1309,12 +1336,12 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni)
|
|||
retry:
|
||||
bit = ntfs_mft_bitmap_find_free_rec(vol, base_ni);
|
||||
if (bit >= 0) {
|
||||
ntfs_log_debug("Found free record (#1), bit 0x%llx.\n",
|
||||
ntfs_log_debug("found free record (#1) at %lld\n",
|
||||
(long long)bit);
|
||||
goto found_free_rec;
|
||||
}
|
||||
if (errno != ENOSPC)
|
||||
return NULL;
|
||||
goto out;
|
||||
/*
|
||||
* No free mft records left. If the mft bitmap already covers more
|
||||
* than the currently used mft records, the next records are all free,
|
||||
|
@ -1329,7 +1356,7 @@ retry:
|
|||
bit = ll;
|
||||
if (bit < 24)
|
||||
bit = 24;
|
||||
ntfs_log_debug("Found free record (#2), bit 0x%llx.\n",
|
||||
ntfs_log_debug("found free record (#2) at %lld\n",
|
||||
(long long)bit);
|
||||
goto found_free_rec;
|
||||
}
|
||||
|
@ -1369,14 +1396,13 @@ retry:
|
|||
(long long)mftbmp_na->allocated_size,
|
||||
(long long)mftbmp_na->data_size,
|
||||
(long long)mftbmp_na->initialized_size);
|
||||
ntfs_log_debug("Found free record (#3), bit 0x%llx.\n", (long long)bit);
|
||||
ntfs_log_debug("found free record (#3) at %lld\n", (long long)bit);
|
||||
found_free_rec:
|
||||
/* @bit is the found free mft record, allocate it in the mft bitmap. */
|
||||
if (ntfs_bitmap_set_bit(mftbmp_na, bit)) {
|
||||
ntfs_log_error("Failed to allocate bit in mft bitmap.\n");
|
||||
goto err_out;
|
||||
}
|
||||
ntfs_log_debug("Set bit 0x%llx in mft bitmap.\n", (long long)bit);
|
||||
|
||||
/* The mft bitmap is now uptodate. Deal with mft data attribute now. */
|
||||
ll = (bit + 1) << vol->mft_record_size_bits;
|
||||
|
@ -1475,9 +1501,11 @@ found_free_rec:
|
|||
if (!base_ni)
|
||||
vol->mft_data_pos = bit + 1;
|
||||
/* Return the opened, allocated inode of the allocated mft record. */
|
||||
ntfs_log_debug("Returning opened, allocated %sinode 0x%llx.\n",
|
||||
ntfs_log_debug("allocated %sinode 0x%llx.\n",
|
||||
base_ni ? "extent " : "", (long long)bit);
|
||||
vol->free_mft_records--;
|
||||
out:
|
||||
ntfs_log_leave("\n");
|
||||
return ni;
|
||||
|
||||
undo_mftbmp_alloc:
|
||||
|
@ -1488,7 +1516,8 @@ undo_mftbmp_alloc:
|
|||
err_out:
|
||||
if (!errno)
|
||||
errno = EIO;
|
||||
return NULL;
|
||||
ni = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue