FAQ SearchLogin
Tuxera Home
View unanswered posts | View active topics It is currently Fri May 07, 2021 03:20



Post new topic Reply to topic  [ 5 posts ] 
Patch to speed-up ntfswipe 
Author Message

Joined: Wed Aug 20, 2014 18:05
Posts: 1
Post Patch to speed-up ntfswipe
Hi,

i suggest a patch to speed-up ntfswipe, for the unused clusters wiping :

How:
1/ read/write on a block basis (64 clusters, arbitrary)
2/ skip of fully used block
3/ skip non-used block already wiped

Pros:
* speed-up the wipe process
* doesn't write already wiped block. That's very good for limiting the grow of virtual disk images.

Cons:
* Last block of the disk isn't wiped (for simplicity, and only if the block size is != 64 clusters)
* Some rare blocks aren't wiped. This is because the block test is based on a simple bytes checksum, witch is faster than a each byte test.

Here is the patch :
Code:
--- ntfswipe.c.orig   2014-02-15 15:07:52.000000000 +0100
+++ ntfswipe.c   2014-08-20 17:54:12.017851189 +0200
@@ -468,44 +468,94 @@
  */
static s64 wipe_unused(ntfs_volume *vol, int byte, enum action act)
{
-   s64 i;
+   s64 i, j, k;
+        s64 wipe_test; //checksum
   s64 total = 0;
   s64 result = 0;
   u8 *buffer = NULL;
+        u8 *big_buffer = NULL;
+        s64 n_clusters = 0; //nb of clusters in a block (in a big_buffer)

   if (!vol || (byte < 0))
      return -1;

   if (act != act_info) {
-      buffer = malloc(vol->cluster_size);
-      if (!buffer) {
+      //buffer = malloc(vol->cluster_size);
+                big_buffer = malloc(vol->cluster_size*64);
+      if (!big_buffer) {
         ntfs_log_error("malloc failed\n");
         return -1;
      }
-      memset(buffer, byte, vol->cluster_size);
+      //memset(buffer, byte, vol->cluster_size);
   }

-   for (i = 0; i < vol->nr_clusters; i++) {
-      if (utils_cluster_in_use(vol, i)) {
-         //ntfs_log_verbose("cluster %lld is in use\n", i);
-         continue;
+        n_clusters = vol->nr_clusters/64; //TO_KNOW: when (mod 64) != 0 , last block is ignored. Neligible.
+
+   for (i = 0; i < n_clusters; i++) {
+           //test if all clusters in this block are used, then ignore this block
+                result = 0;
+                for (j = 0; j < 64 ; j++) {
+                        result = result + utils_cluster_in_use(vol, i*64+j);
+                }
+
+                if (result == 64) {
+                        continue;
+                }
+
+           //test if non used clusters in this block are already zeroed, then ignore this block
+                result = ntfs_pread(vol->dev, vol->cluster_size * i * 64, vol->cluster_size * 64, big_buffer);
+      if (result != vol->cluster_size * 64) {
+              ntfs_log_error("read failed\n");
+         goto free;
      }

+                result = 0;
+                wipe_test = 0;
+                buffer = big_buffer;
+                for (j = 0; j < 64 ; j++) {
+                        if(!utils_cluster_in_use(vol, i*64+j)) {
+                                for(k = 0; k < vol->cluster_size ; k++) {
+                                        result = result + buffer[k];
+                                }
+                                wipe_test += byte*vol->cluster_size;
+                        }
+                        buffer += vol->cluster_size;
+                }
+
+                if (result == wipe_test) { 
+                        // TO_KNOW: if 'byte' = 0 then the clusters in the block will be wiped if needed.
+                        //          But if 'byte' != 0 the test could return a false positive.
+                        //          In this rarely case, the block isn't wiped. For performance and lower complexity it's better to ignore that.
+                        continue;
+                }
+
+           //else zeroing non used clusters in the block
+                buffer = big_buffer;
+
+                for (j = 0; j < 64 ; j++) {
+                        if (!utils_cluster_in_use(vol, i*64+j)) {
+                                memset(buffer, byte, vol->cluster_size);
+              }
+                        buffer += vol->cluster_size;
+                }
+
      if (act == act_wipe) {
         //ntfs_log_verbose("cluster %lld is not in use\n", i);
-         result = ntfs_pwrite(vol->dev, vol->cluster_size * i, vol->cluster_size, buffer);
-         if (result != vol->cluster_size) {
+         result = ntfs_pwrite(vol->dev, vol->cluster_size * i * 64, vol->cluster_size * 64, big_buffer);
+         if (result != vol->cluster_size * 64) {
            ntfs_log_error("write failed\n");
            goto free;
         }
      }

-      total += vol->cluster_size;
+      total += vol->cluster_size * 64;
+
   }

   ntfs_log_quiet("wipe_unused 0x%02x, %lld bytes\n", byte, (long long)total);
free:
-   free(buffer);
+   //free(buffer);
+        free(big_buffer);
   return total;
}


Wed Aug 20, 2014 18:20
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: Patch to speed-up ntfswipe
Hi,
Quote:
i suggest a patch to speed-up ntfswipe, for the unused clusters wiping

Interesting.

I will take it as an option, because most users of ntfswipe want to be sure they delete all remaining parts of sensitive files.

I need some time to actually test the patch.

Regards

Jean-Pierre


Thu Aug 21, 2014 09:36
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: Patch to speed-up ntfswipe
Hi,

Quote:
i suggest a patch to speed-up ntfswipe, for the unused clusters wiping

I have made several changes to your proposal (see attachment). The last block is now wiped and the test for already wiped clusters is now supposed to be foolproof.

Please test.

Regards

Jean-Pierre


Attachments:
ntfswipe.patch.gz [1.97 KiB]
Downloaded 902 times
Wed Aug 27, 2014 09:29
Profile

Joined: Thu Nov 20, 2014 04:29
Posts: 1
Post Re: Patch to speed-up ntfswipe
Do I understand correctly that this option will work like a switch when used with "-a"?
As in, "ntfswipe -aU" will get the speed benefit, effectively becoming "-dlmptUs" instead of "-dlmptus"?

BTW, I think the man page does not convey sufficiently the fact that "-i" also implies "-a".


Thu Nov 20, 2014 05:25
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: Patch to speed-up ntfswipe
Hi,

Quote:
Do I understand correctly that this option will work like a switch when used with "-a"?
As in, "ntfswipe -aU" will get the speed benefit, effectively becoming "-dlmptUs" instead of "-dlmptus"?

Yes.
Quote:
BTW, I think the man page does not convey sufficiently the fact that "-i" also implies "-a".

It should not. Option -a is for wiping all unused data, and option -i is for computing the space which can be wiped, without wiping anything. From the user's point of view, using option -i, implies ignoring the option -a (yes, the man page could be more clear about it).

Regards

Jean-Pierre


Thu Nov 20, 2014 10:11
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Original forum style by Vjacheslav Trushkin.