Re: How to force discarding of invalid cached partition contents?
- From: "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx>
- Date: Thu, 17 Jul 2008 14:35:41 +0900
I'm not doing a format (at present).
If I were doing a format then I'd include a call to IOCTL_DISK_UPDATE_PROPERTIES. As a temporary experiment I did include a call to IOCTL_DISK_UPDATE_PROPERTIES but it didn't help. According to MSDN this call is necessary when doing something like changing a FAT32 partition to NTFS, but my recent experiments make me wonder if Windows would still corrupt the resulting partition anyway.
I'll try to find your other postings.
"David Craig" <drivers@xxxxxxxxxx> wrote in message news:OyLrsz85IHA.784@xxxxxxxxxxxxxxxxxxxxxxx
Norman,
You might want to, before beginning the format sequence, obtain an exclusive lock on the physical drive where the volume is located. Do, the format with that handle, and then unlock to get the cache discarded. The open will force any dirty cache blocks to disk before it grants you a handle.
"David Craig" <drivers@xxxxxxxxxx> wrote in message news:ORJoVv85IHA.1420@xxxxxxxxxxxxxxxxxxxxxxxIn the last few weeks I posted some calling sequences on this newsgroup, microsoft.public.win32.programmer.kernel, or ntdev that provide info on how to do this. You could use IRP Tracker to see what chkdsk does when the /F option is specified.
The format program I wrote uses the physical drive <number> to open the entire drive and only puts on partition on the media. There is also a format utility from linux that has been ported to windows as a command line utility that also works. I have used it on a compact flash that is used to load RTL code into a FPGA because the loader is really picky about the file. I don't know if it is because it requires the file be sequentially allocated or it requires the subdirectories be located in the first entry.
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message news:%23gybGd85IHA.192@xxxxxxxxxxxxxxxxxxxxxxxA USB hard drive contains a FAT32 partition. Sometimes the partition has a drive letter assigned. When the partition has a drive letter, Windows Explorer and/or some other parts of Windows XP read and cache a portion of the contents. I write part of the partition myself, so I want to force Windows to abandon its cached contents.
I call DeviceIoControl several times. FSCTL_LOCK_VOLUME, FSCTL_DISMOUNT_VOLUME, IOCTL_VOLUME_OFFLINE, IOCTL_VOLUME_ONLINE, and FSCTL_UNLOCK_VOLUME. All of these succeed. WinIoCtl.h doesn't define IOCTL_VOLUME_OFFLINE and IOCTL_VOLUME_ONLINE, but MSDN implies that these are supposed to be available to user mode applications, so I define them myself and DeviceIoControl reports success.
After that, I have found two ways to do manual operations to force Windows to abandon its cached contents. One is to use Computer Administrator - Disk Administrator, remove the drive letter from the partition, and reassign the drive letter to the partition. The other way is to open a command prompt and run CHKDSK /F, which finds no errors but which somehow persuades Windows XP to discard its cache. If I omit the /F then the obsolete contents remain in the cache, after which Windows proceeds to corrupt the partition and then the next CHKDSK /F adjusts errors (but lost data remain lost).
Now I want to do this programmatically. I wonder why obsolete contents remain in the cache after IOCTL_VOLUME_OFFLINE and IOCTL_VOLUME_ONLINE, but continue trying anyway. I added calls to BroadcastSystemMessage with DBT_DEVICEREMOVECOMPLETE and DBT_DEVICEARRIVAL. These report success. Furthermore if Windows Explorer was displaying the partition before these operations, I can see Windows Explorer respond by removing that partition from its display, displaying the contents of another partition, and then restoring the drive letter and icon in the left hand pane though the right hand pane continues displaying the other partition that it had switched to. So I think that DBT_DEVICEREMOVECOMPLETE and DBT_DEVICEARRIVAL have some amount of effect. But when I click on that drive letter in Windows Explorer, it still displays obsolete cached information, and creating a new file causes corruption in the partition.
What does it take to force Windows to discard obsolete cached data?
.
- References:
- How to force discarding of invalid cached partition contents?
- From: Norman Diamond
- Re: How to force discarding of invalid cached partition contents?
- From: David Craig
- Re: How to force discarding of invalid cached partition contents?
- From: David Craig
- How to force discarding of invalid cached partition contents?
- Prev by Date: [OT] Driver Loader from OSR Online,...
- Next by Date: Re: capturing emf spool file for later replay.
- Previous by thread: Re: How to force discarding of invalid cached partition contents?
- Next by thread: Re: How to force discarding of invalid cached partition contents?
- Index(es):
Relevant Pages
|