summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-22 16:09:22 (GMT)
committerGitHub <noreply@github.com>2024-01-22 16:09:22 (GMT)
commit1b719b39b9cd125258739699ac5168d139901b48 (patch)
tree49d9ca413c508dae3ef158fe5284a93f94043cc2
parent6d30cbee013b4182937ffa11a7c87d2a7b6b7b41 (diff)
downloadcpython-1b719b39b9cd125258739699ac5168d139901b48.zip
cpython-1b719b39b9cd125258739699ac5168d139901b48.tar.gz
cpython-1b719b39b9cd125258739699ac5168d139901b48.tar.bz2
gh-114321: Expose more constants in the fcntl module (GH-114322)
-rw-r--r--Doc/library/fcntl.rst41
-rw-r--r--Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst2
-rw-r--r--Modules/fcntlmodule.c53
3 files changed, 86 insertions, 10 deletions
diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst
index 309ad65..13ad2dd 100644
--- a/Doc/library/fcntl.rst
+++ b/Doc/library/fcntl.rst
@@ -31,26 +31,26 @@ descriptor.
raise an :exc:`OSError`.
.. versionchanged:: 3.8
- The fcntl module now contains ``F_ADD_SEALS``, ``F_GET_SEALS``, and
+ The :mod:`!fcntl` module now contains ``F_ADD_SEALS``, ``F_GET_SEALS``, and
``F_SEAL_*`` constants for sealing of :func:`os.memfd_create` file
descriptors.
.. versionchanged:: 3.9
- On macOS, the fcntl module exposes the ``F_GETPATH`` constant, which obtains
- the path of a file from a file descriptor.
- On Linux(>=3.15), the fcntl module exposes the ``F_OFD_GETLK``, ``F_OFD_SETLK``
- and ``F_OFD_SETLKW`` constants, which are used when working with open file
- description locks.
+ On macOS, the :mod:`!fcntl` module exposes the ``F_GETPATH`` constant,
+ which obtains the path of a file from a file descriptor.
+ On Linux(>=3.15), the :mod:`!fcntl` module exposes the ``F_OFD_GETLK``,
+ ``F_OFD_SETLK`` and ``F_OFD_SETLKW`` constants, which are used when working
+ with open file description locks.
.. versionchanged:: 3.10
- On Linux >= 2.6.11, the fcntl module exposes the ``F_GETPIPE_SZ`` and
+ On Linux >= 2.6.11, the :mod:`!fcntl` module exposes the ``F_GETPIPE_SZ`` and
``F_SETPIPE_SZ`` constants, which allow to check and modify a pipe's size
respectively.
.. versionchanged:: 3.11
- On FreeBSD, the fcntl module exposes the ``F_DUP2FD`` and ``F_DUP2FD_CLOEXEC``
- constants, which allow to duplicate a file descriptor, the latter setting
- ``FD_CLOEXEC`` flag in addition.
+ On FreeBSD, the :mod:`!fcntl` module exposes the ``F_DUP2FD`` and
+ ``F_DUP2FD_CLOEXEC`` constants, which allow to duplicate a file descriptor,
+ the latter setting ``FD_CLOEXEC`` flag in addition.
.. versionchanged:: 3.12
On Linux >= 4.5, the :mod:`fcntl` module exposes the ``FICLONE`` and
@@ -58,6 +58,27 @@ descriptor.
another file by reflinking on some filesystems (e.g., btrfs, OCFS2, and
XFS). This behavior is commonly referred to as "copy-on-write".
+.. versionchanged:: 3.13
+ On Linux >= 2.6.32, the :mod:`!fcntl` module exposes the
+ ``F_GETOWN_EX``, ``F_SETOWN_EX``, ``F_OWNER_TID``, ``F_OWNER_PID``, ``F_OWNER_PGRP`` constants, which allow to direct I/O availability signals
+ to a specific thread, process, or process group.
+ On Linux >= 4.13, the :mod:`!fcntl` module exposes the
+ ``F_GET_RW_HINT``, ``F_SET_RW_HINT``, ``F_GET_FILE_RW_HINT``,
+ ``F_SET_FILE_RW_HINT``, and ``RWH_WRITE_LIFE_*`` constants, which allow
+ to inform the kernel about the relative expected lifetime of writes on
+ a given inode or via a particular open file description.
+ On Linux >= 5.1 and NetBSD, the :mod:`!fcntl` module exposes the
+ ``F_SEAL_FUTURE_WRITE`` constant for use with ``F_ADD_SEALS`` and
+ ``F_GET_SEALS`` operations.
+ On FreeBSD, the :mod:`!fcntl` module exposes the ``F_READAHEAD``, ``F_ISUNIONSTACK``, and ``F_KINFO`` constants.
+ On macOS and FreeBSD, the :mod:`!fcntl` module exposes the ``F_RDAHEAD``
+ constant.
+ On NetBSD and AIX, the :mod:`!fcntl` module exposes the ``F_CLOSEM``
+ constant.
+ On NetBSD, the :mod:`!fcntl` module exposes the ``F_MAXFD`` constant.
+ On macOS and NetBSD, the :mod:`!fcntl` module exposes the ``F_GETNOSIGPIPE``
+ and ``F_SETNOSIGPIPE`` constant.
+
The module defines the following functions:
diff --git a/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst b/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst
new file mode 100644
index 0000000..dc2934b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-19-18-41-02.gh-issue-114321.yj_Xw3.rst
@@ -0,0 +1,2 @@
+Expose more platform specific constants in the :mod:`fcntl` module on Linux,
+macOS, FreeBSD and NetBSD.
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index fd03abf..0d16602 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -583,6 +583,30 @@ all_ins(PyObject* m)
#ifdef FICLONERANGE
if (PyModule_AddIntMacro(m, FICLONERANGE)) return -1;
#endif
+#ifdef F_GETOWN_EX
+ // since Linux 2.6.32
+ if (PyModule_AddIntMacro(m, F_GETOWN_EX)) return -1;
+ if (PyModule_AddIntMacro(m, F_SETOWN_EX)) return -1;
+ if (PyModule_AddIntMacro(m, F_OWNER_TID)) return -1;
+ if (PyModule_AddIntMacro(m, F_OWNER_PID)) return -1;
+ if (PyModule_AddIntMacro(m, F_OWNER_PGRP)) return -1;
+#endif
+#ifdef F_GET_RW_HINT
+ // since Linux 4.13
+ if (PyModule_AddIntMacro(m, F_GET_RW_HINT)) return -1;
+ if (PyModule_AddIntMacro(m, F_SET_RW_HINT)) return -1;
+ if (PyModule_AddIntMacro(m, F_GET_FILE_RW_HINT)) return -1;
+ if (PyModule_AddIntMacro(m, F_SET_FILE_RW_HINT)) return -1;
+#ifndef RWH_WRITE_LIFE_NOT_SET // typo in Linux < 5.5
+# define RWH_WRITE_LIFE_NOT_SET RWF_WRITE_LIFE_NOT_SET
+#endif
+ if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_NOT_SET)) return -1;
+ if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_NONE)) return -1;
+ if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_SHORT)) return -1;
+ if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_MEDIUM)) return -1;
+ if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_LONG)) return -1;
+ if (PyModule_AddIntMacro(m, RWH_WRITE_LIFE_EXTREME)) return -1;
+#endif
/* OS X specifics */
#ifdef F_FULLFSYNC
@@ -599,6 +623,32 @@ all_ins(PyObject* m)
#ifdef F_DUP2FD_CLOEXEC
if (PyModule_AddIntMacro(m, F_DUP2FD_CLOEXEC)) return -1;
#endif
+#ifdef F_READAHEAD
+ if (PyModule_AddIntMacro(m, F_READAHEAD)) return -1;
+#endif
+#ifdef F_RDAHEAD
+ if (PyModule_AddIntMacro(m, F_RDAHEAD)) return -1;
+#endif
+#ifdef F_ISUNIONSTACK
+ if (PyModule_AddIntMacro(m, F_ISUNIONSTACK)) return -1;
+#endif
+#ifdef F_KINFO
+ if (PyModule_AddIntMacro(m, F_KINFO)) return -1;
+#endif
+
+/* NetBSD specifics */
+#ifdef F_CLOSEM
+ if (PyModule_AddIntMacro(m, F_CLOSEM)) return -1;
+#endif
+#ifdef F_MAXFD
+ if (PyModule_AddIntMacro(m, F_MAXFD)) return -1;
+#endif
+#ifdef F_GETNOSIGPIPE
+ if (PyModule_AddIntMacro(m, F_GETNOSIGPIPE)) return -1;
+#endif
+#ifdef F_SETNOSIGPIPE
+ if (PyModule_AddIntMacro(m, F_SETNOSIGPIPE)) return -1;
+#endif
/* For F_{GET|SET}FL */
#ifdef FD_CLOEXEC
@@ -673,6 +723,9 @@ all_ins(PyObject* m)
if (PyModule_AddIntMacro(m, F_SEAL_SHRINK)) return -1;
if (PyModule_AddIntMacro(m, F_SEAL_GROW)) return -1;
if (PyModule_AddIntMacro(m, F_SEAL_WRITE)) return -1;
+#ifdef F_SEAL_FUTURE_WRITE
+ if (PyModule_AddIntMacro(m, F_SEAL_FUTURE_WRITE)) return -1;
+#endif
#endif
return 0;
}