By reason of historical accident, Android uses "/dev/block/loopX" rather
than "/dev/loopX" (though the control file is in the usual place). Work
around that.
---
 toys/other/losetup.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
From db3de47288888ce26592057b007128b3ec2586ab Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Wed, 29 Nov 2017 18:47:15 -0800
Subject: [PATCH] Fix losetup for Android.

By reason of historical accident, Android uses "/dev/block/loopX" rather
than "/dev/loopX" (though the control file is in the usual place). Work
around that.
---
 toys/other/losetup.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/toys/other/losetup.c b/toys/other/losetup.c
index 4e467a9..ce3bd82 100644
--- a/toys/other/losetup.c
+++ b/toys/other/losetup.c
@@ -55,6 +55,12 @@ todo: basic /dev file association
     https://lkml.org/lkml/2011/7/26/148
 */
 
+#ifdef __ANDROID__
+#define DEV_LOOP "/dev/block/loop"
+#else
+#define DEV_LOOP "/dev/loop"
+#endif
+
 // -f: *device is NULL
 
 // Perform requested operation on one device. Returns 1 if handled, 0 if error
@@ -76,7 +82,7 @@ static void loopback_setup(char *device, char *file)
     // mount -o loop depends on found device being at the start of toybuf.
     if (cfd != -1) {
       if (0 <= (i = ioctl(cfd, 0x4C82))) // LOOP_CTL_GET_FREE
-        sprintf(device = toybuf, "/dev/loop%d", i);
+        sprintf(device = toybuf, DEV_LOOP "%d", i);
       close(cfd);
     }
   }
-- 
2.15.0.531.g2ccb3012c9-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to