fstrim: Don't double trim mountpoints with alternative fs types.

Now we skip mountpoints that are repeated.

Bug: 19744511
Change-Id: Iff1618274a07180e62a01c3e2479dc1d52baf267
Signed-off-by: JP Abgrall <jpa@google.com>
diff --git a/fstrim.c b/fstrim.c
index 231d66e..60c9f24 100644
--- a/fstrim.c
+++ b/fstrim.c
@@ -64,6 +64,7 @@
     struct fstrim_range range = { 0 };
     extern struct fstab *fstab;
     int deep_trim = !!thread_arg;
+    struct fstab_rec *prev_rec = NULL;
 
     SLOGI("Starting fstrim work...\n");
 
@@ -92,6 +93,13 @@
             continue;
         }
 
+        /* Skip the multi-type partitions, which are required to be following each other.
+         * See fs_mgr.c's mount_with_alternatives().
+         */
+        if (prev_rec && !strcmp(prev_rec->mount_point, fstab->recs[i].mount_point)) {
+            continue;
+        }
+
         fd = open(fstab->recs[i].mount_point, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
         if (fd < 0) {
             SLOGE("Cannot open %s for FITRIM\n", fstab->recs[i].mount_point);
@@ -111,6 +119,7 @@
             SLOGI("Trimmed %llu bytes on %s\n", range.len, fstab->recs[i].mount_point);
         }
         close(fd);
+        prev_rec = &fstab->recs[i];
     }
 
     /* Log the finish time in the event log */