aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-12-02 21:18:52 -0600
committerRob Landley <rob@landley.net>2017-12-02 21:18:52 -0600
commit3cc79396fd8b7e64f4cd2267261f3fcda8391827 (patch)
tree0212dd3a8af53e47556f9df41040f63fd0c30f0a
parentd61aeaf9e48cde0481e3a54acaa89a99018fda99 (diff)
downloadtoybox-3cc79396fd8b7e64f4cd2267261f3fcda8391827.tar.gz
Android has its loop devices under "block" as Elliott says "by reason of
historical accident", so fall back to check there. Also remove an obsolete comment TODO block, check !parent for dirtree top of tree instead of '/' in the filename, and typecast some printf arguments for 32-bit systems.
-rw-r--r--toys/other/losetup.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/toys/other/losetup.c b/toys/other/losetup.c
index 4e467a9c..e8f02aa9 100644
--- a/toys/other/losetup.c
+++ b/toys/other/losetup.c
@@ -45,16 +45,6 @@ GLOBALS(
ino_t jino;
)
-/*
-todo: basic /dev file association
- associate DEV FILE
- #-a
- cdfjosS
- allocate new loop device:
- /dev/loop-control
- https://lkml.org/lkml/2011/7/26/148
-*/
-
// -f: *device is NULL
// Perform requested operation on one device. Returns 1 if handled, 0 if error
@@ -75,8 +65,11 @@ 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
+ 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);
+ }
close(cfd);
}
}
@@ -119,8 +112,8 @@ static void loopback_setup(char *device, char *file)
free(s);
} else if (flags & FLAG_f) printf("%s", device);
else {
- xprintf("%s: [%04llx]:%llu (%s)", device, loop->lo_device, loop->lo_inode,
- loop->lo_file_name);
+ xprintf("%s: [%04llx]:%llu (%s)", device, (long long)loop->lo_device,
+ (long long)loop->lo_inode, loop->lo_file_name);
if (loop->lo_offset) xprintf(", offset %llu", loop->lo_offset);
if (loop->lo_sizelimit) xprintf(", sizelimit %llu", loop->lo_sizelimit);
xputc('\n');
@@ -137,7 +130,7 @@ static int dash_a(struct dirtree *node)
char *s = node->name;
// Initial /dev node needs to recurse down one level, then only loop[0-9]*
- if (*s == '/') return DIRTREE_RECURSE;
+ if (!node->parent) return DIRTREE_RECURSE;
if (strncmp(s, "loop", 4) || !isdigit(s[4])) return 0;
s = dirtree_path(node, 0);