source: rtems/cpukit/libblock/include/rtems/diskdevs.h @ b96e09c

4.104.11
Last change on this file since b96e09c was b96e09c, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Oct 13, 2009 at 7:58:33 AM
  • libblock/include/rtems/diskdevs.h: Added driver data pointer to IO control function. The IO control handler takes now the disk device as first parameter instead of the physical device number.
  • cpukit/libblock/include/rtems/blkdev.h, libblock/src/bdbuf.c, libblock/src/blkdev.c, libblock/src/diskdevs.c, libblock/src/nvdisk.c, libblock/src/flashdisk.c, libblock/src/ramdisk.c: Update for block device API change.
  • Property mode set to 100644
File size: 7.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_disk
5 *
6 * Block device disk management.
7 */
8 
9/*
10 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
11 * Author: Victor V. Vengerov <vvv@oktet.ru>
12 *
13 * @(#) $Id$
14 */
15
16#ifndef _RTEMS_DISKDEVS_H
17#define _RTEMS_DISKDEVS_H
18
19#include <rtems.h>
20#include <rtems/libio.h>
21#include <stdlib.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27typedef struct rtems_disk_device rtems_disk_device;
28
29/**
30 * @defgroup rtems_disk Block Device Disk Management
31 *
32 * @ingroup rtems_libblock
33 *
34 * @brief This module provides functions to manage disk devices.
35 *
36 * A disk is a set of blocks which are identified by a consecutive set of
37 * non-negative integers starting at zero.  There are also logical disks which
38 * contain a subset of consecutive disk blocks.  The logical disks are used to
39 * represent the partitions of a disk.  The disk devices are accessed via the
40 * @ref rtems_bdbuf "block device buffer module".
41 *
42 * @{
43 */
44
45/**
46 * @brief Block device block index type.
47 */
48typedef uint32_t rtems_blkdev_bnum;
49
50/**
51 * @brief Block device IO control handler type.
52 */
53typedef int (*rtems_block_device_ioctl)(
54  rtems_disk_device *dd,
55  uint32_t req,
56  void *argp
57);
58
59/**
60 * @brief Description of a disk device (logical and physical disks).
61 *
62 * An array of pointer tables to rtems_disk_device structures is maintained.
63 * The first table will be indexed by the major number and the second table
64 * will be indexed by the minor number.  This allows quick lookup using a data
65 * structure of moderated size.
66 */
67struct rtems_disk_device {
68  /**
69   * @brief Device identifier (concatenation of major and minor number).
70   */
71  dev_t dev;
72
73  /**
74   * @brief Physical device identifier (equals the @c dev entry if it specifies a
75   * physical device).
76   */
77  rtems_disk_device *phys_dev;
78
79  /**
80   * @brief Driver capabilities.
81   */
82  uint32_t capabilities;
83
84  /**
85   * @brief Disk device name.
86   */
87  char *name;
88
89  /**
90   * @brief Usage counter.
91   *
92   * Devices cannot be removed if they are in use.
93   */
94  unsigned uses;
95
96  /**
97   * @brief Start block number.
98   *
99   * Equals zero for physical devices.  It is a block offset to the related
100   * physical device for logical device.
101   */
102  rtems_blkdev_bnum start;
103
104  /**
105   * @brief Size of the physical or logical disk in blocks.
106   */
107  rtems_blkdev_bnum size;
108
109  /**
110   * @brief Device block size in bytes.
111   *
112   * This is the minimum transfer unit. It can be any size.
113   */
114  uint32_t block_size;
115
116  /**
117   * @brief Device media block size in bytes.
118   *
119   * This is the media transfer unit the hardware defaults to.
120   */
121  uint32_t media_block_size;
122
123  /**
124   * @brief IO control handler for this disk.
125   */
126  rtems_block_device_ioctl ioctl;
127
128  /**
129   * @brief Private data for the disk driver.
130   */
131  void *driver_data;
132};
133
134/**
135 * @name Disk Device Data
136 *
137 * @{
138 */
139
140static inline dev_t rtems_disk_physical_device_number(
141  const rtems_disk_device *dd
142)
143{
144  return dd->phys_dev->dev;
145}
146
147static inline rtems_device_major_number rtems_disk_physical_major_number(
148  const rtems_disk_device *dd
149)
150{
151  return rtems_filesystem_dev_major_t(dd->phys_dev->dev);
152}
153
154static inline rtems_device_minor_number rtems_disk_physical_minor_number(
155  const rtems_disk_device *dd
156)
157{
158  return rtems_filesystem_dev_minor_t(dd->phys_dev->dev);
159}
160
161static inline dev_t rtems_disk_device_number(const rtems_disk_device *dd)
162{
163  return dd->dev;
164}
165
166static inline rtems_device_major_number rtems_disk_major_number(
167  const rtems_disk_device *dd
168)
169{
170  return rtems_filesystem_dev_major_t(dd->dev);
171}
172
173static inline rtems_device_minor_number rtems_disk_minor_number(
174  const rtems_disk_device *dd
175)
176{
177  return rtems_filesystem_dev_minor_t(dd->dev);
178}
179
180static inline void *rtems_disk_driver_data(const rtems_disk_device *dd)
181{
182  return dd->driver_data;
183}
184
185static inline uint32_t rtems_disk_block_size(const rtems_disk_device *dd)
186{
187  return dd->block_size;
188}
189
190static inline uint32_t rtems_disk_media_block_size(const rtems_disk_device *dd)
191{
192  return dd->media_block_size;
193}
194
195/** @} */
196
197/**
198 * @name Disk Device Maintainance
199 *
200 * @{
201 */
202
203/**
204 * @brief Creates a physical disk with device identifier @a dev.
205 *
206 * The block size @a block_size must be a power of two.  The disk size @a
207 * disk_size is the number of blocks provided by this disk.  The block index
208 * starts with zero.  The associated disk device driver will be invoked via the
209 * IO control handler @a handler.  A device node will be registered in the file
210 * system with absolute path @a name.  This function is usually invoked from a
211 * block device driver during initialization when a physical device is detected
212 * in the system.  The device driver provides an IO control handler to allow
213 * block device operations.
214 */
215rtems_status_code rtems_disk_create_phys(
216  dev_t dev,
217  uint32_t block_size,
218  rtems_blkdev_bnum disk_size,
219  rtems_block_device_ioctl handler,
220  void *driver_data,
221  const char *name
222);
223
224/**
225 * @brief Creates a logical disk with device identifier @a dev.
226 *
227 * A logical disk manages a subset of consecutive blocks contained in the
228 * physical disk with identifier @a phys.  The start block index of the logical
229 * disk device is @a start.  The block number of the logcal disk will be @a
230 * size.  The blocks must be within the range of blocks managed by the
231 * associated physical disk device.  A device node will be registered in the
232 * file system with absolute path @a name.  The block size and IO control
233 * handler are inherited by the physical disk.
234 */
235rtems_status_code rtems_disk_create_log(
236  dev_t dev,
237  dev_t phys,
238  rtems_blkdev_bnum start,
239  rtems_blkdev_bnum size,
240  const char *name
241);
242
243/**
244 * @brief Deletes a physical or logical disk device with identifier @a dev.
245 *
246 * Disk devices may be deleted if there usage counter (and the usage counters
247 * of all contained logical disks devices) equals zero.  When a physical disk
248 * device is deleted, all logical disk devices will deleted too.  The
249 * corresponding device nodes will be removed from the file system.
250 */
251rtems_status_code rtems_disk_delete(dev_t dev);
252
253/**
254 * @brief Returns the disk device descriptor for the device identifier @a dev.
255 *
256 * Increments usage counter by one.  You should release the disk device
257 * descriptor with rtems_disk_release().  Returns @c NULL if no corresponding
258 * disk exists.
259 */
260rtems_disk_device *rtems_disk_obtain(dev_t dev);
261
262/**
263 * @brief Releases the disk device description @a dd.
264 *
265 * Decrements usage counter by one.
266 */
267rtems_status_code rtems_disk_release(rtems_disk_device *dd);
268
269/** @} */
270
271/**
272 * @name Disk Management
273 *
274 * @{
275 */
276
277/**
278 * @brief Disk device iterator.
279 *
280 * Returns the next disk device descriptor with a device identifier larger than
281 * @a dev.  If there is no such device, @c NULL will be returned.  Use minus
282 * one to start the search.
283 *
284 * @code
285 * rtems_disk_device *dd = rtems_disk_next((dev_t) -1);
286 *
287 * while (dd != NULL) {
288 *   dd = rtems_disk_next(dd->dev);
289 * }
290 * @endcode
291 */
292rtems_disk_device *rtems_disk_next(dev_t dev);
293
294/**
295 * @brief Initializes the disk device management.
296 *
297 * This functions returns successful if the disk device management is already
298 * initialized.  There is no protection against concurrent access.
299 */
300rtems_status_code rtems_disk_io_initialize(void);
301
302/**
303 * @brief Releases all resources allocated for disk device management.
304 */
305rtems_status_code rtems_disk_io_done(void);
306
307/** @} */
308
309/** @} */
310
311#ifdef __cplusplus
312}
313#endif
314
315#endif
Note: See TracBrowser for help on using the repository browser.