aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-02-17 16:40:17 -0800
committerRob Landley <rob@landley.net>2016-02-17 19:01:19 -0600
commit289ca9b68c5bb10c3dda8aa71ae1bbe9dbc98ae7 (patch)
tree7a0750de0dfdefd1ff053ab11179c384bcab70d1 /toys
parentb75c7dfa886e0cb9799e2c5673f7cb5cbf1a77ac (diff)
downloadtoybox-289ca9b68c5bb10c3dda8aa71ae1bbe9dbc98ae7.tar.gz
Fix remounting /system on Android.
This adds the missing "relatime" option, fixes error handling logic (mount returns 0/-1, not an errno value, and I at least get EACCES rather than EROFS in the case where the underlying block device is read-only; we should also probably only try again if the ioctl actually succeeded), and adds the missing newline in case where we go around and try again read-only. The test case was "mount -o rw,remount /system" on Android.
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/mount.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c
index 789d9a53..9510c5e9 100644
--- a/toys/lsb/mount.c
+++ b/toys/lsb/mount.c
@@ -91,6 +91,7 @@ static long flag_opts(char *new, long flags, char **more)
{"noexec", MS_NOEXEC}, {"exec", ~MS_NOEXEC},
{"sync", MS_SYNCHRONOUS}, {"async", ~MS_SYNCHRONOUS},
{"noatime", MS_NOATIME}, {"atime", ~MS_NOATIME},
+ {"norelatime", ~MS_RELATIME}, {"relatime", MS_RELATIME},
{"nodiratime", MS_NODIRATIME}, {"diratime", ~MS_NODIRATIME},
{"loud", ~MS_SILENT},
{"shared", MS_SHARED}, {"rshared", MS_SHARED|MS_REC},
@@ -195,16 +196,21 @@ static void mount_filesystem(char *dev, char *dir, char *type,
printf("try '%s' type '%s' on '%s'\n", dev, type, dir);
for (;;) {
rc = mount(dev, dir, type, flags, opts);
- if ((rc != EACCES && rc != EROFS) || (flags & MS_RDONLY)) break;
- if (rc == EROFS && fd == -1) {
+ // Did we succeed, fail unrecoverably, or already try read-only?
+ if (rc == 0 || (errno != EACCES && errno != EROFS) || (flags&MS_RDONLY))
+ break;
+ // If we haven't already tried it, use the BLKROSET ioctl to ensure
+ // that the underlying device isn't read-only.
+ if (fd == -1) {
+ if (toys.optflags & FLAG_v)
+ printf("trying BLKROSET ioctl on '%s'\n", dev);
if (-1 != (fd = open(dev, O_RDONLY))) {
- ioctl(fd, BLKROSET, &ro);
+ rc = ioctl(fd, BLKROSET, &ro);
close(fd);
-
- continue;
+ if (rc == 0) continue;
}
}
- fprintf(stderr, "'%s' is read-only", dev);
+ fprintf(stderr, "'%s' is read-only\n", dev);
flags |= MS_RDONLY;
}