]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add functions to export syscall/helpers status
authorKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2012 12:01:18 +0000 (13:01 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2012 12:01:18 +0000 (13:01 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/libmount.h.in
libmount/src/libmount.sym

index 83ce0b994a0f600eee5accb174ba31615e0dcfc9..11b44f2ae56a747be54114084b7843590b0b917c 100644 (file)
@@ -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,23 +1621,73 @@ 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)
 {
        return cxt && (!cxt->syscall_status || !cxt->helper_exec_status);
 }
 
+/**
+ * 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__)),
index f86b3f761a67f86d4e1fac2d82b96f557f9dc9f6..d4c20f41d8b1560dc55778c352c06b576e30fbca 100644 (file)
@@ -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.
  *
index 5409ed5158dcb213177ab874e184c3397ce0d24e..e677c362b1d35e1b29398614d948502ec0839d37 100644 (file)
@@ -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);
 
index 563ae7a0c53d217a003c1f8ab26c544c3ee6a94b..d3d94e0cea1d90ffbc066611c5563eb16df3b0d2 100644 (file)
@@ -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;