在文件分配系统中的某个文件中间删除和插入内容如何工作?

How do deleting and inserting something in the middle of a certain file in file allocation system works?

所以我知道每个文件可能使用一堆簇,每个簇都有一个指向下一个包含文件其余部分的簇的指针,但我不明白当我们尝试删除或插入某些内容时会发生什么在某个扇区的文件中间。 FAT 如何解决这个问题?

我想到的第一个想法是移动数据,但这似乎不是一种非常有效的方法。

So I know that each file may use a bunch of clusters with each cluster having a pointer to the next cluster having the rest of the file, but I don't understand what happens when we try to delete or insert something in the middle of a file in a certain sector. How is this issue resolved in FAT?

一般来说,您不能在文件中间删除或插入,我的意思是文件系统驱动程序不直接支持这些操作。您可以通过从文件原始开始的特定偏移量开始写入数据块来修改文件。您使用写入来实现插入或删除,这是在用户空间级别管理的,而不是文件系统级别。

The first Idea that came to me, was shifting the data, but that doesn't seem to be a very efficient approach.

有两个基本选项:

  • 你就地覆盖文件的尾部,从插入或删除的起始位置开始。这实际上是一种转变,是的,程序必须自行管理。

  • 你写一个全新的文件,然后用它替换原来的文件。

后者通常是除文件末尾以外的修改的首选选项,因为原始文件在整个过程中保持一致状态,并且因为您不需要额外的中间存储部分需要移动的文件内容。

None 这是 FAT 特有的。我不能排除在某处应用不同规则的某些深奥的文件系统或存储介质的可能性,但在大多数情况下,这是持久存储的本质。