How to check if the block is present in a sparse file (for simple copy-on-write)?

孤者浪人 提交于 2020-01-14 08:47:08

问题


How to get sparse block size and check if data is present at the given offset in sparse file in reiserfs/ext3 in Linux?

I want to use it to implement simple copy-on-write block device using FUSE.

Or I should better keep a bitmap in a separate file?


回答1:


/usr/src/linux/Documentation/filesystems/fiemap.txt

The fiemap ioctl is an efficient method for userspace to get file extent mappings. Instead of block-by-block mapping (such as bmap), fiemap returns a list of extents.

There's a quick example of usage in git://kernel.ubuntu.com/cking/debug-code/fiemap/. A sparse file will lack extents for the "missing" portions.




回答2:


Since Linux 3.1, lseek provides flags SEEK_HOLE and SEEK_DATA to navigate to the beginning or end of a hole, so this might be an alternative to the ioctl based solution. Haven't tried either in practice, so I don't have any real experience to compare the two.




回答3:


Well, http://lxr.linux.no/#linux+v2.6.33/arch/um/drivers/cow_user.c indicates that User Mode Linux uses an explicit bitmap for this, FWIW.



来源:https://stackoverflow.com/questions/2563305/how-to-check-if-the-block-is-present-in-a-sparse-file-for-simple-copy-on-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!