EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Operation of CBDisk as a Removal Media Disk

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#11310
Posted: 10/11/2009 20:33:59
by John Hyde (Standard support level)
Joined: 10/11/2009
Posts: 9

When working with a physical disk that has removal media (such as a Thumb Drive or a MediaCard reader) Windows will send a Mass Storage Class command "Prevent Removal" prior to any data writes to the media, it will also send an "Allow Removal" when the writes have been completed. These commands are used so that it is known when the media can be removed.

How does CallbackDisk support this?

I don't know but I am assuming that this has something to do with "Locking the volume" - I am assuming that the CBDisk driver must be handling this DeviceIoControl command, so can this be passed through as an event?

Actually, it may be easier to describe my problem at a higher level rather than presume a solution.

I have two processes that both want to own the data file that CBDisk is managing - the CBDisk image.st file is a FAT32 based file system and both processes want to manage the FAT tables. This is fine for reads but not for writes.
To manage this, I plan to dismount the drive from process A if process B decides to write, then I remount it once the write has finished. Similarly when B writes I dismount the drive from A and remount when the writes have completed. I have measured the mount/dismount times at well below 200 msec so doing this dynamically should be straight forward.

Process B will use Prevent and Allow.

I am now wanting process A (which looks just like the FileDisk example) to understand/implement Prevent and Allow.

If this is not easily supportable by CBDisk itself I plan to create a psuedo-Prevent/Allow by starting a retriggerable timer on a CBDiskWriteFileFunc( ) - ie I set "Prevent" on any CBDiskWriteFileFunc( ) and clear it if my 200 msec timer expires.

Or if anyone has a better method of doing this please let me know.
I have attached a JPEG of the 'bigger picture' - the CallbackDisk is half of the VRD (Virtual Removable Drive) Ap and "Go-Between" is a 2-headed USB device that I have constructed and is working.

Best regards, John


#11311
Posted: 10/12/2009 02:17:52
by Volodymyr Zinin (EldoS Corp.)

Quote
John Hyde wrote:
When working with a physical disk that has removal media (such as a Thumb Drive or a MediaCard reader) Windows will send a Mass Storage Class command "Prevent Removal" prior to any data writes to the media, it will also send an "Allow Removal" when the writes have been completed. These commands are used so that it is known when the media can be removed.

How does CallbackDisk support this?

CallbackDisk doesn't support these commands. But it isn't necessary because the only way to remove CallbackDisk virtual disks is via the CallbackDisk API.

Quote
John Hyde wrote:
I don't know but I am assuming that this has something to do with "Locking the volume" - I am assuming that the CBDisk driver must be handling this DeviceIoControl command, so can this be passed through as an event?

"Locking the volume" is a file system feature. For details see the FSCTL_LOCK_VOLUME description in MSDN.


Quote
John Hyde wrote:
I have two processes that both want to own the data file that CBDisk is managing - the CBDisk image.st file is a FAT32 based file system and both processes want to manage the FAT tables. This is fine for reads but not for writes. ...

If you want to modify any internal file system data (FAT tables, etc) directly you need at first to dismount the mounted file system. Because file systems usually cache their internal data and expect that no one else would modify it. In order to dismount file system use CBDisk.UnmountMedia.
#11318
Posted: 10/12/2009 10:37:58
by John Hyde (Standard support level)
Joined: 10/11/2009
Posts: 9

Vladimir, thank you for your response however you have missed the point of my question.

I understand that
Quote
If you want to modify any internal file system data (FAT tables, etc) directly you need at first to dismount the mounted file system. Because file systems usually cache their internal data and expect that no one else would modify it. In order to dismount file system use CBDisk.UnmountMedia.
.

My question is WHEN to do this.

As you can see from my diagram I have two CPUs and I want both to be able to read and write the Virtual Disk. One CPU is internal to the PC and it is running Windows and my VRD application. The other CPU is external (in my embedded equipment) and it is sending sector read/write requests via USB.

To manage both CPUs writing to the Virtual Disk I plan to dismount the disk from one CPU when the other CPU is writing. Pretty straight forward.

The external CPU warns me that it is about to write to the "disk" by sending a Prevent Removal Mass Storage Class commands - I will use this to dismount the "disk" from the internal CPU. The external CPU then does its writes. The external CPU then sends me a Allow Removal command and I use this to remount the disk for the internal CPU, which will then reload FAT tables etc. All nice and orderly and how a removable media device is designed to work.

What I am looking for is some kind of support in CallbackDisk that warns my application that the OS is about to do a write of the disk and some indication that the writes have completed. The CBDisk driver must know this since Windows must check that the removable media that CBDisk is emulating is present before it attempts its read/write of FAT tables. I will then use this indication to dismount the 'disk' from my external CPU.

I know that CBDisk currently does not do this - hence this question on your forum. I'm assuming that this would be a small add to your driver (ie pass information that it aready has through as an event for the API).

Regards John
#11326
Posted: 10/13/2009 02:12:51
by Volodymyr Zinin (EldoS Corp.)

I see. It is possible to realize sending the Prevent Removal Mass Storage Class commands to the CallbackDisk callbacks. At least it will be possible with the new CallbackDisk driver that we are going to release in a month or two.

But how do you intercept commands sent from "Go-Between" to "PC"? As I understand the "Go-Between" device is shown on "PC" as a USB storage or some another USB device. Is it so? In this case Windows on "PC" builds a stack of USB device drivers to support the "Go-Between" device and it is necessary to have a special filter driver in this USB stack to intercept the Mass Storage Class commands and send them to CallbackDisk.
#11333
Posted: 10/13/2009 11:30:24
by John Hyde (Standard support level)
Joined: 10/11/2009
Posts: 9

Vladimir, yes, this is exactly what I would like: CallbackDisk passing the OS Prevent/Allow Removal MSC commands through as events to CBDisk. This will make my application simpler to implement.

I look forward to testing the next release of CallbackDisk!

Best regards, John
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

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