]> git.proxmox.com Git - grub2.git/blob - include/grub/disk.h
Split mdraid.mod into mdraid09.mod and mdraid1x.mod.
[grub2.git] / include / grub / disk.h
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef GRUB_DISK_HEADER
20 #define GRUB_DISK_HEADER 1
21
22 #include <grub/symbol.h>
23 #include <grub/err.h>
24 #include <grub/types.h>
25 #include <grub/device.h>
26
27 /* These are used to set a device id. When you add a new disk device,
28 you must define a new id for it here. */
29 enum grub_disk_dev_id
30 {
31 GRUB_DISK_DEVICE_BIOSDISK_ID,
32 GRUB_DISK_DEVICE_OFDISK_ID,
33 GRUB_DISK_DEVICE_LOOPBACK_ID,
34 GRUB_DISK_DEVICE_EFIDISK_ID,
35 GRUB_DISK_DEVICE_RAID_ID,
36 GRUB_DISK_DEVICE_LVM_ID,
37 GRUB_DISK_DEVICE_HOST_ID,
38 GRUB_DISK_DEVICE_ATA_ID,
39 GRUB_DISK_DEVICE_MEMDISK_ID,
40 GRUB_DISK_DEVICE_NAND_ID,
41 GRUB_DISK_DEVICE_UUID_ID,
42 GRUB_DISK_DEVICE_PXE_ID,
43 GRUB_DISK_DEVICE_SCSI_ID,
44 GRUB_DISK_DEVICE_FILE_ID,
45 GRUB_DISK_DEVICE_LUKS_ID
46 };
47
48 struct grub_disk;
49 #ifdef GRUB_UTIL
50 struct grub_disk_memberlist;
51 #endif
52
53 /* Disk device. */
54 struct grub_disk_dev
55 {
56 /* The device name. */
57 const char *name;
58
59 /* The device id used by the cache manager. */
60 enum grub_disk_dev_id id;
61
62 /* Call HOOK with each device name, until HOOK returns non-zero. */
63 int (*iterate) (int (*hook) (const char *name));
64
65 /* Open the device named NAME, and set up DISK. */
66 grub_err_t (*open) (const char *name, struct grub_disk *disk);
67
68 /* Close the disk DISK. */
69 void (*close) (struct grub_disk *disk);
70
71 /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
72 grub_err_t (*read) (struct grub_disk *disk, grub_disk_addr_t sector,
73 grub_size_t size, char *buf);
74
75 /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
76 grub_err_t (*write) (struct grub_disk *disk, grub_disk_addr_t sector,
77 grub_size_t size, const char *buf);
78
79 #ifdef GRUB_UTIL
80 struct grub_disk_memberlist *(*memberlist) (struct grub_disk *disk);
81 #endif
82
83 /* The next disk device. */
84 struct grub_disk_dev *next;
85 };
86 typedef struct grub_disk_dev *grub_disk_dev_t;
87
88 struct grub_partition;
89
90 /* Disk. */
91 struct grub_disk
92 {
93 /* The disk name. */
94 const char *name;
95
96 /* The underlying disk device. */
97 grub_disk_dev_t dev;
98
99 /* The total number of sectors. */
100 grub_uint64_t total_sectors;
101
102 /* The id used by the disk cache manager. */
103 unsigned long id;
104
105 /* The partition information. This is machine-specific. */
106 struct grub_partition *partition;
107
108 /* Called when a sector was read. OFFSET is between 0 and
109 the sector size minus 1, and LENGTH is between 0 and the sector size. */
110 void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
111 unsigned offset, unsigned length);
112
113 /* Device-specific data. */
114 void *data;
115 };
116 typedef struct grub_disk *grub_disk_t;
117
118 #ifdef GRUB_UTIL
119 struct grub_disk_memberlist
120 {
121 grub_disk_t disk;
122 struct grub_disk_memberlist *next;
123 };
124 typedef struct grub_disk_memberlist *grub_disk_memberlist_t;
125 #endif
126
127 /* The sector size. */
128 #define GRUB_DISK_SECTOR_SIZE 0x200
129 #define GRUB_DISK_SECTOR_BITS 9
130
131 /* The maximum number of disk caches. */
132 #define GRUB_DISK_CACHE_NUM 1021
133
134 /* The size of a disk cache in sector units. */
135 #define GRUB_DISK_CACHE_SIZE 8
136 #define GRUB_DISK_CACHE_BITS 3
137
138 /* Return value of grub_disk_get_size() in case disk size is unknown. */
139 #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL
140
141 /* This is called from the memory manager. */
142 void grub_disk_cache_invalidate_all (void);
143
144 void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev);
145 void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev);
146 int EXPORT_FUNC(grub_disk_dev_iterate) (int (*hook) (const char *name));
147
148 grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name);
149 void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk);
150 grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk,
151 grub_disk_addr_t sector,
152 grub_off_t offset,
153 grub_size_t size,
154 void *buf);
155 grub_err_t EXPORT_FUNC(grub_disk_write) (grub_disk_t disk,
156 grub_disk_addr_t sector,
157 grub_off_t offset,
158 grub_size_t size,
159 const void *buf);
160
161 grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk);
162
163 extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void);
164 extern int EXPORT_VAR(grub_disk_firmware_is_tainted);
165
166 /* ATA pass through parameters and function. */
167 struct grub_disk_ata_pass_through_parms
168 {
169 grub_uint8_t taskfile[8];
170 void * buffer;
171 int size;
172 };
173
174 extern grub_err_t (* EXPORT_VAR(grub_disk_ata_pass_through)) (grub_disk_t,
175 struct grub_disk_ata_pass_through_parms *);
176
177 #if defined (GRUB_UTIL) || defined (GRUB_MACHINE_EMU)
178 void grub_lvm_init (void);
179 void grub_mdraid09_init (void);
180 void grub_mdraid1x_init (void);
181 void grub_raid_init (void);
182 void grub_lvm_fini (void);
183 void grub_mdraid09_fini (void);
184 void grub_mdraid1x_fini (void);
185 void grub_raid_fini (void);
186 #endif
187
188 #endif /* ! GRUB_DISK_HEADER */