[b80dd59d] | 1 | /** |
---|
[57aa979] | 2 | * @file |
---|
| 3 | * |
---|
| 4 | * Block device disk management. |
---|
[b80dd59d] | 5 | */ |
---|
| 6 | |
---|
[8b96149] | 7 | /* |
---|
[e51bd96] | 8 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
| 9 | * Author: Victor V. Vengerov <vvv@oktet.ru> |
---|
| 10 | * |
---|
| 11 | * @(#) $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
[a6f5d89] | 14 | #ifndef _RTEMS_DISKDEVS_H |
---|
| 15 | #define _RTEMS_DISKDEVS_H |
---|
[e51bd96] | 16 | |
---|
| 17 | #include <rtems.h> |
---|
| 18 | #include <rtems/libio.h> |
---|
| 19 | #include <stdlib.h> |
---|
| 20 | |
---|
[57aa979] | 21 | /** |
---|
| 22 | * @ingroup rtems_bdbuf |
---|
| 23 | * |
---|
| 24 | * Buffer pool identifier. |
---|
| 25 | */ |
---|
[e51bd96] | 26 | typedef int rtems_bdpool_id; |
---|
| 27 | |
---|
[90b2c072] | 28 | #include <rtems/blkdev.h> |
---|
[3899a537] | 29 | |
---|
[57aa979] | 30 | #ifdef __cplusplus |
---|
| 31 | extern "C" { |
---|
| 32 | #endif |
---|
[3899a537] | 33 | |
---|
[57aa979] | 34 | /** |
---|
| 35 | * @defgroup rtems_disk Block Device Disk Management |
---|
| 36 | * |
---|
| 37 | * @ingroup rtems_libblock |
---|
| 38 | * |
---|
[d8602eb] | 39 | * This module provides functions to manage disk devices. |
---|
| 40 | * |
---|
| 41 | * A disk is a set of blocks which are identified by a consecutive set of |
---|
| 42 | * non-negative integers starting at zero. There are also logical disks which |
---|
| 43 | * contain a subset of consecutive disk blocks. The logical disks are used to |
---|
| 44 | * represent the partitions of a disk. The disk devices are accessed via the |
---|
| 45 | * @ref rtems_bdbuf "block device buffer module". |
---|
[57aa979] | 46 | * |
---|
| 47 | * @{ |
---|
| 48 | */ |
---|
[e51bd96] | 49 | |
---|
[57aa979] | 50 | /** |
---|
| 51 | * Block device IO control handler type. |
---|
| 52 | */ |
---|
| 53 | typedef int (*rtems_block_device_ioctl)( dev_t dev, uint32_t req, void *argp); |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * Description of a disk device (logical and physical disks). |
---|
| 57 | * |
---|
| 58 | * An array of pointer tables to rtems_disk_device structures is maintained. |
---|
| 59 | * The first table will be indexed by the major number and the second table |
---|
| 60 | * will be indexed by the minor number. This allows quick lookup using a data |
---|
| 61 | * structure of moderated size. |
---|
[e51bd96] | 62 | */ |
---|
[3899a537] | 63 | typedef struct rtems_disk_device { |
---|
[57aa979] | 64 | /** |
---|
| 65 | * Device identifier (concatenation of major and minor number). |
---|
| 66 | */ |
---|
| 67 | dev_t dev; |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * Physical device identifier (equals the @c dev entry if it specifies a |
---|
| 71 | * physical device). |
---|
| 72 | */ |
---|
| 73 | struct rtems_disk_device *phys_dev; |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * Driver capabilities. |
---|
| 77 | */ |
---|
| 78 | uint32_t capabilities; |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * Disk device name. |
---|
| 82 | */ |
---|
| 83 | char *name; |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * Usage counter. |
---|
| 87 | * |
---|
| 88 | * Devices cannot be removed if they are in use. |
---|
| 89 | */ |
---|
| 90 | unsigned uses; |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * Start block number. |
---|
| 94 | * |
---|
| 95 | * Equals zero for physical devices. It is a block offset to the related |
---|
| 96 | * physical device for logical device. |
---|
| 97 | */ |
---|
| 98 | rtems_blkdev_bnum start; |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * Size of the physical or logical disk in blocks. |
---|
| 102 | */ |
---|
| 103 | rtems_blkdev_bnum size; |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Device block size in bytes. |
---|
| 107 | * |
---|
| 108 | * This is the minimum transfer unit and must be power of two. |
---|
| 109 | */ |
---|
| 110 | uint32_t block_size; |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * Binary logarithm of the block size. |
---|
| 114 | */ |
---|
| 115 | uint32_t block_size_log2; |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * Buffer pool assigned to this disk. |
---|
| 119 | */ |
---|
| 120 | rtems_bdpool_id pool; |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | * IO control handler for this disk. |
---|
| 124 | */ |
---|
| 125 | rtems_block_device_ioctl ioctl; |
---|
[3899a537] | 126 | } rtems_disk_device; |
---|
[e51bd96] | 127 | |
---|
[57aa979] | 128 | /** |
---|
| 129 | * Creates a physical disk with device identifier @a dev. |
---|
| 130 | * |
---|
| 131 | * The block size @a block_size must be a power of two. The disk size @a |
---|
| 132 | * disk_size is the number of blocks provided by this disk. The block index |
---|
| 133 | * starts with zero. The associated disk device driver will be invoked via the |
---|
| 134 | * IO control handler @a handler. A device node will be registered in the file |
---|
| 135 | * system with absolute path @a name. This function is usually invoked from a |
---|
| 136 | * block device driver during initialization when a physical device is detected |
---|
| 137 | * in the system. The device driver provides an IO control handler to allow |
---|
| 138 | * block device operations. |
---|
[e51bd96] | 139 | */ |
---|
[57aa979] | 140 | rtems_status_code rtems_disk_create_phys( |
---|
| 141 | dev_t dev, |
---|
| 142 | uint32_t block_size, |
---|
| 143 | rtems_blkdev_bnum disk_size, |
---|
| 144 | rtems_block_device_ioctl handler, |
---|
| 145 | const char *name |
---|
| 146 | ); |
---|
| 147 | |
---|
| 148 | /** |
---|
| 149 | * Creates a logical disk with device identifier @a dev. |
---|
| 150 | * |
---|
| 151 | * A logical disk manages a subset of consecutive blocks containd in the |
---|
| 152 | * physical disk with identifier @a phys. The start block index of the logical |
---|
| 153 | * disk device is @a start. The block number of the logcal disk will be @a |
---|
| 154 | * size. The blocks must be within the range of blocks managed by the |
---|
| 155 | * associated physical disk device. A device node will be registered in the |
---|
| 156 | * file system with absolute path @a name. The block size and IO control |
---|
| 157 | * handler are inherited by the physical disk. |
---|
[e51bd96] | 158 | */ |
---|
[57aa979] | 159 | rtems_status_code rtems_disk_create_log( |
---|
| 160 | dev_t dev, |
---|
| 161 | dev_t phys, |
---|
| 162 | rtems_blkdev_bnum start, |
---|
| 163 | rtems_blkdev_bnum size, |
---|
| 164 | const char *name |
---|
| 165 | ); |
---|
[e51bd96] | 166 | |
---|
[57aa979] | 167 | /** |
---|
| 168 | * Deletes a physical or logical disk device with identifier @a dev. |
---|
[e51bd96] | 169 | * |
---|
[57aa979] | 170 | * Disk devices may be deleted if there usage counter (and the usage counters |
---|
| 171 | * of all contained logical disks devices) equals zero. When a physical disk |
---|
| 172 | * device is deleted, all logical disk devices will deleted too. The |
---|
| 173 | * corresponding device nodes will be removed from the file system. |
---|
[e51bd96] | 174 | */ |
---|
[57aa979] | 175 | rtems_status_code rtems_disk_delete(dev_t dev); |
---|
[e51bd96] | 176 | |
---|
[57aa979] | 177 | /** |
---|
| 178 | * Returns the disk device descriptor for the device identifier @a dev. |
---|
[e51bd96] | 179 | * |
---|
[57aa979] | 180 | * Increments usage counter by one. You should release the disk device |
---|
| 181 | * descriptor with rtems_disk_release(). Returns @c NULL if no corresponding |
---|
| 182 | * disk exists. |
---|
[e51bd96] | 183 | */ |
---|
[57aa979] | 184 | rtems_disk_device *rtems_disk_obtain(dev_t dev); |
---|
[048dcd2b] | 185 | |
---|
[57aa979] | 186 | /** |
---|
| 187 | * Releases the disk device description @a dd. |
---|
[e51bd96] | 188 | * |
---|
[57aa979] | 189 | * Decrements usage counter by one. |
---|
| 190 | */ |
---|
| 191 | rtems_status_code rtems_disk_release(rtems_disk_device *dd); |
---|
[e51bd96] | 192 | |
---|
[57aa979] | 193 | /** |
---|
| 194 | * Disk device iterator. |
---|
[e51bd96] | 195 | * |
---|
[57aa979] | 196 | * Returns the next disk device descriptor with a device identifier larger than |
---|
| 197 | * @a dev. If there is no such device, @c NULL will be returned. Use minus |
---|
| 198 | * one to start the search. |
---|
[e51bd96] | 199 | * |
---|
[57aa979] | 200 | * @code |
---|
| 201 | * rtems_disk_device *dd = rtems_disk_next((dev_t) -1); |
---|
| 202 | * |
---|
| 203 | * while (dd != NULL) { |
---|
| 204 | * dd = rtems_disk_next(dd->dev); |
---|
| 205 | * } |
---|
| 206 | * @endcode |
---|
[e51bd96] | 207 | */ |
---|
[57aa979] | 208 | rtems_disk_device *rtems_disk_next(dev_t dev); |
---|
[e51bd96] | 209 | |
---|
[57aa979] | 210 | /** |
---|
| 211 | * Initializes the disk device management. |
---|
[e51bd96] | 212 | * |
---|
[57aa979] | 213 | * This functions returns successful if the disk device management is already |
---|
| 214 | * initialized. There is no protection against concurrent access. |
---|
[e51bd96] | 215 | */ |
---|
[57aa979] | 216 | rtems_status_code rtems_disk_io_initialize(void); |
---|
| 217 | |
---|
| 218 | /** |
---|
| 219 | * Releases all resources allocated for disk device management. |
---|
| 220 | */ |
---|
| 221 | rtems_status_code rtems_disk_io_done(void); |
---|
| 222 | |
---|
| 223 | /** @} */ |
---|
[e51bd96] | 224 | |
---|
| 225 | #ifdef __cplusplus |
---|
| 226 | } |
---|
| 227 | #endif |
---|
| 228 | |
---|
| 229 | #endif |
---|