From e47a19312ff91de3c4ead99714b8bfa06139809e Mon Sep 17 00:00:00 2001 From: Ondrej Oprala Date: Thu, 10 Jan 2013 12:35:08 +0100 Subject: libmount: read optional mountinfo fields [kzak@redhat.com: - rename struct member and functions from "propagation" to "optional fields" - split the original patch - fix parser] Signed-off-by: Ondrej Oprala Signed-off-by: Karel Zak --- libmount/docs/libmount-sections.txt | 1 + libmount/src/fs.c | 14 ++++++++++++++ libmount/src/libmount.h.in | 3 +++ libmount/src/libmount.sym | 5 +++++ libmount/src/mountP.h | 1 + libmount/src/tab_parse.c | 2 ++ 6 files changed, 26 insertions(+) (limited to 'libmount') diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt index e0f899471..f69a63b8a 100644 --- a/libmount/docs/libmount-sections.txt +++ b/libmount/docs/libmount-sections.txt @@ -169,6 +169,7 @@ mnt_fs_get_fs_options mnt_fs_get_fstype mnt_fs_get_id mnt_fs_get_option +mnt_fs_get_optional_fields mnt_fs_get_options mnt_fs_get_parent_id mnt_fs_get_passno diff --git a/libmount/src/fs.c b/libmount/src/fs.c index d94476870..5c1a1074a 100644 --- a/libmount/src/fs.c +++ b/libmount/src/fs.c @@ -691,6 +691,18 @@ const char *mnt_fs_get_options(struct libmnt_fs *fs) return fs ? fs->optstr : NULL; } +/** + * mnt_fs_get_optional_fields + * @fs: mountinfo entry pointer + * + * Returns: pointer to string with mountinfo optional fields + * or NULL in case of error. + */ +const char *mnt_fs_get_optional_fields(struct libmnt_fs *fs) +{ + assert(fs); + return fs ? fs->opt_fields : NULL; +} /** * mnt_fs_set_options: @@ -1394,6 +1406,8 @@ int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file) fprintf(file, "FS-opstr: %s\n", mnt_fs_get_fs_options(fs)); if (mnt_fs_get_user_options(fs)) fprintf(file, "user-optstr: %s\n", mnt_fs_get_user_options(fs)); + if (mnt_fs_get_optional_fields(fs)) + fprintf(file, "optional-fields: '%s'\n", mnt_fs_get_optional_fields(fs)); if (mnt_fs_get_attributes(fs)) fprintf(file, "attributes: %s\n", mnt_fs_get_attributes(fs)); diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index 06b1595a5..b93011aa8 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -327,6 +327,9 @@ extern char *mnt_fs_strdup_options(struct libmnt_fs *fs) extern const char *mnt_fs_get_options(struct libmnt_fs *fs) __ul_attribute__((nonnull)) __ul_attribute__((warn_unused_result)); +extern const char *mnt_fs_get_optional_fields(struct libmnt_fs *fs) + __ul_attribute__((nonnull)) + __ul_attribute__((warn_unused_result)); 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 9e0f2c45d..ecb3e01f7 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -248,3 +248,8 @@ global: mnt_table_find_devno; mnt_table_parse_swaps; } MOUNT_2.21; + +MOUNT_2.23 { +global: + mnt_fs_get_optional_fields; +} MOUNT_2.22; diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index 5f2f780dc..edef94c1b 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -217,6 +217,7 @@ struct libmnt_fs { char *optstr; /* fstab[4], merged options */ char *vfs_optstr; /* mountinfo[6]: fs-independent (VFS) options */ + char *opt_fields; /* mountinfo[7]: optional fields */ char *fs_optstr; /* mountinfo[11]: fs-dependent options */ char *user_optstr; /* userspace mount options */ char *attrs; /* mount attributes */ diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 56da8ec47..a8b7b79d4 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -161,6 +161,8 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s) DBG(TAB, mnt_debug("mountinfo parse error: not found separator")); return -EINVAL; } + if (p > s + 1) + fs->opt_fields = strndup(s + 1, p - s - 1); s = p + 3; rc += sscanf(s, UL_SCNsA" " /* (8) FS type */ -- cgit v1.2.3-55-g7522