How do I create a sparse file programmatically, in C, on Mac OS X?

后端 未结 7 1452
谎友^
谎友^ 2020-12-19 03:00

I\'d like to create a sparse file such that all-zero blocks don\'t take up actual disk space until I write data to them. Is it possible?

相关标签:
7条回答
  • 2020-12-19 03:53

    If you want portability, the last resort is to write your own access function so that you manage an index and a set of blocks.

    In essence you manage a single file as the OS manages the disk keeping the chain of the blocks that are part of the file, the bitmap of allocated/free blocks etc.

    Of course this will lead to a non optimized and slower access, I would reccomend this apprach only if the requirement to save space is absolutely critical and you have enough time to write a robust set of access functions.

    And even in that case, I would first investigate if your problem is in need of a different solution. Probably you should store your data differently?

    0 讨论(0)
提交回复
热议问题