ReactOS 0.4.16-dev-205-g7b2bb7e
dosfiles.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "../../memory.h"
#include "dos.h"
#include "dos/dem.h"
#include "dosfiles.h"
#include "handle.h"
#include "process.h"
#include "bios/bios.h"
Include dependency graph for dosfiles.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID StoreNameInSft (LPCSTR FilePath, PDOS_FILE_DESCRIPTOR Descriptor)
 
BYTE DosFindFreeDescriptor (VOID)
 
BYTE DosFindWin32Descriptor (HANDLE Win32Handle)
 
BYTE DosFindDeviceDescriptor (DWORD DevicePointer)
 
PDOS_FILE_DESCRIPTOR DosGetFileDescriptor (BYTE Id)
 
PDOS_FILE_DESCRIPTOR DosGetHandleFileDescriptor (WORD DosHandle)
 
WORD DosCreateFileEx (LPWORD Handle, LPWORD CreationStatus, LPCSTR FilePath, BYTE AccessShareModes, WORD CreateActionFlags, WORD Attributes)
 
WORD DosCreateFile (LPWORD Handle, LPCSTR FilePath, DWORD CreationDisposition, WORD Attributes)
 
WORD DosOpenFile (LPWORD Handle, LPCSTR FilePath, BYTE AccessShareModes)
 
BYTE DosReadLineBuffered (WORD FileHandle, DWORD Buffer, BYTE MaxSize)
 
WORD DosReadFile (WORD FileHandle, DWORD Buffer, WORD Count, LPWORD BytesRead)
 
WORD DosWriteFile (WORD FileHandle, DWORD Buffer, WORD Count, LPWORD BytesWritten)
 
WORD DosSeekFile (WORD FileHandle, LONG Offset, BYTE Origin, LPDWORD NewOffset)
 
BOOL DosFlushFileBuffers (WORD FileHandle)
 
BOOLEAN DosLockFile (WORD DosHandle, DWORD Offset, DWORD Size)
 
BOOLEAN DosUnlockFile (WORD DosHandle, DWORD Offset, DWORD Size)
 
BOOLEAN DosDeviceIoControlDrive (WORD DriveNumber, BYTE ControlCode, DWORD Buffer, PWORD Result)
 
BOOLEAN DosDeviceIoControl (WORD FileHandle, BYTE ControlCode, DWORD Buffer, PWORD Length)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file dosfiles.c.

Function Documentation

◆ DosCreateFile()

WORD DosCreateFile ( LPWORD  Handle,
LPCSTR  FilePath,
DWORD  CreationDisposition,
WORD  Attributes 
)

Definition at line 442 of file dosfiles.c.

446{
449 WORD DosHandle;
450 BYTE DescriptorId;
452
453 DPRINT("DosCreateFile: FilePath \"%s\", CreationDisposition 0x%04X, Attributes 0x%04X\n",
454 FilePath, CreationDisposition, Attributes);
455
457 if (Node != NULL)
458 {
459 if (Node->OpenRoutine) Node->OpenRoutine(Node);
460 }
461 else
462 {
463 /* Create the file */
467 NULL,
468 CreationDisposition,
470 NULL);
472 {
473 /* Return the error code */
474 return (WORD)GetLastError();
475 }
476 }
477
478 DescriptorId = DosFindFreeDescriptor();
479 if (DescriptorId == 0xFF)
480 {
481 /* Close the file and return the error code */
484 }
485
486 /* Set up the new descriptor */
487 Descriptor = DosGetFileDescriptor(DescriptorId);
489 RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' ');
490
491 if (Node != NULL)
492 {
493 Descriptor->DevicePointer = Node->Driver;
494 Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE;
495 RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length);
496 }
497 else
498 {
501 Descriptor->Win32Handle = FileHandle;
503 }
504
505 Descriptor->OwnerPsp = Sda->CurrentPsp;
506
507 /* Open the DOS handle */
508 DosHandle = DosOpenHandle(DescriptorId);
509 if (DosHandle == INVALID_DOS_HANDLE)
510 {
511 /* Close the file and return the error code */
514 }
515
516 /* It was successful */
517 *Handle = DosHandle;
518 return ERROR_SUCCESS;
519}
PCWSTR FilePath
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
union node Node
Definition: types.h:1255
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:636
PDOS_SDA Sda
Definition: dos.c:48
static VOID StoreNameInSft(LPCSTR FilePath, PDOS_FILE_DESCRIPTOR Descriptor)
Definition: dosfiles.c:30
PDOS_FILE_DESCRIPTOR DosGetFileDescriptor(BYTE Id)
Definition: dosfiles.c:153
BYTE DosFindFreeDescriptor(VOID)
Definition: dosfiles.c:69
#define FILE_INFO_DEVICE
Definition: dosfiles.h:16
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
ULONG Handle
Definition: gdb_input.c:15
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define LOBYTE(W)
Definition: jmemdos.c:487
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define GENERIC_WRITE
Definition: nt_native.h:90
#define DPRINT
Definition: sndvol32.h:73
WORD CurrentPsp
Definition: dos.h:165
PDOS_DEVICE_NODE DosGetDevice(LPCSTR DeviceName)
Definition: device.c:342
#define INVALID_DOS_HANDLE
Definition: dos.h:41
WORD DosOpenHandle(BYTE DescriptorId)
Definition: handle.c:200
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_TOO_MANY_OPEN_FILES
Definition: winerror.h:107
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DosInt21h().

◆ DosCreateFileEx()

