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

Petr Vorel
2025-02-27T16:27:40Z

Hi Wei,

> +++ 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);
> + }

@Wei We usually add only function signature to headers, the rest goes into
lib/tst_safe_macros.c. The only exception are functions in
include/tst_safe_macros_inline.h due off_t or structs which contain it, which is
not this case.

Besides following ioctl_fiemap01.c it could be used also in libs/swap/libswap.c
and lib/tst_fill_fs.c, where we don't even check return code. Not that many
cases but probably useful.

FYI fstatvfs() with TBROK is used in fsync02.c not sure if to add it as well.

Kind regards,
Petr