ReactOS  0.4.13-dev-235-g7373cb3
ramdisk.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for ramdisk.c:

Go to the source code of this file.

Functions

static ARC_STATUS RamDiskClose (ULONG FileId)
 
static ARC_STATUS RamDiskGetFileInformation (ULONG FileId, FILEINFORMATION *Information)
 
static ARC_STATUS RamDiskOpen (CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
 
static ARC_STATUS RamDiskRead (ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
 
static ARC_STATUS RamDiskSeek (ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
 
VOID NTAPI RamDiskInitialize (VOID)
 
BOOLEAN NTAPI RamDiskLoadVirtualFile (IN PCHAR FileName)
 

Variables

PVOID gRamDiskBase
 
ULONG gRamDiskSize
 
ULONG gRamDiskOffset
 
static const DEVVTBL RamDiskVtbl
 

Function Documentation

◆ RamDiskClose()

static ARC_STATUS RamDiskClose ( ULONG  FileId)
static

Definition at line 24 of file ramdisk.c.

25 {
26  //
27  // Nothing to do
28  //
29  return ESUCCESS;
30 }
Definition: arc.h:32

◆ RamDiskGetFileInformation()

static ARC_STATUS RamDiskGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)
static

Definition at line 32 of file ramdisk.c.

33 {
34  //
35  // Give current seek offset and ram disk size to caller
36  //
38  Information->EndingAddress.LowPart = gRamDiskSize;
39  Information->CurrentAddress.LowPart = gRamDiskOffset;
40 
41  return ESUCCESS;
42 }
Definition: arc.h:32
ULONG gRamDiskSize
Definition: ramdisk.c:19
ULONG gRamDiskOffset
Definition: ramdisk.c:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
Iosb Information
Definition: create.c:4377

◆ RamDiskInitialize()

VOID NTAPI RamDiskInitialize ( VOID  )

Definition at line 113 of file ramdisk.c.

114 {
115  /* Register the RAMDISK device */
116  FsRegisterDevice("ramdisk(0)", &RamDiskVtbl);
117 }
static const DEVVTBL RamDiskVtbl
Definition: ramdisk.c:103
VOID FsRegisterDevice(CHAR *Prefix, const DEVVTBL *FuncTable)
Definition: fs.c:441

Referenced by ArmHwDetect(), and RamDiskLoadVirtualFile().

◆ RamDiskLoadVirtualFile()

BOOLEAN NTAPI RamDiskLoadVirtualFile ( IN PCHAR  FileName)

Definition at line 121 of file ramdisk.c.

122 {
123  PFILE RamFile;
124  ULONG TotalRead, ChunkSize, Count;
125  PCHAR MsgBuffer = "Loading RamDisk...";
126  ULONG PercentPerChunk, Percent;
130 
131  //
132  // Display progress
133  //
134  UiDrawBackdrop();
135  UiDrawProgressBarCenter(1, 100, MsgBuffer);
136 
137  //
138  // Try opening the ramdisk file
139  //
140  RamFile = FsOpenFile(FileName);
141  if (!RamFile)
142  return FALSE;
143 
144  //
145  // Get the file size
146  //
148  if (Status != ESUCCESS)
149  {
150  FsCloseFile(RamFile);
151  return FALSE;
152  }
153 
154  //
155  // For now, limit RAM disks to 4GB
156  //
157  if (Information.EndingAddress.HighPart != 0)
158  {
159  UiMessageBox("RAM disk too big.");
160  FsCloseFile(RamFile);
161  return FALSE;
162  }
163  gRamDiskSize = Information.EndingAddress.LowPart;
164 
165  //
166  // Allocate memory for it
167  //
168  ChunkSize = 8 * 1024 * 1024;
169  if (gRamDiskSize < ChunkSize)
170  Percent = PercentPerChunk = 0;
171  else
172  Percent = PercentPerChunk = 100 / (gRamDiskSize / ChunkSize);
174  if (!gRamDiskBase)
175  {
176  UiMessageBox("Failed to allocate memory for RAM disk.");
177  FsCloseFile(RamFile);
178  return FALSE;
179  }
180 
181  //
182  // Read it in chunks
183  //
184  for (TotalRead = 0; TotalRead < gRamDiskSize; TotalRead += ChunkSize)
185  {
186  //
187  // Check if we're at the last chunk
188  //
189  if ((gRamDiskSize - TotalRead) < ChunkSize)
190  {
191  //
192  // Only need the actual data required
193  //
194  ChunkSize = gRamDiskSize - TotalRead;
195  }
196 
197  //
198  // Draw progress
199  //
200  UiDrawProgressBarCenter(Percent, 100, MsgBuffer);
201  Percent += PercentPerChunk;
202 
203  //
204  // Copy the contents
205  //
206  Position.HighPart = 0;
207  Position.LowPart = TotalRead;
208  Status = ArcSeek(RamFile, &Position, SeekAbsolute);
209  if (Status == ESUCCESS)
210  {
211  Status = ArcRead(RamFile,
212  (PVOID)((ULONG_PTR)gRamDiskBase + TotalRead),
213  ChunkSize,
214  &Count);
215  }
216 
217  //
218  // Check for success
219  //
220  if (Status != ESUCCESS || Count != ChunkSize)
221  {
223  gRamDiskBase = NULL;
224  gRamDiskSize = 0;
225  FsCloseFile(RamFile);
226  UiMessageBox("Failed to read RAM disk.");
227  return FALSE;
228  }
229  }
230 
231  FsCloseFile(RamFile);
232 
233  /* Setup the RAMDISK device */
235 
236  return TRUE;
237 }
signed char * PCHAR
Definition: retypes.h:7
#define TRUE
Definition: types.h:120
Definition: arc.h:32
static COORD Position
Definition: mouse.c:34
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
ULONG ARC_STATUS
Definition: arc.h:4
VOID FsCloseFile(PFILE FileHandle)
Definition: fs.c:309
uint32_t ULONG_PTR
Definition: typedefs.h:63
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
VOID UiMessageBox(PCSTR Format,...)
Definition: ui.c:347
smooth NULL
Definition: ftsmooth.c:416
ULONG gRamDiskSize
Definition: ramdisk.c:19
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:237
VOID NTAPI RamDiskInitialize(VOID)
Definition: ramdisk.c:113
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: fs.c:244
VOID UiDrawBackdrop(VOID)
Definition: ui.c:241
Status
Definition: gdiplustypes.h:24
VOID MmFreeMemory(PVOID MemoryPointer)
Definition: mm.c:215
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:251
PVOID gRamDiskBase
Definition: ramdisk.c:18
unsigned int ULONG
Definition: retypes.h:1
#define PFILE
Definition: fs.h:37
Iosb Information
Definition: create.c:4377
PFILE FsOpenFile(PCSTR FileName)
Definition: fs.c:266
VOID UiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
Definition: ui.c:373

Referenced by LoadAndBootWindows(), and LoadReactOSSetup().

◆ RamDiskOpen()

static ARC_STATUS RamDiskOpen ( CHAR Path,
OPENMODE  OpenMode,
ULONG FileId 
)
static

Definition at line 44 of file ramdisk.c.

45 {
46  //
47  // Always return success, as contents are already in memory
48  //
49  return ESUCCESS;
50 }
Definition: arc.h:32

◆ RamDiskRead()

static ARC_STATUS RamDiskRead ( ULONG  FileId,
VOID Buffer,
ULONG  N,
ULONG Count 
)
static

Definition at line 52 of file ramdisk.c.

53 {
54  PVOID StartAddress;
55 
56  //
57  // Get actual pointer
58  //
59  StartAddress = (PVOID)((ULONG_PTR)gRamDiskBase + gRamDiskOffset);
60 
61  //
62  // Don't allow reads past our image
63  //
65  {
66  *Count = 0;
67  return EIO;
68  }
69 
70  //
71  // Do the read
72  //
73  RtlCopyMemory(Buffer, StartAddress, N);
74  *Count = N;
75 
76  return ESUCCESS;
77 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
Definition: arc.h:32
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: bidi.c:97
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
ULONG gRamDiskSize
Definition: ramdisk.c:19
ULONG gRamDiskOffset
Definition: ramdisk.c:20
Definition: arc.h:40
PVOID gRamDiskBase
Definition: ramdisk.c:18

◆ RamDiskSeek()

static ARC_STATUS RamDiskSeek ( ULONG  FileId,
LARGE_INTEGER Position,
SEEKMODE  SeekMode 
)
static

Definition at line 79 of file ramdisk.c.

80 {
81  //
82  // Only accept absolute mode now
83  //
84  if (SeekMode != SeekAbsolute)
85  return EINVAL;
86 
87  //
88  // Check if we're in the ramdisk
89  //
90  if (Position->HighPart != 0)
91  return EINVAL;
92  if (Position->LowPart >= gRamDiskSize)
93  return EINVAL;
94 
95  //
96  // OK, remember seek position
97  //
98  gRamDiskOffset = Position->LowPart;
99 
100  return ESUCCESS;
101 }
Definition: arc.h:32
Definition: arc.h:39
static COORD Position
Definition: mouse.c:34
ULONG gRamDiskSize
Definition: ramdisk.c:19
ULONG gRamDiskOffset
Definition: ramdisk.c:20

Variable Documentation

◆ gRamDiskBase

PVOID gRamDiskBase

Definition at line 18 of file ramdisk.c.

Referenced by CmdLineParse(), RamDiskLoadVirtualFile(), and RamDiskRead().

◆ gRamDiskOffset

ULONG gRamDiskOffset

Definition at line 20 of file ramdisk.c.

Referenced by RamDiskGetFileInformation(), RamDiskRead(), and RamDiskSeek().

◆ gRamDiskSize

ULONG gRamDiskSize

◆ RamDiskVtbl

const DEVVTBL RamDiskVtbl
static
Initial value:
= {
}
static ARC_STATUS RamDiskClose(ULONG FileId)
Definition: ramdisk.c:24
static ARC_STATUS RamDiskGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: ramdisk.c:32
static ARC_STATUS RamDiskOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: ramdisk.c:44
static ARC_STATUS RamDiskRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: ramdisk.c:52
static ARC_STATUS RamDiskSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: ramdisk.c:79

Definition at line 103 of file ramdisk.c.

Referenced by RamDiskInitialize().