NTFS: Change ntfs_map_runlist_nolock() to only decompress the mapping pairs

if the requested vcn is inside it.  Otherwise we get into problems
      when we try to map an out of bounds vcn because we then try to map
      the already mapped runlist fragment which causes
      ntfs_mapping_pairs_decompress() to fail and return error.  Update
      ntfs_attr_find_vcn_nolock() accordingly.

Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
This commit is contained in:
Anton Altaparmakov 2005-06-25 17:24:08 +01:00
parent fa3be92317
commit 4757d7dff6
2 changed files with 48 additions and 19 deletions

View file

@ -139,6 +139,12 @@ ToDo/Notes:
and ntfs_mapping_pairs_build() to allow the runlist encoding to be and ntfs_mapping_pairs_build() to allow the runlist encoding to be
partial which is desirable when filling holes in sparse attributes. partial which is desirable when filling holes in sparse attributes.
Update all callers. Update all callers.
- Change ntfs_map_runlist_nolock() to only decompress the mapping pairs
if the requested vcn is inside it. Otherwise we get into problems
when we try to map an out of bounds vcn because we then try to map
the already mapped runlist fragment which causes
ntfs_mapping_pairs_decompress() to fail and return error. Update
ntfs_attr_find_vcn_nolock() accordingly.
2.1.22 - Many bug and race fixes and error handling improvements. 2.1.22 - Many bug and race fixes and error handling improvements.

View file

@ -39,15 +39,19 @@
* *
* Map the part of a runlist containing the @vcn of the ntfs inode @ni. * Map the part of a runlist containing the @vcn of the ntfs inode @ni.
* *
* Return 0 on success and -errno on error. * Return 0 on success and -errno on error. There is one special error code
* which is not an error as such. This is -ENOENT. It means that @vcn is out
* of bounds of the runlist.
* *
* Locking: - The runlist must be locked for writing. * Locking: - The runlist must be locked for writing.
* - This function modifies the runlist. * - This function modifies the runlist.
*/ */
int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn) int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn)
{ {
VCN end_vcn;
ntfs_inode *base_ni; ntfs_inode *base_ni;
MFT_RECORD *mrec; MFT_RECORD *m;
ATTR_RECORD *a;
ntfs_attr_search_ctx *ctx; ntfs_attr_search_ctx *ctx;
runlist_element *rl; runlist_element *rl;
int err = 0; int err = 0;
@ -58,26 +62,43 @@ int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn)
base_ni = ni; base_ni = ni;
else else
base_ni = ni->ext.base_ntfs_ino; base_ni = ni->ext.base_ntfs_ino;
mrec = map_mft_record(base_ni); m = map_mft_record(base_ni);
if (IS_ERR(mrec)) if (IS_ERR(m))
return PTR_ERR(mrec); return PTR_ERR(m);
ctx = ntfs_attr_get_search_ctx(base_ni, mrec); ctx = ntfs_attr_get_search_ctx(base_ni, m);
if (unlikely(!ctx)) { if (unlikely(!ctx)) {
err = -ENOMEM; err = -ENOMEM;
goto err_out; goto err_out;
} }
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len, err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, vcn, NULL, 0, ctx); CASE_SENSITIVE, vcn, NULL, 0, ctx);
if (likely(!err)) { if (unlikely(err)) {
rl = ntfs_mapping_pairs_decompress(ni->vol, ctx->attr, if (err == -ENOENT)
ni->runlist.rl); err = -EIO;
if (IS_ERR(rl)) goto err_out;
err = PTR_ERR(rl);
else
ni->runlist.rl = rl;
} }
ntfs_attr_put_search_ctx(ctx); a = ctx->attr;
/*
* Only decompress the mapping pairs if @vcn is inside it. Otherwise
* we get into problems when we try to map an out of bounds vcn because
* we then try to map the already mapped runlist fragment and
* ntfs_mapping_pairs_decompress() fails.
*/
end_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn) + 1;
if (unlikely(!a->data.non_resident.lowest_vcn && end_vcn <= 1))
end_vcn = ni->allocated_size >> ni->vol->cluster_size_bits;
if (unlikely(vcn >= end_vcn)) {
err = -ENOENT;
goto err_out;
}
rl = ntfs_mapping_pairs_decompress(ni->vol, a, ni->runlist.rl);
if (IS_ERR(rl))
err = PTR_ERR(rl);
else
ni->runlist.rl = rl;
err_out: err_out:
if (likely(ctx))
ntfs_attr_put_search_ctx(ctx);
unmap_mft_record(base_ni); unmap_mft_record(base_ni);
return err; return err;
} }
@ -89,7 +110,9 @@ err_out:
* *
* Map the part of a runlist containing the @vcn of the ntfs inode @ni. * Map the part of a runlist containing the @vcn of the ntfs inode @ni.
* *
* Return 0 on success and -errno on error. * Return 0 on success and -errno on error. There is one special error code
* which is not an error as such. This is -ENOENT. It means that @vcn is out
* of bounds of the runlist.
* *
* Locking: - The runlist must be unlocked on entry and is unlocked on return. * Locking: - The runlist must be unlocked on entry and is unlocked on return.
* - This function takes the runlist lock for writing and modifies the * - This function takes the runlist lock for writing and modifies the
@ -287,11 +310,11 @@ retry_remap:
goto retry_remap; goto retry_remap;
} }
/* /*
* -EINVAL and -ENOENT coming from a failed mapping attempt are * -EINVAL coming from a failed mapping attempt is equivalent
* equivalent to i/o errors for us as they should not happen in * to i/o error for us as it should not happen in our code
* our code paths. * paths.
*/ */
if (err == -EINVAL || err == -ENOENT) if (err == -EINVAL)
err = -EIO; err = -EIO;
} else if (!err) } else if (!err)
err = -EIO; err = -EIO;