首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ext4如何使用fallocate

ext4如何使用fallocate
EN

Stack Overflow用户
提问于 2017-03-18 02:31:17
回答 1查看 734关注 0票数 0

最近,我正在测试ext4文件系统的正确用法。我的专家是:

当系统崩溃时,数据已经被写回ok不能丢失,但是元数据可以。

下面是我的用法:

代码语言:javascript
复制
   1. call fallocate to alloc centain space          fallocate(fd, 0, 0, 4\*1024\*1024);    //4MB
   2. call fsync(fd)  let data and metadata write to disks
   3. then i call function to randomly write the file with 4k   size(random data but not 0).  with O\_DRICT flag,but not call fsync.  I log the offset with return write ok.
   4. check the offset that logged. but i find in some offset, read 4k data, is 0. It seems mean that offset isn't used like hole files.  

我的问题是:

代码语言:javascript
复制
<1. why after calling fallocate and fsync the metadata of the file still seems indicate some blocks is not used, so when read it return null. It is my understand .
代码语言:javascript
复制
<2. have other api to call, can make sure that in allocate space with file is not holes ,after that  when write data return ok with O\_DIRECT  can make sure the data will not be loss even the system crashed. 
代码语言:javascript
复制
Thanks.
EN

回答 1

Stack Overflow用户

发布于 2017-08-09 20:40:41

只有写入文件空间才能消除漏洞。如果不写,就没有脏页,fsync什么也不做。

我想知道你是如何执行你的第四步的。看起来你是手动崩溃的,是吗?如果你在没有崩溃的情况下读完它,它不应该是零,只要你写了非零。如果您在崩溃后读取它,如果存在磁盘缓存,则可能发生零。然而,这种类型的零不像孔,它们是从磁盘读取的零(很可能磁盘包含零)。

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

https://stackoverflow.com/questions/42864794

复制
相关文章

相似问题

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