RTEMS 6.1-rc2
Loading...
Searching...
No Matches
ide_part_table.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
9/*
10 * Copyright (C) 2002 OKTET Ltd., St.-Petersburg, Russia
11 *
12 * Author: Konstantin Abramenko <Konstantin.Abramenko@oktet.ru>
13 * Alexander Kukuta <Alexander.Kukuta@oktet.ru>
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 *****************************************************************************/
37
38#ifndef _RTEMS_IDE_PART_TABLE_H
39#define _RTEMS_IDE_PART_TABLE_H
40
41#include <rtems/chain.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#include <errno.h>
46#include <sys/ioctl.h>
47#include <sys/types.h>
48#include <sys/endian.h>
49#include <sys/stat.h>
50#include <unistd.h>
51#include <fcntl.h>
52#include <rtems.h>
53#include <rtems/blkdev.h>
54#include <rtems/libio.h>
55#include <rtems/libio_.h>
56#include <rtems/bdbuf.h>
57#include <rtems/seterr.h>
58
59/* Minor base number for all logical devices */
60#define RTEMS_IDE_SECTOR_BITS 9
61#define RTEMS_IDE_SECTOR_SIZE 512
62#define RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE 16
63#define RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER 63
64#define RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER 4
65#define RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX 16
66
67#define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA1 0x55
68#define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA2 0xaa
69#define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_OFFSET 0x1fe
70#define RTEMS_IDE_PARTITION_TABLE_OFFSET 0x1be
71#define RTEMS_IDE_PARTITION_TABLE_SIZE (4 * 16)
72#define RTEMS_IDE_PARTITION_BOOTABLE_OFFSET 0
73#define RTEMS_IDE_PARTITION_SYS_TYPE_OFFSET 4
74#define RTEMS_IDE_PARTITION_START_OFFSET 8
75#define RTEMS_IDE_PARTITION_SIZE_OFFSET 12
76
77/*
78 * Conversion from and to little-endian byte order. (no-op on i386/i486)
79 */
80#define LE_TO_CPU_U16(v) le16toh(v)
81#define LE_TO_CPU_U32(v) le32toh(v)
82#define CPU_TO_LE_U16(v) htole16(v)
83#define CPU_TO_LE_U32(v) htole32(v)
84
85/*
86 * sector_data_t --
87 * corresponds to the sector on the device
88 */
89typedef struct rtems_sector_data_s
90{
91 uint32_t sector_num; /* sector number on the device */
92 uint8_t data[RTEMS_ZERO_LENGTH_ARRAY]; /* raw sector data */
94
95
96/*
97 * Enum partition types
98 * see list at http://ata-atapi.com/hiwtab.htm
99 *
100 * @todo Should these have RTEMS before them.
101 */
102enum {
103 EMPTY_PARTITION = 0x00,
104 DOS_FAT12_PARTITION = 0x01,
105 DOS_FAT16_PARTITION = 0x04,
106 EXTENDED_PARTITION = 0x05,
107 DOS_P32MB_PARTITION = 0x06,
108 FAT32_PARTITION = 0x0B,
109 FAT32_LBA_PARTITION = 0x0C,
110 FAT16_LBA_PARTITION = 0x0E,
111 DM6_PARTITION = 0x54,
112 EZD_PARTITION = 0x55,
113 DM6_AUX1PARTITION = 0x51,
114 DM6_AUX3PARTITION = 0x53,
115 LINUX_SWAP = 0x82,
116 LINUX_NATIVE = 0x83,
117 LINUX_EXTENDED = 0x85
118};
119
120
121/* Forward declaration */
122struct rtems_disk_desc_s;
123
124/*
125 * part_desc_t --
126 * contains all neccessary information about partition
127 */
128typedef struct rtems_part_desc_s {
129 uint8_t bootable; /* is the partition active */
130 uint8_t sys_type; /* type of partition */
131 uint8_t log_id; /* logical number of partition */
132 uint32_t start; /* first partition sector, in absolute
133 * numeration */
134 uint32_t size; /* size in sectors */
135 uint32_t end; /* last partition sector, end = start + size - 1 */
136 struct rtems_disk_desc_s *disk_desc; /* descriptor of disk, partition
137 * contains in */
138 struct rtems_part_desc_s *ext_part; /* extended partition containing this
139 * one */
140
141 /* partitions, containing in this one */
142 struct rtems_part_desc_s *sub_part[RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER];
144
145
146
147typedef struct rtems_disk_desc_s {
148 /* device name in /dev filesystem */
149 char dev_name[RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX];
150
151 uint32_t sector_size; /* size of sector */
152 uint32_t sector_bits; /* the base-2 logarithm of sector_size */
153 uint32_t lba_size; /* total amount of sectors in lba address mode */
154 int last_log_id; /* used for logical disks enumerating */
155
156 /* primary partition descriptors */
157 rtems_part_desc_t *partitions[RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER];
159
160#ifdef __cplusplus
161extern "C" {
162#endif
163
164/*
165 * rtems_ide_part_table_free --
166 * frees disk descriptor structure
167 *
168 * PARAMETERS:
169 * disk_desc - disc descriptor structure to free
170 *
171 * RETURNS:
172 * N/A
173 */
178 rtems_disk_desc_t *disk_desc
180
181
182/*
183 * rtems_ide_part_table_get --
184 * reads partition table structure from the device
185 * and creates disk description structure
186 *
187 * PARAMETERS:
188 * dev_name - path to physical device in /dev filesystem
189 * disk_desc - returned disc description structure
190 *
191 * RETURNS:
192 * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else
193 */
198 const char *dev_name,
199 rtems_disk_desc_t *disk_desc
201
202
203/*
204 * rtems_ide_part_table_initialize --
205 * initializes logical devices on the physical IDE drive
206 *
207 * PARAMETERS:
208 * dev_name - path to physical device in /dev filesystem
209 *
210 * RETURNS:
211 * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else
212 */
217 const char *dev_name
219
220#ifdef __cplusplus
221}
222#endif
223
224#endif /* _RTEMS_IDE_PART_TABLE_H */
Block Device Buffer Management.
Block Device Management.
This header file provides the Chains API.
#define RTEMS_DEPRECATED
Instructs the compiler in a declaration to issue a warning whenever a variable, function,...
Definition: basedefs.h:334
#define RTEMS_ZERO_LENGTH_ARRAY
This constant represents the element count of a zero-length array.
Definition: basedefs.h:1032
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
void rtems_ide_part_table_free(rtems_disk_desc_t *disk_desc) RTEMS_DEPRECATED
Definition: ide_part_table.c:531
rtems_status_code rtems_ide_part_table_get(const char *dev_name, rtems_disk_desc_t *disk_desc) RTEMS_DEPRECATED
Definition: ide_part_table.c:550
rtems_status_code rtems_ide_part_table_initialize(const char *dev_name) RTEMS_DEPRECATED
Definition: ide_part_table.c:569
Basic IO API.
LibIO Internal Interface.
This header file defines the RTEMS Classic API.
This header file defines macros to set errno and return minus one.
Definition: ide_part_table.h:147
Definition: ide_part_table.h:128
Definition: ide_part_table.h:90
This header file provides interfaces of the system endianness support.