ReactOS  0.4.13-dev-687-g023794c
disk.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "disk.h"
#include "memory.h"
#include "utils.h"
Include dependency graph for disk.c:

Go to the source code of this file.

Classes

struct  _VHD_FOOTER
 
struct  _DISK_GEO
 
struct  _DISK_MOUNT_INFO
 

Macros

#define NDEBUG
 
#define VHD_TIMESTAMP_BASE   946684800
 

Typedefs

typedef struct _VHD_FOOTER VHD_FOOTER
 
typedef struct _VHD_FOOTERPVHD_FOOTER
 
typedef struct _DISK_GEO DISK_GEO
 
typedef struct _DISK_GEOPDISK_GEO
 
typedef BOOLEAN(* MOUNT_DISK_HANDLER) (IN PDISK_IMAGE DiskImage, IN HANDLE hFile)
 
typedef struct _DISK_MOUNT_INFO DISK_MOUNT_INFO
 
typedef struct _DISK_MOUNT_INFOPDISK_MOUNT_INFO
 

Enumerations

enum  VHD_TYPE { VHD_FIXED = 2, VHD_DYNAMIC = 3, VHD_DIFFERENCING = 4 }
 

Functions

 C_ASSERT (sizeof(VHD_FOOTER)==0x200)
 
BOOLEAN MountFDI (IN PDISK_IMAGE DiskImage, IN HANDLE hFile)
 
BOOLEAN MountHDD (IN PDISK_IMAGE DiskImage, IN HANDLE hFile)
 
BOOLEAN IsDiskPresent (IN PDISK_IMAGE DiskImage)
 
BYTE SeekDisk (IN PDISK_IMAGE DiskImage, IN WORD Cylinder, IN BYTE Head, IN BYTE Sector)
 
BYTE ReadDisk (IN PDISK_IMAGE DiskImage, IN WORD Cylinder, IN BYTE Head, IN BYTE Sector, IN BYTE NumSectors)
 
BYTE WriteDisk (IN PDISK_IMAGE DiskImage, IN WORD Cylinder, IN BYTE Head, IN BYTE Sector, IN BYTE NumSectors)
 
PDISK_IMAGE RetrieveDisk (IN DISK_TYPE DiskType, IN ULONG DiskNumber)
 
BOOLEAN MountDisk (IN DISK_TYPE DiskType, IN ULONG DiskNumber, IN PCWSTR FileName, IN BOOLEAN ReadOnly)
 
BOOLEAN UnmountDisk (IN DISK_TYPE DiskType, IN ULONG DiskNumber)
 
BOOLEAN DiskCtrlInitialize (VOID)
 
VOID DiskCtrlCleanup (VOID)
 

Variables

static DISK_IMAGE XDCFloppyDrive [4]
 
static WORD HackSectorSize = 512
 
static DISK_GEO DiskGeometryList []
 
static DISK_IMAGE XDCHardDrive [4]
 
static DISK_MOUNT_INFO DiskMountInfo [MAX_DISK_TYPE]
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 25 of file disk.c.

◆ VHD_TIMESTAMP_BASE

#define VHD_TIMESTAMP_BASE   946684800

Definition at line 55 of file disk.c.

Typedef Documentation

◆ DISK_GEO

◆ DISK_MOUNT_INFO

◆ MOUNT_DISK_HANDLER

typedef BOOLEAN(* MOUNT_DISK_HANDLER) (IN PDISK_IMAGE DiskImage, IN HANDLE hFile)

Definition at line 469 of file disk.c.

◆ PDISK_GEO

◆ PDISK_MOUNT_INFO

◆ PVHD_FOOTER

◆ VHD_FOOTER

Enumeration Type Documentation

◆ VHD_TYPE

Enumerator
VHD_FIXED 
VHD_DYNAMIC 
VHD_DIFFERENCING 

Definition at line 47 of file disk.c.

