Changeset b96e09c in rtems for cpukit/libblock


Ignore:
Timestamp:
Oct 13, 2009, 7:58:33 AM (10 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
94d7bd7
Parents:
2e92a5d
Message:
  • libblock/include/rtems/diskdevs.h: Added driver data pointer to IO control function. The IO control handler takes now the disk device as first parameter instead of the physical device number.
  • cpukit/libblock/include/rtems/blkdev.h, libblock/src/bdbuf.c, libblock/src/blkdev.c, libblock/src/diskdevs.c, libblock/src/nvdisk.c, libblock/src/flashdisk.c, libblock/src/ramdisk.c: Update for block device API change.
Location:
cpukit/libblock
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/include/rtems/blkdev.h

    r2e92a5d rb96e09c  
    1818
    1919#include <rtems.h>
     20#include <rtems/diskdevs.h>
    2021#include <sys/ioctl.h>
    2122
     
    3940 * @{
    4041 */
    41 
    42 /**
    43  * Block device block index type.
    44  */
    45 typedef uint32_t rtems_blkdev_bnum;
    4642
    4743/**
     
    251247 */
    252248int
    253 rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp);
     249rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
    254250
    255251/** @} */
  • cpukit/libblock/include/rtems/diskdevs.h

    r2e92a5d rb96e09c  
    2121#include <stdlib.h>
    2222
    23 #include <rtems/blkdev.h>
    24 
    2523#ifdef __cplusplus
    2624extern "C" {
    2725#endif
    2826
     27typedef struct rtems_disk_device rtems_disk_device;
     28
    2929/**
    3030 * @defgroup rtems_disk Block Device Disk Management
     
    3232 * @ingroup rtems_libblock
    3333 *
    34  * This module provides functions to manage disk devices.
     34 * @brief This module provides functions to manage disk devices.
    3535 *
    3636 * A disk is a set of blocks which are identified by a consecutive set of
     
    4444
    4545/**
    46  * Block device IO control handler type.
    47  */
    48 typedef int (*rtems_block_device_ioctl)( dev_t dev, uint32_t req, void *argp);
    49 
    50 /**
    51  * Description of a disk device (logical and physical disks).
     46 * @brief Block device block index type.
     47 */
     48typedef uint32_t rtems_blkdev_bnum;
     49
     50/**
     51 * @brief Block device IO control handler type.
     52 */
     53typedef int (*rtems_block_device_ioctl)(
     54  rtems_disk_device *dd,
     55  uint32_t req,
     56  void *argp
     57);
     58
     59/**
     60 * @brief Description of a disk device (logical and physical disks).
    5261 *
    5362 * An array of pointer tables to rtems_disk_device structures is maintained.
     
    5665 * structure of moderated size.
    5766 */
    58 typedef struct rtems_disk_device {
    59   /**
    60    * Device identifier (concatenation of major and minor number).
     67struct rtems_disk_device {
     68  /**
     69   * @brief Device identifier (concatenation of major and minor number).
    6170   */
    6271  dev_t dev;
    6372
    6473  /**
    65    * Physical device identifier (equals the @c dev entry if it specifies a
     74   * @brief Physical device identifier (equals the @c dev entry if it specifies a
    6675   * physical device).
    6776   */
    68   struct rtems_disk_device *phys_dev;
    69 
    70   /**
    71    * Driver capabilities.
     77  rtems_disk_device *phys_dev;
     78
     79  /**
     80   * @brief Driver capabilities.
    7281   */
    7382  uint32_t capabilities;
    7483
    7584  /**
    76    * Disk device name.
     85   * @brief Disk device name.
    7786   */
    7887  char *name;
    7988
    8089  /**
    81    * Usage counter.
     90   * @brief Usage counter.
    8291   *
    8392   * Devices cannot be removed if they are in use.
     
    8695
    8796  /**
    88    * Start block number.
     97   * @brief Start block number.
    8998   *
    9099   * Equals zero for physical devices.  It is a block offset to the related
     
    94103
    95104  /**
    96    * Size of the physical or logical disk in blocks.
     105   * @brief Size of the physical or logical disk in blocks.
    97106   */
    98107  rtems_blkdev_bnum size;
    99108
    100109  /**
    101    * Device block size in bytes.
     110   * @brief Device block size in bytes.
    102111   *
    103112   * This is the minimum transfer unit. It can be any size.
     
    106115
    107116  /**
    108    * Device media block size in bytes.
     117   * @brief Device media block size in bytes.
    109118   *
    110119   * This is the media transfer unit the hardware defaults to.
     
    113122
    114123  /**
    115    * IO control handler for this disk.
     124   * @brief IO control handler for this disk.
    116125   */
    117126  rtems_block_device_ioctl ioctl;
    118 } rtems_disk_device;
    119 
    120 /**
    121  * Creates a physical disk with device identifier @a dev.
     127
     128  /**
     129   * @brief Private data for the disk driver.
     130   */
     131  void *driver_data;
     132};
     133
     134/**
     135 * @name Disk Device Data
     136 *
     137 * @{
     138 */
     139
     140static inline dev_t rtems_disk_physical_device_number(
     141  const rtems_disk_device *dd
     142)
     143{
     144  return dd->phys_dev->dev;
     145}
     146
     147static inline rtems_device_major_number rtems_disk_physical_major_number(
     148  const rtems_disk_device *dd
     149)
     150{
     151  return rtems_filesystem_dev_major_t(dd->phys_dev->dev);
     152}
     153
     154static inline rtems_device_minor_number rtems_disk_physical_minor_number(
     155  const rtems_disk_device *dd
     156)
     157{
     158  return rtems_filesystem_dev_minor_t(dd->phys_dev->dev);
     159}
     160
     161static inline dev_t rtems_disk_device_number(const rtems_disk_device *dd)
     162{
     163  return dd->dev;
     164}
     165
     166static inline rtems_device_major_number rtems_disk_major_number(
     167  const rtems_disk_device *dd
     168)
     169{
     170  return rtems_filesystem_dev_major_t(dd->dev);
     171}
     172
     173static inline rtems_device_minor_number rtems_disk_minor_number(
     174  const rtems_disk_device *dd
     175)
     176{
     177  return rtems_filesystem_dev_minor_t(dd->dev);
     178}
     179
     180static inline void *rtems_disk_driver_data(const rtems_disk_device *dd)
     181{
     182  return dd->driver_data;
     183}
     184
     185static inline uint32_t rtems_disk_block_size(const rtems_disk_device *dd)
     186{
     187  return dd->block_size;
     188}
     189
     190static inline uint32_t rtems_disk_media_block_size(const rtems_disk_device *dd)
     191{
     192  return dd->media_block_size;
     193}
     194
     195/** @} */
     196
     197/**
     198 * @name Disk Device Maintainance
     199 *
     200 * @{
     201 */
     202
     203/**
     204 * @brief Creates a physical disk with device identifier @a dev.
    122205 *
    123206 * The block size @a block_size must be a power of two.  The disk size @a
     
    135218  rtems_blkdev_bnum disk_size,
    136219  rtems_block_device_ioctl handler,
     220  void *driver_data,
    137221  const char *name
    138222);
    139223
    140224/**
    141  * Creates a logical disk with device identifier @a dev.
    142  *
    143  * A logical disk manages a subset of consecutive blocks containd in the
     225 * @brief Creates a logical disk with device identifier @a dev.
     226 *
     227 * A logical disk manages a subset of consecutive blocks contained in the
    144228 * physical disk with identifier @a phys.  The start block index of the logical
    145229 * disk device is @a start.  The block number of the logcal disk will be @a
     
    158242
    159243/**
    160  * Deletes a physical or logical disk device with identifier @a dev.
     244 * @brief Deletes a physical or logical disk device with identifier @a dev.
    161245 *
    162246 * Disk devices may be deleted if there usage counter (and the usage counters
     
    168252
    169253/**
    170  * Returns the disk device descriptor for the device identifier @a dev.
     254 * @brief Returns the disk device descriptor for the device identifier @a dev.
    171255 *
    172256 * Increments usage counter by one.  You should release the disk device
     
    177261
    178262/**
    179  * Releases the disk device description @a dd.
     263 * @brief Releases the disk device description @a dd.
    180264 *
    181265 * Decrements usage counter by one.
     
    183267rtems_status_code rtems_disk_release(rtems_disk_device *dd);
    184268
    185 /**
    186  * Disk device iterator.
     269/** @} */
     270
     271/**
     272 * @name Disk Management
     273 *
     274 * @{
     275 */
     276
     277/**
     278 * @brief Disk device iterator.
    187279 *
    188280 * Returns the next disk device descriptor with a device identifier larger than
     
    201293
    202294/**
    203  * Initializes the disk device management.
     295 * @brief Initializes the disk device management.
    204296 *
    205297 * This functions returns successful if the disk device management is already
     
    209301
    210302/**
    211  * Releases all resources allocated for disk device management.
     303 * @brief Releases all resources allocated for disk device management.
    212304 */
    213305rtems_status_code rtems_disk_io_done(void);
     
    215307/** @} */
    216308
     309/** @} */
     310
    217311#ifdef __cplusplus
    218312}
  • cpukit/libblock/src/bdbuf.c

    r2e92a5d rb96e09c  
    19761976    req->error = 0;
    19771977 
    1978     result = dd->ioctl (dd->phys_dev->dev, RTEMS_BLKIO_REQUEST, req);
     1978    result = dd->ioctl (dd, RTEMS_BLKIO_REQUEST, req);
    19791979
    19801980    /*
     
    24022402           * device is being held.
    24032403           */
    2404           result = dd->phys_dev->ioctl (dd->phys_dev->dev,
    2405                                         RTEMS_BLKIO_REQUEST, transfer->write_req);
    2406 
     2404          result = dd->ioctl (dd, RTEMS_BLKIO_REQUEST, transfer->write_req);
    24072405          if (result < 0)
    24082406          {
  • cpukit/libblock/src/blkdev.c

    r2e92a5d rb96e09c  
    238238        case RTEMS_BLKIO_SYNCDEV:
    239239            rc = rtems_bdbuf_syncdev(dd->dev);
    240             args->ioctl_return = (rc == RTEMS_SUCCESSFUL ? 0 : -1);
     240            args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
    241241            break;
    242242
     
    244244        {
    245245            rtems_blkdev_request *req = args->buffer;
    246             args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
    247                                            req);
     246            args->ioctl_return = (uint32_t) dd->ioctl(dd, args->command, req);
    248247            break;
    249248        }
    250249
    251250        default:
    252             args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
    253                                            args->buffer);
     251            args->ioctl_return = (uint32_t) dd->ioctl(dd, args->command,
     252                                                      args->buffer);
    254253            break;
    255254    }
     
    260259
    261260int
    262 rtems_blkdev_ioctl(dev_t dev, uint32_t req, void *argp)
    263 {
    264     rtems_disk_device *dd;
     261rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
     262{
    265263    size_t            *arg_size = argp;
    266264    int                rc = 0;
    267 
    268     dd = rtems_disk_obtain(dev);
    269     if (dd == NULL)
    270     {
    271         errno = ENODEV;
    272         return -1;
    273     }
    274265   
    275266    switch (req)
     
    296287            break;
    297288    }
    298    
    299     rtems_disk_release(dd);
    300289
    301290    return rc;
  • cpukit/libblock/src/diskdevs.c

    r2e92a5d rb96e09c  
    224224  rtems_blkdev_bnum disk_size,
    225225  rtems_block_device_ioctl handler,
     226  void *driver_data,
    226227  const char *name
    227228)
     
    253254    dd->block_size = dd->media_block_size = block_size;
    254255    dd->ioctl = handler;
     256    dd->driver_data = driver_data;
    255257
    256258    rc = rtems_io_register_name(name, major, minor);
    257259
    258     if (handler (dd->phys_dev->dev,
    259                  RTEMS_BLKDEV_CAPABILITIES,
    260                  &dd->capabilities) < 0)
     260    if (handler (dd, RTEMS_BLKDEV_CAPABILITIES, &dd->capabilities) < 0)
    261261      dd->capabilities = 0;
    262262   
     
    317317  dd->block_size = dd->media_block_size = pdd->block_size;
    318318  dd->ioctl = pdd->ioctl;
     319  dd->driver_data = pdd->driver_data;
    319320
    320321  rc = rtems_io_register_name(name, major, minor);
  • cpukit/libblock/src/flashdisk.c

    r2e92a5d rb96e09c  
    23362336 * Flash disk IOCTL handler.
    23372337 *
    2338  * @param dev Device number (major, minor number).
     2338 * @param dd Disk device.
    23392339 * @param req IOCTL request code.
    23402340 * @param argp IOCTL argument.
     
    23422342 */
    23432343static int
    2344 rtems_fdisk_ioctl (dev_t dev, uint32_t req, void* argp)
    2345 {
     2344rtems_fdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
     2345{
     2346  dev_t                     dev = rtems_disk_physical_device_number (dd);
    23462347  rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
    23472348  rtems_blkdev_request*     r = argp;
     
    24092410
    24102411      default:
    2411         rtems_blkdev_ioctl (dev, req, argp);
     2412        rtems_blkdev_ioctl (dd, req, argp);
    24122413        break;
    24132414    }
     
    24802481    sc = rtems_disk_create_phys(dev, c->block_size,
    24812482                                blocks - fd->unavail_blocks,
    2482                                 rtems_fdisk_ioctl, name);
     2483                                rtems_fdisk_ioctl, NULL, name);
    24832484    if (sc != RTEMS_SUCCESSFUL)
    24842485    {
  • cpukit/libblock/src/nvdisk.c

    r2e92a5d rb96e09c  
    675675 * NV disk IOCTL handler.
    676676 *
    677  * @param dev Device number (major, minor number).
     677 * @param dd Disk device.
    678678 * @param req IOCTL request code.
    679679 * @param argp IOCTL argument.
     
    681681 */
    682682static int
    683 rtems_nvdisk_ioctl (dev_t dev, uint32_t req, void* argp)
    684 {
     683rtems_nvdisk_ioctl (rtems_disk_device *dd, uint32_t req, void* argp)
     684{
     685  dev_t                     dev = rtems_disk_physical_device_number (dd);
    685686  rtems_device_minor_number minor = rtems_filesystem_dev_minor_t (dev);
    686687  rtems_blkdev_request*     r = argp;
     
    735736       
    736737      default:
    737         rtems_blkdev_ioctl (dev, req, argp);
     738        rtems_blkdev_ioctl (dd, req, argp);
    738739        break;
    739740    }
     
    818819
    819820    sc = rtems_disk_create_phys(dev, c->block_size, blocks,
    820                                 rtems_nvdisk_ioctl, name);
     821                                rtems_nvdisk_ioctl, NULL, name);
    821822    if (sc != RTEMS_SUCCESSFUL)
    822823    {
  • cpukit/libblock/src/ramdisk.c

    r2e92a5d rb96e09c  
    164164 */
    165165static int
    166 ramdisk_ioctl(dev_t dev, uint32_t req, void *argp)
     166ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
    167167{
    168168    switch (req)
     
    170170        case RTEMS_BLKIO_REQUEST:
    171171        {
    172             rtems_device_minor_number minor;
    173172            rtems_blkdev_request *r = argp;
    174             struct ramdisk *rd;
    175 
    176             minor = rtems_filesystem_dev_minor_t(dev);
    177             if ((minor >= nramdisks) || !ramdisk[minor].initialized)
    178             {
    179                 errno = ENODEV;
    180                 return -1;
    181             }
    182 
    183             rd = ramdisk + minor;
     173            struct ramdisk *rd = rtems_disk_driver_data(dd);
    184174
    185175            switch (r->req)
     
    199189 
    200190        default:
    201             return rtems_blkdev_ioctl (dev, req, argp);
     191            return rtems_blkdev_ioctl (dd, req, argp);
    202192            break;
    203193    }
     
    267257        }
    268258        rc = rtems_disk_create_phys(dev, c->block_size, c->block_num,
    269                                     ramdisk_ioctl, name);
     259                                    ramdisk_ioctl, r, name);
    270260        if (rc != RTEMS_SUCCESSFUL)
    271261        {
Note: See TracChangeset for help on using the changeset viewer.