我正在查看fallocate的手册页,但我不明白这两者之间的区别。一种似乎分配了块但没有写入它们,另一种似乎释放了块而不覆盖它们。无论哪种方式,从用户的角度来看,效果似乎都无法区分。请给我解释一下。
清零文件空间在模式中指定 FALLOC_FL_ZERO_RANGE 标志(自 Linux 3.15 起可用)会将字节范围内的空间清零,从 offset 开始并持续到 len 个字节。在指定范围内,为跨越文件中空洞的区域预先分配块。成功调用后,从此范围内的后续读取将返回零。
Zeroing is done within the filesystem preferably by converting the range into unwritten extents. This approach means that the specified range will not be physically zeroed out on the device (except for partial blocks at the either end of the range), and I/O is (otherwise) required only to update metadata. If the FALLOC_FL_KEEP_SIZE flag is additionally specified in mode, the behavior of the call is similar, but the file size will not be changed even if offset+len is greater than the file size. This behavior is the same as when preallocating space with FALLOC_FL_KEEP_SIZE specified. Not all filesystems support FALLOC_FL_ZERO_RANGE; if a filesystem doesn't support the operation, an error is returned. The operation is supported on at least the following filesystems: * XFS (since Linux 3.15) * ext4, for extent-based files (since Linux 3.15) * SMB3 (since Linux 3.17)
增加文件空间 在模式中指定 FALLOC_FL_INSERT_RANGE 标志(自 Linux 4.1 起可用)通过在文件大小内插入一个洞而不覆盖任何现有数据来增加文件空间。该孔将从偏移量开始并持续 len 个字节。当在文件中插入孔时,从偏移量开始的文件内容将向上移动(即到更高的文件偏移量) len 个字节。在文件中插入一个洞会使文件大小增加 len 个字节。
This mode has the same limitations as FALLOC_FL_COLLAPSE_RANGE regarding the granularity of the operation. If the granularity requirements are not met, fallocate() will fail with the error EINVAL. If the offset is equal to or greater than the end of file, an error is returned. For such operations (i.e., inserting a hole at the end of file), ftruncate(2) should be used. No other flags may be specified in mode in conjunction with FALLOC_FL_INSERT_RANGE. FALLOC_FL_INSERT_RANGE requires filesystem support. Filesystems that support this operation include XFS (since Linux 4.1) and ext4 (since Linux 4.2).