From 776aa3cb927f889a0481c2530128940c75984feb Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 12 Apr 2015 06:17:11 -0500 Subject: [PATCH] Before trying to remount read only, see if block device responds to "become rw" ioctl(). (This is a thing Android's old mount already does.) --- toys/lsb/mount.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c index ce1f87b..789d9a5 100644 --- a/toys/lsb/mount.c +++ b/toys/lsb/mount.c @@ -56,6 +56,7 @@ GLOBALS( int okuser; ) +// mount.tests should check for all of this: // TODO detect existing identical mount (procfs with different dev name?) // TODO user, users, owner, group, nofail // TODO -p (passfd) @@ -170,6 +171,8 @@ static void mount_filesystem(char *dev, char *dir, char *type, toys.exitval |= xrun((char *[]){"swapon", "--", dev, 0}); for (;;) { + int fd = -1, ro = 0; + // If type wasn't specified, try all of them in order. if (fp && !buf) { size_t i; @@ -193,6 +196,14 @@ static void mount_filesystem(char *dev, char *dir, char *type, for (;;) { rc = mount(dev, dir, type, flags, opts); if ((rc != EACCES && rc != EROFS) || (flags & MS_RDONLY)) break; + if (rc == EROFS && fd == -1) { + if (-1 != (fd = open(dev, O_RDONLY))) { + ioctl(fd, BLKROSET, &ro); + close(fd); + + continue; + } + } fprintf(stderr, "'%s' is read-only", dev); flags |= MS_RDONLY; } -- 2.7.4