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

Wei Gao via ltp
2024-12-12T08:51:54Z

Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_safe_macros.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index f2ce8919b..777f81b5f 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -429,6 +429,27 @@ static inline int safe_statfs(const char *file, const int lineno,
#define SAFE_STATFS(path, buf) \
safe_statfs(__FILE__, __LINE__, (path), (buf))

+static inline 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;
+}
+#define SAFE_STATVFS(path, buf) \
+ safe_statvfs(__FILE__, __LINE__, (path), (buf))
+
static inline off_t safe_lseek(const char *file, const int lineno,
int fd, off_t offset, int whence)
{
--
2.35.3