summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmount/src/context.c74
-rw-r--r--libmount/src/context_loopdev.c2
-rw-r--r--libmount/src/context_umount.c8
-rw-r--r--libmount/src/mountP.h5
4 files changed, 73 insertions, 16 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c
index 1a04c1a29..65171eceb 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -65,11 +65,6 @@ struct libmnt_context *mnt_new_context(void)
DBG(CXT, ul_debugobj(cxt, "----> allocate %s",
cxt->restricted ? "[RESTRICTED]" : ""));
- mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
-
- if (!cxt->mtab_writable)
- /* use /run/mount/utab if /etc/mtab is useless */
- mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
return cxt;
}
@@ -178,6 +173,7 @@ int mnt_reset_context(struct libmnt_context *cxt)
cxt->flags |= (fl & MNT_FL_NOCANONICALIZE);
cxt->flags |= (fl & MNT_FL_RDONLY_UMOUNT);
cxt->flags |= (fl & MNT_FL_NOSWAPMATCH);
+ cxt->flags |= (fl & MNT_FL_TABPATHS_CHECKED);
return 0;
}
@@ -205,6 +201,59 @@ int mnt_context_reset_status(struct libmnt_context *cxt)
return 0;
}
+static int context_init_paths(struct libmnt_context *cxt, int writable)
+{
+ assert(cxt);
+
+ if (!cxt->mtab_path)
+ cxt->mtab_path = mnt_get_mtab_path();
+ if (!cxt->utab_path)
+ cxt->utab_path = mnt_get_utab_path();
+
+ if (!writable)
+ return 0; /* only paths wanted */
+ if (mnt_context_is_nomtab(cxt))
+ return 0; /* write mode overrided by mount -n */
+ if (cxt->flags & MNT_FL_TABPATHS_CHECKED)
+ return 0;
+
+ DBG(CXT, ul_debugobj(cxt, "checking for writable tab files"));
+
+ mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
+
+ if (!cxt->mtab_writable)
+ /* use /run/mount/utab if /etc/mtab is useless */
+ mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
+
+ cxt->flags |= MNT_FL_TABPATHS_CHECKED;
+ return 0;
+}
+
+int mnt_context_mtab_writable(struct libmnt_context *cxt)
+{
+ assert(cxt);
+
+ context_init_paths(cxt, 1);
+ return cxt->mtab_writable == 1;
+}
+
+int mnt_context_utab_writable(struct libmnt_context *cxt)
+{
+ assert(cxt);
+
+ context_init_paths(cxt, 1);
+ return cxt->utab_writable == 1;
+}
+
+const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt)
+{
+ assert(cxt);
+
+ context_init_paths(cxt, 1);
+ return cxt->mtab_writable ? cxt->mtab_path : cxt->utab_path;
+}
+
+
static int set_flag(struct libmnt_context *cxt, int flag, int enable)
{
assert(cxt);
@@ -978,6 +1027,8 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb)
if (!cxt->mtab) {
int rc;
+ context_init_paths(cxt, 0);
+
cxt->mtab = mnt_new_table();
if (!cxt->mtab)
return -ENOMEM;
@@ -1220,8 +1271,8 @@ struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt)
return NULL;
if (!cxt->lock) {
- cxt->lock = mnt_new_lock(cxt->mtab_writable ?
- cxt->mtab_path : cxt->utab_path, 0);
+ cxt->lock = mnt_new_lock(
+ mnt_context_get_writable_tabpath(cxt), 0);
if (cxt->lock)
mnt_lock_block_signals(cxt->lock, TRUE);
}
@@ -1740,7 +1791,7 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
DBG(CXT, ul_debugobj(cxt, "skip update: NOMTAB flag"));
return 0;
}
- if (!cxt->mtab_writable && !cxt->utab_writable) {
+ if (!mnt_context_get_writable_tabpath(cxt)) {
DBG(CXT, ul_debugobj(cxt, "skip update: no writable destination"));
return 0;
}
@@ -1753,7 +1804,7 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
}
if (!cxt->update) {
- const char *name = cxt->mtab_writable ? cxt->mtab_path : cxt->utab_path;
+ const char *name = mnt_context_get_writable_tabpath(cxt);
if (cxt->action == MNT_ACT_UMOUNT && is_file_empty(name)) {
DBG(CXT, ul_debugobj(cxt,
@@ -1765,7 +1816,8 @@ int mnt_context_prepare_update(struct libmnt_context *cxt)
if (!cxt->update)
return -ENOMEM;
- mnt_update_set_filename(cxt->update, name, !cxt->mtab_writable);
+ mnt_update_set_filename(cxt->update, name,
+ !mnt_context_mtab_writable(cxt));
}
if (cxt->action == MNT_ACT_UMOUNT)
@@ -1796,7 +1848,7 @@ int mnt_context_update_tabs(struct libmnt_context *cxt)
/* check utab update when external helper executed */
if (mnt_context_helper_executed(cxt)
&& mnt_context_get_helper_status(cxt) == 0
- && cxt->utab_writable) {
+ && mnt_context_utab_writable(cxt)) {
if (mnt_update_already_done(cxt->update, cxt->lock)) {
DBG(CXT, ul_debugobj(cxt, "don't update: error evaluate or already updated"));
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c
index e8f637b29..f4525b3ad 100644
--- a/libmount/src/context_loopdev.c
+++ b/libmount/src/context_loopdev.c
@@ -227,7 +227,7 @@ int mnt_context_setup_loopdev(struct libmnt_context *cxt)
* because kernel provides the name in /sys.
*/
if (get_linux_version() >= KERNEL_VERSION(2, 6, 37) ||
- !cxt->mtab_writable) {
+ !mnt_context_mtab_writable(cxt)) {
DBG(CXT, ul_debugobj(cxt, "enabling AUTOCLEAR flag"));
lo_flags |= LO_FLAGS_AUTOCLEAR;
}
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index 7df4c2cca..220f28bc6 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -92,7 +92,7 @@ int mnt_context_find_umount_fs(struct libmnt_context *cxt,
* where LABEL, UUID or symlinks are canonicalized. It means that
* it's usable only for canonicalized stuff (e.g. kernel mountinfo).
*/
- if (!cxt->mtab_writable && *tgt == '/' &&
+ if (!mnt_context_mtab_writable(cxt) && *tgt == '/' &&
!mnt_context_is_force(cxt) && !mnt_context_is_lazy(cxt)) {
struct stat st;
@@ -259,7 +259,7 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
if (!mnt_context_is_restricted(cxt)
&& *tgt == '/'
&& !(cxt->flags & MNT_FL_HELPER)
- && !cxt->mtab_writable
+ && !mnt_context_mtab_writable(cxt)
&& !mnt_context_is_force(cxt)
&& !mnt_context_is_lazy(cxt)
&& stat(tgt, &st) == 0 && S_ISDIR(st.st_mode)
@@ -267,7 +267,7 @@ static int lookup_umount_fs(struct libmnt_context *cxt)
const char *type = mnt_fs_get_fstype(cxt->fs);
- /* !cxt->mtab_writable && has_utab_entry() verified that there
+ /* !mnt_context_mtab_writable(cxt) && has_utab_entry() verified that there
* is no stuff in utab, so disable all mtab/utab related actions */
mnt_context_disable_mtab(cxt, TRUE);
@@ -865,7 +865,7 @@ int mnt_context_do_umount(struct libmnt_context *cxt)
&& (cxt->mountflags & MS_REMOUNT)) {
/* use "remount" instead of "umount" in /etc/mtab */
- if (!rc && cxt->update && cxt->mtab_writable)
+ if (!rc && cxt->update && mnt_context_mtab_writable(cxt))
rc = mnt_update_set_fs(cxt->update,
cxt->mountflags, NULL, cxt->fs);
}
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
index d85a078de..f2660e057 100644
--- a/libmount/src/mountP.h
+++ b/libmount/src/mountP.h
@@ -340,6 +340,7 @@ struct libmnt_context
#define MNT_FL_HELPER (1 << 25) /* [u]mount.<type> */
#define MNT_FL_LOOPDEV_READY (1 << 26) /* /dev/loop<N> initialized by the library */
#define MNT_FL_MOUNTOPTS_FIXED (1 << 27)
+#define MNT_FL_TABPATHS_CHECKED (1 << 28)
/* default flags */
#define MNT_FL_DEFAULT 0
@@ -371,6 +372,10 @@ extern int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype)
__attribute__((nonnull(1)));
/* context.c */
+extern int mnt_context_mtab_writable(struct libmnt_context *cxt);
+extern int mnt_context_utab_writable(struct libmnt_context *cxt);
+extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt);
+
extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
extern int mnt_context_prepare_target(struct libmnt_context *cxt);
extern int mnt_context_guess_fstype(struct libmnt_context *cxt);