-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-83714: Implement os.statx #139178
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
base: main
Are you sure you want to change the base?
gh-83714: Implement os.statx #139178
Changes from all commits
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3383,6 +3383,176 @@ features: | |||||||||||||
Added the :attr:`st_birthtime` member on Windows. | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
.. function:: statx(path, mask, flags=0, *, dir_fd=None, follow_symlinks=True) | ||||||||||||||
|
||||||||||||||
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. *flags* is a combination of the module-level | ||||||||||||||
:const:`AT_STATX_* <AT_STATX_FORCE_SYNC>` constants and/or | ||||||||||||||
:const:`AT_NO_AUTOMOUNT`. Returns a :class:`statx_result` object whose | ||||||||||||||
:attr:`~os.statx_result.stx_mask` attribute specifies the information | ||||||||||||||
actually retrieved (which may differ from *mask*). | ||||||||||||||
|
||||||||||||||
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 | ||||||||||||||
|
||||||||||||||
.. data:: AT_STATX_FORCE_SYNC | ||||||||||||||
|
||||||||||||||
A flag for the :func:`os.statx` function. Requests that the kernel return | ||||||||||||||
up-to-date information even when doing so is expensive (for example, | ||||||||||||||
requiring a round trip to the server for a file on a network filesystem). | ||||||||||||||
|
||||||||||||||
.. availability:: Linux >= 4.11 with glibc >= 2.28. | ||||||||||||||
|
||||||||||||||
.. versionadded:: next | ||||||||||||||
|
||||||||||||||
.. data:: AT_STATX_DONT_SYNC | ||||||||||||||
|
||||||||||||||
A flag for the :func:`os.statx` function. Requests that the kernel return | ||||||||||||||
cached information if possible. | ||||||||||||||
|
||||||||||||||
.. availability:: Linux >= 4.11 with glibc >= 2.28. | ||||||||||||||
|
||||||||||||||
.. versionadded:: next | ||||||||||||||
|
||||||||||||||
.. data:: AT_STATX_SYNC_AS_STAT | ||||||||||||||
|
||||||||||||||
A flag for the :func:`os.statx` function. This flag is defined as ``0``, so | ||||||||||||||
it has no effect, but it can be used to explicitly indicate neither | ||||||||||||||
:data:`AT_STATX_FORCE_SYNC` nor :data:`AT_STATX_DONT_SYNC` is being passed. | ||||||||||||||
In the absence of the other two flags, the kernel will generally return | ||||||||||||||
information as fresh as :func:`os.stat` would return. | ||||||||||||||
|
||||||||||||||
.. availability:: Linux >= 4.11 with glibc >= 2.28. | ||||||||||||||
|
||||||||||||||
.. versionadded:: next | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
.. data:: AT_NO_AUTOMOUNT | ||||||||||||||
|
||||||||||||||
If the final component of a path is an automount point, operate on the | ||||||||||||||
automount point instead of performing the automount. (On Linux, | ||||||||||||||
:func:`os.stat`, :func:`os.fstat` and :func:`os.lstat` always behave this | ||||||||||||||
way.) | ||||||||||||||
Comment on lines
+3547
to
+3549
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.
Suggested change
|
||||||||||||||
|
||||||||||||||
.. availability:: Linux. | ||||||||||||||
|
||||||||||||||
.. versionadded:: next | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
.. function:: statvfs(path) | ||||||||||||||
|
||||||||||||||
Perform a :c:func:`!statvfs` system call on the given path. The return value is | ||||||||||||||
|
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.
What do you think of marking mask optional? Add a default value of
0
.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.
So it's possible to just call
os.statx('.')
.