WORD DosCreateFileEx ( LPWORD  Handle,
LPWORD  CreationStatus,
LPCSTR  FilePath,
BYTE  AccessShareModes,
WORD  CreateActionFlags,
WORD  Attributes 
)

Definition at line 181 of file dosfiles.c.

187{
188 WORD LastError;
191 WORD DosHandle;
193 DWORD ShareMode = 0;
194 DWORD CreationDisposition = 0;
195 BOOL InheritableFile = FALSE;
196 SECURITY_ATTRIBUTES SecurityAttributes;
197 BYTE DescriptorId;
199
200 DPRINT1("DosCreateFileEx: FilePath \"%s\", AccessShareModes 0x%04X, CreateActionFlags 0x%04X, Attributes 0x%04X\n",
201 FilePath, AccessShareModes, CreateActionFlags, Attributes);
202
203 //
204 // The article about OpenFile API: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365430(v=vs.85).aspx
205 // explains what those AccessShareModes are (see the uStyle flag).
206 //
207
209 if (Node != NULL)
210 {
211 if (Node->OpenRoutine) Node->OpenRoutine(Node);
212 }
213 else
214 {
215 /* Parse the access mode */
216 switch (AccessShareModes & 0x03)
217 {
218 /* Read-only */
219 case 0:
221 break;
222
223 /* Write only */
224 case 1:
226 break;
227
228 /* Read and write */
229 case 2:
231 break;
232
233 /* Invalid */
234 default:
236 }
237
238 /* Parse the share mode */
239 switch ((AccessShareModes >> 4) & 0x07)
240 {
241 /* Compatibility mode */
242 case 0:
244 break;
245
246 /* No sharing "DenyAll" */
247 case 1:
248 ShareMode = 0;
249 break;
250
251 /* No write share "DenyWrite" */
252 case 2:
253 ShareMode = FILE_SHARE_READ;
254 break;
255
256 /* No read share "DenyRead" */
257 case 3:
258 ShareMode = FILE_SHARE_WRITE;
259 break;
260
261 /* Full share "DenyNone" */
262 case 4:
263 ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
264 break;
265
266 /* Invalid */
267 default:
269 }
270
271 /*
272 * Parse the creation action flags:
273 *
274 * Bitfields for action:
275 * Bit(s) Description
276 *
277 * 7-4 Action if file does not exist.
278 * 0000 Fail
279 * 0001 Create
280 *
281 * 3-0 Action if file exists.
282 * 0000 Fail
283 * 0001 Open
284 * 0010 Replace/open
285 */
286 switch (CreateActionFlags)
287 {
288 /* If the file exists, fail, otherwise, fail also */
289 case 0x00:
290 // A special case is used after the call to CreateFileA if it succeeds,
291 // in order to close the opened handle and return an adequate error.
292 CreationDisposition = OPEN_EXISTING;
293 break;
294
295 /* If the file exists, open it, otherwise, fail */
296 case 0x01:
297 CreationDisposition = OPEN_EXISTING;
298 break;
299
300 /* If the file exists, replace it, otherwise, fail */
301 case 0x02:
302 CreationDisposition = TRUNCATE_EXISTING;
303 break;
304
305 /* If the file exists, fail, otherwise, create it */
306 case 0x10:
307 CreationDisposition = CREATE_NEW;
308 break;
309
310 /* If the file exists, open it, otherwise, create it */
311 case 0x11:
312 CreationDisposition = OPEN_ALWAYS;
313 break;
314
315 /* If the file exists, replace it, otherwise, create it */
316 case 0x12:
317 CreationDisposition = CREATE_ALWAYS;
318 break;
319
320 /* Invalid */
321 default:
323 }
324
325 /* Check for inheritance */
326 InheritableFile = ((AccessShareModes & 0x80) == 0);
327
328 /* Assign default security attributes to the file, and set the inheritance flag */
329 SecurityAttributes.nLength = sizeof(SecurityAttributes);
330 SecurityAttributes.lpSecurityDescriptor = NULL;
331 SecurityAttributes.bInheritHandle = InheritableFile;
332
333 /* Open the file */
336 ShareMode,
337 &SecurityAttributes,
338 CreationDisposition,
340 NULL);
341
342 LastError = (WORD)GetLastError();
343
345 {
346 /* Return the error code */
347 return LastError;
348 }
349
350 /*
351 * Special case: CreateActionFlags == 0, we must fail because
352 * the file exists (if it didn't exist we already failed).
353 */
354 if (CreateActionFlags == 0)
355 {
356 /* Close the file and return the error code */
358 return ERROR_FILE_EXISTS;
359 }
360
361 /* Set the creation status */
362 switch (CreateActionFlags)
363 {
364 case 0x01:
365 *CreationStatus = 0x01; // The file was opened
366 break;
367
368 case 0x02:
369 *CreationStatus = 0x03; // The file was replaced
370 break;
371
372 case 0x10:
373 *CreationStatus = 0x02; // The file was created
374 break;
375
376 case 0x11:
377 {
378 if (LastError == ERROR_ALREADY_EXISTS)
379 *CreationStatus = 0x01; // The file was opened
380 else
381 *CreationStatus = 0x02; // The file was created
382
383 break;
384 }
385
386 case 0x12:
387 {
388 if (LastError == ERROR_ALREADY_EXISTS)
389 *CreationStatus = 0x03; // The file was replaced
390 else
391 *CreationStatus = 0x02; // The file was created
392
393 break;
394 }
395 }
396 }
397
398 DescriptorId = DosFindFreeDescriptor();
399 if (DescriptorId == 0xFF)
400 {
401 /* Close the file and return the error code */
404 }
405
406 /* Set up the new descriptor */
407 Descriptor = DosGetFileDescriptor(DescriptorId);
409 RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' ');
410
411 if (Node != NULL)
412 {
413 Descriptor->DevicePointer = Node->Driver;
414 Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE;
415 RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length);
416 }
417 else
418 {
419 Descriptor->OpenMode = AccessShareModes;
422 Descriptor->Win32Handle = FileHandle;
424 }
425
426 Descriptor->OwnerPsp = Sda->CurrentPsp;
427
428 /* Open the DOS handle */
429 DosHandle = DosOpenHandle(DescriptorId);
430 if (DosHandle == INVALID_DOS_HANDLE)
431 {
432 /* Close the file and return the error code */
435 }
436
437 /* It was successful */
438 *Handle = DosHandle;
439 return ERROR_SUCCESS;
440}
#define DPRINT1
Definition: precomp.h:8
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define OPEN_EXISTING
Definition: compat.h:775
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CREATE_ALWAYS
Definition: disk.h:72
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
ULONG ACCESS_MASK
Definition: nt_native.h:40
LPVOID lpSecurityDescriptor
Definition: compat.h:193
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396

