Some memory manager cleanups

Hopefully fixed vfat fsd reported by Philip Susi
FAT lookups go through cache

svn path=/trunk/; revision=1499
This commit is contained in:
David Welch 2001-01-08 02:14:06 +00:00
parent 21c3a954d0
commit 48b5533bd5
28 changed files with 690 additions and 422 deletions

View file

@ -18,15 +18,17 @@
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
BOOLEAN NTSTATUS
VFATReadSectors (IN PDEVICE_OBJECT pDeviceObject, VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector, IN ULONG SectorCount, IN UCHAR * Buffer) IN ULONG DiskSector,
IN ULONG SectorCount,
IN OUT PUCHAR Buffer)
{ {
LARGE_INTEGER sectorNumber; LARGE_INTEGER sectorNumber;
PIRP irp; PIRP Irp;
IO_STATUS_BLOCK ioStatus; IO_STATUS_BLOCK IoStatus;
KEVENT event; KEVENT event;
NTSTATUS status; NTSTATUS Status;
ULONG sectorSize; ULONG sectorSize;
sectorNumber.u.LowPart = DiskSector << 9; sectorNumber.u.LowPart = DiskSector << 9;
@ -35,7 +37,6 @@ VFATReadSectors (IN PDEVICE_OBJECT pDeviceObject,
KeInitializeEvent (&event, NotificationEvent, FALSE); KeInitializeEvent (&event, NotificationEvent, FALSE);
sectorSize = BLOCKSIZE * SectorCount; sectorSize = BLOCKSIZE * SectorCount;
DPRINT ("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n", DPRINT ("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
pDeviceObject, DiskSector, Buffer); pDeviceObject, DiskSector, Buffer);
DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n", DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n",
@ -44,53 +45,55 @@ VFATReadSectors (IN PDEVICE_OBJECT pDeviceObject,
DPRINT ("Building synchronous FSD Request...\n"); DPRINT ("Building synchronous FSD Request...\n");
irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ, Irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ,
pDeviceObject, pDeviceObject,
Buffer, Buffer,
sectorSize, sectorSize,
&sectorNumber, &event, &ioStatus); &sectorNumber,
&event,
&IoStatus);
if (!irp) if (Irp == NULL)
{ {
DbgPrint ("READ failed!!!\n"); DPRINT("IoBuildSynchronousFsdRequest failed\n");
return FALSE; return(STATUS_UNSUCCESSFUL);;
} }
DPRINT ("Calling IO Driver... with irp %x\n", irp); DPRINT ("Calling IO Driver... with irp %x\n", Irp);
status = IoCallDriver (pDeviceObject, irp); Status = IoCallDriver (pDeviceObject, Irp);
DPRINT ("Waiting for IO Operation for %x\n", irp); DPRINT ("Waiting for IO Operation for %x\n", Irp);
if (status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
DPRINT ("Operation pending\n"); DPRINT ("Operation pending\n");
KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL); KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL);
DPRINT ("Getting IO Status... for %x\n", irp); DPRINT ("Getting IO Status... for %x\n", Irp);
status = ioStatus.Status; Status = IoStatus.Status;
} }
if (!NT_SUCCESS (status)) if (!NT_SUCCESS (Status))
{ {
DbgPrint ("IO failed!!! VFATREadSectors : Error code: %x\n", status); DPRINT ("IO failed!!! VFATREadSectors : Error code: %x\n", Status);
DbgPrint DPRINT ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart, pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
sectorNumber.u.LowPart); sectorNumber.u.LowPart);
return FALSE; return (Status);
} }
DPRINT ("Block request succeeded for %x\n", irp); DPRINT ("Block request succeeded for %x\n", Irp);
return TRUE; return (STATUS_SUCCESS);
} }
BOOLEAN NTSTATUS
VFATWriteSectors (IN PDEVICE_OBJECT pDeviceObject, VfatWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector, IN ULONG DiskSector,
IN ULONG SectorCount, IN UCHAR * Buffer) IN ULONG SectorCount,
IN PUCHAR Buffer)
{ {
LARGE_INTEGER sectorNumber; LARGE_INTEGER sectorNumber;
PIRP irp; PIRP Irp;
IO_STATUS_BLOCK ioStatus; IO_STATUS_BLOCK IoStatus;
KEVENT event; KEVENT event;
NTSTATUS status; NTSTATUS Status;
ULONG sectorSize; ULONG sectorSize;
DPRINT ("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n", DPRINT ("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
@ -104,35 +107,37 @@ VFATWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
sectorSize = BLOCKSIZE * SectorCount; sectorSize = BLOCKSIZE * SectorCount;
DPRINT ("Building synchronous FSD Request...\n"); DPRINT ("Building synchronous FSD Request...\n");
irp = IoBuildSynchronousFsdRequest (IRP_MJ_WRITE, Irp = IoBuildSynchronousFsdRequest (IRP_MJ_WRITE,
pDeviceObject, pDeviceObject,
Buffer, Buffer,
sectorSize, sectorSize,
&sectorNumber, &event, &ioStatus); &sectorNumber,
&event,
&IoStatus);
if (!irp) if (!Irp)
{ {
DbgPrint ("WRITE failed!!!\n"); DPRINT ("WRITE failed!!!\n");
return FALSE; return (STATUS_UNSUCCESSFUL);
} }
DPRINT ("Calling IO Driver...\n"); DPRINT ("Calling IO Driver...\n");
status = IoCallDriver (pDeviceObject, irp); Status = IoCallDriver (pDeviceObject, Irp);
DPRINT ("Waiting for IO Operation...\n"); DPRINT ("Waiting for IO Operation...\n");
if (status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL); KeWaitForSingleObject (&event, Suspended, KernelMode, FALSE, NULL);
DPRINT ("Getting IO Status...\n"); 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); DPRINT ("IO failed!!! VFATWriteSectors : Error code: %x\n", Status);
return FALSE; return (Status);
} }
DPRINT ("Block request succeeded\n"); DPRINT ("Block request succeeded\n");
return TRUE; return (STATUS_SUCCESS);
} }

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -95,7 +95,8 @@ GetEntryName (PVOID Block, PULONG _Offset, PWSTR Name, PULONG _jloop,
Offset = 0; Offset = 0;
StartingSector++; //FIXME : nor always the next sector StartingSector++; //FIXME : nor always the next sector
jloop++; jloop++;
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
StartingSector, 1, Block); StartingSector, 1, Block);
test2 = (slot *) Block; test2 = (slot *) Block;
} }
@ -156,7 +157,8 @@ ReadVolumeLabel (PDEVICE_EXTENSION DeviceExt, PVPB Vpb)
DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i); DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i);
for (j = 0; j < Size; j++) 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++) for (i = 0; i < ENTRIES_PER_SECTOR; i++)
{ {
@ -291,7 +293,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i); DPRINT ("FindFile : start at sector %lx, entry %ld\n", StartingSector, i);
for (j = 0; j < Size; j++) 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++) for (i = (Entry) ? (*Entry) : 0; i < ENTRIES_PER_SECTOR; i++)
{ {
@ -320,7 +323,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
/* entry is in next sector */ /* entry is in next sector */
StartingSector++; StartingSector++;
/* FIXME : treat case of next sector fragmented */ /* FIXME : treat case of next sector fragmented */
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
StartingSector, 1, block); StartingSector, 1, block);
i = 0; i = 0;
} }
@ -563,7 +567,8 @@ FsdOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
ParentFcb = Temp; ParentFcb = Temp;
} }
FileObject->Flags = FileObject->Flags |
FO_FCB_IS_VALID | FO_DIRECT_CACHE_PAGING_READ;
FileObject->FsContext = (PVOID)&ParentFcb->RFCB; FileObject->FsContext = (PVOID)&ParentFcb->RFCB;
newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB)); newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
memset (newCCB, 0, sizeof (VFATCCB)); memset (newCCB, 0, sizeof (VFATCCB));

