File indexing completed on 2025-05-11 08:24:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifdef HAVE_CONFIG_H
0015 #include "config.h"
0016 #endif
0017
0018 #include <stdlib.h>
0019
0020 #include <rtems.h>
0021 #include <rtems/libio.h>
0022 #include <rtems/ramdisk.h>
0023
0024 rtems_device_driver
0025 ramdisk_initialize(
0026 rtems_device_major_number major RTEMS_UNUSED,
0027 rtems_device_minor_number minor RTEMS_UNUSED,
0028 void *arg RTEMS_UNUSED)
0029 {
0030 rtems_device_minor_number i;
0031 rtems_ramdisk_config *c = rtems_ramdisk_configuration;
0032 struct ramdisk *r;
0033 rtems_status_code rc;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 r = calloc(rtems_ramdisk_configuration_size, sizeof(struct ramdisk));
0044 r->trace = false;
0045 for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++)
0046 {
0047 char name [] = RAMDISK_DEVICE_BASE_NAME "a";
0048 name [sizeof(RAMDISK_DEVICE_BASE_NAME) - 1] += i;
0049 r->block_size = c->block_size;
0050 r->block_num = c->block_num;
0051 if (c->location == NULL)
0052 {
0053 r->malloced = true;
0054 r->area = malloc(r->block_size * r->block_num);
0055 if (r->area == NULL)
0056 {
0057 r->initialized = false;
0058 continue;
0059 }
0060 else
0061 {
0062 r->initialized = true;
0063 }
0064 }
0065 else
0066 {
0067 r->malloced = false;
0068 r->initialized = true;
0069 r->area = c->location;
0070 }
0071 rc = rtems_blkdev_create(name, c->block_size, c->block_num,
0072 ramdisk_ioctl, r);
0073 if (rc != RTEMS_SUCCESSFUL)
0074 {
0075 if (r->malloced)
0076 {
0077 free(r->area);
0078 }
0079 r->initialized = false;
0080 }
0081 }
0082 return RTEMS_SUCCESSFUL;
0083 }