Hello,

my storage device driver connects the file system (mountmgr) with the
pcmcia bus driver. It is used to read and write data from/to pcmcia flash
cards. The pcmcia flash cards are FAT16 formatted by an other operating
system. So far everything works well.

The problems arise as soon as i try to format a pcmcia card, because
windows has the habbit to raise the cluster (allocation unit) size and
change the file system from FAT16 to FAT12.
Now the question is: How can a driver force windows to format a partition
with FAT16 instead of FAT12? Or how can a driver specify the allocation unit
(cluster) size?


The driver receives (and handles) the following IOCTLs after a format
command has been entered: (In ther same order as they are listed)

IOCTL_DISK_CHECK_VERIFY
IOCTL_DISK_IS_WRITEABLE
IOCTL_DISK_GET_DRIVE_GEOMETRY
DiskGeometry.Cylinders.QuadPart = PartitionSize/512;
DiskGeometry.MediaType = FixedMedia;
DiskGeometry.TracksPerCylinder = 1;
DiskGeometry.SectorsPerTrack = 1;
DiskGeometry.BytesPerSector = 512;
IOCTL_DISK_GET_LENGTH_INFO
IOCTL_DISK_GET_PARTITION_INFO_EX
The parameter PARTITION_INFORMATION_EX.Mbr.PartitionType is set
to PARTITION_FAT16 but the value seems to be ignored.
IOCTL_STORAGE_GET_DEVICE_NUMBER
IOCTL_DISK_GET_DRIVE_LAYOUT_EX
PDRIVE_LAYOUT_INFORMATION_EX.PartitionCount = 4;
Type of first partition is PARTITION_FAT_16, the three remaining
partitions are set to PARTITION_ENTRY_UNUSED.
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
IOCTL_DISK_CHECK_VERIFY
IOCTL_DISK_VERIFY
Returns STATUS_SUCCESS without any futher action.
This should be ok, because the formating should only erase/reset
the file system.
IOCTL_DISK_GET_DRIVE_GEOMETRY
IOCTL_DISK_GET_PARTITION_INFO_EX
*** The boot sector is written here, but all previously supplied
file system parameters will be ignored! Why?!?
IOCTL_DISK_SET_PARTITION_INFO:
tries to write the type of the first partition to fat12. Which is
ignored because FAT12 should not be supported!

Non of the above ioctls allows a driver to change the cluster size. So
i suppose there's an other way to adjust the file system parameters.
Please let me know if you have any ideas how to ensure a partition will
be formatted with FAT16.
Thanks in advance,
Mike

Re: FAT16 format troubles by David

David
Thu Oct 14 10:21:45 CDT 2004

Write your own format utility.

"Mike" <xfire666@gmx.ch> wrote in message
news:c341f6b9.0410140712.10846834@posting.google.com...
> Hello,
>
> my storage device driver connects the file system (mountmgr) with the
> pcmcia bus driver. It is used to read and write data from/to pcmcia flash
> cards. The pcmcia flash cards are FAT16 formatted by an other operating
> system. So far everything works well.
>
> The problems arise as soon as i try to format a pcmcia card, because
> windows has the habbit to raise the cluster (allocation unit) size and
> change the file system from FAT16 to FAT12.
> Now the question is: How can a driver force windows to format a partition
> with FAT16 instead of FAT12? Or how can a driver specify the allocation
> unit
> (cluster) size?
>
>
> The driver receives (and handles) the following IOCTLs after a format
> command has been entered: (In ther same order as they are listed)
>
> IOCTL_DISK_CHECK_VERIFY
> IOCTL_DISK_IS_WRITEABLE
> IOCTL_DISK_GET_DRIVE_GEOMETRY
> DiskGeometry.Cylinders.QuadPart = PartitionSize/512;
> DiskGeometry.MediaType = FixedMedia;
> DiskGeometry.TracksPerCylinder = 1;
> DiskGeometry.SectorsPerTrack = 1;
> DiskGeometry.BytesPerSector = 512;
> IOCTL_DISK_GET_LENGTH_INFO
> IOCTL_DISK_GET_PARTITION_INFO_EX
> The parameter PARTITION_INFORMATION_EX.Mbr.PartitionType is set
> to PARTITION_FAT16 but the value seems to be ignored.
> IOCTL_STORAGE_GET_DEVICE_NUMBER
> IOCTL_DISK_GET_DRIVE_LAYOUT_EX
> PDRIVE_LAYOUT_INFORMATION_EX.PartitionCount = 4;
> Type of first partition is PARTITION_FAT_16, the three remaining
> partitions are set to PARTITION_ENTRY_UNUSED.
> IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
> IOCTL_DISK_CHECK_VERIFY
> IOCTL_DISK_VERIFY
> Returns STATUS_SUCCESS without any futher action.
> This should be ok, because the formating should only erase/reset
> the file system.
> IOCTL_DISK_GET_DRIVE_GEOMETRY
> IOCTL_DISK_GET_PARTITION_INFO_EX
> *** The boot sector is written here, but all previously supplied
> file system parameters will be ignored! Why?!?
> IOCTL_DISK_SET_PARTITION_INFO:
> tries to write the type of the first partition to fat12. Which is
> ignored because FAT12 should not be supported!
>
> Non of the above ioctls allows a driver to change the cluster size. So
> i suppose there's an other way to adjust the file system parameters.
> Please let me know if you have any ideas how to ensure a partition will
> be formatted with FAT16.
> Thanks in advance,
> Mike



