[b80dd59d] | 1 | /** |
---|
| 2 | * @file rtems/ide_part_table.h |
---|
[ef142d7] | 3 | * |
---|
[b80dd59d] | 4 | * Support for "MS-DOS-style" partition tables |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /* |
---|
[ef142d7] | 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 |
---|
[5b38506] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[ef142d7] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | * |
---|
| 19 | *****************************************************************************/ |
---|
| 20 | |
---|
[a6f5d89] | 21 | #ifndef _RTEMS_IDE_PART_TABLE_H |
---|
| 22 | #define _RTEMS_IDE_PART_TABLE_H |
---|
[ef142d7] | 23 | |
---|
[ebbe119e] | 24 | #include <rtems/chain.h> |
---|
[ef142d7] | 25 | #include <stdio.h> |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <errno.h> |
---|
| 29 | #include <sys/ioctl.h> |
---|
| 30 | #include <sys/types.h> |
---|
| 31 | #include <sys/stat.h> |
---|
| 32 | #include <unistd.h> |
---|
| 33 | #include <fcntl.h> |
---|
| 34 | #include <rtems.h> |
---|
| 35 | #include <rtems/blkdev.h> |
---|
| 36 | #include <rtems/libio.h> |
---|
| 37 | #include <rtems/libio_.h> |
---|
| 38 | #include <rtems/bdbuf.h> |
---|
| 39 | #include <rtems/seterr.h> |
---|
| 40 | |
---|
| 41 | /* Minor base number for all logical devices */ |
---|
| 42 | #define RTEMS_IDE_SECTOR_BITS 9 |
---|
| 43 | #define RTEMS_IDE_SECTOR_SIZE 512 |
---|
| 44 | #define RTEMS_IDE_PARTITION_DESCRIPTOR_SIZE 16 |
---|
| 45 | #define RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER 63 |
---|
| 46 | #define RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER 4 |
---|
| 47 | #define RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX 16 |
---|
| 48 | |
---|
| 49 | #define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA1 0x55 |
---|
| 50 | #define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_DATA2 0xaa |
---|
| 51 | #define RTEMS_IDE_PARTITION_MSDOS_SIGNATURE_OFFSET 0x1fe |
---|
| 52 | #define RTEMS_IDE_PARTITION_TABLE_OFFSET 0x1be |
---|
[164adec] | 53 | #define RTEMS_IDE_PARTITION_TABLE_SIZE (4 * 16) |
---|
[ef142d7] | 54 | #define RTEMS_IDE_PARTITION_BOOTABLE_OFFSET 0 |
---|
| 55 | #define RTEMS_IDE_PARTITION_SYS_TYPE_OFFSET 4 |
---|
| 56 | #define RTEMS_IDE_PARTITION_START_OFFSET 8 |
---|
| 57 | #define RTEMS_IDE_PARTITION_SIZE_OFFSET 12 |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * Conversion from and to little-endian byte order. (no-op on i386/i486) |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | #if (CPU_BIG_ENDIAN == TRUE) |
---|
| 64 | # define LE_TO_CPU_U16(v) CPU_swap_u16(v) |
---|
| 65 | # define LE_TO_CPU_U32(v) CPU_swap_u32(v) |
---|
| 66 | # define CPU_TO_LE_U16(v) CPU_swap_u16(v) |
---|
| 67 | # define CPU_TO_LE_U32(v) CPU_swap_u32(v) |
---|
| 68 | #else |
---|
| 69 | # define LE_TO_CPU_U16(v) (v) |
---|
| 70 | # define LE_TO_CPU_U32(v) (v) |
---|
| 71 | # define CPU_TO_LE_U16(v) (v) |
---|
| 72 | # define CPU_TO_LE_U32(v) (v) |
---|
| 73 | #endif |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | /* |
---|
| 77 | * sector_data_t -- |
---|
| 78 | * corresponds to the sector on the device |
---|
| 79 | */ |
---|
[3899a537] | 80 | typedef struct rtems_sector_data_s |
---|
[ef142d7] | 81 | { |
---|
[c01d95b7] | 82 | uint32_t sector_num; /* sector number on the device */ |
---|
| 83 | uint8_t data[0]; /* raw sector data */ |
---|
[3899a537] | 84 | } rtems_sector_data_t; |
---|
[ef142d7] | 85 | |
---|
| 86 | |
---|
| 87 | /* |
---|
| 88 | * Enum partition types |
---|
[dbe06865] | 89 | * see list at http://ata-atapi.com/hiwtab.htm |
---|
[3899a537] | 90 | * |
---|
| 91 | * @todo Should these have RTEMS before them. |
---|
[ef142d7] | 92 | */ |
---|
| 93 | enum { |
---|
[dbe06865] | 94 | EMPTY_PARTITION = 0x00, |
---|
| 95 | DOS_FAT12_PARTITION = 0x01, |
---|
| 96 | DOS_FAT16_PARTITION = 0x04, |
---|
| 97 | EXTENDED_PARTITION = 0x05, |
---|
| 98 | DOS_P32MB_PARTITION = 0x06, |
---|
| 99 | FAT32_PARTITION = 0x0B, |
---|
| 100 | FAT32_LBA_PARTITION = 0x0C, |
---|
| 101 | FAT16_LBA_PARTITION = 0x0E, |
---|
[ef142d7] | 102 | DM6_PARTITION = 0x54, |
---|
| 103 | EZD_PARTITION = 0x55, |
---|
| 104 | DM6_AUX1PARTITION = 0x51, |
---|
| 105 | DM6_AUX3PARTITION = 0x53, |
---|
| 106 | LINUX_SWAP = 0x82, |
---|
| 107 | LINUX_NATIVE = 0x83, |
---|
| 108 | LINUX_EXTENDED = 0x85 |
---|
| 109 | }; |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | /* Forward declaration */ |
---|
[3899a537] | 113 | struct rtems_disk_desc_s; |
---|
[ef142d7] | 114 | |
---|
| 115 | /* |
---|
| 116 | * part_desc_t -- |
---|
| 117 | * contains all neccessary information about partition |
---|
| 118 | */ |
---|
[3899a537] | 119 | typedef struct rtems_part_desc_s { |
---|
[c01d95b7] | 120 | uint8_t bootable; /* is the partition active */ |
---|
| 121 | uint8_t sys_type; /* type of partition */ |
---|
| 122 | uint8_t log_id; /* logical number of partition */ |
---|
[3899a537] | 123 | uint32_t start; /* first partition sector, in absolute |
---|
| 124 | * numeration */ |
---|
[c01d95b7] | 125 | uint32_t size; /* size in sectors */ |
---|
| 126 | uint32_t end; /* last partition sector, end = start + size - 1 */ |
---|
[3899a537] | 127 | struct rtems_disk_desc_s *disk_desc; /* descriptor of disk, partition |
---|
| 128 | * contains in */ |
---|
| 129 | struct rtems_part_desc_s *ext_part; /* extended partition containing this |
---|
| 130 | * one */ |
---|
[ef142d7] | 131 | |
---|
| 132 | /* partitions, containing in this one */ |
---|
[3899a537] | 133 | struct rtems_part_desc_s *sub_part[RTEMS_IDE_PARTITION_MAX_SUB_PARTITION_NUMBER]; |
---|
| 134 | } rtems_part_desc_t; |
---|
[ef142d7] | 135 | |
---|
| 136 | |
---|
| 137 | |
---|
[3899a537] | 138 | typedef struct rtems_disk_desc_s { |
---|
[ef142d7] | 139 | dev_t dev; /* device number */ |
---|
| 140 | |
---|
| 141 | /* device name in /dev filesystem */ |
---|
[ce92867b] | 142 | char dev_name[RTEMS_IDE_PARTITION_DEV_NAME_LENGTH_MAX]; |
---|
[ef142d7] | 143 | |
---|
[c01d95b7] | 144 | uint32_t sector_size; /* size of sector */ |
---|
| 145 | uint32_t sector_bits; /* the base-2 logarithm of sector_size */ |
---|
| 146 | uint32_t lba_size; /* total amount of sectors in lba address mode */ |
---|
[ef142d7] | 147 | int last_log_id; /* used for logical disks enumerating */ |
---|
| 148 | |
---|
| 149 | /* primary partition descriptors */ |
---|
[3899a537] | 150 | rtems_part_desc_t *partitions[RTEMS_IDE_PARTITION_MAX_PARTITION_NUMBER]; |
---|
| 151 | } rtems_disk_desc_t; |
---|
[ef142d7] | 152 | |
---|
[f139738] | 153 | #ifdef __cplusplus |
---|
| 154 | extern "C" { |
---|
| 155 | #endif |
---|
[ef142d7] | 156 | |
---|
| 157 | /* |
---|
| 158 | * rtems_ide_part_table_free -- |
---|
| 159 | * frees disk descriptor structure |
---|
| 160 | * |
---|
| 161 | * PARAMETERS: |
---|
| 162 | * disk_desc - disc descriptor structure to free |
---|
| 163 | * |
---|
| 164 | * RETURNS: |
---|
| 165 | * N/A |
---|
| 166 | */ |
---|
[7c411bd] | 167 | /** |
---|
| 168 | * @deprecated Use the @ref rtems_bdpart "block device partition module" instead. |
---|
| 169 | */ |
---|
| 170 | void rtems_ide_part_table_free( |
---|
| 171 | rtems_disk_desc_t *disk_desc |
---|
| 172 | ) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE; |
---|
[ef142d7] | 173 | |
---|
| 174 | |
---|
| 175 | /* |
---|
| 176 | * rtems_ide_part_table_get -- |
---|
| 177 | * reads partition table structure from the device |
---|
| 178 | * and creates disk description structure |
---|
| 179 | * |
---|
| 180 | * PARAMETERS: |
---|
| 181 | * dev_name - path to physical device in /dev filesystem |
---|
| 182 | * disk_desc - returned disc description structure |
---|
| 183 | * |
---|
| 184 | * RETURNS: |
---|
| 185 | * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else |
---|
| 186 | */ |
---|
[7c411bd] | 187 | /** |
---|
| 188 | * @deprecated Use the @ref rtems_bdpart "block device partition module" instead. |
---|
| 189 | */ |
---|
| 190 | rtems_status_code rtems_ide_part_table_get( |
---|
| 191 | const char *dev_name, |
---|
| 192 | rtems_disk_desc_t *disk_desc |
---|
| 193 | ) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE; |
---|
[ef142d7] | 194 | |
---|
| 195 | |
---|
| 196 | /* |
---|
| 197 | * rtems_ide_part_table_initialize -- |
---|
| 198 | * initializes logical devices on the physical IDE drive |
---|
| 199 | * |
---|
| 200 | * PARAMETERS: |
---|
| 201 | * dev_name - path to physical device in /dev filesystem |
---|
| 202 | * |
---|
| 203 | * RETURNS: |
---|
| 204 | * RTEMS_SUCCESSFUL if success, or -1 and corresponding errno else |
---|
| 205 | */ |
---|
[7c411bd] | 206 | /** |
---|
| 207 | * @deprecated Use the @ref rtems_bdpart "block device partition module" instead. |
---|
| 208 | */ |
---|
| 209 | rtems_status_code rtems_ide_part_table_initialize( |
---|
| 210 | char *dev_name |
---|
| 211 | ) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE; |
---|
[ef142d7] | 212 | |
---|
[f139738] | 213 | #ifdef __cplusplus |
---|
| 214 | } |
---|
| 215 | #endif |
---|
[ef142d7] | 216 | |
---|
[f139738] | 217 | #endif /* _RTEMS_IDE_PART_TABLE_H */ |
---|