EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Complete Overwrite vs Append

Posted: 05/05/2015 15:48:59
by Danil Kornishev (Basic support level)
Joined: 05/05/2015
Posts: 4

Hi, I am trying to figure out how to distinguish incoming writes that want to first truncate the file to 0 and then write anew (overwrite) vs append calls.

I used desiredAccess value to check the append/write bits, but! There is nothing preventing a program from requesting both WRITE and APPEND even when it only intends to append (and java FileOutputStream seems to do just that).

My other thought was to check for position 0 in onWrite, but sadly, on SSDs write blocks arrive out of order.

Any help would be appreciated.
Posted: 05/06/2015 01:11:28
by Eugene Mayevski (Team)

Truncate can be done in multiple ways: eg. the application opens the file as a regular one and the ncalls SetAllocationSize or SetEndOfFile (these are imaginary names, I don't have access to WinAPI reference now) and in several other ways. So it would be nice to understand, what you are trying to achieve with the knowledge of the file being truncated.

Sincerely yours
Eugene Mayevski
Posted: 05/06/2015 07:12:34
by Danil Kornishev (Basic support level)
Joined: 05/05/2015
Posts: 4

Basically we have a db-like storage behind CBFS and we need to purge the previous file data when a new file with the same name is being added.

If I understand you correctly, it is insufficient for writing program to request write access with correct flag, first it has to truncate which would trigger onSetAllocationSize(0) or onSetEndOfFile(0)

In either case, I would know that file data needs to be purged?
Posted: 05/06/2015 07:32:28
by Eugene Mayevski (Team)

What I am saying is that there's more than one way to skin a cat, i.e. to "truncate" a file. So the best is to handle the commands as they come and not make any assumptions about what the application intends to do. If you get the request to set file length to 0, then you are safe to truncate your data or discard the record and create another one. If the file is opened, you can analyze the flags and act accordingly.

Sincerely yours
Eugene Mayevski



Topic viewed 3267 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!