diff options
author | Khem Raj <raj.khem@gmail.com> | 2012-06-26 22:36:24 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-06-29 13:31:00 +0100 |
commit | 56bcc2ff59a61e7a084863f6c66e4d357c75321d (patch) | |
tree | e39749e469ccafc6a026e15f8ad3b947f42f9af3 | |
parent | 55e369dd90c3e9b17eee465edfaac350fba55295 (diff) | |
download | poky-56bcc2ff59a61e7a084863f6c66e4d357c75321d.tar.gz |
uclibc-0.9.33: add posix_fallocate implementation
This gets systemd building with uclibc
(From OE-Core rev: d577fa59d8643954249fed7a79232e609add36f8)
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-core/uclibc/uclibc-0.9.33.inc | 1 | ||||
-rw-r--r-- | meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch | 408 |
2 files changed, 409 insertions, 0 deletions
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33.inc b/meta/recipes-core/uclibc/uclibc-0.9.33.inc index 8d03e21859..f03dd2ec6c 100644 --- a/meta/recipes-core/uclibc/uclibc-0.9.33.inc +++ b/meta/recipes-core/uclibc/uclibc-0.9.33.inc | |||
@@ -16,6 +16,7 @@ SRC_URI = "git://uclibc.org/uClibc.git;branch=${PV};protocol=git \ | |||
16 | file://orign_path.patch \ | 16 | file://orign_path.patch \ |
17 | file://dup3.patch \ | 17 | file://dup3.patch \ |
18 | file://define-MSG_CMSG_CLOEXEC.patch \ | 18 | file://define-MSG_CMSG_CLOEXEC.patch \ |
19 | file://posix_fallocate.patch \ | ||
19 | " | 20 | " |
20 | 21 | ||
21 | S = "${WORKDIR}/git" | 22 | S = "${WORKDIR}/git" |
diff --git a/meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch b/meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch new file mode 100644 index 0000000000..6dfd16fd96 --- /dev/null +++ b/meta/recipes-core/uclibc/uclibc-0.9.33/posix_fallocate.patch | |||
@@ -0,0 +1,408 @@ | |||
1 | Delivered-To: raj.khem@gmail.com | ||
2 | Received: by 10.152.129.134 with SMTP id nw6csp47712lab; | ||
3 | Tue, 17 Apr 2012 00:30:48 -0700 (PDT) | ||
4 | Received: by 10.68.216.167 with SMTP id or7mr34112133pbc.140.1334647840512; | ||
5 | Tue, 17 Apr 2012 00:30:40 -0700 (PDT) | ||
6 | Return-Path: <uclibc-bounces@uclibc.org> | ||
7 | Received: from hemlock.osuosl.org (hemlock.osuosl.org. [140.211.166.133]) | ||
8 | by mx.google.com with ESMTP id gr10si13305623pbc.339.2012.04.17.00.30.39; | ||
9 | Tue, 17 Apr 2012 00:30:40 -0700 (PDT) | ||
10 | Received-SPF: neutral (google.com: 140.211.166.133 is neither permitted nor denied by best guess record for domain of uclibc-bounces@uclibc.org) client-ip=140.211.166.133; | ||
11 | Authentication-Results: mx.google.com; spf=neutral (google.com: 140.211.166.133 is neither permitted nor denied by best guess record for domain of uclibc-bounces@uclibc.org) smtp.mail=uclibc-bounces@uclibc.org; dkim=neutral (body hash did not verify) header.i=@gmail.com | ||
12 | Received: from localhost (localhost [127.0.0.1]) | ||
13 | by hemlock.osuosl.org (Postfix) with ESMTP id 7C494A0277; | ||
14 | Tue, 17 Apr 2012 07:30:39 +0000 (UTC) | ||
15 | X-Virus-Scanned: amavisd-new at osuosl.org | ||
16 | Received: from hemlock.osuosl.org ([127.0.0.1]) | ||
17 | by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) | ||
18 | with ESMTP id ZsSp5xE48GwC; Tue, 17 Apr 2012 07:30:34 +0000 (UTC) | ||
19 | Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) | ||
20 | by hemlock.osuosl.org (Postfix) with ESMTP id 1C4F5A0274; | ||
21 | Tue, 17 Apr 2012 07:30:33 +0000 (UTC) | ||
22 | X-Original-To: uclibc@lists.busybox.net | ||
23 | Delivered-To: uclibc@osuosl.org | ||
24 | Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) | ||
25 | by ash.osuosl.org (Postfix) with ESMTP id 17FDE8F75B | ||
26 | for <uclibc@lists.busybox.net>; Tue, 17 Apr 2012 07:30:32 +0000 (UTC) | ||
27 | Received: from localhost (localhost [127.0.0.1]) | ||
28 | by fraxinus.osuosl.org (Postfix) with ESMTP id 07B491016A1 | ||
29 | for <uclibc@lists.busybox.net>; Tue, 17 Apr 2012 07:30:32 +0000 (UTC) | ||
30 | X-Virus-Scanned: amavisd-new at osuosl.org | ||
31 | Received: from fraxinus.osuosl.org ([127.0.0.1]) | ||
32 | by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) | ||
33 | with ESMTP id XKP7jhcUijp4 for <uclibc@lists.busybox.net>; | ||
34 | Tue, 17 Apr 2012 07:30:27 +0000 (UTC) | ||
35 | X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 | ||
36 | Received: from mail-we0-f174.google.com (mail-we0-f174.google.com | ||
37 | [74.125.82.174]) | ||
38 | by fraxinus.osuosl.org (Postfix) with ESMTPS id 2CC0B100190 | ||
39 | for <uclibc@uclibc.org>; Tue, 17 Apr 2012 07:30:26 +0000 (UTC) | ||
40 | Received: by wejx9 with SMTP id x9so5218587wej.33 | ||
41 | for <uclibc@uclibc.org>; Tue, 17 Apr 2012 00:30:25 -0700 (PDT) | ||
42 | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; | ||
43 | h=from:to:cc:subject:date:message-id:x-mailer; | ||
44 | bh=vadTQ1GL81XLDadHLtwCrcdL0YvVNNbIuISfTaQphgg=; | ||
45 | b=KkyW95PC1TUTmwGt+iBJ8p0FfGtTPAsTlXmul/1iH2p21itEpWkU+WcVd2jBH+jc6L | ||
46 | gzf4d6K1pmmfscdbPY3OkpFfvO/v/E4KYN7JmeI+fX1NY+gLBSHhExAVhM1Opue9z09V | ||
47 | 54MrEMtlIA9Wo/5QPd1+W7o9gXHYEnMkoqYYZLmfPlG3+pCXZ6RP36fOZnSV44BQgOFz | ||
48 | KBqn7XLo6nxgP5X/+JuEe4stvCrI9/66nX30u/Sh77a9poj5pp8hQZmtIpbbm3xRKGnM | ||
49 | Fi72jNCq/0nHh3M7eMqn+rvwi1JQjk/90zWNv8v5ShAKqSJVrfqLVN72KjTJtXfLOqbL | ||
50 | e2qA== | ||
51 | Received: by 10.216.133.72 with SMTP id p50mr8903959wei.78.1334647825412; | ||
52 | Tue, 17 Apr 2012 00:30:25 -0700 (PDT) | ||
53 | Received: from s42.loc (85-127-86-115.dynamic.xdsl-line.inode.at. | ||
54 | [85.127.86.115]) | ||
55 | by mx.google.com with ESMTPS id n20sm40466274wiw.5.2012.04.17.00.30.23 | ||
56 | (version=TLSv1/SSLv3 cipher=OTHER); | ||
57 | Tue, 17 Apr 2012 00:30:24 -0700 (PDT) | ||
58 | Received: from cow by s42.loc with local (Exim 4.77) | ||
59 | (envelope-from <rep.dot.nop@gmail.com>) | ||
60 | id 1SK2rm-0008Pl-V3; Tue, 17 Apr 2012 09:30:23 +0200 | ||
61 | From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | ||
62 | To: uclibc@uclibc.org | ||
63 | Subject: [PATCH,CFT] libc: add posix_fallocate() | ||
64 | Date: Tue, 17 Apr 2012 09:30:15 +0200 | ||
65 | Message-Id: <1334647815-32315-1-git-send-email-rep.dot.nop@gmail.com> | ||
66 | X-Mailer: git-send-email 1.7.9.1 | ||
67 | X-BeenThere: uclibc@uclibc.org | ||
68 | X-Mailman-Version: 2.1.14 | ||
69 | Precedence: list | ||
70 | List-Id: "Discussion and development of uClibc \(the embedded C library\)" | ||
71 | <uclibc.uclibc.org> | ||
72 | List-Unsubscribe: <http://lists.busybox.net/mailman/options/uclibc>, | ||
73 | <mailto:uclibc-request@uclibc.org?subject=unsubscribe> | ||
74 | List-Archive: <http://lists.busybox.net/pipermail/uclibc> | ||
75 | List-Post: <mailto:uclibc@uclibc.org> | ||
76 | List-Help: <mailto:uclibc-request@uclibc.org?subject=help> | ||
77 | List-Subscribe: <http://lists.busybox.net/mailman/listinfo/uclibc>, | ||
78 | <mailto:uclibc-request@uclibc.org?subject=subscribe> | ||
79 | MIME-Version: 1.0 | ||
80 | Content-Type: text/plain; charset="us-ascii" | ||
81 | Content-Transfer-Encoding: 7bit | ||
82 | Errors-To: uclibc-bounces@uclibc.org | ||
83 | Sender: uclibc-bounces@uclibc.org | ||
84 | |||
85 | Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | ||
86 | Upstream-Status: Pending | ||
87 | --- | ||
88 | include/fcntl.h | 4 +- | ||
89 | libc/sysdeps/linux/common/Makefile.in | 3 +- | ||
90 | libc/sysdeps/linux/common/bits/kernel-features.h | 8 ++ | ||
91 | libc/sysdeps/linux/common/posix_fallocate.c | 43 ++++++++ | ||
92 | libc/sysdeps/linux/common/posix_fallocate64.c | 39 +++++++ | ||
93 | libc/sysdeps/linux/common/stubs.c | 4 + | ||
94 | test/.gitignore | 1 + | ||
95 | test/unistd/Makefile.in | 3 + | ||
96 | test/unistd/tst-posix_fallocate.c | 121 ++++++++++++++++++++++ | ||
97 | 9 files changed, 222 insertions(+), 4 deletions(-) | ||
98 | create mode 100644 libc/sysdeps/linux/common/posix_fallocate.c | ||
99 | create mode 100644 libc/sysdeps/linux/common/posix_fallocate64.c | ||
100 | create mode 100644 test/unistd/tst-posix_fallocate.c | ||
101 | |||
102 | Index: git/include/fcntl.h | ||
103 | =================================================================== | ||
104 | --- git.orig/include/fcntl.h 2012-06-26 14:51:04.000000000 -0700 | ||
105 | +++ git/include/fcntl.h 2012-06-26 14:51:36.361767240 -0700 | ||
106 | @@ -210,9 +210,7 @@ | ||
107 | |||
108 | #endif | ||
109 | |||
110 | -#if 0 /* && defined __UCLIBC_HAS_ADVANCED_REALTIME__ */ | ||
111 | - | ||
112 | -/* FIXME -- uClibc should probably implement these... */ | ||
113 | +#if defined __UCLIBC_HAS_ADVANCED_REALTIME__ | ||
114 | |||
115 | /* Reserve storage for the data of the file associated with FD. | ||
116 | |||
117 | Index: git/libc/sysdeps/linux/common/Makefile.in | ||
118 | =================================================================== | ||
119 | --- git.orig/libc/sysdeps/linux/common/Makefile.in 2012-06-26 14:51:04.000000000 -0700 | ||
120 | +++ git/libc/sysdeps/linux/common/Makefile.in 2012-06-26 14:52:33.153769997 -0700 | ||
121 | @@ -81,7 +81,8 @@ | ||
122 | sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \ | ||
123 | sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c | ||
124 | # 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 | ||
125 | -CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c | ||
126 | +CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c \ | ||
127 | + posix_fallocate.c posix_fallocate64.c | ||
128 | CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c | ||
129 | CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c | ||
130 | CSRC-$(UCLIBC_HAS_XATTR) += xattr.c | ||
131 | Index: git/libc/sysdeps/linux/common/bits/kernel-features.h | ||
132 | =================================================================== | ||
133 | --- git.orig/libc/sysdeps/linux/common/bits/kernel-features.h 2012-06-26 14:51:04.000000000 -0700 | ||
134 | +++ git/libc/sysdeps/linux/common/bits/kernel-features.h 2012-06-26 14:51:36.361767240 -0700 | ||
135 | @@ -494,6 +494,14 @@ | ||
136 | # define __ASSUME_PRIVATE_FUTEX 1 | ||
137 | #endif | ||
138 | |||
139 | +/* Support for fallocate was added in 2.6.23, | ||
140 | + on s390 only after 2.6.23-rc1, on alpha only after 2.6.33-rc1. */ | ||
141 | +#if __LINUX_KERNEL_VERSION >= 0x020617 \ | ||
142 | + && (!defined __s390__ || __LINUX_KERNEL_VERSION >= 0x020618) \ | ||
143 | + && (!defined __alpha__ || __LINUX_KERNEL_VERSION >= 0x020621) | ||
144 | +# define __ASSUME_FALLOCATE 1 | ||
145 | +#endif | ||
146 | + | ||
147 | /* getcpu is a syscall for x86-64 since 3.1. */ | ||
148 | #if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100 | ||
149 | # define __ASSUME_GETCPU_SYSCALL 1 | ||
150 | Index: git/libc/sysdeps/linux/common/posix_fallocate.c | ||
151 | =================================================================== | ||
152 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
153 | +++ git/libc/sysdeps/linux/common/posix_fallocate.c 2012-06-26 14:51:36.373767243 -0700 | ||
154 | @@ -0,0 +1,43 @@ | ||
155 | +/* vi: set sw=4 ts=4: */ | ||
156 | +/* | ||
157 | + * posix_fallocate() for uClibc | ||
158 | + * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html | ||
159 | + * | ||
160 | + * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> | ||
161 | + * | ||
162 | + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. | ||
163 | + */ | ||
164 | + | ||
165 | +#include <sys/syscall.h> | ||
166 | +#include <fcntl.h> | ||
167 | +#include <bits/kernel-features.h> | ||
168 | +#include <stdint.h> | ||
169 | + | ||
170 | +#if defined __NR_fallocate | ||
171 | +int posix_fallocate(int fd, __off_t offset, __off_t len) | ||
172 | +{ | ||
173 | + int ret; | ||
174 | + | ||
175 | +# if __WORDSIZE == 32 | ||
176 | + uint32_t off_low = offset; | ||
177 | + uint32_t len_low = len; | ||
178 | + /* may assert that these >>31 are 0 */ | ||
179 | + uint32_t zero = 0; | ||
180 | + INTERNAL_SYSCALL_DECL(err); | ||
181 | + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0, | ||
182 | + __LONG_LONG_PAIR (zero, off_low), | ||
183 | + __LONG_LONG_PAIR (zero, len_low))); | ||
184 | +# elif __WORDSIZE == 64 | ||
185 | + INTERNAL_SYSCALL_DECL(err); | ||
186 | + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, 0, offset, len)); | ||
187 | +# else | ||
188 | +# error your machine is neither 32 bit or 64 bit ... it must be magical | ||
189 | +#endif | ||
190 | + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) | ||
191 | + return INTERNAL_SYSCALL_ERRNO (ret, err); | ||
192 | + return 0; | ||
193 | +} | ||
194 | +# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 | ||
195 | +strong_alias(posix_fallocate,posix_fallocate64) | ||
196 | +# endif | ||
197 | +#endif | ||
198 | Index: git/libc/sysdeps/linux/common/posix_fallocate64.c | ||
199 | =================================================================== | ||
200 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
201 | +++ git/libc/sysdeps/linux/common/posix_fallocate64.c 2012-06-26 14:51:36.373767243 -0700 | ||
202 | @@ -0,0 +1,39 @@ | ||
203 | +/* vi: set sw=4 ts=4: */ | ||
204 | +/* | ||
205 | + * posix_fallocate() for uClibc | ||
206 | + * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html | ||
207 | + * | ||
208 | + * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> | ||
209 | + * | ||
210 | + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. | ||
211 | + */ | ||
212 | + | ||
213 | +#include <sys/syscall.h> | ||
214 | +#include <fcntl.h> | ||
215 | +#include <bits/kernel-features.h> | ||
216 | +#include <stdint.h> | ||
217 | + | ||
218 | +#if defined __NR_fallocate | ||
219 | + | ||
220 | +# if __WORDSIZE == 64 | ||
221 | +/* Can use normal posix_fallocate() */ | ||
222 | +# elif __WORDSIZE == 32 | ||
223 | +int posix_fallocate64(int fd, __off64_t offset, __off64_t len) | ||
224 | +{ | ||
225 | + int ret; | ||
226 | + uint32_t off_low = offset & 0xffffffff; | ||
227 | + uint32_t off_high = offset >> 32; | ||
228 | + uint32_t len_low = len & 0xffffffff; | ||
229 | + uint32_t len_high = len >> 32; | ||
230 | + INTERNAL_SYSCALL_DECL(err); | ||
231 | + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0, | ||
232 | + __LONG_LONG_PAIR (off_high, off_low), | ||
233 | + __LONG_LONG_PAIR (len_high, len_low))); | ||
234 | + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) | ||
235 | + return INTERNAL_SYSCALL_ERRNO (ret, err); | ||
236 | + return 0; | ||
237 | +} | ||
238 | +# else | ||
239 | +# error your machine is neither 32 bit or 64 bit ... it must be magical | ||
240 | +# endif | ||
241 | +#endif | ||
242 | Index: git/libc/sysdeps/linux/common/stubs.c | ||
243 | =================================================================== | ||
244 | --- git.orig/libc/sysdeps/linux/common/stubs.c 2012-06-26 14:51:04.000000000 -0700 | ||
245 | +++ git/libc/sysdeps/linux/common/stubs.c 2012-06-26 14:53:48.997773660 -0700 | ||
246 | @@ -209,6 +209,10 @@ | ||
247 | make_stub(madvise) | ||
248 | #endif | ||
249 | |||
250 | +#if !defined __NR_fallocate && defined __UCLIBC_HAS_ADVANCED_REALTIME__ | ||
251 | +make_ret_stub(posix_fallocate) | ||
252 | +#endif | ||
253 | + | ||
254 | #if !defined __NR_modify_ldt && defined __UCLIBC_LINUX_SPECIFIC__ | ||
255 | make_stub(modify_ldt) | ||
256 | #endif | ||
257 | Index: git/test/.gitignore | ||
258 | =================================================================== | ||
259 | --- git.orig/test/.gitignore 2012-06-26 14:51:04.000000000 -0700 | ||
260 | +++ git/test/.gitignore 2012-06-26 14:51:36.373767243 -0700 | ||
261 | @@ -302,6 +302,7 @@ | ||
262 | unistd/getopt | ||
263 | unistd/getopt_long | ||
264 | unistd/tstgetopt | ||
265 | +unistd/tst-posix_fallocate | ||
266 | unistd/tst-preadwrite | ||
267 | unistd/tst-preadwrite64 | ||
268 | unistd/vfork | ||
269 | Index: git/test/unistd/Makefile.in | ||
270 | =================================================================== | ||
271 | --- git.orig/test/unistd/Makefile.in 2012-06-26 14:51:05.000000000 -0700 | ||
272 | +++ git/test/unistd/Makefile.in 2012-06-26 14:51:36.373767243 -0700 | ||
273 | @@ -4,6 +4,9 @@ | ||
274 | ifeq ($(UCLIBC_HAS_LFS),) | ||
275 | TESTS_DISABLED := tst-preadwrite64 | ||
276 | endif | ||
277 | +ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),) | ||
278 | +TESTS_DISABLED := tst-posix_fallocate | ||
279 | +endif | ||
280 | OPTS_getopt := -abcXXX -9 | ||
281 | OPTS_getopt_long := --add XXX --delete YYY --verbose | ||
282 | ifeq ($(UCLIBC_HAS_GNU_GETOPT),y) | ||
283 | Index: git/test/unistd/tst-posix_fallocate.c | ||
284 | =================================================================== | ||
285 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | ||
286 | +++ git/test/unistd/tst-posix_fallocate.c 2012-06-26 14:51:36.373767243 -0700 | ||
287 | @@ -0,0 +1,121 @@ | ||
288 | +#include <fcntl.h> | ||
289 | +#include <sys/stat.h> | ||
290 | + | ||
291 | +static void do_prepare (void); | ||
292 | +#define PREPARE(argc, argv) do_prepare () | ||
293 | +static int do_test (void); | ||
294 | +#define TEST_FUNCTION do_test () | ||
295 | +#include <test-skeleton.c> | ||
296 | + | ||
297 | +static int fd; | ||
298 | +#ifndef O_LARGEFILE | ||
299 | +# error no O_LARGEFILE | ||
300 | +#endif | ||
301 | +static void | ||
302 | +do_prepare (void) | ||
303 | +{ | ||
304 | + fd = create_temp_file ("tst-posix_fallocate.", NULL); | ||
305 | + if (fd == -1) | ||
306 | + { | ||
307 | + printf ("cannot create temporary file: %m\n"); | ||
308 | + exit (1); | ||
309 | + } | ||
310 | +} | ||
311 | + | ||
312 | + | ||
313 | +static int | ||
314 | +do_test (void) | ||
315 | +{ | ||
316 | + struct stat64 st; | ||
317 | + | ||
318 | + if (fstat64 (fd, &st) != 0) | ||
319 | + { | ||
320 | + puts ("1st fstat failed"); | ||
321 | + return 1; | ||
322 | + } | ||
323 | + | ||
324 | + if (st.st_size != 0) | ||
325 | + { | ||
326 | + puts ("file not created with size 0"); | ||
327 | + return 1; | ||
328 | + } | ||
329 | + | ||
330 | + if (posix_fallocate (fd, 512, 768) != 0) | ||
331 | + { | ||
332 | + puts ("1st posix_fallocate call failed"); | ||
333 | + return 1; | ||
334 | + } | ||
335 | + | ||
336 | + if (fstat64 (fd, &st) != 0) | ||
337 | + { | ||
338 | + puts ("2nd fstat failed"); | ||
339 | + return 1; | ||
340 | + } | ||
341 | + | ||
342 | + if (st.st_size != 512 + 768) | ||
343 | + { | ||
344 | + printf ("file size after 1st posix_fallocate call is %llu, expected %u\n", | ||
345 | + (unsigned long long int) st.st_size, 512u + 768u); | ||
346 | + return 1; | ||
347 | + } | ||
348 | + | ||
349 | + if (posix_fallocate (fd, 0, 1024) != 0) | ||
350 | + { | ||
351 | + puts ("2nd posix_fallocate call failed"); | ||
352 | + return 1; | ||
353 | + } | ||
354 | + | ||
355 | + if (fstat64 (fd, &st) != 0) | ||
356 | + { | ||
357 | + puts ("3rd fstat failed"); | ||
358 | + return 1; | ||
359 | + } | ||
360 | + | ||
361 | + if (st.st_size != 512 + 768) | ||
362 | + { | ||
363 | + puts ("file size changed in 2nd posix_fallocate"); | ||
364 | + return 1; | ||
365 | + } | ||
366 | + | ||
367 | + if (posix_fallocate (fd, 2048, 64) != 0) | ||
368 | + { | ||
369 | + puts ("3rd posix_fallocate call failed"); | ||
370 | + return 1; | ||
371 | + } | ||
372 | + | ||
373 | + if (fstat64 (fd, &st) != 0) | ||
374 | + { | ||
375 | + puts ("4th fstat failed"); | ||
376 | + return 1; | ||
377 | + } | ||
378 | + | ||
379 | + if (st.st_size != 2048 + 64) | ||
380 | + { | ||
381 | + printf ("file size after 3rd posix_fallocate call is %llu, expected %u\n", | ||
382 | + (unsigned long long int) st.st_size, 2048u + 64u); | ||
383 | + return 1; | ||
384 | + } | ||
385 | + | ||
386 | + if (posix_fallocate64 (fd, 4097ULL, 4294967295ULL + 2ULL) != 0) | ||
387 | + { | ||
388 | + puts ("4th posix_fallocate call failed"); | ||
389 | + return 1; | ||
390 | + } | ||
391 | + | ||
392 | + if (fstat64 (fd, &st) != 0) | ||
393 | + { | ||
394 | + puts ("5th fstat failed"); | ||
395 | + return 1; | ||
396 | + } | ||
397 | + | ||
398 | + if (st.st_size != 4097ULL + 4294967295ULL + 2ULL) | ||
399 | + { | ||
400 | + printf ("file size after 4th posix_fallocate call is %llu, expected %u\n", | ||
401 | + (unsigned long long int) st.st_size, 4097ULL + 4294967295ULL + 2ULL); | ||
402 | + return 1; | ||
403 | + } | ||
404 | + | ||
405 | + close (fd); | ||
406 | + | ||
407 | + return 0; | ||
408 | +} | ||