summaryrefslogtreecommitdiffstats
path: root/libmount
diff options
context:
space:
mode:
authorKarel Zak2012-01-13 13:01:18 +0100
committerKarel Zak2012-01-13 13:01:18 +0100
commit8ab6accf014b1ba9f7437a78463dbed35f08cceb (patch)
tree61535651c2ca4d415a1e53390c50937bff27bc07 /libmount
parenttests: fix mount/special to be compatible with libmount (diff)
downloadkernel-qcow2-util-linux-8ab6accf014b1ba9f7437a78463dbed35f08cceb.tar.gz
kernel-qcow2-util-linux-8ab6accf014b1ba9f7437a78463dbed35f08cceb.tar.xz
kernel-qcow2-util-linux-8ab6accf014b1ba9f7437a78463dbed35f08cceb.zip
libmount: add functions to export syscall/helpers status
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount')
-rw-r--r--libmount/src/context.c94
-rw-r--r--libmount/src/context_mount.c12
-rw-r--r--libmount/src/libmount.h.in9
-rw-r--r--libmount/src/libmount.sym5
4 files changed, 110 insertions, 10 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c
index 83ce0b994..11b44f2ae 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -52,8 +52,8 @@ struct libmnt_context *mnt_new_context(void)
ruid = getuid();
euid = geteuid();
- cxt->syscall_status = 1; /* not called yet */
- cxt->helper_exec_status = 1;
+ mnt_context_reset_status(cxt);
+
cxt->loopdev_fd = -1;
/* if we're really root and aren't running setuid */
@@ -151,9 +151,8 @@ int mnt_reset_context(struct libmnt_context *cxt)
cxt->user_mountflags = 0;
cxt->mountdata = NULL;
cxt->flags = MNT_FL_DEFAULT;
- cxt->syscall_status = 1;
- cxt->helper_exec_status = 1;
- cxt->helper_status = 0;
+
+ mnt_context_reset_status(cxt);
/* restore non-resetable flags */
cxt->flags |= (fl & MNT_FL_EXTERN_FSTAB);
@@ -172,6 +171,29 @@ int mnt_reset_context(struct libmnt_context *cxt)
return 0;
}
+/**
+ * mnt_context_reset_status:
+ * @cxt: context
+ *
+ * Resets mount(2) and mount.<type> statuses, so mnt_context_do_mount() or
+ * mnt_context_do_umount() could be again called with the same settings.
+ *
+ * BE CAREFUL -- after this soft reset the libmount will NOT parse mount
+ * options, evaluate permissions or apply stuff from fstab.
+ *
+ * Returns: 0 on success, negative number in case of error.
+ */
+int mnt_context_reset_status(struct libmnt_context *cxt)
+{
+ if (!cxt)
+ return -EINVAL;
+
+ cxt->syscall_status = 1; /* means not called yet */
+ cxt->helper_exec_status = 1;
+ cxt->helper_status = 0;
+ return 0;
+}
+
static int set_flag(struct libmnt_context *cxt, int flag, int enable)
{
if (!cxt)
@@ -1599,7 +1621,7 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt)
* mnt_context_get_status:
* @cxt: mount context
*
- * Returns: 1 if /sbin/mount.type or mount(2) syscall was successfull.
+ * Returns: 1 if mount.type or mount(2) syscall was successful.
*/
int mnt_context_get_status(struct libmnt_context *cxt)
{
@@ -1607,15 +1629,65 @@ int mnt_context_get_status(struct libmnt_context *cxt)
}
/**
+ * mnt_context_helper_executed:
+ * @cxt: mount context
+ *
+ * Returns: 1 if mount.type helper has been executed, or 0.
+ */
+int mnt_context_helper_executed(struct libmnt_context *cxt)
+{
+ return cxt->helper_exec_status != 1;
+}
+
+/**
+ * mnt_context_get_helper_status:
+ * @cxt: mount context
+ *
+ * Return: mount.<type> exit status, result is reliable only if
+ * mnt_context_helper_executed() returns 1.
+ */
+int mnt_context_get_helper_status(struct libmnt_context *cxt)
+{
+ return cxt->helper_status;
+}
+
+/**
+ * mnt_context_syscall_called:
+ * @cxt: mount context
+ *
+ * Returns: 1 if mount(2) syscall has been called, or 0.
+ */
+int mnt_context_syscall_called(struct libmnt_context *cxt)
+{
+ return cxt->syscall_status != 1;
+}
+
+/**
+ * mnt_context_get_syscall_errno:
+ * @cxt: mount context
+ *
+ * The result from this function is reliable only if
+ * mnt_context_syscall_called() returns 1.
+ *
+ * Returns: mount(2) errno if the syscall failed or 0.
+ */
+int mnt_context_get_syscall_errno(struct libmnt_context *cxt)
+{
+ if (cxt->syscall_status < 0)
+ return -cxt->syscall_status;
+
+ return 0;
+}
+
+/**
* mnt_context_set_syscall_status:
* @cxt: mount context
* @status: mount(2) status
*
- * The @status should be 0 on succcess, or negative number on error (-1 or
- * -errno).
+ * The @status should be 0 on success, or negative number on error (-errno).
*
- * This function should be used if [u]mount(2) syscall was NOT called by
- * libmount (by mnt_context_mount() or mnt_context_do_mount()) only.
+ * This function should be used only if [u]mount(2) syscall is NOT called by
+ * libmount code.
*
* Returns: 0 or negative number in case of error.
*/
@@ -1635,6 +1707,8 @@ int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status)
* @buf: buffer
* @bufsiz: size of the buffer
*
+ * Not implemented yet.
+ *
* Returns: 0 or negative number in case of error.
*/
int mnt_context_strerror(struct libmnt_context *cxt __attribute__((__unused__)),
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index f86b3f761..d4c20f41d 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -556,6 +556,13 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt)
*
* Call mount(2) or mount.type helper. Unnecessary for mnt_context_mount().
*
+ * Note that this function could be called only once. If you want to mount
+ * another source or target than you have to call mnt_reset_context().
+ *
+ * If you want to call mount(2) for the same source and target with a diffrent
+ * mount flags or fstype then you call mnt_context_reset_state() and then try
+ * again mnt_context_do_mount().
+ *
* WARNING: non-zero return code does not mean that mount(2) syscall or
* umount.type helper wasn't sucessfully called.
*
@@ -627,6 +634,11 @@ int mnt_context_finalize_mount(struct libmnt_context *cxt)
*
* See also mnt_context_disable_helpers().
*
+ * Note that this function could be called only once. If you want to mount with
+ * different setting than you have to call mnt_reset_context(). It's NOT enough
+ * to call mnt_context_reset_state() if you want call this function more than
+ * once, whole context has to be reseted.
+ *
* WARNING: non-zero return code does not mean that mount(2) syscall or
* mount.type helper wasn't sucessfully called.
*
diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in
index 5409ed515..e677c362b 100644
--- a/libmount/src/libmount.h.in
+++ b/libmount/src/libmount.h.in
@@ -462,7 +462,16 @@ extern int mnt_context_get_user_mflags(struct libmnt_context *cxt,
extern int mnt_context_set_mountdata(struct libmnt_context *cxt, void *data);
extern int mnt_context_apply_fstab(struct libmnt_context *cxt);
+
+extern int mnt_context_reset_status(struct libmnt_context *cxt);
extern int mnt_context_get_status(struct libmnt_context *cxt);
+
+extern int mnt_context_helper_executed(struct libmnt_context *cxt);
+extern int mnt_context_get_helper_status(struct libmnt_context *cxt);
+
+extern int mnt_context_syscall_called(struct libmnt_context *cxt);
+extern int mnt_context_get_syscall_errno(struct libmnt_context *cxt);
+
extern int mnt_context_strerror(struct libmnt_context *cxt, char *buf,
size_t bufsiz);
diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym
index 563ae7a0c..d3d94e0ce 100644
--- a/libmount/src/libmount.sym
+++ b/libmount/src/libmount.sym
@@ -209,11 +209,16 @@ global:
MOUNT_2.21 {
global:
mnt_context_enable_fork;
+ mnt_context_get_helper_status;
+ mnt_context_get_syscall_errno;
+ mnt_context_helper_executed;
mnt_context_is_child;
mnt_context_is_fork;
mnt_context_is_parent;
mnt_context_next_umount;
+ mnt_context_reset_status;
mnt_context_set_passwd_cb;
+ mnt_context_syscall_called;
mnt_context_wait_for_children;
mnt_fs_is_netfs;
mnt_fs_is_pseudofs;