basic: add generated statx_mask_one_to_name()/statx_attribute_to_name()

This commit is contained in:
Mike Yuan
2026-02-05 14:14:39 +01:00
parent 539e2b75aa
commit 6b039272e9
6 changed files with 83 additions and 23 deletions
+10
View File
@@ -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; }'
+11
View File
@@ -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; }'
+29 -23
View 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
+14
View File
@@ -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 "}"
}
+14
View File
@@ -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 "}"
}
+5
View 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',
)