Skip to content

Commit 60df1d7

Browse files
authored
pythongh-83714: Check for struct statx members in configure (python#140402)
Some systems have the definitions of the mask bits without having the corresponding members in struct statx. Add configure checks for members added after Linux 4.11 (when statx itself was added).
1 parent b4d2307 commit 60df1d7

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

Doc/library/os.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,9 +3566,9 @@ features:
35663566
STATX_WRITE_ATOMIC
35673567
STATX_DIO_READ_ALIGN
35683568

3569-
Bitflags for use in the *mask* parameter to :func:`os.statx`. Flags
3570-
including and after :const:`!STATX_MNT_ID` are only available when their
3571-
corresponding members in :class:`statx_result` are available.
3569+
Bitflags for use in the *mask* parameter to :func:`os.statx`. Some of these
3570+
flags may be available even when their corresponding members in
3571+
:class:`statx_result` are not available.
35723572

35733573
.. availability:: Linux >= 4.11 with glibc >= 2.28.
35743574

Modules/posixmodule.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,15 +3364,15 @@ static PyMemberDef pystatx_result_members[] = {
33643364
STATX_GET_UINT(st_uid, stx_uid, STATX_UID)
33653365
STATX_GET_UINT(st_gid, stx_gid, STATX_GID)
33663366
STATX_GET_UINT(st_nlink, stx_nlink, STATX_NLINK)
3367-
#ifdef STATX_DIOALIGN
3367+
#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
33683368
STATX_GET_UINT(stx_dio_mem_align, stx_dio_mem_align, STATX_DIOALIGN)
33693369
STATX_GET_UINT(stx_dio_offset_align, stx_dio_offset_align, STATX_DIOALIGN)
33703370
#endif
3371-
#ifdef STATX_DIO_READ_ALIGN
3371+
#ifdef HAVE_STRUCT_STATX_STX_DIO_READ_OFFSET_ALIGN
33723372
STATX_GET_UINT(stx_dio_read_offset_align, stx_dio_read_offset_align,
33733373
STATX_DIO_READ_ALIGN)
33743374
#endif
3375-
#ifdef STATX_WRITE_ATOMIC
3375+
#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MIN
33763376
STATX_GET_UINT(stx_atomic_write_unit_min, stx_atomic_write_unit_min,
33773377
STATX_WRITE_ATOMIC)
33783378
STATX_GET_UINT(stx_atomic_write_unit_max, stx_atomic_write_unit_max,
@@ -3401,10 +3401,10 @@ STATX_GET_UINT(stx_atomic_write_unit_max_opt, stx_atomic_write_unit_max_opt,
34013401
STATX_GET_ULONGLONG(st_blocks, stx_blocks, STATX_BLOCKS)
34023402
STATX_GET_ULONGLONG(st_ino, stx_ino, STATX_INO)
34033403
STATX_GET_ULONGLONG(st_size, stx_size, STATX_SIZE)
3404-
#ifdef STATX_MNT_ID
3404+
#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
34053405
STATX_GET_ULONGLONG(stx_mnt_id, stx_mnt_id, STATX_MNT_ID)
34063406
#endif
3407-
#ifdef STATX_SUBVOL
3407+
#ifdef HAVE_STRUCT_STATX_STX_SUBVOL
34083408
STATX_GET_ULONGLONG(stx_subvol, stx_subvol, STATX_SUBVOL)
34093409
#endif
34103410

@@ -3463,25 +3463,25 @@ static PyGetSetDef pystatx_result_getset[] = {
34633463
G(st_ctime_ns, "time of last change in nanoseconds"),
34643464
G(st_mtime, "time of last modification"),
34653465
G(st_mtime_ns, "time of last modification in nanoseconds"),
3466-
#ifdef STATX_MNT_ID
3466+
#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
34673467
G(stx_mnt_id, "mount ID"),
34683468
#endif
3469-
#ifdef STATX_DIOALIGN
3469+
#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
34703470
G(stx_dio_mem_align, "direct I/O memory buffer alignment"),
34713471
G(stx_dio_offset_align, "direct I/O file offset alignment"),
34723472
#endif
3473-
#ifdef STATX_SUBVOL
3473+
#ifdef HAVE_STRUCT_STATX_STX_SUBVOL
34743474
G(stx_subvol, "subvolume ID"),
34753475
#endif
3476-
#ifdef STATX_WRITE_ATOMIC
3476+
#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MIN
34773477
G(stx_atomic_write_unit_min,
34783478
"minimum size for direct I/O with torn-write protection"),
34793479
G(stx_atomic_write_unit_max,
34803480
"maximum size for direct I/O with torn-write protection"),
34813481
G(stx_atomic_write_segments_max,
34823482
"maximum iovecs for direct I/O with torn-write protection"),
34833483
#endif
3484-
#ifdef STATX_DIO_READ_ALIGN
3484+
#ifdef HAVE_STRUCT_STATX_STX_DIO_READ_OFFSET_ALIGN
34853485
G(stx_dio_read_offset_align, "direct I/O file offset alignment for reads"),
34863486
#endif
34873487
#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT

configure

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5827,6 +5827,17 @@ AC_CHECK_MEMBERS([struct passwd.pw_gecos, struct passwd.pw_passwd], [], [], [[
58275827
AC_CHECK_MEMBERS([siginfo_t.si_band], [], [], [[@%:@include <signal.h>]])
58285828

58295829
if test "$ac_cv_func_statx" = yes; then
5830+
# Some systems have the definitions of the mask bits without having the
5831+
# corresponding members in struct statx. Check for members added after Linux
5832+
# 4.11 (when statx itself was added).
5833+
AC_CHECK_MEMBERS([struct statx.stx_mnt_id])
5834+
AC_CHECK_MEMBERS([struct statx.stx_dio_mem_align])
5835+
# stx_dio_offset_align was added together with stx_dio_mem_align
5836+
AC_CHECK_MEMBERS([struct statx.stx_subvol])
5837+
AC_CHECK_MEMBERS([struct statx.stx_atomic_write_unit_min])
5838+
# stx_atomic_write_unit_max and stx_atomic_write_segments_max were added
5839+
# together with stx_atomic_write_unit_min
5840+
AC_CHECK_MEMBERS([struct statx.stx_dio_read_offset_align])
58305841
# stx_atomic_write_unit_max_opt was added in Linux 6.16, but is controlled by
58315842
# the STATX_WRITE_ATOMIC mask bit added in Linux 6.11, so having the mask bit
58325843
# doesn't imply having the member.

pyconfig.h.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,23 @@
13341334
statx'. */
13351335
#undef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
13361336

1337+
/* Define to 1 if 'stx_atomic_write_unit_min' is a member of 'struct statx'.
1338+
*/
1339+
#undef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MIN
1340+
1341+
/* Define to 1 if 'stx_dio_mem_align' is a member of 'struct statx'. */
1342+
#undef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
1343+
1344+
/* Define to 1 if 'stx_dio_read_offset_align' is a member of 'struct statx'.
1345+
*/
1346+
#undef HAVE_STRUCT_STATX_STX_DIO_READ_OFFSET_ALIGN
1347+
1348+
/* Define to 1 if 'stx_mnt_id' is a member of 'struct statx'. */
1349+
#undef HAVE_STRUCT_STATX_STX_MNT_ID
1350+
1351+
/* Define to 1 if 'stx_subvol' is a member of 'struct statx'. */
1352+
#undef HAVE_STRUCT_STATX_STX_SUBVOL
1353+
13371354
/* Define to 1 if 'st_birthtime' is a member of 'struct stat'. */
13381355
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
13391356

0 commit comments

Comments
 (0)