Referenced by DosInt21h().

◆ DosDeviceIoControl()

BOOLEAN DosDeviceIoControl ( WORD  FileHandle,
BYTE  ControlCode,
DWORD  Buffer,
PWORD  Length 
)

Definition at line 1185 of file dosfiles.c.

1186{
1189
1190 switch (ControlCode)
1191 {
1192 case 0x04:
1193 case 0x05:
1194 case 0x08:
1195 case 0x09:
1197 }
1198
1200
1201 if (!Descriptor)
1202 {
1204 return FALSE;
1205 }
1206
1207 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE)
1208 {
1209 Node = DosGetDriverNode(Descriptor->DevicePointer);
1210 }
1211
1212 switch (ControlCode)
1213 {
1214 /* Get Device Information */
1215 case 0x00:
1216 {
1217 /*
1218 * See Ralf Brown: http://www.ctyme.com/intr/rb-2820.htm
1219 * for a list of possible flags.
1220 */
1221 setDX(Descriptor->DeviceInfo);
1222 return TRUE;
1223 }
1224
1225 /* Set Device Information */
1226 case 0x01:
1227 {
1228 // TODO: NOT IMPLEMENTED
1230 return FALSE;
1231 }
1232
1233 /* Read from Device I/O Control Channel */
1234 case 0x02:
1235 {
1236 if (Node == NULL || !(Node->DeviceAttributes & DOS_DEVATTR_IOCTL))
1237 {
1239 return FALSE;
1240 }
1241
1242 /* Do nothing if there is no IOCTL routine */
1243 if (!Node->IoctlReadRoutine)
1244 {
1245 *Length = 0;
1246 return TRUE;
1247 }
1248
1249 Node->IoctlReadRoutine(Node, Buffer, Length);
1250 return TRUE;
1251 }
1252
1253 /* Write to Device I/O Control Channel */
1254 case 0x03:
1255 {
1256 if (Node == NULL || !(Node->DeviceAttributes & DOS_DEVATTR_IOCTL))
1257 {
1259 return FALSE;
1260 }
1261
1262 /* Do nothing if there is no IOCTL routine */
1263 if (!Node->IoctlWriteRoutine)
1264 {
1265 *Length = 0;
1266 return TRUE;
1267 }
1268
1269 Node->IoctlWriteRoutine(Node, Buffer, Length);
1270 return TRUE;
1271 }
1272
1273 /* Get Input Status */
1274 case 0x06:
1275 {
1276 /* Check if this is a file or a device */
1277 if (Node)
1278 {
1279 /* Device*/
1280
1281 if (!Node->InputStatusRoutine || Node->InputStatusRoutine(Node))
1282 {
1283 /* Set the length to 0xFF to mark that it's ready */
1284 *Length = 0xFF;
1285 }
1286 else
1287 {
1288 /* Not ready */
1289 *Length = 0;
1290 }
1291 }
1292 else
1293 {
1294 /* File */
1295
1296 if (Descriptor->Position < Descriptor->Size)
1297 {
1298 /* Set the length to 0xFF to mark that it's ready */
1299 *Length = 0xFF;
1300 }
1301 else
1302 {
1303 /* Not ready */
1304 *Length = 0;
1305 }
1306 }
1307
1308 return TRUE;
1309 }
1310
1311 /* Get Output Status */
1312 case 0x07:
1313 {
1314 /* Check if this is a file or a device */
1315 if (Node)
1316 {
1317 /* Device*/
1318
1319 if (!Node->OutputStatusRoutine || Node->OutputStatusRoutine(Node))
1320 {
1321 /* Set the length to 0xFF to mark that it's ready */
1322 *Length = 0xFF;
1323 }
1324 else
1325 {
1326 /* Not ready */
1327 *Length = 0;
1328 }
1329 }
1330 else
1331 {
1332 /* Files are always ready for output */
1333 *Length = 0xFF;
1334 }
1335
1336 return TRUE;
1337 }
1338
1339 /* Unsupported control code */
1340 default:
1341 {
1342 DPRINT1("Unsupported IOCTL: 0x%02X\n", ControlCode);
1343
1345 return FALSE;
1346 }
1347 }
1348}
#define UNIMPLEMENTED
Definition: debug.h:118
Definition: bufpool.h:45
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
PDOS_FILE_DESCRIPTOR DosGetHandleFileDescriptor(WORD DosHandle)
Definition: dosfiles.c:173
BOOLEAN DosDeviceIoControlDrive(WORD DriveNumber, BYTE ControlCode, DWORD Buffer, PWORD Result)
Definition: dosfiles.c:1128
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
WORD LastErrorCode
Definition: dos.h:160
PDOS_DEVICE_NODE DosGetDriverNode(DWORD Driver)
Definition: device.c:305
#define DOS_DEVATTR_IOCTL
Definition: device.h:28
VOID WINAPI setDX(USHORT)
Definition: registers.c:293
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

