Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 928
Vi. Avatar asked Apr 01 '10 20:04

Vi.


People also ask

What is a sparse copy?

In computer science, a sparse file is a type of computer file that attempts to use file system space more efficiently when the file itself is partially empty.

Is sparse a file?

Sparse Files are a type of computer file that allows for efficient storage allocation for large data. A file is considered to be sparse when much of its data is zero (empty data). Support for the creation of such files is generally provided by the File system.

What is sparse file Linux?

Sparse file is a type of computer file, which generally has file size (logical) higher than allocated size (clusters allocated to data of the file). Most File systems support this type of file, but Operating system suppresses them underneath command interpreters' command or API calls.


1 Answers

/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.

like image 135
ephemient Avatar answered Sep 28 '22 07:09

ephemient