1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
4 */
5
6 #ifndef STATMOUNT_H
7 #define STATMOUNT_H
8
9 #define _GNU_SOURCE
10
11 #include "tst_test.h"
12 #include "lapi/mount.h"
13 #include "lapi/syscalls.h"
14 #include "tst_safe_stdio.h"
15
statmount(uint64_t mnt_id,uint64_t mask,struct statmount * buf,size_t bufsize,unsigned int flags)16 static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *buf,
17 size_t bufsize, unsigned int flags)
18 {
19 struct mnt_id_req req = {
20 .size = MNT_ID_REQ_SIZE_VER0,
21 .mnt_id = mnt_id,
22 .param = mask,
23 };
24
25 return tst_syscall(__NR_statmount, &req, buf, bufsize, flags);
26 }
27
read_peer_group(const char * path)28 static inline int read_peer_group(const char *path)
29 {
30 FILE *file;
31 char line[PATH_MAX];
32 char mroot[PATH_MAX];
33 int group = -1;
34
35 file = SAFE_FOPEN("/proc/self/mountinfo", "r");
36
37 while (fgets(line, sizeof(line), file)) {
38 if (sscanf(line, "%*d %*d %*d:%*d %s %*s %*s shared:%d", mroot, &group) != 2)
39 continue;
40
41 if (strcmp(mroot, path) == 0)
42 break;
43 }
44
45 if (group == -1)
46 tst_brk(TBROK, "Can't reed peer group ID for %s", path);
47
48 return group;
49 }
50
51 #endif
52