我使用我的C程序在我的Linux系统上打开了一个输出文件,我让posix_fallocate为它预留了一堆磁盘空间。
比我需要的要多,因为我不知道我有多需要。
天真地,我希望当我关闭文件时,它会被裁剪到我实际需要的空间。但是,当然,生活不是那么容易。
那么,我如何为输出保留一堆空间,然后将其缩减到实际使用的范围呢?
谢谢!
发布于 2012-03-01 16:33:29
这种行为是预期的-引用posix_fallocate手册页:
If the size of the file is less than offset+len, then the file is increased to this size; otherwise the file size is left unchanged.
在关闭签出ftruncate之前修复文件大小
The truncate() and ftruncate() functions cause the regular file named by path or referenced by fd to be truncated to a size of precisely length bytes.
https://stackoverflow.com/questions/9519957
复制相似问题