48 {
49  VHD_FIXED = 2,
50  VHD_DYNAMIC = 3,
51  VHD_DIFFERENCING = 4,
52 };
Definition: disk.c:49

Function Documentation

◆ C_ASSERT()

C_ASSERT ( sizeof(VHD_FOOTER = =0x200)

◆ DiskCtrlCleanup()

VOID DiskCtrlCleanup ( VOID  )

Definition at line 637 of file disk.c.

638 {
639  ULONG DiskNumber;
640 
641  /* Unmount all the floppy disk drives */
642  for (DiskNumber = 0; DiskNumber < DiskMountInfo[FLOPPY_DISK].NumDisks; ++DiskNumber)
643  UnmountDisk(FLOPPY_DISK, DiskNumber);
644 
645  /* Unmount all the hard disk drives */
646  for (DiskNumber = 0; DiskNumber < DiskMountInfo[HARD_DISK].NumDisks; ++DiskNumber)
647  UnmountDisk(HARD_DISK, DiskNumber);
648 }
ULONG NumDisks
Definition: disk.c:474
BOOLEAN UnmountDisk(IN DISK_TYPE DiskType, IN ULONG DiskNumber)
Definition: disk.c:602
unsigned int ULONG
Definition: retypes.h:1
static DISK_MOUNT_INFO DiskMountInfo[MAX_DISK_TYPE]
Definition: disk.c:478
Definition: disk.h:45

Referenced by EmulatorCleanup().

◆ DiskCtrlInitialize()

BOOLEAN DiskCtrlInitialize ( VOID  )

Definition at line 632 of file disk.c.

633 {
634  return TRUE;
635 }
#define TRUE
Definition: types.h:120

Referenced by EmulatorInitialize().

◆ IsDiskPresent()

BOOLEAN IsDiskPresent ( IN PDISK_IMAGE  DiskImage)

Definition at line 321 of file disk.c.

322 {
323  ASSERT(DiskImage);
324  return (DiskImage->hDisk != INVALID_HANDLE_VALUE && DiskImage->hDisk != NULL);
325 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by BiosDiskService(), MountDisk(), and UnmountDisk().

◆ MountDisk()

BOOLEAN MountDisk ( IN DISK_TYPE  DiskType,
IN ULONG  DiskNumber,
IN PCWSTR  FileName,
IN BOOLEAN  ReadOnly 
)

Definition at line 500 of file disk.c.

504 {
506  PDISK_IMAGE DiskImage;
507  HANDLE hFile;
508 
510 
511  ASSERT(DiskType < MAX_DISK_TYPE);
512 
513  if (DiskNumber >= DiskMountInfo[DiskType].NumDisks)
514  {
515  DisplayMessage(L"MountDisk: Disk number %d:%d invalid.", DiskType, DiskNumber);
516  return FALSE;
517  }
518 
519  DiskImage = &DiskMountInfo[DiskType].DiskArray[DiskNumber];
520  if (IsDiskPresent(DiskImage))
521  {
522  DPRINT1("MountDisk: Disk %d:%d:0x%p already in use, recycling...\n", DiskType, DiskNumber, DiskImage);
523  UnmountDisk(DiskType, DiskNumber);
524  }
525 
526  /* Try to open the file */
527  SetLastError(0); // For debugging purposes
528  if (ReadOnly)
529  {
531  GENERIC_READ,
533  NULL,
536  NULL);
537  }
538  else
539  {
542  0, // No sharing access
543  NULL,
546  NULL);
547  }
548  DPRINT1("File '%S' opening %s ; GetLastError() = %u\n",
549  FileName, hFile != INVALID_HANDLE_VALUE ? "succeeded" : "failed", GetLastError());
550 
551  /* If we failed, bail out */
553  {
554  DisplayMessage(L"MountDisk: Error when opening disk file '%s' (Error: %u).", FileName, GetLastError());
555  return FALSE;
556  }
557 
558  /* OK, we have a handle to the file */
559 
560  /*
561  * Check that it is really a file, and not a physical drive.
562  * For obvious security reasons, we do not want to be able to
563  * write directly to physical drives.
564  *
565  * Redundant checks
566  */
567  SetLastError(0);
570  {
571  /* Objects other than real files are not supported */
572  DisplayMessage(L"MountDisk: '%s' is not a valid disk file.", FileName);
573  goto Quit;
574  }
575  SetLastError(0);
578  {
579  /* Objects other than real files are not supported */
580  DisplayMessage(L"MountDisk: '%s' is not a valid disk file.", FileName);
581  goto Quit;
582  }
583 
584  /* Success, mount the image */
585  if (!DiskMountInfo[DiskType].MountDiskHelper(DiskImage, hFile))
586  {
587  DisplayMessage(L"MountDisk: Failed to mount disk file '%s' in 0x%p.", FileName, DiskImage);
588  goto Quit;
589  }
590 
591  /* Update its read/write state */
592  DiskImage->ReadOnly = ReadOnly;
593 
594  Success = TRUE;
595 
596 Quit:
597  if (!Success) FileClose(hFile);
598  return Success;
599 }
#define TRUE
Definition: types.h:120
PDISK_IMAGE DiskArray
Definition: disk.c:473
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
Definition: arc.h:80
BOOLEAN IsDiskPresent(IN PDISK_IMAGE DiskImage)
Definition: disk.c:321
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define INVALID_FILE_SIZE
Definition: winbase.h:529
VOID FileClose(IN HANDLE FileHandle)
Definition: utils.c:21
#define FILE_SHARE_READ
Definition: compat.h:125
#define GENERIC_WRITE
Definition: nt_native.h:90
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:608
BOOLEAN ReadOnly
Definition: disk.h:37
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define SetLastError(x)
Definition: compat.h:409
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOLEAN UnmountDisk(IN DISK_TYPE DiskType, IN ULONG DiskNumber)
Definition: disk.c:602
#define DPRINT1
Definition: precomp.h:8
#define CreateFileW
Definition: compat.h:400
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
static DISK_MOUNT_INFO DiskMountInfo[MAX_DISK_TYPE]
Definition: disk.c:478

