2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2003,2004,2005,2006 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 2 of the License, or
8 * (at your option) any later version.
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.
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.
20 #ifndef GRUB_DISK_HEADER
21 #define GRUB_DISK_HEADER 1
23 #include <grub/symbol.h>
25 #include <grub/types.h>
26 #include <grub/device.h>
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. */
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
45 /* The device name. */
48 /* The device id used by the cache manager. */
51 /* Call HOOK with each device name, until HOOK returns non-zero. */
52 int (*iterate
) (int (*hook
) (const char *name
));
54 /* Open the device named NAME, and set up DISK. */
55 grub_err_t (*open
) (const char *name
, struct grub_disk
*disk
);
57 /* Close the disk DISK. */
58 void (*close
) (struct grub_disk
*disk
);
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
);
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
);
68 /* The next disk device. */
69 struct grub_disk_dev
*next
;
71 typedef struct grub_disk_dev
*grub_disk_dev_t
;
73 struct grub_partition
;
81 /* The underlying disk device. */
84 /* The total number of sectors. */
85 grub_uint64_t total_sectors
;
87 /* If partitions can be stored. */
90 /* The id used by the disk cache manager. */
93 /* The partition information. This is machine-specific. */
94 struct grub_partition
*partition
;
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
);
101 /* Device-specific data. */
104 typedef struct grub_disk
*grub_disk_t
;
106 /* The sector size. */
107 #define GRUB_DISK_SECTOR_SIZE 0x200
108 #define GRUB_DISK_SECTOR_BITS 9
110 /* The maximum number of disk caches. */
111 #define GRUB_DISK_CACHE_NUM 1021
113 /* The size of a disk cache in sector units. */
114 #define GRUB_DISK_CACHE_SIZE 8
115 #define GRUB_DISK_CACHE_BITS 3
117 /* This is called from the memory manager. */
118 void grub_disk_cache_invalidate_all (void);
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
));
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
,
131 grub_err_t
EXPORT_FUNC(grub_disk_write
) (grub_disk_t disk
,
132 grub_disk_addr_t sector
,
137 grub_uint64_t
EXPORT_FUNC(grub_disk_get_size
) (grub_disk_t disk
);
140 void grub_raid_init (void);
141 void grub_raid_fini (void);
142 void grub_lvm_init (void);
143 void grub_lvm_fini (void);
146 #endif /* ! GRUB_DISK_HEADER */