Setting Dirty Flag without fsutil.exe from my code,...

Discussion in 'Windows 64bit' started by Kerem Gümrükcü, Apr 3, 2007.

  1. 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ü
    Kerem Gümrükcü, Apr 3, 2007
    #1
    1. Advertising

  2. 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

    Kerem Gümrükcü wrote:
    > 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], Apr 3, 2007
    #2
    1. Advertising

  3. .... 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

    Kerem Gümrükcü wrote:
    > 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], Apr 3, 2007
    #3
  4. 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ü


    "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    Newsbeitrag news:e$m%...
    > ... 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
    >
    > Kerem Gümrükcü wrote:
    >> 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ü
    >>
    Kerem Gümrükcü, Apr 3, 2007
    #4
  5. 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ü
    Kerem Gümrükcü, Apr 3, 2007
    #5
  6. 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ü


    "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    Newsbeitrag news:e$m%...
    > ... 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
    >
    > Kerem Gümrükcü wrote:
    >> 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ü
    >>
    Kerem Gümrükcü, Apr 3, 2007
    #6
  7. 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

    Kerem Gümrükcü wrote:
    > 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ü
    >
    >
    > "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    > Newsbeitrag news:e$m%...
    >> ... 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
    >>
    >> Kerem Gümrükcü wrote:
    >>> 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], Apr 3, 2007
    #7
  8. 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ü

    "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    Newsbeitrag news:%...
    > 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
    >
    > Kerem Gümrükcü wrote:
    >> 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ü
    >>
    >>
    >> "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb
    >> im Newsbeitrag news:e$m%...
    >>> ... 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
    >>>
    >>> Kerem Gümrükcü wrote:
    >>>> 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ü
    >>>>

    >>
    Kerem Gümrükcü, Apr 3, 2007
    #8
  9. > 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ü, Apr 4, 2007
    #9
  10. Hi Rafael,

    i cant set the dirty bit on the system volume. Do you have
    any idea why?

    Best regards

    Kerem Gümrükcü


    "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    Newsbeitrag news:%...
    > 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
    >
    > Kerem Gümrükcü wrote:
    >> 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ü
    >>
    >>
    >> "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb
    >> im Newsbeitrag news:e$m%...
    >>> ... 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
    >>>
    >>> Kerem Gümrükcü wrote:
    >>>> 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ü
    >>>>

    >>
    Kerem Gümrükcü, Apr 5, 2007
    #10
  11. 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

    Kerem Gümrükcü wrote:
    > Hi Rafael,
    >
    > i cant set the dirty bit on the system volume. Do you have
    > any idea why?
    >
    > Best regards
    >
    > Kerem Gümrükcü
    >
    >
    > "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    > Newsbeitrag news:%...
    >> 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
    >>
    >> Kerem Gümrükcü wrote:
    >>> 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ü
    >>>
    >>>
    >>> "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb
    >>> im Newsbeitrag news:e$m%...
    >>>> ... 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
    >>>>
    >>>> Kerem Gümrükcü wrote:
    >>>>> 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], Apr 5, 2007
    #11
  12. 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

    Kerem Gümrükcü wrote:
    > Hi Rafael,
    >
    > i cant set the dirty bit on the system volume. Do you have
    > any idea why?
    >
    > Best regards
    >
    > Kerem Gümrükcü
    Rafael R. [Live Butterfly], Apr 6, 2007
    #12
  13. "Rafael R. [Live Butterfly]" <"[myfirstname]"@fromvistatoxp.com> schrieb im
    Newsbeitrag news:eV%23sbI%...
    > 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
    >
    > Kerem Gümrükcü wrote:
    >> Hi Rafael,
    >>
    >> i cant set the dirty bit on the system volume. Do you have
    >> any idea why?
    >>
    >> Best regards
    >>
    >> 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ü
    Kerem Gümrükcü, Apr 6, 2007
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan

    New Message Flag on folder

    Dan, Oct 14, 2004, in forum: Firefox
    Replies:
    4
    Views:
    555
  2. Rob

    saA Flag

    Rob, Mar 18, 2005, in forum: Cisco
    Replies:
    2
    Views:
    5,696
  3. Burt

    error flag send to Microsoft

    Burt, Jan 8, 2004, in forum: Computer Support
    Replies:
    3
    Views:
    1,015
    MrToad
    Jan 9, 2004
  4. Hipster Dufus

    Outlook2000 - Flag for Follow Up

    Hipster Dufus, Jan 8, 2004, in forum: Computer Support
    Replies:
    1
    Views:
    497
    Sultan
    Jan 9, 2004
  5. MrPepper11

    Crack in Computer Security Code Raises Red Flag

    MrPepper11, Mar 15, 2005, in forum: Computer Security
    Replies:
    10
    Views:
    1,061
Loading...

Share This Page