aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/losetup.test18
-rw-r--r--toys/other/losetup.c8
2 files changed, 17 insertions, 9 deletions
diff --git a/tests/losetup.test b/tests/losetup.test
index c04a72b9..7968ecd9 100755
--- a/tests/losetup.test
+++ b/tests/losetup.test
@@ -9,6 +9,14 @@ then
exit
fi
+# Android's loopback devices are only in /dev/block/loop*.
+# Debian has symlinks like /dev/block/7:0 back to ../loop*.
+if [ -b /dev/block/sda ]; then
+ DIR="/dev/block" # Presumably Android.
+else
+ DIR="/dev"
+fi
+
#testing "name" "command" "result" "infile" "stdin"
truncate -s 1M blah.img &&
@@ -17,13 +25,13 @@ DEV="$(stat --format %d blah.img)"
NODE="$(stat --format %i blah.img)"
# TODO: assumes there are no loopback devices!
-testcmd "-f" "-f" "/dev/loop0\n" "" ""
+testcmd "-f" "-f" "$DIR/loop0\n" "" ""
testcmd "-f blah.img" "-f blah.img" "" "" ""
-testcmd "-f --show" "-f --show blah.img" "/dev/loop1\n" "" ""
+testcmd "-f --show" "-f --show blah.img" "$DIR/loop1\n" "" ""
testcmd "-a" "-a | sort" \
- "/dev/loop0: [$DEV]:$NODE ($FILE)\n/dev/loop1: [$DEV]:$NODE ($FILE)\n" "" ""
-testcmd "-d /dev/loop0" "-d /dev/loop0 && losetup -a" \
- "/dev/loop1: [$DEV]:$NODE ($FILE)\n" "" ""
+ "$DIR/loop0: [$DEV]:$NODE ($FILE)\n$DIR/loop1: [$DEV]:$NODE ($FILE)\n" "" ""
+testcmd "-d $DIR/loop0" "-d $DIR/loop0 && losetup -a" \
+ "$DIR/loop1: [$DEV]:$NODE ($FILE)\n" "" ""
testcmd "-D" "-D && losetup -a" "" "" ""
rm blah.img
diff --git a/toys/other/losetup.c b/toys/other/losetup.c
index 02856c27..8edc65ae 100644
--- a/toys/other/losetup.c
+++ b/toys/other/losetup.c
@@ -43,6 +43,7 @@ GLOBALS(
int openflags;
dev_t jdev;
ino_t jino;
+ char *dir;
)
// -f: *device is NULL
@@ -65,9 +66,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);
- // Fallback for Android
- if (access(toybuf, F_OK)) sprintf(toybuf, "/dev/block/loop%d", i);
+ sprintf(device = toybuf, "%s/loop%d", TT.dir, i);
}
close(cfd);
}
@@ -150,6 +149,7 @@ void losetup_main(void)
{
char **s;
+ TT.dir = CFG_TOYBOX_ON_ANDROID ? "/dev/block" : "/dev";
TT.openflags = FLAG(r) ? O_RDONLY : O_RDWR;
if (TT.j) {
@@ -176,7 +176,7 @@ void losetup_main(void)
loopback_setup(NULL, *toys.optargs);
} else if (FLAG(a) || FLAG(j)) {
if (toys.optc) error_exit("bad args");
- dirtree_read("/dev", dash_a);
+ dirtree_read(TT.dir, dash_a);
// Do we need one DEVICE argument?
} else {
char *file = (FLAG(c) || FLAG(d)) ? NULL : toys.optargs[1];