Insert bytes into middle of a file (in windows filesystem) without reading entire file (using File Allocation Table)?

前端 未结 8 1116
盖世英雄少女心
盖世英雄少女心 2020-12-13 19:04

I need a way to insert some file clusters into the middle of a file to insert some data.

Normally, I would just read the entire file and write it back out again with

8条回答
  •  伪装坚强ぢ
    2020-12-13 19:31

    Abstract question, abstract answer:

    It is certainly possible to do this in FAT and probably in most other FS, you would essentially be fragmenting the file, rather than the more common process of defragmenting.

    FAT is organized with around cluster pointers which produce a chain of cluster numbers where data is stored, the first link index is stored with the file record, the second one is stored in the allocation table at index [the first link's number] etc. It's possible to insert another link anywhere in the chain, for as long as the data you're inserting ends at the boundary of a cluster.

    Chances are you'll have much easier time doing this in C by finding an open source library. While it's probably possible to do that in C# with PInvoke you won't find any good sample code floating around for you to get started.

    I suspect you don't have any control over the file format (video files?), if you do it would be much easier to design your data storage to avoid the problem in the first place.

提交回复
热议问题