• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*\
7  * [Description]
8  *
9  * This test verifies that statmount() is correctly reading basic filesystem
10  * info using STATMOUNT_SB_BASIC.
11  * The btrfs validation is currently skipped due to the lack of support for VFS.
12  *
13  * [Algorithm]
14  *
15  * - create a mount point and read its mount info
16  * - run statmount() on the mount point using STATMOUNT_SB_BASIC
17  * - read results and check if mount info are correct
18  */
19 
20 #define _GNU_SOURCE
21 
22 #include "statmount.h"
23 #include "lapi/stat.h"
24 #include "lapi/sched.h"
25 #include <linux/btrfs.h>
26 
27 #define MNTPOINT "mntpoint"
28 
29 static struct statmount *st_mount;
30 static struct ltp_statx *sx_mount;
31 static struct statfs *sf_mount;
32 
run(void)33 static void run(void)
34 {
35 	memset(st_mount, 0, sizeof(struct statmount));
36 
37 	TST_EXP_PASS(statmount(sx_mount->data.stx_mnt_id, STATMOUNT_SB_BASIC,
38 		st_mount, sizeof(struct statmount), 0));
39 
40 	if (!TST_PASS)
41 		return;
42 
43 	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_SB_BASIC);
44 	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
45 	TST_EXP_EQ_LI(st_mount->sb_dev_major, sx_mount->data.stx_dev_major);
46 	TST_EXP_EQ_LI(st_mount->sb_dev_minor, sx_mount->data.stx_dev_minor);
47 	TST_EXP_EQ_LI(st_mount->sb_magic, sf_mount->f_type);
48 	TST_EXP_EQ_LI(st_mount->sb_flags, MS_RDONLY);
49 }
50 
setup(void)51 static void setup(void)
52 {
53 	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, MS_RDONLY, NULL);
54 
55 	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, sx_mount);
56 	SAFE_STATFS(MNTPOINT, sf_mount);
57 }
58 
cleanup(void)59 static void cleanup(void)
60 {
61 	if (tst_is_mounted(MNTPOINT))
62 		SAFE_UMOUNT(MNTPOINT);
63 }
64 
65 static struct tst_test test = {
66 	.test_all = run,
67 	.setup = setup,
68 	.cleanup = cleanup,
69 	.min_kver = "6.8",
70 	.mntpoint = MNTPOINT,
71 	.format_device = 1,
72 	.all_filesystems = 1,
73 	.skip_filesystems = (const char *const []) {
74 		"fuse",
75 		"btrfs",
76 		NULL
77 	},
78 	.bufs = (struct tst_buffers []) {
79 		{&st_mount, .size = sizeof(struct statmount)},
80 		{&sx_mount, .size = sizeof(struct ltp_statx)},
81 		{&sf_mount, .size = sizeof(struct statfs)},
82 		{}
83 	}
84 };
85