EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to use SOLFS OS callback in memory?

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
Posted: 08/10/2013 08:58:38
by Erwin Liong (Priority Standard support level)
Joined: 06/04/2013
Posts: 2

I am using Solid File System OS Edition Version 1.5.108.
Based on the dot net sample, I created a simple C# application to create a virtual drive. I used the callback methods as part of the SOLFS Storage constructor. The Constructor is as follow:
m_Storage = new SolFSStorage(@".\myDisk.st", true, 4096, false, false, '\\', "My SOLFS Disk",
                                new SolFSCreateFileEvent(OnCreateFile),
                                new SolFSOpenFileEvent(OnOpenFile),
                                new SolFSCloseFileEvent(OnCloseFile),
                                new SolFSFlushFileEvent(OnFlushFile),
                                new SolFSDeleteFileEvent(OnDeleteFile),
                                new SolFSGetFileSizeEvent(OnGetFileSize),
                                new SolFSSetFileSizeEvent(OnSetFileSize),
                                new SolFSSeekFileEvent(OnSeekFile),
                                new SolFSReadFileEvent(OnReadFile),
                                new SolFSWriteFileEvent(OnWriteFile));

As an example, the Create File handle is as follow:
private void OnCreateFile(SolFSStorage Sender, String FileName, ref UInt32 File, bool Overwrite, bool IsJournalFile, ref int Result)
            FileStream stream = null;
                if (Overwrite)
                    stream = new FileStream(FileName, FileMode.Create);
                    Result = 0;
                        stream = new FileStream(FileName, FileMode.CreateNew);
                        Result = 0;
                    catch (IOException)
                        Result = 183; //ERROR_ALREADY_EXISTS
                if (Result == 0)
                    int hashcode = stream.GetHashCode();
                    if (hashcode < 0)
                        hashcode += 0x7fffffff;
                    File = (uint)hashcode;
                    StorageStreams.Add(File, stream);
            catch (Exception)
                Result = -1;
                File = 0xffffffff;

This would create a file myDisk.st as a working file system. When the storage is open, I am able to add directories or files into myDisk.st and it would be persisted within the disk.

Is there a way to write such files to memory instead of persisting them onto a file (myDisk.st)?

Any sample code snippet to do this?
Thanks in advance...
Posted: 08/10/2013 10:53:19
by Eugene Mayevski (EldoS Corp.)

First let's ensure that callback mode does what you need. With callback mode you can have a virtual disk, whose data is stored not in the disk file (as it is by default) but where your application needs.

Consequently all On***File callbacks are about the container file, not about files stored in the SolFS storage.

Now in your code OnCreateFile creates a container on the disk. You use FileStream.

To switch to memory just change FileStream to MemoryStream class. Just remember that memory is not unlimited, so using MaxPageCount property and handling OnParentSize is a good idea.

Sincerely yours
Eugene Mayevski



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