Search code examples
linuxunixfilesystemspartition

If the size of the file exceeds the maximum size of the file system, what happens?


For example, In FAT32 partition, The maximum file size is 4GB. but I was able to create a 5GB file with vim and I saved the file and opened it again, the console output was broken like a staircase. I have three questions.

  1. If the size of the file exceeds the maximum size of the file system, what happens?

  2. In my case, Why break?

  3. In Unix system call, stat() can succeed up to a 2GB(2^31 - 1). Does this have anything to do with the file system? Is there a relationship between the limits of data in stat() and the limits of each feature in the file system?


Solution

  • If the size of the file exceeds the maximum size of the file system, what happens?

    By definition, that can never happens. What really happens is that some system call (probably write(2) ...) is failing, and the code doing that should take care of that case.

    Notice that FAT32 filesystems restrict the maximal size of files to 2Gigabytes. Use a better file system on your USB key if you want more (or split(1) large files in smaller chunks before copying them to your FAT32-formatted USB key).

    If using <stdio.h> notice that fflush(3), fprintf(3), fclose(3) (and most other standard functions) can fail (e.g. because they will do some failing write(2)).

    the console output was broken like a staircase

    probably because your pseudoterminal was in some broken state. See stty(1), reset(1), termios(3) and read the tty demystified.

    In Unix system call, stat() can succeed up to a 2GB(2^31 - 1)

    You are misunderstanding stat(2). Read again its documentation

    Read Advanced Linux Programming then syscalls(2).

    I was able to create a 5GB file with vim

    To understand the behavior of vim read first its documentation then study its source code (it is free software, and you can and perhaps should study its code).

    You could also use strace(1) to understand what system calls are done by some command or process.