source: rtems/cpukit/libblock/include/rtems/diskdevs.h @ 57aa979

4.104.11
Last change on this file since 57aa979 was 57aa979, checked in by Chris Johns <chrisj@…>, on Apr 29, 2009 at 8:51:07 AM

2009-04-29 Sebastian Huber <sebastian.huber@…>

  • sapi/include/confdefs.h, libblock/include/rtems/bdbuf.h: Changed type of rtems_bdbuf_pool_configuration_size to size_t.
  • libblock/include/rtems/bdbuf.h, libblock/include/rtems/blkdev.h, libblock/include/rtems/diskdevs.h, libblock/src/bdbuf.c, libblock/src/blkdev.c, libblock/src/diskdevs.c: Buffer pool allocation is now cache aligned. The cache functions are currently not available on all platforms so the cache line size is fixed to 32 bytes for now. Changed various integer types which refer to block sizes, numbers and indexes. Fixed logical block indexes in buffer get and read function. It is now possible to delete logical disks. Modified 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.  The disk devices are
40 * accessed via the RTEMS block device library.  A disk is a set of blocks
41 * which are identified by a consecutive set of non-negative integers starting
42 * at zero.  There are also logical disks which contain a subset of consecutive
43 * disk blocks.  The logical disks are used to represent the partitions of a
44 * disk.
45 *
46 * @{
47 */
48
49/**
50 * Block device IO control handler type.
51 */
52typedef int (*rtems_block_device_ioctl)( dev_t dev, uint32_t req, void *argp);
53
54/**
55 * Description of a disk device (logical and physical disks).
56 *
57 * An array of pointer tables to rtems_disk_device structures is maintained.
58 * The first table will be indexed by the major number and the second table
59 * will be indexed by the minor number.  This allows quick lookup using a data
60 * structure of moderated size.
61 */
62typedef struct rtems_disk_device {
63  /**
64   * Device identifier (concatenation of major and minor number).
65   */
66  dev_t dev;
67
68  /**
69   * Physical device identifier (equals the @c dev entry if it specifies a
70   * physical device).
71   */
72  struct rtems_disk_device *phys_dev;
73
74  /**
75   * Driver capabilities.
76   */
77  uint32_t capabilities;
78
79  /**
80   * Disk device name.
81   */
82  char *name;
83
84  /**
85   * Usage counter.
86   *
87   * Devices cannot be removed if they are in use.
88   */
89  unsigned uses;
90
91  /**
92   * Start block number.
93   *
94   * Equals zero for physical devices.  It is a block offset to the related
95   * physical device for logical device.
96   */
97  rtems_blkdev_bnum start;
98
99  /**
100   * Size of the physical or logical disk in blocks.
101   */
102  rtems_blkdev_bnum size;
103
104  /**
105   * Device block size in bytes.
106   *
107   * This is the minimum transfer unit and must be power of two.
108   */
109  uint32_t block_size;
110
111  /**
112   * Binary logarithm of the block size.
113   */
114  uint32_t block_size_log2;
115
116  /**
117   * Buffer pool assigned to this disk.
118   */
119  rtems_bdpool_id pool;
120
121  /**
122   * IO control handler for this disk.
123   */
124  rtems_block_device_ioctl ioctl;
125} rtems_disk_device;
126
127/**
128 * Creates a physical disk with device identifier @a dev.
129 *
130 * The block size @a block_size must be a power of two.  The disk size @a
131 * disk_size is the number of blocks provided by this disk.  The block index
132 * starts with zero.  The associated disk device driver will be invoked via the
133 * IO control handler @a handler.  A device node will be registered in the file
134 * system with absolute path @a name.  This function is usually invoked from a
135 * block device driver during initialization when a physical device is detected
136 * in the system.  The device driver provides an IO control handler to allow
137 * block device operations.
138 */
139rtems_status_code rtems_disk_create_phys(
140  dev_t dev,
141  uint32_t block_size,
142  rtems_blkdev_bnum disk_size,
143  rtems_block_device_ioctl handler,
144  const char *name
145);
146
147/**
148 * Creates a logical disk with device identifier @a dev.
149 *
150 * A logical disk manages a subset of consecutive blocks containd in the
151 * physical disk with identifier @a phys.  The start block index of the logical
152 * disk device is @a start.  The block number of the logcal disk will be @a
153 * size.  The blocks must be within the range of blocks managed by the
154 * associated physical disk device.  A device node will be registered in the
155 * file system with absolute path @a name.  The block size and IO control
156 * handler are inherited by the physical disk.
157 */
158rtems_status_code rtems_disk_create_log(
159  dev_t dev,
160  dev_t phys,
161  rtems_blkdev_bnum start,
162  rtems_blkdev_bnum size,
163  const char *name
164);
165
166/**
167 * Deletes a physical or logical disk device with identifier @a dev.
168 *
169 * Disk devices may be deleted if there usage counter (and the usage counters
170 * of all contained logical disks devices) equals zero.  When a physical disk
171 * device is deleted, all logical disk devices will deleted too.  The
172 * corresponding device nodes will be removed from the file system.
173 */
174rtems_status_code rtems_disk_delete(dev_t dev);
175
176/**
177 * Returns the disk device descriptor for the device identifier @a dev.
178 *
179 * Increments usage counter by one.  You should release the disk device
180 * descriptor with rtems_disk_release().  Returns @c NULL if no corresponding
181 * disk exists.
182 */
183rtems_disk_device *rtems_disk_obtain(dev_t dev);
184
185/**
186 * Releases the disk device description @a dd.
187 *
188 * Decrements usage counter by one.
189 */
190rtems_status_code rtems_disk_release(rtems_disk_device *dd);
191
192/**
193 * Disk device iterator.
194 *
195 * Returns the next disk device descriptor with a device identifier larger than
196 * @a dev.  If there is no such device, @c NULL will be returned.  Use minus
197 * one to start the search.
198 *
199 * @code
200 * rtems_disk_device *dd = rtems_disk_next((dev_t) -1);
201 *
202 * while (dd != NULL) {
203 *   dd = rtems_disk_next(dd->dev);
204 * }
205 * @endcode
206 */
207rtems_disk_device *rtems_disk_next(dev_t dev);
208
209/**
210 * Initializes the disk device management.
211 *
212 * This functions returns successful if the disk device management is already
213 * initialized.  There is no protection against concurrent access.
214 */
215rtems_status_code rtems_disk_io_initialize(void);
216
217/**
218 * Releases all resources allocated for disk device management.
219 */
220rtems_status_code rtems_disk_io_done(void);
221
222/** @} */
223
224#ifdef __cplusplus
225}
226#endif
227
228#endif
Note: See TracBrowser for help on using the repository browser.