Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,9 @@ features:

.. versionchanged:: 3.12
``st_birthtime`` is now available on Windows.
.. versionchanged:: next
``st_birthtime`` is now available on Linux kernel 4.11 and later when
supported by the filesystem.

.. attribute:: st_birthtime_ns

Expand Down Expand Up @@ -3276,6 +3279,34 @@ features:

User defined flags for file.

.. attribute:: st_attributes

Linux file attributes.
See the :const:`!STATX_ATTR* <stat.STATX_ATTR_COMPRESSED>`
constants in the :mod:`stat` module.

.. versionadded:: next

.. attribute:: st_attributes_mask

Linux file attributes supported by the filesystem containing the file.

.. versionadded:: next

.. attribute:: st_mnt_id

Mount ID of the mount containing the file, corresponding to the first
field in ``/proc/self/mountinfo``.

.. versionadded:: next

.. attribute:: st_subvol

ID for the subvolume containing the file, or None if the filesystem does
not support subvolumes.

.. versionadded:: next

On other Unix systems (such as FreeBSD), the following attributes may be
available (but may be only filled out if root tries to use them):

Expand Down Expand Up @@ -3367,6 +3398,11 @@ features:

Added the :attr:`st_birthtime` member on Windows.

.. versionchanged:: next
Added the :attr:`st_birthtime`, :attr:`st_attributes`,
:attr:`st_attributes_mask`, :attr:`st_mnt_id`, and :attr:`st_subvol`
members on Linux.


.. function:: statvfs(path)

Expand Down
19 changes: 19 additions & 0 deletions Doc/library/stat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,22 @@ constants, but are not an exhaustive list.
IO_REPARSE_TAG_APPEXECLINK

.. versionadded:: 3.8

On Linux, the following constants are available for comparing against the
``st_attributes`` and ``st_attributes_mask`` members returned by
:func:`os.stat`. See the `statx(2) man page
<https://man.archlinux.org/man/statx.2#File_attributes>` for more detail on the
meaning of these constants.

.. data:: STATX_ATTR_COMPRESSED
STATX_ATTR_IMMUTABLE
STATX_ATTR_APPEND
STATX_ATTR_NODUMP
STATX_ATTR_ENCRYPTED
STATX_ATTR_AUTOMOUNT
STATX_ATTR_MOUNT_ROOT
STATX_ATTR_VERITY
STATX_ATTR_DAX
STATX_ATTR_WRITE_ATOMIC

.. versionadded:: next
2 changes: 2 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(loop)
STRUCT_FOR_ID(manual_reset)
STRUCT_FOR_ID(mapping)
STRUCT_FOR_ID(mask)
STRUCT_FOR_ID(match)
STRUCT_FOR_ID(max_length)
STRUCT_FOR_ID(maxdigits)
Expand Down Expand Up @@ -747,6 +748,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(sub_key)
STRUCT_FOR_ID(subcalls)
STRUCT_FOR_ID(symmetric_difference_update)
STRUCT_FOR_ID(sync)
STRUCT_FOR_ID(tabsize)
STRUCT_FOR_ID(tag)
STRUCT_FOR_ID(target)
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def _add(str, fn):
_add("HAVE_UNLINKAT", "unlink")
_add("HAVE_UNLINKAT", "rmdir")
_add("HAVE_UTIMENSAT", "utime")
if _exists("statx"):
_set.add(statx)
supports_dir_fd = _set

_set = set()
Expand All @@ -152,6 +154,8 @@ def _add(str, fn):
_add("HAVE_FPATHCONF", "pathconf")
if _exists("statvfs") and _exists("fstatvfs"): # mac os x10.3
_add("HAVE_FSTATVFS", "statvfs")
if _exists("statx"):
_set.add(statx)
supports_fd = _set

_set = set()
Expand Down Expand Up @@ -190,6 +194,8 @@ def _add(str, fn):
_add("HAVE_FSTATAT", "stat")
_add("HAVE_UTIMENSAT", "utime")
_add("MS_WINDOWS", "stat")
if _exists("statx"):
_set.add(statx)
supports_follow_symlinks = _set

del _set
Expand Down
15 changes: 15 additions & 0 deletions Lib/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ def filemode(mode):
FILE_ATTRIBUTE_VIRTUAL = 65536


# Linux STATX_ATTR constants for interpreting os.statx()'s
# "stx_attributes" and "stx_attributes_mask" members

STATX_ATTR_COMPRESSED = 0x00000004
STATX_ATTR_IMMUTABLE = 0x00000010
STATX_ATTR_APPEND = 0x00000020
STATX_ATTR_NODUMP = 0x00000040
STATX_ATTR_ENCRYPTED = 0x00000800
STATX_ATTR_AUTOMOUNT = 0x00001000
STATX_ATTR_MOUNT_ROOT = 0x00002000
STATX_ATTR_VERITY = 0x00100000
STATX_ATTR_DAX = 0x00200000
STATX_ATTR_WRITE_ATOMIC = 0x00400000


# If available, use C implementation
try:
from _stat import *
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Médéric Boquien
Matias Bordese
Jonas Borgström
Jurjen Bos
Jeffrey Bosboom
Peter Bosch
Dan Boswell
Eric Bouck
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Provide :func:`os.statx` and populate :attr:`~os.stat_result.st_birthtime`
in the return value of :func:`os.stat` on Linux kernel 4.11 and later using
the statx system call. Contributed by Jeffrey Bosboom and Erin of Yukis.
143 changes: 142 additions & 1 deletion Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading