From 6b039272e95682dcbd17974119acdbfd92842e07 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 4 Feb 2026 23:30:42 +0100 Subject: [PATCH] basic: add generated statx_mask_one_to_name()/statx_attribute_to_name() --- src/basic/generate-statx-attribute-list.sh | 10 +++++ src/basic/generate-statx-mask-list.sh | 11 +++++ src/basic/meson.build | 52 ++++++++++++---------- src/basic/statx-attribute-to-name.awk | 14 ++++++ src/basic/statx-mask-to-name.awk | 14 ++++++ src/include/meson.build | 5 +++ 6 files changed, 83 insertions(+), 23 deletions(-) create mode 100755 src/basic/generate-statx-attribute-list.sh create mode 100755 src/basic/generate-statx-mask-list.sh create mode 100644 src/basic/statx-attribute-to-name.awk create mode 100644 src/basic/statx-mask-to-name.awk diff --git a/src/basic/generate-statx-attribute-list.sh b/src/basic/generate-statx-attribute-list.sh new file mode 100755 index 00000000000..9e0ba450459 --- /dev/null +++ b/src/basic/generate-statx-attribute-list.sh @@ -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 "$@" - '], ], - ['arphrd', arphrd_sources, 'ARPHRD_', [''], ], - ['capability', capability_sources, '', [''], ], - ['errno', [], '', [''], ], + ['af', af_sources, '', [''], ], + ['arphrd', arphrd_sources, 'ARPHRD_', [''], ], + ['capability', capability_sources, '', [''], ], + ['errno', [], '', [''], ], + ['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 index 00000000000..807b57df748 --- /dev/null +++ b/src/basic/statx-attribute-to-name.awk @@ -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 index 00000000000..77ebb76faa1 --- /dev/null +++ b/src/basic/statx-mask-to-name.awk @@ -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 "}" +} diff --git a/src/include/meson.build b/src/include/meson.build index 90c8e0fdf8a..9cf7e4dbc88 100644 --- a/src/include/meson.build +++ b/src/include/meson.build @@ -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', +) -- 2.47.3