Unverified Commit 7dce3b73 by Christian Brauner Committed by Stéphane Graber

conf: mount_entry()

non-functional changes Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent cebba721
...@@ -1687,77 +1687,91 @@ static char *get_field(char *src, int nfields) ...@@ -1687,77 +1687,91 @@ static char *get_field(char *src, int nfields)
static int mount_entry(const char *fsname, const char *target, static int mount_entry(const char *fsname, const char *target,
const char *fstype, unsigned long mountflags, const char *fstype, unsigned long mountflags,
const char *data, int optional, int dev, const char *rootfs) const char *data, int optional, int dev,
const char *rootfs)
{ {
int ret;
#ifdef HAVE_STATVFS #ifdef HAVE_STATVFS
struct statvfs sb; struct statvfs sb;
#endif #endif
if (safe_mount(fsname, target, fstype, mountflags & ~MS_REMOUNT, data, rootfs)) { ret = safe_mount(fsname, target, fstype, mountflags & ~MS_REMOUNT, data,
rootfs);
if (ret < 0) {
if (optional) { if (optional) {
INFO("failed to mount '%s' on '%s' (optional): %s", fsname, INFO("Failed to mount \"%s\" on \"%s\" (optional): %s",
target, strerror(errno)); fsname, target, strerror(errno));
return 0; return 0;
} }
else {
SYSERROR("failed to mount '%s' on '%s'", fsname, target); SYSERROR("Failed to mount \"%s\" on \"%s\"", fsname, target);
return -1; return -1;
} }
}
if ((mountflags & MS_REMOUNT) || (mountflags & MS_BIND)) { if ((mountflags & MS_REMOUNT) || (mountflags & MS_BIND)) {
DEBUG("remounting %s on %s to respect bind or remount options",
fsname ? fsname : "(none)", target ? target : "(none)");
unsigned long rqd_flags = 0; unsigned long rqd_flags = 0;
DEBUG("Remounting \"%s\" on \"%s\" to respect bind or remount "
"options",
fsname ? fsname : "(none)", target ? target : "(none)");
if (mountflags & MS_RDONLY) if (mountflags & MS_RDONLY)
rqd_flags |= MS_RDONLY; rqd_flags |= MS_RDONLY;
#ifdef HAVE_STATVFS #ifdef HAVE_STATVFS
if (statvfs(fsname, &sb) == 0) { if (statvfs(fsname, &sb) == 0) {
unsigned long required_flags = rqd_flags; unsigned long required_flags = rqd_flags;
if (sb.f_flag & MS_NOSUID) if (sb.f_flag & MS_NOSUID)
required_flags |= MS_NOSUID; required_flags |= MS_NOSUID;
if (sb.f_flag & MS_NODEV && !dev) if (sb.f_flag & MS_NODEV && !dev)
required_flags |= MS_NODEV; required_flags |= MS_NODEV;
if (sb.f_flag & MS_RDONLY) if (sb.f_flag & MS_RDONLY)
required_flags |= MS_RDONLY; required_flags |= MS_RDONLY;
if (sb.f_flag & MS_NOEXEC) if (sb.f_flag & MS_NOEXEC)
required_flags |= MS_NOEXEC; required_flags |= MS_NOEXEC;
DEBUG("(at remount) flags for %s was %lu, required extra flags are %lu", fsname, sb.f_flag, required_flags);
/* DEBUG("Flags for \"%s\" were %lu, required extra flags "
* If this was a bind mount request, and required_flags "are %lu", fsname, sb.f_flag, required_flags);
/* If this was a bind mount request, and required_flags
* does not have any flags which are not already in * does not have any flags which are not already in
* mountflags, then skip the remount * mountflags, then skip the remount.
*/ */
if (!(mountflags & MS_REMOUNT)) { if (!(mountflags & MS_REMOUNT)) {
if (!(required_flags & ~mountflags) && rqd_flags == 0) { if (!(required_flags & ~mountflags) &&
DEBUG("mountflags already was %lu, skipping remount", rqd_flags == 0) {
mountflags); DEBUG("Mountflags already were %lu, "
"skipping remount", mountflags);
goto skipremount; goto skipremount;
} }
} }
mountflags |= required_flags; mountflags |= required_flags;
} }
#endif #endif
if (mount(fsname, target, fstype, ret = mount(fsname, target, fstype, mountflags | MS_REMOUNT, data);
mountflags | MS_REMOUNT, data) < 0) { if (ret < 0) {
if (optional) { if (optional) {
INFO("failed to mount '%s' on '%s' (optional): %s", INFO("Failed to mount \"%s\" on \"%s\" "
fsname, target, strerror(errno)); "(optional): %s", fsname, target,
strerror(errno));
return 0; return 0;
} }
else {
SYSERROR("failed to mount '%s' on '%s'", SYSERROR("Failed to mount \"%s\" on \"%s\"", fsname, target);
fsname, target);
return -1; return -1;
} }
} }
}
#ifdef HAVE_STATVFS #ifdef HAVE_STATVFS
skipremount: skipremount:
#endif #endif
DEBUG("mounted '%s' on '%s', type '%s'", fsname, target, fstype); DEBUG("Mounted \"%s\" on \"%s\" with filesystem type \"%s\"", fsname,
target, fstype);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment