简体   繁体   English

如果文件大小超过文件系统的最大大小,会发生什么?

[英]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. 例如,在FAT32分区中,最大文件大小为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. 但是我可以用vim创建一个5GB的文件,然后保存并再次打开该文件,控制台输出像楼梯一样坏了。 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). 在Unix系统调用中,stat()最多可以继承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? stat()中的数据限制与文件系统中每个功能的限制之间是否存在关系?

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. 真正发生的是某个系统调用(可能是write(2) ...)失败了,执行此操作的代码应解决这种情况。

Notice that FAT32 filesystems restrict the maximal size of files to 2Gigabytes. 请注意, FAT32文件系统将文件的最大大小限制为2G。 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). 如果需要更多文件 ,请在USB闪存盘上使用更好的文件系统 (或较大的文件分割成较小的块(将1个文件分割再复制到FAT32格式的USB闪存盘)。

If using <stdio.h> notice that fflush(3) , fprintf(3) , fclose(3) (and most other standard functions) can fail (eg because they will do some failing write(2) ). 如果使用<stdio.h>注意fflush(3)fprintf(3)fclose(3) (以及大多数其他标准函数)可能会失败(例如,因为它们会使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 . 请参阅stty(1)reset(1)termios(3)并阅读tty揭秘

In Unix system call, stat() can succeed up to a 2GB(2^31 - 1) 在Unix系统调用中,stat()最多可以继承2GB(2 ^ 31-1)

You are misunderstanding stat(2) . 您误会stat(2) Read again its documentation 再次阅读其文档

Read Advanced Linux Programming then syscalls(2) . 阅读Advanced Linux Programming,然后阅读syscalls(2)

I was able to create a 5GB file with vim 我能够用vim创建一个5GB的文件

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). 要了解vim的行为,请先阅读其文档,然后研究其源代码(它是免费软件 ,您可以并且应该研究其代码)。

You could also use strace(1) to understand what system calls are done by some command or process. 您还可以使用strace(1)来了解某些命令或进程完成的系统调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM