ReactOS  0.4.14-dev-337-gf981a68
fs.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for fs.c:

Go to the source code of this file.

Classes

struct  tagFILEDATA
 
struct  tagDEVICE
 

Macros

#define TAG_DEVICE_NAME   'NDsF'
 
#define TAG_DEVICE   'vDsF'
 

Typedefs

typedef struct tagFILEDATA FILEDATA
 
typedef struct tagDEVICE DEVICE
 

Functions

 DBG_DEFAULT_CHANNEL (FILESYSTEM)
 
ARC_STATUS ArcOpen (CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
 
ARC_STATUS ArcClose (ULONG FileId)
 
ARC_STATUS ArcRead (ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
 
ARC_STATUS ArcSeek (ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
 
ARC_STATUS ArcGetFileInformation (ULONG FileId, FILEINFORMATION *Information)
 
VOID FileSystemError (PCSTR ErrorString)
 
ARC_STATUS FsOpenFile (IN PCSTR FileName, IN PCSTR DefaultPath OPTIONAL, IN OPENMODE OpenMode, OUT PULONG FileId)
 
ULONG FsGetNumPathParts (PCSTR Path)
 
VOID FsGetFirstNameFromPath (PCHAR Buffer, PCSTR Path)
 
VOID FsRegisterDevice (CHAR *Prefix, const DEVVTBL *FuncTable)
 
PCWSTR FsGetServiceName (ULONG FileId)
 
VOID FsSetDeviceSpecific (ULONG FileId, VOID *Specific)
 
VOIDFsGetDeviceSpecific (ULONG FileId)
 
ULONG FsGetDeviceId (ULONG FileId)
 
VOID FsInit (VOID)
 

Variables

static FILEDATA FileData [MAX_FDS]
 
static LIST_ENTRY DeviceListHead
 

Macro Definition Documentation

◆ TAG_DEVICE

#define TAG_DEVICE   'vDsF'

Definition at line 31 of file fs.c.

◆ TAG_DEVICE_NAME

#define TAG_DEVICE_NAME   'NDsF'

Definition at line 30 of file fs.c.

Typedef Documentation

◆ DEVICE

◆ FILEDATA

Function Documentation

◆ ArcClose()

ARC_STATUS ArcClose ( ULONG  FileId)

Definition at line 218 of file fs.c.

219 {
221 
222  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
223  return EBADF;
224 
225  Status = FileData[FileId].FuncTable->Close(FileId);
226 
227  if (Status == ESUCCESS)
228  {
229  FileData[FileId].FuncTable = NULL;
230  FileData[FileId].Specific = NULL;
231  FileData[FileId].DeviceId = -1;
232  }
233  return Status;
234 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
VOID * Specific
Definition: fs.c:39
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
Definition: arc.h:36
ARC_CLOSE Close
Definition: fs.h:26
smooth NULL
Definition: ftsmooth.c:416
#define MAX_FDS
Definition: fs.h:34
ULONG DeviceId
Definition: fs.c:35
const DEVVTBL * FuncTable
Definition: fs.c:37
Status
Definition: gdiplustypes.h:24

Referenced by InfOpenFile(), IniFileInitialize(), InitOperatingSystemList(), PeLdrLoadImage(), RamDiskLoadVirtualFile(), SpiScanDevice(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ ArcGetFileInformation()

ARC_STATUS ArcGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)

Definition at line 250 of file fs.c.

251 {
252  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
253  return EBADF;
254  return FileData[FileId].FuncTable->GetFileInformation(FileId, Information);
255 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
Definition: arc.h:36
#define MAX_FDS
Definition: fs.h:34
const DEVVTBL * FuncTable
Definition: fs.c:37
ARC_GET_FILE_INFORMATION GetFileInformation
Definition: fs.h:27
Iosb Information
Definition: create.c:4377

Referenced by FatMount(), FrLdrLoadModule(), InfOpenFile(), IniFileInitialize(), RamDiskLoadVirtualFile(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ ArcOpen()

ARC_STATUS ArcOpen ( CHAR Path,
OPENMODE  OpenMode,
ULONG FileId 
)

Definition at line 56 of file fs.c.

57 {
59  ULONG Count, i;
60  PLIST_ENTRY pEntry;
61  DEVICE* pDevice;
63  CHAR* FileName;
64  CHAR* p;
65  CHAR* q;
66  SIZE_T Length;
67  OPENMODE DeviceOpenMode;
68  ULONG DeviceId;
69 
70  /* Print status message */
71  TRACE("Opening file '%s'...\n", Path);
72 
73  *FileId = MAX_FDS;
74 
75  /* Search last ')', which delimits device and path */
76  FileName = strrchr(Path, ')');
77  if (!FileName)
78  return EINVAL;
79  FileName++;
80 
81  /* Count number of "()", which needs to be replaced by "(0)" */
82  Count = 0;
83  for (p = Path; p != FileName; p++)
84  {
85  if (*p == '(' && *(p + 1) == ')')
86  Count++;
87  }
88 
89  /* Duplicate device name, and replace "()" by "(0)" (if required) */
90  Length = FileName - Path + Count;
91  if (Count != 0)
92  {
94  if (!DeviceName)
95  return ENOMEM;
96  for (p = Path, q = DeviceName; p != FileName; p++)
97  {
98  *q++ = *p;
99  if (*p == '(' && *(p + 1) == ')')
100  *q++ = '0';
101  }
102  }
103  else
104  {
105  DeviceName = Path;
106  }
107 
108  /* Search for the device */
109  if (OpenMode == OpenReadOnly || OpenMode == OpenWriteOnly)
110  DeviceOpenMode = OpenMode;
111  else
112  DeviceOpenMode = OpenReadWrite;
113 
114  pEntry = DeviceListHead.Flink;
115  while (pEntry != &DeviceListHead)
116  {
117  pDevice = CONTAINING_RECORD(pEntry, DEVICE, ListEntry);
118  if (strncmp(pDevice->Prefix, DeviceName, Length) == 0)
119  {
120  /* OK, device found. It is already opened? */
121  if (pDevice->ReferenceCount == 0)
122  {
123  /* Search some room for the device */
124  for (DeviceId = 0; DeviceId < MAX_FDS; DeviceId++)
125  {
126  if (!FileData[DeviceId].FuncTable)
127  break;
128  }
129  if (DeviceId == MAX_FDS)
130  return EMFILE;
131 
132  /* Try to open the device */
133  FileData[DeviceId].FuncTable = pDevice->FuncTable;
134  Status = pDevice->FuncTable->Open(pDevice->Prefix, DeviceOpenMode, &DeviceId);
135  if (Status != ESUCCESS)
136  {
137  FileData[DeviceId].FuncTable = NULL;
138  return Status;
139  }
140  else if (!*FileName)
141  {
142  /* Done, caller wanted to open the raw device */
143  *FileId = DeviceId;
144  pDevice->ReferenceCount++;
145  return ESUCCESS;
146  }
147 
148  /* Try to detect the file system */
149 #ifndef _M_ARM
150  FileData[DeviceId].FileFuncTable = IsoMount(DeviceId);
151  if (!FileData[DeviceId].FileFuncTable)
152 #endif
153  FileData[DeviceId].FileFuncTable = FatMount(DeviceId);
154  if (!FileData[DeviceId].FileFuncTable)
155  FileData[DeviceId].FileFuncTable = BtrFsMount(DeviceId);
156 #ifndef _M_ARM
157  if (!FileData[DeviceId].FileFuncTable)
158  FileData[DeviceId].FileFuncTable = NtfsMount(DeviceId);
159  if (!FileData[DeviceId].FileFuncTable)
160  FileData[DeviceId].FileFuncTable = Ext2Mount(DeviceId);
161 #endif
162 #if defined(_M_IX86) || defined(_M_AMD64)
163  if (!FileData[DeviceId].FileFuncTable)
164  FileData[DeviceId].FileFuncTable = PxeMount(DeviceId);
165 #endif
166  if (!FileData[DeviceId].FileFuncTable)
167  {
168  /* Error, unable to detect file system */
169  pDevice->FuncTable->Close(DeviceId);
170  FileData[DeviceId].FuncTable = NULL;
171  return ENODEV;
172  }
173 
174  pDevice->DeviceId = DeviceId;
175  }
176  else
177  {
178  DeviceId = pDevice->DeviceId;
179  }
180  pDevice->ReferenceCount++;
181  break;
182  }
183  pEntry = pEntry->Flink;
184  }
185  if (pEntry == &DeviceListHead)
186  return ENODEV;
187 
188  /* At this point, device is found and opened. Its file id is stored
189  * in DeviceId, and FileData[DeviceId].FileFuncTable contains what
190  * needs to be called to open the file */
191 
192  /* Search some room for the device */
193  for (i = 0; i < MAX_FDS; i++)
194  {
195  if (!FileData[i].FuncTable)
196  break;
197  }
198  if (i == MAX_FDS)
199  return EMFILE;
200 
201  /* Skip leading path separator, if any */
202  if (*FileName == '\\' || *FileName == '/')
203  FileName++;
204 
205  /* Open the file */
207  FileData[i].DeviceId = DeviceId;
208  *FileId = i;
209  Status = FileData[i].FuncTable->Open(FileName, OpenMode, FileId);
210  if (Status != ESUCCESS)
211  {
213  *FileId = MAX_FDS;
214  }
215  return Status;
216 }
const DEVVTBL * FileFuncTable
Definition: fs.c:38
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
#define TAG_DEVICE_NAME
Definition: fs.c:30
ULONG ReferenceCount
Definition: fs.c:48
static LIST_ENTRY DeviceListHead
Definition: fs.c:52
Definition: arc.h:32
Definition: arc.h:39
char CHAR
Definition: xmlstorage.h:175
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
ULONG ARC_STATUS
Definition: arc.h:4
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
WCHAR DeviceName[]
Definition: adapter.cpp:21
ARC_CLOSE Close
Definition: fs.h:26
Definition: arc.h:48
const DEVVTBL * NtfsMount(ULONG DeviceId)
Definition: ntfs.c:881
NTSTATUS FatMount(_In_ ULONG DeviceId, _In_ ULONG Unknown, _Out_ PBL_FILE_ENTRY *FileEntry)
Definition: fat.c:23
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
ARC_OPEN Open
Definition: fs.h:28
const DEVVTBL * FuncTable
Definition: fs.c:45
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
CHAR * Prefix
Definition: fs.c:46
#define MAX_FDS
Definition: fs.h:34
ULONG DeviceId
Definition: fs.c:35
const DEVVTBL * FuncTable
Definition: fs.c:37
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
Definition: arc.h:45
ULONG_PTR SIZE_T
Definition: typedefs.h:78
struct _FileName FileName
Definition: fatprocs.h:884
PRTL_UNICODE_STRING_BUFFER Path
const DEVVTBL * BtrFsMount(ULONG DeviceId)
Definition: btrfs.c:1257
Definition: arc.h:42
const DEVVTBL * IsoMount(ULONG DeviceId)
Definition: iso.c:495
const DEVVTBL * PxeMount(ULONG DeviceId)
Definition: pxe.c:309
const DEVVTBL * Ext2Mount(ULONG DeviceId)
Definition: ext2.c:1297
unsigned int ULONG
Definition: retypes.h:1
Definition: fs.c:42
ULONG DeviceId
Definition: fs.c:47
GLfloat GLfloat p
Definition: glext.h:8902
enum _OPENMODE OPENMODE

Referenced by FsOpenFile(), InfOpenFile(), InitOperatingSystemList(), PeLdrLoadImage(), SpiScanDevice(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ ArcRead()

ARC_STATUS ArcRead ( ULONG  FileId,
VOID Buffer,
ULONG  N,
ULONG Count 
)

Definition at line 236 of file fs.c.

237 {
238  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
239  return EBADF;
240  return FileData[FileId].FuncTable->Read(FileId, Buffer, N, Count);
241 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
Definition: arc.h:36
Definition: bufpool.h:45
ARC_READ Read
Definition: fs.h:29
#define MAX_FDS
Definition: fs.h:34
const DEVVTBL * FuncTable
Definition: fs.c:37

Referenced by disk_read(), Ext2Mount(), Ext2ReadSuperBlock(), Ext2ReadVolumeSectors(), FatMount(), FatReadVolumeSectors(), FrLdrLoadModule(), FrLdrMapModule(), InfOpenFile(), IniFileInitialize(), IopReadBootRecord(), IsoBufferDirectory(), IsoLookupFile(), IsoMount(), IsoRead(), NtfsDiskRead(), NtfsMount(), PeLdrLoadImage(), RamDiskLoadVirtualFile(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ ArcSeek()

ARC_STATUS ArcSeek ( ULONG  FileId,
LARGE_INTEGER Position,
SEEKMODE  SeekMode 
)

Definition at line 243 of file fs.c.

244 {
245  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
246  return EBADF;
247  return FileData[FileId].FuncTable->Seek(FileId, Position, SeekMode);
248 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
static COORD Position
Definition: mouse.c:34
Definition: arc.h:36
#define MAX_FDS
Definition: fs.h:34
const DEVVTBL * FuncTable
Definition: fs.c:37
ARC_SEEK Seek
Definition: fs.h:30

Referenced by disk_read(), Ext2Mount(), Ext2ReadSuperBlock(), Ext2ReadVolumeSectors(), FatMount(), FatReadVolumeSectors(), FrLdrMapModule(), IopReadBootRecord(), IsoBufferDirectory(), IsoLookupFile(), IsoMount(), IsoRead(), NtfsDiskRead(), NtfsMount(), PeLdrLoadImage(), and RamDiskLoadVirtualFile().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( FILESYSTEM  )

◆ FileSystemError()

VOID FileSystemError ( PCSTR  ErrorString)

Definition at line 259 of file fs.c.

260 {
261  ERR("%s\n", ErrorString);
262  UiMessageBox(ErrorString);
263 }
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:320
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by Ext2LookupFile(), Ext2ReadBlock(), Ext2ReadDirectory(), Ext2ReadFileBig(), Ext2ReadGroupDescriptors(), Ext2ReadInode(), Ext2ReadSuperBlock(), Ext2SearchDirectoryBufferForFile(), FatOpenVolume(), and NtfsMount().

◆ FsGetDeviceId()

ULONG FsGetDeviceId ( ULONG  FileId)

Definition at line 423 of file fs.c.

424 {
425  if (FileId >= MAX_FDS)
426  return (ULONG)-1;
427  return FileData[FileId].DeviceId;
428 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
#define MAX_FDS
Definition: fs.h:34
ULONG DeviceId
Definition: fs.c:35
unsigned int ULONG
Definition: retypes.h:1

Referenced by Ext2Open(), FatOpen(), IsoOpen(), IsoRead(), and NtfsOpen().

◆ FsGetDeviceSpecific()

VOID* FsGetDeviceSpecific ( ULONG  FileId)

Definition at line 416 of file fs.c.

417 {
418  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
419  return NULL;
420  return FileData[FileId].Specific;
421 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
VOID * Specific
Definition: fs.c:39
smooth NULL
Definition: ftsmooth.c:416
#define MAX_FDS
Definition: fs.h:34

Referenced by BtrFsClose(), BtrFsGetFileInformation(), BtrFsRead(), BtrFsSeek(), DiskClose(), DiskGetFileInformation(), DiskRead(), DiskSeek(), Ext2Close(), Ext2GetFileInformation(), Ext2Read(), Ext2Seek(), FatClose(), FatGetFileInformation(), FatRead(), FatSeek(), IsoClose(), IsoGetFileInformation(), IsoRead(), IsoSeek(), NtfsClose(), NtfsGetFileInformation(), NtfsRead(), and NtfsSeek().

◆ FsGetFirstNameFromPath()

VOID FsGetFirstNameFromPath ( PCHAR  Buffer,
PCSTR  Path 
)

Definition at line 356 of file fs.c.

357 {
358  size_t i;
359  size_t len;
360 
361  len = strlen(Path);
362 
363  // Copy all the characters up to the end of the
364  // string or until we hit a '\' character
365  // and put them in Buffer
366  for (i = 0; i < len; i++)
367  {
368  if ((Path[i] == '\\') || (Path[i] == '/'))
369  {
370  break;
371  }
372  else
373  {
374  Buffer[i] = Path[i];
375  }
376  }
377 
378  Buffer[i] = 0;
379 
380  TRACE("FsGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer);
381 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: bufpool.h:45
#define TRACE(s)
Definition: solgame.cpp:4
GLenum GLsizei len
Definition: glext.h:6722
PRTL_UNICODE_STRING_BUFFER Path

Referenced by Ext2LookupFile(), FatLookupFile(), IsoLookupFile(), and NtfsLookupFile().

◆ FsGetNumPathParts()

ULONG FsGetNumPathParts ( PCSTR  Path)

Definition at line 328 of file fs.c.

329 {
330  size_t i;
331  size_t len;
332  ULONG num;
333 
334  len = strlen(Path);
335 
336  for (i = 0, num = 0; i < len; i++)
337  {
338  if ((Path[i] == '\\') || (Path[i] == '/'))
339  {
340  num++;
341  }
342  }
343  num++;
344 
345  TRACE("FsGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num);
346 
347  return num;
348 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define TRACE(s)
Definition: solgame.cpp:4
GLuint GLuint num
Definition: glext.h:9618
GLenum GLsizei len
Definition: glext.h:6722
PRTL_UNICODE_STRING_BUFFER Path
unsigned int ULONG
Definition: retypes.h:1

Referenced by Ext2LookupFile(), FatLookupFile(), IsoLookupFile(), and NtfsLookupFile().

◆ FsGetServiceName()

PCWSTR FsGetServiceName ( ULONG  FileId)

Definition at line 402 of file fs.c.

403 {
404  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
405  return NULL;
406  return FileData[FileId].FuncTable->ServiceName;
407 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
PCWSTR ServiceName
Definition: fs.h:31
smooth NULL
Definition: ftsmooth.c:416
#define MAX_FDS
Definition: fs.h:34
const DEVVTBL * FuncTable
Definition: fs.c:37

Referenced by WinLdrLoadSystemHive().

◆ FsInit()

VOID FsInit ( VOID  )

Definition at line 430 of file fs.c.

431 {
432  ULONG i;
433 
434  RtlZeroMemory(FileData, sizeof(FileData));
435  for (i = 0; i < MAX_FDS; i++)
436  FileData[i].DeviceId = (ULONG)-1;
437 
439 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
static LIST_ENTRY DeviceListHead
Definition: fs.c:52
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MAX_FDS
Definition: fs.h:34
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by BootMain().

◆ FsOpenFile()

ARC_STATUS FsOpenFile ( IN PCSTR  FileName,
IN PCSTR DefaultPath  OPTIONAL,
IN OPENMODE  OpenMode,
OUT PULONG  FileId 
)

Definition at line 266 of file fs.c.

271 {
273  SIZE_T cchPathLen;
274  CHAR FullPath[MAX_PATH] = "";
275 
276  /*
277  * Check whether FileName is a full path and if not, create a full
278  * file name using the user-provided default path (if present).
279  *
280  * See ArcOpen(): Search last ')', which delimits device and path.
281  */
282  if (strrchr(FileName, ')') == NULL)
283  {
284  /* This is not a full path: prepend the user-provided default path */
285  if (DefaultPath)
286  {
287  Status = RtlStringCbCopyA(FullPath, sizeof(FullPath), DefaultPath);
288  if (!NT_SUCCESS(Status))
289  return ENAMETOOLONG;
290  }
291 
292  /* Append a path separator if needed */
293 
294  cchPathLen = min(sizeof(FullPath)/sizeof(CHAR), strlen(FullPath));
295  if (cchPathLen >= sizeof(FullPath)/sizeof(CHAR))
296  return ENAMETOOLONG;
297 
298  if ((*FileName != '\\' && *FileName != '/') &&
299  cchPathLen > 0 && (FullPath[cchPathLen-1] != '\\' && FullPath[cchPathLen-1] != '/'))
300  {
301  /* FileName does not start with '\' and FullPath does not end with '\' */
302  Status = RtlStringCbCatA(FullPath, sizeof(FullPath), "\\");
303  if (!NT_SUCCESS(Status))
304  return ENAMETOOLONG;
305  }
306  else if ((*FileName == '\\' || *FileName == '/') &&
307  cchPathLen > 0 && (FullPath[cchPathLen-1] == '\\' || FullPath[cchPathLen-1] == '/'))
308  {
309  /* FileName starts with '\' and FullPath ends with '\' */
310  while (*FileName == '\\' || *FileName == '/')
311  ++FileName; // Skip any backslash
312  }
313  }
314  /* Append (or just copy) the remaining file name */
315  Status = RtlStringCbCatA(FullPath, sizeof(FullPath), FileName);
316  if (!NT_SUCCESS(Status))
317  return ENAMETOOLONG;
318 
319  /* Open the file */
320  return ArcOpen(FullPath, OpenMode, FileId);
321 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
struct _FileName FileName
Definition: fatprocs.h:884
#define min(a, b)
Definition: monoChain.cc:55
NTSTRSAFEAPI RtlStringCbCatA(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:625

Referenced by IniFileInitialize(), and RamDiskLoadVirtualFile().

◆ FsRegisterDevice()

VOID FsRegisterDevice ( CHAR Prefix,
const DEVVTBL FuncTable 
)

Definition at line 383 of file fs.c.

384 {
385  DEVICE* pNewEntry;
386  SIZE_T Length;
387 
388  TRACE("FsRegisterDevice() Prefix = %s\n", Prefix);
389 
390  Length = strlen(Prefix) + 1;
391  pNewEntry = FrLdrTempAlloc(sizeof(DEVICE) + Length, TAG_DEVICE);
392  if (!pNewEntry)
393  return;
394  pNewEntry->FuncTable = FuncTable;
395  pNewEntry->ReferenceCount = 0;
396  pNewEntry->Prefix = (CHAR*)(pNewEntry + 1);
397  memcpy(pNewEntry->Prefix, Prefix, Length);
398 
399  InsertHeadList(&DeviceListHead, &pNewEntry->ListEntry);
400 }
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
ULONG ReferenceCount
Definition: fs.c:48
static LIST_ENTRY DeviceListHead
Definition: fs.c:52
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
char CHAR
Definition: xmlstorage.h:175
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:177
LIST_ENTRY ListEntry
Definition: fs.c:44
#define TRACE(s)
Definition: solgame.cpp:4
const DEVVTBL * FuncTable
Definition: fs.c:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
CHAR * Prefix
Definition: fs.c:46
#define TAG_DEVICE
Definition: fs.c:31
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG_PTR SIZE_T
Definition: typedefs.h:78
Definition: fs.c:42

Referenced by GetHarddiskInformation(), PcInitializeBootDevices(), PxeInit(), RamDiskInitialize(), SpiScanAdapter(), and SpiScanDevice().

◆ FsSetDeviceSpecific()

VOID FsSetDeviceSpecific ( ULONG  FileId,
VOID Specific 
)

Definition at line 409 of file fs.c.

410 {
411  if (FileId >= MAX_FDS || !FileData[FileId].FuncTable)
412  return;
413  FileData[FileId].Specific = Specific;
414 }
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
VOID * Specific
Definition: fs.c:39
#define MAX_FDS
Definition: fs.h:34

Referenced by BtrFsOpen(), DiskOpen(), Ext2Open(), FatOpen(), IsoOpen(), and NtfsOpen().

Variable Documentation

◆ DeviceListHead

LIST_ENTRY DeviceListHead
static

Definition at line 52 of file fs.c.

Referenced by ArcOpen(), FsInit(), and FsRegisterDevice().

◆ FileData