Referenced by EmulatorInitialize(), and MountFloppy().

◆ MountFDI()

BOOLEAN MountFDI ( IN PDISK_IMAGE  DiskImage,
IN HANDLE  hFile 
)

Definition at line 190 of file disk.c.

192 {
193  ULONG FileSize;
194  USHORT i;
195 
196  /*
197  * Retrieve the size of the file. In NTVDM we will handle files
198  * of maximum 1Mb so we can largely use GetFileSize only.
199  */
202  {
203  /* We failed, bail out */
204  DisplayMessage(L"MountFDI: Error when retrieving file size, or size too large (%d).", FileSize);
205  return FALSE;
206  }
207 
208  /* Convert the size in kB */
209  FileSize /= 1024;
210 
211  /* Find the floppy format in the list, and mount it if found */
212  for (i = 0; i < ARRAYSIZE(DiskGeometryList); ++i)
213  {
214  if (DiskGeometryList[i].ksize == FileSize ||
215  DiskGeometryList[i].ksize + 1 == FileSize)
216  {
217  /* Found, mount it */
218  DiskImage->DiskType = DiskGeometryList[i].biosval;
219  DiskImage->DiskInfo.Cylinders = DiskGeometryList[i].cylcount;
220  DiskImage->DiskInfo.Heads = DiskGeometryList[i].headscyl;
221  DiskImage->DiskInfo.Sectors = DiskGeometryList[i].secttrack;
222  DiskImage->DiskInfo.SectorSize = HackSectorSize;
223 
224  /* Set the file pointer to the beginning */
226 
227  DiskImage->hDisk = hFile;
228  return TRUE;
229  }
230  }
231 
232  /* If we are here, we failed to find a suitable format. Bail out. */
233  DisplayMessage(L"MountFDI: Floppy image of invalid size %d.", FileSize);
234  return FALSE;
235 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
WORD headscyl
Definition: disk.c:168
static DISK_GEO DiskGeometryList[]
Definition: disk.c:175
WORD secttrack
Definition: disk.c:167
static WORD HackSectorSize
Definition: disk.c:174
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define INVALID_FILE_SIZE
Definition: winbase.h:529
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
WORD biosval
Definition: disk.c:170
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
smooth NULL
Definition: ftsmooth.c:416
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
static const WCHAR L[]
Definition: oid.c:1250
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_BEGIN
Definition: winbase.h:112
unsigned short USHORT
Definition: pedump.c:61
WORD cylcount
Definition: disk.c:169
unsigned int ULONG
Definition: retypes.h:1
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239

◆ MountHDD()

BOOLEAN MountHDD ( IN PDISK_IMAGE  DiskImage,
IN HANDLE  hFile 
)

Definition at line 246 of file disk.c.

248 {
249  /**** Support for VHD fixed disks ****/
250  DWORD FilePointer, BytesToRead;
251  VHD_FOOTER vhd_footer;
252 
253  /* Go to the end of the file and retrieve the footer */
254  FilePointer = SetFilePointer(hFile, -(LONG)sizeof(VHD_FOOTER), NULL, FILE_END);
255  if (FilePointer == INVALID_SET_FILE_POINTER)
256  {
257  DPRINT1("MountHDD: Error when seeking HDD footer, last error = %d\n", GetLastError());
258  return FALSE;
259  }
260 
261  /* Read footer */
262  // FIXME: We may consider just mapping section to the file...
263  BytesToRead = sizeof(VHD_FOOTER);
264  if (!ReadFile(hFile, &vhd_footer, BytesToRead, &BytesToRead, NULL))
265  {
266  DPRINT1("MountHDD: Error when reading HDD footer, last error = %d\n", GetLastError());
267  return FALSE;
268  }
269 
270  /* Perform validity checks */
271  if (RtlCompareMemory(vhd_footer.creator, "conectix",
272  sizeof(vhd_footer.creator)) != sizeof(vhd_footer.creator))
273  {
274  DisplayMessage(L"MountHDD: Invalid HDD image (expected VHD).");
275  return FALSE;
276  }
277  if (vhd_footer.version != 0x00000100 &&
278  vhd_footer.version != 0x00000500) // FIXME: Big endian!
279  {
280  DisplayMessage(L"MountHDD: VHD HDD image of unexpected version %d.", vhd_footer.version);
281  return FALSE;
282  }
283  if (RtlUlongByteSwap(vhd_footer.type) != VHD_FIXED) // FIXME: Big endian!
284  {
285  DisplayMessage(L"MountHDD: Only VHD HDD fixed images are supported.");
286  return FALSE;
287  }
288  if (vhd_footer.data_offset != 0xFFFFFFFFFFFFFFFF)
289  {
290  DisplayMessage(L"MountHDD: Unexpected data offset for VHD HDD fixed image.");
291  return FALSE;
292  }
293  if (vhd_footer.orig_size != vhd_footer.size)
294  {
295  DisplayMessage(L"MountHDD: VHD HDD fixed image size should be the same as its original size.");
296  return FALSE;
297  }
298  // FIXME: Checksum!
299 
300  /* Found, mount it */
301  DiskImage->DiskType = 0;
302  DiskImage->DiskInfo.Cylinders = RtlUshortByteSwap(vhd_footer.cyls); // FIXME: Big endian!
303  DiskImage->DiskInfo.Heads = vhd_footer.heads;
304  DiskImage->DiskInfo.Sectors = vhd_footer.secs_per_cyl;
305  DiskImage->DiskInfo.SectorSize = RtlUlonglongByteSwap(vhd_footer.size) / // FIXME: Big endian!
306  DiskImage->DiskInfo.Cylinders /
307  DiskImage->DiskInfo.Heads / DiskImage->DiskInfo.Sectors;
308 
309  /* Set the file pointer to the beginning */
311 
312  DiskImage->hDisk = hFile;
313  return TRUE;
314 }
#define TRUE
Definition: types.h:120
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
#define RtlUlonglongByteSwap(_x)
Definition: rtlfuncs.h:3201
#define RtlUshortByteSwap(_x)
Definition: rtlfuncs.h:3199
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define FILE_END
Definition: winbase.h:114
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
struct _VHD_FOOTER VHD_FOOTER
_In_ HANDLE hFile
Definition: mswsock.h:90
#define RtlUlongByteSwap(_x)
Definition: compat.h:465
#define FILE_BEGIN
Definition: winbase.h:112
Definition: disk.c:49
#define DPRINT1
Definition: precomp.h:8
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

◆ ReadDisk()

BYTE ReadDisk ( IN PDISK_IMAGE  DiskImage,
IN WORD  Cylinder,
IN BYTE  Head,
IN BYTE  Sector,
IN BYTE  NumSectors 
)

Definition at line 359 of file disk.c.

364 {
365  BYTE Result;
366  DWORD BytesToRead;
367 
368  PVOID LocalBuffer;
369  BYTE StaticBuffer[1024];
370 
371  /* Read the sectors */
372  Result = SeekDisk(DiskImage, Cylinder, Head, Sector);
373  if (Result != 0x00)
374  return Result;
375 
376  BytesToRead = (DWORD)NumSectors * DiskImage->DiskInfo.SectorSize;
377 
378  // FIXME: Consider just looping around filling each time the buffer...
379 
380  if (BytesToRead <= sizeof(StaticBuffer))
381  {
382  LocalBuffer = StaticBuffer;
383  }
384  else
385  {
386  LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BytesToRead);
387  ASSERT(LocalBuffer != NULL);
388  }
389 
390  if (ReadFile(DiskImage->hDisk, LocalBuffer, BytesToRead, &BytesToRead, NULL))
391  {
392  /* Write to the memory */
394  TO_LINEAR(getES(), getBX()),
395  LocalBuffer,
396  BytesToRead);
397 
398  Result = 0x00;
399  }
400  else
401  {
402  Result = 0x04;
403  }
404 
405  if (LocalBuffer != StaticBuffer)
406  RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
407 
408  /* Return success or error */
409  return Result;
410 }
USHORT WINAPI getBX(VOID)
Definition: registers.c:170
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
VOID FASTCALL EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:183
#define DWORD
Definition: nt_native.h:44
smooth NULL
Definition: ftsmooth.c:416
_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:426
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
if(!(yy_init))
Definition: macro.lex.yy.c:714
USHORT WINAPI getES(VOID)
Definition: registers.c:522
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TO_LINEAR(seg, off)
Definition: emulator.h:22
unsigned char BYTE
Definition: mem.h:68
BYTE SeekDisk(IN PDISK_IMAGE DiskImage, IN WORD Cylinder, IN BYTE Head, IN BYTE Sector)
Definition: disk.c:328
FAST486_STATE EmulatorContext
Definition: cpu.c:39
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123

