source: rtems/cpukit/libblock/include/rtems/ramdisk.h @ 33c3b54d

4.104.115
Last change on this file since 33c3b54d was 33c3b54d, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 11:57:23

Whitespace removal.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_ramdisk
5 *
6 * @brief RAM disk block device 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_RAMDISK_H
17#define _RTEMS_RAMDISK_H
18
19
20#include <rtems.h>
21#include <rtems/blkdev.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/**
28 * @defgroup rtems_ramdisk RAM Disk Device
29 *
30 * @ingroup rtems_blkdev
31 *
32 * @{
33 */
34
35/**
36 * @name Static Configuration
37 *
38 * @{
39 */
40
41/**
42 * @brief RAM disk configuration table entry.
43 */
44typedef struct rtems_ramdisk_config {
45  /**
46   * @brief RAM disk block size.
47   */
48  uint32_t block_size;
49
50  /**
51   * @brief Number of blocks on this RAM disk.
52   */
53  rtems_blkdev_bnum block_num;
54
55  /**
56   * @brief RAM disk location or @c NULL if RAM disk memory should be allocated
57   * dynamically.
58   */
59  void *location;
60} rtems_ramdisk_config;
61
62/**
63 * @brief External reference to the RAM disk configuration table describing
64 * each RAM disk in the system.
65 *
66 * The configuration table is provided by the application.
67 */
68extern rtems_ramdisk_config rtems_ramdisk_configuration [];
69
70/**
71 * @brief External reference the size of the RAM disk configuration table @ref
72 * rtems_ramdisk_configuration.
73 *
74 * The configuration table size is provided by the application.
75 */
76extern size_t rtems_ramdisk_configuration_size;
77
78/**
79 * @brief RAM disk driver initialization entry point.
80 */
81rtems_device_driver ramdisk_initialize(
82 rtems_device_major_number major,
83 rtems_device_minor_number minor,
84 void *arg
85);
86
87/**
88 * RAM disk driver table entry.
89 */
90#define RAMDISK_DRIVER_TABLE_ENTRY \
91  { \
92    .initialization_entry = ramdisk_initialize, \
93    RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \
94  }
95
96#define RAMDISK_DEVICE_BASE_NAME "/dev/rd"
97
98/** @} */
99
100/**
101 * @name Runtime Configuration
102 *
103 * @{
104 */
105
106/**
107 * @brief RAM disk descriptor.
108 */
109typedef struct ramdisk {
110  /**
111   * @brief RAM disk block size, the media size.
112   */
113  uint32_t block_size;
114
115  /**
116   * @brief Number of blocks on this RAM disk.
117   */
118  rtems_blkdev_bnum block_num;
119
120  /**
121   * @brief RAM disk memory area.
122   */
123  void *area;
124
125  /**
126   * @brief RAM disk is initialized.
127   */
128  bool initialized;
129
130  /**
131   * @brief Indicates if memory is allocated by malloc() for this RAM disk.
132   */
133  bool malloced;
134
135  /**
136   * @brief Trace enable.
137   */
138  bool trace;
139} ramdisk;
140
141extern const rtems_driver_address_table ramdisk_ops;
142
143int ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
144
145/**
146 * @brief Allocates and initializes a RAM disk descriptor.
147 *
148 * The block size will be @a block_size.  The block count will be @a
149 * block_count.  The disk storage area begins at @a area_begin.  If @a
150 * area_begin is @c NULL, the memory will be allocated and zeroed.  Sets the
151 * trace enable to @a trace.
152 *
153 * @return Pointer to allocated and initialized ramdisk structure, or @c NULL
154 * if no memory is available.
155 *
156 * @note
157 * Runtime configuration example:
158 * @code
159 * #include <rtems.h>
160 * #include <rtems/libio.h>
161 * #include <rtems/ramdisk.h>
162 *
163 * rtems_status_code create_ramdisk(
164 *   const char *disk_name_path,
165 *   uint32_t block_size,
166 *   rtems_blkdev_bnum block_count
167 * )
168 * {
169 *   rtems_status_code sc = RTEMS_SUCCESSFUL;
170 *   rtems_device_major_number major = 0;
171 *   ramdisk *rd = NULL;
172 *   dev_t dev = 0;
173 *
174 *   sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
175 *   if (sc != RTEMS_SUCCESSFUL) {
176 *     return RTEMS_UNSATISFIED;
177 *   }
178 *
179 *   rd = ramdisk_allocate(NULL, block_size, block_count, false);
180 *   if (rd == NULL) {
181 *     rtems_io_unregister_driver(major);
182 *
183 *     return RTEMS_UNSATISFIED;
184 *   }
185 *
186 *   dev = rtems_filesystem_make_dev_t(major, 0);
187 *
188 *   sc = rtems_disk_create_phys(
189 *     dev,
190 *     block_size,
191 *     block_count,
192 *     ramdisk_ioctl,
193 *     rd,
194 *     disk_name_path
195 *   );
196 *   if (sc != RTEMS_SUCCESSFUL) {
197 *     ramdisk_free(rd);
198 *     rtems_io_unregister_driver(major);
199 *
200 *     return RTEMS_UNSATISFIED;
201 *   }
202 *
203 *   return RTEMS_SUCCESSFUL;
204 * }
205 * @endcode
206 */
207ramdisk *ramdisk_allocate(
208  void *area_begin,
209  uint32_t block_size,
210  rtems_blkdev_bnum block_count,
211  bool trace
212);
213
214void ramdisk_free(ramdisk *rd);
215
216/**
217 * @brief Allocates, initializes and registers a RAM disk.
218 *
219 * The block size will be @a block_size.  The block count will be @a
220 * block_count.  The disk storage will be allocated.  Sets the trace enable to
221 * @a trace.  Registers a device node with disk name path @a disk.  The
222 * registered device number will be returned in @a dev.
223 *
224 * @retval RTEMS_SUCCESSFUL Successful operation.
225 * @retval RTEMS_UNSATISFIED Something is wrong.
226 */
227rtems_status_code ramdisk_register(
228  uint32_t block_size,
229  rtems_blkdev_bnum block_count,
230  bool trace,
231  const char *disk,
232  dev_t *dev
233);
234
235/** @} */
236
237/** @} */
238
239#ifdef __cplusplus
240}
241#endif
242
243#endif
Note: See TracBrowser for help on using the repository browser.