4.115
Line | |
---|
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 <stdlib.h> |
---|
28 | |
---|
29 | #include <rtems.h> |
---|
30 | #include <rtems/ramdisk.h> |
---|
31 | |
---|
32 | ramdisk *ramdisk_allocate( |
---|
33 | void *area_begin, |
---|
34 | uint32_t block_size, |
---|
35 | rtems_blkdev_bnum block_count, |
---|
36 | bool trace |
---|
37 | ) |
---|
38 | { |
---|
39 | struct ramdisk *rd = malloc(sizeof(struct ramdisk)); |
---|
40 | |
---|
41 | if (rd == NULL) { |
---|
42 | return NULL; |
---|
43 | } |
---|
44 | |
---|
45 | if (area_begin == NULL) { |
---|
46 | area_begin = calloc(block_count, block_size); |
---|
47 | if (area_begin == NULL) { |
---|
48 | free(rd); |
---|
49 | |
---|
50 | return NULL; |
---|
51 | } |
---|
52 | rd->malloced = true; |
---|
53 | } else { |
---|
54 | rd->malloced = false; |
---|
55 | } |
---|
56 | rd->block_size = block_size; |
---|
57 | rd->block_num = block_count; |
---|
58 | rd->area = area_begin; |
---|
59 | rd->trace = trace; |
---|
60 | rd->initialized = true; |
---|
61 | |
---|
62 | return rd; |
---|
63 | } |
---|
64 | |
---|
65 | void ramdisk_free(ramdisk *rd) |
---|
66 | { |
---|
67 | if (rd != NULL) { |
---|
68 | if (rd->malloced) { |
---|
69 | free(rd->area); |
---|
70 | } |
---|
71 | free(rd); |
---|
72 | } |
---|
73 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.