- Check more exactly for a FAT file system.

svn path=/trunk/; revision=9284
This commit is contained in:
Hartmut Birr 2004-05-02 20:12:38 +00:00
parent a4b7d6a7a5
commit 38ed29a671
2 changed files with 151 additions and 47 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: fat.c,v 1.8 2003/11/17 02:12:49 hyperion Exp $ /* $Id: fat.c,v 1.9 2004/05/02 20:12:38 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -41,57 +41,143 @@
static NTSTATUS static NTSTATUS
FsRecIsFatVolume(IN PDEVICE_OBJECT DeviceObject) FsRecIsFatVolume(IN PDEVICE_OBJECT DeviceObject)
{ {
DISK_GEOMETRY DiskGeometry; NTSTATUS Status;
PUCHAR Buffer; PARTITION_INFORMATION PartitionInfo;
ULONG Size; DISK_GEOMETRY DiskGeometry;
NTSTATUS Status; ULONG Size;
struct _BootSector* Boot;
BOOL RecognizedFS = FALSE;
Size = sizeof(DISK_GEOMETRY);
Size = sizeof(DISK_GEOMETRY); Status = FsRecDeviceIoControl(DeviceObject,
Status = FsRecDeviceIoControl(DeviceObject, IOCTL_DISK_GET_DRIVE_GEOMETRY,
IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL,
NULL, 0,
0, &DiskGeometry,
&DiskGeometry, &Size);
&Size); if (!NT_SUCCESS(Status))
DPRINT("FsRecDeviceIoControl() Status %lx\n", Status); {
if (!NT_SUCCESS(Status)) DPRINT("FsRecDeviceIoControl faild (%x)\n", Status);
{ return Status;
return(Status); }
} if (DiskGeometry.MediaType == FixedMedia || DiskGeometry.MediaType == RemovableMedia)
{
// We have found a hard disk
Size = sizeof(PARTITION_INFORMATION);
Status = FsRecDeviceIoControl(DeviceObject,
IOCTL_DISK_GET_PARTITION_INFO,
NULL,
0,
&PartitionInfo,
&Size);
if (!NT_SUCCESS(Status))
{
DPRINT("FsRecDeviceIoControl faild (%x)\n", Status);
return Status;
}
DPRINT("BytesPerSector: %lu\n", DiskGeometry.BytesPerSector); if (PartitionInfo.PartitionType)
Buffer = ExAllocatePool(NonPagedPool, {
DiskGeometry.BytesPerSector); if (PartitionInfo.PartitionType == PARTITION_FAT_12 ||
if (Buffer == NULL) PartitionInfo.PartitionType == PARTITION_FAT_16 ||
{ PartitionInfo.PartitionType == PARTITION_HUGE ||
return(STATUS_INSUFFICIENT_RESOURCES); PartitionInfo.PartitionType == PARTITION_FAT32 ||
} PartitionInfo.PartitionType == PARTITION_FAT32_XINT13 ||
PartitionInfo.PartitionType == PARTITION_XINT13)
{
RecognizedFS = TRUE;
}
}
else if (DiskGeometry.MediaType == RemovableMedia &&
PartitionInfo.PartitionNumber > 0 &&
PartitionInfo.StartingOffset.QuadPart == 0LL &&
PartitionInfo.PartitionLength.QuadPart > 0LL)
{
/* This is possible a removable media formated as super floppy */
RecognizedFS = TRUE;
}
}
if (DiskGeometry.MediaType > Unknown && DiskGeometry.MediaType < RemovableMedia )
{
RecognizedFS = TRUE;
}
if (RecognizedFS == FALSE)
{
return STATUS_UNRECOGNIZED_VOLUME;
}
Status = FsRecReadSectors(DeviceObject, Boot = ExAllocatePool(NonPagedPool, DiskGeometry.BytesPerSector);
0, /* Partition boot sector */ if (Boot == NULL)
1, {
DiskGeometry.BytesPerSector, return STATUS_INSUFFICIENT_RESOURCES;
Buffer); }
if (!NT_SUCCESS(Status))
{
ExFreePool(Buffer);
return(Status);
}
if ((strncmp(&Buffer[0x36], "FAT12", 5) == 0) || Status = FsRecReadSectors(DeviceObject,
(strncmp(&Buffer[0x36], "FAT16", 5) == 0) || 0,
(strncmp(&Buffer[0x52], "FAT32", 5) == 0)) 1,
{ DiskGeometry.BytesPerSector,
Status = STATUS_SUCCESS; (PUCHAR) Boot);
} if (!NT_SUCCESS(Status))
else {
{ return Status;
Status = STATUS_UNRECOGNIZED_VOLUME; }
}
ExFreePool(Buffer); if (Boot->Signatur1 != 0xaa55)
{
RecognizedFS=FALSE;
}
if (RecognizedFS &&
Boot->BytesPerSector != 512 &&
Boot->BytesPerSector != 1024 &&
Boot->BytesPerSector != 2048 &&
Boot->BytesPerSector == 4096)
{
RecognizedFS=FALSE;
}
return(Status); if (RecognizedFS &&
Boot->FATCount != 1 &&
Boot->FATCount != 2)
{
RecognizedFS=FALSE;
}
if (RecognizedFS &&
Boot->Media != 0xf0 &&
Boot->Media != 0xf8 &&
Boot->Media != 0xf9 &&
Boot->Media != 0xfa &&
Boot->Media != 0xfb &&
Boot->Media != 0xfc &&
Boot->Media != 0xfd &&
Boot->Media != 0xfe &&
Boot->Media != 0xff)
{
RecognizedFS=FALSE;
}
if (RecognizedFS &&
Boot->SectorsPerCluster != 1 &&
Boot->SectorsPerCluster != 2 &&
Boot->SectorsPerCluster != 4 &&
Boot->SectorsPerCluster != 8 &&
Boot->SectorsPerCluster != 16 &&
Boot->SectorsPerCluster != 32 &&
Boot->SectorsPerCluster != 64 &&
Boot->SectorsPerCluster != 128)
{
RecognizedFS=FALSE;
}
if (RecognizedFS &&
Boot->BytesPerSector * Boot->SectorsPerCluster > 32 * 1024)
{
RecognizedFS=FALSE;
}
ExFreePool(Boot);
return RecognizedFS ? STATUS_SUCCESS : STATUS_UNRECOGNIZED_VOLUME;
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: fs_rec.h,v 1.3 2003/01/16 11:58:15 ekohl Exp $ /* $Id: fs_rec.h,v 1.4 2004/05/02 20:12:38 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -40,6 +40,24 @@ typedef struct _DEVICE_EXTENSION
ULONG FsType; ULONG FsType;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION; } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
struct _BootSector
{
unsigned char magic0, res0, magic1;
unsigned char OEMName[8];
unsigned short BytesPerSector;
unsigned char SectorsPerCluster;
unsigned short ReservedSectors;
unsigned char FATCount;
unsigned short RootEntries, Sectors;
unsigned char Media;
unsigned short FATSectors, SectorsPerTrack, Heads;
unsigned long HiddenSectors, SectorsHuge;
unsigned char Drive, Res1, Sig;
unsigned long VolumeID;
unsigned char VolumeLabel[11], SysType[8];
unsigned char Res2[448];
unsigned short Signatur1;
} __attribute__((packed));
/* blockdev.c */ /* blockdev.c */