3 * Copyright (C) 2002,2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: drivers/fs/fs_rec/vfat.c
23 * PURPOSE: Filesystem recognizer driver
24 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
35 /* FUNCTIONS ****************************************************************/
38 FsRecIsFatVolume(IN PDEVICE_OBJECT DeviceObject
)
41 PARTITION_INFORMATION PartitionInfo
;
42 DISK_GEOMETRY DiskGeometry
;
44 struct _BootSector
* Boot
;
45 BOOLEAN RecognizedFS
= FALSE
;
46 Size
= sizeof(DISK_GEOMETRY
);
48 Status
= FsRecDeviceIoControl(DeviceObject
,
49 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
54 if (!NT_SUCCESS(Status
))
56 DPRINT("FsRecDeviceIoControl faild (%x)\n", Status
);
59 if (DiskGeometry
.MediaType
== FixedMedia
|| DiskGeometry
.MediaType
== RemovableMedia
)
61 // We have found a hard disk
62 Size
= sizeof(PARTITION_INFORMATION
);
63 Status
= FsRecDeviceIoControl(DeviceObject
,
64 IOCTL_DISK_GET_PARTITION_INFO
,
69 if (!NT_SUCCESS(Status
))
71 DPRINT("FsRecDeviceIoControl faild (%x)\n", Status
);
75 if (PartitionInfo
.PartitionType
)
77 if (PartitionInfo
.PartitionType
== PARTITION_FAT_12
||
78 PartitionInfo
.PartitionType
== PARTITION_FAT_16
||
79 PartitionInfo
.PartitionType
== PARTITION_HUGE
||
80 PartitionInfo
.PartitionType
== PARTITION_FAT32
||
81 PartitionInfo
.PartitionType
== PARTITION_FAT32_XINT13
||
82 PartitionInfo
.PartitionType
== PARTITION_XINT13
)
87 else if (DiskGeometry
.MediaType
== RemovableMedia
&&
88 PartitionInfo
.PartitionNumber
> 0 &&
89 PartitionInfo
.StartingOffset
.QuadPart
== 0 &&
90 PartitionInfo
.PartitionLength
.QuadPart
> 0)
92 /* This is possible a removable media formated as super floppy */
96 if (DiskGeometry
.MediaType
> Unknown
&& DiskGeometry
.MediaType
< RemovableMedia
)
100 if (RecognizedFS
== FALSE
)
102 return STATUS_UNRECOGNIZED_VOLUME
;
105 Boot
= ExAllocatePool(NonPagedPool
, DiskGeometry
.BytesPerSector
);
108 return STATUS_INSUFFICIENT_RESOURCES
;
111 Status
= FsRecReadSectors(DeviceObject
,
114 DiskGeometry
.BytesPerSector
,
116 if (!NT_SUCCESS(Status
))
121 if (Boot
->Signatur1
!= 0xaa55)
126 Boot
->BytesPerSector
!= 512 &&
127 Boot
->BytesPerSector
!= 1024 &&
128 Boot
->BytesPerSector
!= 2048 &&
129 Boot
->BytesPerSector
== 4096)
135 Boot
->FATCount
!= 1 &&
142 Boot
->Media
!= 0xf0 &&
143 Boot
->Media
!= 0xf8 &&
144 Boot
->Media
!= 0xf9 &&
145 Boot
->Media
!= 0xfa &&
146 Boot
->Media
!= 0xfb &&
147 Boot
->Media
!= 0xfc &&
148 Boot
->Media
!= 0xfd &&
149 Boot
->Media
!= 0xfe &&
156 Boot
->SectorsPerCluster
!= 1 &&
157 Boot
->SectorsPerCluster
!= 2 &&
158 Boot
->SectorsPerCluster
!= 4 &&
159 Boot
->SectorsPerCluster
!= 8 &&
160 Boot
->SectorsPerCluster
!= 16 &&
161 Boot
->SectorsPerCluster
!= 32 &&
162 Boot
->SectorsPerCluster
!= 64 &&
163 Boot
->SectorsPerCluster
!= 128)
169 Boot
->BytesPerSector
* Boot
->SectorsPerCluster
> 32 * 1024)
176 return RecognizedFS
? STATUS_SUCCESS
: STATUS_UNRECOGNIZED_VOLUME
;
181 FsRecVfatFsControl(IN PDEVICE_OBJECT DeviceObject
,
184 PIO_STACK_LOCATION Stack
;
185 static UNICODE_STRING RegistryPath
=
186 RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Vfatfs");
189 Stack
= IoGetCurrentIrpStackLocation(Irp
);
191 switch (Stack
->MinorFunction
)
193 case IRP_MN_MOUNT_VOLUME
:
194 DPRINT("FAT: IRP_MN_MOUNT_VOLUME\n");
195 Status
= FsRecIsFatVolume(Stack
->Parameters
.MountVolume
.DeviceObject
);
196 if (NT_SUCCESS(Status
))
198 DPRINT("Identified FAT volume\n");
199 Status
= STATUS_FS_DRIVER_REQUIRED
;
203 case IRP_MN_LOAD_FILE_SYSTEM
:
204 DPRINT("FAT: IRP_MN_LOAD_FILE_SYSTEM\n");
205 Status
= ZwLoadDriver(&RegistryPath
);
206 if (!NT_SUCCESS(Status
))
208 DPRINT("ZwLoadDriver failed (Status %x)\n", Status
);
212 IoUnregisterFileSystem(DeviceObject
);
217 DPRINT("FAT: Unknown minor function %lx\n", Stack
->MinorFunction
);
218 Status
= STATUS_INVALID_DEVICE_REQUEST
;