From d300992de138c4c1f52a41ade64e24fbf8fbf2ce Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 30 Sep 2010 10:42:20 +0200 Subject: libmount: extend mnt_update_* API Signed-off-by: Karel Zak --- shlibs/mount/src/mount.h.in | 3 +++ shlibs/mount/src/mount.sym | 2 ++ shlibs/mount/src/tab_update.c | 57 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) (limited to 'shlibs') diff --git a/shlibs/mount/src/mount.h.in b/shlibs/mount/src/mount.h.in index cf491151..0124a329 100644 --- a/shlibs/mount/src/mount.h.in +++ b/shlibs/mount/src/mount.h.in @@ -285,6 +285,8 @@ extern int mnt_tab_find_next_fs(mnt_tab *tb, mnt_iter *itr, extern mnt_update *mnt_new_update(int action, unsigned long mountflags, const mnt_fs *fs); extern void mnt_free_update(mnt_update *upd); extern int mnt_update_set_filename(mnt_update *upd, const char *filename); +extern const char *mnt_update_get_filename(mnt_update *upd); +extern int mnt_update_get_format(mnt_update *upd); extern int mnt_update_set_action(mnt_update *upd, int action); extern int mnt_update_set_format(mnt_update *upd, int format); extern int mnt_update_set_mountflags(mnt_update *upd, unsigned long flags); @@ -295,6 +297,7 @@ extern int mnt_update_set_fs(mnt_update *upd, const mnt_fs *fs); extern int mnt_prepare_update(mnt_update *upd); extern int mnt_update_mtab(mnt_update *upd); +extern int mnt_update_is_pointless(mnt_update *upd); /* * mount(8) userspace options masks (MNT_MAP_USERSPACE map) diff --git a/shlibs/mount/src/mount.sym b/shlibs/mount/src/mount.sym index bb1ae4f9..19a723a4 100644 --- a/shlibs/mount/src/mount.sym +++ b/shlibs/mount/src/mount.sym @@ -125,6 +125,8 @@ global: mnt_update_set_fs; mnt_update_set_mountflags; mnt_update_set_old_target; + mnt_update_get_format; + mnt_update_get_filename; local: *; }; diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index 1573b58b..8b322dde 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -64,6 +64,7 @@ struct _mnt_update { int nolock; /* don't alloca private mnt_lock */ mnt_fs *fs; /* entry */ mnt_lock *lc; /* lock or NULL */ + int pointless; /* update is unnecessary */ }; /** @@ -136,6 +137,20 @@ int mnt_update_set_filename(mnt_update *upd, const char *filename) return 0; } +/** + * mnt_update_get_filename + * @upd: update + * + * Note that function returns NULL if the filename has not been defined (see + * mnt_update_set_filename()) or mnt_prepare_update() has not been called. + * + * Returns: filename or NULL. + */ +const char *mnt_update_get_filename(mnt_update *upd) +{ + return upd ? upd->filename : NULL; +} + /** * mnt_update_set_action: * @upd: update @@ -174,11 +189,28 @@ int mnt_update_set_format(mnt_update *upd, int format) return 0; } +/** + * mnt_update_get_format + * @upd: update + * + * Note that function returns zero if the format has not been defined (see + * mnt_update_set_format()) or mnt_prepare_update() has not been called. + * + * Returns: MNT_FMT_{MTAB,FSTAB,MOUNTINFO} or 0. + */ +int mnt_update_get_format(mnt_update *upd) +{ + return upd ? upd->format : 0; +} + /** * mnt_update_set_fs: * @upd: update * @fs: filesystem to write to file * + * This function replaces the current setting related to the current FS. Note that + * format, old target and mountflags are not reseted. + * * Returns; 0 on success, -1 in case of error. */ int mnt_update_set_fs(mnt_update *upd, const mnt_fs *fs) @@ -196,6 +228,7 @@ int mnt_update_set_fs(mnt_update *upd, const mnt_fs *fs) mnt_free_fs(upd->fs); upd->fs = x; + upd->pointless = FALSE; return 0; } @@ -517,6 +550,20 @@ err: return -1; } +/** + * mnt_update_is_pointless: + * @upd: update + * + * This function returns 1 if the previous mnt_prepare_update() call returned 1 + * too. + * + * Returns: status of the update. + */ +int mnt_update_is_pointless(mnt_update *upd) +{ + return upd ? upd->pointless : 0; +} + /** * mnt_prepare_update: * @upd: update @@ -642,6 +689,8 @@ err: DBG(UPDATE, mnt_debug_h(upd, "prepare update: failed")); return rc; nothing: + upd->pointless = TRUE; + DBG(UPDATE, mnt_debug_h(upd, "prepare update: pointless")); return 1; } @@ -788,7 +837,8 @@ done: * @upd: update * * Updates the update file. The behavior of this function is undefined if - * mnt_prepare_update() has not been called. + * mnt_prepare_update() has not been called. The request to update file will + * be ignored for pointless updates (see mnt_update_is_pointless()). * * Returns: 0 on success, -1 in case of error. */ @@ -802,6 +852,11 @@ int mnt_update_file(mnt_update *upd) if (!upd || !upd->fs) return -1; + if (upd->pointless) { + DBG(UPDATE, mnt_debug_h(upd, "ingnore update requiest (pointless)")); + return 0; + } + DBG(UPDATE, mnt_debug_h(upd, "update (target %s)", mnt_fs_get_target(upd->fs))); /* -- cgit v1.2.3