View file

@ -1,5 +1,5 @@
/* /*
* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -35,7 +35,8 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
Block = ExAllocatePool (NonPagedPool, 1024); Block = ExAllocatePool (NonPagedPool, 1024);
FATsector = CurrentCluster / (512 / sizeof (ULONG)); FATsector = CurrentCluster / (512 / sizeof (ULONG));
FATeis = CurrentCluster - (FATsector * (512 / sizeof (ULONG))); FATeis = CurrentCluster - (FATsector * (512 / sizeof (ULONG)));
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + FATsector), 1, (ULONG) (DeviceExt->FATStart + FATsector), 1,
(UCHAR *) Block); (UCHAR *) Block);
CurrentCluster = Block[FATeis]; CurrentCluster = Block[FATeis];
@ -53,11 +54,36 @@ Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
*/ */
{ {
PUSHORT Block; PUSHORT Block;
Block = (PUSHORT) DeviceExt->FAT; PVOID BaseAddress;
CurrentCluster = Block[CurrentCluster]; 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) if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
CurrentCluster = 0xffffffff; CurrentCluster = 0xffffffff;
DPRINT ("Returning %x\n", CurrentCluster); CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
return (CurrentCluster); return (CurrentCluster);
} }
@ -71,17 +97,82 @@ Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
unsigned char *CBlock; unsigned char *CBlock;
ULONG FATOffset; ULONG FATOffset;
ULONG Entry; ULONG Entry;
CBlock = DeviceExt->FAT; PVOID PBlock;
FATOffset = (CurrentCluster * 12) / 8; //first byte containing value NTSTATUS Status;
if ((CurrentCluster % 2) == 0) 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)
{ {
Entry = CBlock[FATOffset]; Status = VfatReadSectors(DeviceExt->StorageDevice,
Entry |= ((CBlock[FATOffset + 1] & 0xf) << 8); 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 else
{ {
Entry = (CBlock[FATOffset] >> 4); Value2 = ((PUCHAR)BaseAddress)[(FATOffset % PAGESIZE) + 1];
Entry |= (CBlock[FATOffset + 1] << 4); CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
}
if ((CurrentCluster % 2) == 0)
{
Entry = Value1;
Entry |= ((Value2 & 0xf) << 8);
}
else
{
Entry = (Value1 >> 4);
Entry |= (Value2 << 4);
} }
DPRINT ("Entry %x\n", Entry); DPRINT ("Entry %x\n", Entry);
if (Entry >= 0xff8 && Entry <= 0xfff) if (Entry >= 0xff8 && Entry <= 0xfff)
@ -182,7 +273,8 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32; sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++) sector++)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + sector), 1, (ULONG) (DeviceExt->FATStart + sector), 1,
(UCHAR *) Block); (UCHAR *) Block);
@ -278,7 +370,8 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32; sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++) sector++)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + sector), 1, (ULONG) (DeviceExt->FATStart + sector), 1,
(UCHAR *) Block); (UCHAR *) Block);
@ -324,14 +417,16 @@ FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
{ {
if ((FATOffset % BLOCKSIZE) == (BLOCKSIZE - 1)) //entry is on 2 sectors if ((FATOffset % BLOCKSIZE) == (BLOCKSIZE - 1)) //entry is on 2 sectors
{ {
VFATWriteSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatWriteSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector DeviceExt->FATStart + FATsector
+ i * DeviceExt->Boot->FATSectors, + i * DeviceExt->Boot->FATSectors,
2, CBlock + FATsector * 512); 2, CBlock + FATsector * 512);
} }
else else
{ {
VFATWriteSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatWriteSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector DeviceExt->FATStart + FATsector
+ i * DeviceExt->Boot->FATSectors, + i * DeviceExt->Boot->FATSectors,
1, CBlock + FATsector * 512); 1, CBlock + FATsector * 512);
@ -363,7 +458,8 @@ FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
Start = DeviceExt->FATStart + FATsector; Start = DeviceExt->FATStart + FATsector;
for (i = 0; i < DeviceExt->Boot->FATCount; i++) for (i = 0; i < DeviceExt->Boot->FATCount; i++)
{ {
VFATWriteSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatWriteSectors (DeviceExt->StorageDevice,
Start, 1, ((UCHAR *) Block) + FATsector * 512); Start, 1, ((UCHAR *) Block) + FATsector * 512);
Start += DeviceExt->Boot->FATSectors; Start += DeviceExt->Boot->FATSectors;
} }
@ -387,7 +483,8 @@ FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
FATsector = ClusterToWrite / 128; FATsector = ClusterToWrite / 128;
FATeis = ClusterToWrite - (FATsector * 128); FATeis = ClusterToWrite - (FATsector * 128);
/* load sector, change value, then rewrite sector */ /* load sector, change value, then rewrite sector */
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector, 1, (UCHAR *) Block); DeviceExt->FATStart + FATsector, 1, (UCHAR *) Block);
Block[FATeis] = NewValue; Block[FATeis] = NewValue;
/* Write the changed FAT sector to disk (all FAT's) */ /* Write the changed FAT sector to disk (all FAT's) */
@ -395,7 +492,8 @@ FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
pBoot = (struct _BootSector32 *) DeviceExt->Boot; pBoot = (struct _BootSector32 *) DeviceExt->Boot;
for (i = 0; i < pBoot->FATCount; i++) 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; Start += pBoot->FATSectors;
} }
ExFreePool (Block); ExFreePool (Block);
@ -503,7 +601,8 @@ VFATLoadCluster (PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
Sector = ClusterToSector (DeviceExt, Cluster); Sector = ClusterToSector (DeviceExt, Cluster);
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster, Buffer); Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
DPRINT ("Finished VFATReadSectors\n"); DPRINT ("Finished VFATReadSectors\n");
} }
@ -520,6 +619,7 @@ VFATWriteCluster (PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
Sector = ClusterToSector (DeviceExt, Cluster); Sector = ClusterToSector (DeviceExt, Cluster);
VFATWriteSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatWriteSectors (DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster, Buffer); Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
} }

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -51,7 +51,8 @@ VfatHasFileSystem (PDEVICE_OBJECT DeviceToMount)
Boot = ExAllocatePool (NonPagedPool, 512); 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); DPRINT ("Boot->SysType %.5s\n", Boot->SysType);
if (strncmp (Boot->SysType, "FAT12", 5) == 0 || if (strncmp (Boot->SysType, "FAT12", 5) == 0 ||
@ -75,10 +76,8 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
DPRINT ("DeviceExt %x\n", DeviceExt); DPRINT ("DeviceExt %x\n", DeviceExt);
DeviceExt->Boot = ExAllocatePool (NonPagedPool, 512); DeviceExt->Boot = ExAllocatePool (NonPagedPool, 512);
VFATReadSectors (DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot); /* FIXME: Check status */
VfatReadSectors (DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
DPRINT ("DeviceExt->Boot->BytesPerSector %x\n",
DeviceExt->Boot->BytesPerSector);
DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors; DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
DeviceExt->rootDirectorySectors = DeviceExt->rootDirectorySectors =
@ -107,6 +106,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
if (strncmp (DeviceExt->Boot->SysType, "FAT12", 5) == 0) if (strncmp (DeviceExt->Boot->SysType, "FAT12", 5) == 0)
{ {
DbgPrint("FAT12\n");
DeviceExt->FatType = FAT12; DeviceExt->FatType = FAT12;
} }
else else
@ -114,6 +114,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
(((struct _BootSector32 *) (DeviceExt->Boot))->SysType, "FAT32", (((struct _BootSector32 *) (DeviceExt->Boot))->SysType, "FAT32",
5) == 0) 5) == 0)
{ {
DbgPrint("FAT32\n");
DeviceExt->FatType = FAT32; DeviceExt->FatType = FAT32;
DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster; DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster;
DeviceExt->rootStart = DeviceExt->rootStart =
@ -123,6 +124,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
} }
else else
{ {
DbgPrint("FAT16\n");
DeviceExt->FatType = FAT16; DeviceExt->FatType = FAT16;
} }
@ -133,7 +135,8 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
DeviceExt->FAT = DeviceExt->FAT =
ExAllocatePool (NonPagedPool, ExAllocatePool (NonPagedPool,
BLOCKSIZE * DeviceExt->Boot->FATSectors); BLOCKSIZE * DeviceExt->Boot->FATSectors);
VFATReadSectors (DeviceToMount, DeviceExt->FATStart, /* FIXME: Check status */
VfatReadSectors (DeviceToMount, DeviceExt->FATStart,
DeviceExt->Boot->FATSectors, (UCHAR *) DeviceExt->FAT); DeviceExt->Boot->FATSectors, (UCHAR *) DeviceExt->FAT);
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -147,6 +150,7 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
{ {
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
PDEVICE_EXTENSION DeviceExt; PDEVICE_EXTENSION DeviceExt;
NTSTATUS Status;
IoCreateDevice (VfatDriverObject, IoCreateDevice (VfatDriverObject,
sizeof (DEVICE_EXTENSION), sizeof (DEVICE_EXTENSION),
@ -159,6 +163,11 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
DeviceObject->Vpb->Flags |= VPB_MOUNTED; DeviceObject->Vpb->Flags |= VPB_MOUNTED;
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack (DeviceObject, DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack (DeviceObject,
DeviceToMount); DeviceToMount);
DeviceExt->StreamStorageDevice =
IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice);
Status = CcInitializeFileCache(DeviceExt->StreamStorageDevice,
&DeviceExt->StorageBcb,
PAGESIZE);
ExInitializeResourceLite (&DeviceExt->DirResource); ExInitializeResourceLite (&DeviceExt->DirResource);
ExInitializeResourceLite (&DeviceExt->FatResource); ExInitializeResourceLite (&DeviceExt->FatResource);

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -26,6 +26,24 @@
/* FUNCTIONS *****************************************************************/ /* 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 ULONG
OffsetToCluster(PDEVICE_EXTENSION DeviceExt, OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster, ULONG FirstCluster,
@ -34,6 +52,8 @@ OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster; ULONG CurrentCluster;
ULONG i; ULONG i;
DPRINT("OffsetToCluster(FirstCluster 0x%x)\n", FirstCluster);
CurrentCluster = FirstCluster; CurrentCluster = FirstCluster;
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
@ -48,6 +68,7 @@ OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster); CurrentCluster = GetNextCluster (DeviceExt, CurrentCluster);
} }
} }
DPRINT("OffsetToCluster() = 0x%x\n", CurrentCluster);
return(CurrentCluster); return(CurrentCluster);
} }
@ -139,7 +160,8 @@ VfatReadFileNoCache (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
{ {
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster, CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp); DeviceExt->Boot->SectorsPerCluster, Temp);
CurrentCluster += DeviceExt->Boot->SectorsPerCluster; CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
@ -164,7 +186,8 @@ VfatReadFileNoCache (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
{ {
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster, CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Buffer); DeviceExt->Boot->SectorsPerCluster, Buffer);
CurrentCluster += DeviceExt->Boot->SectorsPerCluster; CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
@ -190,7 +213,8 @@ VfatReadFileNoCache (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
(*LengthRead) = (*LengthRead) + Length; (*LengthRead) = (*LengthRead) + Length;
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster, CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp); DeviceExt->Boot->SectorsPerCluster, Temp);
CurrentCluster += DeviceExt->Boot->SectorsPerCluster; CurrentCluster += DeviceExt->Boot->SectorsPerCluster;
@ -212,9 +236,11 @@ VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
PULONG CurrentCluster, PULONG CurrentCluster,
PVOID Destination) PVOID Destination)
{ {
DPRINT("VfatRawReadCluster() *CurrentCluster 0x%x\n", *CurrentCluster);
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
(*CurrentCluster), (*CurrentCluster),
DeviceExt->Boot->SectorsPerCluster, DeviceExt->Boot->SectorsPerCluster,
Destination); Destination);
@ -225,6 +251,8 @@ VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
VFATLoadCluster (DeviceExt, Destination, (*CurrentCluster)); VFATLoadCluster (DeviceExt, Destination, (*CurrentCluster));
(*CurrentCluster) = GetNextCluster (DeviceExt, (*CurrentCluster)); (*CurrentCluster) = GetNextCluster (DeviceExt, (*CurrentCluster));
} }
DPRINT("VfatRawReadCluster() finished *CurrentCluster 0x%x\n",
*CurrentCluster);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -298,8 +326,9 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
ULONG ReadOffset; ULONG ReadOffset;
ULONG InternalOffset; ULONG InternalOffset;
ReadOffset = ROUND_DOWN(StartOffset, PAGESIZE); /*
InternalOffset = StartOffset % PAGESIZE; * Otherwise we read a page of clusters together
*/
Status = CcRequestCacheSegment(Fcb->RFCB.Bcb, Status = CcRequestCacheSegment(Fcb->RFCB.Bcb,
ReadOffset, ReadOffset,
&BaseAddress, &BaseAddress,
@ -311,37 +340,43 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
} }
/* /*
* 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) if (!Valid)
{ {
ULONG StartCluster;
StartCluster = OffsetToCluster(DeviceExt, FirstCluster, ReadOffset);
for (i = 0; i < (PAGESIZE / BytesPerCluster); i++) for (i = 0; i < (PAGESIZE / BytesPerCluster); i++)
{ {
Status = VfatRawReadCluster(DeviceExt, Status = VfatRawReadCluster(DeviceExt,
FirstCluster, FirstCluster,
&StartCluster, CurrentCluster,
BaseAddress + (i * BytesPerCluster)); BaseAddress + (i * BytesPerCluster));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, FALSE); CcReleaseCacheSegment(Fcb->RFCB.Bcb, CacheSeg, FALSE);
return(Status); return(Status);
} }
} if (CurrentCluster == 0xFFFFFFFF)
}
/*
* Go on to the next cluster
*/
if (FirstCluster == 1)
{ {
(*CurrentCluster) += DeviceExt->Boot->SectorsPerCluster; break;
}
}
} }
else 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 * Copy the data from the cache to the caller
@ -366,6 +401,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
PVFATFCB Fcb; PVFATFCB Fcb;
PVOID Temp; PVOID Temp;
ULONG TempLength; ULONG TempLength;
ULONG ChunkSize;
/* PRECONDITION */ /* PRECONDITION */
assert (DeviceExt != NULL); assert (DeviceExt != NULL);
@ -374,7 +410,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
assert (FileObject->FsContext != NULL); assert (FileObject->FsContext != NULL);
DPRINT ("FsdReadFile(DeviceExt %x, FileObject %x, Buffer %x, " 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); Length, ReadOffset);
Fcb = ((PVFATCCB)FileObject->FsContext2)->pFcb; Fcb = ((PVFATCCB)FileObject->FsContext2)->pFcb;
@ -405,12 +441,14 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
} }
ChunkSize = max(DeviceExt->BytesPerCluster, PAGESIZE);
*LengthRead = 0; *LengthRead = 0;
/* /*
* Allocate a buffer to hold partial clusters * Allocate a buffer to hold partial clusters
*/ */
Temp = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster); Temp = ExAllocatePool (NonPagedPool, ChunkSize);
if (!Temp) if (!Temp)
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
@ -425,16 +463,14 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
* If the read doesn't begin on a cluster boundary then read a full * If the read doesn't begin on a cluster boundary then read a full
* cluster and copy it. * cluster and copy it.
*/ */
if ((ReadOffset % DeviceExt->BytesPerCluster) != 0) if ((ReadOffset % ChunkSize) != 0)
{ {
VfatReadCluster(DeviceExt, Fcb, VfatReadCluster(DeviceExt, Fcb,
ROUND_DOWN(ReadOffset, DeviceExt->BytesPerCluster), ROUND_DOWN(ReadOffset, ChunkSize),
FirstCluster, &CurrentCluster, Temp, 1); FirstCluster, &CurrentCluster, Temp, 1);
TempLength = min (Length, DeviceExt->BytesPerCluster - TempLength = min (Length, ChunkSize - (ReadOffset % ChunkSize));
(ReadOffset % DeviceExt->BytesPerCluster));
memcpy (Buffer, Temp + ReadOffset % DeviceExt->BytesPerCluster, memcpy (Buffer, Temp + ReadOffset % ChunkSize, TempLength);
TempLength);
(*LengthRead) = (*LengthRead) + TempLength; (*LengthRead) = (*LengthRead) + TempLength;
Length = Length - TempLength; Length = Length - TempLength;
@ -442,7 +478,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
ReadOffset = ReadOffset + TempLength; ReadOffset = ReadOffset + TempLength;
} }
while (Length >= DeviceExt->BytesPerCluster) while (Length >= ChunkSize)
{ {
VfatReadCluster(DeviceExt, Fcb, ReadOffset, VfatReadCluster(DeviceExt, Fcb, ReadOffset,
FirstCluster, &CurrentCluster, Buffer, 1); FirstCluster, &CurrentCluster, Buffer, 1);
@ -452,10 +488,10 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
return (STATUS_SUCCESS); return (STATUS_SUCCESS);
} }
(*LengthRead) = (*LengthRead) + DeviceExt->BytesPerCluster; (*LengthRead) = (*LengthRead) + ChunkSize;
Buffer = Buffer + DeviceExt->BytesPerCluster; Buffer = Buffer + ChunkSize;
Length = Length - DeviceExt->BytesPerCluster; Length = Length - ChunkSize;
ReadOffset = ReadOffset + DeviceExt->BytesPerCluster; ReadOffset = ReadOffset + ChunkSize;
} }
if (Length > 0) if (Length > 0)
@ -558,7 +594,8 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
/* Read in the existing cluster data */ /* Read in the existing cluster data */
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster, CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp); DeviceExt->Boot->SectorsPerCluster, Temp);
} }
@ -632,7 +669,8 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
/* Read in the existing cluster data */ /* Read in the existing cluster data */
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
VFATReadSectors (DeviceExt->StorageDevice, /* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
CurrentCluster, CurrentCluster,
DeviceExt->Boot->SectorsPerCluster, Temp); DeviceExt->Boot->SectorsPerCluster, Temp);
} }

View file

@ -1,4 +1,4 @@
/* $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> #include <ddk/ntifs.h>
@ -81,6 +81,8 @@ typedef struct
LIST_ENTRY FcbListHead; LIST_ENTRY FcbListHead;
PDEVICE_OBJECT StorageDevice; PDEVICE_OBJECT StorageDevice;
PFILE_OBJECT StreamStorageDevice;
PBCB StorageBcb;
BootSector *Boot; BootSector *Boot;
int rootDirectorySectors, FATStart, rootStart, dataStart; int rootDirectorySectors, FATStart, rootStart, dataStart;
int FATEntriesPerSector, FATUnit; int FATEntriesPerSector, FATUnit;
@ -119,7 +121,6 @@ typedef struct _VFATCCB
#define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry)) #define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
typedef struct __DOSTIME typedef struct __DOSTIME
{ {
WORD Second:5; WORD Second:5;
@ -154,14 +155,14 @@ VfatQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
/* internal functions in blockdev.c */ /* internal functions in blockdev.c */
BOOLEAN NTSTATUS
VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject, VfatReadSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector, IN ULONG DiskSector,
IN ULONG SectorCount, IN ULONG SectorCount,
IN UCHAR* Buffer); IN UCHAR* Buffer);
BOOLEAN NTSTATUS
VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject, VfatWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector, IN ULONG DiskSector,
IN ULONG SectorCount, IN ULONG SectorCount,
IN UCHAR* Buffer); IN UCHAR* Buffer);

