1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2022 SUSE LLC <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker */
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * Test whether the kernel properly advertises support for statx() attributes:
10*49cdfc7eSAndroid Build Coastguard Worker *
11*49cdfc7eSAndroid Build Coastguard Worker * - STATX_ATTR_COMPRESSED: The file is compressed by the filesystem.
12*49cdfc7eSAndroid Build Coastguard Worker * - STATX_ATTR_IMMUTABLE: The file cannot be modified.
13*49cdfc7eSAndroid Build Coastguard Worker * - STATX_ATTR_APPEND: The file can only be opened in append mode for writing.
14*49cdfc7eSAndroid Build Coastguard Worker * - STATX_ATTR_NODUMP: File is not a candidate for backup when a backup
15*49cdfc7eSAndroid Build Coastguard Worker * program such as dump(8) is run.
16*49cdfc7eSAndroid Build Coastguard Worker *
17*49cdfc7eSAndroid Build Coastguard Worker * xfs filesystem doesn't support STATX_ATTR_COMPRESSED flag, so we only test
18*49cdfc7eSAndroid Build Coastguard Worker * three other flags.
19*49cdfc7eSAndroid Build Coastguard Worker *
20*49cdfc7eSAndroid Build Coastguard Worker * ext2, ext4, btrfs, xfs and tmpfs support statx syscall since the following commit
21*49cdfc7eSAndroid Build Coastguard Worker *
22*49cdfc7eSAndroid Build Coastguard Worker * commit 93bc420ed41df63a18ae794101f7cbf45226a6ef
23*49cdfc7eSAndroid Build Coastguard Worker * Author: yangerkun <[email protected]>
24*49cdfc7eSAndroid Build Coastguard Worker * Date: Mon Feb 18 09:07:02 2019 +0800
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * ext2: support statx syscall
27*49cdfc7eSAndroid Build Coastguard Worker *
28*49cdfc7eSAndroid Build Coastguard Worker * commit 99652ea56a4186bc5bf8a3721c5353f41b35ebcb
29*49cdfc7eSAndroid Build Coastguard Worker * Author: David Howells <[email protected]>
30*49cdfc7eSAndroid Build Coastguard Worker * Date: Fri Mar 31 18:31:56 2017 +0100
31*49cdfc7eSAndroid Build Coastguard Worker *
32*49cdfc7eSAndroid Build Coastguard Worker * ext4: Add statx support
33*49cdfc7eSAndroid Build Coastguard Worker *
34*49cdfc7eSAndroid Build Coastguard Worker * commit 04a87e3472828f769a93655d7c64a27573bdbc2c
35*49cdfc7eSAndroid Build Coastguard Worker * Author: Yonghong Song <[email protected]>
36*49cdfc7eSAndroid Build Coastguard Worker * Date: Fri May 12 15:07:43 2017 -0700
37*49cdfc7eSAndroid Build Coastguard Worker *
38*49cdfc7eSAndroid Build Coastguard Worker * Btrfs: add statx support
39*49cdfc7eSAndroid Build Coastguard Worker *
40*49cdfc7eSAndroid Build Coastguard Worker * commit 5f955f26f3d42d04aba65590a32eb70eedb7f37d
41*49cdfc7eSAndroid Build Coastguard Worker * Author: Darrick J. Wong <[email protected]>
42*49cdfc7eSAndroid Build Coastguard Worker * Date: Fri Mar 31 18:32:03 2017 +0100
43*49cdfc7eSAndroid Build Coastguard Worker *
44*49cdfc7eSAndroid Build Coastguard Worker * xfs: report crtime and attribute flags to statx
45*49cdfc7eSAndroid Build Coastguard Worker *
46*49cdfc7eSAndroid Build Coastguard Worker * commit e408e695f5f1f60d784913afc45ff2c387a5aeb8
47*49cdfc7eSAndroid Build Coastguard Worker * Author: Theodore Ts'o <[email protected]>
48*49cdfc7eSAndroid Build Coastguard Worker * Date: Thu Jul 14 21:59:12 2022 -0400
49*49cdfc7eSAndroid Build Coastguard Worker *
50*49cdfc7eSAndroid Build Coastguard Worker * mm/shmem: support FS_IOC_[SG]ETFLAGS in tmpfs
51*49cdfc7eSAndroid Build Coastguard Worker *
52*49cdfc7eSAndroid Build Coastguard Worker */
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker #define _GNU_SOURCE
55*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
56*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
57*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/fs.h"
58*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/stat.h"
59*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/fcntl.h"
60*49cdfc7eSAndroid Build Coastguard Worker
61*49cdfc7eSAndroid Build Coastguard Worker #define MOUNT_POINT "mntpoint"
62*49cdfc7eSAndroid Build Coastguard Worker #define TESTDIR MOUNT_POINT "/testdir"
63*49cdfc7eSAndroid Build Coastguard Worker
64*49cdfc7eSAndroid Build Coastguard Worker #define ATTR(x) {.attr = x, .name = #x}
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker static struct {
67*49cdfc7eSAndroid Build Coastguard Worker uint64_t attr;
68*49cdfc7eSAndroid Build Coastguard Worker const char *name;
69*49cdfc7eSAndroid Build Coastguard Worker } attr_list[] = {
70*49cdfc7eSAndroid Build Coastguard Worker ATTR(STATX_ATTR_COMPRESSED),
71*49cdfc7eSAndroid Build Coastguard Worker ATTR(STATX_ATTR_APPEND),
72*49cdfc7eSAndroid Build Coastguard Worker ATTR(STATX_ATTR_IMMUTABLE),
73*49cdfc7eSAndroid Build Coastguard Worker ATTR(STATX_ATTR_NODUMP)
74*49cdfc7eSAndroid Build Coastguard Worker };
75*49cdfc7eSAndroid Build Coastguard Worker
76*49cdfc7eSAndroid Build Coastguard Worker static uint64_t expected_mask;
77*49cdfc7eSAndroid Build Coastguard Worker
setup(void)78*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
79*49cdfc7eSAndroid Build Coastguard Worker {
80*49cdfc7eSAndroid Build Coastguard Worker size_t i;
81*49cdfc7eSAndroid Build Coastguard Worker int fd;
82*49cdfc7eSAndroid Build Coastguard Worker
83*49cdfc7eSAndroid Build Coastguard Worker SAFE_MKDIR(TESTDIR, 0777);
84*49cdfc7eSAndroid Build Coastguard Worker
85*49cdfc7eSAndroid Build Coastguard Worker /* Check general inode attribute support */
86*49cdfc7eSAndroid Build Coastguard Worker fd = SAFE_OPEN(TESTDIR, O_RDONLY | O_DIRECTORY);
87*49cdfc7eSAndroid Build Coastguard Worker TEST(ioctl(fd, FS_IOC_GETFLAGS, &i));
88*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(fd);
89*49cdfc7eSAndroid Build Coastguard Worker
90*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1 && TST_ERR == ENOTTY)
91*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TCONF | TTERRNO, "Inode attributes not supported");
92*49cdfc7eSAndroid Build Coastguard Worker
93*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET)
94*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TBROK | TTERRNO, "Unexpected ioctl() error");
95*49cdfc7eSAndroid Build Coastguard Worker
96*49cdfc7eSAndroid Build Coastguard Worker for (i = 0, expected_mask = 0; i < ARRAY_SIZE(attr_list); i++)
97*49cdfc7eSAndroid Build Coastguard Worker expected_mask |= attr_list[i].attr;
98*49cdfc7eSAndroid Build Coastguard Worker
99*49cdfc7eSAndroid Build Coastguard Worker /* STATX_ATTR_COMPRESSED not supported on Bcachefs, TMPFS, XFS */
100*49cdfc7eSAndroid Build Coastguard Worker if (!strcmp(tst_device->fs_type, "bcachefs") || !strcmp(tst_device->fs_type, "tmpfs") ||
101*49cdfc7eSAndroid Build Coastguard Worker !strcmp(tst_device->fs_type, "xfs"))
102*49cdfc7eSAndroid Build Coastguard Worker expected_mask &= ~STATX_ATTR_COMPRESSED;
103*49cdfc7eSAndroid Build Coastguard Worker
104*49cdfc7eSAndroid Build Coastguard Worker /* Attribute support was added to Btrfs statx() in kernel v4.13 */
105*49cdfc7eSAndroid Build Coastguard Worker if (!strcmp(tst_device->fs_type, "btrfs") && tst_kvercmp(4, 13, 0) < 0)
106*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TCONF, "statx() attributes not supported on Btrfs");
107*49cdfc7eSAndroid Build Coastguard Worker }
108*49cdfc7eSAndroid Build Coastguard Worker
run(void)109*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
110*49cdfc7eSAndroid Build Coastguard Worker {
111*49cdfc7eSAndroid Build Coastguard Worker size_t i;
112*49cdfc7eSAndroid Build Coastguard Worker struct statx buf;
113*49cdfc7eSAndroid Build Coastguard Worker
114*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTDIR, 0, 0, &buf));
115*49cdfc7eSAndroid Build Coastguard Worker
116*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < ARRAY_SIZE(attr_list); i++) {
117*49cdfc7eSAndroid Build Coastguard Worker if (!(expected_mask & attr_list[i].attr))
118*49cdfc7eSAndroid Build Coastguard Worker continue;
119*49cdfc7eSAndroid Build Coastguard Worker
120*49cdfc7eSAndroid Build Coastguard Worker if (buf.stx_attributes_mask & attr_list[i].attr)
121*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "%s is supported", attr_list[i].name);
122*49cdfc7eSAndroid Build Coastguard Worker else
123*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL, "%s not supported", attr_list[i].name);
124*49cdfc7eSAndroid Build Coastguard Worker }
125*49cdfc7eSAndroid Build Coastguard Worker }
126*49cdfc7eSAndroid Build Coastguard Worker
127*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
128*49cdfc7eSAndroid Build Coastguard Worker .test_all = run,
129*49cdfc7eSAndroid Build Coastguard Worker .setup = setup,
130*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
131*49cdfc7eSAndroid Build Coastguard Worker .all_filesystems = 1,
132*49cdfc7eSAndroid Build Coastguard Worker .mount_device = 1,
133*49cdfc7eSAndroid Build Coastguard Worker .mntpoint = MOUNT_POINT,
134*49cdfc7eSAndroid Build Coastguard Worker .min_kver = "4.11",
135*49cdfc7eSAndroid Build Coastguard Worker .skip_filesystems = (const char *const[]) {
136*49cdfc7eSAndroid Build Coastguard Worker "fuse",
137*49cdfc7eSAndroid Build Coastguard Worker "ntfs",
138*49cdfc7eSAndroid Build Coastguard Worker NULL
139*49cdfc7eSAndroid Build Coastguard Worker },
140*49cdfc7eSAndroid Build Coastguard Worker .tags = (const struct tst_tag[]) {
141*49cdfc7eSAndroid Build Coastguard Worker {"linux-git", "93bc420ed41d"},
142*49cdfc7eSAndroid Build Coastguard Worker {"linux-git", "99652ea56a41"},
143*49cdfc7eSAndroid Build Coastguard Worker {"linux-git", "04a87e347282"},
144*49cdfc7eSAndroid Build Coastguard Worker {"linux-git", "5f955f26f3d4"},
145*49cdfc7eSAndroid Build Coastguard Worker {"linux-git", "e408e695f5f1"},
146*49cdfc7eSAndroid Build Coastguard Worker {}
147*49cdfc7eSAndroid Build Coastguard Worker },
148*49cdfc7eSAndroid Build Coastguard Worker };
149