Referenced by DosInt21h().

◆ DosDeviceIoControlDrive()

BOOLEAN DosDeviceIoControlDrive ( WORD  DriveNumber,
BYTE  ControlCode,
DWORD  Buffer,
PWORD  Result 
)

Definition at line 1128 of file dosfiles.c.

1129{
1130 CHAR RootPath[] = "?:\\";
1131
1132 if (DriveNumber == 0x00)
1133 RootPath[0] = 'A' + Sda->CurrentDrive;
1134 else
1135 RootPath[0] = 'A' + DriveNumber - 1;
1136
1137 switch (ControlCode)
1138 {
1139 case 0x04:
1140 DPRINT1("UNIMPLEMENTED INT 21h, 4404h, Read from block device %s\n", RootPath);
1142 break;
1143 case 0x05:
1144 DPRINT1("UNIMPLEMENTED INT 21h, 4405h, Write block device control string %s\n", RootPath);
1146 break;
1147 case 0x08:
1148 {
1149 DWORD DriveType = GetDriveTypeA(RootPath);
1150
1151 switch (DriveType)
1152 {
1153 case DRIVE_UNKNOWN:
1154 case DRIVE_NO_ROOT_DIR:
1155 default:
1156 DPRINT1("INT 21h, 4408h, %s -> DriveType = 0x%x\n", RootPath, DriveType);
1157 *Result = 0x000f;
1158 return TRUE;
1159 case DRIVE_REMOVABLE:
1160 case DRIVE_CDROM:
1161 *Result = 0x0000;
1162 return TRUE;
1163 case DRIVE_FIXED:
1164 *Result = 0x0001;
1165 return TRUE;
1166 case DRIVE_REMOTE:
1167 case DRIVE_RAMDISK: // ??
1168 break;
1169 }
1171 return FALSE;
1172 }
1173 case 0x09:
1174 DPRINT1("UNIMPLEMENTED INT 21h, 4409h, Determine if a logical device is local or remote %s\n", RootPath);
1176 return FALSE;
1177 default:
1178 assert(0);
1179 break;
1180 }
1181
1182 return FALSE;
1183}
UINT DriveType
UINT WINAPI GetDriveTypeA(IN LPCSTR lpRootPathName)
Definition: disk.c:468
#define assert(x)
Definition: debug.h:53
#define DRIVE_CDROM
Definition: machpc98.h:119
BYTE CurrentDrive
Definition: dos.h:168
#define DRIVE_UNKNOWN
Definition: winbase.h:281
#define DRIVE_NO_ROOT_DIR
Definition: winbase.h:282
#define DRIVE_REMOTE
Definition: winbase.h:278
#define DRIVE_RAMDISK
Definition: winbase.h:280
#define DRIVE_FIXED
Definition: winbase.h:277
#define DRIVE_REMOVABLE
Definition: winbase.h:276
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
char CHAR
Definition: xmlstorage.h:175

Referenced by DosDeviceIoControl().

◆ DosFindDeviceDescriptor()

BYTE DosFindDeviceDescriptor ( DWORD  DevicePointer)

Definition at line 123 of file dosfiles.c.

124{
125 UINT i;
126 BYTE Count = 0;
127 DWORD CurrentSft = SysVars->FirstSft;
128
129 while (LOWORD(CurrentSft) != 0xFFFF)
130 {
131 PDOS_SFT Sft = (PDOS_SFT)FAR_POINTER(CurrentSft);
132
133 for (i = 0; i < Sft->NumDescriptors; i++)
134 {
135 if ((Sft->FileDescriptors[i].RefCount > 0)
137 && (Sft->FileDescriptors[i].DevicePointer == DevicePointer))
138 {
139 return Count;
140 }
141
142 Count++;
143 }
144
145 /* Go to the next table */
146 CurrentSft = Sft->Link;
147 }
148
149 /* Invalid ID */
150 return 0xFF;
151}
PDOS_SYSVARS SysVars
Definition: dos.c:47
struct _DOS_SFT * PDOS_SFT
#define FAR_POINTER(x)
Definition: emulator.h:35
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
unsigned int UINT
Definition: ndis.h:50
int Count
Definition: noreturn.cpp:7
#define LOWORD(l)
Definition: pedump.c:82
WORD NumDescriptors
Definition: dosfiles.h:67
DOS_FILE_DESCRIPTOR FileDescriptors[ANYSIZE_ARRAY]
Definition: dosfiles.h:68
DWORD Link
Definition: dosfiles.h:66
DWORD FirstSft
Definition: dos.h:81

Referenced by DosCopyHandleTable().

◆ DosFindFreeDescriptor()

BYTE DosFindFreeDescriptor ( VOID  )

Definition at line 69 of file dosfiles.c.

70{
71 UINT i;
72 BYTE Count = 0;
73 DWORD CurrentSft = SysVars->FirstSft;
74
75 while (LOWORD(CurrentSft) != 0xFFFF)
76 {
77 PDOS_SFT Sft = (PDOS_SFT)FAR_POINTER(CurrentSft);
78
79 for (i = 0; i < Sft->NumDescriptors; i++)
80 {
81 if (Sft->FileDescriptors[i].RefCount == 0) return Count;
82 Count++;
83 }
84
85 /* Go to the next table */
86 CurrentSft = Sft->Link;
87 }
88
89 /* Invalid ID */
90 return 0xFF;
91}

