Changes by: flatcap
Update of /cvsroot/linux-ntfs/ntfs-driver-tng/linux/fs/ntfs
In directory usw-pr-cvs1:/tmp/cvs-serv28137/linux/fs/ntfs
Modified Files:
attrib.c
Log Message:
resync attrib.c, rl.c and check test cases
Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/ntfs-driver-tng/linux/fs/ntfs/attrib.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -U2 -r1.66 -r1.67
--- attrib.c 25 Feb 2002 04:00:58 -0000 1.66
+++ attrib.c 25 Feb 2002 04:30:08 -0000 1.67
@@ -133,19 +133,22 @@
BUG_ON (!orig || !new);
+ /* First, merge the right hand end, if necesary. */
right = ntfs_rl_merge (new + nsize - 1, orig + loc + 1);
+ /* Space required: Orig size + New size, less one if we merged. */
res = ntfs_rl_realloc (orig, osize, osize + nsize - right);
if (IS_ERR (res))
return res;
+ /* Move the tail of Orig out of the way, then copy in New. */
rl_mm (res, loc + 1 + nsize, loc + 1 + right, osize - loc - 1 - right);
rl_mc (res, loc + 1, new, 0, nsize);
+ /* Adjust the size of the preceding hole. */
res[loc].length = res[loc+1].vcn - res[loc].vcn;
- if (!right) {
- if (res[loc+nsize+1].lcn == LCN_ENOENT)
- res[loc+nsize+1].vcn = res[loc+nsize].vcn + res[loc+nsize].length;
- }
+ /* We may have changed the length of the file, so fix the end marker */
+ if (res[loc+nsize+1].lcn == LCN_ENOENT)
+ res[loc+nsize+1].vcn = res[loc+nsize].vcn + res[loc+nsize].length;
return res;
@@ -179,5 +182,11 @@
BUG_ON (!orig || !new);
- if (loc > 0) {
+ /* disc => Discontinuity between the end of Orig and the start of New.
+ * This means we might need to insert a hole.
+ * hole => Orig ends with a hole or an unmapped region which we can
+ * extend to match the discontinuity. */
+ if (loc == 0) {
+ disc = (new[0].vcn > 0);
+ } else {
left = ntfs_rl_merge (orig + loc - 1, new);
@@ -185,21 +194,17 @@
if (disc)
hole = (orig[loc-1].lcn == LCN_HOLE);
- } else {
- disc = (new[0].vcn > 0);
}
+ /* Space required: Orig size + New size, less one if we merged,
+ * plus one if there was a discontinuity, less one for a trailing hole */
res = ntfs_rl_realloc (orig, osize, osize + nsize - left + disc - hole);
if (IS_ERR (res))
return res;
+ /* Move the tail of Orig out of the way, then copy in New. */
rl_mm (res, loc + nsize - left + disc - hole, loc, osize - loc);
rl_mc (res, loc + disc - hole, new, left, nsize - left);
- if ((res[loc+nsize-left+disc-hole].lcn == LCN_HOLE) ||
- (res[loc+nsize-left+disc-hole].lcn == LCN_RL_NOT_MAPPED)) {
- res[loc+nsize-left+disc-hole].length -= (new[nsize-1].vcn +
- new[nsize-1].length - new[0].vcn);
- }
-
+ /* Adjust the VCN of the last run ... */
if (res[loc+nsize-left+disc-hole].lcn <= LCN_HOLE) {
res[loc+nsize-left+disc-hole].vcn =
@@ -207,5 +212,13 @@
res[loc+nsize-left+disc-hole-1].length;
}
+ /* ... and the length. */
+ if ((res[loc+nsize-left+disc-hole].lcn == LCN_HOLE) ||
+ (res[loc+nsize-left+disc-hole].lcn == LCN_RL_NOT_MAPPED)) {
+ res[loc+nsize-left+disc-hole].length =
+ res[loc+nsize-left+disc-hole+1].vcn -
+ res[loc+nsize-left+disc-hole].vcn;
+ }
+ /* Writing beyond the end of the file and there's a discontinuity. */
if (disc) {
if (hole) {
@@ -222,7 +235,5 @@
res[loc].lcn = LCN_RL_NOT_MAPPED;
}
- }
- if (disc) {
if (res[loc+nsize-left+disc].lcn == LCN_ENOENT)
res[loc+nsize-left+disc].vcn = res[loc+nsize-left+disc-1].vcn +
@@ -258,24 +269,24 @@
BUG_ON (!orig || !new);
+ /* First, merge the left and right ends, if necessary. */
right = ntfs_rl_merge (new + nsize - 1, orig + loc + 1);
if (loc > 0)
left = ntfs_rl_merge (orig + loc - 1, new);
+ /* Allocate some space. We'll need less if the left, right
+ * or both ends were merged. */
res = ntfs_rl_realloc (orig, osize, osize + nsize - left - right);
if (IS_ERR (res))
return res;
- rl_mm (res, loc + nsize - left,
- loc + right + 1,
- osize - loc - right - 1);
-
+ /* Move the tail of Orig out of the way, then copy in New. */
+ rl_mm (res, loc + nsize - left, loc + right + 1,
+ osize - loc - right - 1);
rl_mc (res, loc, new, left, nsize - left);
- if (!right) {
- if (res[loc+nsize-left].lcn == LCN_ENOENT)
- res[loc+nsize-left].vcn = res[loc+nsize-left-1].vcn +
- res[loc+nsize-left-1].length;
- }
-
+ /* We may have changed the length of the file, so fix the end marker */
+ if (res[loc+nsize-left].lcn == LCN_ENOENT)
+ res[loc+nsize-left].vcn = res[loc+nsize-left-1].vcn +
+ res[loc+nsize-left-1].length;
return res;
}
@@ -287,5 +298,5 @@
* @new: The run_list to be inserted.
* @nsize: The number of elements in @new (excluding end marker).
- * @loc: Index of run_list @orig to insert @new before.
+ * @loc: Index of run_list in @orig to split with @new.
*
* Split the run_list at @loc into two and insert @new. No merging of
@@ -304,14 +315,17 @@
BUG_ON (!orig || !new);
+ /* Space required: Orig size + New size + One new hole. */
res = ntfs_rl_realloc (orig, osize, osize + nsize + 1);
if (IS_ERR (res))
return res;
+ /* Move the tail of Orig out of the way, then copy in New. */
rl_mm (res, loc + 1 + nsize, loc, osize - loc);
rl_mc (res, loc + 1, new, 0, nsize);
- res[loc].length = res[loc+1].vcn - res[loc].vcn;
- res[loc+nsize+1].vcn = res[loc+nsize].vcn + res[loc+nsize].length;
- res[loc+nsize+1].length -= (new[nsize-1].vcn + new[nsize-1].length - new[0].vcn) + res[loc].length;
+ /* Adjust the size of the holes either size of New. */
+ res[loc].length = res[loc+1].vcn - res[loc].vcn;
+ res[loc+nsize+1].vcn = res[loc+nsize].vcn + res[loc+nsize].length;
+ res[loc+nsize+1].length = res[loc+nsize+2].vcn - res[loc+nsize+1].vcn;
return res;
|