]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: add generated statx_mask_one_to_name()/statx_attribute_to_name()
authorMike Yuan <me@yhndnzj.com>
Wed, 4 Feb 2026 22:30:42 +0000 (23:30 +0100)
committerMike Yuan <me@yhndnzj.com>
Thu, 5 Feb 2026 13:14:39 +0000 (14:14 +0100)
src/basic/generate-statx-attribute-list.sh [new file with mode: 0755]
src/basic/generate-statx-mask-list.sh [new file with mode: 0755]
src/basic/meson.build
src/basic/statx-attribute-to-name.awk [new file with mode: 0644]
src/basic/statx-mask-to-name.awk [new file with mode: 0644]
src/include/meson.build

diff --git a/src/basic/generate-statx-attribute-list.sh b/src/basic/generate-statx-attribute-list.sh
new file mode 100755 (executable)
index 0000000..9e0ba45
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eu
+set -o pipefail
+
+CC=${1:?}
+shift
+
+$CC -E -dM -include linux/stat.h "$@" - </dev/null | \
+       awk '/^#define[ \t]+STATX_ATTR_[A-Z][A-Z_]*[ \t]+/ { print $2; }'
diff --git a/src/basic/generate-statx-mask-list.sh b/src/basic/generate-statx-mask-list.sh
new file mode 100755 (executable)
index 0000000..835f0c5
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eu
+set -o pipefail
+
+CC=${1:?}
+shift
+
+$CC -E -dM -include linux/stat.h "$@" - </dev/null | \
+       grep -Ev '^#define[[:space:]]+(STATX_BASIC_STATS|STATX_ALL|STATX_ATTR_)' | \
+       awk '/^#define[ \t]+STATX_[A-Z][A-Z_]*[ \t]+/ { print $2; }'
index d05d9581f2fefd08b14908cb3cb8777a324588bc..dc9259c710004e6073ae8409894fe676ce23e580 100644 (file)
@@ -125,10 +125,12 @@ sources += basic_sources
 generated_gperf_headers = []
 foreach item : [
         # name,        source,             prefix,    headers
-        ['af',         af_sources,         '',        ['<sys/socket.h>'],       ],
-        ['arphrd',     arphrd_sources,     'ARPHRD_', ['<linux/if_arp.h>'],     ],
-        ['capability', capability_sources, '',        ['<linux/capability.h>'], ],
-        ['errno',      [],                 '',        ['<errno.h>'],            ],
+        ['af',              af_sources,         '',        ['<sys/socket.h>'],       ],
+        ['arphrd',          arphrd_sources,     'ARPHRD_', ['<linux/if_arp.h>'],     ],
+        ['capability',      capability_sources, '',        ['<linux/capability.h>'], ],
+        ['errno',           [],                 '',        ['<errno.h>'],            ],
+        ['statx-mask',      statx_sources                                            ],
+        ['statx-attribute', statx_sources                                            ],
 ]
 
         generate_list = files('generate-@0@-list.sh'.format(item[0]))
@@ -138,31 +140,35 @@ foreach item : [
                 command : [env, 'bash', generate_list, cpp, system_include_args],
                 capture : true)
 
-        gperf_file = custom_target(
-                input : list_txt,
-                output : '@0@-from-name.gperf'.format(item[0]),
-                command : [generate_gperfs, item[0], item[2], '@INPUT@'] + item[3],
-                capture : true)
-
-        target1 = custom_target(
-                input : gperf_file,
-                output : '@0@-from-name.inc'.format(item[0]),
-                command : [gperf,
-                           '-L', 'ANSI-C', '-t', '--ignore-case',
-                           '-N', 'lookup_@0@'.format(item[0]),
-                           '-H', 'hash_@0@_name'.format(item[0]),
-                           '-p', '-C',
-                           '@INPUT@'],
-                capture : true)
-
         awkscript = '@0@-to-name.awk'.format(item[0])
-        target2 = custom_target(
+        target = custom_target(
                 input : [awkscript, list_txt],
                 output : '@0@-to-name.inc'.format(item[0]),
                 command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
                 capture : true)
 
-        generated_gperf_headers += [target1, target2]
+        generated_gperf_headers += [target]
+
+        if item.length() > 2
+                gperf_file = custom_target(
+                        input : list_txt,
+                        output : '@0@-from-name.gperf'.format(item[0]),
+                        command : [generate_gperfs, item[0], item[2], '@INPUT@'] + item[3],
+                        capture : true)
+
+                target = custom_target(
+                        input : gperf_file,
+                        output : '@0@-from-name.inc'.format(item[0]),
+                        command : [gperf,
+                                '-L', 'ANSI-C', '-t', '--ignore-case',
+                                '-N', 'lookup_@0@'.format(item[0]),
+                                '-H', 'hash_@0@_name'.format(item[0]),
+                                '-p', '-C',
+                                '@INPUT@'],
+                        capture : true)
+
+                generated_gperf_headers += [target]
+        endif
 endforeach
 
 generated_sources += generated_gperf_headers
diff --git a/src/basic/statx-attribute-to-name.awk b/src/basic/statx-attribute-to-name.awk
new file mode 100644 (file)
index 0000000..807b57d
--- /dev/null
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+BEGIN{
+        print "const char* statx_attribute_to_name(uint64_t attr) {"
+        print "        switch (attr) {"
+}
+{
+        printf "        case %s: return \"%s\";\n", $1, $1
+}
+END{
+        print "        default: return NULL;"
+        print "        }"
+        print "}"
+}
diff --git a/src/basic/statx-mask-to-name.awk b/src/basic/statx-mask-to-name.awk
new file mode 100644 (file)
index 0000000..77ebb76
--- /dev/null
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+BEGIN{
+        print "const char* statx_mask_one_to_name(unsigned mask) {"
+        print "        switch (mask) {"
+}
+{
+        printf "        case %s: return \"%s\";\n", $1, $1
+}
+END{
+        print "        default: return NULL;"
+        print "        }"
+        print "}"
+}
index 90c8e0fdf8a6dafc67122e708d17bda64e4386f4..9cf7e4dbc8895792a5e9d02f17549e0256938464 100644 (file)
@@ -43,3 +43,8 @@ keyboard_sources = files(
         'uapi/linux/input.h',
         'uapi/linux/input-event-codes.h',
 )
+
+# Source files that provides STATX_*
+statx_sources = files(
+        'uapi/linux/stat.h',
+)