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