1 | /* Some basic tests for LFS.
|
---|
2 | Copyright (C) 2000, 2001 Free Software Foundation, Inc.
|
---|
3 | This file is part of the GNU C Library.
|
---|
4 | Contributed by Andreas Jaeger <aj@suse.de>, 2000.
|
---|
5 |
|
---|
6 | The GNU C Library is free software; you can redistribute it and/or
|
---|
7 | modify it under the terms of the GNU Lesser General Public
|
---|
8 | License as published by the Free Software Foundation; either
|
---|
9 | version 2.1 of the License, or (at your option) any later version.
|
---|
10 |
|
---|
11 | The GNU C Library is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | Lesser General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU Lesser General Public
|
---|
17 | License along with the GNU C Library; if not, write to the Free
|
---|
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA. */
|
---|
20 |
|
---|
21 | #include <unistd.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <sys/types.h>
|
---|
24 | #include <sys/stat.h>
|
---|
25 | #include <fcntl.h>
|
---|
26 | #include <error.h>
|
---|
27 | #include <errno.h>
|
---|
28 | #include <sys/resource.h>
|
---|
29 | #ifndef HAVE_64BIT_FILEIO_TYPES
|
---|
30 | #define getrlimit64 getrlimit
|
---|
31 | #define setrlimit64 setrlimit
|
---|
32 | #define mkstemp64 mkstemp
|
---|
33 | #define fopen64 fopen
|
---|
34 | #define fstat64 fstat
|
---|
35 | #define stat64 stat
|
---|
36 | #define fseeko64 fseeko
|
---|
37 | #define ftello64 ftello
|
---|
38 | #define lseek64 lseek
|
---|
39 | #define rlimit64 rlimit
|
---|
40 | #define off64_t off_t
|
---|
41 | #endif
|
---|
42 |
|
---|
43 |
|
---|
44 | /* Prototype for our test function. */
|
---|
45 | extern void do_prepare (int argc, char *argv[]);
|
---|
46 | extern int do_test (int argc, char *argv[]);
|
---|
47 |
|
---|
48 | /* We have a preparation function. */
|
---|
49 | #define PREPARE do_prepare
|
---|
50 |
|
---|
51 | /* We might need a bit longer timeout. */
|
---|
52 | #define TIMEOUT 20 /* sec */
|
---|
53 |
|
---|
54 | /* This defines the `main' function and some more. */
|
---|
55 | #include <test-skeleton.c>
|
---|
56 |
|
---|
57 | /* These are for the temporary file we generate. */
|
---|
58 | char *name;
|
---|
59 | int fd;
|
---|
60 |
|
---|
61 | /* 2^31 = 2GB. */
|
---|
62 | #define TWO_GB 2147483648LL
|
---|
63 |
|
---|
64 | void
|
---|
65 | do_prepare (int argc, char *argv[])
|
---|
66 | {
|
---|
67 | char name_len;
|
---|
68 | struct rlimit64 rlim;
|
---|
69 |
|
---|
70 | name_len = strlen (test_dir);
|
---|
71 | name = malloc (name_len + sizeof ("/lfsXXXXXX"));
|
---|
72 | mempcpy (mempcpy (name, test_dir, name_len),
|
---|
73 | "/lfsXXXXXX", sizeof ("/lfsXXXXXX"));
|
---|
74 | add_temp_file (name);
|
---|
75 |
|
---|
76 | /* Open our test file. */
|
---|
77 | fd = mkstemp64 (name);
|
---|
78 | if (fd == -1)
|
---|
79 | {
|
---|
80 | if (errno == ENOSYS)
|
---|
81 | {
|
---|
82 | /* Fail silently. */
|
---|
83 | error (0, 0, "open64 is not supported");
|
---|
84 | exit (EXIT_SUCCESS);
|
---|
85 | }
|
---|
86 | else
|
---|
87 | error (EXIT_FAILURE, errno, "cannot create temporary file");
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (getrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
|
---|
91 | {
|
---|
92 | error (0, errno, "cannot get resource limit");
|
---|
93 | exit (0);
|
---|
94 | }
|
---|
95 | if (rlim.rlim_cur < TWO_GB + 200)
|
---|
96 | {
|
---|
97 | rlim.rlim_cur = TWO_GB + 200;
|
---|
98 | if (setrlimit64 (RLIMIT_FSIZE, &rlim) != 0)
|
---|
99 | {
|
---|
100 | error (0, errno, "cannot reset file size limits");
|
---|
101 | exit (0);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | static void
|
---|
107 | test_ftello (void)
|
---|
108 | {
|
---|
109 | FILE *f;
|
---|
110 | int ret;
|
---|
111 | off64_t pos;
|
---|
112 |
|
---|
113 | f = fopen64 (name, "w");
|
---|
114 |
|
---|
115 | ret = fseeko64 (f, TWO_GB+100, SEEK_SET);
|
---|
116 | if (ret == -1 && errno == ENOSYS)
|
---|
117 | {
|
---|
118 | error (0, 0, "fseeko64 is not supported.");
|
---|
119 | exit (EXIT_SUCCESS);
|
---|
120 | }
|
---|
121 | if (ret == -1 && errno == EINVAL)
|
---|
122 | {
|
---|
123 | error (0, 0, "LFS seems not to be supported");
|
---|
124 | exit (EXIT_SUCCESS);
|
---|
125 | }
|
---|
126 | if (ret == -1)
|
---|
127 | {
|
---|
128 | error (0, errno, "fseeko64 failed with error");
|
---|
129 | exit (EXIT_FAILURE);
|
---|
130 | }
|
---|
131 |
|
---|
132 | ret = fwrite ("Hello", 1, 5, f);
|
---|
133 | if (ret == -1 && errno == EFBIG)
|
---|
134 | {
|
---|
135 | error (0, errno, "LFS seems not to be supported");
|
---|
136 | exit (EXIT_SUCCESS);
|
---|
137 | }
|
---|
138 |
|
---|
139 | if (ret == -1 && errno == ENOSPC)
|
---|
140 | {
|
---|
141 | error (0, 0, "Not enough space to write file.");
|
---|
142 | exit (EXIT_SUCCESS);
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (ret != 5)
|
---|
146 | error (EXIT_FAILURE, errno, "Cannot write test string to large file");
|
---|
147 |
|
---|
148 | pos = ftello64 (f);
|
---|
149 |
|
---|
150 | if (pos != TWO_GB+105)
|
---|
151 | {
|
---|
152 | error (0, 0, "ftello64 gives wrong result.");
|
---|
153 | exit (EXIT_FAILURE);
|
---|
154 | }
|
---|
155 |
|
---|
156 | fclose (f);
|
---|
157 | }
|
---|
158 |
|
---|
159 | int
|
---|
160 | do_test (int argc, char *argv[])
|
---|
161 | {
|
---|
162 | int ret;
|
---|
163 | struct stat64 statbuf;
|
---|
164 |
|
---|
165 | ret = lseek64 (fd, TWO_GB+100, SEEK_SET);
|
---|
166 | if (ret == -1 && errno == ENOSYS)
|
---|
167 | {
|
---|
168 | error (0, 0, "lseek64 is not supported.");
|
---|
169 | exit (EXIT_SUCCESS);
|
---|
170 | }
|
---|
171 | if (ret == -1 && errno == EINVAL)
|
---|
172 | {
|
---|
173 | error (0, 0, "LFS seems not to be supported.");
|
---|
174 | exit (EXIT_SUCCESS);
|
---|
175 | }
|
---|
176 | if (ret == -1)
|
---|
177 | {
|
---|
178 | error (0, errno, "lseek64 failed with error");
|
---|
179 | exit (EXIT_FAILURE);
|
---|
180 | }
|
---|
181 |
|
---|
182 | ret = write (fd, "Hello", 5);
|
---|
183 | if (ret == -1 && errno == EFBIG)
|
---|
184 | {
|
---|
185 | error (0, 0, "LFS seems not to be supported.");
|
---|
186 | exit (EXIT_SUCCESS);
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (ret == -1 && errno == ENOSPC)
|
---|
190 | {
|
---|
191 | error (0, 0, "Not enough space to write file.");
|
---|
192 | exit (EXIT_SUCCESS);
|
---|
193 | }
|
---|
194 |
|
---|
195 | if (ret != 5)
|
---|
196 | error (EXIT_FAILURE, errno, "cannot write test string to large file");
|
---|
197 |
|
---|
198 | ret = close (fd);
|
---|
199 |
|
---|
200 | if (ret == -1)
|
---|
201 | error (EXIT_FAILURE, errno, "error closing file");
|
---|
202 |
|
---|
203 | ret = stat64 (name, &statbuf);
|
---|
204 |
|
---|
205 | if (ret == -1 && (errno == ENOSYS || errno == EOVERFLOW))
|
---|
206 | error (0, 0, "stat64 is not supported.");
|
---|
207 | else if (ret == -1)
|
---|
208 | error (EXIT_FAILURE, errno, "cannot stat file `%s'", name);
|
---|
209 | else if (statbuf.st_size != (TWO_GB + 100 + 5))
|
---|
210 | error (EXIT_FAILURE, 0, "stat reported size %lld instead of %lld.",
|
---|
211 | (long long int) statbuf.st_size, (TWO_GB + 100 + 5));
|
---|
212 |
|
---|
213 | test_ftello ();
|
---|
214 |
|
---|
215 | return 0;
|
---|
216 | }
|
---|