Commit 3db46c2
committed
support 64-bit file offsets on systems with 32-bit off_t
Adds large file support (64-bit file positions) to the existing Nix
API when targetting systems that have separate 32-bit and 64-bit
APIs.
On many platforms that support 64-bit file positions, this support is
present in the standard I/O functions. On others, there have
historically been two APIs: the standard API, which limits file size to
2**31-1 bytes, and a separate API that suffixes function names with "64"
and supports 64-bit file sizes. This "transitional interface for 64-bit
file offsets" is not present on every platform. As a result, using the
*64 API will make programs non-portable, whereas using the standard API
will result in programs that cannot handle large file offsets on some
systems, even if those systems actually do have a way to handle
large file offsets.
This change enables 64-bit file offsets on the following platforms
where the standard API only provides 32-bit offsets:
- 32-bit Linux with glibc.
- 32-bit Android.
To support large files with a consistent API across platforms, this
change makes Nix functions call the 64-bit capable equivalents where
necessary. Other C libraries may not provide the *64 API, so we continue
to call the standard functions on those.
Broadly, the change consists of 5 parts:
1. Uses of libc::off_t have are replaced by i64. This provides a
consistent API across platforms and allows 64-bit offsets to
be used even when libc::off_t is 32-bit. This is similar to
std::fs, which uses u64 for file positions. Nix uses i64
because off_t is a signed type. Into<i64> is used where appropriate
so that existing code that uses libc::off_t will continue to
work without changes.
2. A largefile_fn macro that is used to select the large-file-capable
version of a function. E.g. largefile_fn![pwrite] is equivalent
to libc::pwrite64 on glibc/Linux and plain libc::pwrite on
systems that don't have or need libc::pwrite64.
3. A new require_largefile macro that is used to skip tests that
require libc::off_t to be larger than 32 bits.
4. Changes to fallocate, ftruncate, lseek, mmap, open, openat,
posix_fadvise, posix_fallocate, pread, preadv, pwrite, pwritev,
sendfile, and truncate, making them support large files.
5. A set of test_*_largefile tests to verify that each of the
previously mentioned functions now works with files whose size
requires more than 32 bits to represent.
A few functions are still limited to 32-bit file sizes after this
change. This includes the aio* functions, the *stat* functions, and
mkstemp(). Adding large file support to those requires a bit more
work than simply calling a different function and is therefore left
for later.1 parent 25b437c commit 3db46c2
File tree
14 files changed
+437
-100
lines changed- src
- sys
- test
- common
- sys
14 files changed
+437
-100
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
167 | 170 | | |
| 171 | + | |
168 | 172 | | |
169 | 173 | | |
170 | 174 | | |
| |||
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
252 | | - | |
| 256 | + | |
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
| |||
280 | 284 | | |
281 | 285 | | |
282 | 286 | | |
283 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
284 | 293 | | |
285 | 294 | | |
286 | 295 | | |
| |||
1303 | 1312 | | |
1304 | 1313 | | |
1305 | 1314 | | |
1306 | | - | |
| 1315 | + | |
1307 | 1316 | | |
1308 | 1317 | | |
1309 | | - | |
1310 | | - | |
| 1318 | + | |
| 1319 | + | |
1311 | 1320 | | |
1312 | 1321 | | |
1313 | 1322 | | |
1314 | | - | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
1315 | 1327 | | |
1316 | 1328 | | |
1317 | 1329 | | |
1318 | 1330 | | |
1319 | 1331 | | |
1320 | 1332 | | |
1321 | 1333 | | |
1322 | | - | |
| 1334 | + | |
1323 | 1335 | | |
1324 | 1336 | | |
1325 | 1337 | | |
| |||
1334 | 1346 | | |
1335 | 1347 | | |
1336 | 1348 | | |
1337 | | - | |
| 1349 | + | |
1338 | 1350 | | |
1339 | 1351 | | |
1340 | 1352 | | |
1341 | 1353 | | |
1342 | 1354 | | |
1343 | | - | |
| 1355 | + | |
1344 | 1356 | | |
1345 | 1357 | | |
1346 | 1358 | | |
| |||
1437 | 1449 | | |
1438 | 1450 | | |
1439 | 1451 | | |
1440 | | - | |
| 1452 | + | |
1441 | 1453 | | |
1442 | | - | |
1443 | | - | |
| 1454 | + | |
| 1455 | + | |
1444 | 1456 | | |
1445 | 1457 | | |
1446 | 1458 | | |
1447 | 1459 | | |
1448 | | - | |
1449 | | - | |
| 1460 | + | |
| 1461 | + | |
1450 | 1462 | | |
1451 | 1463 | | |
1452 | 1464 | | |
| |||
1505 | 1517 | | |
1506 | 1518 | | |
1507 | 1519 | | |
1508 | | - | |
| 1520 | + | |
1509 | 1521 | | |
1510 | | - | |
1511 | | - | |
| 1522 | + | |
| 1523 | + | |
1512 | 1524 | | |
1513 | 1525 | | |
1514 | 1526 | | |
1515 | 1527 | | |
1516 | | - | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
1517 | 1536 | | |
1518 | 1537 | | |
1519 | 1538 | | |
| |||
1535 | 1554 | | |
1536 | 1555 | | |
1537 | 1556 | | |
1538 | | - | |
| 1557 | + | |
1539 | 1558 | | |
1540 | | - | |
1541 | | - | |
| 1559 | + | |
| 1560 | + | |
1542 | 1561 | | |
1543 | 1562 | | |
1544 | 1563 | | |
1545 | | - | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
1546 | 1571 | | |
1547 | 1572 | | |
1548 | 1573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
329 | 331 | | |
330 | 332 | | |
331 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
| 401 | + | |
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
| 408 | + | |
408 | 409 | | |
409 | 410 | | |
410 | 411 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
| 136 | + | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
| 265 | + | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
308 | | - | |
| 307 | + | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
| 311 | + | |
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
| 319 | + | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| |||
0 commit comments