Forcing a mounted filesystem to dismount

I’m developing a UDF file system. I need to programmatically force a file
system (e.g. the MS UDF reader) to dismount so my file system can mount at
the users request. I thought that I could simply issue a
FSCTL_DISMOUNT_VOLUME to the raw device but this doesn’t appear to dismount
the file system.

Anybody now a better method to force a dismount? Anybody know what’s wrong
with my code below?

if(vpb->Flags&VPB_MOUNTED)
{
UNICODE_STRING FileName;
OBJECT_ATTRIBUTES Attributes;
NTSTATUS NtStatus;
STRING NameStr;
CCHAR NameBuf[6];
IO_STATUS_BLOCK IoStatus;
PHANDLE FileHandle;

// force the device to verify
device->Flags |= DO_VERIFY_VOLUME;

sprintf(NameBuf, “\??\%c:”, driveLetter);

RtlInitAnsiString(&NameStr, NameBuf);

if (RtlAnsiStringToUnicodeString(&FileName, &NameStr, TRUE) ==
STATUS_SUCCESS)
{
// issue a FSCTL_DISMOUNT_VOLUME to the raw device
InitializeObjectAttributes(&Attributes, &FileName,
OBJ_CASE_INSENSITIVE, NULL, NULL);

NtStatus = ZwCreateFile(FileHandle,
SYNCHRONIZE,
&Attributes,
&IoStatus,
NULL,
0,
FILE_SHARE_READ,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);

if(NtStatus == STATUS_SUCCESS)
{
NtStatus = ZwDeviceIoControlFile(FileHandle, 0,0,0,
&IoStatus, FSCTL_DISMOUNT_VOLUME, 0,0,0,0);
}

RtlFreeUnicodeString(&FileName);

ZwClose(FileHandle);
}
}

Unless you will change the load order of the binaries, so that your will be
always loaded at startup before MS’s UDFS.SYS, you will never see the disk.

The thing is that the IO manager tries to mount the filesystems in their
registration (=load) order, and thus you need to be called before UDFS. There
is no other ways to block MS’s FSD from mounting - mount occurs by metadata
recognition only.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Fred”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Monday, September 27, 2004 3:16 AM
Subject: [ntfsd] Forcing a mounted filesystem to dismount

> I’m developing a UDF file system. I need to programmatically force a file
> system (e.g. the MS UDF reader) to dismount so my file system can mount at
> the users request. I thought that I could simply issue a
> FSCTL_DISMOUNT_VOLUME to the raw device but this doesn’t appear to dismount
> the file system.
>
> Anybody now a better method to force a dismount? Anybody know what’s wrong
> with my code below?
>
> if(vpb->Flags&VPB_MOUNTED)
> {
> UNICODE_STRING FileName;
> OBJECT_ATTRIBUTES Attributes;
> NTSTATUS NtStatus;
> STRING NameStr;
> CCHAR NameBuf[6];
> IO_STATUS_BLOCK IoStatus;
> PHANDLE FileHandle;
>
> // force the device to verify
> device->Flags |= DO_VERIFY_VOLUME;
>
> sprintf(NameBuf, “\??\%c:”, driveLetter);
>
> RtlInitAnsiString(&NameStr, NameBuf);
>
> if (RtlAnsiStringToUnicodeString(&FileName, &NameStr, TRUE) ==
> STATUS_SUCCESS)
> {
> // issue a FSCTL_DISMOUNT_VOLUME to the raw device
> InitializeObjectAttributes(&Attributes, &FileName,
> OBJ_CASE_INSENSITIVE, NULL, NULL);
>
> NtStatus = ZwCreateFile(FileHandle,
> SYNCHRONIZE,
> &Attributes,
> &IoStatus,
> NULL,
> 0,
> FILE_SHARE_READ,
> FILE_OPEN,
> FILE_SYNCHRONOUS_IO_NONALERT,
> NULL,
> 0);
>
> if(NtStatus == STATUS_SUCCESS)
> {
> NtStatus = ZwDeviceIoControlFile(FileHandle, 0,0,0,
> &IoStatus, FSCTL_DISMOUNT_VOLUME, 0,0,0,0);
> }
>
> RtlFreeUnicodeString(&FileName);
>
> ZwClose(FileHandle);
> }
> }
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Okay, so suppose that my file system does load before the MS UDF file system
and that I will get a chance to mount first. If I elect not to mount during
the initial mount request and let MS UDF mount, then at a later time the
user elects to enable my file system then shouldn’t a FSCTL_DISMOUNT_VOLUME
request dismount the MS UDF file system which would result in the io manager
calling into my file system to query a new mount?

It seeems like it should but my code (below) doesn’t force MS UDF to
dismount. What’s the purpose of FSCTL_DISMOUNT_VOLUME if it doesn’t
dismount a file sytem?

