source: rtems/cpukit/libblock/include/rtems/ramdisk.h @ 1560d12

4.104.11
Last change on this file since 1560d12 was 1560d12, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Oct 16, 2009 at 8:44:51 AM

restructuring of ramdisk code

  • Property mode set to 100644
File size: 4.1 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
78int ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
79
80/**
81 * @brief RAM disk driver initialization entry point.
82 */
83rtems_device_driver ramdisk_initialize(
84 rtems_device_major_number major,
85 rtems_device_minor_number minor,
86 void *arg
87);
88
89/**
90 * RAM disk driver table entry.
91 */
92#define RAMDISK_DRIVER_TABLE_ENTRY \
93  { \
94    .initialization_entry = ramdisk_initialize, \
95    RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \
96  }
97
98#define RAMDISK_DEVICE_BASE_NAME "/dev/rd"
99
100/** @} */
101
102/**
103 * @name Runtime Configuration
104 *
105 * @{
106 */
107
108/**
109 * @brief RAM disk descriptor.
110 */
111typedef struct ramdisk {
112  /**
113   * @brief RAM disk block size, the media size.
114   */
115  uint32_t block_size;
116
117  /**
118   * @brief Number of blocks on this RAM disk.
119   */
120  rtems_blkdev_bnum block_num;
121
122  /**
123   * @brief RAM disk memory area.
124   */
125  void *area;
126
127  /**
128   * @brief RAM disk is initialized.
129   */
130  bool initialized;
131
132  /**
133   * @brief Indicates if memory is allocated by malloc() for this RAM disk.
134   */
135  bool malloced;
136
137  /**
138   * @brief Trace enable.
139   */
140  bool trace;
141} ramdisk;
142
143extern const rtems_driver_address_table ramdisk_ops;
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 * @code
157 * rtems_status_code create_ramdisk(
158 *   const char *disk_name_path,
159 *   uint32_t block_size,
160 *   rtems_blkdev_bnum block_count
161 * )
162 * {
163 *   rtems_status_code sc = RTEMS_SUCCESSFUL;
164 *   rtems_device_major_number major = 0;
165 *   ramdisk *rd = NULL;
166 *   dev_t dev = 0;
167 *
168 *   sc = rtems_io_register_driver(0, &ramdisk_ops, &major);
169 *   if (sc != RTEMS_SUCCESSFUL) {
170 *     return RTEMS_UNSATISFIED;
171 *   }
172 *
173 *   rd = ramdisk_allocate(NULL, block_size, block_count, false);
174 *   if (rd == NULL) {
175 *     rtems_io_unregister_driver(major);
176 *
177 *     return RTEMS_UNSATISFIED;
178 *   }
179 *
180 *   dev = rtems_filesystem_make_dev_t(major, 0);
181 *
182 *   sc = rtems_disk_create_phys(
183 *     dev,
184 *     block_size,
185 *     block_count,
186 *     ramdisk_ioctl,
187 *     rd,
188 *     disk_name_path
189 *   );
190 *   if (sc != RTEMS_SUCCESSFUL) {
191 *     ramdisk_free(rd);
192 *     rtems_io_unregister_driver(major);
193 *
194 *     return RTEMS_UNSATISFIED;
195 *   }
196 *
197 *   return RTEMS_SUCCESSFUL;
198 * }
199 * @endcode
200 */
201ramdisk *ramdisk_allocate(
202  void *area_begin,
203  uint32_t block_size,
204  rtems_blkdev_bnum block_count,
205  bool trace
206);
207
208void ramdisk_free(ramdisk *rd);
209
210/** @} */
211
212/** @} */
213
214#ifdef __cplusplus
215}
216#endif
217
218#endif
Note: See TracBrowser for help on using the repository browser.