EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to know if file is written

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#32873
Posted: 03/31/2015 23:48:00
by Manoj Jain (Standard support level)
Joined: 02/28/2013
Posts: 94

Sample C++ EncryptWithHeader:

1. I select a folder to encrypt.

Using a copy operation on button click, I copy a file to the folder to encrypt.

I want to know or get the information that file write is complete and I can use the file or do my next operation.

what is the correct way?
#32874
Posted: 04/01/2015 01:14:41
by Eugene Mayevski (EldoS Corp.)

OnCloseFileC event is a right place to schedule further operations. Note that OnCloseFileC is fired before the file is actually closed. So it makes sense to use OnCloseFileN notification event which is called a bit later (in a second or two).


Sincerely yours
Eugene Mayevski
#32875
Posted: 04/01/2015 01:38:26
by Manoj Jain (Standard support level)
Joined: 02/28/2013
Posts: 94

OnCloseFileC is available in the sample C++ EncryptWithHeader


How to add OnCloseFileN in the same sample as I am using this for encryption so will continue.
#32888
Posted: 04/02/2015 05:09:51
by Manoj Jain (Standard support level)
Joined: 02/28/2013
Posts: 94

Waiting for reply....

I have already tried adding definition, declaration etc of OnCloseFileN as per FileMon Sample but Close Notify event is not firing

I have added CloseNotify in SetFilter.

OnCloseFileC is firing but it fires many times and it is difficult to jufge if copy is complete

Please help
#32889
Posted: 04/02/2015 05:27:07
by Vladimir Cherniga (EldoS Corp.)

Quote
Manoj Jain wrote:
I have already tried adding definition, declaration etc of OnCloseFileN as per FileMon Sample but Close Notify event is not firing

You should also add a corresponding flag in AddCallbackFilter() api call. Check it please.

Quote
Manoj Jain wrote:
OnCloseFileC is firing but it fires many times and it is difficult to jufge if copy is complete

There is a multiple open/close requests may arrive simultaneously. You should keep a reference count, increment on post-open/post-create, decrement on close file event. When it reaches zero - it it safe to decide that there is no opened handles exists and no deferred write/read requests.
#32890
Posted: 04/02/2015 05:52:51
by Manoj Jain (Standard support level)
Joined: 02/28/2013
Posts: 94

Code
g_CbFlt.AddFilterCallbackRule(FolderToEncrypt, (CallbackFilter::CbFltCallbackFlags)(
      CallbackFilter::ReadCallback |
      CallbackFilter::WriteCallback |
      CallbackFilter::CreateCallback |
      CallbackFilter::RenameCallback |
      CallbackFilter::SetSizesCallback |
      CallbackFilter::EnumerateDirectoryCallback |
      CallbackFilter::OpenCallback |
      CallbackFilter::CloseCallback |
      CallbackFilter::GetSizesCallback |
      CallbackFilter::CloseNotify
      ));


Code
void CbFltCloseFileN(CallbackFilter*, LPCWSTR);


Code
   g_CbFlt.SetOnCloseFileN(CbFltCloseFileN);


Code
void CbFltCloseFileN(
    CallbackFilter* Sender,
    LPCWSTR FileName
    )
{
      AddToLogFile(L"File Closed");
}



I have done four changes above
#32891
Posted: 04/02/2015 06:03:52
by Vladimir Cherniga (EldoS Corp.)

CloseFile notification is masked by CloseFile callback. This is by design. Disable CallbackFilter::CloseCallback flag and you will get notification. But in your case callbacks is preferable, because UserContext field is not present in notifications, therefore any context information cannot be saved between callbacks.
#32892
Posted: 04/02/2015 06:13:48
by Manoj Jain (Standard support level)
Joined: 02/28/2013
Posts: 94

Code
void CbFltCloseFileC(
    CallbackFilter* Sender,
    LPCWSTR FileName,
    PVOID* UserContext
    )
{
   EncryptContext *MyContext;
   MyContext = (EncryptContext*)(*UserContext);
   // WCHAR text[MAX_PATH * 2];

    if (MyContext !=NULL)
    {
       /* wsprintfW(text, L"CloseFileC RefCnt(%d) (%s)", MyContext->RefCnt(), FileName);
        AddToLog(text);*/
        if(MyContext->RefCnt() < 0)
            DebugBreak();
    }
    else
    {
       /* wsprintfW(text, L"CloseFileC MyContext(NULL) (%s)", FileName);
        AddToLog(text);*/
    }
   if ((MyContext != NULL) && (MyContext->DecrementRef() == 0)) {
        /*wsprintfW(text, L"CloseFileC (%s) delete ctx(%08X)", FileName, MyContext);
        AddToLog(text);*/
      delete MyContext;
      *UserContext = NULL;
   }

     AddToLogFile(L"File Close Callback");

}



This is the code in the Close Call back.

I could not understand what actually you want to say. You said in my case closecallback is preferable, does this mean I cannot use close Notify?

Or above code in closecallback will not be important as you suggested me to delete it ...

Need a specific answer so that I can look for another alternative
#32893
Posted: 04/02/2015 06:21:16
by Vladimir Cherniga (EldoS Corp.)

Quote
Manoj Jain wrote:
I could not understand what actually you want to say. You said in my case closecallback is preferable, does this mean I cannot use close Notify?

If you wish to use close notify, you should disable close callback. Or do you need both handlers active at the same time ?
#32894
Posted: 04/02/2015 06:24:31
by Manoj Jain (Standard support level)
Joined: 02/28/2013
Posts: 94

In the EncryotwithHeader Sample there is code in CloseCallback

If I disablwe CloseCallback and use close Notify ..... How will it affect the performance of EncryotwithHeader sample.

Will it affect encryption?

I repeat, I am using EncryotwithHeader, no change at this stage
Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.

Reply

Statistics

Topic viewed 8348 times

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




|

Back to top

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

Got it!