-1

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

atmgnd
  • 1
  • Please note that Stack Overflow is for programming questions and not general computing issues. Please review [What topics can I ask here?](https://stackoverflow.com/help/on-topic) for more details. Question may be appropriate for [Super User](http://superuser.com) or [Unix & Linux](http://unix.stackexchange.com) but do check their help before posting. – kaylum Aug 04 '20 at 06:25
  • c/c++ code is also acceptable – atmgnd Aug 04 '20 at 06:29

1 Answers1

0

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.

atmgnd
  • 1