Changeset 0fe7133 in rtems


Ignore:
Timestamp:
Jul 31, 2018, 2:01:17 PM (16 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1dec54f9
Parents:
16f3f10
git-author:
Sebastian Huber <sebastian.huber@…> (07/31/18 14:01:17)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/07/18 05:17:17)
Message:

flashdisk: Use rtems_blkdev_create()

Update #3358.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/src/flashdisk.c

    r16f3f10 r0fe7133  
    4242#include <stdio.h>
    4343#include <string.h>
     44#include <unistd.h>
    4445#include <inttypes.h>
    4546
    4647#include <rtems/blkdev.h>
    47 #include <rtems/diskdevs.h>
    4848#include <rtems/flashdisk.h>
    4949#include <rtems/thread.h>
     
    205205  uint32_t starvations;                    /**< Erased blocks starvations counter. */
    206206} rtems_flashdisk;
    207 
    208 /**
    209  * The array of flash disks we support.
    210  */
    211 static rtems_flashdisk* rtems_flashdisks;
    212 
    213 /**
    214  * The number of flash disks we have.
    215  */
    216 static uint32_t rtems_flashdisk_count;
    217207
    218208/**
     
    23752365rtems_fdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
    23762366{
    2377   dev_t                     dev = rtems_disk_get_device_identifier (dd);
    2378   rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
    2379   rtems_blkdev_request*     r = argp;
     2367  rtems_flashdisk*      fd = rtems_disk_get_driver_data (dd);
     2368  rtems_blkdev_request* r = argp;
    23802369
    23812370  errno = 0;
    23822371
    2383   rtems_mutex_lock (&rtems_flashdisks[minor].lock);
     2372  rtems_mutex_lock (&fd->lock);
    23842373
    23852374  switch (req)
    23862375  {
    23872376    case RTEMS_BLKIO_REQUEST:
    2388       if ((minor >= rtems_flashdisk_count) ||
    2389           (rtems_flashdisks[minor].device_count == 0))
     2377      if (fd->device_count == 0)
    23902378      {
    23912379        errno = ENODEV;
     
    23962384        {
    23972385          case RTEMS_BLKDEV_REQ_READ:
    2398             errno = rtems_fdisk_read (&rtems_flashdisks[minor], r);
     2386            errno = rtems_fdisk_read (fd, r);
    23992387            break;
    24002388
    24012389          case RTEMS_BLKDEV_REQ_WRITE:
    2402             errno = rtems_fdisk_write (&rtems_flashdisks[minor], r);
     2390            errno = rtems_fdisk_write (fd, r);
    24032391            break;
    24042392
     
    24112399
    24122400    case RTEMS_FDISK_IOCTL_ERASE_DISK:
    2413       errno = rtems_fdisk_erase_disk (&rtems_flashdisks[minor]);
     2401      errno = rtems_fdisk_erase_disk (fd);
    24142402      break;
    24152403
    24162404    case RTEMS_FDISK_IOCTL_COMPACT:
    2417       errno = rtems_fdisk_compact (&rtems_flashdisks[minor]);
     2405      errno = rtems_fdisk_compact (fd);
    24182406      break;
    24192407
    24202408    case RTEMS_FDISK_IOCTL_ERASE_USED:
    2421       errno = rtems_fdisk_erase_used (&rtems_flashdisks[minor]);
     2409      errno = rtems_fdisk_erase_used (fd);
    24222410      break;
    24232411
    24242412    case RTEMS_FDISK_IOCTL_MONITORING:
    2425       errno = rtems_fdisk_monitoring_data (&rtems_flashdisks[minor],
     2413      errno = rtems_fdisk_monitoring_data (fd,
    24262414                                           (rtems_fdisk_monitor_data*) argp);
    24272415      break;
    24282416
    24292417    case RTEMS_FDISK_IOCTL_INFO_LEVEL:
    2430       rtems_flashdisks[minor].info_level = (uintptr_t) argp;
     2418      fd->info_level = (uintptr_t) argp;
    24312419      break;
    24322420
    24332421    case RTEMS_FDISK_IOCTL_PRINT_STATUS:
    2434       errno = rtems_fdisk_print_status (&rtems_flashdisks[minor]);
     2422      errno = rtems_fdisk_print_status (fd);
    24352423      break;
    24362424
     
    24402428  }
    24412429
    2442   rtems_mutex_unlock (&rtems_flashdisks[minor].lock);
     2430  rtems_mutex_unlock (&fd->lock);
    24432431
    24442432  return errno == 0 ? 0 : -1;
     
    24632451  rtems_status_code             sc;
    24642452
    2465   sc = rtems_disk_io_initialize ();
    2466   if (sc != RTEMS_SUCCESSFUL)
    2467     return sc;
    2468 
    24692453  sc = rtems_fdisk_crc16_gen_factors (0x8408);
    24702454  if (sc != RTEMS_SUCCESSFUL)
    24712455      return sc;
    24722456
    2473   rtems_flashdisks = calloc (rtems_flashdisk_configuration_size,
    2474                              sizeof (rtems_flashdisk));
    2475 
    2476   if (!rtems_flashdisks)
     2457  fd = calloc (rtems_flashdisk_configuration_size, sizeof (*fd));
     2458  if (!fd)
    24772459    return RTEMS_NO_MEMORY;
    24782460
    2479   for (minor = 0; minor < rtems_flashdisk_configuration_size; minor++, c++)
     2461  for (minor = 0; minor < rtems_flashdisk_configuration_size; minor++, c++, fd++)
    24802462  {
    24812463    char     name[] = RTEMS_FLASHDISK_DEVICE_BASE_NAME "a";
    2482     dev_t    dev = rtems_filesystem_make_dev_t (major, minor);
    24832464    uint32_t device;
    24842465    uint32_t blocks = 0;
    24852466    int      ret;
    2486 
    2487     fd = &rtems_flashdisks[minor];
    24882467
    24892468    name [sizeof(RTEMS_FLASHDISK_DEVICE_BASE_NAME)] += minor;
     
    25212500    rtems_mutex_init (&fd->lock, "Flash Disk");
    25222501
    2523     sc = rtems_disk_create_phys(dev, c->block_size,
    2524                                 blocks - fd->unavail_blocks,
    2525                                 rtems_fdisk_ioctl, NULL, name);
     2502    sc = rtems_blkdev_create(name, c->block_size, blocks - fd->unavail_blocks,
     2503                             rtems_fdisk_ioctl, fd);
    25262504    if (sc != RTEMS_SUCCESSFUL)
    25272505    {
    25282506      rtems_mutex_destroy (&fd->lock);
    2529       rtems_disk_delete (dev);
    25302507      free (fd->copy_buffer);
    25312508      free (fd->blocks);
     
    25472524      if (!fd->devices[device].segments)
    25482525      {
    2549         rtems_disk_delete (dev);
     2526        unlink (name);
    25502527        rtems_mutex_destroy (&fd->lock);
    25512528        free (fd->copy_buffer);
     
    25822559    if (ret)
    25832560    {
    2584       rtems_disk_delete (dev);
     2561      unlink (name);
    25852562      rtems_mutex_destroy (&fd->lock);
    25862563      free (fd->copy_buffer);
     
    25952572    if (ret)
    25962573    {
    2597       rtems_disk_delete (dev);
     2574      unlink (name);
    25982575      rtems_mutex_destroy (&fd->lock);
    25992576      free (fd->copy_buffer);
     
    26062583  }
    26072584
    2608   rtems_flashdisk_count = rtems_flashdisk_configuration_size;
    2609 
    26102585  return RTEMS_SUCCESSFUL;
    26112586}
  • testsuites/libtests/flashdisk01/init.c

    r16f3f10 r0fe7133  
    326326uint32_t rtems_flashdisk_configuration_size = FLASHDISK_CONFIG_COUNT;
    327327
    328 #define FLASHDISK_DRIVER { \
    329   .initialization_entry = flashdisk_initialize, \
    330   .open_entry = rtems_blkdev_generic_open, \
    331   .close_entry = rtems_blkdev_generic_close, \
    332   .read_entry = rtems_blkdev_generic_read, \
    333   .write_entry = rtems_blkdev_generic_write, \
    334   .control_entry = rtems_blkdev_generic_ioctl \
    335 }
     328#define FLASHDISK_DRIVER { .initialization_entry = flashdisk_initialize }
    336329
    337330#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
Note: See TracChangeset for help on using the changeset viewer.