Re: How to force discarding of invalid cached partition contents?



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@xxxxxxxxxxxxxxxxxxxxxxx
In 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@xxxxxxxxxxxxxxxxxxxxxxx
A 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?





.



Relevant Pages

  • Re: Can I boot of an XP System disk, nested in a logical volume
    ... The boot partition contains the Windows operating system and its support files. ... Note On dynamic disks, this is known as the system volume. ... The boot volume must always keep the drive letter assigned to it when Windows was installed. ...
    (microsoft.public.windowsxp.basics)
  • Re: How to force discarding of invalid cached partition contents?
    ... When the partition has a drive letter, Windows ... Furthermore if Windows Explorer was displaying the partition before these ...
    (microsoft.public.development.device.drivers)
  • Re: Format C:
    ... > The Windows XP CD is bootable and contains all the tools necessary ... > to partition and format your drive. ... Clean Install Windows XP ...
    (microsoft.public.windowsxp.newusers)
  • Re: Disk Management fails in changing C/[a]-driveletters
    ... From what I can decipher you are trying to change the drive letter onto which Windows is installed, you cannot do that, if you want Windows on a different drive letter you will have to reinstall it. ... You can have more than one Windows installation on a computer and have each installation on its own C:\ drive, you just have to take appropriate measures to ensure that the partition onto which you want to install Windows is the first active partition enumerated by the Windows setup program. ... It will only make a difference if you try to install old applications that absolutely want to be installed on C:, there are few applications who require that nowadays. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: How to force discarding of invalid cached partition contents?
    ... You might want to, before beginning the format sequence, obtain an exclusive ... When the partition has a drive letter, Windows ...
    (microsoft.public.development.device.drivers)