Referenced by DosCopyHandleTable(), DosCreateFile(), DosCreateFileEx(), and DosOpenFile().

◆ DosFindWin32Descriptor()

BYTE DosFindWin32Descriptor ( HANDLE  Win32Handle)

Definition at line 93 of file dosfiles.c.

94{
95 UINT i;
96 BYTE Count = 0;
97 DWORD CurrentSft = SysVars->FirstSft;
98
99 while (LOWORD(CurrentSft) != 0xFFFF)
100 {
101 PDOS_SFT Sft = (PDOS_SFT)FAR_POINTER(CurrentSft);
102
103 for (i = 0; i < Sft->NumDescriptors; i++)
104 {
105 if ((Sft->FileDescriptors[i].RefCount > 0)
107 && (Sft->FileDescriptors[i].Win32Handle == Win32Handle))
108 {
109 return Count;
110 }
111
112 Count++;
113 }
114
115 /* Go to the next table */
116 CurrentSft = Sft->Link;
117 }
118
119 /* Invalid ID */
120 return 0xFF;
121}

Referenced by DosCopyHandleTable().

◆ DosFlushFileBuffers()

BOOL DosFlushFileBuffers ( WORD  FileHandle)

Definition at line 1056 of file dosfiles.c.

1057{
1059
1060 if (Descriptor == NULL)
1061 {
1062 /* Invalid handle */
1064 return FALSE;
1065 }
1066
1067 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE)
1068 {
1070
1071 if (Node->FlushInputRoutine) Node->FlushInputRoutine(Node);
1072 if (Node->FlushOutputRoutine) Node->FlushOutputRoutine(Node);
1073
1074 return TRUE;
1075 }
1076 else
1077 {
1078 return FlushFileBuffers(Descriptor->Win32Handle);
1079 }
1080}
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25

Referenced by DosInt21h().

◆ DosGetFileDescriptor()

PDOS_FILE_DESCRIPTOR DosGetFileDescriptor ( BYTE  Id)

Definition at line 153 of file dosfiles.c.

154{
155 DWORD CurrentSft = SysVars->FirstSft;
156
157 while (LOWORD(CurrentSft) != 0xFFFF)
158 {
159 PDOS_SFT Sft = (PDOS_SFT)FAR_POINTER(CurrentSft);
160
161 /* Return it if it's in this table */
162 if (Id <= Sft->NumDescriptors) return &Sft->FileDescriptors[Id];
163
164 /* Go to the next table */
165 Id -= Sft->NumDescriptors;
166 CurrentSft = Sft->Link;
167 }
168
169 /* Invalid ID */
170 return NULL;
171}
DWORD Id

Referenced by DosCloseHandle(), DosCopyHandleTable(), DosCreateFile(), DosCreateFileEx(), DosForceDuplicateHandle(), DosGetHandleFileDescriptor(), DosOpenFile(), and DosOpenHandle().

◆ DosGetHandleFileDescriptor()

PDOS_FILE_DESCRIPTOR DosGetHandleFileDescriptor ( WORD  DosHandle)

Definition at line 173 of file dosfiles.c.

174{
175 BYTE DescriptorId = DosQueryHandle(DosHandle);
176 if (DescriptorId == 0xFF) return NULL;
177
178 return DosGetFileDescriptor(DescriptorId);
179}
BYTE DosQueryHandle(WORD DosHandle)
Definition: handle.c:238

Referenced by DosCheckInput(), DosDeviceIoControl(), DosFlushFileBuffers(), DosInt21h(), DosLockFile(), DosReadCharacter(), DosReadFile(), DosReadLineBuffered(), DosSeekFile(), DosUnlockFile(), and DosWriteFile().

◆ DosLockFile()

BOOLEAN DosLockFile ( WORD  DosHandle,
DWORD  Offset,
DWORD  Size 
)

Definition at line 1082 of file dosfiles.c.

1083{
1085
1086 if (Descriptor == NULL)
1087 {
1088 /* Invalid handle */
1090 return FALSE;
1091 }
1092
1093 /* Always succeed for character devices */
1094 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE) return TRUE;
1095
1096 if (!LockFile(Descriptor->Win32Handle, Offset, 0, Size, 0))
1097 {
1099 return FALSE;
1100 }
1101
1102 return TRUE;
1103}
BOOL WINAPI LockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToLockLow, IN DWORD nNumberOfBytesToLockHigh)
Definition: lock.c:25
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by DosInt21h().

◆ DosOpenFile()

WORD DosOpenFile ( LPWORD  Handle,
LPCSTR  FilePath,
BYTE  AccessShareModes 
)

Definition at line 521 of file dosfiles.c.