Any ideas?

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
> Unless you will change the load order of the binaries, so that your
> will be
> always loaded at startup before MS’s UDFS.SYS, you will never see the
> disk.
>
> The thing is that the IO manager tries to mount the filesystems in
> their
> registration (=load) order, and thus you need to be called before UDFS.
> There
> is no other ways to block MS’s FSD from mounting - mount occurs by
> metadata
> recognition only.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Fred”
> Newsgroups: ntfsd
> To: “Windows File Systems Devs Interest List”
> Sent: Monday, September 27, 2004 3:16 AM
> Subject: [ntfsd] Forcing a mounted filesystem to dismount
>
>
>> I’m developing a UDF file system. I need to programmatically force a
>> file
>> system (e.g. the MS UDF reader) to dismount so my file system can mount
>> at
>> the users request. I thought that I could simply issue a
>> FSCTL_DISMOUNT_VOLUME to the raw device but this doesn’t appear to
>> dismount
>> the file system.
>>
>> Anybody now a better method to force a dismount? Anybody know what’s
>> wrong
>> with my code below?
>>
>> if(vpb->Flags&VPB_MOUNTED)
>> {
>> UNICODE_STRING FileName;
>> OBJECT_ATTRIBUTES Attributes;
>> NTSTATUS NtStatus;
>> STRING NameStr;
>> CCHAR NameBuf[6];
>> IO_STATUS_BLOCK IoStatus;
>> PHANDLE FileHandle;
>>
>> // force the device to verify
>> device->Flags |= DO_VERIFY_VOLUME;
>>
>> sprintf(NameBuf, “\??\%c:”, driveLetter);
>>
>> RtlInitAnsiString(&NameStr, NameBuf);
>>
>> if (RtlAnsiStringToUnicodeString(&FileName, &NameStr, TRUE) ==
>> STATUS_SUCCESS)
>> {
>> // issue a FSCTL_DISMOUNT_VOLUME to the raw device
>> InitializeObjectAttributes(&Attributes, &FileName,
>> OBJ_CASE_INSENSITIVE, NULL, NULL);
>>
>> NtStatus = ZwCreateFile(FileHandle,
>> SYNCHRONIZE,
>> &Attributes,
>> &IoStatus,
>> NULL,
>> 0,
>> FILE_SHARE_READ,
>> FILE_OPEN,
>> FILE_SYNCHRONOUS_IO_NONALERT,
>> NULL,
>> 0);
>>
>> if(NtStatus == STATUS_SUCCESS)
>> {
>> NtStatus = ZwDeviceIoControlFile(FileHandle, 0,0,0,
>> &IoStatus, FSCTL_DISMOUNT_VOLUME, 0,0,0,0);
>> }
>>
>> RtlFreeUnicodeString(&FileName);
>>
>> ZwClose(FileHandle);
>> }
>> }
>>
>>
>>
>> —
>> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

Mount is called in reverse order of registration - RAW registers first
(for instance) and then the boot file system and then others as loaded.
Mount calls are from most recently registered to least recently
registered, so RAW is called last.

Max is right, though if you don’t get your load order set up properly,
you won’t ever be called to mount. Also, if another file system returns
an I/O error the mount processing will halt (we saw this on WORM media
where NTFS returned a “blank check” error and the I/O manager treated
the error as fatal).

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Monday, September 27, 2004 9:25 AM
To: ntfsd redirect
Subject: Re: [ntfsd] Forcing a mounted filesystem to dismount

Unless you will change the load order of the binaries, so that your
will be
always loaded at startup before MS’s UDFS.SYS, you will never see the
disk.

The thing is that the IO manager tries to mount the filesystems in
their
registration (=load) order, and thus you need to be called before UDFS.
There
is no other ways to block MS’s FSD from mounting - mount occurs by
metadata
recognition only.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Fred”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Monday, September 27, 2004 3:16 AM
Subject: [ntfsd] Forcing a mounted filesystem to dismount

> I’m developing a UDF file system. I need to programmatically force a
file
> system (e.g. the MS UDF reader) to dismount so my file system can
mount at
> the users request. I thought that I could simply issue a
> FSCTL_DISMOUNT_VOLUME to the raw device but this doesn’t appear to
dismount
> the file system.
>
> Anybody now a better method to force a dismount? Anybody know what’s
wrong
> with my code below?
>
> if(vpb->Flags&VPB_MOUNTED)
> {
> UNICODE_STRING FileName;
> OBJECT_ATTRIBUTES Attributes;
> NTSTATUS NtStatus;
> STRING NameStr;
> CCHAR NameBuf[6];
> IO_STATUS_BLOCK IoStatus;
> PHANDLE FileHandle;
>
> // force the device to verify
> device->Flags |= DO_VERIFY_VOLUME;
>
> sprintf(NameBuf, “\??\%c:”, driveLetter);
>
> RtlInitAnsiString(&NameStr, NameBuf);
>
> if (RtlAnsiStringToUnicodeString(&FileName, &NameStr, TRUE)
==
> STATUS_SUCCESS)
> {
> // issue a FSCTL_DISMOUNT_VOLUME to the raw device
> InitializeObjectAttributes(&Attributes, &FileName,
> OBJ_CASE_INSENSITIVE, NULL, NULL);
>
> NtStatus = ZwCreateFile(FileHandle,
> SYNCHRONIZE,
> &Attributes,
> &IoStatus,
> NULL,
> 0,
> FILE_SHARE_READ,
> FILE_OPEN,
> FILE_SYNCHRONOUS_IO_NONALERT,
> NULL,
> 0);
>
> if(NtStatus == STATUS_SUCCESS)
> {
> NtStatus = ZwDeviceIoControlFile(FileHandle,
0,0,0,
> &IoStatus, FSCTL_DISMOUNT_VOLUME, 0,0,0,0);
> }
>
> RtlFreeUnicodeString(&FileName);
>
> ZwClose(FileHandle);
> }
> }
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Don’t forget to do LOCK/DISMOUNT/UNLOCK

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Fred”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Monday, September 27, 2004 7:52 PM
Subject: Re:[ntfsd] Forcing a mounted filesystem to dismount

