1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup rtems_ramdisk |
---|
5 | * |
---|
6 | * @brief RAM disk block device implementation. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.com/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <rtems.h> |
---|
28 | #include <rtems/ramdisk.h> |
---|
29 | |
---|
30 | const rtems_driver_address_table ramdisk_ops = { |
---|
31 | .initialization_entry = NULL, |
---|
32 | RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES |
---|
33 | }; |
---|
34 | |
---|
35 | rtems_status_code ramdisk_register( |
---|
36 | uint32_t block_size, |
---|
37 | rtems_blkdev_bnum block_count, |
---|
38 | bool trace, |
---|
39 | const char *disk, |
---|
40 | dev_t *dev_ptr |
---|
41 | ) |
---|
42 | { |
---|
43 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
44 | rtems_device_major_number major = 0; |
---|
45 | ramdisk *rd = NULL; |
---|
46 | dev_t dev = 0; |
---|
47 | |
---|
48 | sc = rtems_io_register_driver(0, &ramdisk_ops, &major); |
---|
49 | if (sc != RTEMS_SUCCESSFUL) { |
---|
50 | return RTEMS_UNSATISFIED; |
---|
51 | } |
---|
52 | |
---|
53 | rd = ramdisk_allocate(NULL, block_size, block_count, trace); |
---|
54 | if (rd == NULL) { |
---|
55 | rtems_io_unregister_driver(major); |
---|
56 | |
---|
57 | return RTEMS_UNSATISFIED; |
---|
58 | } |
---|
59 | |
---|
60 | dev = rtems_filesystem_make_dev_t(major, 0); |
---|
61 | |
---|
62 | sc = rtems_disk_create_phys( |
---|
63 | dev, |
---|
64 | block_size, |
---|
65 | block_count, |
---|
66 | ramdisk_ioctl, |
---|
67 | rd, |
---|
68 | disk |
---|
69 | ); |
---|
70 | if (sc != RTEMS_SUCCESSFUL) { |
---|
71 | ramdisk_free(rd); |
---|
72 | rtems_io_unregister_driver(major); |
---|
73 | |
---|
74 | return RTEMS_UNSATISFIED; |
---|
75 | } |
---|
76 | |
---|
77 | *dev_ptr = dev; |
---|
78 | |
---|
79 | return RTEMS_SUCCESSFUL; |
---|
80 | } |
---|