2 * Copyright (C) 2009-2010, Shao Miller <shao.miller@yrdsb.edu.on.ca>.
3 * Copyright 2006-2008, V.
4 * For WinAoE contact information, see http://winaoe.org/
6 * This file is part of WinVBlock, derived from WinAoE.
8 * WinVBlock is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * WinVBlock is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with WinVBlock. If not, see <http://www.gnu.org/licenses/>.
27 * Disk device specifics.
30 typedef enum WV_DISK_MEDIA_TYPE {
31 WvDiskMediaTypeFloppy,
33 WvDiskMediaTypeOptical,
35 } WV_E_DISK_MEDIA_TYPE, * WV_EP_DISK_MEDIA_TYPE;
37 typedef char WV_A_DISK_BOOT_SECT[512];
38 typedef WV_A_DISK_BOOT_SECT * WV_AP_DISK_BOOT_SECT;
40 extern winvblock__bool WvDiskIsRemovable[WvDiskMediaTypes];
41 extern PWCHAR WvDiskCompatIds[WvDiskMediaTypes];
43 typedef enum WV_DISK_IO_MODE {
47 } WV_E_DISK_IO_MODE, * WV_EP_DISK_IO_MODE;
49 /* Forward declaration. */
50 typedef struct WV_DISK_T WV_S_DISK_T, * WV_SP_DISK_T;
55 * @v dev_ptr Points to the disk's device structure.
56 * @v mode Read / write mode.
57 * @v start_sector First sector for request.
58 * @v sector_count Number of sectors to work with.
59 * @v buffer Buffer to read / write sectors to / from.
60 * @v irp Interrupt request packet for this request.
62 typedef NTSTATUS STDCALL WV_F_DISK_IO(
67 IN winvblock__uint8_ptr,
70 typedef WV_F_DISK_IO * WV_FP_DISK_IO;
73 * Maximum transfer length response routine.
75 * @v disk_ptr The disk being queried.
76 * @ret UINT32 The maximum transfer length.
78 typedef winvblock__uint32 WV_F_DISK_MAX_XFER_LEN(IN WV_SP_DISK_T);
79 typedef WV_F_DISK_MAX_XFER_LEN * WV_FP_DISK_MAX_XFER_LEN;
82 * Disk initialization routine.
84 * @v disk_ptr The disk device being initialized.
85 * @ret BOOLEAN FALSE if initialization failed, otherwise TRUE
87 typedef winvblock__bool STDCALL WV_F_DISK_INIT(IN WV_SP_DISK_T);
88 typedef WV_F_DISK_INIT * WV_FP_DISK_INIT;
93 * @v disk_ptr The disk device being closed.
95 typedef void STDCALL WV_F_DISK_CLOSE(IN WV_SP_DISK_T);
96 typedef WV_F_DISK_CLOSE * WV_FP_DISK_CLOSE;
98 typedef struct WV_DISK_OPS {
100 WV_FP_DISK_MAX_XFER_LEN MaxXferLen;
101 WV_FP_DISK_INIT Init;
102 WV_FP_DISK_CLOSE Close;
103 } WV_S_DISK_OPS, * WV_SP_DISK_OPS;
109 winvblock__bool BootDrive;
110 winvblock__bool Unmount;
111 WV_E_DISK_MEDIA_TYPE Media;
112 WV_S_DISK_OPS disk_ops;
113 ULONGLONG LBADiskSize;
115 winvblock__uint32 Heads;
116 winvblock__uint32 Sectors;
117 winvblock__uint32 SectorSize;
118 winvblock__uint32 SpecialFileCount;
120 winvblock__any_ptr ext;
123 /* Yield a pointer to the disk. */
124 #define disk__get_ptr(dev_ptr) ((WV_SP_DISK_T) dev_ptr->ext)
126 /* An MBR C/H/S address and ways to access its components. */
127 typedef winvblock__uint8 chs[3];
129 #define chs_head(chs) chs[0]
130 #define chs_sector(chs) (chs[1] & 0x3F)
131 #define chs_cyl_high(chs) (((winvblock__uint16) (chs[1] & 0xC0)) << 2)
132 #define chs_cyl_low(chs) ((winvblock__uint16) chs[2])
133 #define chs_cylinder(chs) (chs_cyl_high(chs) | chs_cyl_low(chs))
140 winvblock__def_struct (mbr) {
141 winvblock__uint8 code[440];
142 winvblock__uint32 disk_sig;
143 winvblock__uint16 pad;
145 winvblock__uint8 status;
147 winvblock__uint8 type;
149 winvblock__uint32 lba_start;
150 winvblock__uint32 lba_count;
151 } partition[4] __attribute__((packed));
152 winvblock__uint16 mbr_sig;
153 } __attribute__((__packed__));
159 extern WV_F_DISK_IO disk__io;
160 extern WV_F_DISK_MAX_XFER_LEN disk__max_xfer_len;
163 * Attempt to guess a disk's geometry.
165 * @v boot_sect_ptr The MBR or VBR with possible geometry clues.
166 * @v disk_ptr The disk to set the geometry for.
168 extern winvblock__lib_func void disk__guess_geometry(
169 IN WV_AP_DISK_BOOT_SECT,
170 IN OUT WV_SP_DISK_T disk_ptr
176 * @ret disk_ptr The address of a new disk, or NULL for failure.
178 * This function should not be confused with a PDO creation routine, which is
179 * actually implemented for each device type. This routine will allocate a
180 * WV_S_DISK_T, track it in a global list, as well as populate the disk
181 * with default values.
183 extern winvblock__lib_func WV_SP_DISK_T disk__create(void);
185 extern NTSTATUS disk__module_init(void);
187 #endif /* WV_M_DISK_H_ */