Add a helper to allocate a statmount buffer and call statmount(). This helper will be shared by multiple test suites that need to query mount information via statmount(). Signed-off-by: Christian Brauner --- .../selftests/filesystems/statmount/statmount.h | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/filesystems/statmount/statmount.h b/tools/testing/selftests/filesystems/statmount/statmount.h index e1cba4bfd8d9..4ef23e54212c 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount.h +++ b/tools/testing/selftests/filesystems/statmount/statmount.h @@ -3,10 +3,14 @@ #ifndef __STATMOUNT_H #define __STATMOUNT_H +#include #include +#include #include #include +#define STATMOUNT_BUFSIZE (1 << 15) + #ifndef __NR_statmount #if defined __alpha__ #define __NR_statmount 567 @@ -84,4 +88,27 @@ static inline ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id, return syscall(__NR_listmount, &req, list, num, flags); } +static inline struct statmount *statmount_alloc(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask) +{ + struct statmount *buf; + size_t bufsize = STATMOUNT_BUFSIZE; + int ret; + + for (;;) { + buf = malloc(bufsize); + if (!buf) + return NULL; + + ret = statmount(mnt_id, mnt_ns_id, 0, mask, buf, bufsize, 0); + if (ret == 0) + return buf; + + free(buf); + if (errno != EOVERFLOW) + return NULL; + + bufsize <<= 1; + } +} + #endif /* __STATMOUNT_H */ -- 2.47.3