How to force discarding of invalid cached partition contents?



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: How to force discarding of invalid cached partition contents?
    ... If I were doing a format then I'd include a call to IOCTL_DISK_UPDATE_PROPERTIES. ... 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. ... 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. ...
    (microsoft.public.development.device.drivers)
  • 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: Cloning a disk using dd
    ... In Linux you would just do a clean install of the OS, ... In Windows none of this is possible ... it possible that they are just using a label in the partition table? ... If you are looking to _change_ the drive letter of the clone, ...
    (comp.os.linux.misc)

Loading