[1560d12] | 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 | * @(#) $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include <stdlib.h> |
---|
| 17 | |
---|
| 18 | #include <rtems.h> |
---|
| 19 | #include <rtems/libio.h> |
---|
| 20 | #include <rtems/ramdisk.h> |
---|
| 21 | |
---|
| 22 | rtems_device_driver |
---|
| 23 | ramdisk_initialize( |
---|
| 24 | rtems_device_major_number major, |
---|
| 25 | rtems_device_minor_number minor __attribute__((unused)), |
---|
| 26 | void *arg __attribute__((unused))) |
---|
| 27 | { |
---|
| 28 | rtems_device_minor_number i; |
---|
| 29 | rtems_ramdisk_config *c = rtems_ramdisk_configuration; |
---|
| 30 | struct ramdisk *r; |
---|
| 31 | rtems_status_code rc; |
---|
| 32 | |
---|
| 33 | rc = rtems_disk_io_initialize(); |
---|
| 34 | if (rc != RTEMS_SUCCESSFUL) |
---|
| 35 | return rc; |
---|
| 36 | |
---|
| 37 | r = calloc(rtems_ramdisk_configuration_size, sizeof(struct ramdisk)); |
---|
| 38 | r->trace = false; |
---|
| 39 | for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++) |
---|
| 40 | { |
---|
| 41 | dev_t dev = rtems_filesystem_make_dev_t(major, i); |
---|
| 42 | char name [] = RAMDISK_DEVICE_BASE_NAME "a"; |
---|
| 43 | name [sizeof(RAMDISK_DEVICE_BASE_NAME)] += i; |
---|
| 44 | r->block_size = c->block_size; |
---|
| 45 | r->block_num = c->block_num; |
---|
| 46 | if (c->location == NULL) |
---|
| 47 | { |
---|
| 48 | r->malloced = true; |
---|
| 49 | r->area = malloc(r->block_size * r->block_num); |
---|
| 50 | if (r->area == NULL) /* No enough memory for this disk */ |
---|
| 51 | { |
---|
| 52 | r->initialized = false; |
---|
| 53 | continue; |
---|
| 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | r->initialized = true; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | else |
---|
| 61 | { |
---|
| 62 | r->malloced = false; |
---|
| 63 | r->initialized = true; |
---|
| 64 | r->area = c->location; |
---|
| 65 | } |
---|
| 66 | rc = rtems_disk_create_phys(dev, c->block_size, c->block_num, |
---|
| 67 | ramdisk_ioctl, r, name); |
---|
| 68 | if (rc != RTEMS_SUCCESSFUL) |
---|
| 69 | { |
---|
| 70 | if (r->malloced) |
---|
| 71 | { |
---|
| 72 | free(r->area); |
---|
| 73 | } |
---|
| 74 | r->initialized = false; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | return RTEMS_SUCCESSFUL; |
---|
| 78 | } |
---|