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

4.104.115
Last change on this file since c8522fd was c8522fd, checked in by Sebastian Huber <sebastian.huber@…>, on 05/17/10 at 08:08:30

2010-05-17 Oleg Kravtsov <Oleg.Kravtsov@…>

PR 1449/cpukit

  • libblock/src/diskdevs.c: rtems_disk_next() will now implicitly obtain the returned disk.
  • libblock/include/rtems/diskdevs.h: Documentation.
  • Property mode set to 100644
File size: 8.9 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_disk
5 *
6 * @brief Block device disk management API.
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 deleted 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   * @brief Indicates that this disk should be deleted as soon as the last user
135   * releases this disk.
136   */
137  bool deleted;
138};
139
140/**
141 * @name Disk Device Data
142 *
143 * @{
144 */
145
146static inline dev_t rtems_disk_get_device_identifier(
147  const rtems_disk_device *dd
148)
149{
150  return dd->dev;
151}
152
153static inline rtems_device_major_number rtems_disk_get_major_number(
154  const rtems_disk_device *dd
155)
156{
157  return rtems_filesystem_dev_major_t(dd->dev);
158}
159
160static inline rtems_device_minor_number rtems_disk_get_minor_number(
161  const rtems_disk_device *dd
162)
163{
164  return rtems_filesystem_dev_minor_t(dd->dev);
165}
166
167static inline void *rtems_disk_get_driver_data(
168  const rtems_disk_device *dd
169)
170{
171  return dd->driver_data;
172}
173
174static inline uint32_t rtems_disk_get_media_block_size(
175  const rtems_disk_device *dd
176)
177{
178  return dd->media_block_size;
179}
180
181/** @} */
182
183/**
184 * @name Disk Device Maintainance
185 *
186 * @{
187 */
188
189/**
190 * @brief Creates a physical disk with device identifier @a dev.
191 *
192 * The block size @a block_size must be positive.  The disk will have
193 * @a block_count blocks.  The block index starts with zero.  The associated disk
194 * device driver will be invoked via the IO control handler @a handler.  A
195 * device node will be registered in the file system with absolute path @a
196 * name, if @a name is not @c NULL.  This function is usually invoked from a
197 * block device driver during initialization when a physical device is detected
198 * in the system.  The device driver provides an IO control handler to allow
199 * block device operations.
200 *
201 * @retval RTEMS_SUCCESSFUL Successful operation.
202 * @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
203 * @retval RTEMS_INVALID_ADDRESS IO control handler is @c NULL.
204 * @retval RTEMS_INVALID_NUMBER Block size is zero.
205 * @retval RTEMS_NO_MEMORY Not enough memory.
206 * @retval RTEMS_RESOURCE_IN_USE Disk device descriptor is already in use.
207 * @retval RTEMS_UNSATISFIED Cannot create device node.
208 */
209rtems_status_code rtems_disk_create_phys(
210  dev_t dev,
211  uint32_t block_size,
212  rtems_blkdev_bnum block_count,
213  rtems_block_device_ioctl handler,
214  void *driver_data,
215  const char *name
216);
217
218/**
219 * @brief Creates a logical disk with device identifier @a dev.
220 *
221 * A logical disk manages a subset of consecutive blocks contained in the
222 * physical disk with identifier @a phys.  The start block index of the logical
223 * disk device is @a begin_block.  The block count of the logcal disk will be
224 * @a block_count.  The blocks must be within the range of blocks managed by
225 * the associated physical disk device.  A device node will be registered in
226 * the file system with absolute path @a name, if @a name is not @c NULL.  The
227 * block size and IO control handler are inherited by the physical disk.
228 *
229 * @retval RTEMS_SUCCESSFUL Successful operation.
230 * @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
231 * @retval RTEMS_INVALID_ID Specified physical disk identifier does not
232 * correspond to a physical disk.
233 * @retval RTEMS_INVALID_NUMBER Begin block or block count are out of range.
234 * @retval RTEMS_NO_MEMORY Not enough memory.
235 * @retval RTEMS_RESOURCE_IN_USE Disk device descriptor for logical disk
236 * identifier is already in use.
237 * @retval RTEMS_UNSATISFIED Cannot create device node.
238 */
239rtems_status_code rtems_disk_create_log(
240  dev_t dev,
241  dev_t phys,
242  rtems_blkdev_bnum begin_block,
243  rtems_blkdev_bnum block_count,
244  const char *name
245);
246
247/**
248 * @brief Deletes a physical or logical disk device with identifier @a dev.
249 *
250 * Marks the disk device as deleted.  When a physical disk device is deleted,
251 * all corresponding logical disk devices will marked as deleted too.  Disks
252 * that are marked as deleted and have a usage counter of zero will be deleted.
253 * The corresponding device nodes will be removed from the file system.  In
254 * case of a physical disk deletion the IO control handler will be invoked with
255 * a RTEMS_BLKIO_DELETED request.  Disks that are still in use will be deleted
256 * upon release.
257 *
258 * @retval RTEMS_SUCCESSFUL Successful operation.
259 * @retval RTEMS_NOT_CONFIGURED Cannot lock disk device operation mutex.
260 * @retval RTEMS_INVALID_ID No disk for specified device identifier.
261 */
262rtems_status_code rtems_disk_delete(dev_t dev);
263
264/**
265 * @brief Returns the disk device descriptor for the device identifier @a dev.
266 *
267 * Increments usage counter by one.  You should release the disk device
268 * descriptor with rtems_disk_release().
269 *
270 * @return Pointer to the disk device descriptor or @c NULL if no corresponding
271 * disk exists.
272 */
273rtems_disk_device *rtems_disk_obtain(dev_t dev);
274
275/**
276 * @brief Releases the disk device descriptor @a dd.
277 *
278 * Decrements usage counter by one.
279 *
280 * @retval RTEMS_SUCCESSFUL Successful operation.
281 */
282rtems_status_code rtems_disk_release(rtems_disk_device *dd);
283
284/** @} */
285
286/**
287 * @name Disk Management
288 *
289 * @{
290 */
291
292/**
293 * @brief Initializes the disk device management.
294 *
295 * This functions returns successful if the disk device management is already
296 * initialized.  There is no protection against concurrent access.
297 *
298 * @retval RTEMS_SUCCESSFUL Successful initialization.
299 * @retval RTEMS_NO_MEMORY Not enough memory or no semaphore available.
300 * @retval RTEMS_UNSATISFIED Block device buffer initialization failed.
301 */
302rtems_status_code rtems_disk_io_initialize(void);
303
304/**
305 * @brief Releases all resources allocated for disk device management.
306 *
307 * There is no protection against concurrent access.  If parts of the system
308 * are still in use the behaviour is undefined.
309 *
310 * @retval RTEMS_SUCCESSFUL Successful operation.
311 */
312rtems_status_code rtems_disk_io_done(void);
313
314/** @} */
315
316/** @} */
317
318/**
319 * @brief Disk device iterator.
320 *
321 * Returns the next disk device descriptor with a device identifier larger than
322 * @a dev.  If there is no such device, @c NULL will be returned.  Use minus
323 * one to start the search.
324 *
325 * @code
326 * rtems_status_code sc = RTEMS_SUCCESSFUL;
327 * rtems_disk_device *dd = (dev_t) -1;
328 *
329 * while (sc == RTEMS_SUCCESSFUL && (dd = rtems_disk_next(dev)) != NULL) {
330 *   dev = rtems_disk_get_device_identifier(dd);
331 *   sc = rtems_disk_release(dd);
332 * }
333 * @endcode
334 */
335rtems_disk_device *rtems_disk_next(dev_t dev);
336
337#ifdef __cplusplus
338}
339#endif
340
341#endif
Note: See TracBrowser for help on using the repository browser.