Skip to content

Conversation

ntninja
Copy link

@ntninja ntninja commented Mar 23, 2020

Still missing tests, but I'd appreciate feedback on the changes themselves in the meantime. Also ideas for properly testing btime would be appreciated.

#83714

@ghost
Copy link

ghost commented Sep 12, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

On BSD/macOS this uses the value of `st_birthtime` (which remains for
compatibity reasons), on Windows it duplicates the value of `st_ctime`.

A Linux implementation is added in subsequent commits.
It cannot be enabled by default because this implementation does not have
any fallback to plain stat for older kernels and Linux 4.11 is still fairly
recent. The configure checks also ensure that the C library expose the
proper stub functions (glibc 2.28+ only).
Use the ``statx(2)`` system call for :func:`os.stat` under Linux to provide
cross-platform support for btime (time of file creation) and file
attributes. On Windows btime is emulated using ctime and both Linux and
Windows file attributes are converted to their (Free)BSD equivalent were

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo - "were" should be "where"

STATX_ATTR_VERITY
STATX_ATTR_DAX

.. versionadded:: 3.12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tip - update version markers in docs to "next" and it'll automagically use the right version.

@cmaloney
Copy link
Contributor

Could this be performance checked against the existing stat? Stat is called a lot (in Python 3.14 on linux once for every file opened which includes imports by default) and my worry is issues like https://lwn.net/Articles/944214/ where the different variants of stat have quite a bit of performance delta.

@gpshead
Copy link
Member

gpshead commented Aug 31, 2025

Another take on this: How about not modifying os.stat behavior at all but instead introduce an os.statx API that uses the more modern system call when available and exposes its functionality - in particular the mask functionality so that people can call it and get only the specific data they want instead of a large everything-bagel os.stat result.

The os module is all about providing wrappers around the underlying platform APIs.
(edit: raised this question on the issue)

@gpshead gpshead changed the title bpo-39533: Use statx on more recent Linux to expose st_flags and st_btime on all platforms gh-83714: Use statx on more recent Linux to expose st_flags and st_btime on all platforms Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants