Signed-off-by: Matus Marhefka <mmarh...@redhat.com> --- include/safe_macros.h | 15 ++++++++++++++- lib/safe_macros.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/include/safe_macros.h b/include/safe_macros.h index abd5f6e..d832d4f 100644 --- a/include/safe_macros.h +++ b/include/safe_macros.h @@ -226,6 +226,20 @@ int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void), #define SAFE_RENAME(cleanup_fn, oldpath, newpath) \ safe_rename(__FILE__, __LINE__, (cleanup_fn), (oldpath), (newpath)) +int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void), + const char *source, const char *target, + const char *filesystemtype, unsigned long mountflags, + const void *data); +#define SAFE_MOUNT(cleanup_fn, source, target, filesystemtype, \ + mountflags, data) \ + safe_mount(__FILE__, __LINE__, (cleanup_fn), (source), (target), \ + (filesystemtype), (mountflags), (data)) + +int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void), + const char *target); +#define SAFE_UMOUNT(cleanup_fn, target) \ + safe_umount(__FILE__, __LINE__, (cleanup_fn), (target)) + /* * following functions are inline because the behaviour may depend on * -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t compile flags @@ -354,7 +368,6 @@ static inline off_t safe_lseek(const char *file, const int lineno, #define SAFE_LSEEK(cleanup_fn, fd, offset, whence) \ safe_lseek(__FILE__, __LINE__, cleanup_fn, (fd), (offset), (whence)) - static inline int safe_getrlimit(const char *file, const int lineno, void (cleanup_fn)(void), int resource, struct rlimit *rlim) { diff --git a/lib/safe_macros.c b/lib/safe_macros.c index 05cbebd..90885fd 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -4,6 +4,7 @@ #include <sys/resource.h> #include <sys/stat.h> #include <sys/wait.h> +#include <sys/mount.h> #include <errno.h> #include <fcntl.h> #include <libgen.h> @@ -643,3 +644,38 @@ int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void), return rval; } + +int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void), + const char *source, const char *target, + const char *filesystemtype, unsigned long mountflags, + const void *data) +{ + int rval; + + rval = mount(source, target, filesystemtype, mountflags, data); + + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: mount(%s, %s, %s, %lu, %p) failed", + file, lineno, source, target, filesystemtype, + mountflags, data); + } + + return rval; +} + +int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void), + const char *target) +{ + int rval; + + rval = umount(target); + + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: umount(%s) failed", + file, lineno, target); + } + + return rval; +} -- 1.8.3.1 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list