Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/uclibc/0.9.33.2: 06_all_posix_fallocate.patch
Date: Sun, 19 May 2013 05:20:34
Message-Id: 20130519052027.F31F12171D@flycatcher.gentoo.org
1 vapier 13/05/19 05:20:27
2
3 Added: 06_all_posix_fallocate.patch
4 Log:
5 add posix_fallocate() from upstream #458920 by Mark Reiche
6
7 Revision Changes Path
8 1.1 src/patchsets/uclibc/0.9.33.2/06_all_posix_fallocate.patch
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/uclibc/0.9.33.2/06_all_posix_fallocate.patch?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/uclibc/0.9.33.2/06_all_posix_fallocate.patch?rev=1.1&content-type=text/plain
12
13 Index: 06_all_posix_fallocate.patch
14 ===================================================================
15 From 5643900913f64c00f1c2958914586708efa5a473 Mon Sep 17 00:00:00 2001
16 From: Bernhard Reutner-Fischer <rep.dot.nop@×××××.com>
17 Date: Tue, 17 Apr 2012 09:30:15 +0200
18 Subject: [PATCH] libc: add posix_fallocate()
19
20 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@×××××.com>
21 ---
22 include/fcntl.h | 4 +-
23 libc/sysdeps/linux/common/Makefile.in | 3 +-
24 libc/sysdeps/linux/common/bits/kernel-features.h | 8 ++
25 libc/sysdeps/linux/common/posix_fallocate.c | 43 ++++++++
26 libc/sysdeps/linux/common/posix_fallocate64.c | 39 +++++++
27 test/.gitignore | 2 +
28 test/unistd/Makefile.in | 5 +-
29 test/unistd/tst-posix_fallocate.c | 127 +++++++++++++++++++++++
30 test/unistd/tst-posix_fallocate64.c | 2 +
31 9 files changed, 228 insertions(+), 5 deletions(-)
32 create mode 100644 libc/sysdeps/linux/common/posix_fallocate.c
33 create mode 100644 libc/sysdeps/linux/common/posix_fallocate64.c
34 create mode 100644 test/unistd/tst-posix_fallocate.c
35 create mode 100644 test/unistd/tst-posix_fallocate64.c
36
37 diff --git a/include/fcntl.h b/include/fcntl.h
38 index ed009dd..c749ad5 100644
39 --- a/include/fcntl.h
40 +++ b/include/fcntl.h
41 @@ -217,9 +217,7 @@ extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len,
42
43 #endif
44
45 -#if 0 /* && defined __UCLIBC_HAS_ADVANCED_REALTIME__ */
46 -
47 -/* FIXME -- uClibc should probably implement these... */
48 +#if defined __UCLIBC_HAS_ADVANCED_REALTIME__
49
50 /* Reserve storage for the data of the file associated with FD.
51
52 diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
53 index 566722d..29566dd 100644
54 --- a/libc/sysdeps/linux/common/Makefile.in
55 +++ b/libc/sysdeps/linux/common/Makefile.in
56 @@ -82,7 +82,8 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_getres.c clock_gettime.c clock_settime.c \
57 sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \
58 sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c
59 # clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp|posix_typed_mem_g
60 et_info|pthread_mutex_timedlock|sem_timedwait
61 -CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c
62 +CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c \
63 + posix_fallocate.c posix_fallocate64.c
64 CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c
65 CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c
66 CSRC-$(UCLIBC_HAS_XATTR) += xattr.c
67 diff --git a/libc/sysdeps/linux/common/bits/kernel-features.h b/libc/sysdeps/linux/common/bits/kernel-features.h
68 index 4d1e0cb..6184c2b 100644
69 --- a/libc/sysdeps/linux/common/bits/kernel-features.h
70 +++ b/libc/sysdeps/linux/common/bits/kernel-features.h
71 @@ -495,6 +495,14 @@
72 # define __ASSUME_PRIVATE_FUTEX 1
73 #endif
74
75 +/* Support for fallocate was added in 2.6.23,
76 + on s390 only after 2.6.23-rc1, on alpha only after 2.6.33-rc1. */
77 +#if __LINUX_KERNEL_VERSION >= 0x020617 \
78 + && (!defined __s390__ || __LINUX_KERNEL_VERSION >= 0x020618) \
79 + && (!defined __alpha__ || __LINUX_KERNEL_VERSION >= 0x020621)
80 +# define __ASSUME_FALLOCATE 1
81 +#endif
82 +
83 /* getcpu is a syscall for x86-64 since 3.1. */
84 #if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100
85 # define __ASSUME_GETCPU_SYSCALL 1
86 diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c
87 new file mode 100644
88 index 0000000..9aaa6ce
89 --- /dev/null
90 +++ b/libc/sysdeps/linux/common/posix_fallocate.c
91 @@ -0,0 +1,43 @@
92 +/* vi: set sw=4 ts=4: */
93 +/*
94 + * posix_fallocate() for uClibc
95 + * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
96 + *
97 + * Copyright (C) 2000-2006 Erik Andersen <andersen@××××××.org>
98 + *
99 + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
100 + */
101 +
102 +#include <sys/syscall.h>
103 +#include <fcntl.h>
104 +#include <bits/kernel-features.h>
105 +#include <stdint.h>
106 +
107 +#if defined __NR_fallocate
108 +int posix_fallocate(int fd, __off_t offset, __off_t len)
109 +{
110 + int ret;
111 +
112 +# if __WORDSIZE == 32
113 + uint32_t off_low = offset;
114 + uint32_t len_low = len;
115 + /* may assert that these >>31 are 0 */
116 + uint32_t zero = 0;
117 + INTERNAL_SYSCALL_DECL(err);
118 + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
119 + __LONG_LONG_PAIR (zero, off_low),
120 + __LONG_LONG_PAIR (zero, len_low)));
121 +# elif __WORDSIZE == 64
122 + INTERNAL_SYSCALL_DECL(err);
123 + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, 0, offset, len));
124 +# else
125 +# error your machine is neither 32 bit or 64 bit ... it must be magical
126 +#endif
127 + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
128 + return INTERNAL_SYSCALL_ERRNO (ret, err);
129 + return 0;
130 +}
131 +# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
132 +strong_alias(posix_fallocate,posix_fallocate64)
133 +# endif
134 +#endif
135 diff --git a/libc/sysdeps/linux/common/posix_fallocate64.c b/libc/sysdeps/linux/common/posix_fallocate64.c
136 new file mode 100644
137 index 0000000..818d868
138 --- /dev/null
139 +++ b/libc/sysdeps/linux/common/posix_fallocate64.c
140 @@ -0,0 +1,39 @@
141 +/* vi: set sw=4 ts=4: */
142 +/*
143 + * posix_fallocate() for uClibc
144 + * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
145 + *
146 + * Copyright (C) 2000-2006 Erik Andersen <andersen@××××××.org>
147 + *
148 + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
149 + */
150 +
151 +#include <sys/syscall.h>
152 +#include <fcntl.h>
153 +#include <bits/kernel-features.h>
154 +#include <stdint.h>
155 +
156 +#if defined __NR_fallocate
157 +
158 +# if __WORDSIZE == 64
159 +/* Can use normal posix_fallocate() */
160 +# elif __WORDSIZE == 32
161 +int posix_fallocate64(int fd, __off64_t offset, __off64_t len)
162 +{
163 + int ret;
164 + uint32_t off_low = offset & 0xffffffff;
165 + uint32_t off_high = offset >> 32;
166 + uint32_t len_low = len & 0xffffffff;
167 + uint32_t len_high = len >> 32;
168 + INTERNAL_SYSCALL_DECL(err);
169 + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
170 + __LONG_LONG_PAIR (off_high, off_low),
171 + __LONG_LONG_PAIR (len_high, len_low)));
172 + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
173 + return INTERNAL_SYSCALL_ERRNO (ret, err);
174 + return 0;
175 +}
176 +# else
177 +# error your machine is neither 32 bit or 64 bit ... it must be magical
178 +# endif
179 +#endif
180 diff --git a/test/.gitignore b/test/.gitignore
181 index c068f89..ec04628 100644
182 --- a/test/.gitignore
183 +++ b/test/.gitignore
184 @@ -319,6 +319,8 @@ unistd/getcwd
185 unistd/getopt
186 unistd/getopt_long
187 unistd/tstgetopt
188 +unistd/tst-posix_fallocate
189 +unistd/tst-posix_fallocate64
190 unistd/tst-preadwrite
191 unistd/tst-preadwrite64
192 unistd/vfork
193 diff --git a/test/unistd/Makefile.in b/test/unistd/Makefile.in
194 index c542f98..24b9a37 100644
195 --- a/test/unistd/Makefile.in
196 +++ b/test/unistd/Makefile.in
197 @@ -2,7 +2,10 @@
198 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
199
200 ifeq ($(UCLIBC_HAS_LFS),)
201 -TESTS_DISABLED := tst-preadwrite64
202 +TESTS_DISABLED := tst-preadwrite64 tst-posix_fallocate64
203 +endif
204 +ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),)
205 +TESTS_DISABLED := tst-posix_fallocate
206 endif
207 OPTS_getopt := -abcXXX -9
208 OPTS_getopt_long := --add XXX --delete YYY --verbose
209 diff --git a/test/unistd/tst-posix_fallocate.c b/test/unistd/tst-posix_fallocate.c
210 new file mode 100644
211 index 0000000..d41c604
212 --- /dev/null
213 +++ b/test/unistd/tst-posix_fallocate.c
214 @@ -0,0 +1,127 @@
215 +#include <fcntl.h>
216 +#include <sys/stat.h>
217 +
218 +#ifndef TST_POSIX_FALLOCATE64
219 +# define stat64 stat
220 +# define fstat64 fstat
221 +# else
222 +# ifndef O_LARGEFILE
223 +# error no O_LARGEFILE but you want to test with LFS enabled
224 +# endif
225 +#endif
226 +
227 +static void do_prepare (void);
228 +#define PREPARE(argc, argv) do_prepare ()
229 +static int do_test (void);
230 +#define TEST_FUNCTION do_test ()
231 +#include <test-skeleton.c>
232 +
233 +static int fd;
234 +static void
235 +do_prepare (void)
236 +{
237 + fd = create_temp_file ("tst-posix_fallocate.", NULL);
238 + if (fd == -1)
239 + {
240 + printf ("cannot create temporary file: %m\n");
241 + exit (1);
242 + }
243 +}
244 +
245 +
246 +static int
247 +do_test (void)
248 +{
249 + struct stat64 st;
250 +
251 + if (fstat64 (fd, &st) != 0)
252 + {
253 + puts ("1st fstat failed");
254 + return 1;
255 + }
256 +
257 + if (st.st_size != 0)
258 + {
259 + puts ("file not created with size 0");
260 + return 1;
261 + }
262 +
263 + if (posix_fallocate (fd, 512, 768) != 0)
264 + {
265 + puts ("1st posix_fallocate call failed");
266 + return 1;
267 + }
268 +
269 + if (fstat64 (fd, &st) != 0)
270 + {
271 + puts ("2nd fstat failed");
272 + return 1;
273 + }
274 +
275 + if (st.st_size != 512 + 768)
276 + {
277 + printf ("file size after 1st posix_fallocate call is %llu, expected %u\n",
278 + (unsigned long long int) st.st_size, 512u + 768u);
279 + return 1;
280 + }
281 +
282 + if (posix_fallocate (fd, 0, 1024) != 0)
283 + {
284 + puts ("2nd posix_fallocate call failed");
285 + return 1;
286 + }
287 +
288 + if (fstat64 (fd, &st) != 0)
289 + {
290 + puts ("3rd fstat failed");
291 + return 1;
292 + }
293 +
294 + if (st.st_size != 512 + 768)
295 + {
296 + puts ("file size changed in 2nd posix_fallocate");
297 + return 1;
298 + }
299 +
300 + if (posix_fallocate (fd, 2048, 64) != 0)
301 + {
302 + puts ("3rd posix_fallocate call failed");
303 + return 1;
304 + }
305 +
306 + if (fstat64 (fd, &st) != 0)
307 + {
308 + puts ("4th fstat failed");
309 + return 1;
310 + }
311 +
312 + if (st.st_size != 2048 + 64)
313 + {
314 + printf ("file size after 3rd posix_fallocate call is %llu, expected %u\n",
315 + (unsigned long long int) st.st_size, 2048u + 64u);
316 + return 1;
317 + }
318 +#ifdef TST_POSIX_FALLOCATE64
319 + if (posix_fallocate64 (fd, 4097ULL, 4294967295ULL + 2ULL) != 0)
320 + {
321 + puts ("4th posix_fallocate call failed");
322 + return 1;
323 + }
324 +
325 + if (fstat64 (fd, &st) != 0)
326 + {
327 + puts ("5th fstat failed");
328 + return 1;
329 + }
330 +
331 + if (st.st_size != 4097ULL + 4294967295ULL + 2ULL)
332 + {
333 + printf ("file size after 4th posix_fallocate call is %llu, expected %llu\n",
334 + (unsigned long long int) st.st_size, 4097ULL + 4294967295ULL + 2ULL);
335 + return 1;
336 + }
337 +#endif
338 + close (fd);
339 +
340 + return 0;
341 +}
342 diff --git a/test/unistd/tst-posix_fallocate64.c b/test/unistd/tst-posix_fallocate64.c
343 new file mode 100644
344 index 0000000..b1ee0ff
345 --- /dev/null
346 +++ b/test/unistd/tst-posix_fallocate64.c
347 @@ -0,0 +1,2 @@
348 +#define TST_POSIX_FALLOCATE64
349 +#include "tst-posix_fallocate.c"
350 --
351 1.8.2.1