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 | #include <rtems/blkdev.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @defgroup rtems_disk Block Device Disk Management |
---|
31 | * |
---|
32 | * @ingroup rtems_libblock |
---|
33 | * |
---|
34 | * 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 | * Block device IO control handler type. |
---|
47 | */ |
---|
48 | typedef int (*rtems_block_device_ioctl)( dev_t dev, uint32_t req, void *argp); |
---|
49 | |
---|
50 | /** |
---|
51 | * Description of a disk device (logical and physical disks). |
---|
52 | * |
---|
53 | * An array of pointer tables to rtems_disk_device structures is maintained. |
---|
54 | * The first table will be indexed by the major number and the second table |
---|
55 | * will be indexed by the minor number. This allows quick lookup using a data |
---|
56 | * structure of moderated size. |
---|
57 | */ |
---|
58 | typedef struct rtems_disk_device { |
---|
59 | /** |
---|
60 | * Device identifier (concatenation of major and minor number). |
---|
61 | */ |
---|
62 | dev_t dev; |
---|
63 | |
---|
64 | /** |
---|
65 | * Physical device identifier (equals the @c dev entry if it specifies a |
---|
66 | * physical device). |
---|
67 | */ |
---|
68 | struct rtems_disk_device *phys_dev; |
---|
69 | |
---|
70 | /** |
---|
71 | * Driver capabilities. |
---|
72 | */ |
---|
73 | uint32_t capabilities; |
---|
74 | |
---|
75 | /** |
---|
76 | * Disk device name. |
---|
77 | */ |
---|
78 | char *name; |
---|
79 | |
---|
80 | /** |
---|
81 | * Usage counter. |
---|
82 | * |
---|
83 | * Devices cannot be removed if they are in use. |
---|
84 | */ |
---|
85 | unsigned uses; |
---|
86 | |
---|
87 | /** |
---|
88 | * Start block number. |
---|
89 | * |
---|
90 | * Equals zero for physical devices. It is a block offset to the related |
---|
91 | * physical device for logical device. |
---|
92 | */ |
---|
93 | rtems_blkdev_bnum start; |
---|
94 | |
---|
95 | /** |
---|
96 | * Size of the physical or logical disk in blocks. |
---|
97 | */ |
---|
98 | rtems_blkdev_bnum size; |
---|
99 | |
---|
100 | /** |
---|
101 | * Device block size in bytes. |
---|
102 | * |
---|
103 | * This is the minimum transfer unit. It can be any size. |
---|
104 | */ |
---|
105 | uint32_t block_size; |
---|
106 | |
---|
107 | /** |
---|
108 | * Device media block size in bytes. |
---|
109 | * |
---|
110 | * This is the media transfer unit the hardware defaults to. |
---|
111 | */ |
---|
112 | uint32_t media_block_size; |
---|
113 | |
---|
114 | /** |
---|
115 | * IO control handler for this disk. |
---|
116 | */ |
---|
117 | rtems_block_device_ioctl ioctl; |
---|
118 | } rtems_disk_device; |
---|
119 | |
---|
120 | /** |
---|
121 | * Creates a physical disk with device identifier @a dev. |
---|
122 | * |
---|
123 | * The block size @a block_size must be a power of two. The disk size @a |
---|
124 | * disk_size is the number of blocks provided by this disk. The block index |
---|
125 | * starts with zero. The associated disk device driver will be invoked via the |
---|
126 | * IO control handler @a handler. A device node will be registered in the file |
---|
127 | * system with absolute path @a name. This function is usually invoked from a |
---|
128 | * block device driver during initialization when a physical device is detected |
---|
129 | * in the system. The device driver provides an IO control handler to allow |
---|
130 | * block device operations. |
---|
131 | */ |
---|
132 | rtems_status_code rtems_disk_create_phys( |
---|
133 | dev_t dev, |
---|
134 | uint32_t block_size, |
---|
135 | rtems_blkdev_bnum disk_size, |
---|
136 | rtems_block_device_ioctl handler, |
---|
137 | const char *name |
---|
138 | ); |
---|
139 | |
---|
140 | /** |
---|
141 | * Creates a logical disk with device identifier @a dev. |
---|
142 | * |
---|
143 | * A logical disk manages a subset of consecutive blocks containd in the |
---|
144 | * physical disk with identifier @a phys. The start block index of the logical |
---|
145 | * disk device is @a start. The block number of the logcal disk will be @a |
---|
146 | * size. The blocks must be within the range of blocks managed by the |
---|
147 | * associated physical disk device. A device node will be registered in the |
---|
148 | * file system with absolute path @a name. The block size and IO control |
---|
149 | * handler are inherited by the physical disk. |
---|
150 | */ |
---|
151 | rtems_status_code rtems_disk_create_log( |
---|
152 | dev_t dev, |
---|
153 | dev_t phys, |
---|
154 | rtems_blkdev_bnum start, |
---|
155 | rtems_blkdev_bnum size, |
---|
156 | const char *name |
---|
157 | ); |
---|
158 | |
---|
159 | /** |
---|
160 | * Deletes a physical or logical disk device with identifier @a dev. |
---|
161 | * |
---|
162 | * Disk devices may be deleted if there usage counter (and the usage counters |
---|
163 | * of all contained logical disks devices) equals zero. When a physical disk |
---|
164 | * device is deleted, all logical disk devices will deleted too. The |
---|
165 | * corresponding device nodes will be removed from the file system. |
---|
166 | */ |
---|
167 | rtems_status_code rtems_disk_delete(dev_t dev); |
---|
168 | |
---|
169 | /** |
---|
170 | * Returns the disk device descriptor for the device identifier @a dev. |
---|
171 | * |
---|
172 | * Increments usage counter by one. You should release the disk device |
---|
173 | * descriptor with rtems_disk_release(). Returns @c NULL if no corresponding |
---|
174 | * disk exists. |
---|
175 | */ |
---|
176 | rtems_disk_device *rtems_disk_obtain(dev_t dev); |
---|
177 | |
---|
178 | /** |
---|
179 | * Releases the disk device description @a dd. |
---|
180 | * |
---|
181 | * Decrements usage counter by one. |
---|
182 | */ |
---|
183 | rtems_status_code rtems_disk_release(rtems_disk_device *dd); |
---|
184 | |
---|
185 | /** |
---|
186 | * Disk device iterator. |
---|
187 | * |
---|
188 | * Returns the next disk device descriptor with a device identifier larger than |
---|
189 | * @a dev. If there is no such device, @c NULL will be returned. Use minus |
---|
190 | * one to start the search. |
---|
191 | * |
---|
192 | * @code |
---|
193 | * rtems_disk_device *dd = rtems_disk_next((dev_t) -1); |
---|
194 | * |
---|
195 | * while (dd != NULL) { |
---|
196 | * dd = rtems_disk_next(dd->dev); |
---|
197 | * } |
---|
198 | * @endcode |
---|
199 | */ |
---|
200 | rtems_disk_device *rtems_disk_next(dev_t dev); |
---|
201 | |
---|
202 | /** |
---|
203 | * Initializes the disk device management. |
---|
204 | * |
---|
205 | * This functions returns successful if the disk device management is already |
---|
206 | * initialized. There is no protection against concurrent access. |
---|
207 | */ |
---|
208 | rtems_status_code rtems_disk_io_initialize(void); |
---|
209 | |
---|
210 | /** |
---|
211 | * Releases all resources allocated for disk device management. |
---|
212 | */ |
---|
213 | rtems_status_code rtems_disk_io_done(void); |
---|
214 | |
---|
215 | /** @} */ |
---|
216 | |
---|
217 | #ifdef __cplusplus |
---|
218 | } |
---|
219 | #endif |
---|
220 | |
---|
221 | #endif |
---|