source: rtems/cpukit/include/rtems/ramdisk.h @ 878487b0

5
Last change on this file since 878487b0 was 24b94c4, checked in by Sebastian Huber <sebastian.huber@…>, on 07/30/18 at 04:39:09

ramdisk: Use rtems_blkdev_create()

Update #3358.

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