EldoS | Feel safer!

Software components for data protection, secure storage and transfer

GetOriginatorProcessName

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#27965
Posted: 01/14/2014 06:26:20
by pnina (Standard support level)
Joined: 11/20/2013
Posts: 36

I am referring to this question:
https://www.eldos.com/cbfs/articles/5301.php

I tried to do this inside the CbFsReadFile event (C#):
Code
   string process = null;
         bool a = fileSystem.GetOriginatorProcessName(ref process);

And the process is always empty, and returns "false". I used GetLastError(), and it returned "0" (success).
Can GetOriginatorProcessName be used inside CbFsReadFile?
#27973
Posted: 01/14/2014 06:55:13
by Volodymyr Zinin (EldoS Corp.)

Theoretically GetOriginatorProcessName can be used inside the OnRead and OnWrite callbacks, but in some cases it's "useless". For example a memory mapped section is created for a file (for example by the use of MapViewOfFile) and access to the file data is done via this section. In this case it is the system memory manager component in the context of the "SYSTEM" process (with PID = 4) which is originator of read/write requests to the file system. And in the case several processes have access the memory mapped section there is no way to know which of them performs specific read/write.
It's better to call GetOriginatorProcessName from the OnCreate and OnOpen callbacks. In this case you will be able to know which process is opening the file/directory and what access rights are requested.
#27978
Posted: 01/14/2014 07:10:40
by pnina (Standard support level)
Joined: 11/20/2013
Posts: 36

Hi Vladimir!

From what I saw so far, while enumerating a directory, cbfs calls CbFsOpenFile to all the files inside the enumerated directory.

CbFsReadFile is called when the user tries to open the file (double-click), when the user touches the file without clicking it, and sometimes randomly without any user's action. (less times than CbFsOpenFile is called)

My data for the VDisk comes from another app. I get it by methods such as AnotherApp.getList(), AnotherApp.getFile(), etc.

So on enumerate directory callback I use AnotherApp.getList(), and according to the list I create the content using VirtualFile class (from the VDisk sample).
Since the list is nothing but VirtualFile items, they are empty.

When the user wants to open a file, I call AnotherApp.getFile(), to get a stream.
I perform AnotherApp.getFile() inside CbFsReadFile, to avoid unnecessary download. But still CbFsReadFile can be called randomly, and I am thinking how to avoid it.
I thought I can know if I need to download a file or not based on the process who called it, which didn't work.
Can you suggest how can I avoid unnecessary downloads that can slow down the whole project?
#27980
Posted: 01/14/2014 07:37:00
by Volodymyr Zinin (EldoS Corp.)

CBFS just passes I/O requests to user mode callbacks. I.e. it isn't CBFS which opens every file during directory enumeration. Perhaps it's Explorer which performs it in order to read thumbnails for files being enumerated.
In order to minimize quantity of operations you can try to use network mounting points instead of "usual" ones (for details see the description of CBFS_SYMLINK_NETWORK flag in the CBFS documentation). At least Explorer for not locally "located" files performs less I/O requests. Also if additionally setting the FILE_ATTRIBUTE_OFFLINE for files (with the use of a network mounting point) then at least Windows 7 doesn't read thumbnails at all.

As I understand you are trying to return error or fill the output buffer with dummy data from the OnRead callback. It isn't good idea because some programs can start working incorrectly. For example even if Explorer doesn't show any error in this case there can be third-party shell extension DLLs. Also the problem can be if a file is opened as a memory mapped section.
#27982
Posted: 01/14/2014 07:50:28
by pnina (Standard support level)
Joined: 11/20/2013
Posts: 36

I am using network mounting point already :)

I read in another post that you don't recommend using FILE_ATTRIBUTE_OFFLINE. Is it okay now?
(Btw, when creating a new VirtualFile, just tried adding vfile.Attributes = System.IO.FileAttributes.Offline; and it didn't change anything)

Where do you think I should obtain the stream of the VirtualFile item, instead of the CbFsReadFile callback? (to have minimal number of random calls)
I currently do this inside CbFsReadFile:
Code
                gch = GCHandle.FromIntPtr(FileInfo.UserContext);
                vfile = (VirtualFile)gch.Target;

                if (vfile.AllocationSize == 0 && vfile.EndOfFile != 0)
                {
                    Stream stream = AnotherApp.getFile();
                    vfile.Write(stream);
                }

                vfile.Read(Buffer, Position, BytesToRead, ref BytesRead);

And I added another Write function inside VirtualFile class:
Code
        public void Write(Stream stream)
        {
            stream.CopyTo(mStream);
        }
#27987
Posted: 01/14/2014 10:04:16
by Volodymyr Zinin (EldoS Corp.)

Quote
testt4558 wrote:
I read in another post that you don't recommend using FILE_ATTRIBUTE_OFFLINE. Is it okay now?

Could you specify a link to this post? In any case you can try to use of this attribute.

Quote
testt4558 wrote:
Btw, when creating a new VirtualFile, just tried adding vfile.Attributes = System.IO.FileAttributes.Offline; and it didn't change anything

Use the OR operation to add the attribute. I.e.
vfile.Attributes |= System.IO.FileAttributes.Offline;
Also CBFS will know about the modified attribute only when you specified it via the OnGetFileInfo and/or OnEnumerateDirectory callbacks.

Quote
testt4558 wrote:
Where do you think I should obtain the stream of the VirtualFile item, instead of the CbFsReadFile callback?

It's up to your implementation of CBFS callbacks. It doesn't influence on the number of callbacks (i.e. on the number of I/O requests that Windows sends to the CBFS virtual disk).
#27988
Posted: 01/14/2014 10:20:05
by Eugene Mayevski (EldoS Corp.)

Quote
Vladimir Zinin wrote:
Quote testt4558 wrote: I read in another post that you don't recommend using FILE_ATTRIBUTE_OFFLINE. Is it okay now?

Could you specify a link to this post? In any case you can try to use of this attribute.


It is not recommended because (a) Explorer will display the offline icon for those files and (b) behavior of different applications with those flag was not investigated. We can't guarantee that "offline" files will be properly handled by various third-party applications.


Sincerely yours
Eugene Mayevski
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

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