524{
527 WORD DosHandle;
528 BYTE DescriptorId;
530
531 DPRINT("DosOpenFile: FilePath \"%s\", AccessShareModes 0x%04X\n",
532 FilePath, AccessShareModes);
533
534 //
535 // The article about OpenFile API: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365430(v=vs.85).aspx
536 // explains what those AccessShareModes are (see the uStyle flag).
537 //
538
540 if (Node != NULL)
541 {
542 if (Node->OpenRoutine) Node->OpenRoutine(Node);
543 }
544 else
545 {
547 DWORD ShareMode = 0;
548 BOOL InheritableFile = FALSE;
549 SECURITY_ATTRIBUTES SecurityAttributes;
550
551 /* Parse the access mode */
552 switch (AccessShareModes & 0x03)
553 {
554 /* Read-only */
555 case 0:
557 break;
558
559 /* Write only */
560 case 1:
562 break;
563
564 /* Read and write */
565 case 2:
567 break;
568
569 /* Invalid */
570 default:
572 }
573
574 /* Parse the share mode */
575 switch ((AccessShareModes >> 4) & 0x07)
576 {
577 /* Compatibility mode */
578 case 0:
580 break;
581
582 /* No sharing "DenyAll" */
583 case 1:
584 ShareMode = 0;
585 break;
586
587 /* No write share "DenyWrite" */
588 case 2:
589 ShareMode = FILE_SHARE_READ;
590 break;
591
592 /* No read share "DenyRead" */
593 case 3:
594 ShareMode = FILE_SHARE_WRITE;
595 break;
596
597 /* Full share "DenyNone" */
598 case 4:
599 ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
600 break;
601
602 /* Invalid */
603 default:
605 }
606
607 /* Check for inheritance */
608 InheritableFile = ((AccessShareModes & 0x80) == 0);
609
610 /* Assign default security attributes to the file, and set the inheritance flag */
611 SecurityAttributes.nLength = sizeof(SecurityAttributes);
612 SecurityAttributes.lpSecurityDescriptor = NULL;
613 SecurityAttributes.bInheritHandle = InheritableFile;
614
615 /* Open the file */
618 ShareMode,
619 &SecurityAttributes,
622 NULL);
624 {
625 /* Return the error code */
626 return (WORD)GetLastError();
627 }
628 }
629
630 DescriptorId = DosFindFreeDescriptor();
631 if (DescriptorId == 0xFF)
632 {
633 /* Close the file and return the error code */
636 }
637
638 /* Set up the new descriptor */
639 Descriptor = DosGetFileDescriptor(DescriptorId);
641 RtlFillMemory(Descriptor->FileName, sizeof(Descriptor->FileName), ' ');
642
643 if (Node != NULL)
644 {
645 Descriptor->DevicePointer = Node->Driver;
646 Descriptor->DeviceInfo = Node->DeviceAttributes | FILE_INFO_DEVICE;
647 RtlCopyMemory(Descriptor->FileName, Node->Name.Buffer, Node->Name.Length);
648 }
649 else
650 {
651 Descriptor->OpenMode = AccessShareModes;
654 Descriptor->Win32Handle = FileHandle;
656 }
657
658 Descriptor->OwnerPsp = Sda->CurrentPsp;
659
660 /* Open the DOS handle */
661 DosHandle = DosOpenHandle(DescriptorId);
662 if (DosHandle == INVALID_DOS_HANDLE)
663 {
664 /* Close the file and return the error code */
667 }
668
669 /* It was successful */
670 *Handle = DosHandle;
671 return ERROR_SUCCESS;
672}
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137

Referenced by DosInt21h().

◆ DosReadFile()

WORD DosReadFile ( WORD  FileHandle,
DWORD  Buffer,
WORD  Count,
LPWORD  BytesRead 
)

Definition at line 768 of file dosfiles.c.

772{
775 BYTE StaticBuffer[8192];
776
777 DPRINT("DosReadFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, Count);
778
779 if (Descriptor == NULL)
780 {
781 /* Invalid handle */
783 }
784
785 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE)
786 {
788 if (!Node->ReadRoutine) return ERROR_INVALID_FUNCTION;
789
790 if (Descriptor->DeviceInfo & FILE_INFO_BINARY)
791 {
792 /* Read from the device directly */
793 Node->ReadRoutine(Node, Buffer, &Count);
794 *BytesRead = Count;
795 }
796 else if (Descriptor->DeviceInfo & FILE_INFO_STDIN)
797 {
798 /* Line-buffered CON input */
799 PCHAR ConBuffer = NULL;
800 PCHAR Pointer = FAR_POINTER(Buffer);
801
802 /* Check if the buffer is empty */
804 {
805 SysVars->UnreadConInput = FIELD_OFFSET(DOS_DATA, UnreadConInputBuffer);
806
810 }
811
812 *BytesRead = 0;
814
815 while (*BytesRead < Count)
816 {
817 Pointer[(*BytesRead)++] = *ConBuffer;
818
819 if (*ConBuffer == '\r')
820 {
821 /* A carriage return turns into a line feed */
822 *ConBuffer = '\n';
823 }
824 else if (*ConBuffer == '\n')
825 {
826 /* A line feed marks the true end of the line */
828
829 /* Echo the line feed */
830 DosEchoCharacter('\n');
831 break;
832 }
833 else
834 {
835 /* Move to the next character */
837 ConBuffer++;
838 }
839 }
840 }
841 else
842 {
843 /* Translated input from a character device that isn't CON */
844 PCHAR Pointer = FAR_POINTER(Buffer);
845 CHAR Character;
846
847 *BytesRead = 0;
848
849 while (*BytesRead < Count)
850 {
851 USHORT Amount = 1;
852
853 /* Read a character from the device */
854 Node->ReadRoutine(Node,
857 &Amount);
858 if (Amount == 0) break;
859
860 Character = Sda->ByteBuffer;
861 // TODO: Process it somehow?
862
863 /* Store the character in the output buffer */
864 Pointer[(*BytesRead)++] = Character;
865
866 /* Check for EOF */
867 if (Character == 0x1A) break;
868 }
869 }
870 }
871 else
872 {
873 DWORD BytesRead32 = 0;
874 PVOID LocalBuffer;
875
876 if (Count <= sizeof(StaticBuffer))
877 {
878 LocalBuffer = StaticBuffer;
879 }
880 else
881 {
882 LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count);
883 ASSERT(LocalBuffer != NULL);
884 }
885
886 /* Read from the file */
887 if (ReadFile(Descriptor->Win32Handle, LocalBuffer, Count, &BytesRead32, NULL))
888 {
889 /* Write to the memory */
892 LocalBuffer,
893 LOWORD(BytesRead32));
894
895 /* Update the position */
896 Descriptor->Position += BytesRead32; // or LOWORD(BytesRead32); ?
897 }
898 else
899 {
900 /* Store the error code */
902 }
903
904 /* The number of bytes read is always 16-bit */
905 *BytesRead = LOWORD(BytesRead32);
906
907 if (LocalBuffer != StaticBuffer)
908 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
909 }
910
911 /* Return the error code */
912 return Result;
913}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
PDOS_DATA DosData
Definition: dos.c:45
BYTE DosReadLineBuffered(WORD FileHandle, DWORD Buffer, BYTE MaxSize)
Definition: dosfiles.c:674
#define FILE_INFO_BINARY
Definition: dosfiles.h:15
#define FILE_INFO_STDIN
Definition: dosfiles.h:13
#define TO_LINEAR(seg, off)
Definition: emulator.h:26
#define SEG_OFF_TO_PTR(seg, off)
Definition: emulator.h:32
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
Definition: fsrtlfuncs.h:551
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
unsigned short USHORT
Definition: pedump.c:61
Definition: dos.h:252
BYTE UnreadConInputBuffer[128]
Definition: dos.h:258
BYTE ByteBuffer
Definition: dos.h:202
WORD UnreadConInput
Definition: dos.h:76
FAST486_STATE EmulatorContext
Definition: cpu.c:39
VOID DosEchoCharacter(CHAR Character)
Definition: bios.c:48
#define DOS_DATA_OFFSET(x)
Definition: dos.h:35
#define DOS_DATA_SEGMENT
Definition: dos.h:33
VOID FASTCALL EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:186
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define HIWORD(l)
Definition: typedefs.h:247
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870

