I want to develop an application that could open file and replace all bytes in that physical location in order to making recovery hard (some kind of data wiper).
So how I could be sure if I open a file with QFile
which is n Mb and write n Mb of dummy data over that data will be overwrite in same physical location (in both Windows and Linux)?
For "usual" file systems, on HDD drives, it should be enough just to seek to the start of the file and write the right amount of bytes. They will be put to the same location.
However, it's quite hard to do that this way in SSD, because you need to deal with write aplification, when data is not actually written into the same location, even if the operating system thinks it is. Instead, for SSD the TRIM command should be used, which marks the blocks free, and SSD controller will rewrite them with zeroes to be able to reuse them later. In modern file systems, such as ext4
or ntfs
it is already done for deleted files.
Resuming, on HDD your method is good and applicable. For SSD it will only make a few copies of the data, so I would better avoid that and just delete the file, hoping that the FS driver will send TRIM to the SSD controller for me.