Improved creating gaps in sparse files
parent
93b695f1cc
commit
ddfb2175a9
|
@ -54,7 +54,7 @@ extern LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn);
|
|||
extern s64 ntfs_rl_pread(const ntfs_volume *vol, const runlist_element *rl,
|
||||
const s64 pos, s64 count, void *b);
|
||||
extern s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl,
|
||||
const s64 pos, s64 count, void *b);
|
||||
s64 ofs, const s64 pos, s64 count, void *b);
|
||||
|
||||
extern runlist_element *ntfs_runlists_merge(runlist_element *drl,
|
||||
runlist_element *srl);
|
||||
|
|
|
@ -991,6 +991,9 @@ static int ntfs_attr_fill_zero(ntfs_attr *na, s64 pos, s64 count)
|
|||
{
|
||||
char *buf;
|
||||
s64 written, size, end = pos + count;
|
||||
s64 ofsi;
|
||||
const runlist_element *rli;
|
||||
ntfs_volume *vol;
|
||||
int ret = -1;
|
||||
|
||||
ntfs_log_trace("pos %lld, count %lld\n", (long long)pos,
|
||||
|
@ -1005,9 +1008,17 @@ static int ntfs_attr_fill_zero(ntfs_attr *na, s64 pos, s64 count)
|
|||
if (!buf)
|
||||
goto err_out;
|
||||
|
||||
rli = na->rl;
|
||||
ofsi = 0;
|
||||
vol = na->ni->vol;
|
||||
while (pos < end) {
|
||||
while (rli->length && (ofsi + (rli->length <<
|
||||
vol->cluster_size_bits) <= pos)) {
|
||||
ofsi += (rli->length << vol->cluster_size_bits);
|
||||
rli++;
|
||||
}
|
||||
size = min(end - pos, NTFS_BUF_SIZE);
|
||||
written = ntfs_rl_pwrite(na->ni->vol, na->rl, pos, size, buf);
|
||||
written = ntfs_rl_pwrite(vol, rli, ofsi, pos, size, buf);
|
||||
if (written <= 0) {
|
||||
ntfs_log_perror("Failed to zero space");
|
||||
goto err_free;
|
||||
|
@ -4381,7 +4392,7 @@ retry:
|
|||
/* Get the size for the rest of mapping pairs array. */
|
||||
mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, stop_rl,
|
||||
stop_vcn, exp_max_mp_size);
|
||||
{ /* temporary compare against old computation */
|
||||
{ /* temporary compare against old computation
|
||||
int old;
|
||||
|
||||
old = ntfs_get_size_for_mapping_pairs(na->ni->vol, na->rl,
|
||||
|
@ -4391,7 +4402,7 @@ int old;
|
|||
ntfs_log_error("Bad runlist size, old %d new %d\n",old,mp_size);
|
||||
goto put_err_out;
|
||||
}
|
||||
}
|
||||
*/}
|
||||
if (mp_size <= 0) {
|
||||
ntfs_log_perror("%s: get MP size failed", __FUNCTION__);
|
||||
goto put_err_out;
|
||||
|
|
|
@ -1114,8 +1114,9 @@ rl_err_out:
|
|||
/**
|
||||
* ntfs_rl_pwrite - scatter write to disk
|
||||
* @vol: ntfs volume to write to
|
||||
* @rl: runlist specifying where to write the data to
|
||||
* @pos: byte position within runlist @rl at which to begin the write
|
||||
* @rl: runlist entry specifying where to write the data to
|
||||
* @ofs: offset in file for runlist element indicated in @rl
|
||||
* @pos: byte position from runlist beginning at which to begin the write
|
||||
* @count: number of bytes to write
|
||||
* @b: data buffer to write to disk
|
||||
*
|
||||
|
@ -1134,9 +1135,9 @@ rl_err_out:
|
|||
* of invalid arguments.
|
||||
*/
|
||||
s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl,
|
||||
const s64 pos, s64 count, void *b)
|
||||
s64 ofs, const s64 pos, s64 count, void *b)
|
||||
{
|
||||
s64 written, to_write, ofs, total = 0;
|
||||
s64 written, to_write, total = 0;
|
||||
int err = EIO;
|
||||
|
||||
if (!vol || !rl || pos < 0 || count < 0) {
|
||||
|
@ -1149,9 +1150,11 @@ s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl,
|
|||
if (!count)
|
||||
goto out;
|
||||
/* Seek in @rl to the run containing @pos. */
|
||||
for (ofs = 0; rl->length && (ofs + (rl->length <<
|
||||
vol->cluster_size_bits) <= pos); rl++)
|
||||
while (rl->length && (ofs + (rl->length <<
|
||||
vol->cluster_size_bits) <= pos)) {
|
||||
ofs += (rl->length << vol->cluster_size_bits);
|
||||
rl++;
|
||||
}
|
||||
/* Offset in the run at which to begin writing. */
|
||||
ofs = pos - ofs;
|
||||
for (total = 0LL; count; rl++, ofs = 0) {
|
||||
|
|
Loading…
Reference in New Issue