2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
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.
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.
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/>.
19 #ifndef GRUB_DISK_HEADER
20 #define GRUB_DISK_HEADER 1
22 #include <grub/symbol.h>
24 #include <grub/types.h>
25 #include <grub/device.h>
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. */
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
,
48 struct grub_disk_memberlist
;
54 /* The device name. */
57 /* The device id used by the cache manager. */
60 /* Call HOOK with each device name, until HOOK returns non-zero. */
61 int (*iterate
) (int (*hook
) (const char *name
));
63 /* Open the device named NAME, and set up DISK. */
64 grub_err_t (*open
) (const char *name
, struct grub_disk
*disk
);
66 /* Close the disk DISK. */
67 void (*close
) (struct grub_disk
*disk
);
69 /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
70 grub_err_t (*read
) (struct grub_disk
*disk
, grub_disk_addr_t sector
,
71 grub_size_t size
, char *buf
);
73 /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
74 grub_err_t (*write
) (struct grub_disk
*disk
, grub_disk_addr_t sector
,
75 grub_size_t size
, const char *buf
);
78 struct grub_disk_memberlist
*(*memberlist
) (struct grub_disk
*disk
);
81 /* The next disk device. */
82 struct grub_disk_dev
*next
;
84 typedef struct grub_disk_dev
*grub_disk_dev_t
;
86 struct grub_partition
;
94 /* The underlying disk device. */
97 /* The total number of sectors. */
98 grub_uint64_t total_sectors
;
100 /* If partitions can be stored. */
103 /* The id used by the disk cache manager. */
106 /* The partition information. This is machine-specific. */
107 struct grub_partition
*partition
;
109 /* Called when a sector was read. OFFSET is between 0 and
110 the sector size minus 1, and LENGTH is between 0 and the sector size. */
111 void NESTED_FUNC_ATTR (*read_hook
) (grub_disk_addr_t sector
,
112 unsigned offset
, unsigned length
);
114 /* Device-specific data. */
117 typedef struct grub_disk
*grub_disk_t
;
120 struct grub_disk_memberlist
123 struct grub_disk_memberlist
*next
;
125 typedef struct grub_disk_memberlist
*grub_disk_memberlist_t
;
128 /* The sector size. */
129 #define GRUB_DISK_SECTOR_SIZE 0x200
130 #define GRUB_DISK_SECTOR_BITS 9
132 /* The maximum number of disk caches. */
133 #define GRUB_DISK_CACHE_NUM 1021
135 /* The size of a disk cache in sector units. */
136 #define GRUB_DISK_CACHE_SIZE 8
137 #define GRUB_DISK_CACHE_BITS 3
139 /* This is called from the memory manager. */
140 void grub_disk_cache_invalidate_all (void);
142 void EXPORT_FUNC(grub_disk_dev_register
) (grub_disk_dev_t dev
);
143 void EXPORT_FUNC(grub_disk_dev_unregister
) (grub_disk_dev_t dev
);
144 int EXPORT_FUNC(grub_disk_dev_iterate
) (int (*hook
) (const char *name
));
146 grub_disk_t
EXPORT_FUNC(grub_disk_open
) (const char *name
);
147 void EXPORT_FUNC(grub_disk_close
) (grub_disk_t disk
);
148 grub_err_t
EXPORT_FUNC(grub_disk_read
) (grub_disk_t disk
,
149 grub_disk_addr_t sector
,
153 grub_err_t
EXPORT_FUNC(grub_disk_write
) (grub_disk_t disk
,
154 grub_disk_addr_t sector
,
159 grub_uint64_t
EXPORT_FUNC(grub_disk_get_size
) (grub_disk_t disk
);
161 extern void (* EXPORT_VAR(grub_disk_firmware_fini
)) (void);
162 extern int EXPORT_VAR(grub_disk_firmware_is_tainted
);
165 void grub_raid_init (void);
166 void grub_raid_fini (void);
167 void grub_lvm_init (void);
168 void grub_lvm_fini (void);
171 #endif /* ! GRUB_DISK_HEADER */