View file

@ -1,4 +1,4 @@
/* $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 $
* *
*/ */
@ -267,10 +267,14 @@ typedef struct _IO_COMPLETION_CONTEXT
#define FO_HANDLE_CREATED 0x00040000 #define FO_HANDLE_CREATED 0x00040000
#define FO_FILE_FAST_IO_READ 0x00080000 #define FO_FILE_FAST_IO_READ 0x00080000
/*
* ReactOS specific flags
*/
#define FO_DIRECT_CACHE_READ 0x72000001 #define FO_DIRECT_CACHE_READ 0x72000001
#define FO_DIRECT_CACHE_WRITE 0x72000002 #define FO_DIRECT_CACHE_WRITE 0x72000002
#define FO_DIRECT_CACHE_PAGING_READ 0x72000004 #define FO_DIRECT_CACHE_PAGING_READ 0x72000004
#define FO_DIRECT_CACHE_PAGING_WRITE 0x72000008 #define FO_DIRECT_CACHE_PAGING_WRITE 0x72000008
#define FO_FCB_IS_VALID 0x72000010
typedef struct _FILE_OBJECT typedef struct _FILE_OBJECT
{ {

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -23,6 +23,7 @@ extern "C"
#ifndef FASTCALL #ifndef FASTCALL
#define FASTCALL STDCALL #define FASTCALL STDCALL
#endif #endif
#define STATIC static
#include <ntos/types.h> #include <ntos/types.h>
#include <ntos/disk.h> #include <ntos/disk.h>

View file

@ -426,7 +426,7 @@ typedef struct _IMAGE_CONTROL_DATA{
#define BUTTON 0x80 #define BUTTON 0x80
#define EDIT 0x81 #define EDIT 0x81
#define STATIC 0x82 //#define STATIC 0x82
#define LISTBOX 0x83 #define LISTBOX 0x83
#define SCROLLBAR 0x84 #define SCROLLBAR 0x84
#define COMBOBOX 0x85 #define COMBOBOX 0x85

View file

@ -13,20 +13,18 @@
struct _EPROCESS; struct _EPROCESS;
typedef ULONG SWAPENTRY; typedef ULONG SWAPENTRY;
enum #define MEMORY_AREA_INVALID (0)
{ #define MEMORY_AREA_SECTION_VIEW_COMMIT (1)
MEMORY_AREA_INVALID, #define MEMORY_AREA_CONTINUOUS_MEMORY (2)
MEMORY_AREA_SECTION_VIEW_COMMIT, #define MEMORY_AREA_NO_CACHE (3)
MEMORY_AREA_CONTINUOUS_MEMORY, #define MEMORY_AREA_IO_MAPPING (4)
MEMORY_AREA_NO_CACHE, #define MEMORY_AREA_SYSTEM (5)
MEMORY_AREA_IO_MAPPING, #define MEMORY_AREA_MDL_MAPPING (7)
MEMORY_AREA_SYSTEM, #define MEMORY_AREA_VIRTUAL_MEMORY (8)
MEMORY_AREA_MDL_MAPPING, #define MEMORY_AREA_SECTION_VIEW_RESERVE (9)
MEMORY_AREA_VIRTUAL_MEMORY, #define MEMORY_AREA_CACHE_SEGMENT (10)
MEMORY_AREA_SECTION_VIEW_RESERVE, #define MEMORY_AREA_SHARED_DATA (11)
MEMORY_AREA_CACHE_SEGMENT,
MEMORY_AREA_SHARED_DATA,
};
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \ #define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
((x) / (4*1024*1024)) ((x) / (4*1024*1024))
@ -42,8 +40,27 @@ enum
#define SPE_DIRTY (0x8) #define SPE_DIRTY (0x8)
#define SPE_IN_PAGEFILE (0x10) #define SPE_IN_PAGEFILE (0x10)
/*
* Flags for section objects
*/
#define SO_PHYSICAL_MEMORY (0x1) #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 typedef struct
{ {
ULONG Pages[NR_SECTION_PAGE_ENTRIES]; ULONG Pages[NR_SECTION_PAGE_ENTRIES];
@ -259,7 +276,6 @@ VOID MmInit3(VOID);
NTSTATUS MmInitPagerThread(VOID); NTSTATUS MmInitPagerThread(VOID);
VOID MmInitKernelMap(PVOID BaseAddress); VOID MmInitKernelMap(PVOID BaseAddress);
unsigned int alloc_pool_region(unsigned int nr_pages);
VOID MmWaitForFreePages(VOID); VOID MmWaitForFreePages(VOID);
PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry); PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry);

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -172,18 +172,14 @@ IoCreateStreamFileObject (PFILE_OBJECT FileObject,
PFILE_OBJECT CreatedFileObject; PFILE_OBJECT CreatedFileObject;
DbgPrint("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n", DbgPrint("IoCreateStreamFileObject(FileObject %x, DeviceObject %x)\n",
FileObject, FileObject, DeviceObject);
DeviceObject
);
assert_irql (PASSIVE_LEVEL); assert_irql (PASSIVE_LEVEL);
CreatedFileObject = ObCreateObject ( CreatedFileObject = ObCreateObject (&FileHandle,
& FileHandle,
STANDARD_RIGHTS_REQUIRED, STANDARD_RIGHTS_REQUIRED,
NULL, NULL,
IoFileObjectType IoFileObjectType);
);
if (NULL == CreatedFileObject) if (NULL == CreatedFileObject)
{ {
return (NULL); return (NULL);
@ -197,7 +193,6 @@ IoCreateStreamFileObject (PFILE_OBJECT FileObject,
CreatedFileObject->DeviceObject = DeviceObject; CreatedFileObject->DeviceObject = DeviceObject;
CreatedFileObject->Vpb = DeviceObject->Vpb; CreatedFileObject->Vpb = DeviceObject->Vpb;
CreatedFileObject->Type = InternalFileType; CreatedFileObject->Type = InternalFileType;
//CreatedFileObject->Flags = CreatedFileObject->Flags | FO_DIRECT_DEVICE_OPEN;
CreatedFileObject->Flags |= FO_DIRECT_DEVICE_OPEN; CreatedFileObject->Flags |= FO_DIRECT_DEVICE_OPEN;
ZwClose (FileHandle); ZwClose (FileHandle);

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel

View file

@ -235,6 +235,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
*/ */
RtlInitAnsiString (&ProcedureName, RtlInitAnsiString (&ProcedureName,
"LdrInitializeThunk"); "LdrInitializeThunk");
DPRINT1("Getting address of system DLL entrypoint\n");
Status = LdrGetProcedureAddress ((PVOID)ImageBase, Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName, &ProcedureName,
0, 0,
@ -247,7 +248,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
ZwClose(NTDllSectionHandle); ZwClose(NTDllSectionHandle);
return (Status); return (Status);
} }
DPRINT("SystemDllEntryPoint 0x%08lx\n", DPRINT1("SystemDllEntryPoint 0x%08lx\n",
SystemDllEntryPoint); SystemDllEntryPoint);
*LdrStartupAddr = SystemDllEntryPoint; *LdrStartupAddr = SystemDllEntryPoint;

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -19,11 +19,12 @@
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
static MADDRESS_SPACE KernelAddressSpace; STATIC MADDRESS_SPACE KernelAddressSpace;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace) VOID
MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
{ {
(VOID)KeWaitForMutexObject(&AddressSpace->Lock, (VOID)KeWaitForMutexObject(&AddressSpace->Lock,
0, 0,
@ -32,12 +33,14 @@ VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
NULL); NULL);
} }
VOID MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace) VOID
MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
{ {
KeReleaseMutex(&AddressSpace->Lock, FALSE); KeReleaseMutex(&AddressSpace->Lock, FALSE);
} }
VOID MmInitializeKernelAddressSpace(VOID) VOID
MmInitializeKernelAddressSpace(VOID)
{ {
MmInitializeAddressSpace(NULL, &KernelAddressSpace); MmInitializeAddressSpace(NULL, &KernelAddressSpace);
} }
@ -52,7 +55,8 @@ PMADDRESS_SPACE MmGetKernelAddressSpace(VOID)
return(&KernelAddressSpace); return(&KernelAddressSpace);
} }
NTSTATUS MmInitializeAddressSpace(PEPROCESS Process, NTSTATUS
MmInitializeAddressSpace(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace) PMADDRESS_SPACE AddressSpace)
{ {
InitializeListHead(&AddressSpace->MAreaListHead); InitializeListHead(&AddressSpace->MAreaListHead);
@ -84,7 +88,8 @@ NTSTATUS MmInitializeAddressSpace(PEPROCESS Process,
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace) NTSTATUS
MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
{ {
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -69,11 +69,19 @@ MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
PBase = MmGetContinuousPages(NumberOfBytes, PBase = MmGetContinuousPages(NumberOfBytes,
HighestAcceptableAddress); HighestAcceptableAddress);
if (PBase == NULL)
{
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
0,
TRUE);
return(NULL);
}
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++) for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
{ {
MmCreateVirtualMapping(NULL, MmCreateVirtualMapping(NULL,
BaseAddress + (i * 4096), BaseAddress + (i * 4096),
PAGE_EXECUTE_READWRITE, PAGE_EXECUTE_READWRITE | PAGE_SYSTEM,
(ULONG)(PBase + (i * 4096))); (ULONG)(PBase + (i * 4096)));
} }
return(BaseAddress); return(BaseAddress);

View file

@ -475,7 +475,8 @@ VOID MmUnlockPage(PVOID PhysicalAddress)
} }
PVOID MmAllocPage(SWAPENTRY SavedSwapEntry) PVOID
MmAllocPage(SWAPENTRY SavedSwapEntry)
{ {
ULONG offset; ULONG offset;
PLIST_ENTRY ListEntry; PLIST_ENTRY ListEntry;
@ -518,7 +519,8 @@ PVOID MmAllocPage(SWAPENTRY SavedSwapEntry)
return((PVOID)offset); return((PVOID)offset);
} }
PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry) PVOID
MmMustAllocPage(SWAPENTRY SavedSwapEntry)
{ {
PVOID Page; PVOID Page;
@ -532,7 +534,8 @@ PVOID MmMustAllocPage(SWAPENTRY SavedSwapEntry)
return(Page); return(Page);
} }
PVOID MmAllocPageMaybeSwap(SWAPENTRY SavedSwapEntry) PVOID
MmAllocPageMaybeSwap(SWAPENTRY SavedSwapEntry)
{ {
PVOID Page; PVOID Page;
@ -545,7 +548,8 @@ PVOID MmAllocPageMaybeSwap(SWAPENTRY SavedSwapEntry)
return(Page); return(Page);
} }
NTSTATUS MmWaitForPage(PVOID PhysicalAddress) NTSTATUS
MmWaitForPage(PVOID PhysicalAddress)
{ {
NTSTATUS Status; NTSTATUS Status;
ULONG Start; ULONG Start;
@ -559,7 +563,8 @@ NTSTATUS MmWaitForPage(PVOID PhysicalAddress)
return(Status); return(Status);
} }
VOID MmClearWaitPage(PVOID PhysicalAddress) VOID
MmClearWaitPage(PVOID PhysicalAddress)
{ {
ULONG Start; ULONG Start;
@ -568,7 +573,8 @@ VOID MmClearWaitPage(PVOID PhysicalAddress)
KeClearEvent(&MmPageArray[Start].Event); KeClearEvent(&MmPageArray[Start].Event);
} }
VOID MmSetWaitPage(PVOID PhysicalAddress) VOID
MmSetWaitPage(PVOID PhysicalAddress)
{ {
ULONG Start; ULONG Start;

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -25,17 +25,23 @@
#define PA_BIT_PRESENT (0) #define PA_BIT_PRESENT (0)
#define PA_BIT_READWRITE (1) #define PA_BIT_READWRITE (1)
#define PA_BIT_USER (2) #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_BIT_DIRTY (6)
#define PA_PRESENT (1 << PA_BIT_PRESENT) #define PA_PRESENT (1 << PA_BIT_PRESENT)
#define PA_DIRTY (1 << PA_BIT_DIRTY) #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 PAGETABLE_MAP (0xf0000000)
#define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024))) #define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024)))
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
PULONG MmGetPageDirectory(void) PULONG
MmGetPageDirectory(VOID)
{ {
unsigned int page_dir=0; unsigned int page_dir=0;
__asm__("movl %%cr3,%0\n\t" __asm__("movl %%cr3,%0\n\t"
@ -43,7 +49,8 @@ PULONG MmGetPageDirectory(void)
return((PULONG)page_dir); return((PULONG)page_dir);
} }
static ULONG ProtectToPTE(ULONG flProtect) static ULONG
ProtectToPTE(ULONG flProtect)
{ {
ULONG Attributes = 0; ULONG Attributes = 0;
@ -53,12 +60,24 @@ static ULONG ProtectToPTE(ULONG flProtect)
} }
if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE) if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE)
{ {
Attributes = PA_WRITE | PA_USER; Attributes = PA_WRITE;
} }
if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE || if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE ||
flProtect & PAGE_EXECUTE_READ) 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(Attributes);
} }
@ -448,9 +467,8 @@ NTSTATUS MmCreateVirtualMapping(PEPROCESS Process,
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
VOID MmSetPageProtect(PEPROCESS Process, VOID
PVOID Address, MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
ULONG flProtect)
{ {
ULONG Attributes = 0; ULONG Attributes = 0;
PULONG PageEntry; PULONG PageEntry;
@ -471,7 +489,8 @@ VOID MmSetPageProtect(PEPROCESS Process,
} }
} }
PHYSICAL_ADDRESS STDCALL MmGetPhysicalAddress(PVOID vaddr) PHYSICAL_ADDRESS STDCALL
MmGetPhysicalAddress(PVOID vaddr)
/* /*
* FUNCTION: Returns the physical address corresponding to a virtual address * FUNCTION: Returns the physical address corresponding to a virtual address
*/ */

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -47,7 +47,8 @@
* REVISIONS * REVISIONS
* *
*/ */
PVOID STDCALL MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress, PVOID STDCALL
MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
IN ULONG NumberOfBytes, IN ULONG NumberOfBytes,
IN BOOLEAN CacheEnable) IN BOOLEAN CacheEnable)
{ {
@ -69,17 +70,18 @@ PVOID STDCALL MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
{ {
return (NULL); return (NULL);
} }
Attributes = PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM; Attributes = PAGE_EXECUTE_READWRITE | PAGE_SYSTEM;
if (!CacheEnable) if (!CacheEnable)
{ {
Attributes |= (PA_PWT | PA_PCD); Attributes |= (PAGE_NOCACHE | PAGE_WRITETHROUGH);
} }
for (i = 0; (i <= (NumberOfBytes / PAGESIZE)); i++) for (i = 0; (i <= (NumberOfBytes / PAGESIZE)); i++)
{ {
Status = MmCreateVirtualMapping (NULL, Status =
MmCreateVirtualMapping (NULL,
(Result + (i * PAGESIZE)), (Result + (i * PAGESIZE)),
PAGE_READWRITE, Attributes,
(PhysicalAddress.u.LowPart + (i * PAGESIZE))); PhysicalAddress.u.LowPart + (i * PAGESIZE));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Unable to create virtual mapping\n"); DbgPrint("Unable to create virtual mapping\n");
@ -127,33 +129,20 @@ VOID STDCALL MmUnmapIoSpace (IN PVOID BaseAddress,
* NAME EXPORTED * NAME EXPORTED
* MmMapVideoDisplay@16 * MmMapVideoDisplay@16
*/ */
PVOID PVOID STDCALL
STDCALL MmMapVideoDisplay (IN PHYSICAL_ADDRESS PhysicalAddress,
MmMapVideoDisplay (
IN PHYSICAL_ADDRESS PhysicalAddress,
IN ULONG NumberOfBytes, IN ULONG NumberOfBytes,
IN MEMORY_CACHING_TYPE CacheType IN MEMORY_CACHING_TYPE CacheType)
)
{ {
return MmMapIoSpace ( return MmMapIoSpace (PhysicalAddress, NumberOfBytes, CacheType);
PhysicalAddress,
NumberOfBytes,
CacheType
);
} }
VOID VOID STDCALL
STDCALL MmUnmapVideoDisplay (IN PVOID BaseAddress,
MmUnmapVideoDisplay ( IN ULONG NumberOfBytes)
IN PVOID BaseAddress,
IN ULONG NumberOfBytes
)
{ {
MmUnmapIoSpace ( MmUnmapIoSpace (BaseAddress, NumberOfBytes);
BaseAddress,
NumberOfBytes
);
} }

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -34,7 +34,8 @@ static PVOID kernel_pool_base;
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
VOID ExUnmapPage(PVOID Addr) VOID
ExUnmapPage(PVOID Addr)
{ {
KIRQL oldIrql; KIRQL oldIrql;
ULONG i = (Addr - kernel_pool_base) / PAGESIZE; ULONG i = (Addr - kernel_pool_base) / PAGESIZE;
@ -48,7 +49,8 @@ VOID ExUnmapPage(PVOID Addr)
KeReleaseSpinLock(&AllocMapLock, oldIrql); KeReleaseSpinLock(&AllocMapLock, oldIrql);
} }
PVOID ExAllocatePage(VOID) PVOID
ExAllocatePage(VOID)
{ {
KIRQL oldlvl; KIRQL oldlvl;
ULONG addr; ULONG addr;
@ -73,7 +75,7 @@ PVOID ExAllocatePage(VOID)
addr = (ULONG)(kernel_pool_base + (i*PAGESIZE)); addr = (ULONG)(kernel_pool_base + (i*PAGESIZE));
Status = MmCreateVirtualMapping(NULL, Status = MmCreateVirtualMapping(NULL,
(PVOID)addr, (PVOID)addr,
PAGE_READWRITE, PAGE_READWRITE | PAGE_SYSTEM,
PhysPage); PhysPage);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -88,13 +90,15 @@ PVOID ExAllocatePage(VOID)
return(NULL); return(NULL);
} }
VOID MmInitKernelMap(PVOID BaseAddress) VOID
MmInitKernelMap(PVOID BaseAddress)
{ {
kernel_pool_base = BaseAddress; kernel_pool_base = BaseAddress;
KeInitializeSpinLock(&AllocMapLock); 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 * FUNCTION: Allocates a region of pages within the nonpaged pool area
*/ */

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -311,3 +311,12 @@ VOID STDCALL MmMapMemoryDumpMdl (PVOID Unknown0)
} }
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -210,13 +210,10 @@ NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,
/* Miscellanea functions: they may fit somewhere else */ /* Miscellanea functions: they may fit somewhere else */
DWORD DWORD STDCALL
STDCALL MmAdjustWorkingSetSize (DWORD Unknown0,
MmAdjustWorkingSetSize (
DWORD Unknown0,
DWORD Unknown1, DWORD Unknown1,
DWORD Unknown2 DWORD Unknown2)
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
return (0); return (0);

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -44,12 +44,14 @@
* REVISIONS * REVISIONS
* *
*/ */
PVOID STDCALL MmAllocateNonCachedMemory(IN ULONG NumberOfBytes) PVOID STDCALL
MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
{ {
PVOID Result; PVOID Result;
MEMORY_AREA* marea; MEMORY_AREA* marea;
NTSTATUS Status; NTSTATUS Status;
ULONG i; ULONG i;
ULONG Attributes;
Result = NULL; Result = NULL;
Status = MmCreateMemoryArea (NULL, Status = MmCreateMemoryArea (NULL,
@ -63,17 +65,17 @@ PVOID STDCALL MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
{ {
return (NULL); 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, PVOID NPage;
(Result + (i * PAGESIZE)),
PAGE_READWRITE, NPage = MmAllocPageMaybeSwap(0);
(ULONG)MmAllocPage(0)); MmCreateVirtualMapping (NULL,
if (!NT_SUCCESS(Status)) Result + (i * PAGESIZE),
{ Attributes,
DbgPrint("Unable to create virtual mapping\n"); (ULONG)NPage);
KeBugCheck(0);
}
} }
return ((PVOID)Result); return ((PVOID)Result);
} }
@ -108,7 +110,7 @@ PVOID STDCALL MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress, VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
IN ULONG NumberOfBytes) IN ULONG NumberOfBytes)
{ {
MmFreeMemoryArea (&PsGetCurrentProcess()->AddressSpace, MmFreeMemoryArea (MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
NumberOfBytes, NumberOfBytes,
TRUE); TRUE);

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -76,6 +76,9 @@ static KSPIN_LOCK MmNpoolLock;
unsigned int EiFreeNonPagedPool = 0; unsigned int EiFreeNonPagedPool = 0;
unsigned int EiUsedNonPagedPool = 0; unsigned int EiUsedNonPagedPool = 0;
unsigned int
alloc_pool_region(unsigned int nr_pages);
/* FUNCTIONS ***************************************************************/ /* FUNCTIONS ***************************************************************/
VOID ExInitNonPagedPool(ULONG BaseAddress) VOID ExInitNonPagedPool(ULONG BaseAddress)

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -21,7 +21,7 @@
/* TYPES *********************************************************************/ /* TYPES *********************************************************************/
typedef struct _PPAGINGFILE typedef struct _PAGINGFILE
{ {
LIST_ENTRY PagingFileListEntry; LIST_ENTRY PagingFileListEntry;
PFILE_OBJECT FileObject; PFILE_OBJECT FileObject;
@ -347,3 +347,10 @@ NTSTATUS STDCALL NtCreatePagingFile(IN PUNICODE_STRING PageFileName,
/* EOF */ /* EOF */

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -27,7 +27,8 @@ POBJECT_TYPE EXPORTED MmSectionObjectType = NULL;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS MmWritePageSectionView(PMADDRESS_SPACE AddressSpace, NTSTATUS
MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MArea, PMEMORY_AREA MArea,
PVOID Address) PVOID Address)
{ {
@ -153,6 +154,7 @@ MmUnalignedLoadPageForSection(PMADDRESS_SPACE AddressSpace,
&IoStatus); &IoStatus);
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE) if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
{ {
DPRINT("IoPageRead failed (%x)\n", Status);
MmLockAddressSpace(AddressSpace); MmLockAddressSpace(AddressSpace);
return(Status); return(Status);
} }
@ -434,7 +436,7 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
/* /*
* FIXME: What do we know in this case? * FIXME: What do we know in this case?
*/ */
DPRINT("IoPageRead failed (Status %x)\n", Status);
MmLockAddressSpace(AddressSpace); MmLockAddressSpace(AddressSpace);
return(Status); return(Status);
} }
@ -481,7 +483,7 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
KeBugCheck(0); KeBugCheck(0);
} }
MmUnlockSection(Section); MmUnlockSection(Section);
DPRINT("MmNotPresentFaultSectionView succeeded\n");
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -35,7 +35,8 @@ typedef struct _MM_SEGMENT
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
PMM_SEGMENT MmGetSegmentForAddress(PMEMORY_AREA MArea, PMM_SEGMENT
MmGetSegmentForAddress(PMEMORY_AREA MArea,
PVOID Address, PVOID Address,
PVOID* PCurrentAddress) PVOID* PCurrentAddress)
/* /*
@ -46,7 +47,7 @@ PMM_SEGMENT MmGetSegmentForAddress(PMEMORY_AREA MArea,
* Address (IN) = The address to get the segment for * Address (IN) = The address to get the segment for
* PCurrentAddress (OUT) = The start of the segment * PCurrentAddress (OUT) = The start of the segment
* RETURNS: * RETURNS:
* The corresponding memory or NULL if an error occurred * The corresponding segment or NULL if an error occurred
*/ */
{ {
PVOID CurrentAddress; PVOID CurrentAddress;
@ -81,7 +82,8 @@ PMM_SEGMENT MmGetSegmentForAddress(PMEMORY_AREA MArea,
return(NULL); return(NULL);
} }
NTSTATUS MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace, NTSTATUS
MmWritePageVirtualMemory(PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MArea, PMEMORY_AREA MArea,
PVOID Address) PVOID Address)
{ {
@ -196,7 +198,8 @@ ULONG MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace,
return(0); return(0);
} }
NTSTATUS MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace, NTSTATUS
MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
MEMORY_AREA* MemoryArea, MEMORY_AREA* MemoryArea,
PVOID Address) PVOID Address)
/* /*
@ -284,7 +287,8 @@ NTSTATUS MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
VOID MmModifyAttributes(PMADDRESS_SPACE AddressSpace, VOID STATIC
MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress, PVOID BaseAddress,
ULONG RegionSize, ULONG RegionSize,
ULONG OldType, ULONG OldType,
@ -295,8 +299,11 @@ VOID MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
* FUNCTION: Modify the attributes of a memory region * FUNCTION: Modify the attributes of a memory region
*/ */
{ {
if (NewType == MEM_RESERVE && /*
OldType == MEM_COMMIT) * 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; ULONG i;
@ -311,14 +318,22 @@ VOID MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
BaseAddress + (i*PAGESIZE)); BaseAddress + (i*PAGESIZE));
MmDereferencePage((PVOID)(ULONG)(PhysicalAddr.u.LowPart)); 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 && if (NewType == MEM_COMMIT && OldType == MEM_COMMIT &&
OldProtect != NewProtect) OldProtect != NewProtect)
{ {
ULONG i; ULONG i;
for (i=0; i<(RegionSize/PAGESIZE); i++) for (i=0; i <= (RegionSize/PAGESIZE); i++)
{ {
if (MmIsPagePresent(AddressSpace->Process, if (MmIsPagePresent(AddressSpace->Process,
BaseAddress + (i*PAGESIZE))) BaseAddress + (i*PAGESIZE)))
@ -331,7 +346,8 @@ VOID MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
} }
} }
VOID InsertAfterEntry(PLIST_ENTRY Previous, VOID STATIC
InsertAfterEntry(PLIST_ENTRY Previous,
PLIST_ENTRY Entry) PLIST_ENTRY Entry)
/* /*
* FUNCTION: Insert a list entry after another entry in the list * FUNCTION: Insert a list entry after another entry in the list
@ -345,7 +361,9 @@ VOID InsertAfterEntry(PLIST_ENTRY Previous,
Previous->Flink = Entry; Previous->Flink = Entry;
} }
VOID MmDumpSegmentsMemoryArea(PMEMORY_AREA MemoryArea) #if 0
VOID STATIC
MmDumpSegmentsMemoryArea(PMEMORY_AREA MemoryArea)
{ {
PVOID CurrentAddress; PVOID CurrentAddress;
PLIST_ENTRY CurrentEntry; PLIST_ENTRY CurrentEntry;
@ -372,8 +390,10 @@ VOID MmDumpSegmentsMemoryArea(PMEMORY_AREA MemoryArea)
CurrentEntry = CurrentEntry->Flink; CurrentEntry = CurrentEntry->Flink;
} }
} }
#endif
NTSTATUS MmSplitSegment(PMADDRESS_SPACE AddressSpace, NTSTATUS
MmSplitSegment(PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MemoryArea, PMEMORY_AREA MemoryArea,
PVOID RegionAddress, PVOID RegionAddress,
ULONG RegionLength, ULONG RegionLength,
@ -398,6 +418,15 @@ NTSTATUS MmSplitSegment(PMADDRESS_SPACE AddressSpace,
OldProtect = FirstSegment->Protect; OldProtect = FirstSegment->Protect;
OldLength = FirstSegment->Length; 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 * Allocate the segment we might need here because if the allocation
* fails below it will be difficult to undo what we've done already. * fails below it will be difficult to undo what we've done already.
@ -408,15 +437,6 @@ NTSTATUS MmSplitSegment(PMADDRESS_SPACE AddressSpace,
return(STATUS_NO_MEMORY); 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) if (FirstAddress < RegionAddress)
{ {
/* /*
@ -710,10 +730,11 @@ NTSTATUS MmComplexVirtualMemoryOperation(PMADDRESS_SPACE AddressSpace,
} }
NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
IN OUT PVOID* PBaseAddress, NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
IN OUT PVOID* UBaseAddress,
IN ULONG ZeroBits, IN ULONG ZeroBits,
IN OUT PULONG PRegionSize, IN OUT PULONG URegionSize,
IN ULONG AllocationType, IN ULONG AllocationType,
IN ULONG Protect) IN ULONG Protect)
/* /*
@ -753,15 +774,28 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
PMM_SEGMENT Segment; PMM_SEGMENT Segment;
PVOID BaseAddress; PVOID BaseAddress;
ULONG RegionSize; ULONG RegionSize;
PVOID PBaseAddress;
ULONG PRegionSize;
DPRINT("NtAllocateVirtualMemory(ProcessHandle %x, *BaseAddress %x, " DPRINT("NtAllocateVirtualMemory(ProcessHandle %x, *BaseAddress %x, "
"ZeroBits %d, *RegionSize %x, AllocationType %x, Protect %x)\n", "ZeroBits %d, *RegionSize %x, AllocationType %x, Protect %x)\n",
ProcessHandle,*BaseAddress,ZeroBits,*RegionSize,AllocationType, ProcessHandle,*BaseAddress,ZeroBits,*RegionSize,AllocationType,
Protect); Protect);
BaseAddress = (PVOID)PAGE_ROUND_DOWN((*PBaseAddress)); /*
RegionSize = PAGE_ROUND_UP((*PBaseAddress) + (*PRegionSize)) - * Check the validity of the parameters
PAGE_ROUND_DOWN((*PBaseAddress)); */
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, Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_OPERATION, PROCESS_VM_OPERATION,
@ -855,8 +889,8 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
MmReserveSwapPages(RegionSize); MmReserveSwapPages(RegionSize);
} }
*PBaseAddress = BaseAddress; *UBaseAddress = BaseAddress;
*PRegionSize = RegionSize; *URegionSize = RegionSize;
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process); ObDereferenceObject(Process);
@ -864,7 +898,8 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
} }
NTSTATUS STDCALL NtFlushVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
NtFlushVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress, IN PVOID BaseAddress,
IN ULONG NumberOfBytesToFlush, IN ULONG NumberOfBytesToFlush,
OUT PULONG NumberOfBytesFlushed OPTIONAL) OUT PULONG NumberOfBytesFlushed OPTIONAL)
@ -883,7 +918,8 @@ NTSTATUS STDCALL NtFlushVirtualMemory(IN HANDLE ProcessHandle,
} }
NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
NtFreeVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID* PBaseAddress, IN PVOID* PBaseAddress,
IN PULONG PRegionSize, IN PULONG PRegionSize,
IN ULONG FreeType) IN ULONG FreeType)
@ -997,7 +1033,8 @@ NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle,
} }
NTSTATUS STDCALL NtLockVirtualMemory(HANDLE ProcessHandle, NTSTATUS STDCALL
NtLockVirtualMemory(HANDLE ProcessHandle,
PVOID BaseAddress, PVOID BaseAddress,
ULONG NumberOfBytesToLock, ULONG NumberOfBytesToLock,
PULONG NumberOfBytesLocked) PULONG NumberOfBytesLocked)
@ -1006,7 +1043,8 @@ NTSTATUS STDCALL NtLockVirtualMemory(HANDLE ProcessHandle,
} }
VOID MmChangeAreaProtection(PEPROCESS Process, VOID
MmChangeAreaProtection(PEPROCESS Process,
PVOID BaseAddress, PVOID BaseAddress,
ULONG Length, ULONG Length,
ULONG Protect) ULONG Protect)
@ -1179,7 +1217,8 @@ NTSTATUS STDCALL NtQueryVirtualMemory (IN HANDLE ProcessHandle,
} }
NTSTATUS STDCALL NtReadVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
NtReadVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress, IN PVOID BaseAddress,
OUT PVOID Buffer, OUT PVOID Buffer,
IN ULONG NumberOfBytesToRead, IN ULONG NumberOfBytesToRead,
@ -1226,7 +1265,8 @@ NTSTATUS STDCALL NtReadVirtualMemory(IN HANDLE ProcessHandle,
} }
NTSTATUS STDCALL NtUnlockVirtualMemory(HANDLE ProcessHandle, NTSTATUS STDCALL
NtUnlockVirtualMemory(HANDLE ProcessHandle,
PVOID BaseAddress, PVOID BaseAddress,
ULONG NumberOfBytesToUnlock, ULONG NumberOfBytesToUnlock,
PULONG NumberOfBytesUnlocked OPTIONAL) PULONG NumberOfBytesUnlocked OPTIONAL)
@ -1235,7 +1275,8 @@ NTSTATUS STDCALL NtUnlockVirtualMemory(HANDLE ProcessHandle,
} }
NTSTATUS STDCALL NtWriteVirtualMemory(IN HANDLE ProcessHandle, NTSTATUS STDCALL
NtWriteVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress, IN PVOID BaseAddress,
IN PVOID Buffer, IN PVOID Buffer,
IN ULONG NumberOfBytesToWrite, IN ULONG NumberOfBytesToWrite,

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -198,3 +198,4 @@ BOOLEAN MmAddPageToWorkingSet(PEPROCESS Process,
} }