Umount context

Umount context — high-level API to umount operation.

Synopsis

int                 mnt_context_find_umount_fs          (struct libmnt_context *cxt,
                                                         const char *tgt,
                                                         struct libmnt_fs **pfs);
int                 mnt_context_do_umount               (struct libmnt_context *cxt);
int                 mnt_context_finalize_umount         (struct libmnt_context *cxt);
int                 mnt_context_next_umount             (struct libmnt_context *cxt,
                                                         struct libmnt_iter *itr,
                                                         struct libmnt_fs **fs,
                                                         int *mntrc,
                                                         int *ignored);
int                 mnt_context_prepare_umount          (struct libmnt_context *cxt);
int                 mnt_context_umount                  (struct libmnt_context *cxt);

Description

Details

mnt_context_find_umount_fs ()

int                 mnt_context_find_umount_fs          (struct libmnt_context *cxt,
                                                         const char *tgt,
                                                         struct libmnt_fs **pfs);

cxt :

mount context

tgt :

mountpoint, device, ...

pfs :

returns point to filesystem

Returns :

0 on success, <0 on error, 1 if target filesystem not found

mnt_context_do_umount ()

int                 mnt_context_do_umount               (struct libmnt_context *cxt);

Umount filesystem by umount(2) or fork()+exec(/sbin/umount.type). Unnecessary for mnt_context_umount().

See also mnt_context_disable_helpers().

WARNING: non-zero return code does not mean that umount(2) syscall or umount.type helper wasn't successfully called.

Check mnt_context_get_status() after error!

cxt :

mount context

Returns :

0 on success; >0 in case of umount(2) error (returns syscall errno), <0 in case of other errors.

mnt_context_finalize_umount ()

int                 mnt_context_finalize_umount         (struct libmnt_context *cxt);

Mtab update, etc. Unnecessary for mnt_context_umount(), but should be called after mnt_context_do_umount(). See also mnt_context_set_syscall_status().

cxt :

context

Returns :

negative number on error, 0 on success.

mnt_context_next_umount ()

int                 mnt_context_next_umount             (struct libmnt_context *cxt,
                                                         struct libmnt_iter *itr,
                                                         struct libmnt_fs **fs,
                                                         int *mntrc,
                                                         int *ignored);

This function tries to umount the next filesystem from mtab (as returned by mnt_context_get_mtab()).

You can filter out filesystems by: mnt_context_set_options_pattern() to simulate umount -a -O pattern mnt_context_set_fstype_pattern() to simulate umount -a -t pattern

If the filesystem is not mounted or does not match the defined criteria, then the function mnt_context_next_umount() returns zero, but the ignored is non-zero. Note that the root filesystem is always ignored.

If umount(2) syscall or umount.type helper failed, then the mnt_context_next_umount() function returns zero, but the mntrc is non-zero. Use also mnt_context_get_status() to check if the filesystem was successfully umounted.

cxt :

context

itr :

iterator

fs :

returns the current filesystem

mntrc :

returns the return code from mnt_context_umount()

ignored :

returns 1 for not matching

Returns :

0 on success, <0 in case of error (!= umount(2) errors) 1 at the end of the list.

mnt_context_prepare_umount ()

int                 mnt_context_prepare_umount          (struct libmnt_context *cxt);

Prepare context for umounting, unnecessary for mnt_context_umount().

cxt :

mount context

Returns :

0 on success, and negative number in case of error.

mnt_context_umount ()

int                 mnt_context_umount                  (struct libmnt_context *cxt);

High-level, umounts filesystem by umount(2) or fork()+exec(/sbin/umount.type).

This is similar to:

mnt_context_prepare_umount(cxt); mnt_context_do_umount(cxt); mnt_context_finalize_umount(cxt);

See also mnt_context_disable_helpers().

WARNING: non-zero return code does not mean that umount(2) syscall or umount.type helper wasn't successfully called.

Check mnt_context_get_status() after error!

cxt :

umount context

Returns :

0 on success; >0 in case of umount(2) error (returns syscall errno), <0 in case of other errors.