Referenced by DosInt21h(), and DosReadCharacter().

◆ DosReadLineBuffered()

BYTE DosReadLineBuffered ( WORD  FileHandle,
DWORD  Buffer,
BYTE  MaxSize 
)

Definition at line 674 of file dosfiles.c.

675{
678 BYTE LineSize = 0;
679 PCHAR Pointer = FAR_POINTER(Buffer);
680 CHAR Character;
681
682 do
683 {
684 USHORT Amount = 1;
685
686 /* Read a character from the device */
687 Node->ReadRoutine(Node,
690 &Amount);
691 if (Amount == 0) break;
692
693 Character = Sda->ByteBuffer;
694
695 if (LineSize == MaxSize - 1 && Character != '\r' && Character != '\b')
696 {
697 /* Line buffer full */
698 // TODO: Should we beep?
699 continue;
700 }
701
702 switch (Character)
703 {
704 /* Extended character */
705 case '\0':
706 {
707 /* Read the scancode and discard it */
708 Amount = 1;
709 Node->ReadRoutine(Node,
712 &Amount);
713 break;
714 }
715
716 /* Ctrl-C */
717 case 0x03:
718 {
719 DosEchoCharacter(Character);
720
721 if (DosControlBreak())
722 {
723 /* Set the character to CR to end the loop */
724 Character = '\r';
725 }
726
727 break;
728 }
729
730 case '\n':
731 {
732 DosEchoCharacter('\r');
733 DosEchoCharacter('\n');
734 break;
735 }
736
737 case '\b':
738 {
739 if (LineSize > 0)
740 {
741 LineSize--;
742 DosEchoCharacter(Character);
743
744 /* Erase the '^' too */
745 if (Pointer[LineSize] > 0x00 && Pointer[LineSize] < 0x20)
746 {
747 DosEchoCharacter(Character);
748 }
749 }
750
751 break;
752 }
753
754 default:
755 {
756 /* Store the character in the buffer */
757 Pointer[LineSize++] = Character;
758 DosEchoCharacter(Character);
759 }
760 }
761
762 /* Stop on a carriage return */
763 } while (Character != '\r');
764
765 return LineSize - 1;
766}
BOOLEAN DosControlBreak(VOID)
Definition: dos.c:181

Referenced by DosInt21h(), and DosReadFile().

◆ DosSeekFile()

WORD DosSeekFile ( WORD  FileHandle,
LONG  Offset,
BYTE  Origin,
LPDWORD  NewOffset 
)

Definition at line 1001 of file dosfiles.c.

1005{
1007 DWORD FilePointer;
1009
1010 DPRINT("DosSeekFile: FileHandle 0x%04X, Offset 0x%08X, Origin 0x%02X\n",
1011 FileHandle, Offset, Origin);
1012
1013 if (Descriptor == NULL)
1014 {
1015 /* Invalid handle */
1016 return ERROR_INVALID_HANDLE;
1017 }
1018
1019 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE)
1020 {
1021 /* For character devices, always return success */
1022 return ERROR_SUCCESS;
1023 }
1024
1025 /* Check if the origin is valid */
1026 if (Origin != FILE_BEGIN && Origin != FILE_CURRENT && Origin != FILE_END)
1027 {
1029 }
1030
1031 FilePointer = SetFilePointer(Descriptor->Win32Handle, Offset, NULL, Origin);
1032
1033 /* Check if there's a possibility the operation failed */
1034 if (FilePointer == INVALID_SET_FILE_POINTER)
1035 {
1036 /* Get the real error code */
1038 }
1039
1040 if (Result != ERROR_SUCCESS)
1041 {
1042 /* The operation did fail */
1043 return Result;
1044 }
1045
1046 /* Update the position */
1047 Descriptor->Position = FilePointer;
1048
1049 /* Return the file pointer, if requested */
1050 if (NewOffset) *NewOffset = FilePointer;
1051
1052 /* Return success */
1053 return ERROR_SUCCESS;
1054}
#define FILE_BEGIN
Definition: compat.h:761
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define SetFilePointer
Definition: compat.h:743
#define FILE_END
Definition: winbase.h:114
#define FILE_CURRENT
Definition: winbase.h:113

