run_list_element * ntfs_merge_run_lists (run_list_element * drl, run_list_element * srl);
First we sanity check the two run lists srl and drl to make sure that they are sensible and can be merged. The run list srl must be either after the run list drl or completely within a hole (or unmapped region) in drl.
It is up to the caller to serialize access to the run lists drl and srl.
1. When attribute lists are used and a further extent is being mapped. 2. When new clusters are allocated to fill a hole or extend a file.
There are four possible ways srl can be merged. It can: - be inserted at the beginning of a hole, - split the hole in two and be inserted between the two fragments, - be appended at the end of a hole, or it can - replace the whole hole. It can also be appended to the end of the run list, which is just a variant of the insert case.
On success, return a pointer to the new, combined, run list. Note, both run lists drl and srl are deallocated before returning so you cannot use the pointers for anything any more. (Strictly speaking the returned run list may be the same as dst but this is irrelevant.)
On error, return -errno. Both run lists are left unmodified. The following
-ENOMEM - Not enough memory to allocate run list array. -EINVAL - Invalid parameters were passed in. -ERANGE - The run lists overlap and cannot be merged.