Changes by: flatcap
Update of /cvsroot/linux-ntfs/ntfs-driver-tng/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv5857
Modified Files:
rl.c
Log Message:
lots of comments
Index: rl.c
===================================================================
RCS file: /cvsroot/linux-ntfs/ntfs-driver-tng/scripts/rl.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -U2 -r1.24 -r1.25
--- rl.c 18 Feb 2002 01:53:00 -0000 1.24
+++ rl.c 24 Feb 2002 20:05:18 -0000 1.25
@@ -86,4 +86,5 @@
}
+
/**
* ntfs_rl_append - Append a run_list after the given element
@@ -111,19 +112,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;
@@ -157,5 +161,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);
@@ -163,21 +173,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 =
@@ -185,5 +191,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) {
@@ -200,7 +214,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 +
@@ -236,24 +248,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;
}
@@ -265,5 +277,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
@@ -282,18 +294,22 @@
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;
}
+
/**
* merge_run_lists - merge two run_lists into one
@@ -958,7 +974,7 @@
{
ntfs_volume vol;
- ATTR_RECORD *attr1 = malloc (1024);
- ATTR_RECORD *attr2 = malloc (1024);
- ATTR_RECORD *attr3 = malloc (1024);
+ ATTR_RECORD *attr1 = ntfs_malloc_nofs (1024);
+ ATTR_RECORD *attr2 = ntfs_malloc_nofs (1024);
+ ATTR_RECORD *attr3 = ntfs_malloc_nofs (1024);
if (!attr1 || !attr2 || !attr3)
@@ -987,7 +1003,7 @@
out:
- free (attr1);
- free (attr2);
- free (attr3);
+ ntfs_free (attr1);
+ ntfs_free (attr2);
+ ntfs_free (attr3);
}
|