Windows Forum / Windows XP / 64-bit / April 2007
Setting Dirty Flag without fsutil.exe from my code,...
|
|
Thread rating:  |
Kerem Gümrükcü - 03 Apr 2007 11:35 GMT Hi,
is there a way, to set a ntfs volumes "dirty" flag without the fsutil.exe tool. I want to integrate this functionality of setting a dirty flag on a volume into my application.Where and what do i have to modify on the drive/registry to enforce a drive check after a system reboot. Is this applicable to other drives like FAT(32). I think it should be, as far as i know from fsutil.exe.
TIA
Best regards
Kerem Gümrükcü
Rafael R. [Live Butterfly] - 03 Apr 2007 16:26 GMT I reverse engineered fsutil.exe for you (Windows Server 2003) Your mileage may vary. I'm not responsible if your computer is turned into cheese.
Sample code:
--- snip --- /* Undocumented volume management control code */ #define FSCTL_SET_DIRTY_BIT 0x90030
DWORD bytesReturned = 0x00;
HANDLE hVol = CreateFile( _T("\\\\.\\I:"), GENERIC_WRITE FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
BOOL bitSet = DeviceIoControl( hVol, FSCTL_SET_DIRTY_BIT, 0x00, 0x00, 0x00, 0x00, &bytesReturned, 0);
if( bitSet ) printf( _T("dirty bit set.\n") );
--- snip ---
- Rafael
> Hi, > [quoted text clipped - 11 lines] > > Kerem Gümrükcü Kerem Gümrükcü - 03 Apr 2007 17:40 GMT By the Way,
> Your mileage may vary. I'm not responsible if your computer is turned into > cheese. I like Cheeese,...;-)
Best regards
Kerem Gümrükcü
Rafael R. [Live Butterfly] - 03 Apr 2007 16:30 GMT ... and no, it doesn't appear the bit can be set on non-NTFS volumes using fsutil.exe methods. You may have to drill down into the BIOS parameter block on disk... Sounds like a pain.
- Rafael
> Hi, > [quoted text clipped - 11 lines] > > Kerem Gümrükcü Kerem Gümrükcü - 03 Apr 2007 17:30 GMT Hi Rafael,
thanks for the example. It is always the DeviceIOControl that makes such things possible. Accessing NTFS Volumes is just enough. I found interessting informations here: http://www.ntfs.com/
But i think i will let the Drivers do the work for me since i dont want to risk to damage a drive. Ill will do some tests on some virtual systems on my machine and see what i can achieve...
Thank you very much,...
Best regards
Kerem Gümrükcü
> ... and no, it doesn't appear the bit can be set on non-NTFS volumes using > fsutil.exe methods. You may have to drill down into the BIOS parameter [quoted text clipped - 17 lines] >> >> Kerem Gümrükcü Kerem Gümrükcü - 03 Apr 2007 18:39 GMT Hi Rafael,
when i try to gain access to my Windows Drive ("C:") with the given Parameters for the DeviceIOControl with the CreateFile function i get a "Invalid Handle", all other drives work fine. Do you have any idea why?
Best regards
Kerem Gümrükcü
> ... and no, it doesn't appear the bit can be set on non-NTFS volumes using > fsutil.exe methods. You may have to drill down into the BIOS parameter [quoted text clipped - 17 lines] >> >> Kerem Gümrükcü Rafael R. [Live Butterfly] - 03 Apr 2007 18:51 GMT I'm assuming you meant DeviceIoControl() returns 0 and GetLastError() returns INVALID_HANDLE. Does CreateFile( \\.\C:, ... ) return a proper handle?
I'll check fsutil.exe again but I don't recall seeing any special handling for the system volume. Try using the volume names (i.e. \\?\Volume{475977c3-578a-11da-8cd6-806e6f6e6963}\)?
- Rafael
> Hi Rafael, > [quoted text clipped - 29 lines] >>> >>> Kerem Gümrükcü Kerem Gümrükcü - 03 Apr 2007 19:15 GMT Hi Rafael,
yes, DeviceIOControl returns FALSE and GetLastError says "Invalid Handle". What could cause that return code, sure a invalid handle, but how does this happen. How do i get volume names? I work with GetLogicalDriveStrings(...) to retrieve the logical volumes. How to get volume names?
When i tried to open the the A: Floppy i got something like "Wrong Parameter" from DeviceIOControl = FALSE and GetLastError() following it. Ok Floppy A: is empty and no disk inserted,...
Best regards
Kerem Gümrükcü
> I'm assuming you meant DeviceIoControl() returns 0 and GetLastError() > returns INVALID_HANDLE. Does CreateFile( \\.\C:, ... ) return a proper [quoted text clipped - 39 lines] >>>> >>>> Kerem Gümrükcü Kerem Gümrükcü - 04 Apr 2007 00:01 GMT > How do i get volume names? I work with GetLogicalDriveStrings(...) to > retrieve > the logical volumes. How to get volume names? Ok, i got it: GetVolumeNameForVolumeMountPoint
Kerem Gümrükcü - 05 Apr 2007 04:17 GMT Hi Rafael,
i cant set the dirty bit on the system volume. Do you have any idea why?
Best regards
Kerem Gümrükcü
> I'm assuming you meant DeviceIoControl() returns 0 and GetLastError() > returns INVALID_HANDLE. Does CreateFile( \\.\C:, ... ) return a proper [quoted text clipped - 39 lines] >>>> >>>> Kerem Gümrükcü Rafael R. [Live Butterfly] - 05 Apr 2007 21:19 GMT Hi Kerem,
Sorry I haven't gotten back to you. I'll take a look at this sometime later this afternoon/evening (GMT-5) and get back to you.
- Rafael
> Hi Rafael, > [quoted text clipped - 48 lines] >>>>> >>>>> Kerem Gümrükcü Rafael R. [Live Butterfly] - 06 Apr 2007 01:25 GMT Kerem,
I have no issues using the code snippet provided on any of my volumes. Is your system volume NTFS? Anything unique about it? Are you sure you got a proper CreateFile() handle? Are you an administrator and/or have the proper permissions?
- Rafael
> Hi Rafael, > [quoted text clipped - 4 lines] > > Kerem Gümrükcü Kerem Gümrükcü - 06 Apr 2007 12:48 GMT > Kerem, > [quoted text clipped - 13 lines] >> >> Kerem Gümrükcü Hi Rafael,
if found it! It was my fault, it was a code-logic error. The Code branch was wrong, i returned a wrong error code to the calling function so it did return me a strange error code too. I found out over the years that the win32 api error return codes are not always reliable so this is my excperience.
Thank you for your time and effort,...
By the way: Yesterday i found out that the Windows DDK doesnt like spaces in directory paths. i was about to become nuts, since i wrote my own make-file and i was wondering why it throws a lot of make errors, even though everything was alright.
Again, thank you very much,...
Best regards
Kerem Gümrükcü
|
|
|