Author: hpoussin
Date: Sat Oct 17 16:05:34 2009
New Revision: 43529
URL:
http://svn.reactos.org/svn/reactos?rev=43529&view=rev
Log:
[freeldr] FAT driver: check for directory attribute before parsing the next part of
filename
Implement OpenDirectory mode in FAT driver
Modified:
trunk/reactos/boot/freeldr/freeldr/fs/fat.c
trunk/reactos/boot/freeldr/freeldr/include/fs/fat.h
Modified: trunk/reactos/boot/freeldr/freeldr/fs/fat.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/fs/fa…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/fs/fat.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/fs/fat.c [iso-8859-1] Sat Oct 17 16:05:34 2009
@@ -1,6 +1,7 @@
/*
* FreeLoader
* Copyright (C) 1998-2003 Brian Palmer <brianp(a)sginet.com>
+ * Copyright (C) 2009 Hervé Poussineau
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -598,6 +599,7 @@
//
// We found the entry, now fill in the FAT_FILE_INFO struct
//
+ FatFileInfoPointer->Attributes = DirEntry->Attr;
FatFileInfoPointer->FileSize = DirEntry->Size;
FatFileInfoPointer->FilePointer = 0;
@@ -791,6 +793,14 @@
//
if ((i+1) < NumberOfPathParts)
{
+ //
+ // Check if current entry is a directory
+ //
+ if (!FatFileInfo.Attributes & ATTR_DIRECTORY)
+ {
+ MmFreeMemory(FatFileInfo.FileFatChain);
+ return ENOTDIR;
+ }
DirectoryStartCluster = FatFileInfo.FileFatChain[0];
}
MmFreeMemory(FatFileInfo.FileFatChain);
@@ -1347,9 +1357,10 @@
FAT_FILE_INFO TempFileInfo;
PFAT_FILE_INFO FileHandle;
ULONG DeviceId;
+ BOOLEAN IsDirectory;
LONG ret;
- if (OpenMode != OpenReadOnly)
+ if (OpenMode != OpenReadOnly && OpenMode != OpenDirectory)
return EACCES;
DeviceId = FsGetDeviceId(*FileId);
@@ -1361,6 +1372,15 @@
ret = FatLookupFile(FatVolume, Path, DeviceId, &TempFileInfo);
if (ret != ESUCCESS)
return ENOENT;
+
+ //
+ // Check if caller opened what he expected (dir vs file)
+ //
+ IsDirectory = (TempFileInfo.Attributes & ATTR_DIRECTORY) != 0;
+ if (IsDirectory && OpenMode != OpenDirectory)
+ return EISDIR;
+ else if (!IsDirectory && OpenMode != OpenReadOnly)
+ return ENOTDIR;
FileHandle = MmHeapAlloc(sizeof(FAT_FILE_INFO));
if (!FileHandle)
Modified: trunk/reactos/boot/freeldr/freeldr/include/fs/fat.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/fs/fat.h [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/fs/fat.h [iso-8859-1] Sat Oct 17 16:05:34
2009
@@ -148,6 +148,7 @@
typedef struct
{
+ UCHAR Attributes; /* File attributes */
ULONG FileSize; /* File size */
ULONG FilePointer; /* File pointer */
ULONG* FileFatChain; /* File fat chain array */