@@ -734,11 +734,24 @@ static int mount_device(struct blkid_struct_probe *pr, int hotplug)
err = mount(pr->dev, target, pr->id->name, m->flags,
(m->options) ? (m->options) : (""));
- if (err)
- ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n",
- pr->dev, pr->id->name, target, err, strerror(err));
- else
- handle_swapfiles(true);
+ while (1) {
+ err = mount(pr->dev, target, pr->id->name, mflags,
+ (m->options) ? (m->options) : (""));
+ if (err) {
+ if (!(mflags & MS_RDONLY)) {
+ ERROR("fall back on RO mount. %s.\n", strerror(errno));
+ mflags |= MS_RDONLY;
+ continue;
+ } else {
+ ERROR("mounting %s (%s) as %s failed (%d) - %s\n",
+ pr->dev, pr->id->name, target, err, strerror(errno));
+ break;
+ }
+ } else {
+ handle_swapfiles(true);
+ break;
+ }
+ }
return err;
}
@@ -752,12 +765,26 @@ static int mount_device(struct blkid_struct_probe *pr, int hotplug)
if (check_fs)
check_filesystem(pr);
- err = mount(pr->dev, target, pr->id->name, 0, "");
- if (err)
- ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n",
- pr->dev, pr->id->name, target, err, strerror(err));
- else
- handle_swapfiles(true);
+ err = mount(pr->dev, target, pr->id->name, m->flags,
+ (m->options) ? (m->options) : (""));
+ while (1) {
+ err = mount(pr->dev, target, pr->id->name, mflags,
+ (m->options) ? (m->options) : (""));
+ if (err) {
+ if (!(mflags & MS_RDONLY)) {
+ ERROR("fall back on RO mount. %s.\n", strerror(errno));
+ mflags |= MS_RDONLY;
+ continue;
+ } else {
+ ERROR("mounting %s (%s) as %s failed (%d) - %s\n",
+ pr->dev, pr->id->name, target, err, strerror(errno));
+ break;
+ }
+ } else {
+ handle_swapfiles(true);
+ break;
+ }
+ }
return err;
}
A read-only device will fail to mount without MS_RDONLY flag. Signed-off-by: Hua Shao <nossiac@163.com> --- block.c | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-)