[Python-checkins] gh-93475: Expose FICLONE and FICLONERANGE constants in fcntl (#93478)

vstinner webhook-mailer at python.org
Mon Jun 6 17:22:03 EDT 2022


https://github.com/python/cpython/commit/d1e2e0e1b2af10ddecc5a6a0f9f4ab19ee8a0036
commit: d1e2e0e1b2af10ddecc5a6a0f9f4ab19ee8a0036
branch: main
author: Illia Volochii <illia.volochii at gmail.com>
committer: vstinner <vstinner at python.org>
date: 2022-06-06T23:21:58+02:00
summary:

gh-93475: Expose FICLONE and FICLONERANGE constants in fcntl (#93478)

files:
A Misc/NEWS.d/next/Library/2022-06-04-00-11-54.gh-issue-93475.vffFw1.rst
M Doc/library/fcntl.rst
M Modules/fcntlmodule.c
M configure
M configure.ac
M pyconfig.h.in

diff --git a/Doc/library/fcntl.rst b/Doc/library/fcntl.rst
index 1ecd552fbd02c..784e7071c2b35 100644
--- a/Doc/library/fcntl.rst
+++ b/Doc/library/fcntl.rst
@@ -50,6 +50,12 @@ descriptor.
    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
+   ``FICLONERANGE`` constants, which allow to share some data of one file with
+   another file by reflinking on some filesystems (e.g., btrfs, OCFS2, and
+   XFS). This behavior is commonly referred to as "copy-on-write".
+
 The module defines the following functions:
 
 
diff --git a/Misc/NEWS.d/next/Library/2022-06-04-00-11-54.gh-issue-93475.vffFw1.rst b/Misc/NEWS.d/next/Library/2022-06-04-00-11-54.gh-issue-93475.vffFw1.rst
new file mode 100644
index 0000000000000..efe7ff3e9b4fb
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-06-04-00-11-54.gh-issue-93475.vffFw1.rst
@@ -0,0 +1,2 @@
+Expose ``FICLONE`` and ``FICLONERANGE`` constants in :mod:`fcntl`. Patch by
+Illia Volochii.
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index ea9b2bc14a9f2..9a8ec8dc9858d 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -8,6 +8,9 @@
 #ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
 #endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h>
+#endif
 
 #include <sys/ioctl.h>
 #include <fcntl.h>
@@ -572,6 +575,12 @@ all_ins(PyObject* m)
 #ifdef F_GETPIPE_SZ
     if (PyModule_AddIntMacro(m, F_GETPIPE_SZ)) return -1;
 #endif
+#ifdef FICLONE
+    if (PyModule_AddIntMacro(m, FICLONE)) return -1;
+#endif
+#ifdef FICLONERANGE
+    if (PyModule_AddIntMacro(m, FICLONERANGE)) return -1;
+#endif
 
 /* OS X specifics */
 #ifdef F_FULLFSYNC
diff --git a/configure b/configure
index 74972842a41d9..34c43b9dde316 100755
--- a/configure
+++ b/configure
@@ -8847,7 +8847,8 @@ $as_echo "#define STDC_HEADERS 1" >>confdefs.h
 # checks for header files
 for ac_header in  \
   alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
-  ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/memfd.h linux/random.h linux/soundcard.h \
+  ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/memfd.h \
+  linux/random.h linux/soundcard.h \
   linux/tipc.h linux/wait.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
   sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \
   sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \
diff --git a/configure.ac b/configure.ac
index 269f9201d7833..07a178a996c19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2504,7 +2504,8 @@ AC_DEFINE(STDC_HEADERS, 1, [Define to 1 if you have the ANSI C header files.])
 # checks for header files
 AC_CHECK_HEADERS([ \
   alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
-  ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/memfd.h linux/random.h linux/soundcard.h \
+  ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/memfd.h \
+  linux/random.h linux/soundcard.h \
   linux/tipc.h linux/wait.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
   sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \
   sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 1fba0c68aae4b..b32a5802d3182 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -685,6 +685,9 @@
 /* Define if compiling using Linux 4.1 or later. */
 #undef HAVE_LINUX_CAN_RAW_JOIN_FILTERS
 
+/* Define to 1 if you have the <linux/fs.h> header file. */
+#undef HAVE_LINUX_FS_H
+
 /* Define to 1 if you have the <linux/memfd.h> header file. */
 #undef HAVE_LINUX_MEMFD_H
 



More information about the Python-checkins mailing list