How to unset sparse flag of a file in ntfs-3g partition, using only linux?

277 views Asked by At

I want to unset sparse flag of a file in ntfs-3g partition, using only linux. and properly(zerofill holes ?).

What I have tried: setfattr -h -v 0x00000000 -n system.ntfs_attrib_be /xxx/file

1

There are 1 answers

0
atmgnd On

I found a workaround. using the following command may clear the sparse flag if there is holes in orignal spase file.

filesize=$(stat --format="%s" filename)
ntfsfallocate /dev/sdb1 -l ${filesize} /relative_path_to_mnt_target

What if there no holes in orignal sparse file? also there is a wrokaround.

  1. first resize(enlarge) the file using truncate to create some holes.
  2. umount, using ntfsfallocate to truncate to orginal size. demo command:
filesize=$(stat --format="%s" filename)
truncate -s $((filesize + 16 * 1024 * 1024)) /path_to_sparse_file
umount /dev/sdb1
ntfsfallocate /dev/sdb1 -l ${filesize} /relative_path_to_mnt_target

Finally, You can patch ntfsfallocate's source(provided by ntfs-3g), to clear the sparse flag directly, but I am not show any c code here.