Referenced by BiosDiskService().

◆ RetrieveDisk()

PDISK_IMAGE RetrieveDisk ( IN DISK_TYPE  DiskType,
IN ULONG  DiskNumber 
)

Definition at line 485 of file disk.c.

487 {
488  ASSERT(DiskType < MAX_DISK_TYPE);
489 
490  if (DiskNumber >= DiskMountInfo[DiskType].NumDisks)
491  {
492  DisplayMessage(L"RetrieveDisk: Disk number %d:%d invalid.", DiskType, DiskNumber);
493  return NULL;
494  }
495 
496  return &DiskMountInfo[DiskType].DiskArray[DiskNumber];
497 }
PDISK_IMAGE DiskArray
Definition: disk.c:473
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
static DISK_MOUNT_INFO DiskMountInfo[MAX_DISK_TYPE]
Definition: disk.c:478

Referenced by DiskBios32Initialize().

◆ SeekDisk()

BYTE SeekDisk ( IN PDISK_IMAGE  DiskImage,
IN WORD  Cylinder,
IN BYTE  Head,
IN BYTE  Sector 
)

Definition at line 328 of file disk.c.

332 {
333  DWORD FilePointer;
334 
335  /* Check that the sector number is 1-based */
336  // FIXME: Or do it in the caller?
337  if (Sector == 0)
338  {
339  /* Return error */
340  return 0x01;
341  }
342 
343  /* Set position */
344  // Compute the offset
345  FilePointer = (DWORD)((DWORD)((DWORD)Cylinder * DiskImage->DiskInfo.Heads + Head)
346  * DiskImage->DiskInfo.Sectors + (Sector - 1))
347  * DiskImage->DiskInfo.SectorSize;
348  FilePointer = SetFilePointer(DiskImage->hDisk, FilePointer, NULL, FILE_BEGIN);
349  if (FilePointer == INVALID_SET_FILE_POINTER)
350  {
351  /* Return error */
352  return 0x40;
353  }
354 
355  return 0x00;
356 }
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
#define DWORD
Definition: nt_native.h:44
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_BEGIN
Definition: winbase.h:112

