/* FUNCTIONS ***************************************************************/
-BOOLEAN
-VFATReadSectors (IN PDEVICE_OBJECT pDeviceObject,
- IN ULONG DiskSector, IN ULONG SectorCount, IN UCHAR * Buffer)
+NTSTATUS
+VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
+ IN ULONG DiskSector,
+ IN ULONG SectorCount,
+ IN OUT PUCHAR Buffer)
{
LARGE_INTEGER sectorNumber;
- PIRP irp;
- IO_STATUS_BLOCK ioStatus;
+ PIRP Irp;
+ IO_STATUS_BLOCK IoStatus;
KEVENT event;
- NTSTATUS status;
+ NTSTATUS Status;
ULONG sectorSize;
sectorNumber.u.LowPart = DiskSector << 9;
KeInitializeEvent (&event, NotificationEvent, FALSE);
sectorSize = BLOCKSIZE * SectorCount;
-
DPRINT ("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
pDeviceObject, DiskSector, Buffer);
DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n",
DPRINT ("Building synchronous FSD Request...\n");
- irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ,
+ Irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ,
pDeviceObject,
Buffer,
sectorSize,
- §orNumber, &event, &ioStatus);
+ §orNumber,
+ &event,
+ &IoStatus);
- if (!irp)
+ if (Irp == NULL)
{
- DbgPrint ("READ failed!!!\n");
- return FALSE;
+ DPRINT("IoBuildSynchronousFsdRequest failed\n");
+ return(STATUS_UNSUCCESSFUL);;
}
- DPRINT ("Calling IO Driver... with irp %x\n", irp);
- status = IoCallDriver (pDeviceObject, irp);
+ DPRINT ("Calling IO Driver... with irp %x\n", Irp);
+ Status = IoCallDriver (pDeviceObject, Irp);
- DPRINT ("Waiting for IO Operation for %x\n", irp);
- if (status == STATUS_PENDING)
+ DPRINT ("Waiting for IO Operation for %x\n", Irp);
+ if (Status == STATUS_PENDING)
{
DPRINT ("Operation pending\n");
KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL);
- DPRINT ("Getting IO Status... for %x\n", irp);
- status = ioStatus.Status;
+ DPRINT ("Getting IO Status... for %x\n", Irp);
+ Status = IoStatus.Status;
}
- if (!NT_SUCCESS (status))
+ if (!NT_SUCCESS (Status))
{
- DbgPrint ("IO failed!!! VFATREadSectors : Error code: %x\n", status);
- DbgPrint
- ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
- pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
- sectorNumber.u.LowPart);
- return FALSE;
+ DPRINT ("IO failed!!! VFATREadSectors : Error code: %x\n", Status);
+ DPRINT ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
+ pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
+ sectorNumber.u.LowPart);
+ return (Status);
}
- DPRINT ("Block request succeeded for %x\n", irp);
- return TRUE;
+ DPRINT ("Block request succeeded for %x\n", Irp);
+ return (STATUS_SUCCESS);
}
-BOOLEAN
-VFATWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
+NTSTATUS
+VfatWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
- IN ULONG SectorCount, IN UCHAR * Buffer)
+ IN ULONG SectorCount,
+ IN PUCHAR Buffer)
{
LARGE_INTEGER sectorNumber;
- PIRP irp;
- IO_STATUS_BLOCK ioStatus;
+ PIRP Irp;
+ IO_STATUS_BLOCK IoStatus;
KEVENT event;
- NTSTATUS status;
+ NTSTATUS Status;
ULONG sectorSize;
DPRINT ("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
sectorSize = BLOCKSIZE * SectorCount;
DPRINT ("Building synchronous FSD Request...\n");
- irp = IoBuildSynchronousFsdRequest (IRP_MJ_WRITE,
+ Irp = IoBuildSynchronousFsdRequest (IRP_MJ_WRITE,
pDeviceObject,
Buffer,
sectorSize,
- §orNumber, &event, &ioStatus);
+ §orNumber,
+ &event,
+ &IoStatus);
- if (!irp)
+ if (!Irp)
{
- DbgPrint ("WRITE failed!!!\n");
- return FALSE;
+ DPRINT ("WRITE failed!!!\n");
+ return (STATUS_UNSUCCESSFUL);
}
DPRINT ("Calling IO Driver...\n");
- status = IoCallDriver (pDeviceObject, irp);
+ Status = IoCallDriver (pDeviceObject, Irp);
DPRINT ("Waiting for IO Operation...\n");
- if (status == STATUS_PENDING)
+ if (Status == STATUS_PENDING)
{
KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL);
DPRINT ("Getting IO Status...\n");
- status = ioStatus.Status;
+ Status = IoStatus.Status;
}
- if (!NT_SUCCESS (status))
+ if (!NT_SUCCESS (Status))
{
- DbgPrint ("IO failed!!! VFATWriteSectors : Error code: %x\n", status);
- return FALSE;
+ DPRINT ("IO failed!!! VFATWriteSectors : Error code: %x\n", Status);
+ return (Status);
}
DPRINT ("Block request succeeded\n");
- return TRUE;
+ return (STATUS_SUCCESS);
}
-/* $Id: create.c,v 1.11 2001/01/01 04:42:11 dwelch Exp $
+/* $Id: create.c,v 1.12 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
Offset = 0;
StartingSector++; //FIXME : nor always the next sector
jloop++;
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
StartingSector, 1, Block);
test2 = (slot *) Block;
}
DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i);
for (j = 0; j < Size; j++)
{
- VFATReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block);
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block);
for (i = 0; i < ENTRIES_PER_SECTOR; i++)
{
DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i);
for (j = 0; j < Size; j++)
{
- VFATReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block);
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice, StartingSector, 1, block);
for (i = (Entry) ? (*Entry) : 0; i < ENTRIES_PER_SECTOR; i++)
{
/* entry is in next sector */
StartingSector++;
/* FIXME : treat case of next sector fragmented */
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
StartingSector, 1, block);
i = 0;
}
ParentFcb = Temp;
}
-
+ FileObject->Flags = FileObject->Flags |
+ FO_FCB_IS_VALID | FO_DIRECT_CACHE_PAGING_READ;
FileObject->FsContext = (PVOID)&ParentFcb->RFCB;
newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
memset (newCCB, 0, sizeof (VFATCCB));
/*
- * $Id: fat.c,v 1.9 2000/12/29 23:17:12 dwelch Exp $
+ * $Id: fat.c,v 1.10 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
Block = ExAllocatePool (NonPagedPool, 1024);
FATsector = CurrentCluster / (512 / sizeof (ULONG));
FATeis = CurrentCluster - (FATsector * (512 / sizeof (ULONG)));
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + FATsector), 1,
(UCHAR *) Block);
CurrentCluster = Block[FATeis];
*/
{
PUSHORT Block;
- Block = (PUSHORT) DeviceExt->FAT;
- CurrentCluster = Block[CurrentCluster];
+ PVOID BaseAddress;
+ BOOLEAN Valid;
+ PCACHE_SEGMENT CacheSeg;
+ NTSTATUS Status;
+ ULONG FATOffset;
+
+ FATOffset = (DeviceExt->FATStart * BLOCKSIZE) + (CurrentCluster * 2);
+
+ Status = CcRequestCacheSegment(DeviceExt->StorageBcb,
+ PAGE_ROUND_DOWN(FATOffset),
+ &BaseAddress,
+ &Valid,
+ &CacheSeg);
+ if (!Valid)
+ {
+ Status = VfatReadSectors(DeviceExt->StorageDevice,
+ PAGE_ROUND_DOWN(FATOffset) / BLOCKSIZE,
+ PAGESIZE / BLOCKSIZE,
+ BaseAddress);
+ if (!NT_SUCCESS(Status))
+ {
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
+ return(0xFFFFFFFF);
+ }
+ }
+
+ CurrentCluster = *((PUSHORT)(BaseAddress + (FATOffset % PAGESIZE)));
if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
- CurrentCluster = 0xffffffff;
- DPRINT ("Returning %x\n", CurrentCluster);
+ CurrentCluster = 0xffffffff;
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
return (CurrentCluster);
}
unsigned char *CBlock;
ULONG FATOffset;
ULONG Entry;
- CBlock = DeviceExt->FAT;
- FATOffset = (CurrentCluster * 12) / 8; //first byte containing value
+ PVOID PBlock;
+ NTSTATUS Status;
+ PVOID BaseAddress;
+ BOOLEAN Valid;
+ PCACHE_SEGMENT CacheSeg;
+ UCHAR Value1, Value2;
+
+ FATOffset = (DeviceExt->FATStart * BLOCKSIZE) + ((CurrentCluster * 12) / 8);
+
+ /*
+ * Get the page containing this offset
+ */
+ Status = CcRequestCacheSegment(DeviceExt->StorageBcb,
+ PAGE_ROUND_DOWN(FATOffset),
+ &BaseAddress,
+ &Valid,
+ &CacheSeg);
+ if (!Valid)
+ {
+ Status = VfatReadSectors(DeviceExt->StorageDevice,
+ PAGE_ROUND_DOWN(FATOffset) / BLOCKSIZE,
+ PAGESIZE / BLOCKSIZE,
+ BaseAddress);
+ if (!NT_SUCCESS(Status))
+ {
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
+ return(0xFFFFFFFF);
+ }
+ }
+ Value1 = ((PUCHAR)BaseAddress)[FATOffset % PAGESIZE];
+
+ /*
+ * A FAT12 entry may straggle two sectors
+ */
+ if ((FATOffset + 1) == PAGESIZE)
+ {
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
+ Status = CcRequestCacheSegment(DeviceExt->StorageBcb,
+ PAGE_ROUND_DOWN(FATOffset) + PAGESIZE,
+ &BaseAddress,
+ &Valid,
+ &CacheSeg);
+ if (!Valid)
+ {
+ ULONG NextOffset;
+
+ NextOffset = (PAGE_ROUND_DOWN(FATOffset) + PAGESIZE) / BLOCKSIZE;
+ Status =
+ VfatReadSectors(DeviceExt->StorageDevice,
+ NextOffset,
+ PAGESIZE / BLOCKSIZE,
+ BaseAddress);
+ if (!NT_SUCCESS(Status))
+ {
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
+ return(0xFFFFFFFF);
+ }
+ }
+ Value2 = ((PUCHAR)BaseAddress)[0];
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
+ }
+ else
+ {
+ Value2 = ((PUCHAR)BaseAddress)[(FATOffset % PAGESIZE) + 1];
+ CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
+ }
+
if ((CurrentCluster % 2) == 0)
{
- Entry = CBlock[FATOffset];
- Entry |= ((CBlock[FATOffset + 1] & 0xf) << 8);
+ Entry = Value1;
+ Entry |= ((Value2 & 0xf) << 8);
}
else
{
- Entry = (CBlock[FATOffset] >> 4);
- Entry |= (CBlock[FATOffset + 1] << 4);
+ Entry = (Value1 >> 4);
+ Entry |= (Value2 << 4);
}
DPRINT ("Entry %x\n", Entry);
if (Entry >= 0xff8 && Entry <= 0xfff)
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + sector), 1,
(UCHAR *) Block);
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + sector), 1,
(UCHAR *) Block);
{
if ((FATOffset % BLOCKSIZE) == (BLOCKSIZE - 1)) //entry is on 2 sectors
{
- VFATWriteSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatWriteSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector
+ i * DeviceExt->Boot->FATSectors,
2, CBlock + FATsector * 512);
}
else
{
- VFATWriteSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatWriteSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector
+ i * DeviceExt->Boot->FATSectors,
1, CBlock + FATsector * 512);
Start = DeviceExt->FATStart + FATsector;
for (i = 0; i < DeviceExt->Boot->FATCount; i++)
{
- VFATWriteSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatWriteSectors (DeviceExt->StorageDevice,
Start, 1, ((UCHAR *) Block) + FATsector * 512);
Start += DeviceExt->Boot->FATSectors;
}
FATsector = ClusterToWrite / 128;
FATeis = ClusterToWrite - (FATsector * 128);
/* load sector, change value, then rewrite sector */
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector, 1, (UCHAR *) Block);
Block[FATeis] = NewValue;
/* Write the changed FAT sector to disk (all FAT's) */
pBoot = (struct _BootSector32 *) DeviceExt->Boot;
for (i = 0; i < pBoot->FATCount; i++)
{
- VFATWriteSectors (DeviceExt->StorageDevice, Start, 1, (UCHAR *) Block);
+ /* FIXME: Check status */
+ VfatWriteSectors (DeviceExt->StorageDevice, Start, 1, (UCHAR *) Block);
Start += pBoot->FATSectors;
}
ExFreePool (Block);
Sector = ClusterToSector (DeviceExt, Cluster);
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
DPRINT ("Finished VFATReadSectors\n");
}
Sector = ClusterToSector (DeviceExt, Cluster);
- VFATWriteSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatWriteSectors (DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
}
-/* $Id: iface.c,v 1.46 2001/01/01 04:42:11 dwelch Exp $
+/* $Id: iface.c,v 1.47 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
Boot = ExAllocatePool (NonPagedPool, 512);
- VFATReadSectors (DeviceToMount, 0, 1, (UCHAR *) Boot);
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceToMount, 0, 1, (UCHAR *) Boot);
DPRINT ("Boot->SysType %.5s\n", Boot->SysType);
if (strncmp (Boot->SysType, "FAT12", 5) == 0 ||
DPRINT ("DeviceExt %x\n", DeviceExt);
DeviceExt->Boot = ExAllocatePool (NonPagedPool, 512);
- VFATReadSectors (DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
-
- DPRINT ("DeviceExt->Boot->BytesPerSector %x\n",
- DeviceExt->Boot->BytesPerSector);
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
DeviceExt->rootDirectorySectors =
if (strncmp (DeviceExt->Boot->SysType, "FAT12", 5) == 0)
{
+ DbgPrint("FAT12\n");
DeviceExt->FatType = FAT12;
}
else
(((struct _BootSector32 *) (DeviceExt->Boot))->SysType, "FAT32",
5) == 0)
{
+ DbgPrint("FAT32\n");
DeviceExt->FatType = FAT32;
DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster;
DeviceExt->rootStart =
}
else
{
+ DbgPrint("FAT16\n");
DeviceExt->FatType = FAT16;
}
DeviceExt->FAT =
ExAllocatePool (NonPagedPool,
BLOCKSIZE * DeviceExt->Boot->FATSectors);
- VFATReadSectors (DeviceToMount, DeviceExt->FATStart,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceToMount, DeviceExt->FATStart,
DeviceExt->Boot->FATSectors, (UCHAR *) DeviceExt->FAT);
}
return STATUS_SUCCESS;
{
PDEVICE_OBJECT DeviceObject;
PDEVICE_EXTENSION DeviceExt;
+ NTSTATUS Status;
IoCreateDevice (VfatDriverObject,
sizeof (DEVICE_EXTENSION),
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack (DeviceObject,
DeviceToMount);
+ DeviceExt->StreamStorageDevice =
+ IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice);
+ Status = CcInitializeFileCache(DeviceExt->StreamStorageDevice,
+ &DeviceExt->StorageBcb,
+ PAGESIZE);
ExInitializeResourceLite (&DeviceExt->DirResource);
ExInitializeResourceLite (&DeviceExt->FatResource);
-/* $Id: rw.c,v 1.13 2001/01/01 04:42:12 dwelch Exp $
+/* $Id: rw.c,v 1.14 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* FUNCTIONS *****************************************************************/
+VOID
+NextCluster(PDEVICE_EXTENSION DeviceExt,
+ ULONG FirstCluster,
+ PULONG CurrentCluster)
+{
+ DPRINT("NextCluster() (*CurrentCluster) 0x%x\n", (*CurrentCluster));
+ if (FirstCluster == 1)
+ {
+ (*CurrentCluster) += DeviceExt->Boot->SectorsPerCluster;
+ }
+ else
+ {
+ (*CurrentCluster) = GetNextCluster(DeviceExt, (*CurrentCluster));
+ }
+ DPRINT("NextCluster() finished (*CurrentCluster) 0x%x\n",
+ (*CurrentCluster));
+}
+
ULONG
OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster,
{
ULONG CurrentCluster;
ULONG i;
+
+ DPRINT("OffsetToCluster(FirstCluster 0x%x)\n", FirstCluster);
CurrentCluster = FirstCluster;
if (FirstCluster == 1)
CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster);
}
}
+ DPRINT("OffsetToCluster() = 0x%x\n", CurrentCluster);
return(CurrentCluster);
}
{
if (FirstCluster == 1)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp);
CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
{
if (FirstCluster == 1)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Buffer);
CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
(*LengthRead) = (*LengthRead) + Length;
if (FirstCluster == 1)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp);
CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
PULONG CurrentCluster,
PVOID Destination)
{
+ DPRINT("VfatRawReadCluster() *CurrentCluster 0x%x\n", *CurrentCluster);
if (FirstCluster == 1)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
(*CurrentCluster),
DeviceExt->Boot->SectorsPerCluster,
Destination);
VFATLoadCluster (DeviceExt, Destination, (*CurrentCluster));
(*CurrentCluster) = GetNextCluster (DeviceExt, (*CurrentCluster));
}
+ DPRINT("VfatRawReadCluster() finished *CurrentCluster 0x%x\n",
+ *CurrentCluster);
return(STATUS_SUCCESS);
}
ULONG i;
ULONG ReadOffset;
ULONG InternalOffset;
-
- ReadOffset = ROUND_DOWN(StartOffset, PAGESIZE);
- InternalOffset = StartOffset % PAGESIZE;
+
+ /*
+ * Otherwise we read a page of clusters together
+ */
Status = CcRequestCacheSegment(Fcb->RFCB.Bcb,
ReadOffset,
&BaseAddress,
}
/*
- * If necessary read all the data for the page
+ * If necessary read all the data for the page, unfortunately the
+ * file length may not be page aligned in which case the page will
+ * only be partially filled.
+ * FIXME: So zero fill the rest?
*/
if (!Valid)
{
- ULONG StartCluster;
-
- StartCluster = OffsetToCluster(DeviceExt, FirstCluster, ReadOffset);
-
for (i = 0; i < (PAGESIZE / BytesPerCluster); i++)
{
Status = VfatRawReadCluster(DeviceExt,
FirstCluster,
- &StartCluster,
+ CurrentCluster,
BaseAddress + (i * BytesPerCluster));
if (!NT_SUCCESS(Status))
{
CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, FALSE);
return(Status);
}
+ if (CurrentCluster == 0xFFFFFFFF)
+ {
+ break;
+ }
}
}
- /*
- * Go on to the next cluster
- */
- if (FirstCluster == 1)
- {
- (*CurrentCluster) += DeviceExt->Boot->SectorsPerCluster;
- }
else
{
- (*CurrentCluster) = GetNextCluster(DeviceExt, (*CurrentCluster));
+ /*
+ * Otherwise just move onto the next cluster
+ */
+ for (i = 0; i < (PAGESIZE / DeviceExt->BytesPerCluster); i++)
+ {
+ NextCluster(DeviceExt, FirstCluster, CurrentCluster);
+ if (CurrentCluster == 0xFFFFFFFF)
+ {
+ break;
+ }
+ }
}
/*
* Copy the data from the cache to the caller
PVFATFCB Fcb;
PVOID Temp;
ULONG TempLength;
+ ULONG ChunkSize;
/* PRECONDITION */
assert (DeviceExt != NULL);
assert (FileObject->FsContext != NULL);
DPRINT ("FsdReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
- "Length %d, ReadOffset %d)\n", DeviceExt, FileObject, Buffer,
+ "Length %d, ReadOffset 0x%x)\n", DeviceExt, FileObject, Buffer,
Length, ReadOffset);
Fcb = ((PVFATCCB)FileObject->FsContext2)->pFcb;
}
}
+
+ ChunkSize = max(DeviceExt->BytesPerCluster, PAGESIZE);
*LengthRead = 0;
/*
* Allocate a buffer to hold partial clusters
*/
- Temp = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
+ Temp = ExAllocatePool (NonPagedPool, ChunkSize);
if (!Temp)
return STATUS_UNSUCCESSFUL;
* If the read doesn't begin on a cluster boundary then read a full
* cluster and copy it.
*/
- if ((ReadOffset % DeviceExt->BytesPerCluster) != 0)
+ if ((ReadOffset % ChunkSize) != 0)
{
VfatReadCluster(DeviceExt, Fcb,
- ROUND_DOWN(ReadOffset, DeviceExt->BytesPerCluster),
+ ROUND_DOWN(ReadOffset, ChunkSize),
FirstCluster, &CurrentCluster, Temp, 1);
- TempLength = min (Length, DeviceExt->BytesPerCluster -
- (ReadOffset % DeviceExt->BytesPerCluster));
+ TempLength = min (Length, ChunkSize - (ReadOffset % ChunkSize));
- memcpy (Buffer, Temp + ReadOffset % DeviceExt->BytesPerCluster,
- TempLength);
+ memcpy (Buffer, Temp + ReadOffset % ChunkSize, TempLength);
(*LengthRead) = (*LengthRead) + TempLength;
Length = Length - TempLength;
ReadOffset = ReadOffset + TempLength;
}
- while (Length >= DeviceExt->BytesPerCluster)
+ while (Length >= ChunkSize)
{
VfatReadCluster(DeviceExt, Fcb, ReadOffset,
FirstCluster, &CurrentCluster, Buffer, 1);
return (STATUS_SUCCESS);
}
- (*LengthRead) = (*LengthRead) + DeviceExt->BytesPerCluster;
- Buffer = Buffer + DeviceExt->BytesPerCluster;
- Length = Length - DeviceExt->BytesPerCluster;
- ReadOffset = ReadOffset + DeviceExt->BytesPerCluster;
+ (*LengthRead) = (*LengthRead) + ChunkSize;
+ Buffer = Buffer + ChunkSize;
+ Length = Length - ChunkSize;
+ ReadOffset = ReadOffset + ChunkSize;
}
if (Length > 0)
/* Read in the existing cluster data */
if (FirstCluster == 1)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp);
}
/* Read in the existing cluster data */
if (FirstCluster == 1)
{
- VFATReadSectors (DeviceExt->StorageDevice,
+ /* FIXME: Check status */
+ VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp);
}
-/* $Id: vfat.h,v 1.19 2000/12/29 23:17:12 dwelch Exp $ */
+/* $Id: vfat.h,v 1.20 2001/01/08 02:14:06 dwelch Exp $ */
#include <ddk/ntifs.h>
typedef struct
{
- ERESOURCE DirResource;
- ERESOURCE FatResource;
-
- KSPIN_LOCK FcbListLock;
- LIST_ENTRY FcbListHead;
-
- PDEVICE_OBJECT StorageDevice;
- BootSector *Boot;
- int rootDirectorySectors, FATStart, rootStart, dataStart;
- int FATEntriesPerSector, FATUnit;
- ULONG BytesPerCluster;
- ULONG FatType;
- unsigned char* FAT;
+ ERESOURCE DirResource;
+ ERESOURCE FatResource;
+
+ KSPIN_LOCK FcbListLock;
+ LIST_ENTRY FcbListHead;
+
+ PDEVICE_OBJECT StorageDevice;
+ PFILE_OBJECT StreamStorageDevice;
+ PBCB StorageBcb;
+ BootSector *Boot;
+ int rootDirectorySectors, FATStart, rootStart, dataStart;
+ int FATEntriesPerSector, FATUnit;
+ ULONG BytesPerCluster;
+ ULONG FatType;
+ unsigned char* FAT;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
typedef struct _VFATFCB
#define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
-
typedef struct __DOSTIME
{
WORD Second:5;
/* internal functions in blockdev.c */
-BOOLEAN
-VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
+NTSTATUS
+VfatReadSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN ULONG SectorCount,
IN UCHAR* Buffer);
-BOOLEAN
-VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
+NTSTATUS
+VfatWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN ULONG SectorCount,
IN UCHAR* Buffer);
-/* $Id: iotypes.h,v 1.21 2000/12/29 23:17:11 dwelch Exp $
+/* $Id: iotypes.h,v 1.22 2001/01/08 02:14:05 dwelch Exp $
*
*/
#define FO_HANDLE_CREATED 0x00040000
#define FO_FILE_FAST_IO_READ 0x00080000
+/*
+ * ReactOS specific flags
+ */
#define FO_DIRECT_CACHE_READ 0x72000001
#define FO_DIRECT_CACHE_WRITE 0x72000002
#define FO_DIRECT_CACHE_PAGING_READ 0x72000004
#define FO_DIRECT_CACHE_PAGING_WRITE 0x72000008
+#define FO_FCB_IS_VALID 0x72000010
typedef struct _FILE_OBJECT
{
-/* $Id: ntddk.h,v 1.16 2000/08/27 22:35:22 ekohl Exp $
+/* $Id: ntddk.h,v 1.17 2001/01/08 02:14:05 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#ifndef FASTCALL
#define FASTCALL STDCALL
#endif
+#define STATIC static
#include <ntos/types.h>
#include <ntos/disk.h>
#define BUTTON 0x80
#define EDIT 0x81
-#define STATIC 0x82
+//#define STATIC 0x82
#define LISTBOX 0x83
#define SCROLLBAR 0x84
#define COMBOBOX 0x85
struct _EPROCESS;
typedef ULONG SWAPENTRY;
-enum
-{
- MEMORY_AREA_INVALID,
- MEMORY_AREA_SECTION_VIEW_COMMIT,
- MEMORY_AREA_CONTINUOUS_MEMORY,
- MEMORY_AREA_NO_CACHE,
- MEMORY_AREA_IO_MAPPING,
- MEMORY_AREA_SYSTEM,
- MEMORY_AREA_MDL_MAPPING,
- MEMORY_AREA_VIRTUAL_MEMORY,
- MEMORY_AREA_SECTION_VIEW_RESERVE,
- MEMORY_AREA_CACHE_SEGMENT,
- MEMORY_AREA_SHARED_DATA,
-};
+#define MEMORY_AREA_INVALID (0)
+#define MEMORY_AREA_SECTION_VIEW_COMMIT (1)
+#define MEMORY_AREA_CONTINUOUS_MEMORY (2)
+#define MEMORY_AREA_NO_CACHE (3)
+#define MEMORY_AREA_IO_MAPPING (4)
+#define MEMORY_AREA_SYSTEM (5)
+#define MEMORY_AREA_MDL_MAPPING (7)
+#define MEMORY_AREA_VIRTUAL_MEMORY (8)
+#define MEMORY_AREA_SECTION_VIEW_RESERVE (9)
+#define MEMORY_AREA_CACHE_SEGMENT (10)
+#define MEMORY_AREA_SHARED_DATA (11)
+
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
((x) / (4*1024*1024))
#define SPE_DIRTY (0x8)
#define SPE_IN_PAGEFILE (0x10)
+/*
+ * Flags for section objects
+ */
#define SO_PHYSICAL_MEMORY (0x1)
+/*
+ * Additional flags for protection attributes
+ */
+#define PAGE_WRITETHROUGH (1024)
+#define PAGE_SYSTEM (2048)
+#define PAGE_FLAGS_VALID_FROM_USER_MODE (PAGE_READONLY | \
+ PAGE_READWRITE | \
+ PAGE_WRITECOPY | \
+ PAGE_EXECUTE | \
+ PAGE_EXECUTE_READ | \
+ PAGE_EXECUTE_READWRITE | \
+ PAGE_EXECUTE_WRITECOPY | \
+ PAGE_GUARD | \
+ PAGE_NOACCESS | \
+ PAGE_NOCACHE)
+
typedef struct
{
ULONG Pages[NR_SECTION_PAGE_ENTRIES];
NTSTATUS MmInitPagerThread(VOID);
VOID MmInitKernelMap(PVOID BaseAddress);
-unsigned int alloc_pool_region(unsigned int nr_pages);
VOID MmWaitForFreePages(VOID);
PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry);
-/* $Id: create.c,v 1.34 2000/12/23 02:37:39 dwelch Exp $
+/* $Id: create.c,v 1.35 2001/01/08 02:14:05 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
IoCreateStreamFileObject (PFILE_OBJECT FileObject,
PDEVICE_OBJECT DeviceObject)
{
- HANDLE FileHandle;
- PFILE_OBJECT CreatedFileObject;
+ HANDLE FileHandle;
+ PFILE_OBJECT CreatedFileObject;
+
+ DbgPrint("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n",
+ FileObject, DeviceObject);
- DbgPrint("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n",
- FileObject,
- DeviceObject
- );
-
- assert_irql (PASSIVE_LEVEL);
-
- CreatedFileObject = ObCreateObject (
- & FileHandle,
- STANDARD_RIGHTS_REQUIRED,
- NULL,
- IoFileObjectType
- );
- if (NULL == CreatedFileObject)
- {
- return (NULL);
- }
-
- if (FileObject != NULL)
- {
- DeviceObject = FileObject->DeviceObject;
- }
- DeviceObject = IoGetAttachedDevice(DeviceObject);
- CreatedFileObject->DeviceObject = DeviceObject;
- CreatedFileObject->Vpb = DeviceObject->Vpb;
- CreatedFileObject->Type = InternalFileType;
- //CreatedFileObject->Flags = CreatedFileObject->Flags | FO_DIRECT_DEVICE_OPEN;
- CreatedFileObject->Flags |= FO_DIRECT_DEVICE_OPEN;
-
- ZwClose (FileHandle);
-
- return (CreatedFileObject);
+ assert_irql (PASSIVE_LEVEL);
+
+ CreatedFileObject = ObCreateObject (&FileHandle,
+ STANDARD_RIGHTS_REQUIRED,
+ NULL,
+ IoFileObjectType);
+ if (NULL == CreatedFileObject)
+ {
+ return (NULL);
+ }
+
+ if (FileObject != NULL)
+ {
+ DeviceObject = FileObject->DeviceObject;
+ }
+ DeviceObject = IoGetAttachedDevice(DeviceObject);
+ CreatedFileObject->DeviceObject = DeviceObject;
+ CreatedFileObject->Vpb = DeviceObject->Vpb;
+ CreatedFileObject->Type = InternalFileType;
+ CreatedFileObject->Flags |= FO_DIRECT_DEVICE_OPEN;
+
+ ZwClose (FileHandle);
+
+ return (CreatedFileObject);
}
-/* $Id: page.c,v 1.9 2000/07/07 10:30:55 dwelch Exp $
+/* $Id: page.c,v 1.10 2001/01/08 02:14:05 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
DPRINT("Before IoCallDriver\n");
Status = IoCallDriver(FileObject->DeviceObject,Irp);
DPRINT("Status %d STATUS_PENDING %d\n",Status,STATUS_PENDING);
- if (Status==STATUS_PENDING && (FileObject->Flags & FO_SYNCHRONOUS_IO))
+ if (Status == STATUS_PENDING && (FileObject->Flags & FO_SYNCHRONOUS_IO))
{
DPRINT("Waiting for io operation\n");
if (FileObject->Flags & FO_ALERTABLE_IO)
/*
* retrieve ntdll's startup address
- */
+ */
RtlInitAnsiString (&ProcedureName,
"LdrInitializeThunk");
+ DPRINT1("Getting address of system DLL entrypoint\n");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
ZwClose(NTDllSectionHandle);
return (Status);
}
- DPRINT("SystemDllEntryPoint 0x%08lx\n",
+ DPRINT1("SystemDllEntryPoint 0x%08lx\n",
SystemDllEntryPoint);
*LdrStartupAddr = SystemDllEntryPoint;
-/* $Id: aspace.c,v 1.4 2000/08/20 17:02:08 dwelch Exp $
+/* $Id: aspace.c,v 1.5 2001/01/08 02:14:05 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* GLOBALS ******************************************************************/
-static MADDRESS_SPACE KernelAddressSpace;
+STATIC MADDRESS_SPACE KernelAddressSpace;
/* FUNCTIONS *****************************************************************/
-VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
+VOID
+MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
{
(VOID)KeWaitForMutexObject(&AddressSpace->Lock,
0,
NULL);
}
-VOID MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
+VOID
+MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
{
KeReleaseMutex(&AddressSpace->Lock, FALSE);
}
-VOID MmInitializeKernelAddressSpace(VOID)
+VOID
+MmInitializeKernelAddressSpace(VOID)
{
MmInitializeAddressSpace(NULL, &KernelAddressSpace);
}
return(&KernelAddressSpace);
}
-NTSTATUS MmInitializeAddressSpace(PEPROCESS Process,
- PMADDRESS_SPACE AddressSpace)
+NTSTATUS
+MmInitializeAddressSpace(PEPROCESS Process,
+ PMADDRESS_SPACE AddressSpace)
{
InitializeListHead(&AddressSpace->MAreaListHead);
KeInitializeMutex(&AddressSpace->Lock, 1);
return(STATUS_SUCCESS);
}
-NTSTATUS MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
+NTSTATUS
+MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
{
return(STATUS_SUCCESS);
}
-/* $Id: cont.c,v 1.5 2000/12/29 23:17:12 dwelch Exp $
+/* $Id: cont.c,v 1.6 2001/01/08 02:14:05 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
PBase = MmGetContinuousPages(NumberOfBytes,
HighestAcceptableAddress);
+ if (PBase == NULL)
+ {
+ MmFreeMemoryArea(MmGetKernelAddressSpace(),
+ BaseAddress,
+ 0,
+ TRUE);
+ return(NULL);
+ }
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
{
MmCreateVirtualMapping(NULL,
BaseAddress + (i * 4096),
- PAGE_EXECUTE_READWRITE,
+ PAGE_EXECUTE_READWRITE | PAGE_SYSTEM,
(ULONG)(PBase + (i * 4096)));
}
return(BaseAddress);
}
-PVOID MmAllocPage(SWAPENTRY SavedSwapEntry)
+PVOID
+MmAllocPage(SWAPENTRY SavedSwapEntry)
{
ULONG offset;
PLIST_ENTRY ListEntry;
return((PVOID)offset);
}
-PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry)
+PVOID
+MmMustAllocPage(SWAPENTRY SavedSwapEntry)
{
PVOID Page;
return(Page);
}
-PVOID MmAllocPageMaybeSwap(SWAPENTRY SavedSwapEntry)
+PVOID
+MmAllocPageMaybeSwap(SWAPENTRY SavedSwapEntry)
{
PVOID Page;
return(Page);
}
-NTSTATUS MmWaitForPage(PVOID PhysicalAddress)
+NTSTATUS
+MmWaitForPage(PVOID PhysicalAddress)
{
NTSTATUS Status;
ULONG Start;
return(Status);
}
-VOID MmClearWaitPage(PVOID PhysicalAddress)
+VOID
+MmClearWaitPage(PVOID PhysicalAddress)
{
ULONG Start;
KeClearEvent(&MmPageArray[Start].Event);
}
-VOID MmSetWaitPage(PVOID PhysicalAddress)
+VOID
+MmSetWaitPage(PVOID PhysicalAddress)
{
ULONG Start;
-/* $Id: page.c,v 1.16 2000/10/22 16:36:52 ekohl Exp $
+/* $Id: page.c,v 1.17 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
#define PA_BIT_PRESENT (0)
#define PA_BIT_READWRITE (1)
#define PA_BIT_USER (2)
+#define PA_BIT_WT (3)
+#define PA_BIT_CD (4)
+#define PA_BIT_ACCESSED (5)
#define PA_BIT_DIRTY (6)
-#define PA_PRESENT (1<<PA_BIT_PRESENT)
-#define PA_DIRTY (1<<PA_BIT_DIRTY)
+#define PA_PRESENT (1 << PA_BIT_PRESENT)
+#define PA_DIRTY (1 << PA_BIT_DIRTY)
+#define PA_WT (1 << PA_BIT_WT)
+#define PA_CD (1 << PA_BIT_CD)
#define PAGETABLE_MAP (0xf0000000)
#define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024)))
/* FUNCTIONS ***************************************************************/
-PULONG MmGetPageDirectory(void)
+PULONG
+MmGetPageDirectory(VOID)
{
unsigned int page_dir=0;
__asm__("movl %%cr3,%0\n\t"
return((PULONG)page_dir);
}
-static ULONG ProtectToPTE(ULONG flProtect)
+static ULONG
+ProtectToPTE(ULONG flProtect)
{
- ULONG Attributes = 0;
-
- if (flProtect & PAGE_NOACCESS || flProtect & PAGE_GUARD)
- {
- Attributes = 0;
- }
+ ULONG Attributes = 0;
+
+ if (flProtect & PAGE_NOACCESS || flProtect & PAGE_GUARD)
+ {
+ Attributes = 0;
+ }
if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE)
{
- Attributes = PA_WRITE | PA_USER;
+ Attributes = PA_WRITE;
}
if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE ||
flProtect & PAGE_EXECUTE_READ)
{
- Attributes = PA_READ | PA_USER;
- }
+ Attributes = PA_READ;
+ }
+ if (!(flProtect & PAGE_SYSTEM))
+ {
+ Attributes = Attributes | PA_USER;
+ }
+ if (!(flProtect & PAGE_NOCACHE))
+ {
+ Attributes = Attributes | PA_CD;
+ }
+ if (!(flProtect & PAGE_WRITETHROUGH))
+ {
+ Attributes = Attributes | PA_WT;
+ }
return(Attributes);
}
return(STATUS_SUCCESS);
}
-VOID MmSetPageProtect(PEPROCESS Process,
- PVOID Address,
- ULONG flProtect)
+VOID
+MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
{
ULONG Attributes = 0;
PULONG PageEntry;
}
}
-PHYSICAL_ADDRESS STDCALL MmGetPhysicalAddress(PVOID vaddr)
+PHYSICAL_ADDRESS STDCALL
+MmGetPhysicalAddress(PVOID vaddr)
/*
* FUNCTION: Returns the physical address corresponding to a virtual address
*/
-/* $Id: iospace.c,v 1.6 2000/08/20 17:02:08 dwelch Exp $
+/* $Id: iospace.c,v 1.7 2001/01/08 02:14:05 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* REVISIONS
*
*/
-PVOID STDCALL MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
- IN ULONG NumberOfBytes,
- IN BOOLEAN CacheEnable)
+PVOID STDCALL
+MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
+ IN ULONG NumberOfBytes,
+ IN BOOLEAN CacheEnable)
{
PVOID Result;
MEMORY_AREA* marea;
{
return (NULL);
}
- Attributes = PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM;
+ Attributes = PAGE_EXECUTE_READWRITE | PAGE_SYSTEM;
if (!CacheEnable)
{
- Attributes |= (PA_PWT | PA_PCD);
+ Attributes |= (PAGE_NOCACHE | PAGE_WRITETHROUGH);
}
for (i = 0; (i <= (NumberOfBytes / PAGESIZE)); i++)
{
- Status = MmCreateVirtualMapping (NULL,
- (Result + (i * PAGESIZE)),
- PAGE_READWRITE,
- (PhysicalAddress.u.LowPart + (i * PAGESIZE)));
+ Status =
+ MmCreateVirtualMapping (NULL,
+ (Result + (i * PAGESIZE)),
+ Attributes,
+ PhysicalAddress.u.LowPart + (i * PAGESIZE));
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
* NAME EXPORTED
* MmMapVideoDisplay@16
*/
-PVOID
-STDCALL
-MmMapVideoDisplay (
- IN PHYSICAL_ADDRESS PhysicalAddress,
- IN ULONG NumberOfBytes,
- IN MEMORY_CACHING_TYPE CacheType
- )
+PVOID STDCALL
+MmMapVideoDisplay (IN PHYSICAL_ADDRESS PhysicalAddress,
+ IN ULONG NumberOfBytes,
+ IN MEMORY_CACHING_TYPE CacheType)
{
- return MmMapIoSpace (
- PhysicalAddress,
- NumberOfBytes,
- CacheType
- );
+ return MmMapIoSpace (PhysicalAddress, NumberOfBytes, CacheType);
}
-VOID
-STDCALL
-MmUnmapVideoDisplay (
- IN PVOID BaseAddress,
- IN ULONG NumberOfBytes
- )
+VOID STDCALL
+MmUnmapVideoDisplay (IN PVOID BaseAddress,
+ IN ULONG NumberOfBytes)
{
- MmUnmapIoSpace (
- BaseAddress,
- NumberOfBytes
- );
+ MmUnmapIoSpace (BaseAddress, NumberOfBytes);
}
-/* $Id: kmap.c,v 1.4 2000/10/22 16:36:51 ekohl Exp $
+/* $Id: kmap.c,v 1.5 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* FUNCTIONS ***************************************************************/
-VOID ExUnmapPage(PVOID Addr)
+VOID
+ExUnmapPage(PVOID Addr)
{
KIRQL oldIrql;
ULONG i = (Addr - kernel_pool_base) / PAGESIZE;
KeReleaseSpinLock(&AllocMapLock, oldIrql);
}
-PVOID ExAllocatePage(VOID)
+PVOID
+ExAllocatePage(VOID)
{
KIRQL oldlvl;
ULONG addr;
addr = (ULONG)(kernel_pool_base + (i*PAGESIZE));
Status = MmCreateVirtualMapping(NULL,
(PVOID)addr,
- PAGE_READWRITE,
+ PAGE_READWRITE | PAGE_SYSTEM,
PhysPage);
if (!NT_SUCCESS(Status))
{
return(NULL);
}
-VOID MmInitKernelMap(PVOID BaseAddress)
+VOID
+MmInitKernelMap(PVOID BaseAddress)
{
kernel_pool_base = BaseAddress;
KeInitializeSpinLock(&AllocMapLock);
}
-unsigned int alloc_pool_region(unsigned int nr_pages)
+unsigned int
+alloc_pool_region(unsigned int nr_pages)
/*
* FUNCTION: Allocates a region of pages within the nonpaged pool area
*/
-/* $Id: mdl.c,v 1.26 2000/10/22 16:36:51 ekohl Exp $
+/* $Id: mdl.c,v 1.27 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
}
/* EOF */
+
+
+
+
+
+
+
+
+
-/* $Id: mm.c,v 1.39 2000/10/22 16:36:52 ekohl Exp $
+/* $Id: mm.c,v 1.40 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
Status = MmCreateVirtualMapping(PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address),
PAGE_READONLY,
- (ULONG)MmSharedDataPagePhysicalAddress);
+ (ULONG)MmSharedDataPagePhysicalAddress);
break;
default:
/* Miscellanea functions: they may fit somewhere else */
-DWORD
-STDCALL
-MmAdjustWorkingSetSize (
- DWORD Unknown0,
- DWORD Unknown1,
- DWORD Unknown2
- )
+DWORD STDCALL
+MmAdjustWorkingSetSize (DWORD Unknown0,
+ DWORD Unknown1,
+ DWORD Unknown2)
{
UNIMPLEMENTED;
return (0);
-/* $Id: ncache.c,v 1.6 2000/08/20 17:02:08 dwelch Exp $
+/* $Id: ncache.c,v 1.7 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* REVISIONS
*
*/
-PVOID STDCALL MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
+PVOID STDCALL
+MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
{
PVOID Result;
MEMORY_AREA* marea;
NTSTATUS Status;
ULONG i;
-
+ ULONG Attributes;
+
Result = NULL;
Status = MmCreateMemoryArea (NULL,
MmGetKernelAddressSpace(),
{
return (NULL);
}
- for (i = 0; (i <= (NumberOfBytes / PAGESIZE)); i++)
+ Attributes = PAGE_READWRITE | PAGE_SYSTEM | PAGE_NOCACHE |
+ PAGE_WRITETHROUGH;
+ for (i = 0; i <= (NumberOfBytes / PAGESIZE); i++)
{
- Status = MmCreateVirtualMapping (NULL,
- (Result + (i * PAGESIZE)),
- PAGE_READWRITE,
- (ULONG)MmAllocPage(0));
- if (!NT_SUCCESS(Status))
- {
- DbgPrint("Unable to create virtual mapping\n");
- KeBugCheck(0);
- }
+ PVOID NPage;
+
+ NPage = MmAllocPageMaybeSwap(0);
+ MmCreateVirtualMapping (NULL,
+ Result + (i * PAGESIZE),
+ Attributes,
+ (ULONG)NPage);
}
return ((PVOID)Result);
}
VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
IN ULONG NumberOfBytes)
{
- MmFreeMemoryArea (&PsGetCurrentProcess()->AddressSpace,
- BaseAddress,
- NumberOfBytes,
- TRUE);
+ MmFreeMemoryArea (MmGetKernelAddressSpace(),
+ BaseAddress,
+ NumberOfBytes,
+ TRUE);
}
-/* $Id: npool.c,v 1.32 2000/10/22 16:36:52 ekohl Exp $
+/* $Id: npool.c,v 1.33 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
unsigned int EiFreeNonPagedPool = 0;
unsigned int EiUsedNonPagedPool = 0;
+unsigned int
+alloc_pool_region(unsigned int nr_pages);
+
/* FUNCTIONS ***************************************************************/
VOID ExInitNonPagedPool(ULONG BaseAddress)
-/* $Id: pagefile.c,v 1.7 2000/09/03 14:53:03 ekohl Exp $
+/* $Id: pagefile.c,v 1.8 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* TYPES *********************************************************************/
-typedef struct _PPAGINGFILE
+typedef struct _PAGINGFILE
{
LIST_ENTRY PagingFileListEntry;
PFILE_OBJECT FileObject;
/* EOF */
+
+
+
+
+
+
+
-/* $Id: pager.c,v 1.5 2000/10/22 16:36:52 ekohl Exp $
+/* $Id: pager.c,v 1.6 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
{
DbgPrint("PagerThread: Wait failed\n");
KeBugCheck(0);
- }
+ }
if (PagerThreadShouldTerminate)
{
DbgPrint("PagerThread: Terminating\n");
-/* $Id: section.c,v 1.40 2000/12/28 03:38:07 dwelch Exp $
+/* $Id: section.c,v 1.41 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
/* FUNCTIONS *****************************************************************/
-NTSTATUS MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
- PMEMORY_AREA MArea,
- PVOID Address)
+NTSTATUS
+MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
+ PMEMORY_AREA MArea,
+ PVOID Address)
{
return(STATUS_UNSUCCESSFUL);
}
&IoStatus);
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
{
- MmLockAddressSpace(AddressSpace);
- return(Status);
+ DPRINT("IoPageRead failed (%x)\n", Status);
+ MmLockAddressSpace(AddressSpace);
+ return(Status);
}
MmLockAddressSpace(AddressSpace);
/*
* FIXME: What do we know in this case?
*/
-
- MmLockAddressSpace(AddressSpace);
- return(Status);
+ DPRINT("IoPageRead failed (Status %x)\n", Status);
+ MmLockAddressSpace(AddressSpace);
+ return(Status);
}
/*
KeBugCheck(0);
}
MmUnlockSection(Section);
-
+ DPRINT("MmNotPresentFaultSectionView succeeded\n");
return(STATUS_SUCCESS);
}
-/* $Id: virtual.c,v 1.35 2000/10/22 16:36:52 ekohl Exp $
+/* $Id: virtual.c,v 1.36 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
/* FUNCTIONS *****************************************************************/
-PMM_SEGMENT MmGetSegmentForAddress(PMEMORY_AREA MArea,
- PVOID Address,
- PVOID* PCurrentAddress)
+PMM_SEGMENT
+MmGetSegmentForAddress(PMEMORY_AREA MArea,
+ PVOID Address,
+ PVOID* PCurrentAddress)
/*
* FUNCTION: Get the segment corresponding to a particular memory area and
* address.
* Address (IN) = The address to get the segment for
* PCurrentAddress (OUT) = The start of the segment
* RETURNS:
- * The corresponding memory or NULL if an error occurred
+ * The corresponding segment or NULL if an error occurred
*/
{
PVOID CurrentAddress;
return(NULL);
}
-NTSTATUS MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
- PMEMORY_AREA MArea,
- PVOID Address)
+NTSTATUS
+MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
+ PMEMORY_AREA MArea,
+ PVOID Address)
{
SWAPENTRY se;
ULONG Flags;
return(0);
}
-NTSTATUS MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
- MEMORY_AREA* MemoryArea,
- PVOID Address)
+NTSTATUS
+MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
+ MEMORY_AREA* MemoryArea,
+ PVOID Address)
/*
* FUNCTION: Move data into memory to satisfy a page not present fault
* ARGUMENTS:
return(STATUS_SUCCESS);
}
-VOID MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
- PVOID BaseAddress,
- ULONG RegionSize,
- ULONG OldType,
- ULONG OldProtect,
- ULONG NewType,
- ULONG NewProtect)
+VOID STATIC
+MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
+ PVOID BaseAddress,
+ ULONG RegionSize,
+ ULONG OldType,
+ ULONG OldProtect,
+ ULONG NewType,
+ ULONG NewProtect)
/*
* FUNCTION: Modify the attributes of a memory region
*/
{
- if (NewType == MEM_RESERVE &&
- OldType == MEM_COMMIT)
- {
- ULONG i;
-
- for (i=0; i<=(RegionSize/PAGESIZE); i++)
- {
- LARGE_INTEGER PhysicalAddr;
-
- PhysicalAddr = MmGetPhysicalAddress(BaseAddress + (i*PAGESIZE));
- if (PhysicalAddr.u.LowPart != 0)
- {
- MmRemovePageFromWorkingSet(AddressSpace->Process,
- BaseAddress + (i*PAGESIZE));
- MmDereferencePage((PVOID)(ULONG)(PhysicalAddr.u.LowPart));
- }
- }
- }
- if (NewType == MEM_COMMIT && OldType == MEM_COMMIT &&
- OldProtect != NewProtect)
- {
- ULONG i;
-
- for (i=0; i<(RegionSize/PAGESIZE); i++)
- {
- if (MmIsPagePresent(AddressSpace->Process,
- BaseAddress + (i*PAGESIZE)))
- {
- MmSetPageProtect(AddressSpace->Process,
- BaseAddress + (i*PAGESIZE),
- NewProtect);
- }
- }
- }
+ /*
+ * If we are switching a previously committed region to reserved then
+ * free any allocated pages within the region
+ */
+ if (NewType == MEM_RESERVE && OldType == MEM_COMMIT)
+ {
+ ULONG i;
+
+ for (i=0; i <= (RegionSize/PAGESIZE); i++)
+ {
+ LARGE_INTEGER PhysicalAddr;
+
+ PhysicalAddr = MmGetPhysicalAddress(BaseAddress + (i*PAGESIZE));
+ if (PhysicalAddr.u.LowPart != 0)
+ {
+ MmRemovePageFromWorkingSet(AddressSpace->Process,
+ BaseAddress + (i*PAGESIZE));
+ MmDereferencePage((PVOID)(ULONG)(PhysicalAddr.u.LowPart));
+ }
+ MmDeleteVirtualMapping(AddressSpace->Process,
+ BaseAddress + (i*PAGESIZE),
+ FALSE);
+ }
+ }
+
+ /*
+ * If we are changing the protection attributes of a committed region then
+ * alter the attributes for any allocated pages within the region
+ */
+ if (NewType == MEM_COMMIT && OldType == MEM_COMMIT &&
+ OldProtect != NewProtect)
+ {
+ ULONG i;
+
+ for (i=0; i <= (RegionSize/PAGESIZE); i++)
+ {
+ if (MmIsPagePresent(AddressSpace->Process,
+ BaseAddress + (i*PAGESIZE)))
+ {
+ MmSetPageProtect(AddressSpace->Process,
+ BaseAddress + (i*PAGESIZE),
+ NewProtect);
+ }
+ }
+ }
}
-VOID InsertAfterEntry(PLIST_ENTRY Previous,
- PLIST_ENTRY Entry)
+VOID STATIC
+InsertAfterEntry(PLIST_ENTRY Previous,
+ PLIST_ENTRY Entry)
/*
* FUNCTION: Insert a list entry after another entry in the list
*/
Previous->Flink = Entry;
}
-VOID MmDumpSegmentsMemoryArea(PMEMORY_AREA MemoryArea)
+#if 0
+VOID STATIC
+MmDumpSegmentsMemoryArea(PMEMORY_AREA MemoryArea)
{
PVOID CurrentAddress;
PLIST_ENTRY CurrentEntry;
CurrentEntry = CurrentEntry->Flink;
}
}
+#endif
-NTSTATUS MmSplitSegment(PMADDRESS_SPACE AddressSpace,
- PMEMORY_AREA MemoryArea,
- PVOID RegionAddress,
- ULONG RegionLength,
- ULONG Type,
- ULONG Protect,
- PMM_SEGMENT FirstSegment,
- PVOID FirstAddress)
+NTSTATUS
+MmSplitSegment(PMADDRESS_SPACE AddressSpace,
+ PMEMORY_AREA MemoryArea,
+ PVOID RegionAddress,
+ ULONG RegionLength,
+ ULONG Type,
+ ULONG Protect,
+ PMM_SEGMENT FirstSegment,
+ PVOID FirstAddress)
/*
* FUNCTION: Split a memory segment internally
*/
OldType = FirstSegment->Type;
OldProtect = FirstSegment->Protect;
OldLength = FirstSegment->Length;
+
+ /*
+ * If the segment is already of the right type and protection then
+ * there is nothing to do.
+ */
+ if (FirstSegment->Type == Type && FirstSegment->Protect == Protect)
+ {
+ return(STATUS_SUCCESS);
+ }
/*
* Allocate the segment we might need here because if the allocation
return(STATUS_NO_MEMORY);
}
- /*
- * If the segment is already of the right type and protection then
- * there is nothing to do.
- */
- if (FirstSegment->Type == Type && FirstSegment->Protect == Protect)
- {
- return(STATUS_SUCCESS);
- }
-
if (FirstAddress < RegionAddress)
{
/*
}
-NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
- IN OUT PVOID* PBaseAddress,
- IN ULONG ZeroBits,
- IN OUT PULONG PRegionSize,
- IN ULONG AllocationType,
- IN ULONG Protect)
+NTSTATUS STDCALL
+NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
+ IN OUT PVOID* UBaseAddress,
+ IN ULONG ZeroBits,
+ IN OUT PULONG URegionSize,
+ IN ULONG AllocationType,
+ IN ULONG Protect)
/*
* FUNCTION: Allocates a block of virtual memory in the process address space
* ARGUMENTS:
PMM_SEGMENT Segment;
PVOID BaseAddress;
ULONG RegionSize;
-
+ PVOID PBaseAddress;
+ ULONG PRegionSize;
+
DPRINT("NtAllocateVirtualMemory(ProcessHandle %x, *BaseAddress %x, "
"ZeroBits %d, *RegionSize %x, AllocationType %x, Protect %x)\n",
ProcessHandle,*BaseAddress,ZeroBits,*RegionSize,AllocationType,
Protect);
- BaseAddress = (PVOID)PAGE_ROUND_DOWN((*PBaseAddress));
- RegionSize = PAGE_ROUND_UP((*PBaseAddress) + (*PRegionSize)) -
- PAGE_ROUND_DOWN((*PBaseAddress));
+ /*
+ * Check the validity of the parameters
+ */
+ if ((Protect & PAGE_FLAGS_VALID_FROM_USER_MODE) != Protect)
+ {
+ return(STATUS_INVALID_PAGE_PROTECTION);
+ }
+ PBaseAddress = *UBaseAddress;
+ PRegionSize = *URegionSize;
+
+
+ BaseAddress = (PVOID)PAGE_ROUND_DOWN(PBaseAddress);
+ RegionSize = PAGE_ROUND_UP(PBaseAddress + PRegionSize) -
+ PAGE_ROUND_DOWN(PBaseAddress);
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_OPERATION,
MmReserveSwapPages(RegionSize);
}
- *PBaseAddress = BaseAddress;
- *PRegionSize = RegionSize;
+ *UBaseAddress = BaseAddress;
+ *URegionSize = RegionSize;
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
}
-NTSTATUS STDCALL NtFlushVirtualMemory(IN HANDLE ProcessHandle,
- IN PVOID BaseAddress,
- IN ULONG NumberOfBytesToFlush,
- OUT PULONG NumberOfBytesFlushed OPTIONAL)
+NTSTATUS STDCALL
+NtFlushVirtualMemory(IN HANDLE ProcessHandle,
+ IN PVOID BaseAddress,
+ IN ULONG NumberOfBytesToFlush,
+ OUT PULONG NumberOfBytesFlushed OPTIONAL)
/*
* FUNCTION: Flushes virtual memory to file
* ARGUMENTS:
}
-NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle,
- IN PVOID* PBaseAddress,
- IN PULONG PRegionSize,
- IN ULONG FreeType)
+NTSTATUS STDCALL
+NtFreeVirtualMemory(IN HANDLE ProcessHandle,
+ IN PVOID* PBaseAddress,
+ IN PULONG PRegionSize,
+ IN ULONG FreeType)
/*
* FUNCTION: Frees a range of virtual memory
* ARGUMENTS:
}
-NTSTATUS STDCALL NtLockVirtualMemory(HANDLE ProcessHandle,
- PVOID BaseAddress,
- ULONG NumberOfBytesToLock,
- PULONG NumberOfBytesLocked)
+NTSTATUS STDCALL
+NtLockVirtualMemory(HANDLE ProcessHandle,
+ PVOID BaseAddress,
+ ULONG NumberOfBytesToLock,
+ PULONG NumberOfBytesLocked)
{
- UNIMPLEMENTED;
+ UNIMPLEMENTED;
}
-VOID MmChangeAreaProtection(PEPROCESS Process,
- PVOID BaseAddress,
- ULONG Length,
- ULONG Protect)
+VOID
+MmChangeAreaProtection(PEPROCESS Process,
+ PVOID BaseAddress,
+ ULONG Length,
+ ULONG Protect)
{
ULONG i;
}
-NTSTATUS STDCALL NtReadVirtualMemory(IN HANDLE ProcessHandle,
- IN PVOID BaseAddress,
- OUT PVOID Buffer,
- IN ULONG NumberOfBytesToRead,
- OUT PULONG NumberOfBytesRead)
+NTSTATUS STDCALL
+NtReadVirtualMemory(IN HANDLE ProcessHandle,
+ IN PVOID BaseAddress,
+ OUT PVOID Buffer,
+ IN ULONG NumberOfBytesToRead,
+ OUT PULONG NumberOfBytesRead)
{
NTSTATUS Status;
PMDL Mdl;
}
-NTSTATUS STDCALL NtUnlockVirtualMemory(HANDLE ProcessHandle,
- PVOID BaseAddress,
- ULONG NumberOfBytesToUnlock,
- PULONG NumberOfBytesUnlocked OPTIONAL)
+NTSTATUS STDCALL
+NtUnlockVirtualMemory(HANDLE ProcessHandle,
+ PVOID BaseAddress,
+ ULONG NumberOfBytesToUnlock,
+ PULONG NumberOfBytesUnlocked OPTIONAL)
{
UNIMPLEMENTED;
}
-NTSTATUS STDCALL NtWriteVirtualMemory(IN HANDLE ProcessHandle,
- IN PVOID BaseAddress,
- IN PVOID Buffer,
- IN ULONG NumberOfBytesToWrite,
- OUT PULONG NumberOfBytesWritten)
+NTSTATUS STDCALL
+NtWriteVirtualMemory(IN HANDLE ProcessHandle,
+ IN PVOID BaseAddress,
+ IN PVOID Buffer,
+ IN ULONG NumberOfBytesToWrite,
+ OUT PULONG NumberOfBytesWritten)
{
NTSTATUS Status;
PMDL Mdl;
-/* $Id: wset.c,v 1.5 2000/08/18 22:27:03 dwelch Exp $
+/* $Id: wset.c,v 1.6 2001/01/08 02:14:06 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
}
+