Author: fireball
Date: Thu Oct 15 12:50:12 2009
New Revision: 43477
URL:
http://svn.reactos.org/svn/reactos?rev=43477&view=rev
Log:
[fastfat_new]
- Add a helper function for reading (mapping) volume's stream file object.
- Read a boot sector during volume mounting, unpack it and store values in Vcb->Bpb for
later usage. In particular, a volume's serial number being empty problem is fixed now.
Volume label is still empty.
- Silence more non-important debug prints.
Modified:
trunk/reactos/drivers/filesystems/fastfat_new/fastfat.h
trunk/reactos/drivers/filesystems/fastfat_new/fcb.c
trunk/reactos/drivers/filesystems/fastfat_new/fsctl.c
trunk/reactos/drivers/filesystems/fastfat_new/volume.c
Modified: trunk/reactos/drivers/filesystems/fastfat_new/fastfat.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fastfa…
==============================================================================
--- trunk/reactos/drivers/filesystems/fastfat_new/fastfat.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fastfat_new/fastfat.h [iso-8859-1] Thu Oct 15
12:50:12 2009
@@ -49,6 +49,13 @@
NTSTATUS NTAPI
FatSetVolumeInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+
+VOID NTAPI
+FatReadStreamFile(PVCB Vcb,
+ ULONGLONG ByteOffset,
+ ULONG ByteSize,
+ PBCB *Bcb,
+ PVOID *Buffer);
/* ------------------------------------------------------ blockdev.c */
NTSTATUS
Modified: trunk/reactos/drivers/filesystems/fastfat_new/fcb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fastfa…
==============================================================================
--- trunk/reactos/drivers/filesystems/fastfat_new/fcb.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fastfat_new/fcb.c [iso-8859-1] Thu Oct 15 12:50:12
2009
@@ -502,7 +502,7 @@
RtlDowncaseUnicodeString(UnicodeName, UnicodeName, FALSE);
RtlUpcaseUnicodeString(UnicodeName, UnicodeName, FALSE);
- DPRINT1("Converted long name: %wZ\n", UnicodeName);
+ DPRINT("Converted long name: %wZ\n", UnicodeName);
/* Add the long unicode name link */
FatInsertName(IrpContext, &Fcb->ParentFcb->Dcb.SplayLinksUnicode,
&Fcb->LongName);
@@ -603,7 +603,7 @@
/* Set the length */
OutString->Length = BaseLen + ExtLen;
- DPRINT1("'%s', len %d\n", OutString->Buffer,
OutString->Length);
+ DPRINT("'%s', len %d\n", OutString->Buffer,
OutString->Length);
}
VOID
Modified: trunk/reactos/drivers/filesystems/fastfat_new/fsctl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fastfa…
==============================================================================
--- trunk/reactos/drivers/filesystems/fastfat_new/fsctl.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fastfat_new/fsctl.c [iso-8859-1] Thu Oct 15 12:50:12
2009
@@ -47,6 +47,37 @@
ExReleaseResourceLite(&FatGlobalData.Resource);
}
+VOID
+NTAPI
+FatiUnpackBpb(PBIOS_PARAMETER_BLOCK Bpb, PPACKED_BIOS_PARAMETER_BLOCK PackedBpb)
+{
+ CopyUchar2(&Bpb->BytesPerSector, &PackedBpb->BytesPerSector[0]);
+ CopyUchar1(&Bpb->SectorsPerCluster,
&PackedBpb->SectorsPerCluster[0]);
+ CopyUchar2(&Bpb->ReservedSectors, &PackedBpb->ReservedSectors[0]);
+ CopyUchar1(&Bpb->Fats, &PackedBpb->Fats[0]);
+ CopyUchar2(&Bpb->RootEntries, &PackedBpb->RootEntries[0]);
+ CopyUchar2(&Bpb->Sectors, &PackedBpb->Sectors[0]);
+ CopyUchar1(&Bpb->Media, &PackedBpb->Media[0]);
+ CopyUchar2(&Bpb->SectorsPerFat, &PackedBpb->SectorsPerFat[0]);
+ CopyUchar2(&Bpb->SectorsPerTrack, &PackedBpb->SectorsPerTrack[0]);
+ CopyUchar2(&Bpb->Heads, &PackedBpb->Heads[0]);
+ CopyUchar4(&Bpb->HiddenSectors, &PackedBpb->HiddenSectors[0]);
+ CopyUchar4(&Bpb->LargeSectors, &PackedBpb->LargeSectors[0]);
+ CopyUchar4(&Bpb->LargeSectorsPerFat,
&((PPACKED_BIOS_PARAMETER_BLOCK_EX)PackedBpb)->LargeSectorsPerFat[0]);
+ CopyUchar2(&Bpb->ExtendedFlags,
&((PPACKED_BIOS_PARAMETER_BLOCK_EX)PackedBpb)->ExtendedFlags[0]);
+ CopyUchar2(&Bpb->FsVersion,
&((PPACKED_BIOS_PARAMETER_BLOCK_EX)PackedBpb)->FsVersion[0]);
+
CopyUchar4(&Bpb->RootDirFirstCluster,&((PPACKED_BIOS_PARAMETER_BLOCK_EX)PackedBpb)->RootDirFirstCluster[0]);
+ CopyUchar2(&Bpb->FsInfoSector,
&((PPACKED_BIOS_PARAMETER_BLOCK_EX)PackedBpb)->FsInfoSector[0]);
+ CopyUchar2(&Bpb->BackupBootSector,
&((PPACKED_BIOS_PARAMETER_BLOCK_EX)PackedBpb)->BackupBootSector[0]);
+}
+
+BOOLEAN
+NTAPI
+FatiBpbFat32(PPACKED_BIOS_PARAMETER_BLOCK PackedBpb)
+{
+ return (*(USHORT *)(&PackedBpb->SectorsPerFat) == 0);
+}
+
NTSTATUS
NTAPI
FatMountVolume(PFAT_IRP_CONTEXT IrpContext,
@@ -60,6 +91,8 @@
PVOLUME_DEVICE_OBJECT VolumeDevice;
VCB *Vcb;
FF_ERROR Error;
+ PBCB BootBcb;
+ PPACKED_BOOT_SECTOR BootSector;
DPRINT1("FatMountVolume()\n");
@@ -167,7 +200,46 @@
goto FatMountVolumeCleanup;
}
- // TODO: Read BPB and store it in Vcb->Bpb
+ /* Read the boot sector */
+ FatReadStreamFile(Vcb, 0, sizeof(PACKED_BOOT_SECTOR), &BootBcb,
(PVOID)&BootSector);
+
+ /* Check if it's successful */
+ if (!BootBcb)
+ {
+ Status = STATUS_UNRECOGNIZED_VOLUME;
+ goto FatMountVolumeCleanup;
+ }
+
+ /* Unpack data */
+ FatiUnpackBpb(&Vcb->Bpb, &BootSector->PackedBpb);
+
+ /* Verify if sector size matches */
+ if (DiskGeometry.BytesPerSector != Vcb->Bpb.BytesPerSector)
+ {
+ DPRINT1("Disk geometry BPS %d and bios BPS %d don't match!\n",
+ DiskGeometry.BytesPerSector, Vcb->Bpb.BytesPerSector);
+
+ /* Fail */
+ Status = STATUS_UNRECOGNIZED_VOLUME;
+ goto FatMountVolumeCleanup;
+ }
+
+ /* If Sectors value is set, discard the LargeSectors value */
+ if (Vcb->Bpb.Sectors) Vcb->Bpb.LargeSectors = 0;
+
+ /* Copy serial number */
+ if (FatiBpbFat32(&BootSector->PackedBpb))
+ {
+ CopyUchar4(&Vpb->SerialNumber,
((PPACKED_BOOT_SECTOR_EX)BootSector)->Id);
+ }
+ else
+ {
+ /* This is FAT12/16 */
+ CopyUchar4(&Vpb->SerialNumber, BootSector->Id);
+ }
+
+ /* Unpin the BCB */
+ CcUnpinData(BootBcb);
/* Create root DCB for it */
FatCreateRootDcb(IrpContext, &VolumeDevice->Vcb);
@@ -249,7 +321,7 @@
PFAT_IRP_CONTEXT IrpContext;
BOOLEAN CanWait = TRUE;
- DPRINT1("FatFileSystemControl(DeviceObject %p, Irp %p)\n", DeviceObject,
Irp);
+ DPRINT("FatFileSystemControl(DeviceObject %p, Irp %p)\n", DeviceObject,
Irp);
/* Get CanWait flag */
if (IoGetCurrentIrpStackLocation(Irp)->FileObject)
Modified: trunk/reactos/drivers/filesystems/fastfat_new/volume.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fastfa…
==============================================================================
--- trunk/reactos/drivers/filesystems/fastfat_new/volume.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fastfat_new/volume.c [iso-8859-1] Thu Oct 15
12:50:12 2009
@@ -171,4 +171,27 @@
return STATUS_NOT_IMPLEMENTED;
}
+VOID
+NTAPI
+FatReadStreamFile(PVCB Vcb,
+ ULONGLONG ByteOffset,
+ ULONG ByteSize,
+ PBCB *Bcb,
+ PVOID *Buffer)
+{
+ LARGE_INTEGER Offset;
+
+ Offset.QuadPart = ByteOffset;
+
+ if (!CcMapData(Vcb->StreamFileObject,
+ &Offset,
+ ByteSize,
+ TRUE, // FIXME: CanWait
+ Bcb,
+ Buffer))
+ {
+ ASSERT(FALSE);
+ }
+}
+
/* EOF */