Re: Zero-clearing all zero-clearable bytes.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tetsuo Handa wrote:
Hello.

Andreas Dilger wrote:
Why would you fill the buffer with 0xff instead of 0?
In fact no such program is needed, just "dd if=/dev/zero of=/{fs}/tmp"
and then delete the file.

To avoid that the /{fs}/tmp is created as a sparse file.


Most filesystems will not create a sparse file if zero-byte filled blocks are written. To create a sparse file you normally have to seek beyond the file end and then write blocks, leaving a hole in-between the positions.

The information from stat can tell you if a file has been stored sparsely, because the blocks used count will be less than the file size suggests.

For example:

$ dd if=/dev/zero of=small-file bs=512 count=16
16+0 records in
16+0 records out
8192 bytes (8.2 kB) copied, 0.000187744 seconds, 43.6 MB/s
phillip@dylan:/tmp$ stat small-file
  File: `small-file'
  Size: 8192            Blocks: 16         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 847831      Links: 1

The zero filled file uses 16 blocks (16 * 512 bytes = 8K), and so we know it isn't sparsely stored.

You can get dd to seek a number of blocks into the output file before writing, this will create a sparse file...

$ dd if=/dev/zero of=small-file bs=512 count=16 seek=16
16+0 records in
16+0 records out
8192 bytes (8.2 kB) copied, 0.000212609 seconds, 38.5 MB/s
phillip@dylan:/tmp$ stat small-file
  File: `small-file'
  Size: 16384           Blocks: 16         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 847831      Links: 1

A 16K file is only using 16 blocks, and so 8K is stored sparsely.

Phillip
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux