首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用`posix_fallocate`创建的Trim文件

用`posix_fallocate`创建的Trim文件
EN

Stack Overflow用户
提问于 2012-03-01 16:24:37
回答 1查看 518关注 0票数 0

我使用我的C程序在我的Linux系统上打开了一个输出文件,我让posix_fallocate为它预留了一堆磁盘空间。

比我需要的要多,因为我不知道我有多需要。

天真地,我希望当我关闭文件时,它会被裁剪到我实际需要的空间。但是,当然,生活不是那么容易。

那么,我如何为输出保留一堆空间,然后将其缩减到实际使用的范围呢?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 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.

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9519957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档