> Okay, so suppose that my file system does load before the MS UDF file system
> and that I will get a chance to mount first. If I elect not to mount during
> the initial mount request and let MS UDF mount, then at a later time the
> user elects to enable my file system then shouldn’t a FSCTL_DISMOUNT_VOLUME
> request dismount the MS UDF file system which would result in the io manager
> calling into my file system to query a new mount?
>
> It seeems like it should but my code (below) doesn’t force MS UDF to
> dismount. What’s the purpose of FSCTL_DISMOUNT_VOLUME if it doesn’t
> dismount a file sytem?
>
> Any ideas?
>
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntfsd…
> > Unless you will change the load order of the binaries, so that your
> > will be
> > always loaded at startup before MS’s UDFS.SYS, you will never see the
> > disk.
> >
> > The thing is that the IO manager tries to mount the filesystems in
> > their
> > registration (=load) order, and thus you need to be called before UDFS.
> > There
> > is no other ways to block MS’s FSD from mounting - mount occurs by
> > metadata
> > recognition only.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> > ----- Original Message -----
> > From: “Fred”
> > Newsgroups: ntfsd
> > To: “Windows File Systems Devs Interest List”
> > Sent: Monday, September 27, 2004 3:16 AM
> > Subject: [ntfsd] Forcing a mounted filesystem to dismount
> >
> >
> >> I’m developing a UDF file system. I need to programmatically force a
> >> file
> >> system (e.g. the MS UDF reader) to dismount so my file system can mount
> >> at
> >> the users request. I thought that I could simply issue a
> >> FSCTL_DISMOUNT_VOLUME to the raw device but this doesn’t appear to
> >> dismount
> >> the file system.
> >>
> >> Anybody now a better method to force a dismount? Anybody know what’s
> >> wrong
> >> with my code below?
> >>
> >> if(vpb->Flags&VPB_MOUNTED)
> >> {
> >> UNICODE_STRING FileName;
> >> OBJECT_ATTRIBUTES Attributes;
> >> NTSTATUS NtStatus;
> >> STRING NameStr;
> >> CCHAR NameBuf[6];
> >> IO_STATUS_BLOCK IoStatus;
> >> PHANDLE FileHandle;
> >>
> >> // force the device to verify
> >> device->Flags |= DO_VERIFY_VOLUME;
> >>
> >> sprintf(NameBuf, “\??\%c:”, driveLetter);
> >>
> >> RtlInitAnsiString(&NameStr, NameBuf);
> >>
> >> if (RtlAnsiStringToUnicodeString(&FileName, &NameStr, TRUE) ==
> >> STATUS_SUCCESS)
> >> {
> >> // issue a FSCTL_DISMOUNT_VOLUME to the raw device
> >> InitializeObjectAttributes(&Attributes, &FileName,
> >> OBJ_CASE_INSENSITIVE, NULL, NULL);
> >>
> >> NtStatus = ZwCreateFile(FileHandle,
> >> SYNCHRONIZE,
> >> &Attributes,
> >> &IoStatus,
> >> NULL,
> >> 0,
> >> FILE_SHARE_READ,
> >> FILE_OPEN,
> >> FILE_SYNCHRONOUS_IO_NONALERT,
> >> NULL,
> >> 0);
> >>
> >> if(NtStatus == STATUS_SUCCESS)
> >> {
> >> NtStatus = ZwDeviceIoControlFile(FileHandle, 0,0,0,
> >> &IoStatus, FSCTL_DISMOUNT_VOLUME, 0,0,0,0);
> >> }
> >>
> >> RtlFreeUnicodeString(&FileName);
> >>
> >> ZwClose(FileHandle);
> >> }
> >> }
> >>
> >>
> >>
> >> —
> >> Questions? First check the IFS FAQ at
> > https://www.osronline.com/article.cfm?id=17
> >>
> >> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com