ReactOS 0.4.16-dev-329-g9223134
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  tagDEVICE
 
struct  tagFILEDATA
 

Macros

#define TAG_DEVICE_NAME   'NDsF'
 
#define TAG_DEVICE   'vDsF'
 
#define IS_VALID_FILEID(FileId)    ((ULONG)(FileId) < _countof(FileData) && FileData[(ULONG)(FileId)].FuncTable)
 

Typedefs

typedef struct tagDEVICE DEVICE
 
typedef struct tagFILEDATA FILEDATA
 
typedef const DEVVTBL *(* PFS_MOUNT) (ULONG DeviceId)
 

Functions

 DBG_DEFAULT_CHANNEL (FILESYSTEM)
 
PCHAR NormalizeArcDeviceName (_In_ PCCH DeviceName, _Inout_ PSIZE_T Length)
 Replace "()" by "(0)" in the given ARC device name, if necessary.
 
ARC_STATUS ArcOpen (CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
 
static DEVICEFsGetDeviceById (ULONG DeviceId)
 
ARC_STATUS ArcClose (_In_ 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 (_In_ PCSTR DeviceName, _In_ const DEVVTBL *FuncTable)
 
PCWSTR FsGetServiceName (ULONG FileId)
 
VOID FsSetDeviceSpecific (ULONG FileId, PVOID Specific)
 
PVOID FsGetDeviceSpecific (ULONG FileId)
 
ULONG FsGetDeviceId (ULONG FileId)
 
VOID FsInit (VOID)
 

Variables

static FILEDATA FileData [MAX_FDS]
 
static LIST_ENTRY DeviceListHead
 
PFS_MOUNT FileSystems []
 

Macro Definition Documentation

◆ IS_VALID_FILEID

#define IS_VALID_FILEID (   FileId)     ((ULONG)(FileId) < _countof(FileData) && FileData[(ULONG)(FileId)].FuncTable)

Definition at line 54 of file fs.c.

◆ 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

◆ PFS_MOUNT

typedef const DEVVTBL *(* PFS_MOUNT) (ULONG DeviceId)

Definition at line 57 of file fs.c.

Function Documentation

◆ ArcClose()

ARC_STATUS ArcClose ( _In_ ULONG  FileId)

Definition at line 409 of file fs.c.

411{
412 ULONG DeviceId;
414
415 if (!IS_VALID_FILEID(FileId))
416 return EBADF;
417
418 /* Retrieve the parent device's ID if any, for later */
419 DeviceId = FileData[FileId].DeviceId;
420
421 /* Dereference the file and close it if needed */
422 ASSERT(FileData[FileId].ReferenceCount > 0);
423 if (--FileData[FileId].ReferenceCount == 0)
424 {
425 (void)FileData[FileId].FuncTable->Close(FileId);
427 FileData[FileId].FuncTable = NULL;
428 FileData[FileId].Specific = NULL;
429 }
430
431 /* Check whether this file actually references a device */
432 pDevice = FsGetDeviceById(FileId);
433 if (pDevice)
434 {
435 /* It does, dereference it */
436 ASSERT(pDevice->ReferenceCount > 0);
437 if (--pDevice->ReferenceCount == 0)
438 pDevice->DeviceId = INVALID_FILE_ID;
439 }
440
441 /* And dereference the parent device too, if there is one */
442 if (IS_VALID_FILEID(DeviceId))
443 ArcClose(DeviceId);
444
445 return ESUCCESS;
446}
#define EBADF
Definition: acclib.h:82
#define INVALID_FILE_ID
Definition: fs.h:35
#define IS_VALID_FILEID(FileId)
Definition: fs.c:54
ARC_STATUS ArcClose(_In_ ULONG FileId)
Definition: fs.c:409
static DEVICE * FsGetDeviceById(ULONG DeviceId)
Definition: fs.c:393
static FILEDATA FileData[MAX_FDS]
Definition: fs.c:51
#define NULL
Definition: types.h:112
FxDevice * pDevice
#define ASSERT(a)
Definition: mode.c:44
@ ESUCCESS
Definition: arc.h:32
Definition: fs.c:34
PVOID Specific
Definition: fs.c:48
const DEVVTBL * FuncTable
Definition: fs.c:47
ULONG DeviceId
Parent device's ID.
Definition: fs.c:45
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ArcClose(), InfOpenFile(), IniFileInitialize(), InitOperatingSystemList(), PeLdrLoadImageEx(), RamDiskLoadVirtualFile(), RegLoadHiveLog(), SpiScanDevice(), WinLdrLoadModule(), WinLdrLoadNLSData(), and WinLdrLoadSystemHive().

◆ ArcGetFileInformation()

ARC_STATUS ArcGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)

Definition at line 462 of file fs.c.

463{
464 if (!IS_VALID_FILEID(FileId))
465 return EBADF;
466 return FileData[FileId].FuncTable->GetFileInformation(FileId, Information);
467}
ARC_GET_FILE_INFORMATION GetFileInformation
Definition: fs.h:27
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

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

◆ ArcOpen()

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

Definition at line 219 of file fs.c.

220{
222 ULONG i;
228 OPENMODE DeviceOpenMode;
229 ULONG DeviceId;
230
231 /* Print status message */
232 TRACE("Opening file '%s'...\n", Path);
233
234 *FileId = INVALID_FILE_ID;
235
236 /* Search last ')', which delimits device and path */
237 FileName = strrchr(Path, ')');
238 if (!FileName)
239 return EINVAL;
240 ++FileName;
241
242 /* Normalize the device name, replacing "()" by "(0)" if necessary */
243 Length = FileName - Path;
245 if (!DeviceName)
246 return ENOMEM;
247
248 if (OpenMode == OpenReadOnly || OpenMode == OpenWriteOnly)
249 DeviceOpenMode = OpenMode;
250 else
251 DeviceOpenMode = OpenReadWrite;
252
253 /* Search for the registered device */
254 pDevice = NULL;
258 {
259 pDevice = CONTAINING_RECORD(pEntry, DEVICE, ListEntry);
260 if (strncmp(pDevice->DeviceName, DeviceName, Length) == 0)
261 break;
262 }
263
264 /* Cleanup */
265 if (DeviceName != Path)
268
269 if (pEntry == &DeviceListHead)
270 return ENODEV;
271
272 /* OK, device found. Is it already opened? */
273 if (pDevice->ReferenceCount == 0)
274 {
275 /* Find some room for the device */
276 for (DeviceId = 0; ; ++DeviceId)
277 {
278 if (DeviceId >= _countof(FileData))
279 return EMFILE;
280 if (!FileData[DeviceId].FuncTable)
281 break;
282 }
283
284 /* Try to open the device */
285 FileData[DeviceId].ReferenceCount = 0;
286 FileData[DeviceId].FuncTable = pDevice->FuncTable;
287 Status = pDevice->FuncTable->Open(pDevice->DeviceName, DeviceOpenMode, &DeviceId);
288 if (Status != ESUCCESS)
289 {
290 FileData[DeviceId].FuncTable = NULL;
291 return Status;
292 }
293 pDevice->DeviceId = DeviceId;
294 }
295 else
296 {
297 /* Reuse the existing entry */
298 DeviceId = pDevice->DeviceId;
299 ASSERT(FileData[DeviceId].FuncTable == pDevice->FuncTable);
300 }
301
302 /* Done, increase the device reference count */
303 pDevice->ReferenceCount++;
304 FileData[DeviceId].ReferenceCount++;
305
306 if (!*FileName)
307 {
308 /* The caller wanted to open the raw device: return its ID */
309 *FileId = DeviceId;
310 return ESUCCESS;
311 }
312
313
314 /*
315 * We are opening a file.
316 */
317
318 /* Find some room for the file */
319 for (i = 0; ; ++i)
320 {
321 if (i >= _countof(FileData))
322 {
323 Status = EMFILE;
324 goto Done;
325 }
326 if (!FileData[i].FuncTable)
327 break;
328 }
329
330 /* The device is accessed using filesystem semantics.
331 * Try to detect the file system if not already done. */
332 if (!pDevice->FileFuncTable && (pDevice->ReferenceCount <= 1))
333 {
334 for (ULONG fs = 0; fs < _countof(FileSystems); ++fs)
335 {
336 pDevice->FileFuncTable = FileSystems[fs](DeviceId);
337 if (pDevice->FileFuncTable)
338 break;
339 }
340 }
341 if (!pDevice->FileFuncTable)
342 {
343 /* Error, unable to detect the file system */
344 Status = ENOENT; // ENXIO;
345 goto Done;
346 }
347
348 /*
349 * At this point, the device is found and opened. Its file ID is stored
350 * in DeviceId, and pDevice->FileFuncTable contains what needs to be
351 * called to manipulate the file.
352 */
353
354 /* Open the file */
355 FileData[i].DeviceId = DeviceId;
357 FileData[i].FuncTable = pDevice->FileFuncTable;
358 *FileId = i;
359 Status = FileData[i].FuncTable->Open(FileName, OpenMode, FileId);
360 if (Status != ESUCCESS)
361 {
365 *FileId = INVALID_FILE_ID;
366 }
367 else
368 {
369 /* Reference the file */
371 }
372
373Done:
374 /* If we failed somewhere, dereference the device as well */
375 if (Status != ESUCCESS)
376 {
377 // ArcClose(DeviceId);
378 if (--FileData[DeviceId].ReferenceCount == 0)
379 {
380 (void)FileData[DeviceId].FuncTable->Close(DeviceId);
382 FileData[DeviceId].FuncTable = NULL;
383 FileData[DeviceId].Specific = NULL;
384 }
385 if (--pDevice->ReferenceCount == 0)
386 pDevice->DeviceId = INVALID_FILE_ID;
387 }
388
389 return Status;
390}
PRTL_UNICODE_STRING_BUFFER Path
#define ENOENT
Definition: acclib.h:79
#define EINVAL
Definition: acclib.h:90
#define ENOMEM
Definition: acclib.h:84
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define ENODEV
Definition: acclib.h:89
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
PFS_MOUNT FileSystems[]
Definition: fs.c:59
static LIST_ENTRY DeviceListHead
Definition: fs.c:52
PCHAR NormalizeArcDeviceName(_In_ PCCH DeviceName, _Inout_ PSIZE_T Length)
Replace "()" by "(0)" in the given ARC device name, if necessary.
Definition: fs.c:180
#define TAG_DEVICE_NAME
Definition: fs.c:30
#define EMFILE
Definition: errno.h:30
struct _FileName FileName
Definition: fatprocs.h:897
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
Status
Definition: gdiplustypes.h:25
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 fs
Definition: i386-dis.c:444
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
ULONG ARC_STATUS
Definition: arc.h:4
enum _OPENMODE OPENMODE
@ OpenWriteOnly
Definition: arc.h:66
@ OpenReadWrite
Definition: arc.h:67
@ OpenReadOnly
Definition: arc.h:65
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: ffs.h:70
ARC_OPEN Open
Definition: fs.h:28
ULONG ReferenceCount
Definition: fs.c:46
char * PSTR
Definition: typedefs.h:51
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

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

◆ ArcRead()

◆ ArcSeek()

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

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( FILESYSTEM  )

◆ FileSystemError()

VOID FileSystemError ( PCSTR  ErrorString)

Definition at line 471 of file fs.c.

472{
473 ERR("%s\n", ErrorString);
474 UiMessageBox(ErrorString);
475}
#define ERR(fmt,...)
Definition: precomp.h:57
VOID UiMessageBox(_In_ PCSTR Format,...)
Definition: ui.c:359

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

◆ FsGetDeviceById()

static DEVICE * FsGetDeviceById ( ULONG  DeviceId)
static

Definition at line 393 of file fs.c.

394{
396
400 {
402 if (pDevice->DeviceId == DeviceId)
403 return pDevice;
404 }
405 return NULL;
406}

Referenced by ArcClose().

◆ FsGetDeviceId()

ULONG FsGetDeviceId ( ULONG  FileId)

Definition at line 639 of file fs.c.

640{
641 if (FileId >= _countof(FileData)) // !IS_VALID_FILEID(FileId)
642 return INVALID_FILE_ID;
643 return FileData[FileId].DeviceId;
644}

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

◆ FsGetDeviceSpecific()

◆ FsGetFirstNameFromPath()

VOID FsGetFirstNameFromPath ( PCHAR  Buffer,
PCSTR  Path 
)

Definition at line 568 of file fs.c.

569{
570 size_t i;
571 size_t len;
572
573 len = strlen(Path);
574
575 // Copy all the characters up to the end of the
576 // string or until we hit a '\' character
577 // and put them in Buffer
578 for (i = 0; i < len; i++)
579 {
580 if ((Path[i] == '\\') || (Path[i] == '/'))
581 {
582 break;
583 }
584 else
585 {
586 Buffer[i] = Path[i];
587 }
588 }
589
590 Buffer[i] = 0;
591
592 TRACE("FsGetFirstNameFromPath() Path = %s FirstName = %s\n", Path, Buffer);
593}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLsizei len
Definition: glext.h:6722

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

◆ FsGetNumPathParts()

ULONG FsGetNumPathParts ( PCSTR  Path)

Definition at line 540 of file fs.c.

541{
542 size_t i;
543 size_t len;
544 ULONG num;
545
546 len = strlen(Path);
547
548 for (i = 0, num = 0; i < len; i++)
549 {
550 if ((Path[i] == '\\') || (Path[i] == '/'))
551 {
552 num++;
553 }
554 }
555 num++;
556
557 TRACE("FsGetNumPathParts() Path = %s NumPathParts = %d\n", Path, num);
558
559 return num;
560}
GLuint GLuint num
Definition: glext.h:9618

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

◆ FsGetServiceName()

PCWSTR FsGetServiceName ( ULONG  FileId)

Definition at line 618 of file fs.c.

619{
620 if (!IS_VALID_FILEID(FileId))
621 return NULL;
622 return FileData[FileId].FuncTable->ServiceName;
623}
PCWSTR ServiceName
Definition: fs.h:31

Referenced by WinLdrLoadSystemHive().

◆ FsInit()

VOID FsInit ( VOID  )

Definition at line 646 of file fs.c.

647{
648 ULONG i;
649
651 for (i = 0; i < _countof(FileData); ++i)
652 FileData[i].DeviceId = INVALID_FILE_ID;
653
655}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by BootMain(), and EfiEntry().

◆ FsOpenFile()

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

Definition at line 478 of file fs.c.

483{
485 SIZE_T cchPathLen;
486 CHAR FullPath[MAX_PATH] = "";
487
488 /*
489 * Check whether FileName is a full path and if not, create a full
490 * file name using the user-provided default path (if present).
491 *
492 * See ArcOpen(): Search last ')', which delimits device and path.
493 */
494 if (strrchr(FileName, ')') == NULL)
495 {
496 /* This is not a full path: prepend the user-provided default path */
497 if (DefaultPath)
498 {
499 Status = RtlStringCbCopyA(FullPath, sizeof(FullPath), DefaultPath);
500 if (!NT_SUCCESS(Status))
501 return ENAMETOOLONG;
502 }
503
504 /* Append a path separator if needed */
505
506 cchPathLen = min(sizeof(FullPath)/sizeof(CHAR), strlen(FullPath));
507 if (cchPathLen >= sizeof(FullPath)/sizeof(CHAR))
508 return ENAMETOOLONG;
509
510 if ((*FileName != '\\' && *FileName != '/') &&
511 cchPathLen > 0 && (FullPath[cchPathLen-1] != '\\' && FullPath[cchPathLen-1] != '/'))
512 {
513 /* FileName does not start with '\' and FullPath does not end with '\' */
514 Status = RtlStringCbCatA(FullPath, sizeof(FullPath), "\\");
515 if (!NT_SUCCESS(Status))
516 return ENAMETOOLONG;
517 }
518 else if ((*FileName == '\\' || *FileName == '/') &&
519 cchPathLen > 0 && (FullPath[cchPathLen-1] == '\\' || FullPath[cchPathLen-1] == '/'))
520 {
521 /* FileName starts with '\' and FullPath ends with '\' */
522 while (*FileName == '\\' || *FileName == '/')
523 ++FileName; // Skip any backslash
524 }
525 }
526 /* Append (or just copy) the remaining file name */
527 Status = RtlStringCbCatA(FullPath, sizeof(FullPath), FileName);
528 if (!NT_SUCCESS(Status))
529 return ENAMETOOLONG;
530
531 /* Open the file */
532 return ArcOpen(FullPath, OpenMode, FileId);
533}
LONG NTSTATUS
Definition: precomp.h:26
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:219
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define MAX_PATH
Definition: compat.h:34
#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
NTSTRSAFEAPI RtlStringCbCopyA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:156
#define ENAMETOOLONG
Definition: errno.h:55
char CHAR
Definition: xmlstorage.h:175

Referenced by IniFileInitialize(), and RamDiskLoadVirtualFile().

◆ FsRegisterDevice()

VOID FsRegisterDevice ( _In_ PCSTR  DeviceName,
_In_ const DEVVTBL FuncTable 
)

Definition at line 596 of file fs.c.

599{
600 DEVICE* pNewEntry;
602
603 TRACE("FsRegisterDevice(%s)\n", DeviceName);
604
605 Length = strlen(DeviceName) + 1;
606 pNewEntry = FrLdrTempAlloc(sizeof(DEVICE) + Length, TAG_DEVICE);
607 if (!pNewEntry)
608 return;
609 pNewEntry->FuncTable = FuncTable;
610 pNewEntry->DeviceId = INVALID_FILE_ID;
611 pNewEntry->ReferenceCount = 0;
612 pNewEntry->DeviceName = (PSTR)(pNewEntry + 1);
614
616}
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
#define TAG_DEVICE
Definition: fs.c:31
#define InsertHeadList(ListHead, Entry)
PSTR DeviceName
Definition: fs.c:38
ULONG DeviceId
Entry ID in FileData when the device gets referenced.
Definition: fs.c:39
const DEVVTBL * FuncTable
Driver function table.
Definition: fs.c:36
LIST_ENTRY ListEntry
Definition: fs.c:35
ULONG ReferenceCount
Definition: fs.c:40
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

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

◆ FsSetDeviceSpecific()

VOID FsSetDeviceSpecific ( ULONG  FileId,
PVOID  Specific 
)

Definition at line 625 of file fs.c.

626{
627 if (!IS_VALID_FILEID(FileId))
628 return;
629 FileData[FileId].Specific = Specific;
630}

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

◆ NormalizeArcDeviceName()

PCHAR NormalizeArcDeviceName ( _In_ PCCH  DeviceName,
_Inout_ PSIZE_T  Length 
)

Replace "()" by "(0)" in the given ARC device name, if necessary.

Parameters
[in]DeviceNameThe original ARC device name string to normalize.
[in,out]LengthPoints to a SIZE_T variable that:
  • on input, specifies the length of the ARC device name string pointed by DeviceName;
  • on output, receives the length of the normalized ARC device name, returned by value by this function.
Returns
  • On success, returns a string pointer to the normalized ARC device name. If the device name string had to be normalized, this returned string is allocated from the temporary heap, with TAG_DEVICE_NAME tag. Otherwise, the function returns the original device name string pointer.
  • On failure, the function returns NULL.

Definition at line 180 of file fs.c.

183{
184 ULONG Count;
185 SIZE_T NameLength;
186 PCCH p, End;
187 PCHAR q, NormName;
188
189 NameLength = *Length;
190 End = DeviceName + NameLength;
191
192 /* Count the number of "()", which needs to be replaced by "(0)" */
193 Count = 0;
194 for (p = DeviceName; p < End; ++p)
195 {
196 if ((p + 1) < End && *p == '(' && *(p + 1) == ')')
197 ++Count; //, ++p;
198 }
199
200 if (Count == 0) /* No need to duplicate the device name */
201 return (PCHAR)DeviceName;
202
203 /* Return the updated length */
204 *Length = NameLength + Count;
205
206 /* Duplicate the device name and replace "()" by "(0)" */
208 if (!NormName)
209 return NULL;
210 for (p = DeviceName, q = NormName; p < End; ++p)
211 {
212 *q++ = *p;
213 if ((p + 1) < End && *p == '(' && *(p + 1) == ')')
214 *q++ = '0'; //, *q++ = *++p;
215 }
216 return NormName;
217}
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
CONST CHAR * PCCH
Definition: ntbasedef.h:400

Referenced by ArcOpen().

Variable Documentation

◆ DeviceListHead

LIST_ENTRY DeviceListHead
static

Definition at line 52 of file fs.c.

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

◆ FileData

◆ FileSystems

PFS_MOUNT FileSystems[]
Initial value:
=
{
}
NTSTATUS FatMount(_In_ ULONG DeviceId, _In_ ULONG Unknown, _Out_ PBL_FILE_ENTRY *FileEntry)
Definition: fat.c:23
const DEVVTBL * BtrFsMount(ULONG DeviceId)
Definition: btrfs.c:1297
const DEVVTBL * NtfsMount(ULONG DeviceId)
Definition: ntfs.c:886
const DEVVTBL * Ext2Mount(ULONG DeviceId)
Definition: ext2.c:1298
const DEVVTBL * IsoMount(ULONG DeviceId)
Definition: iso.c:498

Definition at line 59 of file fs.c.

Referenced by ArcOpen().