2 posix_fallocate_xfs preloadable library to make posix_fallocate
3 use XFS' more efficient preallocation using unwritten extents
5 Copyright © 2010 Bjoern JACKE <bjoern@j3e.de>
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/types.h>
32 static int (*libc_posix_fallocate
)(int, off_t
, off_t
)= NULL
;
34 static void __attribute__ ((constructor
)) posix_fallocate_xfs_init(void)
36 libc_posix_fallocate
= dlsym(RTLD_NEXT
, "posix_fallocate");
37 if (!libc_posix_fallocate
|| dlerror())
41 int posix_fallocate(int fd
, off_t offset
, off_t len
)
44 off_t new_len
= offset
+ len
;
51 fl
.l_whence
= SEEK_SET
;
55 ret
=xfsctl(NULL
, fd
, XFS_IOC_RESVSP
, &fl
);
61 /* Make sure the space shows up when we enlarged the file: */
63 if (new_len
> sbuf
.st_size
) {
64 ftruncate(fd
, new_len
);
69 int posix_fallocate64(int fd
, off64_t offset
, off64_t len
)
72 off64_t new_len
= offset
+ len
;
76 fl
.l_whence
= SEEK_SET
;
80 ret
=xfsctl(NULL
, fd
, XFS_IOC_RESVSP
, &fl
);
85 /* Make sure the space shows up when we enlarged the file: */
87 if (new_len
> sbuf
.st_size
) {
88 ftruncate64(fd
, new_len
);