Referenced by DosInt21h().

◆ DosUnlockFile()

BOOLEAN DosUnlockFile ( WORD  DosHandle,
DWORD  Offset,
DWORD  Size 
)

Definition at line 1105 of file dosfiles.c.

1106{
1108
1109 if (Descriptor == NULL)
1110 {
1111 /* Invalid handle */
1113 return FALSE;
1114 }
1115
1116 /* Always succeed for character devices */
1117 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE) return TRUE;
1118
1119 if (!UnlockFile(Descriptor->Win32Handle, Offset, 0, Size, 0))
1120 {
1122 return FALSE;
1123 }
1124
1125 return TRUE;
1126}
BOOL WINAPI UnlockFile(IN HANDLE hFile, IN DWORD dwFileOffsetLow, IN DWORD dwFileOffsetHigh, IN DWORD nNumberOfBytesToUnlockLow, IN DWORD nNumberOfBytesToUnlockHigh)
Definition: lock.c:142

Referenced by DosInt21h().

◆ DosWriteFile()

WORD DosWriteFile ( WORD  FileHandle,
DWORD  Buffer,
WORD  Count,
LPWORD  BytesWritten 
)

Definition at line 915 of file dosfiles.c.

919{
922 BYTE StaticBuffer[8192];
923
924 DPRINT("DosWriteFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, Count);
925
926 if (Descriptor == NULL)
927 {
928 /* Invalid handle */
930 }
931
932 if (Descriptor->DeviceInfo & FILE_INFO_DEVICE)
933 {
935 if (!Node->WriteRoutine) return ERROR_INVALID_FUNCTION;
936
937 /* Read the device */
938 Node->WriteRoutine(Node, Buffer, &Count);
940 }
941 else
942 {
943 DWORD BytesWritten32 = 0;
944 PVOID LocalBuffer;
945
946 /*
947 * Writing zero bytes truncates or extends the file
948 * to the current position of the file pointer.
949 */
950 if (Count == 0)
951 {
952 if (!SetEndOfFile(Descriptor->Win32Handle))
953 {
954 /* Store the error code */
956 }
957 *BytesWritten = 0;
958 return Result;
959 }
960
961 if (Count <= sizeof(StaticBuffer))
962 {
963 LocalBuffer = StaticBuffer;
964 }
965 else
966 {
967 LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Count);
968 ASSERT(LocalBuffer != NULL);
969 }
970
971 /* Read from the memory */
974 LocalBuffer,
975 Count);
976
977 /* Write to the file */
978 if (WriteFile(Descriptor->Win32Handle, LocalBuffer, Count, &BytesWritten32, NULL))
979 {
980 /* Update the position and size */
981 Descriptor->Position += BytesWritten32; // or LOWORD(BytesWritten32); ?
982 if (Descriptor->Position > Descriptor->Size) Descriptor->Size = Descriptor->Position;
983 }
984 else
985 {
986 /* Store the error code */
988 }
989
990 /* The number of bytes written is always 16-bit */
991 *BytesWritten = LOWORD(BytesWritten32);
992
993 if (LocalBuffer != StaticBuffer)
994 RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
995 }
996
997 /* Return the error code */
998 return Result;
999}
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
VOID FASTCALL EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:142
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960

Referenced by DosInt21h(), and DosPrintCharacter().

◆ StoreNameInSft()

static VOID StoreNameInSft ( LPCSTR  FilePath,
PDOS_FILE_DESCRIPTOR  Descriptor 
)
static

Definition at line 30 of file dosfiles.c.

31{
32 CHAR ShortPath[MAX_PATH];
33 PCHAR Name;
35
36 /* Try to get the short path */
37 if (!GetShortPathNameA(FilePath, ShortPath, sizeof(ShortPath)))
38 {
39 /* If it failed, just use the uppercase long path */
40 strncpy(ShortPath, FilePath, sizeof(ShortPath) - 1);
41 _strupr(ShortPath);
42 }
43
44 /* Get the name part */
45 Name = strrchr(ShortPath, '\\');
46 if (Name == NULL) Name = ShortPath;
47
48 /* Find the extension */
49 Extension = strchr(Name, '.');
50
51 if (Extension)
52 {
53 /* Terminate the name string, and move the pointer to after the dot */
54 *Extension++ = 0;
55 }
56
57 /* Copy the name into the SFT descriptor */
58 RtlCopyMemory(Descriptor->FileName, Name, min(strlen(Name), 8));
59
60 if (Extension)
61 {
62 /* Copy the extension too */
64 }
65}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char * strchr(const char *String, int ch)
Definition: utclib.c:501
struct NameRec_ * Name
Definition: cdprocs.h:460
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetShortPathNameA(IN LPCSTR lpszLongPath, OUT LPSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1752
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
#define min(a, b)
Definition: monoChain.cc:55
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)

Referenced by DosCreateFile(), DosCreateFileEx(), and DosOpenFile().