-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-83714: Use statx on Linux 4.11 and later in os.stat #136334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
99c9efd
cebd5b7
ffd7a89
d53650a
4e4e917
bc3155b
b0e8276
1a8a6d6
f71315e
1f1e959
7440397
534e33f
7dc75d0
894efb5
d5bc601
5b36cf0
6be85a3
c32ee72
c84f783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3224,6 +3224,9 @@ | |
|
||
.. versionchanged:: 3.12 | ||
``st_birthtime`` is now available on Windows. | ||
.. versionchanged:: next | ||
``st_birthtime`` is now present on Linux. The value will be ``0.0`` | ||
on kernel versions < 4.11 or if not supported by the filesystem. | ||
|
||
.. attribute:: st_birthtime_ns | ||
|
||
|
@@ -3232,6 +3235,9 @@ | |
:exc:`AttributeError`. | ||
|
||
.. versionadded:: 3.12 | ||
.. versionchanged:: next | ||
``st_birthtime_ns`` is now present on Linux. The value will be ``0`` | ||
on kernel versions < 4.11 or if not supported by the filesystem. | ||
|
||
.. note:: | ||
|
||
|
@@ -3364,6 +3370,139 @@ | |
|
||
Added the :attr:`st_birthtime` member on Windows. | ||
|
||
.. versionchanged:: next | ||
Added the :attr:`st_birthtime` and :attr:`st_birthtime_ns` members on | ||
Linux. | ||
|
||
|
||
.. function:: statx(path, mask, *, dir_fd=None, follow_symlinks=True, sync=None) | ||
|
||
Get the status of a file or file descriptor by performing a :c:func:`statx` | ||
system call on the given path. *path* may be specified as either a string or | ||
bytes -- directly or indirectly through the :class:`PathLike` interface -- | ||
or as an open file descriptor. *mask* is a combination of the module-level | ||
:const:`STATX_* <STATX_TYPE>` constants specifying the information to | ||
retrieve. Returns a :class:`statx_result` object whose | ||
:attr:`~os.statx_result.stx_mask` attribute specifies the information | ||
actually retrieved (which may differ from *mask*). | ||
|
||
The optional parameter *sync* controls the freshness of the returned | ||
information. ``sync=True`` requests that the kernel return up-to-date | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should document the value of |
||
information, even when doing so is expensive (for example, requiring a | ||
round-trip to the server for a file on a network filesystem). | ||
``sync=False`` requests that the kernel return cached information if | ||
available. | ||
|
||
This function supports :ref:`specifying a file descriptor <path_fd>`, | ||
:ref:`paths relative to directory descriptors <dir_fd>`, and | ||
:ref:`not following symlinks <follow_symlinks>`. | ||
|
||
.. seealso:: The :manpage:`statx(2)` man page. | ||
|
||
.. availability:: Linux >= 4.11 with glibc >= 2.28. | ||
|
||
.. versionadded:: next | ||
|
||
|
||
.. class:: statx_result | ||
|
||
Object whose attributes correspond roughly to the members of the | ||
:c:struct:`statx` structure. It is used for the result of :func:`os.statx`. | ||
:class:`!statx_result` has all of the attributes of :class:`stat_result` | ||
available on Linux, but is not a subclass of :class:`stat_result` nor a | ||
tuple. :class:`!statx_result` has the following additional attributes: | ||
|
||
.. attribute:: stx_mask | ||
|
||
Bitmask of :const:`STATX_* <STATX_TYPE>` constants specifying the | ||
information retrieved, which may differ from what was requested depending | ||
on the filesystem, filesystem type, and kernel version. All attributes | ||
of this class are accessible regardless of the value of | ||
:attr:`!stx_mask`, and they may have useful fictitious values. For | ||
example, for a file on a network filesystem, :const:`STATX_UID` and | ||
:const:`STATX_GID` may be unset because file ownership on the server is | ||
based on an external user database, but :attr:`!st_uid` and | ||
:attr:`!st_gid` may contain the IDs of the local user who controls the | ||
mount. | ||
|
||
.. attribute:: stx_attributes_mask | ||
|
||
Bitmask of :const:`!STATX_ATTR_* <stat.STATX_ATTR_COMPRESSED>` constants | ||
specifying the attributes bits supported for this file. | ||
|
||
.. attribute:: stx_attributes | ||
|
||
Bitmask of :const:`!STATX_ATTR_* <stat.STATX_ATTR_COMPRESSED>` constants | ||
specifying the attributes of this file. | ||
|
||
.. attribute:: stx_mnt_id | ||
|
||
Mount ID. | ||
|
||
.. attribute:: stx_dio_mem_align | ||
|
||
Direct I/O memory buffer alignment requirement. | ||
|
||
.. attribute:: stx_dio_offset_align | ||
|
||
Direct I/O file offset alignment requirement. | ||
|
||
.. attribute:: stx_subvol | ||
|
||
Subvolume ID. | ||
|
||
.. attribute:: stx_atomic_write_unit_min | ||
|
||
Minimum size for direct I/O with torn-write protection. | ||
|
||
.. attribute:: stx_atomic_write_unit_max | ||
|
||
Maximum size for direct I/O with torn-write protection. | ||
|
||
.. attribute:: stx_atomic_write_segments_max | ||
|
||
Maximum iovecs for direct I/O with torn-write protection. | ||
|
||
.. attribute:: stx_dio_read_offset_align | ||
|
||
Direct I/O file offset alignment requirement for reads. | ||
|
||
.. attribute:: stx_atomic_write_unit_max_opt | ||
|
||
Maximum optimized size for direct I/O with torn-write protection. | ||
|
||
.. seealso:: The :manpage:`statx(2)` man page. | ||
|
||
.. availability:: Linux >= 4.11 with glibc >= 2.28. | ||
|
||
.. versionadded:: next | ||
|
||
.. data:: STATX_TYPE | ||
STATX_MODE | ||
STATX_NLINK | ||
STATX_UID | ||
STATX_GID | ||
STATX_ATIME | ||
STATX_MTIME | ||
STATX_CTIME | ||
STATX_INO | ||
STATX_SIZE | ||
STATX_BLOCKS | ||
STATX_BASIC_STATS | ||
STATX_BTIME | ||
STATX_MNT_ID | ||
STATX_DIOALIGN | ||
STATX_MNT_ID_UNIQUE | ||
STATX_SUBVOL | ||
STATX_WRITE_ATOMIC | ||
STATX_DIO_READ_ALIGN | ||
|
||
Bitflags for use as the *mask* parameter to :func:`os.statx`. | ||
|
||
.. availability:: Linux >= 4.11 with glibc >= 2.28. | ||
|
||
.. versionadded:: next | ||
|
||
|
||
.. function:: statvfs(path) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be able to make the missing c func / struct pieces stop erroring by adding to:
cpython/Doc/conf.py
Line 121 in 4e00e25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running
make html
andmake check
as directed by the devguide, I don't see any warnings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting all the warnings out of the docs build is difficult (there are many warnings in non-changed code which don't matter for PRs; but new ones do); the CI does check for new warnings and attaches them to PRs. I can see some here on the Github UI: