Cleanup the ntfs_mapping_pairs_build enhancement.

(Logical change 1.548)
edge.strict_endians
cantab.net!aia21 2004-09-13 09:31:42 +00:00
parent a95cff8404
commit 1159ab3656
6 changed files with 32 additions and 28 deletions

View File

@ -72,7 +72,7 @@ extern int ntfs_write_significant_bytes(s8 *dst, const s8 *dst_max,
extern int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
const int dst_len, const runlist_element *rl,
const VCN start_vcn, VCN *stopped_at);
const VCN start_vcn, VCN *const stop_vcn);
extern int ntfs_rl_truncate(runlist **rl, const VCN start_vcn);

View File

@ -2513,7 +2513,7 @@ static int ntfs_attr_make_non_resident(ntfs_attr *na,
/* Generate the mapping pairs array in the attribute record. */
if (ntfs_mapping_pairs_build(vol, (u8*)a + mp_ofs, arec_size - mp_ofs,
rl, 0, 0) < 0) {
rl, 0, NULL) < 0) {
err = errno;
// FIXME: Eeek! We need rollback! (AIA)
Dprintf("%s(): Eeek! Failed to build mapping pairs. Leaving "
@ -3039,7 +3039,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize)
*/
if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(
a->mapping_pairs_offset), mp_size,
na->rl, 0, 0)) {
na->rl, 0, NULL)) {
err = errno;
// FIXME: Eeek! We need rollback! (AIA)
Dprintf("%s(): Eeek! Mapping pairs build "
@ -3354,7 +3354,7 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize)
*/
if (ntfs_mapping_pairs_build(vol, (u8*)a +
le16_to_cpu(a->mapping_pairs_offset), mp_size,
na->rl, sle64_to_cpu(a->lowest_vcn), 0)) {
na->rl, sle64_to_cpu(a->lowest_vcn), NULL)) {
err = errno;
Dprintf("%s(): BUG! Mapping pairs build "
"failed. Please run chkdsk and if "

View File

@ -1396,8 +1396,7 @@ err_out:
* @dst_len: size of destination buffer @dst in bytes
* @rl: runlist for which to build the mapping pairs array
* @start_vcn: vcn at which to start the mapping pairs array
* @stopped_at: if function failed with ENOSPC error code @stopped_at contain
* first vcn outside destination buffer.
* @stop_vcn: first vcn outside destination buffer on on ENOSPC error
*
* Create the mapping pairs array from the runlist @rl, starting at vcn
* @start_vcn and save the array in @dst. @dst_len is the size of @dst in
@ -1406,7 +1405,12 @@ err_out:
*
* If @rl is NULL, just write a single terminator byte to @dst.
*
* @stopped_at can be NULL in case such information is not required.
* On error ENOSPC, if @stop_vcn is not NULL, *@stop_vcn is set to the first
* vcn outside the destination buffer. Note that @dst has been filled with all
* the mapping pairs that will fit, thus it can be treated as partial success,
* in that a new attribute extent needs to be created or the next extent has to
* be used and the mapping pairs build has to be continued with @start_vcn set
* to *@stop_vcn.
*
* Return 0 on success. On error, return -1 with errno set to the error code.
* The following error codes are defined:
@ -1418,10 +1422,10 @@ err_out:
*/
int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
const int dst_len, const runlist_element *rl,
const VCN start_vcn, VCN *stopped_at)
const VCN start_vcn, VCN *const stop_vcn)
{
LCN prev_lcn;
s8 *dst_max;
s8 *dst_max, *dst_next;
s8 len_len, lcn_len;
if (start_vcn < 0)
@ -1479,13 +1483,13 @@ int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
goto size_err;
} else
lcn_len = 0;
if (dst + len_len + lcn_len + 1 <= dst_max) {
/* Update header byte. */
*dst = lcn_len << 4 | len_len;
/* Position at next mapping pairs array element. */
dst += 1 + len_len + lcn_len;
} else
dst_next = dst + len_len + lcn_len + 1;
if (dst_next > dst_max)
goto size_err;
/* Update header byte. */
*dst = lcn_len << 4 | len_len;
/* Position at next mapping pairs array element. */
dst = dst_next;
/* Go to next runlist element. */
rl++;
}
@ -1516,20 +1520,20 @@ int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
prev_lcn = rl->lcn;
} else
lcn_len = 0;
if (dst + len_len + lcn_len + 1 <= dst_max) {
/* Update header byte. */
*dst = lcn_len << 4 | len_len;
/* Position at next mapping pairs array element. */
dst += 1 + len_len + lcn_len;
} else
dst_next = dst + len_len + lcn_len + 1;
if (dst_next > dst_max)
goto size_err;
/* Update header byte. */
*dst = lcn_len << 4 | len_len;
/* Position at next mapping pairs array element. */
dst += 1 + len_len + lcn_len;
}
/* Terminator byte. */
/* Add terminator byte. */
*dst = 0;
return 0;
size_err:
if (stopped_at)
*stopped_at = rl->vcn;
if (stop_vcn)
*stop_vcn = rl->vcn;
*dst = 0;
errno = ENOSPC;
return -1;

View File

@ -1322,7 +1322,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
Eprintf("Error writing non-resident attribute value."
"\n");
err = ntfs_mapping_pairs_build(vol, (s8*)a + hdr_size +
((name_len + 7) & ~7), mpa_size, rl, 0, 0);
((name_len + 7) & ~7), mpa_size, rl, 0, NULL);
}
a->initialized_size = cpu_to_le64(inited_size);
if (err < 0 || bw != val_len) {
@ -1512,7 +1512,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m,
Eprintf("Error writing non-resident attribute value."
"\n");
err = ntfs_mapping_pairs_build(vol, (s8*)a + hdr_size +
((name_len + 7) & ~7), mpa_size, rl, 0, 0);
((name_len + 7) & ~7), mpa_size, rl, 0, NULL);
}
if (err < 0 || bw != val_len) {
// FIXME: Handle error.

View File

@ -709,7 +709,7 @@ static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
// update data runs
ntfs_mapping_pairs_build(vol, ((u8*)rec) + rec->mapping_pairs_offset,
need_to, from, 0, 0);
need_to, from, 0, NULL);
// commit
ntfs_inode_mark_dirty (ino);

View File

@ -1157,7 +1157,7 @@ static void replace_attribute_runlist(ntfs_volume *vol,
if (!(mp = calloc(1, mp_size)))
perr_exit("Couldn't get memory");
if (ntfs_mapping_pairs_build(vol, mp, mp_size, rl, 0, 0))
if (ntfs_mapping_pairs_build(vol, mp, mp_size, rl, 0, NULL))
perr_exit("ntfs_mapping_pairs_build");
memmove((u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp, mp_size);