]>
Commit | Line | Data |
---|---|---|
4d8d554a CW |
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 <config.h> | |
23 | ||
24 | #include <grub/symbol.h> | |
25 | #include <grub/err.h> | |
26 | #include <grub/types.h> | |
27 | #include <grub/device.h> | |
28 | /* For NULL. */ | |
29 | #include <grub/mm.h> | |
30 | ||
31 | /* These are used to set a device id. When you add a new disk device, | |
32 | you must define a new id for it here. */ | |
33 | enum grub_disk_dev_id | |
34 | { | |
35 | GRUB_DISK_DEVICE_BIOSDISK_ID, | |
36 | GRUB_DISK_DEVICE_OFDISK_ID, | |
37 | GRUB_DISK_DEVICE_LOOPBACK_ID, | |
38 | GRUB_DISK_DEVICE_EFIDISK_ID, | |
39 | GRUB_DISK_DEVICE_DISKFILTER_ID, | |
40 | GRUB_DISK_DEVICE_HOST_ID, | |
41 | GRUB_DISK_DEVICE_ATA_ID, | |
42 | GRUB_DISK_DEVICE_MEMDISK_ID, | |
43 | GRUB_DISK_DEVICE_NAND_ID, | |
44 | GRUB_DISK_DEVICE_SCSI_ID, | |
45 | GRUB_DISK_DEVICE_CRYPTODISK_ID, | |
46 | GRUB_DISK_DEVICE_ARCDISK_ID, | |
47 | GRUB_DISK_DEVICE_HOSTDISK_ID, | |
48 | GRUB_DISK_DEVICE_PROCFS_ID, | |
49 | GRUB_DISK_DEVICE_CBFSDISK_ID, | |
50 | GRUB_DISK_DEVICE_UBOOTDISK_ID, | |
51 | GRUB_DISK_DEVICE_XEN, | |
e1c95655 | 52 | GRUB_DISK_DEVICE_OBDISK_ID, |
4d8d554a CW |
53 | }; |
54 | ||
55 | struct grub_disk; | |
56 | #ifdef GRUB_UTIL | |
57 | struct grub_disk_memberlist; | |
58 | #endif | |
59 | ||
60 | typedef enum | |
61 | { | |
62 | GRUB_DISK_PULL_NONE, | |
63 | GRUB_DISK_PULL_REMOVABLE, | |
64 | GRUB_DISK_PULL_RESCAN, | |
65 | GRUB_DISK_PULL_MAX | |
66 | } grub_disk_pull_t; | |
67 | ||
68 | typedef int (*grub_disk_dev_iterate_hook_t) (const char *name, void *data); | |
69 | ||
70 | /* Disk device. */ | |
71 | struct grub_disk_dev | |
72 | { | |
73 | /* The device name. */ | |
74 | const char *name; | |
75 | ||
76 | /* The device id used by the cache manager. */ | |
77 | enum grub_disk_dev_id id; | |
78 | ||
79 | /* Call HOOK with each device name, until HOOK returns non-zero. */ | |
80 | int (*iterate) (grub_disk_dev_iterate_hook_t hook, void *hook_data, | |
81 | grub_disk_pull_t pull); | |
82 | ||
83 | /* Open the device named NAME, and set up DISK. */ | |
84 | grub_err_t (*open) (const char *name, struct grub_disk *disk); | |
85 | ||
86 | /* Close the disk DISK. */ | |
87 | void (*close) (struct grub_disk *disk); | |
88 | ||
89 | /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */ | |
90 | grub_err_t (*read) (struct grub_disk *disk, grub_disk_addr_t sector, | |
91 | grub_size_t size, char *buf); | |
92 | ||
93 | /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */ | |
94 | grub_err_t (*write) (struct grub_disk *disk, grub_disk_addr_t sector, | |
95 | grub_size_t size, const char *buf); | |
96 | ||
97 | #ifdef GRUB_UTIL | |
98 | struct grub_disk_memberlist *(*memberlist) (struct grub_disk *disk); | |
99 | const char * (*raidname) (struct grub_disk *disk); | |
100 | #endif | |
101 | ||
102 | /* The next disk device. */ | |
103 | struct grub_disk_dev *next; | |
104 | }; | |
105 | typedef struct grub_disk_dev *grub_disk_dev_t; | |
106 | ||
107 | extern grub_disk_dev_t EXPORT_VAR (grub_disk_dev_list); | |
108 | ||
109 | struct grub_partition; | |
110 | ||
111 | typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t sector, | |
112 | unsigned offset, unsigned length, | |
113 | void *data); | |
114 | ||
115 | /* Disk. */ | |
116 | struct grub_disk | |
117 | { | |
118 | /* The disk name. */ | |
119 | const char *name; | |
120 | ||
121 | /* The underlying disk device. */ | |
122 | grub_disk_dev_t dev; | |
123 | ||
124 | /* The total number of sectors. */ | |
125 | grub_uint64_t total_sectors; | |
126 | ||
127 | /* Logarithm of sector size. */ | |
128 | unsigned int log_sector_size; | |
129 | ||
130 | /* Maximum number of sectors read divided by GRUB_DISK_CACHE_SIZE. */ | |
131 | unsigned int max_agglomerate; | |
132 | ||
133 | /* The id used by the disk cache manager. */ | |
134 | unsigned long id; | |
135 | ||
136 | /* The partition information. This is machine-specific. */ | |
137 | struct grub_partition *partition; | |
138 | ||
139 | /* Called when a sector was read. OFFSET is between 0 and | |
140 | the sector size minus 1, and LENGTH is between 0 and the sector size. */ | |
141 | grub_disk_read_hook_t read_hook; | |
142 | ||
143 | /* Caller-specific data passed to the read hook. */ | |
144 | void *read_hook_data; | |
145 | ||
146 | /* Device-specific data. */ | |
147 | void *data; | |
148 | }; | |
149 | typedef struct grub_disk *grub_disk_t; | |
150 | ||
151 | #ifdef GRUB_UTIL | |
152 | struct grub_disk_memberlist | |
153 | { | |
154 | grub_disk_t disk; | |
155 | struct grub_disk_memberlist *next; | |
156 | }; | |
157 | typedef struct grub_disk_memberlist *grub_disk_memberlist_t; | |
158 | #endif | |
159 | ||
160 | /* The sector size. */ | |
161 | #define GRUB_DISK_SECTOR_SIZE 0x200 | |
162 | #define GRUB_DISK_SECTOR_BITS 9 | |
163 | ||
164 | /* The maximum number of disk caches. */ | |
165 | #define GRUB_DISK_CACHE_NUM 1021 | |
166 | ||
167 | /* The size of a disk cache in 512B units. Must be at least as big as the | |
168 | largest supported sector size, currently 16K. */ | |
169 | #define GRUB_DISK_CACHE_BITS 6 | |
170 | #define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS) | |
171 | ||
172 | #define GRUB_DISK_MAX_MAX_AGGLOMERATE ((1 << (30 - GRUB_DISK_CACHE_BITS - GRUB_DISK_SECTOR_BITS)) - 1) | |
173 | ||
174 | /* Return value of grub_disk_get_size() in case disk size is unknown. */ | |
175 | #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL | |
176 | ||
177 | /* This is called from the memory manager. */ | |
178 | void grub_disk_cache_invalidate_all (void); | |
179 | ||
180 | void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev); | |
181 | void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev); | |
182 | static inline int | |
183 | grub_disk_dev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data) | |
184 | { | |
185 | grub_disk_dev_t p; | |
186 | grub_disk_pull_t pull; | |
187 | ||
188 | for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++) | |
189 | for (p = grub_disk_dev_list; p; p = p->next) | |
190 | if (p->iterate && (p->iterate) (hook, hook_data, pull)) | |
191 | return 1; | |
192 | ||
193 | return 0; | |
194 | } | |
195 | ||
196 | grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name); | |
197 | void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk); | |
198 | grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk, | |
199 | grub_disk_addr_t sector, | |
200 | grub_off_t offset, | |
201 | grub_size_t size, | |
202 | void *buf); | |
203 | grub_err_t grub_disk_write (grub_disk_t disk, | |
204 | grub_disk_addr_t sector, | |
205 | grub_off_t offset, | |
206 | grub_size_t size, | |
207 | const void *buf); | |
208 | extern grub_err_t (*EXPORT_VAR(grub_disk_write_weak)) (grub_disk_t disk, | |
209 | grub_disk_addr_t sector, | |
210 | grub_off_t offset, | |
211 | grub_size_t size, | |
212 | const void *buf); | |
213 | ||
214 | ||
215 | grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk); | |
216 | ||
217 | #if DISK_CACHE_STATS | |
218 | void | |
219 | EXPORT_FUNC(grub_disk_cache_get_performance) (unsigned long *hits, unsigned long *misses); | |
220 | #endif | |
221 | ||
222 | extern void (* EXPORT_VAR(grub_disk_firmware_fini)) (void); | |
223 | extern int EXPORT_VAR(grub_disk_firmware_is_tainted); | |
224 | ||
225 | static inline void | |
226 | grub_stop_disk_firmware (void) | |
227 | { | |
228 | /* To prevent two drivers operating on the same disks. */ | |
229 | grub_disk_firmware_is_tainted = 1; | |
230 | if (grub_disk_firmware_fini) | |
231 | { | |
232 | grub_disk_firmware_fini (); | |
233 | grub_disk_firmware_fini = NULL; | |
234 | } | |
235 | } | |
236 | ||
237 | /* Disk cache. */ | |
238 | struct grub_disk_cache | |
239 | { | |
240 | enum grub_disk_dev_id dev_id; | |
241 | unsigned long disk_id; | |
242 | grub_disk_addr_t sector; | |
243 | char *data; | |
244 | int lock; | |
245 | }; | |
246 | ||
247 | extern struct grub_disk_cache EXPORT_VAR(grub_disk_cache_table)[GRUB_DISK_CACHE_NUM]; | |
248 | ||
249 | #if defined (GRUB_UTIL) | |
250 | void grub_lvm_init (void); | |
251 | void grub_ldm_init (void); | |
252 | void grub_mdraid09_init (void); | |
253 | void grub_mdraid1x_init (void); | |
254 | void grub_diskfilter_init (void); | |
255 | void grub_lvm_fini (void); | |
256 | void grub_ldm_fini (void); | |
257 | void grub_mdraid09_fini (void); | |
258 | void grub_mdraid1x_fini (void); | |
259 | void grub_diskfilter_fini (void); | |
260 | #endif | |
261 | ||
262 | #endif /* ! GRUB_DISK_HEADER */ |