mirror of
https://github.com/reactos/reactos.git
synced 2025-04-05 13:11:22 +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];
|
||||
ULONG StartingSector;
|
||||
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)
|
||||
{
|
||||
Size = DeviceExt->rootDirectorySectors;//FIXME : in fat32, no limit
|
||||
StartingSector = DeviceExt->rootStart;
|
||||
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
|
||||
memset(Fcb,0,sizeof(VfatFCB));
|
||||
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))
|
||||
{
|
||||
// DPRINT("Comparing %w %w\n",name,FileToFind);
|
||||
DPRINT("Comparing '%w' '%w'\n",name,FileToFind);
|
||||
if (wstrcmpjoki(name,FileToFind))
|
||||
{
|
||||
/* 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;
|
||||
short i,j;
|
||||
|
||||
DPRINT("FsdOpenFile(%08lx, %08lx, %08lx)\n",
|
||||
DPRINT("FsdOpenFile(%08lx, %08lx, %w)\n",
|
||||
DeviceExt,
|
||||
FileObject,
|
||||
FileName);
|
||||
|
||||
//FIXME : treat relative name
|
||||
if(FileObject->RelatedFileObject)
|
||||
{
|
||||
|
@ -833,64 +848,60 @@ DbgPrint("try related for %w\n",FileName);
|
|||
Fcb = ExAllocatePool(NonPagedPool, sizeof(VfatFCB));
|
||||
memset(Fcb,0,sizeof(VfatFCB));
|
||||
Fcb->ObjectName=Fcb->PathName;
|
||||
next = &string[0];
|
||||
current = next+1;
|
||||
|
||||
if(*next==0) // root
|
||||
{
|
||||
Status = FindFile(DeviceExt,Fcb,ParentFcb,next,NULL,NULL);
|
||||
ParentFcb=Fcb;
|
||||
Fcb=NULL;
|
||||
}
|
||||
else
|
||||
next = &string[0];
|
||||
|
||||
while (next!=NULL)
|
||||
{
|
||||
*next = '\\';
|
||||
current = next+1;
|
||||
next = wcschr(next+1,'\\');
|
||||
if (next!=NULL)
|
||||
*next=0;
|
||||
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
|
||||
if (Status != STATUS_SUCCESS)
|
||||
{
|
||||
if (Fcb != NULL)
|
||||
ExFreePool(Fcb);
|
||||
if (ParentFcb != NULL)
|
||||
ExFreePool(ParentFcb);
|
||||
if(AbsFileName)ExFreePool(AbsFileName);
|
||||
return(Status);
|
||||
}
|
||||
Temp = Fcb;
|
||||
if (ParentFcb == NULL)
|
||||
{
|
||||
Fcb = ExAllocatePool(NonPagedPool,sizeof(VfatFCB));
|
||||
memset(Fcb,0,sizeof(VfatFCB));
|
||||
Fcb->ObjectName=Fcb->PathName;
|
||||
}
|
||||
else Fcb = ParentFcb;
|
||||
ParentFcb = Temp;
|
||||
{
|
||||
*next=0;
|
||||
}
|
||||
DPRINT("current '%w'\n",current);
|
||||
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
|
||||
if (Status != STATUS_SUCCESS)
|
||||
{
|
||||
if (Fcb != NULL)
|
||||
ExFreePool(Fcb);
|
||||
if (ParentFcb != NULL)
|
||||
ExFreePool(ParentFcb);
|
||||
if(AbsFileName)ExFreePool(AbsFileName);
|
||||
return(Status);
|
||||
}
|
||||
Temp = Fcb;
|
||||
if (ParentFcb == NULL)
|
||||
{
|
||||
Fcb = ExAllocatePool(NonPagedPool,sizeof(VfatFCB));
|
||||
memset(Fcb,0,sizeof(VfatFCB));
|
||||
Fcb->ObjectName=Fcb->PathName;
|
||||
}
|
||||
else Fcb = ParentFcb;
|
||||
ParentFcb = Temp;
|
||||
}
|
||||
FileObject->FsContext =(PVOID) &ParentFcb->NTRequiredFCB;
|
||||
newCCB = ExAllocatePool(NonPagedPool,sizeof(VfatCCB));
|
||||
memset(newCCB,0,sizeof(VfatCCB));
|
||||
FileObject->FsContext2 = newCCB;
|
||||
newCCB->pFcb=ParentFcb;
|
||||
newCCB->PtrFileObject=FileObject;
|
||||
ParentFcb->RefCount++;
|
||||
//FIXME : initialize all fields in FCB and CCB
|
||||
ParentFcb->nextFcb=pFirstFcb;
|
||||
pFirstFcb=ParentFcb;
|
||||
FileObject->FsContext =(PVOID) &ParentFcb->NTRequiredFCB;
|
||||
newCCB = ExAllocatePool(NonPagedPool,sizeof(VfatCCB));
|
||||
memset(newCCB,0,sizeof(VfatCCB));
|
||||
FileObject->FsContext2 = newCCB;
|
||||
newCCB->pFcb=ParentFcb;
|
||||
newCCB->PtrFileObject=FileObject;
|
||||
ParentFcb->RefCount++;
|
||||
//FIXME : initialize all fields in FCB and CCB
|
||||
ParentFcb->nextFcb=pFirstFcb;
|
||||
pFirstFcb=ParentFcb;
|
||||
vfat_wcsncpy(ParentFcb->PathName,FileName,MAX_PATH);
|
||||
ParentFcb->ObjectName=ParentFcb->PathName+(current-FileName);
|
||||
ParentFcb->pDevExt=DeviceExt;
|
||||
DPRINT("file open, fcb=%x\n",ParentFcb);
|
||||
DPRINT("FileSize %d\n",ParentFcb->entry.FileSize);
|
||||
if(Fcb) ExFreePool(Fcb);
|
||||
if(AbsFileName)ExFreePool(AbsFileName);
|
||||
ParentFcb->ObjectName=ParentFcb->PathName+(current-FileName);
|
||||
ParentFcb->pDevExt=DeviceExt;
|
||||
DPRINT("file open, fcb=%x\n",ParentFcb);
|
||||
DPRINT("FileSize %d\n",ParentFcb->entry.FileSize);
|
||||
if(Fcb) ExFreePool(Fcb);
|
||||
if(AbsFileName)ExFreePool(AbsFileName);
|
||||
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
|
||||
* by this fsd
|
||||
|
|
|
@ -381,6 +381,7 @@ ZwSetValueKey
|
|||
ZwUnmapViewOfSection
|
||||
ZwWriteFile
|
||||
sprintf
|
||||
wcslen
|
||||
wcschr
|
||||
wcsncat
|
||||
wcsncpy
|
||||
|
|
|
@ -100,7 +100,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
|
|||
PIO_STACK_LOCATION StackLoc;
|
||||
PWSTR Remainder;
|
||||
|
||||
DbgPrint("ZwCreateFile(FileHandle %x, DesiredAccess %x, "
|
||||
DPRINT("ZwCreateFile(FileHandle %x, DesiredAccess %x, "
|
||||
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %w)\n",
|
||||
FileHandle,DesiredAccess,ObjectAttributes,
|
||||
ObjectAttributes->ObjectName->Buffer);
|
||||
|
|
|
@ -607,8 +607,9 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type,
|
|||
ULONG Tag,
|
||||
PVOID Caller)
|
||||
{
|
||||
block_hdr* current=NULL;
|
||||
block_hdr* current = NULL;
|
||||
PVOID block;
|
||||
block_hdr* best = NULL;
|
||||
|
||||
POOL_TRACE("ExAllocatePool(NumberOfBytes %d) caller %x ",
|
||||
size,Caller);
|
||||
|
@ -632,56 +633,30 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type,
|
|||
*/
|
||||
current=free_list_head;
|
||||
|
||||
// defrag_free_list();
|
||||
|
||||
while (current!=NULL)
|
||||
{
|
||||
OLD_DPRINT("current %x size %x next %x\n",current,current->size,
|
||||
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",
|
||||
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);
|
||||
best = current;
|
||||
}
|
||||
current=current->next;
|
||||
}
|
||||
|
||||
if(EiFreeNonPagedPool>size+32*PAGESIZE)
|
||||
{//try defrag free list before growing kernel pool
|
||||
defrag_free_list();
|
||||
/*
|
||||
* reLook after defrag
|
||||
*/
|
||||
current=free_list_head;
|
||||
|
||||
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;
|
||||
}
|
||||
if (best != NULL)
|
||||
{
|
||||
OLD_DPRINT("found block %x of size %d\n",best,size);
|
||||
block=take_block(best,size);
|
||||
VALIDATE_POOL;
|
||||
memset(block,0,size);
|
||||
POOL_TRACE("= %x\n",block);
|
||||
return(block);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Otherwise create a new block
|
||||
|
|
Loading…
Reference in a new issue