Re: FlushFileBuffers in non-privileged user mode



Hirakawa wrote:
On Oct 18, 12:28 am, Uwe Sieber <m...@xxxxxxxxxxxxx> wrote:
Hirakawa wrote:
On Oct 17, 8:00 pm, J de Boyne Pollard <j.deboynepoll...@xxxxxxxxx>
wrote:
H> Good day. I am currently working on an encryption software
H> that need to flush file cache before the software end.
Why do you think that it needs to do that?
H> Is there any other method I can try to make FlushFileBuffers
H> works in non-privileged user mode?
<URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/put-down-the-
chocolate-covered-banana.html>
Hi, thank you for reply.
In Windows 2000 and XP user mode, if the working device that I am
using is a removable disk (either Flash Drive or HDD), I will have the
problem of data corruption or small file (<4k) lost. Therefore I need
to make sure that everything is flush back before user plug out or
safely remove the device.
'Safely remove' is good enough, it flushes for you.

To prevent caching problems at all just use FILE_FLAG_NO_BUFFERING
or FILE_FLAG_WRITE_THROUGH.

Uwe

Hi Uwe, I visited your website before and you have a great eject
device software. Since you're here, can I ask you a question about
safely remove composite usb mass storage device? (I hope you don't
mind)

I got some devices with me right now which cannot be safely remove by
Win2K and WinVista. Those devices are composite device and I think I
might have problem to flush the cache under user mode. May I know how
your eject software flush the file cache under user mode?

The EjectMediaTool tries to flush but if it fail then it
just do not flush.
IOCTL_STORAGE_EJECT_MEDIA is called only if FSCTL_LOCK_VOLUME
FSCTL_DISMOUNT_VOLUME succeed before.
I tried to get corrupt data by writing a large file in 3,5KB
blocks to fill up the write cache. FSCTL_LOCK_VOLUME always
failed until all data where written. So, this seems to be
good enough.

Back to my problem, some of my users report to me that under Windows
2000 user mode, they have data corruption problem even though OS
return safely remove successful message. It seems that due to FAT32,
the write back of cache is slower than FAT.

Interesting. I've not tried this so far.

That's the reason why I am
seeking for a solution to flush file buffers in non privileged mode.

Currently I am using the following line to get the handle and send to
flushfilebuffers in Administrator Mode:

CreateFile(szVolumeName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ
| FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0);

The FILE_FLAG should not make a difference for FlushFileBuffers.
It's correct that FlushFileBuffers needs write access. Seems
EjectMedia uses a read handle, so it never flushed...

For FSCTL_LOCK_VOLUME you need at least a read handle. For
restricted uses even this fails. This can be enabled by a
policy:
http://www.uwe-sieber.de/usbstick_e.html#removal_fails
The policy is supposed to enable the ejection of drives with
DriveType DRIVE_REMOVABLE, but in fact it enables read access
to such drive's volume.


Uwe

.



Relevant Pages