`fallocate()` flags again available as per documentation
Previously, the `fcntl.h` header file from the _glibc_ package did not include flags for the `fallocate()` function. As a consequence, programs using `fallocate()` according to the man page did not compile. The missing flags have been added by indirect inclusion of the `<linux/falloc.h>` file and compilation of such programs is again possible.
Description of problem:
RHEL7's kernel supports the fallocate() call and its various flags, such as FALLOC_FL_PUNCH_HOLE. Likewise the man page for fallocate(2) lists this option and says <fcntl.h> should give you the necessary definitions.
However, while FALLOC_FL_PUNCH_HOLE (and other fallocate() flags) is included in /usr/include/linux/falloc.h (supplied by the kernel), that file is not included, directly or indirectly by /usr/include/fcntl.h
Version-Release number of selected component (if applicable):
glibc-2.17-196.el7.ppc64le
kernel-3.10.0-693.el7.ppc64le
How reproducible:
100%
Steps to Reproduce:
1. Create fallocate.c:
#define _GNU_SOURCE
#include <fcntl.h>
int test(int fd)
{
return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
0, 1024 * 1024);
}
2. Compile source file above with:
$ gcc -Wall -c fallocate.c
Actual results:
$ gcc -c fallocate.c
fallocate.c: In function ‘test’:
fallocate.c:7:23: error: ‘FALLOC_FL_PUNCH_HOLE’ undeclared (first use in this function)
return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
^
fallocate.c:7:23: note: each undeclared identifier is reported only once for each function it appears in
fallocate.c:7:46: error: ‘FALLOC_FL_KEEP_SIZE’ undeclared (first use in this function)
return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
^
Expected results:
File compiles successfully.
Additional info:
This works correctly in Fedora 26 (and therefore, presumably, in upstream glibc). In Fedora, fcntl.h indirectly includes linux/falloc.h via bits/fcntl-linux.h.
Relevant upstream commit:
commit 257dabc059447934a90be6fce4b5d2a5f4b63dfd
Author: Joseph Myers <joseph>
Date: Wed Dec 14 18:23:15 2016 +0000
Include <linux/falloc.h> in bits/fcntl-linux.h.
This patch makes bits/fcntl-linux.h include <linux/falloc.h> to define
the FALLOC_* flags under __USE_GNU (linux/falloc.h defines only those
bits, nothing else).
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.
https://access.redhat.com/errata/RHSA-2018:3092
Description of problem: RHEL7's kernel supports the fallocate() call and its various flags, such as FALLOC_FL_PUNCH_HOLE. Likewise the man page for fallocate(2) lists this option and says <fcntl.h> should give you the necessary definitions. However, while FALLOC_FL_PUNCH_HOLE (and other fallocate() flags) is included in /usr/include/linux/falloc.h (supplied by the kernel), that file is not included, directly or indirectly by /usr/include/fcntl.h Version-Release number of selected component (if applicable): glibc-2.17-196.el7.ppc64le kernel-3.10.0-693.el7.ppc64le How reproducible: 100% Steps to Reproduce: 1. Create fallocate.c: #define _GNU_SOURCE #include <fcntl.h> int test(int fd) { return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1024 * 1024); } 2. Compile source file above with: $ gcc -Wall -c fallocate.c Actual results: $ gcc -c fallocate.c fallocate.c: In function ‘test’: fallocate.c:7:23: error: ‘FALLOC_FL_PUNCH_HOLE’ undeclared (first use in this function) return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ fallocate.c:7:23: note: each undeclared identifier is reported only once for each function it appears in fallocate.c:7:46: error: ‘FALLOC_FL_KEEP_SIZE’ undeclared (first use in this function) return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ Expected results: File compiles successfully. Additional info: This works correctly in Fedora 26 (and therefore, presumably, in upstream glibc). In Fedora, fcntl.h indirectly includes linux/falloc.h via bits/fcntl-linux.h.