statmount_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #define _GNU_SOURCE
  3. #include <assert.h>
  4. #include <stddef.h>
  5. #include <sched.h>
  6. #include <fcntl.h>
  7. #include <sys/param.h>
  8. #include <sys/mount.h>
  9. #include <sys/stat.h>
  10. #include <sys/statfs.h>
  11. #include <linux/stat.h>
  12. #include "statmount.h"
  13. #include "../../kselftest.h"
  14. static const char *const known_fs[] = {
  15. "9p", "adfs", "affs", "afs", "aio", "anon_inodefs", "apparmorfs",
  16. "autofs", "bcachefs", "bdev", "befs", "bfs", "binder", "binfmt_misc",
  17. "bpf", "btrfs", "btrfs_test_fs", "ceph", "cgroup", "cgroup2", "cifs",
  18. "coda", "configfs", "cpuset", "cramfs", "cxl", "dax", "debugfs",
  19. "devpts", "devtmpfs", "dmabuf", "drm", "ecryptfs", "efivarfs", "efs",
  20. "erofs", "exfat", "ext2", "ext3", "ext4", "f2fs", "functionfs",
  21. "fuse", "fuseblk", "fusectl", "gadgetfs", "gfs2", "gfs2meta", "hfs",
  22. "hfsplus", "hostfs", "hpfs", "hugetlbfs", "ibmasmfs", "iomem",
  23. "ipathfs", "iso9660", "jffs2", "jfs", "minix", "mqueue", "msdos",
  24. "nfs", "nfs4", "nfsd", "nilfs2", "nsfs", "ntfs", "ntfs3", "ocfs2",
  25. "ocfs2_dlmfs", "ocxlflash", "omfs", "openpromfs", "overlay", "pipefs",
  26. "proc", "pstore", "pvfs2", "qnx4", "qnx6", "ramfs", "reiserfs",
  27. "resctrl", "romfs", "rootfs", "rpc_pipefs", "s390_hypfs", "secretmem",
  28. "securityfs", "selinuxfs", "smackfs", "smb3", "sockfs", "spufs",
  29. "squashfs", "sysfs", "sysv", "tmpfs", "tracefs", "ubifs", "udf",
  30. "ufs", "v7", "vboxsf", "vfat", "virtiofs", "vxfs", "xenfs", "xfs",
  31. "zonefs", NULL };
  32. static struct statmount *statmount_alloc(uint64_t mnt_id, uint64_t mask, unsigned int flags)
  33. {
  34. size_t bufsize = 1 << 15;
  35. struct statmount *buf = NULL, *tmp = alloca(bufsize);
  36. int tofree = 0;
  37. int ret;
  38. for (;;) {
  39. ret = statmount(mnt_id, 0, mask, tmp, bufsize, flags);
  40. if (ret != -1)
  41. break;
  42. if (tofree)
  43. free(tmp);
  44. if (errno != EOVERFLOW)
  45. return NULL;
  46. bufsize <<= 1;
  47. tofree = 1;
  48. tmp = malloc(bufsize);
  49. if (!tmp)
  50. return NULL;
  51. }
  52. buf = malloc(tmp->size);
  53. if (buf)
  54. memcpy(buf, tmp, tmp->size);
  55. if (tofree)
  56. free(tmp);
  57. return buf;
  58. }
  59. static void write_file(const char *path, const char *val)
  60. {
  61. int fd = open(path, O_WRONLY);
  62. size_t len = strlen(val);
  63. int ret;
  64. if (fd == -1)
  65. ksft_exit_fail_msg("opening %s for write: %s\n", path, strerror(errno));
  66. ret = write(fd, val, len);
  67. if (ret == -1)
  68. ksft_exit_fail_msg("writing to %s: %s\n", path, strerror(errno));
  69. if (ret != len)
  70. ksft_exit_fail_msg("short write to %s\n", path);
  71. ret = close(fd);
  72. if (ret == -1)
  73. ksft_exit_fail_msg("closing %s\n", path);
  74. }
  75. static uint64_t get_mnt_id(const char *name, const char *path, uint64_t mask)
  76. {
  77. struct statx sx;
  78. int ret;
  79. ret = statx(AT_FDCWD, path, 0, mask, &sx);
  80. if (ret == -1)
  81. ksft_exit_fail_msg("retrieving %s mount ID for %s: %s\n",
  82. mask & STATX_MNT_ID_UNIQUE ? "unique" : "old",
  83. name, strerror(errno));
  84. if (!(sx.stx_mask & mask))
  85. ksft_exit_fail_msg("no %s mount ID available for %s\n",
  86. mask & STATX_MNT_ID_UNIQUE ? "unique" : "old",
  87. name);
  88. return sx.stx_mnt_id;
  89. }
  90. static char root_mntpoint[] = "/tmp/statmount_test_root.XXXXXX";
  91. static int orig_root;
  92. static uint64_t root_id, parent_id;
  93. static uint32_t old_root_id, old_parent_id;
  94. static FILE *f_mountinfo;
  95. static void cleanup_namespace(void)
  96. {
  97. int ret;
  98. ret = fchdir(orig_root);
  99. if (ret == -1)
  100. ksft_perror("fchdir to original root");
  101. ret = chroot(".");
  102. if (ret == -1)
  103. ksft_perror("chroot to original root");
  104. umount2(root_mntpoint, MNT_DETACH);
  105. rmdir(root_mntpoint);
  106. }
  107. static void setup_namespace(void)
  108. {
  109. int ret;
  110. char buf[32];
  111. uid_t uid = getuid();
  112. gid_t gid = getgid();
  113. ret = unshare(CLONE_NEWNS|CLONE_NEWUSER|CLONE_NEWPID);
  114. if (ret == -1)
  115. ksft_exit_fail_msg("unsharing mountns and userns: %s\n",
  116. strerror(errno));
  117. sprintf(buf, "0 %d 1", uid);
  118. write_file("/proc/self/uid_map", buf);
  119. write_file("/proc/self/setgroups", "deny");
  120. sprintf(buf, "0 %d 1", gid);
  121. write_file("/proc/self/gid_map", buf);
  122. f_mountinfo = fopen("/proc/self/mountinfo", "re");
  123. if (!f_mountinfo)
  124. ksft_exit_fail_msg("failed to open mountinfo: %s\n",
  125. strerror(errno));
  126. ret = mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL);
  127. if (ret == -1)
  128. ksft_exit_fail_msg("making mount tree private: %s\n",
  129. strerror(errno));
  130. if (!mkdtemp(root_mntpoint))
  131. ksft_exit_fail_msg("creating temporary directory %s: %s\n",
  132. root_mntpoint, strerror(errno));
  133. old_parent_id = get_mnt_id("parent", root_mntpoint, STATX_MNT_ID);
  134. parent_id = get_mnt_id("parent", root_mntpoint, STATX_MNT_ID_UNIQUE);
  135. orig_root = open("/", O_PATH);
  136. if (orig_root == -1)
  137. ksft_exit_fail_msg("opening root directory: %s",
  138. strerror(errno));
  139. atexit(cleanup_namespace);
  140. ret = mount(root_mntpoint, root_mntpoint, NULL, MS_BIND, NULL);
  141. if (ret == -1)
  142. ksft_exit_fail_msg("mounting temp root %s: %s\n",
  143. root_mntpoint, strerror(errno));
  144. ret = chroot(root_mntpoint);
  145. if (ret == -1)
  146. ksft_exit_fail_msg("chroot to temp root %s: %s\n",
  147. root_mntpoint, strerror(errno));
  148. ret = chdir("/");
  149. if (ret == -1)
  150. ksft_exit_fail_msg("chdir to root: %s\n", strerror(errno));
  151. old_root_id = get_mnt_id("root", "/", STATX_MNT_ID);
  152. root_id = get_mnt_id("root", "/", STATX_MNT_ID_UNIQUE);
  153. }
  154. static int setup_mount_tree(int log2_num)
  155. {
  156. int ret, i;
  157. ret = mount("", "/", NULL, MS_REC|MS_SHARED, NULL);
  158. if (ret == -1) {
  159. ksft_test_result_fail("making mount tree shared: %s\n",
  160. strerror(errno));
  161. return -1;
  162. }
  163. for (i = 0; i < log2_num; i++) {
  164. ret = mount("/", "/", NULL, MS_BIND, NULL);
  165. if (ret == -1) {
  166. ksft_test_result_fail("mounting submount %s: %s\n",
  167. root_mntpoint, strerror(errno));
  168. return -1;
  169. }
  170. }
  171. return 0;
  172. }
  173. static void test_listmount_empty_root(void)
  174. {
  175. ssize_t res;
  176. const unsigned int size = 32;
  177. uint64_t list[size];
  178. res = listmount(LSMT_ROOT, 0, 0, list, size, 0);
  179. if (res == -1) {
  180. ksft_test_result_fail("listmount: %s\n", strerror(errno));
  181. return;
  182. }
  183. if (res != 1) {
  184. ksft_test_result_fail("listmount result is %zi != 1\n", res);
  185. return;
  186. }
  187. if (list[0] != root_id) {
  188. ksft_test_result_fail("listmount ID doesn't match 0x%llx != 0x%llx\n",
  189. (unsigned long long) list[0],
  190. (unsigned long long) root_id);
  191. return;
  192. }
  193. ksft_test_result_pass("listmount empty root\n");
  194. }
  195. static void test_statmount_zero_mask(void)
  196. {
  197. struct statmount sm;
  198. int ret;
  199. ret = statmount(root_id, 0, 0, &sm, sizeof(sm), 0);
  200. if (ret == -1) {
  201. ksft_test_result_fail("statmount zero mask: %s\n",
  202. strerror(errno));
  203. return;
  204. }
  205. if (sm.size != sizeof(sm)) {
  206. ksft_test_result_fail("unexpected size: %u != %u\n",
  207. sm.size, (uint32_t) sizeof(sm));
  208. return;
  209. }
  210. if (sm.mask != 0) {
  211. ksft_test_result_fail("unexpected mask: 0x%llx != 0x0\n",
  212. (unsigned long long) sm.mask);
  213. return;
  214. }
  215. ksft_test_result_pass("statmount zero mask\n");
  216. }
  217. static void test_statmount_mnt_basic(void)
  218. {
  219. struct statmount sm;
  220. int ret;
  221. uint64_t mask = STATMOUNT_MNT_BASIC;
  222. ret = statmount(root_id, 0, mask, &sm, sizeof(sm), 0);
  223. if (ret == -1) {
  224. ksft_test_result_fail("statmount mnt basic: %s\n",
  225. strerror(errno));
  226. return;
  227. }
  228. if (sm.size != sizeof(sm)) {
  229. ksft_test_result_fail("unexpected size: %u != %u\n",
  230. sm.size, (uint32_t) sizeof(sm));
  231. return;
  232. }
  233. if (sm.mask != mask) {
  234. ksft_test_result_skip("statmount mnt basic unavailable\n");
  235. return;
  236. }
  237. if (sm.mnt_id != root_id) {
  238. ksft_test_result_fail("unexpected root ID: 0x%llx != 0x%llx\n",
  239. (unsigned long long) sm.mnt_id,
  240. (unsigned long long) root_id);
  241. return;
  242. }
  243. if (sm.mnt_id_old != old_root_id) {
  244. ksft_test_result_fail("unexpected old root ID: %u != %u\n",
  245. sm.mnt_id_old, old_root_id);
  246. return;
  247. }
  248. if (sm.mnt_parent_id != parent_id) {
  249. ksft_test_result_fail("unexpected parent ID: 0x%llx != 0x%llx\n",
  250. (unsigned long long) sm.mnt_parent_id,
  251. (unsigned long long) parent_id);
  252. return;
  253. }
  254. if (sm.mnt_parent_id_old != old_parent_id) {
  255. ksft_test_result_fail("unexpected old parent ID: %u != %u\n",
  256. sm.mnt_parent_id_old, old_parent_id);
  257. return;
  258. }
  259. if (sm.mnt_propagation != MS_PRIVATE) {
  260. ksft_test_result_fail("unexpected propagation: 0x%llx\n",
  261. (unsigned long long) sm.mnt_propagation);
  262. return;
  263. }
  264. ksft_test_result_pass("statmount mnt basic\n");
  265. }
  266. static void test_statmount_sb_basic(void)
  267. {
  268. struct statmount sm;
  269. int ret;
  270. uint64_t mask = STATMOUNT_SB_BASIC;
  271. struct statx sx;
  272. struct statfs sf;
  273. ret = statmount(root_id, 0, mask, &sm, sizeof(sm), 0);
  274. if (ret == -1) {
  275. ksft_test_result_fail("statmount sb basic: %s\n",
  276. strerror(errno));
  277. return;
  278. }
  279. if (sm.size != sizeof(sm)) {
  280. ksft_test_result_fail("unexpected size: %u != %u\n",
  281. sm.size, (uint32_t) sizeof(sm));
  282. return;
  283. }
  284. if (sm.mask != mask) {
  285. ksft_test_result_skip("statmount sb basic unavailable\n");
  286. return;
  287. }
  288. ret = statx(AT_FDCWD, "/", 0, 0, &sx);
  289. if (ret == -1) {
  290. ksft_test_result_fail("stat root failed: %s\n",
  291. strerror(errno));
  292. return;
  293. }
  294. if (sm.sb_dev_major != sx.stx_dev_major ||
  295. sm.sb_dev_minor != sx.stx_dev_minor) {
  296. ksft_test_result_fail("unexpected sb dev %u:%u != %u:%u\n",
  297. sm.sb_dev_major, sm.sb_dev_minor,
  298. sx.stx_dev_major, sx.stx_dev_minor);
  299. return;
  300. }
  301. ret = statfs("/", &sf);
  302. if (ret == -1) {
  303. ksft_test_result_fail("statfs root failed: %s\n",
  304. strerror(errno));
  305. return;
  306. }
  307. if (sm.sb_magic != sf.f_type) {
  308. ksft_test_result_fail("unexpected sb magic: 0x%llx != 0x%lx\n",
  309. (unsigned long long) sm.sb_magic,
  310. sf.f_type);
  311. return;
  312. }
  313. ksft_test_result_pass("statmount sb basic\n");
  314. }
  315. static void test_statmount_mnt_point(void)
  316. {
  317. struct statmount *sm;
  318. sm = statmount_alloc(root_id, STATMOUNT_MNT_POINT, 0);
  319. if (!sm) {
  320. ksft_test_result_fail("statmount mount point: %s\n",
  321. strerror(errno));
  322. return;
  323. }
  324. if (!(sm->mask & STATMOUNT_MNT_POINT)) {
  325. ksft_test_result_fail("missing STATMOUNT_MNT_POINT in mask\n");
  326. return;
  327. }
  328. if (strcmp(sm->str + sm->mnt_point, "/") != 0) {
  329. ksft_test_result_fail("unexpected mount point: '%s' != '/'\n",
  330. sm->str + sm->mnt_point);
  331. goto out;
  332. }
  333. ksft_test_result_pass("statmount mount point\n");
  334. out:
  335. free(sm);
  336. }
  337. static void test_statmount_mnt_root(void)
  338. {
  339. struct statmount *sm;
  340. const char *mnt_root, *last_dir, *last_root;
  341. last_dir = strrchr(root_mntpoint, '/');
  342. assert(last_dir);
  343. last_dir++;
  344. sm = statmount_alloc(root_id, STATMOUNT_MNT_ROOT, 0);
  345. if (!sm) {
  346. ksft_test_result_fail("statmount mount root: %s\n",
  347. strerror(errno));
  348. return;
  349. }
  350. if (!(sm->mask & STATMOUNT_MNT_ROOT)) {
  351. ksft_test_result_fail("missing STATMOUNT_MNT_ROOT in mask\n");
  352. return;
  353. }
  354. mnt_root = sm->str + sm->mnt_root;
  355. last_root = strrchr(mnt_root, '/');
  356. if (last_root)
  357. last_root++;
  358. else
  359. last_root = mnt_root;
  360. if (strcmp(last_dir, last_root) != 0) {
  361. ksft_test_result_fail("unexpected mount root last component: '%s' != '%s'\n",
  362. last_root, last_dir);
  363. goto out;
  364. }
  365. ksft_test_result_pass("statmount mount root\n");
  366. out:
  367. free(sm);
  368. }
  369. static void test_statmount_fs_type(void)
  370. {
  371. struct statmount *sm;
  372. const char *fs_type;
  373. const char *const *s;
  374. sm = statmount_alloc(root_id, STATMOUNT_FS_TYPE, 0);
  375. if (!sm) {
  376. ksft_test_result_fail("statmount fs type: %s\n",
  377. strerror(errno));
  378. return;
  379. }
  380. if (!(sm->mask & STATMOUNT_FS_TYPE)) {
  381. ksft_test_result_fail("missing STATMOUNT_FS_TYPE in mask\n");
  382. return;
  383. }
  384. fs_type = sm->str + sm->fs_type;
  385. for (s = known_fs; s != NULL; s++) {
  386. if (strcmp(fs_type, *s) == 0)
  387. break;
  388. }
  389. if (!s)
  390. ksft_print_msg("unknown filesystem type: %s\n", fs_type);
  391. ksft_test_result_pass("statmount fs type\n");
  392. free(sm);
  393. }
  394. static void test_statmount_mnt_opts(void)
  395. {
  396. struct statmount *sm;
  397. const char *statmount_opts;
  398. char *line = NULL;
  399. size_t len = 0;
  400. sm = statmount_alloc(root_id, STATMOUNT_MNT_BASIC | STATMOUNT_MNT_OPTS,
  401. 0);
  402. if (!sm) {
  403. ksft_test_result_fail("statmount mnt opts: %s\n",
  404. strerror(errno));
  405. return;
  406. }
  407. if (!(sm->mask & STATMOUNT_MNT_BASIC)) {
  408. ksft_test_result_fail("missing STATMOUNT_MNT_BASIC in mask\n");
  409. return;
  410. }
  411. while (getline(&line, &len, f_mountinfo) != -1) {
  412. int i;
  413. char *p, *p2;
  414. unsigned int old_mnt_id;
  415. old_mnt_id = atoi(line);
  416. if (old_mnt_id != sm->mnt_id_old)
  417. continue;
  418. for (p = line, i = 0; p && i < 5; i++)
  419. p = strchr(p + 1, ' ');
  420. if (!p)
  421. continue;
  422. p2 = strchr(p + 1, ' ');
  423. if (!p2)
  424. continue;
  425. *p2 = '\0';
  426. p = strchr(p2 + 1, '-');
  427. if (!p)
  428. continue;
  429. for (p++, i = 0; p && i < 2; i++)
  430. p = strchr(p + 1, ' ');
  431. if (!p)
  432. continue;
  433. p++;
  434. /* skip generic superblock options */
  435. if (strncmp(p, "ro", 2) == 0)
  436. p += 2;
  437. else if (strncmp(p, "rw", 2) == 0)
  438. p += 2;
  439. if (*p == ',')
  440. p++;
  441. if (strncmp(p, "sync", 4) == 0)
  442. p += 4;
  443. if (*p == ',')
  444. p++;
  445. if (strncmp(p, "dirsync", 7) == 0)
  446. p += 7;
  447. if (*p == ',')
  448. p++;
  449. if (strncmp(p, "lazytime", 8) == 0)
  450. p += 8;
  451. if (*p == ',')
  452. p++;
  453. p2 = strrchr(p, '\n');
  454. if (p2)
  455. *p2 = '\0';
  456. if (sm->mask & STATMOUNT_MNT_OPTS)
  457. statmount_opts = sm->str + sm->mnt_opts;
  458. else
  459. statmount_opts = "";
  460. if (strcmp(statmount_opts, p) != 0)
  461. ksft_test_result_fail(
  462. "unexpected mount options: '%s' != '%s'\n",
  463. statmount_opts, p);
  464. else
  465. ksft_test_result_pass("statmount mount options\n");
  466. free(sm);
  467. free(line);
  468. return;
  469. }
  470. ksft_test_result_fail("didnt't find mount entry\n");
  471. free(sm);
  472. free(line);
  473. }
  474. static void test_statmount_string(uint64_t mask, size_t off, const char *name)
  475. {
  476. struct statmount *sm;
  477. size_t len, shortsize, exactsize;
  478. uint32_t start, i;
  479. int ret;
  480. sm = statmount_alloc(root_id, mask, 0);
  481. if (!sm) {
  482. ksft_test_result_fail("statmount %s: %s\n", name,
  483. strerror(errno));
  484. goto out;
  485. }
  486. if (sm->size < sizeof(*sm)) {
  487. ksft_test_result_fail("unexpected size: %u < %u\n",
  488. sm->size, (uint32_t) sizeof(*sm));
  489. goto out;
  490. }
  491. if (sm->mask != mask) {
  492. ksft_test_result_skip("statmount %s unavailable\n", name);
  493. goto out;
  494. }
  495. len = sm->size - sizeof(*sm);
  496. start = ((uint32_t *) sm)[off];
  497. for (i = start;; i++) {
  498. if (i >= len) {
  499. ksft_test_result_fail("string out of bounds\n");
  500. goto out;
  501. }
  502. if (!sm->str[i])
  503. break;
  504. }
  505. exactsize = sm->size;
  506. shortsize = sizeof(*sm) + i;
  507. ret = statmount(root_id, 0, mask, sm, exactsize, 0);
  508. if (ret == -1) {
  509. ksft_test_result_fail("statmount exact size: %s\n",
  510. strerror(errno));
  511. goto out;
  512. }
  513. errno = 0;
  514. ret = statmount(root_id, 0, mask, sm, shortsize, 0);
  515. if (ret != -1 || errno != EOVERFLOW) {
  516. ksft_test_result_fail("should have failed with EOVERFLOW: %s\n",
  517. strerror(errno));
  518. goto out;
  519. }
  520. ksft_test_result_pass("statmount string %s\n", name);
  521. out:
  522. free(sm);
  523. }
  524. static void test_listmount_tree(void)
  525. {
  526. ssize_t res;
  527. const unsigned int log2_num = 4;
  528. const unsigned int step = 3;
  529. const unsigned int size = (1 << log2_num) + step + 1;
  530. size_t num, expect = 1 << log2_num;
  531. uint64_t list[size];
  532. uint64_t list2[size];
  533. size_t i;
  534. res = setup_mount_tree(log2_num);
  535. if (res == -1)
  536. return;
  537. num = res = listmount(LSMT_ROOT, 0, 0, list, size, 0);
  538. if (res == -1) {
  539. ksft_test_result_fail("listmount: %s\n", strerror(errno));
  540. return;
  541. }
  542. if (num != expect) {
  543. ksft_test_result_fail("listmount result is %zi != %zi\n",
  544. res, expect);
  545. return;
  546. }
  547. for (i = 0; i < size - step;) {
  548. res = listmount(LSMT_ROOT, 0, i ? list2[i - 1] : 0, list2 + i, step, 0);
  549. if (res == -1)
  550. ksft_test_result_fail("short listmount: %s\n",
  551. strerror(errno));
  552. i += res;
  553. if (res < step)
  554. break;
  555. }
  556. if (i != num) {
  557. ksft_test_result_fail("different number of entries: %zu != %zu\n",
  558. i, num);
  559. return;
  560. }
  561. for (i = 0; i < num; i++) {
  562. if (list2[i] != list[i]) {
  563. ksft_test_result_fail("different value for entry %zu: 0x%llx != 0x%llx\n",
  564. i,
  565. (unsigned long long) list2[i],
  566. (unsigned long long) list[i]);
  567. }
  568. }
  569. ksft_test_result_pass("listmount tree\n");
  570. }
  571. #define str_off(memb) (offsetof(struct statmount, memb) / sizeof(uint32_t))
  572. int main(void)
  573. {
  574. int ret;
  575. uint64_t all_mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC |
  576. STATMOUNT_PROPAGATE_FROM | STATMOUNT_MNT_ROOT |
  577. STATMOUNT_MNT_POINT | STATMOUNT_FS_TYPE | STATMOUNT_MNT_NS_ID;
  578. ksft_print_header();
  579. ret = statmount(0, 0, 0, NULL, 0, 0);
  580. assert(ret == -1);
  581. if (errno == ENOSYS)
  582. ksft_exit_skip("statmount() syscall not supported\n");
  583. setup_namespace();
  584. ksft_set_plan(15);
  585. test_listmount_empty_root();
  586. test_statmount_zero_mask();
  587. test_statmount_mnt_basic();
  588. test_statmount_sb_basic();
  589. test_statmount_mnt_root();
  590. test_statmount_mnt_point();
  591. test_statmount_fs_type();
  592. test_statmount_mnt_opts();
  593. test_statmount_string(STATMOUNT_MNT_ROOT, str_off(mnt_root), "mount root");
  594. test_statmount_string(STATMOUNT_MNT_POINT, str_off(mnt_point), "mount point");
  595. test_statmount_string(STATMOUNT_FS_TYPE, str_off(fs_type), "fs type");
  596. test_statmount_string(all_mask, str_off(mnt_root), "mount root & all");
  597. test_statmount_string(all_mask, str_off(mnt_point), "mount point & all");
  598. test_statmount_string(all_mask, str_off(fs_type), "fs type & all");
  599. test_listmount_tree();
  600. if (ksft_get_fail_cnt() + ksft_get_error_cnt() > 0)
  601. ksft_exit_fail();
  602. else
  603. ksft_exit_pass();
  604. }