From: Karel Zak Date: Thu, 10 Jan 2013 14:58:52 +0000 (+0100) Subject: libmount: add mnt_fs_get_propagation() X-Git-Tag: v2.23-rc1~355 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b9d67a23d8db22ad6772cdb7af94b02f9a59b22;p=thirdparty%2Futil-linux.git libmount: add mnt_fs_get_propagation() Signed-off-by: Karel Zak --- diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt index f69a63b8ac..6a00ea413b 100644 --- a/libmount/docs/libmount-sections.txt +++ b/libmount/docs/libmount-sections.txt @@ -174,6 +174,7 @@ mnt_fs_get_options mnt_fs_get_parent_id mnt_fs_get_passno mnt_fs_get_priority +mnt_fs_get_propagation mnt_fs_get_root mnt_fs_get_size mnt_fs_get_source diff --git a/libmount/src/fs.c b/libmount/src/fs.c index 5c1a1074a0..232a2f6188 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -489,6 +489,41 @@ static int mnt_fs_get_flags(struct libmnt_fs *fs) return fs ? fs->flags : 0; } +/** + * mnt_fs_get_propagation: + * @fs: mountinfo entry + * @flags: returns propagation MS_* flags as present in mountinfo file + * + * Note that this function set @flags to zero if not found any propagation flag + * in mountinfo file. The kernel default is MS_PRIVATE, this flag is not stored + * in the mountinfo file. + * + * Returns: 0 on success or negative number in case of error. + */ +int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags) +{ + if (!fs || !flags) + return -EINVAL; + + *flags = 0; + + if (!fs->opt_fields) + return 0; + + /* + * The optional fields format is incompatible with mount options + * ... we have to parse the field here. + */ + *flags |= strstr(fs->opt_fields, "shared:") ? MS_SHARED : MS_PRIVATE; + + if (strstr(fs->opt_fields, "master:")) + *flags |= MS_SLAVE; + if (strstr(fs->opt_fields, "unbindable")) + *flags |= MS_UNBINDABLE; + + return 0; +} + /** * mnt_fs_is_kernel: * @fs: filesystem diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index b93011aa88..e716f8f0cf 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -330,6 +330,8 @@ extern const char *mnt_fs_get_options(struct libmnt_fs *fs) extern const char *mnt_fs_get_optional_fields(struct libmnt_fs *fs) __ul_attribute__((nonnull)) __ul_attribute__((warn_unused_result)); +extern int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags); + extern int mnt_fs_set_options(struct libmnt_fs *fs, const char *optstr); extern int mnt_fs_append_options(struct libmnt_fs *fs, const char *optstr); extern int mnt_fs_prepend_options(struct libmnt_fs *fs, const char *optstr); diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym index ecb3e01f78..68b272a8d0 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -252,4 +252,5 @@ global: MOUNT_2.23 { global: mnt_fs_get_optional_fields; + mnt_fs_get_propagation; } MOUNT_2.22;