EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to increase file size ?

Posted: 01/02/2013 07:29:14
by Mia Pak (Priority Standard support level)
Joined: 11/19/2012
Posts: 16

I have question for increase file size.
For add encryption information about the encrypted file, I increased the size to 512 bytes for the header block.
So I used callback function in the following ways.

1 WriteFile: Move start position to 512 and write buffer.
2 ReadFile: Move start position to 512 and read buffer.
3 SetEndOfFile: Increase end position to 512.
4 GetFilesize: Return original file size (except for the size of the header)

Usually. By way of the above, file header block is created well. and It's no problem.

However, In the specific program(like powerpoint), WriteFile being called to a larger size than the size of the SetEndofFile.
In this case, file handle size is less than buffer size because of header block and failed to save buffer.
So I use CallbackFiter :SetEndofFile to increase handle size in the WriteFile Callback. but It's occured system hang.

Check SetAllocationSize / EnumurateDirectory Callback but did not know the information about the increased size.

Do you have a advice if there is a way to solve my problem?

thank you.
Posted: 01/02/2013 09:00:02
by Vladimir Cherniga (Team)

Increasing file size possible without explicit SetEndOfFile event. It can be made by extending write request from the user mode. In this case just save a new file size in associated context.
Posted: 01/02/2013 12:39:31
by Mia Pak (Priority Standard support level)
Joined: 11/19/2012
Posts: 16

Could you explain in detail or simple example?
Posted: 01/02/2013 12:52:43
by Vladimir Cherniga (Team)

Could you explain in detail or simple example?

You may refer to the Encrypt sample, look at the EncryptContext::Write() procedure for details.
Posted: 01/04/2013 03:47:49
by Mia Pak (Priority Standard support level)
Joined: 11/19/2012
Posts: 16

I can't find increasing size in encrypt sample.

As I said above question, It's possible to change size at setendoffile callback and I increase size in this callback for my header.
But sometimes in WriteFile Callback, File size is changed writing none cached buffer after writing cache buffer . So I use "callbackfilter::setendoffile" to increase size for my header info size. but in this time SetEndofFile be caused desktop hang.

Is there any solution about my problem?
Posted: 01/04/2013 04:22:37
by Eugene Mayevski (Team)

We are sorry for misleading you, indeed our samples don't shift file data as you do.

As mentioned in the neigbour post, to forge file size you need to handle:
a) GetFileSize (OnPostGetFileSizesC)
b) EnumerateDirectory (OnEnumerateDirectoryC)
c) file alteration operations (OnSetAllocationSizeC, OnSetEndOfFileC, OnWriteFileC)

Note, that besides obvious events there's also OnWriteFileC event which can alter file size.

We do have plans to extend our sample to hold encryption key and IV in the beginning of the file, but such modification of the sample would take some time as our developers have a development plan filled for a couple of months.

Sincerely yours
Eugene Mayevski
Posted: 01/04/2013 04:26:00
by Vladimir Cherniga (Team)

What happened if you write beyond end of file in write callback, without changing EOF value ? Write callback may be originated from the cache or memory manager and in this case exclusive locks are granted to the file. This cause a system lock in callback handler, if you try to perform an operations that requires file system resources be acquired. It does mean that you cannot request file system to change file size in read or write callbacks.
Posted: 01/04/2013 10:09:16
by Mia Pak (Priority Standard support level)
Joined: 11/19/2012
Posts: 16

<--header block-->|<--- encrypted block (same size to original file) ---->

Above feature is what I want to make file structure.
For making this, I resized file size by CallbackFilter::SetEndOfFile in SetEndofFile Callback.(It's only one what I know.)
But cached writing alters the size of the file without firing any CallbackEvent(SetEndOfFile, EnumDiretory, SetAllocationSize). So If I can not resize the file in read/write callback like you said, Is there point to do this?
And Eugene said that altering is possible in write callback, then what is the way?

thank you. :)
Posted: 01/04/2013 10:24:29
by Vladimir Cherniga (Team)

You should try to report fake file size in GetFileSize and EnumerateDirectory callback. Also you may try to patch offsets for non-cached read/write requests in the corresponding callbacks in order to prevent header block reading into the system cache.
Posted: 01/04/2013 10:49:02
by Mia Pak (Priority Standard support level)
Joined: 11/19/2012
Posts: 16

Yes. I did it.
Problem is increasing the size of the file as header block after cached write.



Topic viewed 12117 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!