Referenced by BiosDiskService(), ReadDisk(), and WriteDisk().

◆ UnmountDisk()

BOOLEAN UnmountDisk ( IN DISK_TYPE  DiskType,
IN ULONG  DiskNumber 
)

Definition at line 602 of file disk.c.

604 {
605  PDISK_IMAGE DiskImage;
606 
607  ASSERT(DiskType < MAX_DISK_TYPE);
608 
609  if (DiskNumber >= DiskMountInfo[DiskType].NumDisks)
610  {
611  DisplayMessage(L"UnmountDisk: Disk number %d:%d invalid.", DiskType, DiskNumber);
612  return FALSE;
613  }
614 
615  DiskImage = &DiskMountInfo[DiskType].DiskArray[DiskNumber];
616  if (!IsDiskPresent(DiskImage))
617  {
618  DPRINT1("UnmountDisk: Disk %d:%d:0x%p is already unmounted\n", DiskType, DiskNumber, DiskImage);
619  return FALSE;
620  }
621 
622  /* Flush the image and unmount it */
623  FlushFileBuffers(DiskImage->hDisk);
624  FileClose(DiskImage->hDisk);
625  DiskImage->hDisk = NULL;
626  return TRUE;
627 }
#define TRUE
Definition: types.h:120
PDISK_IMAGE DiskArray
Definition: disk.c:473
BOOLEAN IsDiskPresent(IN PDISK_IMAGE DiskImage)
Definition: disk.c:321
VOID FileClose(IN HANDLE FileHandle)
Definition: utils.c:21
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:175
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
HANDLE hDisk
Definition: disk.h:36
#define DPRINT1
Definition: precomp.h:8
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
static DISK_MOUNT_INFO DiskMountInfo[MAX_DISK_TYPE]
Definition: disk.c:478

