What is the relationship between file pointer width and maximum file size

Just curious about the maximum file size. provided by some popular Linux file systems, I saw that some of them fit the TB scale.

My question is, if the file pointer is 32 bits wide, like most Linux that we meet today, does this mean that the maximum distance we can solve is 2 ^ 32-1 bytes? Then how can we save a file larger than 4 GB?

In addition, even if we can save such a file, how can we find a position outside the range of 2 ^ 32?

+3
source share
6 answers

4 , " " (LFS) Linux. , LFS, , 64- . , Linux 32 64- (, x86 x86-64). . http://www.suse.de/~aj/linux_lfs.html

LFS ​​ glibc 2.2 kernel 2.4.0 ( 2000-2001), Linux .

Linux, (, lseek64 lseek) #define _FILE_OFFSET_BITS 64, 64 .

+4

Linux, , (.. , kohlehydrat).

. , . , #define, , "" " ". 64 , .

+1

. FILE * C stdio - , , , , , . fseek(), , , long, fgetpos() fsetpos() fpos_t.

, off_t . , , , "Large File Support" (LFS), ABI off_t. ( API #define API.)

+1

read(int fd, void *buf, size_t count);

( , "" .)

- - , (Inodes), (), . , .

0

lseek64 . Ext4 16 TiB.

0

UNIX , , 32- , 2,4 .

, 0x7fffffff .

ext2 ​​ . , . . Linux .

There are also some user space programs that cannot handle files larger than 2 GB .

The maximum file size is limited min( (b/4)3+(b/4)2+b/4+12, 232*b )due to i_block (an array of EXT2_N_BLOCKS)and i_blocks( 32-bits integer value )representing the number of bytes of bytes in the file.

-1
source

Source: https://habr.com/ru/post/1790710/


All Articles