From 0f32f1e2fca10124952ca8d83d08f56f79b669c0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 4 Jan 2011 00:43:56 +0100 Subject: [PATCH] libmount: cleanup API and docs Signed-off-by: Karel Zak --- shlibs/mount/docs/libmount-docs.xml | 7 +- shlibs/mount/docs/libmount-sections.txt | 252 ++++++++++++++---------- shlibs/mount/src/context.c | 37 +++- shlibs/mount/src/context_mount.c | 4 +- shlibs/mount/src/context_umount.c | 2 +- shlibs/mount/src/fs.c | 7 +- shlibs/mount/src/lock.c | 18 +- shlibs/mount/src/mount.h.in | 45 ++--- shlibs/mount/src/mount.sym | 5 - shlibs/mount/src/mountP.h | 10 +- shlibs/mount/src/optmap.c | 118 +---------- shlibs/mount/src/optstr.c | 11 +- shlibs/mount/src/tab.c | 6 +- shlibs/mount/src/tab_parse.c | 2 +- shlibs/mount/src/tab_update.c | 12 +- shlibs/mount/src/utils.c | 2 +- 16 files changed, 247 insertions(+), 291 deletions(-) diff --git a/shlibs/mount/docs/libmount-docs.xml b/shlibs/mount/docs/libmount-docs.xml index 25b3f71e..75802a28 100644 --- a/shlibs/mount/docs/libmount-docs.xml +++ b/shlibs/mount/docs/libmount-docs.xml @@ -28,6 +28,10 @@ available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. + + High-level API + + Files parsing @@ -36,13 +40,12 @@ available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. Mount options - - Mtab management + Misc diff --git a/shlibs/mount/docs/libmount-sections.txt b/shlibs/mount/docs/libmount-sections.txt index 59cdf47d..a7ff4c7b 100644 --- a/shlibs/mount/docs/libmount-sections.txt +++ b/shlibs/mount/docs/libmount-sections.txt @@ -13,169 +13,211 @@ mnt_get_library_version utils mnt_fstype_is_netfs mnt_fstype_is_pseudofs +mnt_get_fstab_path +mnt_get_mtab_path +mnt_has_regular_mtab +mnt_mangle mnt_match_fstype mnt_match_options +mnt_unmangle
cache mnt_cache -mnt_new_cache -mnt_free_cache -mnt_cache_find_path -mnt_cache_find_tag -mnt_cache_read_tags mnt_cache_device_has_tag mnt_cache_find_tag_value +mnt_cache_read_tags +mnt_free_cache +mnt_get_fstype +mnt_new_cache mnt_resolve_path -mnt_resolve_tag mnt_resolve_spec +mnt_resolve_tag
optstr -mnt_optstr_next_option mnt_optstr_append_option +mnt_optstr_apply_flags +mnt_optstr_get_flags mnt_optstr_get_option -mnt_optstr_set_option +mnt_optstr_get_options +mnt_optstr_next_option +mnt_optstr_prepend_option mnt_optstr_remove_option +mnt_optstr_set_option +mnt_split_optstr
iter mnt_iter -mnt_new_iter mnt_free_iter -mnt_reset_iter mnt_iter_get_direction +mnt_new_iter +mnt_reset_iter
optmap -mnt_optmap +struct mnt_optmap mnt_get_builtin_optmap
-
-optent -mnt_optent -mnt_optent_get_map -mnt_optent_get_mapent -mnt_optent_get_type -mnt_optent_set_value -mnt_optent_has_value -mnt_optent_require_value -mnt_optent_is_inverted -mnt_optent_strtoul_value -mnt_optent_strtol_value -mnt_optent_strtoull_value -mnt_optent_get_value -mnt_optent_strlen_value -mnt_optent_snprintf_value -mnt_optent_dup_value -mnt_optent_get_name -mnt_optent_get_mask -mnt_optent_get_id -mnt_optent_get_flag -mnt_optent_is_unknown -mnt_optent_print_debug -
- -
-optls -mnt_optls -mnt_new_optls -mnt_free_optls -mnt_optls_add_map -mnt_optls_add_builtin_map -mnt_optls_add_option -mnt_optls_parse_optstr -mnt_optls_remove_option -mnt_optls_remove_option_by_flags -mnt_optls_remove_option_by_iflags -mnt_optls_next_option -mnt_optls_get_option -mnt_optls_get_ids -mnt_optls_create_mountflags -mnt_optls_create_mountdata -mnt_optls_create_mtab_optstr -mnt_optls_create_userspace_optstr -mnt_optls_print_debug -
- -
lock mnt_lock -mnt_new_lock mnt_free_lock -mnt_lock_get_lockfile -mnt_lock_get_linkfile -mnt_unlock_file mnt_lock_file +mnt_new_lock +mnt_unlock_file
-
fs mnt_fs -mnt_new_fs +mnt_copy_fs mnt_free_fs -mnt_fs_get_userdata -mnt_fs_set_userdata +mnt_free_mntent +mnt_fs_append_attributes +mnt_fs_append_fs_options +mnt_fs_append_options +mnt_fs_append_userspace_options +mnt_fs_append_vfs_options +mnt_fs_get_attribute +mnt_fs_get_attributes +mnt_fs_get_bindsrc +mnt_fs_get_devno +mnt_fs_get_freq +mnt_fs_get_fs_options +mnt_fs_get_fstype +mnt_fs_get_id +mnt_fs_get_option +mnt_fs_get_parent_id +mnt_fs_get_passno +mnt_fs_get_root mnt_fs_get_source -mnt_fs_set_source mnt_fs_get_srcpath mnt_fs_get_tag mnt_fs_get_target -mnt_fs_set_target -mnt_fs_get_fstype -mnt_fs_set_fstype -mnt_fs_get_optstr -mnt_fs_set_optstr -mnt_fs_get_fs_optstr -mnt_fs_get_vfs_optstr -mnt_fs_get_freq -mnt_fs_set_freq -mnt_fs_get_passno -mnt_fs_set_passno -mnt_fs_get_id -mnt_fs_get_parent_id -mnt_fs_get_devno -mnt_fs_get_option -mnt_fs_match_target -mnt_fs_match_source +mnt_fs_get_userdata +mnt_fs_get_userspace_options +mnt_fs_get_vfs_options mnt_fs_match_fstype mnt_fs_match_options -mnt_fprintf_line -mnt_fs_fprintf +mnt_fs_match_source +mnt_fs_match_target +mnt_fs_prepend_attributes +mnt_fs_prepend_fs_options +mnt_fs_prepend_options +mnt_fs_prepend_userspace_options +mnt_fs_prepend_vfs_options mnt_fs_print_debug +mnt_fs_set_attributes +mnt_fs_set_bindsrc +mnt_fs_set_freq +mnt_fs_set_fs_options +mnt_fs_set_fstype +mnt_fs_set_options +mnt_fs_set_passno +mnt_fs_set_root +mnt_fs_set_source +mnt_fs_set_target +mnt_fs_set_userdata +mnt_fs_set_userspace_options +mnt_fs_set_vfs_options +mnt_fs_strdup_options +mnt_new_fs +mnt_fs_to_mntent
tab mnt_tab -mnt_new_tab_from_file -mnt_tab_parse_file -mnt_tab_strerror -mnt_tab_get_nerrs -mnt_new_tab mnt_free_tab -mnt_tab_get_nents -mnt_tab_set_cache +mnt_new_tab +mnt_new_tab_from_dir +mnt_new_tab_from_file +mnt_tab_add_fs +mnt_tab_find_next_fs +mnt_tab_find_pair +mnt_tab_find_source +mnt_tab_find_srcpath +mnt_tab_find_tag +mnt_tab_find_target mnt_tab_get_cache mnt_tab_get_name -mnt_tab_add_fs -mnt_tab_remove_fs -mnt_tab_next_fs -mnt_tab_next_child_fs +mnt_tab_get_nents mnt_tab_get_root_fs +mnt_tab_next_child_fs +mnt_tab_next_fs +mnt_tab_parse_file +mnt_tab_parse_fstab +mnt_tab_parse_mtab +mnt_tab_parse_stream +mnt_tab_remove_fs +mnt_tab_set_cache mnt_tab_set_iter -mnt_tab_find_target -mnt_tab_find_srcpath -mnt_tab_find_tag -mnt_tab_find_source -mnt_tab_find_next_fs -mnt_tab_fprintf -mnt_tab_update_file +mnt_tab_set_parser_errcb +
+ +
+update +mnt_update +mnt_free_update +mnt_new_update +mnt_update_force_rdonly +mnt_update_get_filename +mnt_update_get_fs +mnt_update_get_mountflags +mnt_update_is_ready +mnt_update_set_fs +mnt_update_tab +
+ +
+context +mnt_context +mnt_context_append_options +mnt_context_apply_fstab +mnt_context_disable_canonicalize +mnt_context_disable_helpers +mnt_context_disable_mtab +mnt_context_do_mount +mnt_context_do_umount +mnt_context_enable_fake +mnt_context_enable_force +mnt_context_enable_lazy +mnt_context_enable_loopdel +mnt_context_enable_rdonly_umount +mnt_context_enable_sloppy +mnt_context_enable_verbose +mnt_context_get_cache +mnt_context_get_fs +mnt_context_get_fstab +mnt_context_get_lock +mnt_context_get_mountflags +mnt_context_get_mtab +mnt_context_get_status +mnt_context_get_userspace_mountflags +mnt_context_is_restricted +mnt_context_set_cache +mnt_context_set_fs +mnt_context_set_fstab +mnt_context_set_fstype +mnt_context_set_fstype_pattern +mnt_context_set_mountdata +mnt_context_set_mountflags +mnt_context_set_options +mnt_context_set_options_pattern +mnt_context_set_optsmode +mnt_context_set_source +mnt_context_set_target +mnt_context_set_userspace_mountflags +mnt_context_strerror +mnt_free_context +mnt_new_context +mnt_reset_context
+ diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index 7eda42ff..deeb606c 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -5,6 +5,32 @@ * GNU Lesser General Public License. */ +/** + * SECTION: context + * @title: Mount/umount context + * @short_description: high-level API to mount/umount devices. + * + * + * + * mnt_context *cxt = mnt_new_context(); + * + * mnt_context_set_options(cxt, "aaa,bbb,ccc=CCC"); + * mnt_context_set_mountflags(cxt, MS_NOATIME|MS_NOEXEC); + * mnt_context_set_target(cxt, "/mnt/foo"); + * + * if (!mnt_context_do_mount(cxt)) + * printf("successfully mounted\n"); + * mnt_free_context(cxt); + * + * + * + * + * This code is similar to: + * + * mount -o aaa,bbb,ccc=CCC,noatime,noexec /mnt/foo + * + */ + #include #include #include @@ -313,7 +339,7 @@ int mnt_context_enable_force(mnt_context *cxt, int enable) * @cxt: mount context * @enable: TRUE or FALSE * - * Enable/disable verbose output (see also mnt_context_mount_strerror()). + * Enable/disable verbose output (TODO: not implemented yet) * * Returns: 0 on success, negative number in case of error. */ @@ -414,7 +440,7 @@ int mnt_context_set_target(mnt_context *cxt, const char *target) * @fstype: filesystem type * * Note that the @fstype has to be the real FS type. For comma-separated list of - * filesystems or for "no" notation use mnt_context_set_fstype_pattern(). + * filesystems or for "nofs" notation use mnt_context_set_fstype_pattern(). * * Returns: 0 on success, negative number in case of error. */ @@ -428,7 +454,7 @@ int mnt_context_set_fstype(mnt_context *cxt, const char *fstype) /** * mnt_context_set_options: * @cxt: mount context - * @options: comma delimited mount options + * @optstr: comma delimited mount options * * Returns: 0 on success, negative number in case of error. */ @@ -659,9 +685,6 @@ mnt_cache *mnt_context_get_cache(mnt_context *cxt) * remove the lock file when interrupted by signal. It means that properly written * mount(8)-like application has to call mnt_unlock_file() from a signal handler. * - * See also mnt_unlock_file(), mnt_context_disable_lock() and - * mnt_context_disable_mtab(). - * * This function returns NULL if mtab file is not writable or nolock or nomtab * flags is enabled. * @@ -1281,7 +1304,7 @@ err: * mnt_context_get_status: * @cxt: mount context * - * Returns: 1 if mount. or mount(2) syscall was successfull or 0. + * Returns: 1 if /sbin/mount.type or mount(2) syscall was successfull or 0. */ int mnt_context_get_status(mnt_context *cxt) { diff --git a/shlibs/mount/src/context_mount.c b/shlibs/mount/src/context_mount.c index 41673bc0..574a8142 100644 --- a/shlibs/mount/src/context_mount.c +++ b/shlibs/mount/src/context_mount.c @@ -417,12 +417,12 @@ static int do_mount_by_pattern(mnt_context *cxt, const char *pattern) * mnt_context_do_mount: * @cxt: mount context * - * Mount filesystem by mount(2) or fork()+exec(/sbin/mount.). + * Mount filesystem by mount(2) or fork()+exec(/sbin/mount.type). * * See also mnt_context_disable_helpers(). * * Returns: 0 on success, and negative number in case of error. WARNING: error - * does not mean that mount(2) syscall or mount. helper wasn't + * does not mean that mount(2) syscall or mount.type helper wasn't * sucessfully called. Check mnt_context_get_status() after error! */ int mnt_context_do_mount(mnt_context *cxt) diff --git a/shlibs/mount/src/context_umount.c b/shlibs/mount/src/context_umount.c index eeb7f266..9bbdc29a 100644 --- a/shlibs/mount/src/context_umount.c +++ b/shlibs/mount/src/context_umount.c @@ -444,7 +444,7 @@ static int do_umount(mnt_context *cxt) * mnt_context_do_umount: * @cxt: mount context * - * Umount filesystem by umount(2) or fork()+exec(/sbin/umount.). + * Umount filesystem by umount(2) or fork()+exec(/sbin/umount.type). * * See also mnt_context_disable_helpers(). * diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index 21e02f3d..9078f406 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -145,10 +145,7 @@ err: return NULL; } -/** - * mnt_copy_mtab_fs: - * @fs: filesystem - * +/* * This function copies all @fs description except information that does not * belong to /etc/mtab (e.g. VFS and userspace mount options with MNT_NOMTAB * mask). @@ -213,6 +210,7 @@ void *mnt_fs_get_userdata(mnt_fs *fs) /** * mnt_fs_set_userdata: * @fs: mnt_file instance + * @data: user data * * The "userdata" are library independent data. * @@ -546,6 +544,7 @@ char *mnt_fs_strdup_options(mnt_fs *fs) /** * mnt_fs_set_options: * @fs: fstab/mtab/mountinfo entry pointer + * @optstr: options string * * Splits @optstr to VFS, FS and userspace mount options and update relevat * parts of @fs. diff --git a/shlibs/mount/src/lock.c b/shlibs/mount/src/lock.c index b4fa7f7d..4ba59fe4 100644 --- a/shlibs/mount/src/lock.c +++ b/shlibs/mount/src/lock.c @@ -45,7 +45,7 @@ struct _mnt_lock { /** * mnt_new_lock: - * @dataname: the file that should be covered by the lock + * @datafile: the file that should be covered by the lock * @id: unique linkfile identifier or 0 (default is getpid()) * * Returns: newly allocated lock handler or NULL on case of error. @@ -101,27 +101,21 @@ void mnt_free_lock(mnt_lock *ml) free(ml); } -/** - * mnt_lock_get_lockfile: - * @ml: mnt_lock handler - * - * Returns: path to lockfile. +/* + * Returns path to lockfile. */ -const char *mnt_lock_get_lockfile(mnt_lock *ml) +static const char *mnt_lock_get_lockfile(mnt_lock *ml) { return ml ? ml->lockfile : NULL; } -/** - * mnt_lock_get_linkfile: - * @ml: mnt_lock handler - * +/* * Note that the filename is generated by mnt_new_lock() and depends on * getpid() or 'id' argument of the mnt_new_lock() function. * * Returns: unique (per process/thread) path to linkfile. */ -const char *mnt_lock_get_linkfile(mnt_lock *ml) +static const char *mnt_lock_get_linkfile(mnt_lock *ml) { return ml ? ml->linkfile : NULL; } diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index 3b1b5ca4..7710192a 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -126,10 +126,6 @@ extern int mnt_match_fstype(const char *type, const char *pattern); extern int mnt_match_options(const char *optstr, const char *pattern); extern const char *mnt_get_fstab_path(void); extern const char *mnt_get_mtab_path(void); - -extern int mnt_get_filesystems(char ***filesystems, const char *pattern); -extern void mnt_free_filesystems(char **filesystems); - extern int mnt_has_regular_mtab(const char **mtab, int *writable); /* cache.c */ @@ -162,7 +158,7 @@ extern int mnt_optstr_remove_option(char **optstr, const char *name); extern int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs, - int ifnore_user, int ignore_vfs); + int ignore_user, int ignore_vfs); extern int mnt_optstr_get_options(const char *optstr, char **subset, const struct mnt_optmap *map, int ignore); @@ -179,8 +175,8 @@ enum { MNT_ITER_BACKWARD }; extern mnt_iter *mnt_new_iter(int direction); -extern void mnt_free_iter(mnt_iter *mi); -extern void mnt_reset_iter(mnt_iter *mi, int direction); +extern void mnt_free_iter(mnt_iter *itr); +extern void mnt_reset_iter(mnt_iter *itr, int direction); extern int mnt_iter_get_direction(mnt_iter *itr); /* optmap.c */ @@ -193,33 +189,28 @@ extern const struct mnt_optmap *mnt_get_builtin_optmap(int id); /* lock.c */ extern mnt_lock *mnt_new_lock(const char *datafile, pid_t id); extern void mnt_free_lock(mnt_lock *ml); - -extern const char *mnt_lock_get_lockfile(mnt_lock *ml); -extern const char *mnt_lock_get_linkfile(mnt_lock *ml); - extern void mnt_unlock_file(mnt_lock *ml); extern int mnt_lock_file(mnt_lock *ml); /* fs.c */ extern mnt_fs *mnt_new_fs(void); -extern void mnt_free_fs(mnt_fs *ent); +extern void mnt_free_fs(mnt_fs *fs); extern mnt_fs *mnt_copy_fs(const mnt_fs *fs); -extern mnt_fs *mnt_copy_mtab_fs(const mnt_fs *fs); extern void *mnt_fs_get_userdata(mnt_fs *fs); extern int mnt_fs_set_userdata(mnt_fs *fs, void *data); -extern const char *mnt_fs_get_source(mnt_fs *ent); -extern int mnt_fs_set_source(mnt_fs *ent, const char *source); -extern const char *mnt_fs_get_srcpath(mnt_fs *ent); -extern int mnt_fs_get_tag(mnt_fs *ent, const char **name, const char **value); -extern const char *mnt_fs_get_target(mnt_fs *ent); -extern int mnt_fs_set_target(mnt_fs *ent, const char *target); -extern const char *mnt_fs_get_fstype(mnt_fs *ent); -extern int mnt_fs_set_fstype(mnt_fs *ent, const char *fstype); +extern const char *mnt_fs_get_source(mnt_fs *fs); +extern int mnt_fs_set_source(mnt_fs *fs, const char *source); +extern const char *mnt_fs_get_srcpath(mnt_fs *fs); +extern int mnt_fs_get_tag(mnt_fs *fs, const char **name, const char **value); +extern const char *mnt_fs_get_target(mnt_fs *fs); +extern int mnt_fs_set_target(mnt_fs *fs, const char *target); +extern const char *mnt_fs_get_fstype(mnt_fs *fs); +extern int mnt_fs_set_fstype(mnt_fs *fs, const char *fstype); extern char *mnt_fs_strdup_options(mnt_fs *fs); extern int mnt_fs_set_options(mnt_fs *fs, const char *optstr); -extern int mnt_fs_get_option(mnt_fs *ent, const char *name, +extern int mnt_fs_get_option(mnt_fs *fs, const char *name, char **value, size_t *valsz); extern int mnt_fs_append_options(mnt_fs *fs, const char *optstr); @@ -247,10 +238,10 @@ extern int mnt_fs_get_attribute(mnt_fs *fs, const char *name, extern int mnt_fs_append_attributes(mnt_fs *fs, const char *optstr); extern int mnt_fs_prepend_attributes(mnt_fs *fs, const char *optstr); -extern int mnt_fs_get_freq(mnt_fs *ent); -extern int mnt_fs_set_freq(mnt_fs *ent, int freq); -extern int mnt_fs_get_passno(mnt_fs *ent); -extern int mnt_fs_set_passno(mnt_fs *ent, int passno); +extern int mnt_fs_get_freq(mnt_fs *fs); +extern int mnt_fs_set_freq(mnt_fs *fs, int freq); +extern int mnt_fs_get_passno(mnt_fs *fs); +extern int mnt_fs_set_passno(mnt_fs *fs, int passno); extern const char *mnt_fs_get_root(mnt_fs *fs); extern int mnt_fs_set_root(mnt_fs *fs, const char *root); extern const char *mnt_fs_get_bindsrc(mnt_fs *fs); @@ -263,7 +254,7 @@ extern int mnt_fs_match_target(mnt_fs *fs, const char *target, mnt_cache *cache) extern int mnt_fs_match_source(mnt_fs *fs, const char *source, mnt_cache *cache); extern int mnt_fs_match_fstype(mnt_fs *fs, const char *types); extern int mnt_fs_match_options(mnt_fs *fs, const char *options); -extern int mnt_fs_print_debug(mnt_fs *ent, FILE *file); +extern int mnt_fs_print_debug(mnt_fs *fs, FILE *file); extern void mnt_free_mntent(struct mntent *mnt); extern int mnt_fs_to_mntent(mnt_fs *fs, struct mntent **mnt); diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index a62615e8..673f8c80 100644 --- a/shlibs/mount/src/mount.sym +++ b/shlibs/mount/src/mount.sym @@ -46,10 +46,8 @@ global: mnt_context_set_userspace_mountflags; mnt_context_strerror; mnt_copy_fs; - mnt_copy_mtab_fs; mnt_free_cache; mnt_free_context; - mnt_free_filesystems; mnt_free_fs; mnt_free_iter; mnt_free_lock; @@ -107,7 +105,6 @@ global: mnt_fs_to_mntent; mnt_fstype_is_netfs; mnt_fstype_is_pseudofs; - mnt_get_filesystems; mnt_get_fstab_path; mnt_get_fstype; mnt_get_library_version; @@ -116,8 +113,6 @@ global: mnt_init_debug; mnt_iter_get_direction; mnt_lock_file; - mnt_lock_get_linkfile; - mnt_lock_get_lockfile; mnt_mangle; mnt_match_fstype; mnt_match_options; diff --git a/shlibs/mount/src/mountP.h b/shlibs/mount/src/mountP.h index 351bd3c5..f9e3a3f7 100644 --- a/shlibs/mount/src/mountP.h +++ b/shlibs/mount/src/mountP.h @@ -123,6 +123,9 @@ extern int mnt_open_uniq_filename(const char *filename, char **name, int flags); extern int mnt_has_regular_utab(const char **utab, int *writable); extern const char *mnt_get_utab_path(void); +extern int mnt_get_filesystems(char ***filesystems, const char *pattern); +extern void mnt_free_filesystems(char **filesystems); + /* * Generic iterator */ @@ -292,10 +295,6 @@ struct _mnt_context extern const struct mnt_optmap *mnt_optmap_get_entry(struct mnt_optmap const **maps, int nmaps, const char *name, size_t namelen, const struct mnt_optmap **mapent); -extern int mnt_optmap_enum_to_number(const struct mnt_optmap *mapent, - const char *rawdata, size_t len); -extern const char *mnt_optmap_get_type(const struct mnt_optmap *mapent); -extern int mnt_optmap_require_value(const struct mnt_optmap *mapent); /* optstr.c */ extern int mnt_optstr_remove_option_at(char **optstr, char *begin, char *end); @@ -305,10 +304,9 @@ extern int mnt_optstr_fix_secontext(char **optstr, char *value, size_t valsz, ch extern int mnt_optstr_fix_user(char **optstr); /* fs.c */ +extern mnt_fs *mnt_copy_mtab_fs(const mnt_fs *fs); extern int __mnt_fs_set_source_ptr(mnt_fs *fs, char *source); extern int __mnt_fs_set_fstype_ptr(mnt_fs *fs, char *fstype); -extern int __mnt_fs_set_optstr_ptr(mnt_fs *fs, char *optstr, int split); -extern int __mnt_fs_set_optstr(mnt_fs *fs, const char *optstr, int split); /* context.c */ extern int mnt_context_prepare_srcpath(mnt_context *cxt); diff --git a/shlibs/mount/src/optmap.c b/shlibs/mount/src/optmap.c index 38256b09..307a5d4b 100644 --- a/shlibs/mount/src/optmap.c +++ b/shlibs/mount/src/optmap.c @@ -16,37 +16,21 @@ * * @mountdata: (usully a comma separated string of options) * - * The libmount uses options-map(s) to describe mount options. The number of - * maps is unlimited. The libmount options parser could be easily extended - * (e.g. by mnt_optls_add_map()) to work with new options. + * The libmount uses options-map(s) to describe mount options. * * The option description (map entry) includes: * - * @name: and argument type (e.g. "loop[=%s]") + * @name: and argument name * * @id: (in the map unique identifier or a mountflags, e.g MS_RDONLY) * * @mask: (MNT_INVERT, MNT_NOMTAB) * - * The option argument type is defined by: + * The option argument value is defined by: * - * "=type" -- required argument + * "=" -- required argument, e.g "comment=" * - * "[=type]" -- optional argument - * - * where the 'type' is sscanf() format string or - * - * {item0,item1,...} -- enum (mnt_option_get_number() converts the value - * to 0..N number) - * - * The options argument format is used for parsing only. The library internally - * stores the option argument as a string. The conversion to the data type is - * on-demant by mnt_option_get_value_*() functions. - * - * The library checks options argument according to 'type' format for simple - * formats only: - * - * %s, %d, %ld, %lld, %u, %lu, %llu, %x, %o and {enum} + * "[=]" -- optional argument, e.g. "loop[=]" * * Example: * @@ -58,7 +42,7 @@ * mnt_optmap myoptions[] = { * { "foo", MY_MS_FOO }, * { "nofoo", MY_MS_FOO | MNT_INVERT }, - * { "bar=%s",MY_MS_BAR }, + * { "bar=", MY_MS_BAR }, * { NULL } * }; * @@ -149,7 +133,7 @@ static const struct mnt_optmap userspace_opts_map[] = { "auto", MNT_MS_NOAUTO, MNT_INVERT | MNT_NOMTAB }, /* Can be mounted using -a */ { "noauto", MNT_MS_NOAUTO, MNT_NOMTAB }, /* Can only be mounted explicitly */ - { "user[=%s]", MNT_MS_USER }, /* Allow ordinary user to mount (mtab) */ + { "user[=]", MNT_MS_USER }, /* Allow ordinary user to mount (mtab) */ { "nouser", MNT_MS_USER, MNT_INVERT | MNT_NOMTAB }, /* Forbid ordinary user to mount */ { "users", MNT_MS_USERS, MNT_NOMTAB }, /* Allow ordinary users to mount */ @@ -163,13 +147,13 @@ static const struct mnt_optmap userspace_opts_map[] = { "_netdev", MNT_MS_NETDEV }, /* Device requires network */ - { "comment=%s", MNT_MS_COMMENT, MNT_NOMTAB }, /* fstab comment only */ + { "comment=", MNT_MS_COMMENT, MNT_NOMTAB }, /* fstab comment only */ - { "loop[=%s]", MNT_MS_LOOP }, /* use the loop device */ + { "loop[=]", MNT_MS_LOOP }, /* use the loop device */ { "nofail", MNT_MS_NOFAIL, MNT_NOMTAB }, /* Do not fail if ENOENT on dev */ - { "uhelper=%s", MNT_MS_UHELPER }, /* /sbin/umount. */ + { "uhelper=", MNT_MS_UHELPER }, /* /sbin/umount. */ { NULL, 0, 0 } }; @@ -237,85 +221,3 @@ const struct mnt_optmap *mnt_optmap_get_entry( return NULL; } - -/* - * Converts @rawdata to number according to enum definition in the @mapent. - */ -int mnt_optmap_enum_to_number(const struct mnt_optmap *mapent, - const char *rawdata, size_t len) -{ - const char *p, *end = NULL, *begin = NULL; - int n = -1; - - if (!rawdata || !*rawdata || !mapent || !len) - return -EINVAL; - - p = strrchr(mapent->name, '='); - if (!p || *(p + 1) == '{') - return -EINVAL; /* value unexpected or not "enum" */ - p += 2; - if (!*p || *(p + 1) == '}') - return -EINVAL; /* hmm... option is "={" or "={}" */ - - /* we cannot use strstr(), @rawdata is not terminated */ - for (; p && *p; p++) { - if (!begin) - begin = p; /* begin of the item */ - if (*p == ',') - end = p; /* terminate the item */ - if (*(p + 1) == '}') - end = p + 1; /* end of enum definition */ - if (!begin || !end) - continue; - if (end <= begin) - return -EINVAL; - n++; - if (len == end - begin && strncasecmp(begin, rawdata, len) == 0) - return n; - p = end; - } - - return -1; -} - -/* - * Returns data type defined in the @mapent. - */ -const char *mnt_optmap_get_type(const struct mnt_optmap *mapent) -{ - char *type; - - assert(mapent); - assert(mapent->name); - - type = strrchr(mapent->name, '='); - if (!type) - return NULL; /* value is unexpected */ - if (type == mapent->name) - return NULL; /* wrong format of type definition */ - type++; - if (*type != '%' && *type != '{') - return NULL; /* wrong format of type definition */ - return type ? : NULL; -} - -/* - * Does the option (that is described by @mntent) require any value? (e.g. - * uid=) - */ -int mnt_optmap_require_value(const struct mnt_optmap *mapent) -{ - char *type; - - assert(mapent); - assert(mapent->name); - - type = strchr(mapent->name, '='); - if (!type) - return 0; /* value is unexpected */ - if (type == mapent->name) - return 0; /* wrong format of type definition */ - if (*(type - 1) == '[') - return 0; /* optional */ - return 1; -} diff --git a/shlibs/mount/src/optstr.c b/shlibs/mount/src/optstr.c index 7c41f685..8894dfba 100644 --- a/shlibs/mount/src/optstr.c +++ b/shlibs/mount/src/optstr.c @@ -454,8 +454,7 @@ int mnt_optstr_remove_option(char **optstr, const char *name) * * Returns: 0 on success, or negative number in case of error. */ -int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs, - int ignore_user, int ignore_vfs) +int mnt_split_optstr(const char *optstr, char **user, char **vfs, char **fs, int ignore_user, int ignore_vfs) { char *name, *val, *str = (char *) optstr; size_t namesz, valsz; @@ -569,6 +568,7 @@ int mnt_optstr_get_options(const char *optstr, char **subset, * mnt_optstr_get_flags: * @optstr: string with comma separated list of options * @flags: returns mount flags + * @map: options map * * Returns in @flags IDs of options from @optstr as defined in the @map. * @@ -583,7 +583,6 @@ int mnt_optstr_get_options(const char *optstr, char **subset, * * Returns: 0 on success or negative number in case of error */ - int mnt_optstr_get_flags(const char *optstr, unsigned long *flags, const struct mnt_optmap *map) { @@ -615,7 +614,7 @@ int mnt_optstr_get_flags(const char *optstr, unsigned long *flags, } /** - * mnt_optstr_apply_mountflags: + * mnt_optstr_apply_flags: * @optstr: string with comma separated list of options * @flags: returns mount flags * @map: options map @@ -717,9 +716,9 @@ int mnt_optstr_apply_flags(char **optstr, unsigned long flags, p = strchr(ent->name, '='); if (p) { if (*(p - 1) == '[') - p--; /* name[=%s] */ + p--; /* name[=] */ else - continue; /* name=%s */ + continue; /* name= */ p = strndup(ent->name, p - ent->name); if (!p) { diff --git a/shlibs/mount/src/tab.c b/shlibs/mount/src/tab.c index 94683c19..6f845e21 100644 --- a/shlibs/mount/src/tab.c +++ b/shlibs/mount/src/tab.c @@ -7,7 +7,7 @@ /** * SECTION: tab - * @title: FS container + * @title: Table of filesystems * @short_description: container for entries from fstab/mtab/mountinfo * * @@ -300,7 +300,7 @@ int mnt_tab_next_child_fs(mnt_tab *tb, mnt_iter *itr, * * Returns: 0 on success, negative number in case of error or 1 at end of list. * - * Example (list all mountpoints from fstab in backward order): + * Example: * * * mnt_fs *fs; @@ -316,6 +316,8 @@ int mnt_tab_next_child_fs(mnt_tab *tb, mnt_iter *itr, * mnt_free_tab(fi); * * + * + * lists all mountpoints from fstab in backward order. */ int mnt_tab_next_fs(mnt_tab *tb, mnt_iter *itr, mnt_fs **fs) { diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 335f703a..e202bc9c 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -522,7 +522,7 @@ mnt_tab *mnt_new_tab_from_dir(const char *dirname) /** * mnt_tab_set_parser_errcb: - * @tab: pointer to table + * @tb: pointer to table * @cb: pointer to callback function * * The error callback function is called by table parser (mnt_tab_parse_file()) diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index 9638f47c..cf32baf1 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -7,8 +7,15 @@ /** * SECTION: update - * @title: mtab (fstab) managment - * @short_description: userspace mount information management + * @title: mtab managment + * @short_description: userspace mount information management. + * + * The mnt_update provides abstraction to manage mount options in userspace independently on + * system configuration. This low-level API works on system with and without /etc/mtab. On + * systems without the regular /etc/mtab file are userspace mount options (e.g. user=) + * stored to the /dev/.mount/utab file. + * + * It's recommended to use high-level mnt_context API. */ #include @@ -770,6 +777,7 @@ static int update_modify_options(mnt_update *upd, mnt_lock *lc) /** * mnt_update_tab: + * @upd: update * @lc: lock * * High-level API to update /etc/mtab (or private /dev/.mount/utab file). diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index c97144dc..99708333 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -613,7 +613,7 @@ const char *mnt_get_fstab_path(void) * mnt_get_mtab_path: * * This function returns *default* location of the mtab file. The result does - * not have to be writable. See also mnt_get_writable_mtab_path(). + * not have to be writable. See also mnt_has_regular_mtab(). * * Returns: path to /etc/mtab or $LIBMOUNT_MTAB. */ -- 2.39.5