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

4.104.11
Last change on this file since d8602eb was d8602eb, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on May 5, 2009 at 12:56:30 PM

Documentation

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/**
2 * @file
3 *
4 * Block device disk management.
5 */
6 
7/*
8 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
9 * Author: Victor V. Vengerov <vvv@oktet.ru>
10 *
11 * @(#) $Id$
12 */
13
14#ifndef _RTEMS_DISKDEVS_H
15#define _RTEMS_DISKDEVS_H
16
17#include <rtems.h>
18#include <rtems/libio.h>
19#include <stdlib.h>
20
21/**
22 * @ingroup rtems_bdbuf
23 *
24 * Buffer pool identifier.
25 */
26typedef int rtems_bdpool_id;
27
28#include <rtems/blkdev.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 * @defgroup rtems_disk Block Device Disk Management
36 *
37 * @ingroup rtems_libblock
38 *
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".
46 *
47 * @{
48 */
49
50/**
51 * Block device IO control handler type.
52 */
53typedef 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.
62 */
63typedef struct rtems_disk_device {
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;
126} rtems_disk_device;
127
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.
139 */
140rtems_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.
158 */
159rtems_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);
166
167/**
168 * Deletes a physical or logical disk device with identifier @a dev.
169 *
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.
174 */
175rtems_status_code rtems_disk_delete(dev_t dev);
176
177/**
178 * Returns the disk device descriptor for the device identifier @a dev.
179 *
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.
183 */
184rtems_disk_device *rtems_disk_obtain(dev_t dev);
185
186/**
187 * Releases the disk device description @a dd.
188 *
189 * Decrements usage counter by one.
190 */
191rtems_status_code rtems_disk_release(rtems_disk_device *dd);
192
193/**
194 * Disk device iterator.
195 *
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.
199 *
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
207 */
208rtems_disk_device *rtems_disk_next(dev_t dev);
209
210/**
211 * Initializes the disk device management.
212 *
213 * This functions returns successful if the disk device management is already
214 * initialized.  There is no protection against concurrent access.
215 */
216rtems_status_code rtems_disk_io_initialize(void);
217
218/**
219 * Releases all resources allocated for disk device management.
220 */
221rtems_status_code rtems_disk_io_done(void);
222
223/** @} */
224
225#ifdef __cplusplus
226}
227#endif
228
229#endif
Note: See TracBrowser for help on using the repository browser.