Add @stopped_at parameter to ntfs_mapping_pairs_build and adapt all callers.
(Logical change 1.547)edge.strict_endians
parent
64e1f672cf
commit
27e0e7a0c7
|
@ -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);
|
||||
const VCN start_vcn, VCN *stopped_at);
|
||||
|
||||
extern int ntfs_rl_truncate(runlist **rl, const VCN start_vcn);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
rl, 0, 0) < 0) {
|
||||
err = errno;
|
||||
// FIXME: Eeek! We need rollback! (AIA)
|
||||
Dprintf("%s(): Eeek! Failed to build mapping pairs. Leaving "
|
||||
|
@ -3038,7 +3038,8 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize)
|
|||
* correct destination, i.e. the attribute record itself.
|
||||
*/
|
||||
if (ntfs_mapping_pairs_build(vol, (u8*)a + le16_to_cpu(
|
||||
a->mapping_pairs_offset), mp_size, na->rl, 0)) {
|
||||
a->mapping_pairs_offset), mp_size,
|
||||
na->rl, 0, 0)) {
|
||||
err = errno;
|
||||
// FIXME: Eeek! We need rollback! (AIA)
|
||||
Dprintf("%s(): Eeek! Mapping pairs build "
|
||||
|
@ -3353,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))) {
|
||||
na->rl, sle64_to_cpu(a->lowest_vcn), 0)) {
|
||||
err = errno;
|
||||
Dprintf("%s(): BUG! Mapping pairs build "
|
||||
"failed. Please run chkdsk and if "
|
||||
|
|
|
@ -1396,6 +1396,8 @@ 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.
|
||||
*
|
||||
* 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
|
||||
|
@ -1404,6 +1406,8 @@ 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.
|
||||
*
|
||||
* Return 0 on success. On error, return -1 with errno set to the error code.
|
||||
* The following error codes are defined:
|
||||
* EINVAL - Run list contains unmapped elements. Make sure to only pass
|
||||
|
@ -1414,7 +1418,7 @@ 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)
|
||||
const VCN start_vcn, VCN *stopped_at)
|
||||
{
|
||||
LCN prev_lcn;
|
||||
s8 *dst_max;
|
||||
|
@ -1475,10 +1479,13 @@ int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
|
|||
goto size_err;
|
||||
} else
|
||||
lcn_len = 0;
|
||||
/* Update header byte. */
|
||||
*dst = lcn_len << 4 | len_len;
|
||||
/* Position ourselves at next mapping pairs array element. */
|
||||
dst += 1 + len_len + lcn_len;
|
||||
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
|
||||
goto size_err;
|
||||
/* Go to next runlist element. */
|
||||
rl++;
|
||||
}
|
||||
|
@ -1509,17 +1516,21 @@ int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
|
|||
prev_lcn = rl->lcn;
|
||||
} else
|
||||
lcn_len = 0;
|
||||
/* Update header byte. */
|
||||
*dst = lcn_len << 4 | len_len;
|
||||
/* Position ourselves at next mapping pairs array element. */
|
||||
dst += 1 + len_len + lcn_len;
|
||||
}
|
||||
if (dst <= dst_max) {
|
||||
/* Terminator byte. */
|
||||
*dst = 0;
|
||||
return 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
|
||||
goto size_err;
|
||||
}
|
||||
/* Terminator byte. */
|
||||
*dst = 0;
|
||||
return 0;
|
||||
size_err:
|
||||
if (stopped_at)
|
||||
*stopped_at = rl->vcn;
|
||||
*dst = 0;
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
val_err:
|
||||
|
|
|
@ -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);
|
||||
((name_len + 7) & ~7), mpa_size, rl, 0, 0);
|
||||
}
|
||||
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);
|
||||
((name_len + 7) & ~7), mpa_size, rl, 0, 0);
|
||||
}
|
||||
if (err < 0 || bw != val_len) {
|
||||
// FIXME: Handle error.
|
||||
|
|
|
@ -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);
|
||||
need_to, from, 0, 0);
|
||||
|
||||
// commit
|
||||
ntfs_inode_mark_dirty (ino);
|
||||
|
|
|
@ -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))
|
||||
if (ntfs_mapping_pairs_build(vol, mp, mp_size, rl, 0, 0))
|
||||
perr_exit("ntfs_mapping_pairs_build");
|
||||
|
||||
memmove((u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp, mp_size);
|
||||
|
|
Loading…
Reference in New Issue