chain.c32, libcom32: Move struct gpt_part as disk_gpt_part_entry
[profile/ivi/syslinux.git] / com32 / include / syslinux / disk.h
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2003-2009 H. Peter Anvin - All Rights Reserved
4  *   Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
5  *   Copyright (C) 2010 Shao Miller
6  *
7  *   Permission is hereby granted, free of charge, to any person
8  *   obtaining a copy of this software and associated documentation
9  *   files (the "Software"), to deal in the Software without
10  *   restriction, including without limitation the rights to use,
11  *   copy, modify, merge, publish, distribute, sublicense, and/or
12  *   sell copies of the Software, and to permit persons to whom
13  *   the Software is furnished to do so, subject to the following
14  *   conditions:
15  *
16  *   The above copyright notice and this permission notice shall
17  *   be included in all copies or substantial portions of the Software.
18  *
19  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21  *   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23  *   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24  *   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  *   OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * ----------------------------------------------------------------------- */
29
30 /**
31  * @file syslinux/disk.h
32  *
33  * Deal with disks and partitions
34  */
35
36 #ifndef _SYSLINUX_DISK_H
37 #define _SYSLINUX_DISK_H
38
39 #include <com32.h>
40 #include <stdint.h>
41
42 #define SECTOR 512              /* bytes/sector */
43
44 struct disk_info {
45     int disk;
46     int ebios;                  /* EBIOS supported on this disk */
47     int cbios;                  /* CHS geometry is valid */
48     int head;
49     int sect;
50 };
51
52 struct disk_ebios_dapa {
53     uint16_t len;
54     uint16_t count;
55     uint16_t off;
56     uint16_t seg;
57     uint64_t lba;
58 };
59
60 /**
61  * CHS (cylinder, head, sector) value extraction macros.
62  * Taken from WinVBlock.  None expand to an lvalue.
63 */
64 #define     chs_head(chs) chs[0]
65 #define   chs_sector(chs) (chs[1] & 0x3F)
66 #define chs_cyl_high(chs) (((uint16_t)(chs[1] & 0xC0)) << 2)
67 #define  chs_cyl_low(chs) ((uint16_t)chs[2])
68 #define chs_cylinder(chs) (chs_cyl_high(chs) | chs_cyl_low(chs))
69 typedef uint8_t disk_chs[3];
70
71 /* A DOS partition table entry */
72 struct disk_dos_part_entry {
73     uint8_t active_flag;        /* 0x80 if "active" */
74     disk_chs start;
75     uint8_t ostype;
76     disk_chs end;
77     uint32_t start_lba;
78     uint32_t length;
79 } __attribute__ ((packed));
80
81 /* A DOS MBR */
82 struct disk_dos_mbr {
83     char code[440];
84     uint32_t disk_sig;
85     char pad[2];
86     struct disk_dos_part_entry table[4];
87     uint16_t sig;
88 } __attribute__ ((packed));
89 #define disk_mbr_sig_magic 0xAA55
90
91 /**
92  * A GPT disk/partition GUID
93  *
94  * Be careful with endianness, you must adjust it yourself
95  * iff you are directly using the fourth data chunk.
96  * There might be a better header for this...
97  */
98 struct guid {
99     uint32_t data1;
100     uint16_t data2;
101     uint16_t data3;
102     uint64_t data4;
103 } __attribute__ ((packed));
104
105 /**
106  * This walk-map effectively reverses the little-endian
107  * portions of a GPT disk/partition GUID for a string representation.
108  * There might be a better header for this...
109  */
110 static const char guid_le_walk_map[] = {
111     3, -1, -1, -1, 0,
112     5, -1, 0,
113     3, -1, 0,
114     2, 1, 0,
115     1, 1, 1, 1, 1, 1
116 };
117
118 /* A GPT partition */
119 struct disk_gpt_part_entry {
120     struct guid type;
121     struct guid uid;
122     uint64_t lba_first;
123     uint64_t lba_last;
124     uint64_t attribs;
125     char name[72];
126 } __attribute__ ((packed));
127
128 extern int disk_int13_retry(const com32sys_t * inreg, com32sys_t * outreg);
129 extern int disk_get_params(int disk, struct disk_info *const diskinfo);
130 extern void *disk_read_sectors(const struct disk_info *const diskinfo,
131                                uint64_t lba, uint8_t count);
132 extern int disk_write_sector(const struct disk_info *const diskinfo,
133                              unsigned int lba, const void *data);
134 extern int disk_write_verify_sector(const struct disk_info *const diskinfo,
135                                     unsigned int lba, const void *buf);
136 extern void disk_dos_part_dump(const struct disk_dos_part_entry *const part);
137
138 #endif /* _SYSLINUX_DISK_H */