diff options
author | Rob Landley <rob@landley.net> | 2015-04-12 06:17:11 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-04-12 06:17:11 -0500 |
commit | 776aa3cb927f889a0481c2530128940c75984feb (patch) | |
tree | 8f5d1e946517170aebba657bca1ff2fdb6bb02d5 /toys/lsb | |
parent | e398112bdf7f4ced9388bb814697e35144e4a1a5 (diff) | |
download | toybox-776aa3cb927f889a0481c2530128940c75984feb.tar.gz |
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.)
Diffstat (limited to 'toys/lsb')
-rw-r--r-- | toys/lsb/mount.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c index ce1f87bb..789d9a53 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; } |