Re: FAT16 format troubles by xfire666

xfire666
Fri Oct 15 04:26:34 CDT 2004

Hi David,

thanks for your advice, but writing a format utility is only an option
if there is a way to prevent the usage of all other (windows supplied)
format programs.
Is this somehow possible?

I've got an other idea how to fix the fat12 problem and would
appreciate
your advice:
IOCTL_DISK_SET_PARTITION_INFO is a certain indicator that the
partition/drive has just been formatted. Would it be valid to use
IOCTL_DISK_SET_PARTITION_INFO to overwrite the FAT12 boot sector by a
FAT16 boot sector? If the driver also ignores the request to set the
partition type to FAT12, the result would be a FAT16 boot sector on a
FAT16 partition On an empty file system...
But is this a save way to convert (hack) the file system from fat12 to
fat16?

I somehow can't belief that there's no way to specify the file system
parameters. Unfortunatly there's not much information about
fat12/fat16 in the ddk docs, so please let me know if you have any
information.
Thanks and advance,
Mike

Re: FAT16 format troubles by David

David
Fri Oct 15 20:37:04 CDT 2004

There is a FAT doc on the Microsoft site that covers how the rules work for
all FAT types. You need to read and understand it before your questions
will be answered. It is fatgen103.doc. It is somewhere under the hardware
capability labs area.

I did write my own format utility for SmartMedia and to allow hard drive
partitions larger than 32GB to be formatted as FAT32.

"Mike" <xfire666@gmx.ch> wrote in message
news:c341f6b9.0410150126.4e17687c@posting.google.com...
> Hi David,
>
> thanks for your advice, but writing a format utility is only an option
> if there is a way to prevent the usage of all other (windows supplied)
> format programs.
> Is this somehow possible?
>
> I've got an other idea how to fix the fat12 problem and would
> appreciate
> your advice:
> IOCTL_DISK_SET_PARTITION_INFO is a certain indicator that the
> partition/drive has just been formatted. Would it be valid to use
> IOCTL_DISK_SET_PARTITION_INFO to overwrite the FAT12 boot sector by a
> FAT16 boot sector? If the driver also ignores the request to set the
> partition type to FAT12, the result would be a FAT16 boot sector on a
> FAT16 partition On an empty file system...
> But is this a save way to convert (hack) the file system from fat12 to
> fat16?
>
> I somehow can't belief that there's no way to specify the file system
> parameters. Unfortunatly there's not much information about
> fat12/fat16 in the ddk docs, so please let me know if you have any
> information.
> Thanks and advance,
> Mike



Re: FAT16 format troubles by Maxim

Maxim
Mon Oct 18 17:39:43 CDT 2004

Try blocking MJ_CREATE for DASD mode (for zero length or absent
FileObject->FileName).
This will block format and chkdsk.

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

"Mike" <xfire666@gmx.ch> wrote in message
news:c341f6b9.0410150126.4e17687c@posting.google.com...
> Hi David,
>
> thanks for your advice, but writing a format utility is only an option
> if there is a way to prevent the usage of all other (windows supplied)
> format programs.
> Is this somehow possible?
>
> I've got an other idea how to fix the fat12 problem and would
> appreciate
> your advice:
> IOCTL_DISK_SET_PARTITION_INFO is a certain indicator that the
> partition/drive has just been formatted. Would it be valid to use
> IOCTL_DISK_SET_PARTITION_INFO to overwrite the FAT12 boot sector by a
> FAT16 boot sector? If the driver also ignores the request to set the
> partition type to FAT12, the result would be a FAT16 boot sector on a
> FAT16 partition On an empty file system...
> But is this a save way to convert (hack) the file system from fat12 to
> fat16?
>
> I somehow can't belief that there's no way to specify the file system
> parameters. Unfortunatly there's not much information about
> fat12/fat16 in the ddk docs, so please let me know if you have any
> information.
> Thanks and advance,
> Mike



Re: FAT16 format troubles by xfire666

xfire666
Tue Oct 19 04:02:23 CDT 2004