Referenced by DiskCtrlCleanup(), EjectFloppy(), and MountDisk().

◆ WriteDisk()

BYTE WriteDisk ( IN PDISK_IMAGE  DiskImage,
IN WORD  Cylinder,
IN BYTE  Head,
IN BYTE  Sector,
IN BYTE  NumSectors 
)

Definition at line 413 of file disk.c.

418 {
419  BYTE Result;
420  DWORD BytesToWrite;
421 
422  PVOID LocalBuffer;
423  BYTE StaticBuffer[1024];
424 
425  /* Check for write protection */
426  if (DiskImage->ReadOnly)
427  {
428  /* Return error */
429  return 0x03;
430  }
431 
432  /* Write the sectors */
433  Result = SeekDisk(DiskImage, Cylinder, Head, Sector);
434  if (Result != 0x00)
435  return Result;
436 
437  BytesToWrite = (DWORD)NumSectors * DiskImage->DiskInfo.SectorSize;
438 
439  // FIXME: Consider just looping around filling each time the buffer...
440 
441  if (BytesToWrite <= sizeof(StaticBuffer))
442  {
443  LocalBuffer = StaticBuffer;
444  }
445  else
446  {
447  LocalBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, BytesToWrite);
448  ASSERT(LocalBuffer != NULL);
449  }
450 
451  /* Read from the memory */
453  TO_LINEAR(getES(), getBX()),
454  LocalBuffer,
455  BytesToWrite);
456 
457  if (WriteFile(DiskImage->hDisk, LocalBuffer, BytesToWrite, &BytesToWrite, NULL))
458  Result = 0x00;
459  else
460  Result = 0x04;
461 
462  if (LocalBuffer != StaticBuffer)
463  RtlFreeHeap(RtlGetProcessHeap(), 0, LocalBuffer);
464 
465  /* Return success or error */
466  return Result;
467 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
USHORT WINAPI getBX(VOID)
Definition: registers.c:170
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define DWORD
Definition: nt_native.h:44
smooth NULL
Definition: ftsmooth.c:416
_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:426
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
if(!(yy_init))
Definition: macro.lex.yy.c:714
USHORT WINAPI getES(VOID)
Definition: registers.c:522
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define TO_LINEAR(seg, off)
Definition: emulator.h:22
unsigned char BYTE
Definition: mem.h:68
BYTE SeekDisk(IN PDISK_IMAGE DiskImage, IN WORD Cylinder, IN BYTE Head, IN BYTE Sector)
Definition: disk.c:328
FAST486_STATE EmulatorContext
Definition: cpu.c:39
VOID FASTCALL EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:139

