擅长:python、mysql、java
<p>当与I/O操作相关联的数据或元数据由于缺少空间而无法写入任何位置时,<code>ENOSPC</code>(“设备上没有剩余空间”)错误将在<em>任何</em>情况下触发。这并不总是意味着磁盘空间——它可能意味着物理磁盘空间、逻辑空间(例如最大文件长度)、特定数据结构中的空间或地址空间。例如,如果目录表(vfat)中没有空间,或者没有任何索引节点,则可以获取它。大致意思是“我找不到写这件事的地方”。</p>
<p>特别是在Python中,任何写I/O操作都可能发生这种情况。它可以发生在<code>f.write</code>期间,但也可以发生在<code>open</code>、<code>f.flush</code>甚至<code>f.close</code>上。它发生的位置为它发生的原因提供了一个重要的线索-如果它发生在<code>open</code>上,则没有足够的空间为条目写入元数据,如果它发生在<code>f.write</code>、<code>f.flush</code>或<code>f.close</code>期间,则没有足够的磁盘空间,或者您已经超过了最大文件大小。</p>
<p>如果给定目录中的文件系统是<code>vfat</code>,那么您将在达到最大文件限制的同时达到最大文件限制。限制应该是2^16个目录条目,但如果我正确地回忆起来,其他一些因素可能会影响它(例如,某些文件需要多个条目)。</p>
<p>最好避免在一个目录中创建这么多文件。很少有文件系统能轻松地处理这么多目录项。除非您确定您的文件系统能够很好地处理目录中的许多文件,否则您可以考虑另一种策略(例如创建更多目录)。</p>
<p>另外,p.S.也不信任剩余的磁盘空间——一些文件系统为根用户保留了一些空间,而另一些文件系统错误地计算了可用空间,并给了你一个不正确的数字。</p>