I have 2TB HDD contains a single partition of FAT32 file system. While truncating a file to larger size say 100MB or 200MB using ftruncate()
, it takes time of 5 to 10 seconds to do zero padding. Is there any way of file truncation that take a less time or do it without zero padding?
Asked
Active
Viewed 614 times
3

MMM
- 7,221
- 2
- 24
- 42

Parshv Shah
- 31
- 3
-
6What would you prefer the file to be filled with? Just extending the size of the file could present a security risk, as it would be filled with data previously on the disk, and I don't think FAT32 supports [sparse files](https://en.wikipedia.org/wiki/Sparse_file), which would do what you want. – icabod Apr 30 '13 at 12:04
-
Actually pin point is not zero padding. Pin point is time taken to truncate a file. If I want to full 2TB HDD with files of size 200MB then it will take a lot of time which is very long for me and I really want to reduce it. So Is there any way to access blocks directly instead going to each block and do zero padding? – Parshv Shah Apr 30 '13 at 12:22
-
[SetFileValidData](http://msdn.microsoft.com/en-us/library/windows/desktop/aa365544(v=vs.85).aspx) may be useful if your operating system supports it. – Raymond Chen Apr 30 '13 at 13:15
-
You could directly edit the file allocation tables... – Douglas B. Staple May 09 '13 at 14:55
1 Answers
1
No. Ftruncate specifically adds zeros to the end according to the GNU C library page. It also says you could try and just use truncate, and it will try to fill it with holes instead, but this isn't supported on all machines so you might not be able to do that.
You could try and hack the file system by opening the inode and changing the value to make the File system think the file is larger, but this is a security issue.

KrisSodroski
- 2,796
- 3
- 24
- 39
-
In particular, FAT32 file systems, like the one the questioner has, do not support hole-y files; hence the zero-fill extension. – twalberg May 10 '13 at 14:34