[LTP] [PATCH v7 1/2] tst_safe_macros.h: Add SAFE_STATVFS

Wei Gao via ltp
2025-04-14T13:40:37Z

Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
include/tst_safe_macros.h | 6 ++++++
lib/tst_safe_macros.c | 19 +++++++++++++++++++
2 files changed, 25 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 3b02f86c7..19504beb5 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -12,6 +12,7 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/vfs.h>
#include <sys/sysinfo.h>
#include <sys/uio.h>
@@ -503,4 +504,9 @@ char *safe_ptsname(const char *const file, const int lineno, int masterfd);
#define SAFE_PTSNAME(masterfd) \
safe_ptsname(__FILE__, __LINE__, (masterfd))

+int safe_statvfs(const char *file, const int lineno,
+ const char *path, struct statvfs *buf);
+#define SAFE_STATVFS(path, buf) \
+ safe_statvfs(__FILE__, __LINE__, (path), (buf))
+
#endif /* TST_SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index ba095a621..cdc8c7dd3 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -810,3 +810,22 @@ char *safe_ptsname(const char *const file, const int lineno, int masterfd)

return name;
}
+
+int safe_statvfs(const char *file, const int lineno,
+ const char *path, struct statvfs *buf)
+{
+ int rval;
+
+ rval = statvfs(path, buf);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "statvfs(%s,%p) failed", path, buf);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid statvfs(%s,%p) return value %d", path, buf,
+ rval);
+ }
+
+ return rval;
+}
--
2.49.0