mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
- Check more exactly for a FAT file system.
svn path=/trunk/; revision=9284
This commit is contained in:
parent
a4b7d6a7a5
commit
38ed29a671
2 changed files with 151 additions and 47 deletions
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* 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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -41,57 +41,143 @@
|
|||
static NTSTATUS
|
||||
FsRecIsFatVolume(IN PDEVICE_OBJECT DeviceObject)
|
||||
{
|
||||
DISK_GEOMETRY DiskGeometry;
|
||||
PUCHAR Buffer;
|
||||
ULONG Size;
|
||||
NTSTATUS Status;
|
||||
NTSTATUS Status;
|
||||
PARTITION_INFORMATION PartitionInfo;
|
||||
DISK_GEOMETRY DiskGeometry;
|
||||
ULONG Size;
|
||||
struct _BootSector* Boot;
|
||||
BOOL RecognizedFS = FALSE;
|
||||
Size = sizeof(DISK_GEOMETRY);
|
||||
|
||||
Size = sizeof(DISK_GEOMETRY);
|
||||
Status = FsRecDeviceIoControl(DeviceObject,
|
||||
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
||||
NULL,
|
||||
0,
|
||||
&DiskGeometry,
|
||||
&Size);
|
||||
DPRINT("FsRecDeviceIoControl() Status %lx\n", Status);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
Status = FsRecDeviceIoControl(DeviceObject,
|
||||
IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
||||
NULL,
|
||||
0,
|
||||
&DiskGeometry,
|
||||
&Size);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("FsRecDeviceIoControl faild (%x)\n", 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;
|
||||
}
|
||||
|
||||
if (PartitionInfo.PartitionType)
|
||||
{
|
||||
if (PartitionInfo.PartitionType == PARTITION_FAT_12 ||
|
||||
PartitionInfo.PartitionType == PARTITION_FAT_16 ||
|
||||
PartitionInfo.PartitionType == PARTITION_HUGE ||
|
||||
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;
|
||||
}
|
||||
|
||||
DPRINT("BytesPerSector: %lu\n", DiskGeometry.BytesPerSector);
|
||||
Buffer = ExAllocatePool(NonPagedPool,
|
||||
DiskGeometry.BytesPerSector);
|
||||
if (Buffer == NULL)
|
||||
{
|
||||
return(STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
Boot = ExAllocatePool(NonPagedPool, DiskGeometry.BytesPerSector);
|
||||
if (Boot == NULL)
|
||||
{
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
Status = FsRecReadSectors(DeviceObject,
|
||||
0, /* Partition boot sector */
|
||||
1,
|
||||
DiskGeometry.BytesPerSector,
|
||||
Buffer);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
ExFreePool(Buffer);
|
||||
return(Status);
|
||||
}
|
||||
Status = FsRecReadSectors(DeviceObject,
|
||||
0,
|
||||
1,
|
||||
DiskGeometry.BytesPerSector,
|
||||
(PUCHAR) Boot);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
if (Boot->Signatur1 != 0xaa55)
|
||||
{
|
||||
RecognizedFS=FALSE;
|
||||
}
|
||||
if (RecognizedFS &&
|
||||
Boot->BytesPerSector != 512 &&
|
||||
Boot->BytesPerSector != 1024 &&
|
||||
Boot->BytesPerSector != 2048 &&
|
||||
Boot->BytesPerSector == 4096)
|
||||
{
|
||||
RecognizedFS=FALSE;
|
||||
}
|
||||
|
||||
if ((strncmp(&Buffer[0x36], "FAT12", 5) == 0) ||
|
||||
(strncmp(&Buffer[0x36], "FAT16", 5) == 0) ||
|
||||
(strncmp(&Buffer[0x52], "FAT32", 5) == 0))
|
||||
{
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = STATUS_UNRECOGNIZED_VOLUME;
|
||||
}
|
||||
if (RecognizedFS &&
|
||||
Boot->FATCount != 1 &&
|
||||
Boot->FATCount != 2)
|
||||
{
|
||||
RecognizedFS=FALSE;
|
||||
}
|
||||
|
||||
ExFreePool(Buffer);
|
||||
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;
|
||||
}
|
||||
|
||||
return(Status);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* 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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -40,6 +40,24 @@ typedef struct _DEVICE_EXTENSION
|
|||
ULONG FsType;
|
||||
} 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 */
|
||||
|
||||
|
|
Loading…
Reference in a new issue