const char *t, *v, *src;
int rc = 0;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt || !cxt->fs)
return -EINVAL;
+ DBG(CXT, mnt_debug_h(cxt, "preparing source path"));
+
src = mnt_fs_get_source(cxt->fs);
/* ignore filesystems without a real source */
if (!src || (cxt->fs->flags & (MNT_FS_PSEUDO | MNT_FS_NET)))
return 0;
- DBG(CXT, mnt_debug_h(cxt, "preparing srcpath '%s'", src));
+ DBG(CXT, mnt_debug_h(cxt, "srcpath '%s'", src));
cache = mnt_context_get_cache(cxt);
type = mnt_fs_get_fstype(cxt->fs);
const char *dev;
int rc = -EINVAL;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt || !cxt->fs)
return -EINVAL;
assert(cxt);
assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
if (!type)
type = mnt_fs_get_fstype(cxt->fs);
return 0;
}
+int mnt_context_merge_mountflags(mnt_context *cxt)
+{
+ unsigned long fl = 0;
+ int rc;
+
+ assert(cxt);
+
+ DBG(CXT, mnt_debug_h(cxt, "merging mount flags"));
+
+ rc = mnt_context_get_mountflags(cxt, &fl);
+ if (rc)
+ return rc;
+ cxt->mountflags = fl;
+
+ fl = 0;
+ rc = mnt_context_get_userspace_mountflags(cxt, &fl);
+ if (rc)
+ return rc;
+ cxt->user_mountflags = fl;
+
+ cxt->flags |= MNT_FL_MOUNTFLAGS_MERGED;
+ return 0;
+}
+
/*
* Prepare /etc/mtab or /var/run/mount/mountinfo update
*/
int rc;
const char *tgt = cxt->fs ? mnt_fs_get_target(cxt->fs) : NULL;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (act == MNT_ACT_UMOUNT && tgt && !strcmp(tgt, "/"))
/* Don't try to touch mtab if umounting root FS */
cxt->flags |= MNT_FL_NOMTAB;
const char *src = NULL, *tgt = NULL;
int rc;
+ assert(cxt);
+ assert(cxt->fs);
+
if (!cxt->fs)
return -EINVAL;
mnt_tab *fstab, *mtab;
const char *src = NULL, *tgt = NULL;
+ assert(cxt);
+ assert(cxt->fs);
+
if (!cxt || !cxt->fs)
return -EINVAL;
if (cxt->flags & MNT_FL_TAB_APPLIED)
return 0;
+ DBG(CXT, mnt_debug_h(cxt, "appling fstab"));
+
if (cxt->fs) {
src = mnt_fs_get_source(cxt->fs);
tgt = mnt_fs_get_target(cxt->fs);
if (rc)
printf("failed to mount\n");
else {
- printf("successfully mounted");
+ printf("successfully mounted\n");
rc = mnt_context_post_mount(cxt);
if (rc)
printf("mtab update failed\n");
if (rc)
printf("failed to umount\n");
else {
- printf("successfully umounted");
+ printf("successfully umounted\n");
rc = mnt_context_post_umount(cxt);
if (rc)
printf("mtab update failed\n");
char *name, *val;
size_t namesz, valsz;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt)
return -EINVAL;
if (!cxt->fs)
return 0;
- assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+ DBG(CXT, mnt_debug_h(cxt, "mount: fixing optstr"));
/*
* we directly work with optstr pointer here
if (cxt->mountflags & MS_PROPAGATION)
cxt->mountflags &= MS_PROPAGATION;
- if (!mnt_optstr_get_option(*optstr, "user", &val, &valsz)) {
+ if (*optstr && !mnt_optstr_get_option(*optstr, "user", &val, &valsz)) {
if (val) {
cxt->orig_user = strndup(val, valsz);
if (!cxt->orig_user) {
unsigned long u_flags;
const char *srcpath;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt)
return -EINVAL;
if (!cxt->fs)
return 0;
+ DBG(CXT, mnt_debug_h(cxt, "mount: evaluating permissions"));
+
mnt_context_get_userspace_mountflags(cxt, &u_flags);
if (!mnt_context_is_restricted(cxt)) {
return 0;
}
-static int merge_mountflags(mnt_context *cxt)
-{
- unsigned long fl = 0;
- int rc;
-
- rc = mnt_context_get_mountflags(cxt, &fl);
- if (rc)
- return rc;
- cxt->mountflags = fl;
-
- fl = 0;
- rc = mnt_context_get_userspace_mountflags(cxt, &fl);
- if (rc)
- return rc;
- cxt->user_mountflags = fl;
-
- cxt->flags |= MNT_FL_MOUNTFLAGS_MERGED;
- return 0;
-}
-
static int exec_helper(mnt_context *cxt)
{
char *o = NULL;
assert(cxt);
assert(cxt->fs);
assert(cxt->helper);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
+ DBG(CXT, mnt_debug_h(cxt, "mount: executing helper %s", cxt->helper));
rc = generate_helper_optstr(cxt, &o);
if (rc)
assert(cxt);
assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
if (try_type && !cxt->helper) {
rc = mnt_context_prepare_helper(cxt, "mount", try_type);
!mnt_fs_get_target(cxt->fs)))
return -EINVAL;
+ DBG(CXT, mnt_debug_h(cxt, "mount: preparing"));
+
rc = mnt_context_apply_fstab(cxt);
if (!rc)
- rc = merge_mountflags(cxt);
+ rc = mnt_context_merge_mountflags(cxt);
if (!rc)
rc = evaluate_permissions(cxt);
if (!rc)
int rc = -EINVAL;
const char *type;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt || !cxt->fs || (cxt->fs->flags & MNT_FS_SWAP))
return -EINVAL;
+ DBG(CXT, mnt_debug_h(cxt, "mount: do mount"));
+
if (!(cxt->flags & MNT_FL_MOUNTDATA))
cxt->mountdata = (char *) mnt_fs_get_fs_optstr(cxt->fs);
{
int rc = 0;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt)
return -EINVAL;
/*
mnt_tab *mtab;
mnt_fs *fs;
+ assert(cxt);
+ assert(cxt->fs);
+
tgt = mnt_fs_get_target(cxt->fs);
if (!tgt) {
DBG(CXT, mnt_debug_h(cxt, "umount: undefined target"));
int rc, ok = 0;
mnt_fs *fs;
+ assert(cxt);
+ assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
if (!cxt || !cxt->fs)
return -EINVAL;
goto eperm;
}
- mnt_context_get_userspace_mountflags(cxt, &u_flags);
+ if (!(cxt->flags & MNT_FL_NOHELPERS) &&
+ (cxt->user_mountflags & MNT_MS_UHELPER)) {
- if (!(cxt->flags & MNT_FL_NOHELPERS) && (u_flags & MNT_MS_UHELPER)) {
char *suffix = NULL;
char *o = (char *) mnt_fs_get_optstr(cxt->fs);
size_t valsz;
* The options `user', `owner' and `group' only allow unmounting by the
* user that mounted (visible in mtab).
*/
- optstr = mnt_fs_get_optstr(fs);
+ optstr = mnt_fs_get_optstr(fs); /* FSTAB mount options! */
if (!optstr)
goto eperm;
assert(cxt);
assert(cxt->fs);
assert(cxt->helper);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
DBG_FLUSH;
assert(cxt);
assert(cxt->fs);
+ assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
if (cxt->helper)
return exec_helper(cxt);
cxt->helper = NULL;
rc = lookup_umount_fs(cxt);
+ if (!rc)
+ rc = mnt_context_merge_mountflags(cxt);
if (!rc)
rc = evaluate_permissions(cxt);
if (!rc && !cxt->helper)
# define DBG(m,x) do { \
if ((MNT_DEBUG_ ## m) & libmount_debug_mask) {\
- fprintf(stderr, "libmount: %s: ", # m); \
+ fprintf(stderr, "libmount: %8s: ", # m); \
x; \
} \
} while(0)
extern int mnt_context_prepare_helper(mnt_context *cxt, const char *name, const char *type);
extern int mnt_context_prepare_update(mnt_context *cxt, int act);
extern mnt_fs *mnt_context_get_fs(mnt_context *cxt);
+extern int mnt_context_merge_mountflags(mnt_context *cxt);
#endif /* _LIBMOUNT_PRIVATE_H */
return -EINVAL;
DBG(UPDATE, mnt_debug_h(upd,
- "prepare update (target %s, source %s, optstr %s)",
+ "prepare update (target=%s, source=%s, optstr=%s)",
mnt_fs_get_target(upd->fs),
mnt_fs_get_source(upd->fs),
mnt_fs_get_optstr(upd->fs)));
goto err;
}
}
+
+ DBG(UPDATE, mnt_debug_h(upd, "filename: %s", upd->filename));
+
if (!upd->format) {
if (endswith(upd->filename, "mountinfo"))
upd->format = MNT_FMT_MOUNTINFO;