source: rtems/cpukit/libblock/src/ramdisk-config.c @ 121dd881

4.115
Last change on this file since 121dd881 was 13bcb3e, checked in by Sebastian Huber <sebastian.huber@…>, on 03/22/13 at 14:10:37

ramdisk: Fix device name generation

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_ramdisk
5 *
6 * @brief RAM disk block device implementation.
7 */
8
9/*
10 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
11 * Author: Victor V. Vengerov <vvv@oktet.ru>
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <stdlib.h>
19
20#include <rtems.h>
21#include <rtems/libio.h>
22#include <rtems/ramdisk.h>
23
24rtems_device_driver
25ramdisk_initialize(
26    rtems_device_major_number major,
27    rtems_device_minor_number minor __attribute__((unused)),
28    void *arg __attribute__((unused)))
29{
30    rtems_device_minor_number i;
31    rtems_ramdisk_config *c = rtems_ramdisk_configuration;
32    struct ramdisk *r;
33    rtems_status_code rc;
34
35    rc = rtems_disk_io_initialize();
36    if (rc != RTEMS_SUCCESSFUL)
37        return rc;
38
39    /*
40     * Coverity Id 27 notes that this calloc() is a resource leak.
41     *
42     * This is allocating memory for a RAM disk which will persist for
43     * the life of the system. RTEMS has no "de-initialize" driver call
44     * so there is no corresponding free(r).  Coverity is correct that
45     * it is never freed but this is not a problem.
46     */
47    r = calloc(rtems_ramdisk_configuration_size, sizeof(struct ramdisk));
48    r->trace = false;
49    for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++)
50    {
51        dev_t dev = rtems_filesystem_make_dev_t(major, i);
52        char name [] = RAMDISK_DEVICE_BASE_NAME "a";
53        name [sizeof(RAMDISK_DEVICE_BASE_NAME) - 1] += i;
54        r->block_size = c->block_size;
55        r->block_num = c->block_num;
56        if (c->location == NULL)
57        {
58            r->malloced = true;
59            r->area = malloc(r->block_size * r->block_num);
60            if (r->area == NULL) /* No enough memory for this disk */
61            {
62                r->initialized = false;
63                continue;
64            }
65            else
66            {
67                r->initialized = true;
68            }
69        }
70        else
71        {
72            r->malloced = false;
73            r->initialized = true;
74            r->area = c->location;
75        }
76        rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
77                                    ramdisk_ioctl, r, name);
78        if (rc != RTEMS_SUCCESSFUL)
79        {
80            if (r->malloced)
81            {
82                free(r->area);
83            }
84            r->initialized = false;
85        }
86    }
87    return RTEMS_SUCCESSFUL;
88}
Note: See TracBrowser for help on using the repository browser.