mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 20:03:12 +00:00
Removed some memory leaks
Moved from first-fit to best-fit for non-paged pool allocation Fixed bug in console driver (wasn't completing irps) Fixed bug in vfat fsd (didn't recognize paths of the form foo//bar) svn path=/trunk/; revision=196
This commit is contained in:
parent
a984daa5de
commit
3fcccd0b8c
4 changed files with 83 additions and 96 deletions
|
@ -626,14 +626,28 @@ NTSTATUS FindFile(PDEVICE_EXTENSION DeviceExt, PVfatFCB Fcb,
|
||||||
WCHAR name[256];
|
WCHAR name[256];
|
||||||
ULONG StartingSector;
|
ULONG StartingSector;
|
||||||
ULONG NextCluster;
|
ULONG NextCluster;
|
||||||
DPRINT("FindFile(Parent %x, FileToFind %w)\n",Parent,FileToFind);
|
WCHAR TempStr[2];
|
||||||
|
|
||||||
|
DPRINT("FindFile(Parent %x, FileToFind '%w')\n",Parent,FileToFind);
|
||||||
|
|
||||||
|
if (wcslen(FileToFind)==0)
|
||||||
|
{
|
||||||
|
TempStr[0] = (WCHAR)'.';
|
||||||
|
TempStr[1] = 0;
|
||||||
|
FileToFind=&TempStr;
|
||||||
|
}
|
||||||
|
if (Parent != NULL)
|
||||||
|
{
|
||||||
|
DPRINT("Parent->entry.FirstCluster %d\n",Parent->entry.FirstCluster);
|
||||||
|
}
|
||||||
|
|
||||||
if (Parent == NULL||Parent->entry.FirstCluster==1)
|
if (Parent == NULL||Parent->entry.FirstCluster==1)
|
||||||
{
|
{
|
||||||
Size = DeviceExt->rootDirectorySectors;//FIXME : in fat32, no limit
|
Size = DeviceExt->rootDirectorySectors;//FIXME : in fat32, no limit
|
||||||
StartingSector = DeviceExt->rootStart;
|
StartingSector = DeviceExt->rootStart;
|
||||||
NextCluster=0;
|
NextCluster=0;
|
||||||
if(FileToFind[0]==0 ||(FileToFind[0]=='\\' && FileToFind[1]==0))
|
if(FileToFind[0]==0 ||(FileToFind[0]=='\\' && FileToFind[1]==0) ||
|
||||||
|
(FileToFind[0]=='.' && FileToFind[1]==0))
|
||||||
{// it's root : complete essentials fields then return ok
|
{// it's root : complete essentials fields then return ok
|
||||||
memset(Fcb,0,sizeof(VfatFCB));
|
memset(Fcb,0,sizeof(VfatFCB));
|
||||||
memset(Fcb->entry.Filename,' ',11);
|
memset(Fcb->entry.Filename,' ',11);
|
||||||
|
@ -684,7 +698,7 @@ NTSTATUS FindFile(PDEVICE_EXTENSION DeviceExt, PVfatFCB Fcb,
|
||||||
}
|
}
|
||||||
if (GetEntryName((PVOID)block,&i,name,&j,DeviceExt,&StartingSector))
|
if (GetEntryName((PVOID)block,&i,name,&j,DeviceExt,&StartingSector))
|
||||||
{
|
{
|
||||||
// DPRINT("Comparing %w %w\n",name,FileToFind);
|
DPRINT("Comparing '%w' '%w'\n",name,FileToFind);
|
||||||
if (wstrcmpjoki(name,FileToFind))
|
if (wstrcmpjoki(name,FileToFind))
|
||||||
{
|
{
|
||||||
/* In the case of a long filename, the firstcluster is stored in
|
/* In the case of a long filename, the firstcluster is stored in
|
||||||
|
@ -780,10 +794,11 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
PWSTR AbsFileName=NULL;
|
PWSTR AbsFileName=NULL;
|
||||||
short i,j;
|
short i,j;
|
||||||
|
|
||||||
DPRINT("FsdOpenFile(%08lx, %08lx, %08lx)\n",
|
DPRINT("FsdOpenFile(%08lx, %08lx, %w)\n",
|
||||||
DeviceExt,
|
DeviceExt,
|
||||||
FileObject,
|
FileObject,
|
||||||
FileName);
|
FileName);
|
||||||
|
|
||||||
//FIXME : treat relative name
|
//FIXME : treat relative name
|
||||||
if(FileObject->RelatedFileObject)
|
if(FileObject->RelatedFileObject)
|
||||||
{
|
{
|
||||||
|
@ -834,63 +849,59 @@ DbgPrint("try related for %w\n",FileName);
|
||||||
memset(Fcb,0,sizeof(VfatFCB));
|
memset(Fcb,0,sizeof(VfatFCB));
|
||||||
Fcb->ObjectName=Fcb->PathName;
|
Fcb->ObjectName=Fcb->PathName;
|
||||||
next = &string[0];
|
next = &string[0];
|
||||||
current = next+1;
|
|
||||||
|
|
||||||
if(*next==0) // root
|
|
||||||
{
|
|
||||||
Status = FindFile(DeviceExt,Fcb,ParentFcb,next,NULL,NULL);
|
|
||||||
ParentFcb=Fcb;
|
|
||||||
Fcb=NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
while (next!=NULL)
|
while (next!=NULL)
|
||||||
{
|
{
|
||||||
*next = '\\';
|
*next = '\\';
|
||||||
current = next+1;
|
current = next+1;
|
||||||
next = wcschr(next+1,'\\');
|
next = wcschr(next+1,'\\');
|
||||||
if (next!=NULL)
|
if (next!=NULL)
|
||||||
*next=0;
|
{
|
||||||
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
|
*next=0;
|
||||||
if (Status != STATUS_SUCCESS)
|
}
|
||||||
{
|
DPRINT("current '%w'\n",current);
|
||||||
if (Fcb != NULL)
|
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
|
||||||
ExFreePool(Fcb);
|
if (Status != STATUS_SUCCESS)
|
||||||
if (ParentFcb != NULL)
|
{
|
||||||
ExFreePool(ParentFcb);
|
if (Fcb != NULL)
|
||||||
if(AbsFileName)ExFreePool(AbsFileName);
|
ExFreePool(Fcb);
|
||||||
return(Status);
|
if (ParentFcb != NULL)
|
||||||
}
|
ExFreePool(ParentFcb);
|
||||||
Temp = Fcb;
|
if(AbsFileName)ExFreePool(AbsFileName);
|
||||||
if (ParentFcb == NULL)
|
return(Status);
|
||||||
{
|
}
|
||||||
Fcb = ExAllocatePool(NonPagedPool,sizeof(VfatFCB));
|
Temp = Fcb;
|
||||||
memset(Fcb,0,sizeof(VfatFCB));
|
if (ParentFcb == NULL)
|
||||||
Fcb->ObjectName=Fcb->PathName;
|
{
|
||||||
}
|
Fcb = ExAllocatePool(NonPagedPool,sizeof(VfatFCB));
|
||||||
else Fcb = ParentFcb;
|
memset(Fcb,0,sizeof(VfatFCB));
|
||||||
ParentFcb = Temp;
|
Fcb->ObjectName=Fcb->PathName;
|
||||||
|
}
|
||||||
|
else Fcb = ParentFcb;
|
||||||
|
ParentFcb = Temp;
|
||||||
}
|
}
|
||||||
FileObject->FsContext =(PVOID) &ParentFcb->NTRequiredFCB;
|
FileObject->FsContext =(PVOID) &ParentFcb->NTRequiredFCB;
|
||||||
newCCB = ExAllocatePool(NonPagedPool,sizeof(VfatCCB));
|
newCCB = ExAllocatePool(NonPagedPool,sizeof(VfatCCB));
|
||||||
memset(newCCB,0,sizeof(VfatCCB));
|
memset(newCCB,0,sizeof(VfatCCB));
|
||||||
FileObject->FsContext2 = newCCB;
|
FileObject->FsContext2 = newCCB;
|
||||||
newCCB->pFcb=ParentFcb;
|
newCCB->pFcb=ParentFcb;
|
||||||
newCCB->PtrFileObject=FileObject;
|
newCCB->PtrFileObject=FileObject;
|
||||||
ParentFcb->RefCount++;
|
ParentFcb->RefCount++;
|
||||||
//FIXME : initialize all fields in FCB and CCB
|
//FIXME : initialize all fields in FCB and CCB
|
||||||
ParentFcb->nextFcb=pFirstFcb;
|
ParentFcb->nextFcb=pFirstFcb;
|
||||||
pFirstFcb=ParentFcb;
|
pFirstFcb=ParentFcb;
|
||||||
vfat_wcsncpy(ParentFcb->PathName,FileName,MAX_PATH);
|
vfat_wcsncpy(ParentFcb->PathName,FileName,MAX_PATH);
|
||||||
ParentFcb->ObjectName=ParentFcb->PathName+(current-FileName);
|
ParentFcb->ObjectName=ParentFcb->PathName+(current-FileName);
|
||||||
ParentFcb->pDevExt=DeviceExt;
|
ParentFcb->pDevExt=DeviceExt;
|
||||||
DPRINT("file open, fcb=%x\n",ParentFcb);
|
DPRINT("file open, fcb=%x\n",ParentFcb);
|
||||||
DPRINT("FileSize %d\n",ParentFcb->entry.FileSize);
|
DPRINT("FileSize %d\n",ParentFcb->entry.FileSize);
|
||||||
if(Fcb) ExFreePool(Fcb);
|
if(Fcb) ExFreePool(Fcb);
|
||||||
if(AbsFileName)ExFreePool(AbsFileName);
|
if(AbsFileName)ExFreePool(AbsFileName);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
|
|
||||||
|
BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Tests if the device contains a filesystem that can be mounted
|
* FUNCTION: Tests if the device contains a filesystem that can be mounted
|
||||||
* by this fsd
|
* by this fsd
|
||||||
|
|
|
@ -381,6 +381,7 @@ ZwSetValueKey
|
||||||
ZwUnmapViewOfSection
|
ZwUnmapViewOfSection
|
||||||
ZwWriteFile
|
ZwWriteFile
|
||||||
sprintf
|
sprintf
|
||||||
|
wcslen
|
||||||
wcschr
|
wcschr
|
||||||
wcsncat
|
wcsncat
|
||||||
wcsncpy
|
wcsncpy
|
||||||
|
|
|
@ -100,7 +100,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
|
||||||
PIO_STACK_LOCATION StackLoc;
|
PIO_STACK_LOCATION StackLoc;
|
||||||
PWSTR Remainder;
|
PWSTR Remainder;
|
||||||
|
|
||||||
DbgPrint("ZwCreateFile(FileHandle %x, DesiredAccess %x, "
|
DPRINT("ZwCreateFile(FileHandle %x, DesiredAccess %x, "
|
||||||
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %w)\n",
|
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %w)\n",
|
||||||
FileHandle,DesiredAccess,ObjectAttributes,
|
FileHandle,DesiredAccess,ObjectAttributes,
|
||||||
ObjectAttributes->ObjectName->Buffer);
|
ObjectAttributes->ObjectName->Buffer);
|
||||||
|
|
|
@ -607,8 +607,9 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type,
|
||||||
ULONG Tag,
|
ULONG Tag,
|
||||||
PVOID Caller)
|
PVOID Caller)
|
||||||
{
|
{
|
||||||
block_hdr* current=NULL;
|
block_hdr* current = NULL;
|
||||||
PVOID block;
|
PVOID block;
|
||||||
|
block_hdr* best = NULL;
|
||||||
|
|
||||||
POOL_TRACE("ExAllocatePool(NumberOfBytes %d) caller %x ",
|
POOL_TRACE("ExAllocatePool(NumberOfBytes %d) caller %x ",
|
||||||
size,Caller);
|
size,Caller);
|
||||||
|
@ -632,57 +633,31 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type,
|
||||||
*/
|
*/
|
||||||
current=free_list_head;
|
current=free_list_head;
|
||||||
|
|
||||||
|
// defrag_free_list();
|
||||||
|
|
||||||
while (current!=NULL)
|
while (current!=NULL)
|
||||||
{
|
{
|
||||||
OLD_DPRINT("current %x size %x next %x\n",current,current->size,
|
OLD_DPRINT("current %x size %x next %x\n",current,current->size,
|
||||||
current->next);
|
current->next);
|
||||||
if (current->magic != BLOCK_HDR_MAGIC)
|
if (current->size>=size &&
|
||||||
|
(best == NULL ||
|
||||||
|
current->size < best->size))
|
||||||
{
|
{
|
||||||
DbgPrint("Bad block magic (probable pool corruption) at %x\n",
|
best = current;
|
||||||
current);
|
|
||||||
KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
|
|
||||||
}
|
|
||||||
if (current->size>=size)
|
|
||||||
{
|
|
||||||
OLD_DPRINT("found block %x of size %d\n",current,size);
|
|
||||||
block=take_block(current,size);
|
|
||||||
VALIDATE_POOL;
|
|
||||||
memset(block,0,size);
|
|
||||||
POOL_TRACE("= %x\n",block);
|
|
||||||
return(block);
|
|
||||||
}
|
}
|
||||||
current=current->next;
|
current=current->next;
|
||||||
}
|
}
|
||||||
|
if (best != NULL)
|
||||||
if(EiFreeNonPagedPool>size+32*PAGESIZE)
|
{
|
||||||
{//try defrag free list before growing kernel pool
|
OLD_DPRINT("found block %x of size %d\n",best,size);
|
||||||
defrag_free_list();
|
block=take_block(best,size);
|
||||||
/*
|
VALIDATE_POOL;
|
||||||
* reLook after defrag
|
memset(block,0,size);
|
||||||
*/
|
POOL_TRACE("= %x\n",block);
|
||||||
current=free_list_head;
|
return(block);
|
||||||
|
|
||||||
while (current!=NULL)
|
|
||||||
{
|
|
||||||
OLD_DPRINT("current %x size %x next %x\n",current,current->size,
|
|
||||||
current->next);
|
|
||||||
if (current->magic != BLOCK_HDR_MAGIC)
|
|
||||||
{
|
|
||||||
DbgPrint("Bad block magic (probable pool corruption)\n");
|
|
||||||
KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
|
|
||||||
}
|
|
||||||
if (current->size>=size)
|
|
||||||
{
|
|
||||||
OLD_DPRINT("found block %x of size %d\n",current,size);
|
|
||||||
block=take_block(current,size);
|
|
||||||
memset(block,0,size);
|
|
||||||
POOL_TRACE("= %x\n",block);
|
|
||||||
return(block);
|
|
||||||
}
|
|
||||||
current=current->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Otherwise create a new block
|
* Otherwise create a new block
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue