Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
8.9 KiB

  1. #pragma pack(1)
  2. #if defined(NEC_98)
  3. #define MAX_FLOPPY_TYPE 7
  4. #else // !NEC_98
  5. #define MAX_FLOPPY_TYPE 5
  6. #endif // !NEC_98
  7. typedef struct A_DISKIO {
  8. DWORD StartSector;
  9. WORD Sectors;
  10. WORD BufferOff;
  11. WORD BufferSeg;
  12. } DISKIO, * PDISKIO;
  13. // Bios Parameter Block (BPB)
  14. typedef struct A_BPB {
  15. WORD SectorSize; // sector size in bytes
  16. BYTE ClusterSize; // cluster size in sectors
  17. WORD ReservedSectors; // number of reserved sectors
  18. BYTE FATs; // number of FATs
  19. WORD RootDirs; // number of root directory entries
  20. WORD Sectors; // number of sectors
  21. BYTE MediaID; // media descriptor
  22. WORD FATSize; // FAT size in sectors
  23. WORD TrackSize; // track size in sectors;
  24. WORD Heads; // number of heads
  25. DWORD HiddenSectors; // number of hidden sectors
  26. DWORD BigSectors; // number of sectors for big media
  27. } BPB, *PBPB;
  28. typedef struct A_DPB {
  29. BYTE DriveNum; // driver numer, 0 - A, 1 -B and so on
  30. BYTE Unit; // unit number of DPB in the driver
  31. WORD SectorSize; // sector size in bytes
  32. BYTE ClusterMask; // cluster mask
  33. BYTE ClusterShift; // cluster shift count
  34. WORD FATSector; // starting sector of FAT
  35. BYTE FATs; // number of FAT
  36. WORD RootDirs; // number of root directory entries
  37. WORD FirstDataSector; // first sector for the first cluster
  38. WORD MaxCluster; // number of cluster + 1
  39. WORD FATSize; // FAT size in sectors
  40. WORD DirSector; // starting sector of directory
  41. DWORD DriveAddr; // address of the corresponding driver
  42. BYTE MediaID; // media ID
  43. BYTE FirstAccess; // 0xFF if this DPB is first accessed
  44. struct A_DPB * Next; // next DPB
  45. WORD FreeCluster; // cluster # of the last allocated
  46. WORD FreeClusters; // number of free clusters, 0xFFFF
  47. // if unknown
  48. } DPB, * PDPB;
  49. typedef struct A_DEVICEPARAMETERS {
  50. BYTE Functions;
  51. BYTE DeviceType;
  52. WORD DeviceAttrs;
  53. WORD Cylinders;
  54. BYTE MediaType;
  55. BPB bpb;
  56. } DEVICEPARAMETERS, *PDEVICE_PARAMETERS;
  57. #define LABEL_LENGTH 11
  58. #define FILESYSTYPE_LENGTH 8
  59. typedef struct _DISK_LABEL {
  60. CHAR Name[LABEL_LENGTH];
  61. } DISK_LABEL, *PDISK_LABEL;
  62. typedef struct _FILESYSTYPE {
  63. CHAR Name[FILESYSTYPE_LENGTH];
  64. } FILESYSTYPE, * PFILESYSTYPE;
  65. // Functions for Get Device Parameters
  66. #define BUILD_DEVICE_BPB 0x01
  67. // Functions for Set Device Parameters
  68. #define INSTALL_FAKE_BPB 0x01
  69. #define ONLY_SET_TRACKLAYOUT 0x02
  70. #define TRACK_LAYOUT_IS_GOOD 0x04
  71. // Functions for Format Track
  72. #define STATUS_FOR_FORMAT 0x01
  73. // error code from format status call
  74. #define FORMAT_NO_ROM_SUPPORTED 0x01
  75. #define FORMAT_COMB_NOT_SUPPORTED 0x02
  76. // read and write block
  77. typedef struct _RWBLOCK {
  78. BYTE Functions;
  79. WORD Head;
  80. WORD Cylinder;
  81. WORD StartSector;
  82. WORD Sectors;
  83. WORD BufferOff;
  84. WORD BufferSeg;
  85. } RW_BLOCK, *PRW_BLOCK;
  86. // format and verify track block
  87. typedef struct _FMT_BLOCK{
  88. BYTE Functions;
  89. WORD Head;
  90. WORD Cylinder;
  91. } FMT_BLOCK, *PFMT_BLOCK;
  92. // media id block
  93. typedef struct _MID {
  94. WORD InfoLevel;
  95. DWORD SerialNum;
  96. DISK_LABEL Label;
  97. FILESYSTYPE FileSysType;
  98. } MID, *PMID;
  99. // access flage
  100. typedef struct _ACCESSCTRL {
  101. BYTE Functions;
  102. BYTE AccessFlag;
  103. } ACCESSCTRL, * PACCESSCTRL;
  104. // bit definitions for flags
  105. // definitions for misc flags
  106. #define NON_REMOVABLE 0x01
  107. #define HAS_CHANGELINE 0x02
  108. #define RETURN_FAKE_BPB 0x04
  109. #define GOOD_TRACKLAYOUT 0x08
  110. #define MULTI_OWNER 0x10
  111. #define PHYS_OWNER 0x20
  112. #define MEDIA_CHANGED 0x40
  113. #define CHANGED_BY_FORMAT 0x100
  114. #define UNFORMATTED_MEDIA 0x200
  115. #define FIRSTACCESS 0x8000
  116. #define EXT_BOOTSECT_SIG 0x29
  117. typedef struct _BOOTSECTOR {
  118. BYTE Jump;
  119. BYTE Target[2];
  120. BYTE OemName[8];
  121. BPB bpb;
  122. BYTE DriveNum;
  123. BYTE Reserved;
  124. BYTE ExtBootSig;
  125. DWORD SerialNum;
  126. DISK_LABEL Label;
  127. FILESYSTYPE FileSysType;
  128. } BOOTSECTOR, * PBOOTSECTOR;
  129. // Bios Data Structure (BDS)
  130. typedef struct A_BDS {
  131. struct A_BDS *Next; //pointer to next bds
  132. BYTE DrivePhys; //physical drive number, 0 based
  133. BYTE DriveLog; //logical drive number, 0 based
  134. BPB bpb;
  135. BYTE FatSize;
  136. WORD OpenCount;
  137. BYTE MediaType;
  138. WORD Flags;
  139. WORD Cylinders;
  140. BPB rbpb;
  141. BYTE LastTrack;
  142. DWORD Time;
  143. DWORD SerialNum;
  144. DISK_LABEL Label;
  145. FILESYSTYPE FileSysType;
  146. BYTE FormFactor;
  147. // the fllowing fields are dedicated for the drive itself
  148. WORD DriveType;
  149. WORD Sectors;
  150. HANDLE fd;
  151. DWORD TotalSectors;
  152. } BDS, *PBDS;
  153. #pragma pack()
  154. // drive type
  155. #define DRIVETYPE_NULL 0
  156. #define DRIVETYPE_360 1
  157. #define DRIVETYPE_12M 2
  158. #define DRIVETYPE_720 3
  159. #define DRIVETYPE_144 4
  160. #define DRIVETYPE_288 5
  161. #define DRIVETYPE_FDISK 0xff
  162. // FORM FACTOR
  163. #define FF_360 0
  164. #define FF_120 1
  165. #define FF_720 2
  166. #define FF_FDISK 5
  167. #define FF_144 7
  168. #define FF_288 9
  169. #if defined(NEC_98)
  170. #define FF_125 4
  171. #define FF_640 2
  172. #endif // NEC_98
  173. #define DOS_DIR_ENTRY_LENGTH 32
  174. #define DOS_DIR_ENTRY_LENGTH_SHIFT_COUNT 5
  175. // bios diskette i/o functions
  176. #define DISKIO_RESET 0
  177. #define DISKIO_GETSTATUS 1
  178. #define DISKIO_READ 2
  179. #define DISKIO_WRITE 3
  180. #define DISKIO_VERIFY 4
  181. #define DISKIO_FORMAT 5
  182. #define DISKIO_GETPARAMS 8
  183. #define DISKIO_DRIVETYPE 0x15
  184. #define DISKIO_DISKCHANGE 0x16
  185. #define DISKIO_SETTYPE 0x17
  186. #define DISKIO_SETMEDIA 0x18
  187. #define DISKIO_INVALID 0xff
  188. // Block device generic IOCTL(RAWIO) subfunction code
  189. #define IOCTL_SETDPM 0x40
  190. #define IOCTL_WRITETRACK 0x41
  191. #define IOCTL_FORMATTRACK 0x42
  192. #define IOCTL_SETMEDIA 0x46
  193. #define IOCTL_SETACCESS 0x47
  194. #define IOCTL_GETDPM 0x60
  195. #define IOCTL_READTRACK 0x61
  196. #define IOCTL_VERIFYTRACK 0x62
  197. #define IOCTL_GETMEDIA 0x66
  198. #define IOCTL_GETACCESS 0x67
  199. #define IOCTL_SENSEMEDIA 0x68
  200. #define IOCTL_GENERIC_MIN IOCTL_SETDPM
  201. #define IOCTL_GENERIC_MAX IOCTL_SENSEMEDIA
  202. // dos error code
  203. #define DOS_WRITE_PROTECTION 0
  204. #define DOS_UNKNOWN_UNIT 1
  205. #define DOS_DRIVE_NOT_READY 2
  206. #define DOS_CRC_ERROR 4
  207. #define DOS_SEEK_ERROR 6
  208. #define DOS_UNKNOWN_MEDIA 7
  209. #define DOS_SECTOR_NOT_FOUND 8
  210. #define DOS_WRITE_FAULT 10
  211. #define DOS_READ_FAULT 11
  212. #define DOS_GEN_FAILURE 12
  213. #define DOS_INVALID_MEDIA_CHANGE 15
  214. //BIOS disk io error code
  215. #define BIOS_INVALID_FUNCTION 0x01
  216. #define BIOS_BAD_ADDRESS_MARK 0x02
  217. #define BIOS_WRITE_PROTECTED 0x03
  218. #define BIOS_BAD_SECTOR 0x04
  219. #define BIOS_DISK_CHANGED 0x05
  220. #define BIOS_DMA_OVERRUN 0x06
  221. #define BIOS_DMA_BOUNDARY 0x08
  222. #define BIOS_NO_MEDIA 0x0C
  223. #define BIOS_CRC_ERROR 0x10
  224. #define BIOS_FDC_ERROR 0x20
  225. #define BIOS_SEEK_ERROR 0x40
  226. #define BIOS_TIME_OUT 0x80
  227. // dos disk generic io control error code
  228. #define DOS_INVALID_FUNCTION 1
  229. #define DOS_FILE_NOT_FOUND 2
  230. #define DOS_ACCESS_DENIED 5
  231. #define BIOS_DISKCHANGED 6
  232. #if defined(NEC_98)
  233. #define BYTES_PER_SECTOR 1024
  234. #else // !NEC_98
  235. #define BYTES_PER_SECTOR 512
  236. #endif // !NEC_98
  237. VOID demDasdInit(VOID);
  238. VOID demFloppyInit(VOID);
  239. VOID demFdiskInit(VOID);
  240. VOID demAbsReadWrite(BOOL IsWrite);
  241. DWORD demDasdRead(PBDS pbds, DWORD StartSector, DWORD Sectors,
  242. WORD BufferOff, WORD BufferSeg);
  243. DWORD demDasdWrite(PBDS pbds, DWORD StartSector, DWORD Sectors,
  244. WORD BufferOff, WORD BufferSeg);
  245. BOOL demDasdFormat(PBDS pbds, DWORD Head, DWORD Cylinder, MEDIA_TYPE * Media);
  246. BOOL demDasdVerify(PBDS pbds, DWORD Cylinder, DWORD Head);
  247. PBDS demGetBDS(BYTE Drive);
  248. BOOL demGetBPB(PBDS pbds);
  249. WORD demWinErrorToDosError(DWORD LastError);
  250. VOID diskette_io(VOID);
  251. DWORD BiosErrorToNTError(BYTE BiosError);
  252. DWORD demBiosDiskIoRW(PBDS pbds, DWORD StartSector, DWORD Sectors,
  253. WORD BufferOff, WORD BufferSeg, BOOL IsWrite);
  254. VOID sas_loadw(DWORD, WORD *);
  255. // imported from host floppy support module
  256. BOOL nt_floppy_close(BYTE drive);
  257. ULONG nt_floppy_read(BYTE drive, ULONG offset, ULONG size, PBYTE buffer);
  258. ULONG nt_floppy_write(BYTE drive, ULONG offset, ULONG size, PBYTE buffer);
  259. ULONG nt_floppy_format(BYTE drive, WORD cylinder, WORD head, MEDIA_TYPE media);
  260. BOOL nt_floppy_media_check(BYTE drive);
  261. MEDIA_TYPE nt_floppy_get_media_type(BYTE Drive, WORD Cylinders, WORD Sectors, WORD Heads);
  262. BOOL nt_floppy_verify(BYTE drive, DWORD offset, DWORD size);
  263. BOOL nt_fdisk_init(BYTE drive, PBPB bpb, PDISK_GEOMETRY disk_geometry);
  264. ULONG nt_fdisk_read(BYTE drive, PLARGE_INTEGER offset, ULONG size, PBYTE buffer);
  265. ULONG nt_fdisk_write(BYTE drive,PLARGE_INTEGER offset, ULONG size, PBYTE buffer);
  266. BOOL nt_fdisk_verify(BYTE drive, PLARGE_INTEGER offset, ULONG size);
  267. BOOL nt_fdisk_close(BYTE drive);
  268. extern PBDS demBDS;
  269. extern BYTE NumberOfFloppy, NumberOfFdisk;
  270. #if defined(NEC_98)
  271. BOOL demIsDriveFloppy(BYTE DriveLog); // defined in demdasd.c
  272. #else // !NEC_98
  273. #define demIsDriveFloppy(DriveLog) (DriveLog < NumberOfFloppy)
  274. #endif // !NEC_98