]> git.proxmox.com Git - grub2.git/blob - include/grub/disk.h
2006-11-11 Jeroen Dekkers <jeroen@dekkers.cx>
[grub2.git] / include / grub / disk.h
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006 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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef GRUB_DISK_HEADER
21 #define GRUB_DISK_HEADER 1
22
23 #include <grub/symbol.h>
24 #include <grub/err.h>
25 #include <grub/types.h>
26 #include <grub/device.h>
27
28 /* These are used to set a device id. When you add a new disk device,
29 you must define a new id for it here. */
30 enum grub_disk_dev_id
31 {
32 GRUB_DISK_DEVICE_BIOSDISK_ID,
33 GRUB_DISK_DEVICE_OFDISK_ID,
34 GRUB_DISK_DEVICE_LOOPBACK_ID,
35 GRUB_DISK_DEVICE_EFIDISK_ID,
36 GRUB_DISK_DEVICE_RAID_ID,
37 GRUB_DISK_DEVICE_LVM_ID
38 };
39
40 struct grub_disk;
41
42 /* Disk device. */
43 struct grub_disk_dev
44 {
45 /* The device name. */
46 const char *name;
47
48 /* The device id used by the cache manager. */
49 unsigned long id;
50
51 /* Call HOOK with each device name, until HOOK returns non-zero. */
52 int (*iterate) (int (*hook) (const char *name));
53
54 /* Open the device named NAME, and set up DISK. */
55 grub_err_t (*open) (const char *name, struct grub_disk *disk);
56
57 /* Close the disk DISK. */
58 void (*close) (struct grub_disk *disk);
59
60 /* Read SIZE sectors from the sector SECTOR of the disk DISK into BUF. */
61 grub_err_t (*read) (struct grub_disk *disk, grub_disk_addr_t sector,
62 grub_size_t size, char *buf);
63
64 /* Write SIZE sectors from BUF into the sector SECTOR of the disk DISK. */
65 grub_err_t (*write) (struct grub_disk *disk, grub_disk_addr_t sector,
66 grub_size_t size, const char *buf);
67
68 /* The next disk device. */
69 struct grub_disk_dev *next;
70 };
71 typedef struct grub_disk_dev *grub_disk_dev_t;
72
73 struct grub_partition;
74
75 /* Disk. */
76 struct grub_disk
77 {
78 /* The disk name. */
79 const char *name;
80
81 /* The underlying disk device. */
82 grub_disk_dev_t dev;
83
84 /* The total number of sectors. */
85 grub_uint64_t total_sectors;
86
87 /* If partitions can be stored. */
88 int has_partitions;
89
90 /* The id used by the disk cache manager. */
91 unsigned long id;
92
93 /* The partition information. This is machine-specific. */
94 struct grub_partition *partition;
95
96 /* Called when a sector was read. OFFSET is between 0 and
97 the sector size minus 1, and LENGTH is between 0 and the sector size. */
98 void (*read_hook) (grub_disk_addr_t sector,
99 unsigned offset, unsigned length);
100
101 /* Device-specific data. */
102 void *data;
103 };
104 typedef struct grub_disk *grub_disk_t;
105
106 /* The sector size. */
107 #define GRUB_DISK_SECTOR_SIZE 0x200
108 #define GRUB_DISK_SECTOR_BITS 9
109
110 /* The maximum number of disk caches. */
111 #define GRUB_DISK_CACHE_NUM 1021
112
113 /* The size of a disk cache in sector units. */
114 #define GRUB_DISK_CACHE_SIZE 8
115 #define GRUB_DISK_CACHE_BITS 3
116
117 /* This is called from the memory manager. */
118 void grub_disk_cache_invalidate_all (void);
119
120 void EXPORT_FUNC(grub_disk_dev_register) (grub_disk_dev_t dev);
121 void EXPORT_FUNC(grub_disk_dev_unregister) (grub_disk_dev_t dev);
122 int EXPORT_FUNC(grub_disk_dev_iterate) (int (*hook) (const char *name));
123
124 grub_disk_t EXPORT_FUNC(grub_disk_open) (const char *name);
125 void EXPORT_FUNC(grub_disk_close) (grub_disk_t disk);
126 grub_err_t EXPORT_FUNC(grub_disk_read) (grub_disk_t disk,
127 grub_disk_addr_t sector,
128 grub_off_t offset,
129 grub_size_t size,
130 char *buf);
131 grub_err_t EXPORT_FUNC(grub_disk_write) (grub_disk_t disk,
132 grub_disk_addr_t sector,
133 grub_off_t offset,
134 grub_size_t size,
135 const char *buf);
136
137 grub_uint64_t EXPORT_FUNC(grub_disk_get_size) (grub_disk_t disk);
138
139 #ifdef GRUB_UTIL
140 void grub_raid_init (void);
141 void grub_raid_fini (void);
142 void grub_lvm_init (void);
143 void grub_lvm_fini (void);
144 #endif
145
146 #endif /* ! GRUB_DISK_HEADER */