Referenced by BiosDiskService().

Variable Documentation

◆ DiskGeometryList

DISK_GEO DiskGeometryList[]
static
Initial value:
=
{
{ 160, 8, 1, 40, 0},
{ 180, 9, 1, 40, 0},
{ 200, 10, 1, 40, 0},
{ 320, 8, 2, 40, 1},
{ 360, 9, 2, 40, 1},
{ 400, 10, 2, 40, 1},
{ 720, 9, 2, 80, 3},
{1200, 15, 2, 80, 2},
{1440, 18, 2, 80, 4},
{2880, 36, 2, 80, 6},
}

Definition at line 175 of file disk.c.

Referenced by MountFDI().

◆ DiskMountInfo

DISK_MOUNT_INFO DiskMountInfo[MAX_DISK_TYPE]
static
Initial value:
=
{
}
#define _ARRAYSIZE(A)
Definition: ntbasedef.h:708
BOOLEAN MountHDD(IN PDISK_IMAGE DiskImage, IN HANDLE hFile)
Definition: disk.c:246
static DISK_IMAGE XDCFloppyDrive[4]
Definition: disk.c:161
BOOLEAN MountFDI(IN PDISK_IMAGE DiskImage, IN HANDLE hFile)
Definition: disk.c:190
static DISK_IMAGE XDCHardDrive[4]
Definition: disk.c:243

Definition at line 478 of file disk.c.

Referenced by DiskCtrlCleanup(), HalpAssignDrive(), MountDisk(), RetrieveDisk(), UnmountDisk(), and xHalIoAssignDriveLetters().

◆ HackSectorSize

WORD HackSectorSize = 512
static

Definition at line 174 of file disk.c.

Referenced by MountFDI().

◆ XDCFloppyDrive

DISK_IMAGE XDCFloppyDrive[4]
static

Definition at line 161 of file disk.c.

◆ XDCHardDrive

DISK_IMAGE XDCHardDrive[4]
static

Definition at line 243 of file disk.c.