RTEMS  5.1
ide_part_table.h
Go to the documentation of this file.
1 
7 /*
8  * Copyright (C) 2002 OKTET Ltd., St.-Petersburg, Russia
9  *
10  * Author: Konstantin Abramenko <Konstantin.Abramenko@oktet.ru>
11  * Alexander Kukuta <Alexander.Kukuta@oktet.ru>
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  *
17  *****************************************************************************/
18 
19 #ifndef _RTEMS_IDE_PART_TABLE_H
20 #define _RTEMS_IDE_PART_TABLE_H
21 
22 #include <rtems/chain.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <sys/ioctl.h>
28 #include <sys/types.h>
29 #include <sys/endian.h>
30 #include <sys/stat.h>
31 #include <unistd.h>
32 #include <fcntl.h>
33 #include <rtems.h>
34 #include <rtems/blkdev.h>
35 #include <rtems/libio.h>
36 #include <rtems/libio_.h>
37 #include <rtems/bdbuf.h>
38 #include <rtems/seterr.h>
39 
40 /* Minor base number for all logical devices */
41 #define RTEMS_IDE_SECTOR_BITS 9
42 #define RTEMS_IDE_SECTOR_SIZE 512
43 #define RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE 16
44 #define RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER 63
45 #define RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER 4
46 #define RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX 16
47 
48 #define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA1 0x55
49 #define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA2 0xaa
50 #define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_OFFSET 0x1fe
51 #define RTEMS_IDE_PARTITION_TABLE_OFFSET 0x1be
52 #define RTEMS_IDE_PARTITION_TABLE_SIZE (4 * 16)
53 #define RTEMS_IDE_PARTITION_BOOTABLE_OFFSET 0
54 #define RTEMS_IDE_PARTITION_SYS_TYPE_OFFSET 4
55 #define RTEMS_IDE_PARTITION_START_OFFSET 8
56 #define RTEMS_IDE_PARTITION_SIZE_OFFSET 12
57 
58 /*
59  * Conversion from and to little-endian byte order. (no-op on i386/i486)
60  */
61 #define LE_TO_CPU_U16(v) le16toh(v)
62 #define LE_TO_CPU_U32(v) le32toh(v)
63 #define CPU_TO_LE_U16(v) htole16(v)
64 #define CPU_TO_LE_U32(v) htole32(v)
65 
66 /*
67  * sector_data_t --
68  * corresponds to the sector on the device
69  */
70 typedef struct rtems_sector_data_s
71 {
72  uint32_t sector_num; /* sector number on the device */
73  uint8_t data[RTEMS_ZERO_LENGTH_ARRAY]; /* raw sector data */
75 
76 
77 /*
78  * Enum partition types
79  * see list at http://ata-atapi.com/hiwtab.htm
80  *
81  * @todo Should these have RTEMS before them.
82  */
83 enum {
84  EMPTY_PARTITION = 0x00,
85  DOS_FAT12_PARTITION = 0x01,
86  DOS_FAT16_PARTITION = 0x04,
87  EXTENDED_PARTITION = 0x05,
88  DOS_P32MB_PARTITION = 0x06,
89  FAT32_PARTITION = 0x0B,
90  FAT32_LBA_PARTITION = 0x0C,
91  FAT16_LBA_PARTITION = 0x0E,
92  DM6_PARTITION = 0x54,
93  EZD_PARTITION = 0x55,
94  DM6_AUX1PARTITION = 0x51,
95  DM6_AUX3PARTITION = 0x53,
96  LINUX_SWAP = 0x82,
97  LINUX_NATIVE = 0x83,
98  LINUX_EXTENDED = 0x85
99 };
100 
101 
102 /* Forward declaration */
103 struct rtems_disk_desc_s;
104 
105 /*
106  * part_desc_t --
107  * contains all neccessary information about partition
108  */
109 typedef struct rtems_part_desc_s {
110  uint8_t bootable; /* is the partition active */
111  uint8_t sys_type; /* type of partition */
112  uint8_t log_id; /* logical number of partition */
113  uint32_t start; /* first partition sector, in absolute
114  * numeration */
115  uint32_t size; /* size in sectors */
116  uint32_t end; /* last partition sector, end = start + size - 1 */
117  struct rtems_disk_desc_s *disk_desc; /* descriptor of disk, partition
118  * contains in */
119  struct rtems_part_desc_s *ext_part; /* extended partition containing this
120  * one */
121 
122  /* partitions, containing in this one */
123  struct rtems_part_desc_s *sub_part[RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER];
125 
126 
127 
128 typedef struct rtems_disk_desc_s {
129  /* device name in /dev filesystem */
130  char dev_name[RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX];
131 
132  uint32_t sector_size; /* size of sector */
133  uint32_t sector_bits; /* the base-2 logarithm of sector_size */
134  uint32_t lba_size; /* total amount of sectors in lba address mode */
135  int last_log_id; /* used for logical disks enumerating */
136 
137  /* primary partition descriptors */
138  rtems_part_desc_t *partitions[RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER];
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
145 /*
146  * rtems_ide_part_table_free --
147  * frees disk descriptor structure
148  *
149  * PARAMETERS:
150  * disk_desc - disc descriptor structure to free
151  *
152  * RETURNS:
153  * N/A
154  */
159  rtems_disk_desc_t *disk_desc
161 
162 
163 /*
164  * rtems_ide_part_table_get --
165  * reads partition table structure from the device
166  * and creates disk description structure
167  *
168  * PARAMETERS:
169  * dev_name - path to physical device in /dev filesystem
170  * disk_desc - returned disc description structure
171  *
172  * RETURNS:
173  * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else
174  */
179  const char *dev_name,
180  rtems_disk_desc_t *disk_desc
182 
183 
184 /*
185  * rtems_ide_part_table_initialize --
186  * initializes logical devices on the physical IDE drive
187  *
188  * PARAMETERS:
189  * dev_name - path to physical device in /dev filesystem
190  *
191  * RETURNS:
192  * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else
193  */
198  const char *dev_name
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif /* _RTEMS_IDE_PART_TABLE_H */
Basic IO API.
Data which Ease the Burden of Consistently Setting Errno.
rtems_status_code
Classic API Status.
Definition: status.h:43
Definition: ide_part_table.h:109
Definition: ide_part_table.h:70
Definition: ide_part_table.h:128
Chain API.
LibIO Internal Interface.
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:531
#define RTEMS_DEPRECATED
Public name for task floating point context area.
Definition: basedefs.h:141
rtems_status_code rtems_ide_part_table_initialize(const char *dev_name) RTEMS_DEPRECATED
Definition: ide_part_table.c:550
void rtems_ide_part_table_free(rtems_disk_desc_t *disk_desc) RTEMS_DEPRECATED
Definition: ide_part_table.c:512
Block Device Management.
Block Device Buffer Management.