Changes by: flatcap
Update of /cvsroot/linux-ntfs/ntfsprogs/ntfsprogs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16590
Modified Files:
ntfsrm.c
Log Message:
tidy up dt rollback and commit
Index: ntfsrm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/ntfsprogs/ntfsprogs/ntfsrm.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -p -r1.40 -r1.41
--- ntfsrm.c 12 Jul 2005 17:58:47 -0000 1.40
+++ ntfsrm.c 13 Jul 2005 22:55:01 -0000 1.41
@@ -1046,35 +1046,70 @@ static int ntfs_ie_test (void)
/**
- * ntfs_dt_rollback
+ * ntfs_dt_free
*/
-static int ntfs_dt_rollback (struct ntfs_dt *dt)
+static void ntfs_dt_free (struct ntfs_dt *dt)
{
int i;
if (!dt)
- return -1;
-
- return 0; // TEMP
+ return;
for (i = 0; i < dt->child_count; i++) {
- if (dt->sub_nodes)
- ntfs_dt_rollback (dt->sub_nodes[i]);
- if (dt->inodes)
- ntfs_inode_close2 (dt->inodes[i]);
+ ntfs_dt_free (dt->sub_nodes[i]);
+ ntfs_inode_close2 (dt->inodes[i]);
}
- free (dt->data);
- free (dt->children);
free (dt->sub_nodes);
+ free (dt->children);
free (dt->inodes);
+ free (dt->data); // XXX is this always ours?
+ free (dt);
+}
- dt->data = NULL;
- dt->children = NULL;
- dt->sub_nodes = NULL;
- dt->inodes = NULL;
+/**
+ * ntfs_dt_rollback
+ */
+static int ntfs_dt_rollback (struct ntfs_dt *dt)
+{
+ int i;
- return 0;
+ if (!dt)
+ return 0;
+ if (dt->child_count == 0) // No children or nothing mapped
+ return 0;
+
+ if (dt->changed) {
+ // We can't trust anything below us in the tree
+ for (i = 0; i < dt->child_count; i++) {
+ ntfs_dt_free (dt->sub_nodes[i]);
+ ntfs_inode_close2 (dt->inodes[i]);
+ }
+
+ dt->child_count = 0;
+
+ free (dt->data);
+ free (dt->children);
+ free (dt->sub_nodes);
+ free (dt->inodes);
+
+ dt->data = NULL;
+ dt->children = NULL;
+ dt->sub_nodes = NULL;
+ dt->inodes = NULL;
+ } else {
+ // This node is OK, check the su-nodes
+ for (i = 0; i < dt->child_count; i++) {
+ if (ntfs_dt_rollback (dt->sub_nodes[i])) {
+ ntfs_inode_close2 (dt->inodes[i]);
+ // Child was changed so unmap it
+ dt->sub_nodes[i] = NULL;
+ dt->inodes[i] = NULL;
+ }
+ }
+ }
+
+ return (dt->child_count == 0);
}
/**
@@ -1137,32 +1172,6 @@ static int ntfs_dt_commit (struct ntfs_d
}
/**
- * ntfs_dt_free
- */
-static void ntfs_dt_free (struct ntfs_dt *dt)
-{
- int i;
-
- if (!dt)
- return;
-
- ntfs_dt_rollback (dt);
-
- for (i = 0; i < dt->child_count; i++) {
- //if (dt->sub_nodes)
- ntfs_dt_free (dt->sub_nodes[i]);
- //if (dt->inodes)
- ntfs_inode_close2 (dt->inodes[i]);
- }
-
- free (dt->sub_nodes);
- free (dt->children);
- free (dt->inodes);
- free (dt->data); // XXX is this always ours?
- free (dt);
-}
-
-/**
* ntfs_dt_alloc_children
*/
static INDEX_ENTRY ** ntfs_dt_alloc_children (INDEX_ENTRY **children, int count)
|