]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: wipe partition first, then discard
authorLennart Poettering <lennart@poettering.net>
Thu, 30 Jul 2020 20:22:21 +0000 (22:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Aug 2020 20:00:31 +0000 (22:00 +0200)
Wiping means writing zero sectors to disk. Hence it's better to do this
before we discard, so that the zeroes we use to overwrite are properly
discarded. If we'd do it the other way round we'd discard the data and
then reallocte it just to write zeroes.

src/partition/repart.c

index e8d6302296f5ac6ae7f3ca237c40adbdda1771a2..cbb10f747572618b6573eb2c9803a82e581e58a5 100644 (file)
@@ -2193,17 +2193,15 @@ static int context_wipe_and_discard(Context *context, bool from_scratch) {
                 if (!p->allocated_to_area)
                         continue;
 
-                if (!from_scratch) {
-                        r = context_discard_partition(context, p);
-                        if (r < 0)
-                                return r;
-                }
-
                 r = context_wipe_partition(context, p);
                 if (r < 0)
                         return r;
 
                 if (!from_scratch) {
+                        r = context_discard_partition(context, p);
+                        if (r < 0)
+                                return r;
+
                         r = context_discard_gap_after(context, p);
                         if (r < 0)
                                 return r;