Hello together,
thanks for the information.
I currently try to 'mistreat' IOCTL_DISK_SET_PARTITION_INFO to
overwrite the partition table, boot sector and fat structures after
the drive has been formatted. It looks like the only way to force a
fat16 format on a drive with less than or equal 32 MB capacity. But
i'm still uncertain...

Thanks again,
Mike

Re: FAT16 format troubles by xfire666

xfire666
Thu Oct 21 12:09:03 CDT 2004

"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message news:<#n3FmLWtEHA.3884@TK2MSFTNGP11.phx.gbl>...
> Try blocking MJ_CREATE for DASD mode (for zero length or absent
> FileObject->FileName).
> This will block format and chkdsk.

Hi Maxim,
thanks for the hint but i have some more questions about blocking
format and chkdisk.
What is DASD mode? And how can it be enabled?
The driver receives a lot of IRP_MJ_CREATE requests. But all with
pIrpStack->FileObject->FileName.Length set to zero!
Of course, dropping them all blocks any calls to format/chkdisk, but
unfortunatly also limits the access to 'unaccessible'. :)

Anyway, the only difference between the various MJ_CREATEs appears at
the
following two data fields:
pIrpStack->Parameters.Create.ShareAccess
pIrpStack->Parameters.Create.Options
Now i wonder if there's a way to determine the source of an
IRP_MJ_CREATE based on the values of .Create.ShareAccess and
.Create.Options. Or maybe there's an other way?

Please let me know if you have any ideas how to block format/chkdsk.
Thanks in advance,
Mike

Re: FAT16 format troubles by Peter

Peter
Thu Oct 21 13:04:51 CDT 2004

DASD is direct access storage device (or maybe direct access to storage
device) - it's a way of opening the entire volume for block-level access
rather than any particular stream on the volume (including directory
streams).

opening c:\ is opening the root directory stream in the volume. opening c:
(note - no trailing slash) is a DASD open of the volume.

with disks you can open partitions (\\.\c:) or you can use the PhysicalDrive
links (or the PNP device interface names) to get DASD access to the entire
drive.

-p

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mike" <xfire666@gmx.ch> wrote in message
news:c341f6b9.0410210909.30895bce@posting.google.com...
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> news:<#n3FmLWtEHA.3884@TK2MSFTNGP11.phx.gbl>...
>> Try blocking MJ_CREATE for DASD mode (for zero length or absent
>> FileObject->FileName).
>> This will block format and chkdsk.
>
> Hi Maxim,
> thanks for the hint but i have some more questions about blocking
> format and chkdisk.
> What is DASD mode? And how can it be enabled?
> The driver receives a lot of IRP_MJ_CREATE requests. But all with
> pIrpStack->FileObject->FileName.Length set to zero!
> Of course, dropping them all blocks any calls to format/chkdisk, but
> unfortunatly also limits the access to 'unaccessible'. :)
>
> Anyway, the only difference between the various MJ_CREATEs appears at
> the
> following two data fields:
> pIrpStack->Parameters.Create.ShareAccess
> pIrpStack->Parameters.Create.Options
> Now i wonder if there's a way to determine the source of an
> IRP_MJ_CREATE based on the values of .Create.ShareAccess and
> .Create.Options. Or maybe there's an other way?
>
> Please let me know if you have any ideas how to block format/chkdsk.
> Thanks in advance,
> Mike



Re: FAT16 format troubles by Maxim

Maxim
Thu Oct 21 20:27:30 CDT 2004

> What is DASD mode? And how can it be enabled?

DASD = Direct Access Storage Device. Blockwise disk.

To open the volume in DASD mode in Windows, use pathname like "\\.\C:".

This translates to kernel pathname of "\??\C:", without appending the current
directory. Trying to open "C:" will append the current directory for drive C.
The \\.\ prefix blocks it.

From the FSD's point of view, the DASD CREATE is CREATE with empty filename.
This means that the user wants to work with the disk blockwise. The FSD creates
a special file object which stupidly passes all reads/writes down to the disk,
and supports NtQueryVolumeInformationFile so you can get the disk sizes from
Win32 API.

Now note Raw FS. It only supports DASD mode, and nothing else. It is mounted
only if the user wants to open a DASD filename AND no other FS have recognized
the metadata. So, its only purpose is to support NtQueryVolumeInformationFile
on unformatted disk with no valid FS metadata.

Now note CHKDSK and FORMAT. They use the DASD open to access the disk.

> The driver receives a lot of IRP_MJ_CREATE requests. But all with
> pIrpStack->FileObject->FileName.Length set to zero!
> Of course, dropping them all blocks any calls to format/chkdisk, but
> unfortunatly also limits the access to 'unaccessible'. :)

At least block them with write desired access.

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