Changeset 796967c in rtems


Ignore:
Timestamp:
Feb 28, 2012, 4:19:49 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
3ee7b84
Parents:
1024561
git-author:
Sebastian Huber <sebastian.huber@…> (02/28/12 16:19:49)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:24:18)
Message:

libblock: Change bdbuf API

The functions

o rtems_bdbuf_get(),
o rtems_bdbuf_read(),
o rtems_bdbuf_syncdev(), and
o rtems_bdbuf_purge_dev(),

use now the disk device instead of the device identifier. This makes
bdbuf independent of rtems_disk_obtain() and rtems_disk_release(). It
is the responsiblity of the file system to obtain the disk device. This
also reduces the overhead to get a buffer.

The key for the AVL tree uses now the disk device instead of the device
identifier. The pointer is interpreted as an unsigned integer. This
reduces the memory overhead and makes the comparison operation a bit
faster.

Removed function rtems_bdbuf_purge_major(). This function was too
destructive and could have unpredictable side effects.

Files:
42 edited

Legend:

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

    r1024561 r796967c  
    302302 * a range of other information related to managing the buffer in the cache. To
    303303 * speed-up buffer lookup descriptors are organized in AVL-Tree. The fields
    304  * 'dev' and 'block' are search keys.
     304 * 'dd' and 'block' are search keys.
    305305 */
    306306typedef struct rtems_bdbuf_buffer
     
    316316  } avl;
    317317
    318   dev_t             dev;        /**< device number */
     318  const rtems_disk_device *dd;  /**< disk device */
    319319
    320320  rtems_blkdev_bnum block;      /**< block number on the device */
     
    471471 * of the partition on the media.
    472472 *
    473  * @param device [in] Device number (constructed of major and minor device
    474  * number).
     473 * @param dd [in] The disk device.
    475474 * @param block [in] Linear media block number.
    476475 * @param bd [out] Reference to the buffer descriptor pointer.
     
    482481 */
    483482rtems_status_code
    484 rtems_bdbuf_get (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
     483rtems_bdbuf_get (
     484  const rtems_disk_device *dd,
     485  rtems_blkdev_bnum block,
     486  rtems_bdbuf_buffer** bd
     487);
    485488
    486489/**
     
    499502 * first.
    500503 *
    501  * @param device [in] Device number (constructed of major and minor device
    502  * number).
     504 * @param dd [in] The disk device.
    503505 * @param block [in] Linear media block number.
    504506 * @param bd [out] Reference to the buffer descriptor pointer.
     
    511513 */
    512514rtems_status_code
    513 rtems_bdbuf_read (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
     515rtems_bdbuf_read (
     516  const rtems_disk_device *dd,
     517  rtems_blkdev_bnum block,
     518  rtems_bdbuf_buffer** bd
     519);
    514520
    515521/**
     
    576582 * nested call will be blocked until the first sync request has complete.
    577583 *
    578  * @param dev [in] Device number (constructed of major and minor device
    579  * number).
     584 * @param dd [in] The disk device.
    580585 *
    581586 * @retval RTEMS_SUCCESSFUL Successful operation.
     
    584589 */
    585590rtems_status_code
    586 rtems_bdbuf_syncdev (dev_t dev);
    587 
    588 /**
    589  * @brief Purges all buffers that matches the device identifier @a dev.
     591rtems_bdbuf_syncdev (const rtems_disk_device *dd);
     592
     593/**
     594 * @brief Purges all buffers corresponding to the disk device @a dd.
    590595 *
    591596 * This may result in loss of data.
    592597 */
    593598void
    594 rtems_bdbuf_purge_dev (dev_t dev);
    595 
    596 /**
    597  * @brief Purges all buffers that matches the device major number @a major.
    598  *
    599  * This may result in loss of data.
    600  */
    601 void
    602 rtems_bdbuf_purge_major (rtems_device_major_number major);
     599rtems_bdbuf_purge_dev (const rtems_disk_device *dd);
    603600
    604601/** @} */
  • cpukit/libblock/include/rtems/bdpart.h

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009, 2010
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    399400rtems_status_code rtems_bdpart_get_disk_data(
    400401  const char *disk_name,
    401   dev_t *disk,
     402  int *fd_ptr,
     403  const rtems_disk_device **dd_ptr,
    402404  rtems_blkdev_bnum *disk_end
    403405);
  • cpukit/libblock/src/bdbuf.c

    r1024561 r796967c  
    2020 *    issues.
    2121 *
    22  * Copyright (c) 2009 embedded brains GmbH.
     22 * Copyright (c) 2009-2012 embedded brains GmbH.
    2323 *
    2424 * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp
     
    4545#include "rtems/bdbuf.h"
    4646
    47 #define BDBUF_INVALID_DEV ((dev_t) -1)
     47#define BDBUF_INVALID_DEV NULL
    4848
    4949/*
     
    5959{
    6060  rtems_chain_control   bds;         /**< The transfer list of BDs. */
    61   dev_t                 dev;         /**< The device the transfer is for. */
     61  const rtems_disk_device *dd;       /**< The device the transfer is for. */
    6262  bool                  syncing;     /**< The data is a sync'ing. */
    6363  rtems_blkdev_request* write_req;   /**< The write request array. */
     
    114114  bool                sync_active;       /**< True if a sync is active. */
    115115  rtems_id            sync_requester;    /**< The sync requester. */
    116   dev_t               sync_device;       /**< The device to sync and
     116  const rtems_disk_device *sync_device;  /**< The device to sync and
    117117                                          * BDBUF_INVALID_DEV not a device
    118118                                          * sync. */
     
    175175#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_1       RTEMS_BLKDEV_FATAL_ERROR(29)
    176176#define RTEMS_BLKDEV_FATAL_BDBUF_STATE_2       RTEMS_BLKDEV_FATAL_ERROR(30)
    177 #define RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL      RTEMS_BLKDEV_FATAL_ERROR(31)
    178177
    179178/**
     
    323322
    324323/**
    325  * Searches for the node with specified dev/block.
     324 * Searches for the node with specified dd/block.
    326325 *
    327326 * @param root pointer to the root node of the AVL-Tree
    328  * @param dev device search key
     327 * @param dd disk device search key
    329328 * @param block block search key
    330  * @retval NULL node with the specified dev/block is not found
    331  * @return pointer to the node with specified dev/block
     329 * @retval NULL node with the specified dd/block is not found
     330 * @return pointer to the node with specified dd/block
    332331 */
    333332static rtems_bdbuf_buffer *
    334333rtems_bdbuf_avl_search (rtems_bdbuf_buffer** root,
    335                         dev_t                dev,
     334                        const rtems_disk_device *dd,
    336335                        rtems_blkdev_bnum    block)
    337336{
    338337  rtems_bdbuf_buffer* p = *root;
    339338
    340   while ((p != NULL) && ((p->dev != dev) || (p->block != block)))
    341   {
    342     if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
     339  while ((p != NULL) && ((p->dd != dd) || (p->block != block)))
     340  {
     341    if (((uintptr_t) p->dd < (uintptr_t) dd)
     342        || ((p->dd == dd) && (p->block < block)))
    343343    {
    344344      p = p->avl.right;
     
    365365                       rtems_bdbuf_buffer*  node)
    366366{
    367   dev_t             dev = node->dev;
     367  const rtems_disk_device *dd = node->dd;
    368368  rtems_blkdev_bnum block = node->block;
    369369
     
    390390    *buf_prev++ = p;
    391391
    392     if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
     392    if (((uintptr_t) p->dd < (uintptr_t) dd)
     393        || ((p->dd == dd) && (p->block < block)))
    393394    {
    394395      p->avl.cache = 1;
     
    401402      }
    402403    }
    403     else if ((p->dev != dev) || (p->block != block))
     404    else if ((p->dd != dd) || (p->block != block))
    404405    {
    405406      p->avl.cache = -1;
     
    546547                       const rtems_bdbuf_buffer* node)
    547548{
    548   dev_t             dev = node->dev;
     549  const rtems_disk_device *dd = node->dd;
    549550  rtems_blkdev_bnum block = node->block;
    550551
     
    566567    *buf_prev++ = p;
    567568
    568     if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
     569    if (((uintptr_t) p->dd < (uintptr_t) dd)
     570        || ((p->dd == dd) && (p->block < block)))
    569571    {
    570572      p->avl.cache = 1;
    571573      p = p->avl.right;
    572574    }
    573     else if ((p->dev != dev) || (p->block != block))
     575    else if ((p->dd != dd) || (p->block != block))
    574576    {
    575577      p->avl.cache = -1;
     
    10931095rtems_bdbuf_add_to_modified_list_after_access (rtems_bdbuf_buffer *bd)
    10941096{
    1095   if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dev)
     1097  if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dd)
    10961098  {
    10971099    rtems_bdbuf_unlock_cache ();
     
    12221224static void
    12231225rtems_bdbuf_setup_empty_buffer (rtems_bdbuf_buffer *bd,
    1224                                 dev_t               dev,
     1226                                const rtems_disk_device *dd,
    12251227                                rtems_blkdev_bnum   block)
    12261228{
    1227   bd->dev       = dev;
     1229  bd->dd        = dd ;
    12281230  bd->block     = block;
    12291231  bd->avl.left  = NULL;
     
    12381240
    12391241static rtems_bdbuf_buffer *
    1240 rtems_bdbuf_get_buffer_from_lru_list (dev_t             dev,
     1242rtems_bdbuf_get_buffer_from_lru_list (const rtems_disk_device *dd,
    12411243                                      rtems_blkdev_bnum block,
    12421244                                      size_t            bds_per_group)
     
    12721274    if (empty_bd != NULL)
    12731275    {
    1274       rtems_bdbuf_setup_empty_buffer (empty_bd, dev, block);
     1276      rtems_bdbuf_setup_empty_buffer (empty_bd, dd, block);
    12751277
    12761278      return empty_bd;
     
    14231425       b++, bd++, buffer += bdbuf_config.buffer_min)
    14241426  {
    1425     bd->dev    = BDBUF_INVALID_DEV;
     1427    bd->dd    = BDBUF_INVALID_DEV;
    14261428    bd->group  = group;
    14271429    bd->buffer = buffer;
     
    16691671
    16701672static rtems_bdbuf_buffer *
    1671 rtems_bdbuf_get_buffer_for_read_ahead (dev_t             dev,
     1673rtems_bdbuf_get_buffer_for_read_ahead (const rtems_disk_device *dd,
    16721674                                       rtems_blkdev_bnum block,
    16731675                                       size_t            bds_per_group)
     
    16751677  rtems_bdbuf_buffer *bd = NULL;
    16761678
    1677   bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
     1679  bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dd, block);
    16781680
    16791681  if (bd == NULL)
    16801682  {
    1681     bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
     1683    bd = rtems_bdbuf_get_buffer_from_lru_list (dd, block, bds_per_group);
    16821684
    16831685    if (bd != NULL)
     
    16951697
    16961698static rtems_bdbuf_buffer *
    1697 rtems_bdbuf_get_buffer_for_access (dev_t             dev,
     1699rtems_bdbuf_get_buffer_for_access (const rtems_disk_device *dd,
    16981700                                   rtems_blkdev_bnum block,
    16991701                                   size_t            bds_per_group)
     
    17031705  do
    17041706  {
    1705     bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
     1707    bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dd, block);
    17061708
    17071709    if (bd != NULL)
     
    17201722    else
    17211723    {
    1722       bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
     1724      bd = rtems_bdbuf_get_buffer_from_lru_list (dd, block, bds_per_group);
    17231725
    17241726      if (bd == NULL)
     
    17351737
    17361738static rtems_status_code
    1737 rtems_bdbuf_obtain_disk (dev_t               dev,
     1739rtems_bdbuf_obtain_disk (const rtems_disk_device *dd,
    17381740                         rtems_blkdev_bnum   block,
    1739                          rtems_disk_device **dd_ptr,
    17401741                         rtems_blkdev_bnum  *media_block_ptr,
    17411742                         size_t             *bds_per_group_ptr)
    17421743{
    1743   rtems_disk_device *dd = NULL;
    1744 
    17451744  if (!bdbuf_cache.initialised)
    17461745    return RTEMS_NOT_CONFIGURED;
    1747 
    1748   /*
    1749    * Do not hold the cache lock when obtaining the disk table.
    1750    */
    1751   dd = rtems_disk_obtain (dev);
    1752   if (dd == NULL)
    1753     return RTEMS_INVALID_ID;
    1754 
    1755   *dd_ptr = dd;
    17561746
    17571747  if (media_block_ptr != NULL)
     
    17671757    if (mb >= dd->size)
    17681758    {
    1769       rtems_disk_release(dd);
    17701759      return RTEMS_INVALID_NUMBER;
    17711760    }
     
    17801769    if (bds_per_group == 0)
    17811770    {
    1782       rtems_disk_release (dd);
    17831771      return RTEMS_INVALID_NUMBER;
    17841772    }
     
    17901778}
    17911779
    1792 static void
    1793 rtems_bdbuf_release_disk (rtems_disk_device *dd)
    1794 {
    1795   rtems_status_code sc = RTEMS_SUCCESSFUL;
    1796 
    1797   sc = rtems_disk_release (dd);
    1798   if (sc != RTEMS_SUCCESSFUL)
    1799     rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL);
    1800 }
    1801 
    18021780rtems_status_code
    1803 rtems_bdbuf_get (dev_t                dev,
     1781rtems_bdbuf_get (const rtems_disk_device *dd,
    18041782                 rtems_blkdev_bnum    block,
    18051783                 rtems_bdbuf_buffer **bd_ptr)
    18061784{
    18071785  rtems_status_code   sc = RTEMS_SUCCESSFUL;
    1808   rtems_disk_device  *dd = NULL;
    18091786  rtems_bdbuf_buffer *bd = NULL;
    18101787  rtems_blkdev_bnum   media_block = 0;
    18111788  size_t              bds_per_group = 0;
    18121789
    1813   sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
     1790  sc = rtems_bdbuf_obtain_disk (dd, block, &media_block, &bds_per_group);
    18141791  if (sc != RTEMS_SUCCESSFUL)
    18151792    return sc;
     
    18221799  if (rtems_bdbuf_tracer)
    18231800    printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
    1824             media_block, block, (unsigned) dev);
    1825 
    1826   bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
     1801            media_block, block, (unsigned) dd->dev);
     1802
     1803  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block, bds_per_group);
    18271804
    18281805  switch (bd->state)
     
    18571834  rtems_bdbuf_unlock_cache ();
    18581835
    1859   rtems_bdbuf_release_disk (dd);
    1860 
    18611836  *bd_ptr = bd;
    18621837
     
    18931868  rtems_blkdev_bnum   media_block_end = dd->start + dd->size;
    18941869  rtems_blkdev_bnum   media_block_count = dd->block_size / dd->media_block_size;
    1895   dev_t               dev = dd->dev;
    18961870  uint32_t            block_size = dd->block_size;
    18971871  uint32_t            transfer_index = 1;
     
    19081882  req->bufnum = 0;
    19091883
    1910   bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
     1884  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block, bds_per_group);
    19111885
    19121886  *bd_ptr = bd;
     
    19371911    media_block += media_block_count;
    19381912
    1939     bd = rtems_bdbuf_get_buffer_for_read_ahead (dev, media_block,
     1913    bd = rtems_bdbuf_get_buffer_for_read_ahead (dd, media_block,
    19401914                                                bds_per_group);
    19411915
     
    20221996
    20231997rtems_status_code
    2024 rtems_bdbuf_read (dev_t                dev,
     1998rtems_bdbuf_read (const rtems_disk_device *dd,
    20251999                  rtems_blkdev_bnum    block,
    20262000                  rtems_bdbuf_buffer **bd_ptr)
    20272001{
    20282002  rtems_status_code     sc = RTEMS_SUCCESSFUL;
    2029   rtems_disk_device    *dd = NULL;
    20302003  rtems_blkdev_request *req = NULL;
    20312004  rtems_bdbuf_buffer   *bd = NULL;
     
    20332006  size_t                bds_per_group = 0;
    20342007
    2035   sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
     2008  sc = rtems_bdbuf_obtain_disk (dd, block, &media_block, &bds_per_group);
    20362009  if (sc != RTEMS_SUCCESSFUL)
    20372010    return sc;
     
    20482021  if (rtems_bdbuf_tracer)
    20492022    printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
    2050             media_block + dd->start, block, (unsigned) dev);
     2023            media_block + dd->start, block, (unsigned) dd->dev);
    20512024
    20522025  rtems_bdbuf_lock_cache ();
     
    20902063
    20912064  rtems_bdbuf_unlock_cache ();
    2092   rtems_bdbuf_release_disk (dd);
    20932065
    20942066  return sc;
     
    22112183
    22122184rtems_status_code
    2213 rtems_bdbuf_syncdev (dev_t dev)
     2185rtems_bdbuf_syncdev (const rtems_disk_device *dd)
    22142186{
    22152187  rtems_status_code  sc = RTEMS_SUCCESSFUL;
    2216   rtems_disk_device *dd = NULL;
    22172188
    22182189  if (rtems_bdbuf_tracer)
    2219     printf ("bdbuf:syncdev: %08x\n", (unsigned) dev);
    2220 
    2221   sc = rtems_bdbuf_obtain_disk (dev, 0, &dd, NULL, NULL);
     2190    printf ("bdbuf:syncdev: %08x\n", (unsigned) dd->dev);
     2191
     2192  sc = rtems_bdbuf_obtain_disk (dd, 0, NULL, NULL);
    22222193  if (sc != RTEMS_SUCCESSFUL)
    22232194    return sc;
     
    22412212  bdbuf_cache.sync_active    = true;
    22422213  bdbuf_cache.sync_requester = rtems_task_self ();
    2243   bdbuf_cache.sync_device    = dev;
     2214  bdbuf_cache.sync_device    = dd;
    22442215
    22452216  rtems_bdbuf_wake_swapper ();
     
    22472218  rtems_bdbuf_wait_for_event (RTEMS_BDBUF_TRANSFER_SYNC);
    22482219  rtems_bdbuf_unlock_sync ();
    2249   rtems_bdbuf_release_disk (dd);
    22502220
    22512221  return RTEMS_SUCCESSFUL;
    2252 }
    2253 
    2254 static int
    2255 rtems_bdbuf_null_disk_ioctl (rtems_disk_device *dd, uint32_t req, void *arg)
    2256 {
    2257   return -1;
    22582222}
    22592223
     
    22692233{
    22702234  rtems_chain_node *node;
    2271   static rtems_disk_device null_disk = {
    2272     .phys_dev = &null_disk,
    2273     .capabilities = 0,
    2274     .ioctl = rtems_bdbuf_null_disk_ioctl
    2275   };
    22762235
    22772236  if (rtems_bdbuf_tracer)
    2278     printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dev);
     2237    printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dd->dev);
    22792238
    22802239  /*
     
    22952254    uint32_t bufs_per_bd = 0;
    22962255
    2297     /*
    2298      * Obtain the disk device. The cache's mutex has been released to avoid a
    2299      * dead lock.
    2300      */
    2301     rtems_disk_device *dd = rtems_disk_obtain (transfer->dev);
    2302 
    2303     if (dd == NULL)
    2304       dd = &null_disk;
     2256    const rtems_disk_device *dd = transfer->dd;
    23052257
    23062258    bufs_per_bd = dd->block_size / bdbuf_config.buffer_min;
     
    23732325    }
    23742326
    2375     if (dd != &null_disk)
    2376     {
    2377       /*
    2378        * If sync'ing and the deivce is capability of handling a sync IO control
    2379        * call perform the call.
    2380        */
    2381       if (transfer->syncing &&
    2382           (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
    2383       {
    2384         /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
    2385         /* How should the error be handled ? */
    2386       }
    2387      
    2388       rtems_disk_release (dd);
     2327    /*
     2328     * If sync'ing and the deivce is capability of handling a sync IO control
     2329     * call perform the call.
     2330     */
     2331    if (transfer->syncing &&
     2332        (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
     2333    {
     2334      /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
     2335      /* How should the error be handled ? */
    23892336    }
    23902337  }
     
    23952342 * needs to be handled so we have a common function to do the work.
    23962343 *
    2397  * @param dev The device to handle. If BDBUF_INVALID_DEV no device is selected
    2398  * so select the device of the first buffer to be written to disk.
     2344 * @param dd_ptr Pointer to the device to handle. If BDBUF_INVALID_DEV no
     2345 * device is selected so select the device of the first buffer to be written to
     2346 * disk.
    23992347 * @param chain The modified chain to process.
    24002348 * @param transfer The chain to append buffers to be written too.
     
    24052353 */
    24062354static void
    2407 rtems_bdbuf_swapout_modified_processing (dev_t*               dev,
     2355rtems_bdbuf_swapout_modified_processing (const rtems_disk_device **dd_ptr,
    24082356                                         rtems_chain_control* chain,
    24092357                                         rtems_chain_control* transfer,
     
    24222370     * A sync active with no valid dev means sync all.
    24232371     */
    2424     if (sync_active && (*dev == BDBUF_INVALID_DEV))
     2372    if (sync_active && (*dd_ptr == BDBUF_INVALID_DEV))
    24252373      sync_all = true;
    24262374    else
     
    24382386       *       on TOD to be accurate. Does it matter ?
    24392387       */
    2440       if (sync_all || (sync_active && (*dev == bd->dev))
     2388      if (sync_all || (sync_active && (*dd_ptr == bd->dd))
    24412389          || rtems_bdbuf_has_buffer_waiters ())
    24422390        bd->hold_timer = 0;
     
    24602408
    24612409      /*
    2462        * This assumes we can set dev_t to BDBUF_INVALID_DEV which is just an
     2410       * This assumes we can set it to BDBUF_INVALID_DEV which is just an
    24632411       * assumption. Cannot use the transfer list being empty the sync dev
    24642412       * calls sets the dev to use.
    24652413       */
    2466       if (*dev == BDBUF_INVALID_DEV)
    2467         *dev = bd->dev;
    2468 
    2469       if (bd->dev == *dev)
     2414      if (*dd_ptr == BDBUF_INVALID_DEV)
     2415        *dd_ptr = bd->dd;
     2416
     2417      if (bd->dd == *dd_ptr)
    24702418      {
    24712419        rtems_chain_node* next_node = node->next;
     
    25572505
    25582506  rtems_chain_initialize_empty (&transfer->bds);
    2559   transfer->dev = BDBUF_INVALID_DEV;
     2507  transfer->dd = BDBUF_INVALID_DEV;
    25602508  transfer->syncing = bdbuf_cache.sync_active;
    25612509 
     
    25662514   */
    25672515  if (bdbuf_cache.sync_active)
    2568     transfer->dev = bdbuf_cache.sync_device;
     2516    transfer->dd = bdbuf_cache.sync_device;
    25692517   
    25702518  /*
     
    25722520   * list. The first sync buffer will select the device we use.
    25732521   */
    2574   rtems_bdbuf_swapout_modified_processing (&transfer->dev,
     2522  rtems_bdbuf_swapout_modified_processing (&transfer->dd,
    25752523                                           &bdbuf_cache.sync,
    25762524                                           &transfer->bds,
     
    25812529   * Process the cache's modified list.
    25822530   */
    2583   rtems_bdbuf_swapout_modified_processing (&transfer->dev,
     2531  rtems_bdbuf_swapout_modified_processing (&transfer->dd,
    25842532                                           &bdbuf_cache.modified,
    25852533                                           &transfer->bds,
     
    26792627
    26802628    rtems_chain_initialize_empty (&worker->transfer.bds);
    2681     worker->transfer.dev = BDBUF_INVALID_DEV;
     2629    worker->transfer.dd = BDBUF_INVALID_DEV;
    26822630
    26832631    rtems_chain_append (&bdbuf_cache.swapout_workers, &worker->link);
     
    27162664
    27172665    rtems_chain_initialize_empty (&worker->transfer.bds);
    2718     worker->transfer.dev = BDBUF_INVALID_DEV;
     2666    worker->transfer.dd = BDBUF_INVALID_DEV;
    27192667
    27202668    sc = rtems_task_create (rtems_build_name('B', 'D', 'o', 'a' + w),
     
    27782726  transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
    27792727  rtems_chain_initialize_empty (&transfer.bds);
    2780   transfer.dev = BDBUF_INVALID_DEV;
     2728  transfer.dd = BDBUF_INVALID_DEV;
    27812729  transfer.syncing = false;
    27822730
     
    28722820}
    28732821
    2874 typedef bool (*rtems_bdbuf_purge_compare)(dev_t a, dev_t b);
    2875 
    28762822static void
    28772823rtems_bdbuf_gather_for_purge (rtems_chain_control *purge_list,
    2878                               rtems_bdbuf_purge_compare compare,
    2879                               dev_t dev)
     2824                              const rtems_disk_device *dd)
    28802825{
    28812826  rtems_bdbuf_buffer *stack [RTEMS_BDBUF_AVL_MAX_HEIGHT];
     
    28872832  while (cur != NULL)
    28882833  {
    2889     if ((*compare) (cur->dev, dev))
     2834    if (cur->dd == dd)
    28902835    {
    28912836      switch (cur->state)
     
    29512896}
    29522897
    2953 static void
    2954 rtems_bdbuf_purge (rtems_bdbuf_purge_compare compare, dev_t dev)
     2898void
     2899rtems_bdbuf_purge_dev (const rtems_disk_device *dd)
    29552900{
    29562901  rtems_chain_control purge_list;
     
    29582903  rtems_chain_initialize_empty (&purge_list);
    29592904  rtems_bdbuf_lock_cache ();
    2960   rtems_bdbuf_gather_for_purge (&purge_list, compare, dev);
     2905  rtems_bdbuf_gather_for_purge (&purge_list, dd);
    29612906  rtems_bdbuf_purge_list (&purge_list);
    29622907  rtems_bdbuf_unlock_cache ();
    29632908}
    2964 
    2965 static bool
    2966 rtems_bdbuf_purge_compare_dev (dev_t a, dev_t b)
    2967 {
    2968   return a == b;
    2969 }
    2970 
    2971 void
    2972 rtems_bdbuf_purge_dev (dev_t dev)
    2973 {
    2974   rtems_bdbuf_purge (rtems_bdbuf_purge_compare_dev, dev);
    2975 }
    2976 
    2977 static bool
    2978 rtems_bdbuf_purge_compare_major (dev_t a, dev_t b)
    2979 {
    2980   return rtems_filesystem_dev_major_t (a) == rtems_filesystem_dev_major_t (b);
    2981 }
    2982 
    2983 void
    2984 rtems_bdbuf_purge_major (rtems_device_major_number major)
    2985 {
    2986   dev_t dev = rtems_filesystem_make_dev_t (major, 0);
    2987 
    2988   rtems_bdbuf_purge (rtems_bdbuf_purge_compare_major, dev);
    2989 }
  • cpukit/libblock/src/bdpart-create.c

    r1024561 r796967c  
    4646  rtems_blkdev_bnum overhead = 0;
    4747  rtems_blkdev_bnum free_space = 0;
    48   dev_t disk = 0;
    4948  size_t i = 0;
    5049
     
    6160
    6261  /* Get disk data */
    63   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     62  sc = rtems_bdpart_get_disk_data( disk_name, NULL, NULL, &disk_end);
    6463  if (sc != RTEMS_SUCCESSFUL) {
    6564    return sc;
     
    143142    s += record_space - (s % record_space);
    144143
     144    /* Reserve space for the EBR if necessary */
     145    if (count > 4 && i > 2) {
     146      pos += record_space;
     147    }
     148
    145149    /* Partition begin and end */
    146150    p->begin = pos;
    147151    pos += s;
    148152    p->end = pos;
    149 
    150     /* Reserve space for the EBR if necessary */
    151     if (count > 4 && i > 2) {
    152       p->begin += record_space;
    153     }
    154153  }
    155154
  • cpukit/libblock/src/bdpart-read.c

    r1024561 r796967c  
    2424#endif
    2525
     26#include <sys/stat.h>
     27#include <fcntl.h>
     28
    2629#include <rtems.h>
    2730#include <rtems/bdbuf.h>
     
    6568rtems_status_code rtems_bdpart_get_disk_data(
    6669  const char *disk_name,
    67   dev_t *disk,
     70  int *fd_ptr,
     71  const rtems_disk_device **dd_ptr,
    6872  rtems_blkdev_bnum *disk_end
    6973)
     
    7175  rtems_status_code sc = RTEMS_SUCCESSFUL;
    7276  int rv = 0;
     77  int fd = -1;
     78  const rtems_disk_device *dd = NULL;
    7379  rtems_blkdev_bnum disk_begin = 0;
    7480  rtems_blkdev_bnum block_size = 0;
    75   rtems_disk_device *dd = NULL;
    76   struct stat st;
     81
     82  /* Open device file */
     83  fd = open( disk_name, O_RDWR);
     84  if (fd < 0) {
     85    sc = RTEMS_INVALID_NAME;
     86    goto error;
     87  }
    7788
    7889  /* Get disk handle */
    79   rv = stat( disk_name, &st);
     90  rv = rtems_disk_fd_get_disk_device( fd, &dd);
    8091  if (rv != 0) {
    81     return RTEMS_INVALID_NAME;
    82   }
    83   *disk = st.st_rdev;
     92    sc = RTEMS_INVALID_NAME;
     93    goto error;
     94  }
    8495
    8596  /* Get disk begin, end and block size */
    86   dd = rtems_disk_obtain( *disk);
    87   if (dd == NULL) {
    88     return RTEMS_INVALID_NAME;
    89   }
    9097  disk_begin = dd->start;
    9198  *disk_end = dd->size;
    9299  block_size = dd->block_size;
    93   sc = rtems_disk_release( dd);
    94   if (sc != RTEMS_SUCCESSFUL) {
    95     return sc;
    96   }
    97100
    98101  /* Check block size */
    99102  if (block_size < RTEMS_BDPART_BLOCK_SIZE) {
    100     return RTEMS_IO_ERROR;
     103    sc = RTEMS_IO_ERROR;
     104    goto error;
    101105  }
    102106
    103107  /* Check that we have do not have a logical disk */
    104108  if (disk_begin != 0) {
    105     return RTEMS_IO_ERROR;
    106   }
    107 
    108   return RTEMS_SUCCESSFUL;
     109    sc = RTEMS_IO_ERROR;
     110    goto error;
     111  }
     112
     113error:
     114
     115  if (sc == RTEMS_SUCCESSFUL && fd_ptr != NULL && dd_ptr != NULL) {
     116    *fd_ptr = fd;
     117    *dd_ptr = dd;
     118  } else {
     119    close( fd);
     120  }
     121
     122  return sc;
    109123}
    110124
     
    172186
    173187static rtems_status_code rtems_bdpart_read_record(
    174   dev_t disk,
     188  const rtems_disk_device *dd,
    175189  rtems_blkdev_bnum index,
    176190  rtems_bdbuf_buffer **block
     
    188202
    189203  /* Read the record block */
    190   sc = rtems_bdbuf_read( disk, index, block);
     204  sc = rtems_bdbuf_read( dd, index, block);
    191205  if (sc != RTEMS_SUCCESSFUL) {
    192206    return sc;
     
    221235  rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
    222236  rtems_blkdev_bnum disk_end = 0;
    223   dev_t disk = 0;
    224237  size_t i = 0;
    225238  const uint8_t *data = NULL;
     239  int fd = -1;
     240  const rtems_disk_device *dd = NULL;
    226241
    227242  /* Check parameter */
     
    234249
    235250  /* Get disk data */
    236   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     251  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    237252  if (sc != RTEMS_SUCCESSFUL) {
    238253    return sc;
     
    240255
    241256  /* Read MBR */
    242   sc = rtems_bdpart_read_record( disk, 0, &block);
     257  sc = rtems_bdpart_read_record( dd, 0, &block);
    243258  if (sc != RTEMS_SUCCESSFUL) {
    244259    esc = sc;
     
    284299
    285300    /* Read EBR */
    286     sc = rtems_bdpart_read_record( disk, ebr, &block);
     301    sc = rtems_bdpart_read_record( dd, ebr, &block);
    287302    if (sc != RTEMS_SUCCESSFUL) {
    288303      esc = sc;
     
    341356cleanup:
    342357
     358  if (fd >= 0) {
     359    close( fd);
     360  }
     361
    343362  if (block != NULL) {
    344363    rtems_bdbuf_release( block);
  • cpukit/libblock/src/bdpart-register.c

    r1024561 r796967c  
    4848  size_t disk_name_size = strlen( disk_name);
    4949  size_t i = 0;
     50  int fd = -1;
     51  const rtems_disk_device *dd = NULL;
    5052
    5153  /* Get disk data */
    52   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     54  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    5355  if (sc != RTEMS_SUCCESSFUL) {
    5456    return sc;
    5557  }
     58  disk = rtems_disk_get_device_identifier( dd);
     59  close( fd);
    5660
    5761  /* Get the disk device identifier */
     
    135139  dev_t logical_disk = 0;
    136140  size_t i = 0;
     141  int fd = -1;
     142  const rtems_disk_device *dd = NULL;
    137143
    138144  /* Get disk data */
    139   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     145  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    140146  if (sc != RTEMS_SUCCESSFUL) {
    141147    return sc;
    142148  }
     149  disk = rtems_disk_get_device_identifier( dd);
     150  close( fd);
    143151
    144152  /* Get the disk device identifier */
  • cpukit/libblock/src/bdpart-write.c

    r1024561 r796967c  
    4646
    4747static rtems_status_code rtems_bdpart_new_record(
    48   dev_t disk,
     48  const rtems_disk_device *dd,
    4949  rtems_blkdev_bnum index,
    5050  rtems_bdbuf_buffer **block
     
    6262
    6363  /* Read the new record block (this accounts for disk block sizes > 512) */
    64   sc = rtems_bdbuf_read( disk, index, block);
     64  sc = rtems_bdbuf_read( dd, index, block);
    6565  if (sc != RTEMS_SUCCESSFUL) {
    6666    return sc;
     
    100100  rtems_blkdev_bnum record_space =
    101101    dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
    102   dev_t disk = 0;
    103102  size_t ppc = 0; /* Primary partition count */
    104103  size_t i = 0;
    105104  uint8_t *data = NULL;
     105  int fd = -1;
     106  const rtems_disk_device *dd = NULL;
    106107
    107108  /* Check if we have something to do */
     
    117118
    118119  /* Get disk data */
    119   sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
     120  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
    120121  if (sc != RTEMS_SUCCESSFUL) {
    121122    return sc;
     
    212213
    213214  /* New MBR */
    214   sc = rtems_bdpart_new_record( disk, 0, &block);
     215  sc = rtems_bdpart_new_record( dd, 0, &block);
    215216  if (sc != RTEMS_SUCCESSFUL) {
    216217    esc = sc;
     
    276277      /* New EBR */
    277278      ebr = p->begin - record_space;
    278       sc = rtems_bdpart_new_record( disk, ebr, &block);
     279      sc = rtems_bdpart_new_record( dd, ebr, &block);
    279280      if (sc != RTEMS_SUCCESSFUL) {
    280281        esc = sc;
     
    295296cleanup:
    296297
     298  if (fd >= 0) {
     299    close( fd);
     300  }
     301
    297302  if (block != NULL) {
    298303    rtems_bdbuf_sync( block);
  • cpukit/libblock/src/blkdev.c

    r1024561 r796967c  
    4747    rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
    4848    uint32_t blkofs = (uint32_t) (args->offset % block_size);
    49     dev_t dev = dd->dev;
    5049
    5150    args->bytes_moved = 0;
     
    5655        uint32_t            copy;
    5756
    58         rc = rtems_bdbuf_read(dev, block, &diskbuf);
     57        rc = rtems_bdbuf_read(dd, block, &diskbuf);
    5958        if (rc != RTEMS_SUCCESSFUL)
    6059            break;
     
    9594    rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
    9695    uint32_t blkofs = (uint32_t) (args->offset % block_size);
    97     dev_t dev = dd->dev;
    9896
    9997    args->bytes_moved = 0;
     
    105103
    106104        if ((blkofs == 0) && (count >= block_size))
    107             rc = rtems_bdbuf_get(dev, block, &diskbuf);
     105            rc = rtems_bdbuf_get(dd, block, &diskbuf);
    108106        else
    109             rc = rtems_bdbuf_read(dev, block, &diskbuf);
     107            rc = rtems_bdbuf_read(dd, block, &diskbuf);
    110108        if (rc != RTEMS_SUCCESSFUL)
    111109            break;
     
    208206
    209207        case RTEMS_BLKIO_SYNCDEV:
    210             rc = rtems_bdbuf_syncdev(dd->dev);
     208            rc = rtems_bdbuf_syncdev(dd);
    211209            args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
    212210            break;
  • cpukit/libblock/src/media.c

    r1024561 r796967c  
    813813  if (state == RTEMS_MEDIA_STATE_READY) {
    814814    dev_t dev = 0;
     815    rtems_disk_device *dd = NULL;
    815816
    816817    sc = rtems_media_get_device_identifier(src, &dev);
     
    819820    }
    820821
    821     sc = rtems_bdbuf_syncdev(dev);
    822     if (sc != RTEMS_SUCCESSFUL) {
    823       rsc = RTEMS_IO_ERROR;
     822    dd = rtems_disk_obtain(dev);
     823    if (dd != NULL) {
     824      sc = rtems_bdbuf_syncdev(dd);
     825      if (sc != RTEMS_SUCCESSFUL) {
     826        rsc = RTEMS_IO_ERROR;
     827      }
    824828    }
    825829
     
    829833    }
    830834
    831     rtems_bdbuf_purge_dev(dev);
     835    if (dd != NULL) {
     836      rtems_bdbuf_purge_dev(dd);
     837      rtems_disk_release(dd);
     838    }
    832839
    833840    if (rtems_filesystem_dev_minor_t(dev) == 0) {
  • cpukit/libfs/src/dosfs/fat.c

    r1024561 r796967c  
    3838    {
    3939        if (op_type == FAT_OP_TYPE_READ)
    40             sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf);
     40            sc = rtems_bdbuf_read(fs_info->vol.dd, blk, &fs_info->c.buf);
    4141        else
    42             sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf);
     42            sc = rtems_bdbuf_get(fs_info->vol.dd, blk, &fs_info->c.buf);
    4343        if (sc != RTEMS_SUCCESSFUL)
    4444            rtems_set_errno_and_return_minus_one(EIO);
     
    7171                for (i = 1; i < fs_info->vol.fats; i++)
    7272                {
    73                     sc = rtems_bdbuf_get(fs_info->vol.dev,
     73                    sc = rtems_bdbuf_get(fs_info->vol.dd,
    7474                                         fs_info->c.blk_num +
    7575                                         fs_info->vol.fat_length * i,
     
    9393        }
    9494        if (op_type == FAT_OP_TYPE_READ)
    95             sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf);
     95            sc = rtems_bdbuf_read(fs_info->vol.dd, blk, &fs_info->c.buf);
    9696        else
    97             sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf);
     97            sc = rtems_bdbuf_get(fs_info->vol.dd, blk, &fs_info->c.buf);
    9898        if (sc != RTEMS_SUCCESSFUL)
    9999            rtems_set_errno_and_return_minus_one(EIO);
     
    134134            for (i = 1; i < fs_info->vol.fats; i++)
    135135            {
    136                 sc = rtems_bdbuf_get(fs_info->vol.dev,
     136                sc = rtems_bdbuf_get(fs_info->vol.dd,
    137137                                     fs_info->c.blk_num +
    138138                                     fs_info->vol.fat_length * i,
     
    363363    rtems_bdbuf_buffer *block = NULL;
    364364
    365     rc = stat(mt_entry->dev, &stat_buf);
    366     if (rc == -1)
    367         return rc;
     365    vol->fd = open(mt_entry->dev, O_RDWR);
     366    if (vol->fd < 0)
     367    {
     368        rtems_set_errno_and_return_minus_one(ENXIO);
     369    }
     370
     371    rc = fstat(vol->fd, &stat_buf);
     372    if (rc != 0)
     373    {
     374        close(vol->fd);
     375        rtems_set_errno_and_return_minus_one(ENXIO);
     376    }
    368377
    369378    /* Must be a block device. */
    370379    if (!S_ISBLK(stat_buf.st_mode))
    371         rtems_set_errno_and_return_minus_one(ENOTTY);
     380    {
     381        close(vol->fd);
     382        rtems_set_errno_and_return_minus_one(ENXIO);
     383    }
    372384
    373385    /* check that device is registred as block device and lock it */
    374     vol->dd = rtems_disk_obtain(stat_buf.st_rdev);
    375     if (vol->dd == NULL)
    376         rtems_set_errno_and_return_minus_one(EIO);
    377 
    378     vol->dev = stat_buf.st_rdev;
     386    rc = rtems_disk_fd_get_disk_device(vol->fd, &vol->dd);
     387    if (rc != 0) {
     388        close(vol->fd);
     389        rtems_set_errno_and_return_minus_one(ENXIO);
     390    }
    379391
    380392    /* Read boot record */
    381393    /* FIXME: Asserts FAT_MAX_BPB_SIZE < bdbuf block size */
    382     sc = rtems_bdbuf_read( vol->dev, 0, &block);
     394    sc = rtems_bdbuf_read( vol->dd, 0, &block);
    383395    if (sc != RTEMS_SUCCESSFUL)
    384396    {
    385         rtems_disk_release(vol->dd);
     397        close(vol->fd);
    386398        rtems_set_errno_and_return_minus_one( EIO);
    387399    }
     
    392404    if (sc != RTEMS_SUCCESSFUL)
    393405    {
    394         rtems_disk_release(vol->dd);
     406        close(vol->fd);
    395407        rtems_set_errno_and_return_minus_one( EIO );
    396408    }
     
    404416         (vol->bps != 4096))
    405417    {
    406         rtems_disk_release(vol->dd);
     418        close(vol->fd);
    407419        rtems_set_errno_and_return_minus_one( EINVAL );
    408420    }
     
    420432    if (vol->spc == 0)
    421433    {
    422         rtems_disk_release(vol->dd);
     434        close(vol->fd);
    423435        rtems_set_errno_and_return_minus_one(EINVAL);
    424436    }
     
    432444    if ((vol->bpc = vol->bps << vol->spc_log2) > MS_BYTES_PER_CLUSTER_LIMIT)
    433445    {
    434         rtems_disk_release(vol->dd);
     446        close(vol->fd);
    435447        rtems_set_errno_and_return_minus_one(EINVAL);
    436448    }
     
    506518        if( vol->info_sec == 0 )
    507519        {
    508             rtems_disk_release(vol->dd);
     520            close(vol->fd);
    509521            rtems_set_errno_and_return_minus_one( EINVAL );
    510522        }
     
    515527            if ( ret < 0 )
    516528            {
    517                 rtems_disk_release(vol->dd);
     529                close(vol->fd);
    518530                return -1;
    519531            }
     
    523535            {
    524536                _fat_block_release(mt_entry);
    525                 rtems_disk_release(vol->dd);
     537                close(vol->fd);
    526538                rtems_set_errno_and_return_minus_one( EINVAL );
    527539            }
     
    533545                {
    534546                    _fat_block_release(mt_entry);
    535                     rtems_disk_release(vol->dd);
     547                    close(vol->fd);
    536548                    return -1;
    537549                }
     
    544556                {
    545557                    _fat_block_release(mt_entry);
    546                     rtems_disk_release(vol->dd);
     558                    close(vol->fd);
    547559                    return rc;
    548560                }
     
    567579    if ( fs_info->vhash == NULL )
    568580    {
    569         rtems_disk_release(vol->dd);
     581        close(vol->fd);
    570582        rtems_set_errno_and_return_minus_one( ENOMEM );
    571583    }
     
    577589    if ( fs_info->rhash == NULL )
    578590    {
    579         rtems_disk_release(vol->dd);
     591        close(vol->fd);
    580592        free(fs_info->vhash);
    581593        rtems_set_errno_and_return_minus_one( ENOMEM );
     
    590602    if ( fs_info->uino == NULL )
    591603    {
    592         rtems_disk_release(vol->dd);
     604        close(vol->fd);
    593605        free(fs_info->vhash);
    594606        free(fs_info->rhash);
     
    598610    if (fs_info->sec_buf == NULL)
    599611    {
    600         rtems_disk_release(vol->dd);
     612        close(vol->fd);
    601613        free(fs_info->vhash);
    602614        free(fs_info->rhash);
     
    635647    fat_buf_release(fs_info);
    636648
    637     if (rtems_bdbuf_syncdev(fs_info->vol.dev) != RTEMS_SUCCESSFUL)
     649    if (rtems_bdbuf_syncdev(fs_info->vol.dd) != RTEMS_SUCCESSFUL)
    638650        rc = -1;
    639651
     
    661673    free(fs_info->uino);
    662674    free(fs_info->sec_buf);
    663     rtems_disk_release(fs_info->vol.dd);
     675    close(fs_info->vol.fd);
    664676
    665677    if (rc)
  • cpukit/libfs/src/dosfs/fat.h

    r1024561 r796967c  
    320320    uint32_t           afat_loc;       /* active FAT location */
    321321    uint8_t            afat;           /* the number of active FAT */
    322     dev_t              dev;            /* device ID */
     322    int                fd;             /* the disk device file descriptor */
    323323    rtems_disk_device *dd;             /* disk device (see libblock) */
    324324    void              *private_data;   /* reserved */
  • cpukit/libfs/src/dosfs/fat_file.c

    r1024561 r796967c  
    796796        {
    797797            /* ... sync it */
    798             sc = rtems_bdbuf_read(fs_info->vol.dev, (sec + i), &block);
     798            sc = rtems_bdbuf_read(fs_info->vol.dd, (sec + i), &block);
    799799            if (sc != RTEMS_SUCCESSFUL)
    800800                rtems_set_errno_and_return_minus_one( EIO );
  • cpukit/libfs/src/dosfs/msdos_dir.c

    r1024561 r796967c  
    533533        rtems_set_errno_and_return_minus_one(EIO);
    534534
    535     buf->st_dev = fs_info->fat.vol.dev;
     535    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
    536536    buf->st_ino = fat_fd->ino;
    537537    buf->st_mode  = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
  • cpukit/libfs/src/dosfs/msdos_file.c

    r1024561 r796967c  
    282282        rtems_set_errno_and_return_minus_one(EIO);
    283283
    284     buf->st_dev = fs_info->fat.vol.dev;
     284    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
    285285    buf->st_ino = fat_fd->ino;
    286286    buf->st_mode  = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
  • cpukit/libfs/src/dosfs/msdos_format.c

    r1024561 r796967c  
    371371| Input Parameters:                                                         |
    372372\*-------------------------------------------------------------------------*/
    373  const rtems_disk_device            *dd,       /* disk device structure          */
     373 int fd,                                       /* disk file descriptor */
    374374 const msdos_format_request_param_t *rqdata,   /* requested fmt parameters */
    375375 msdos_format_param_t               *fmt_params/* computed fmt parameters        */
     
    387387
    388388  memset(fmt_params,0,sizeof(*fmt_params));
     389
    389390  /*
    390391   * this one is fixed in this implementation.
     
    392393   */
    393394  if (ret_val == 0) {
    394     fmt_params->bytes_per_sector = dd->block_size;
    395     fmt_params->totl_sector_cnt  = dd->size;
    396     total_size = dd->block_size * dd->size;
     395    ret_val = rtems_disk_fd_get_block_size(fd, &fmt_params->bytes_per_sector);
     396  }
     397  if (ret_val == 0) {
     398    ret_val = rtems_disk_fd_get_block_count(fd, &fmt_params->totl_sector_cnt);
     399  }
     400  if (ret_val == 0) {
     401    total_size = fmt_params->bytes_per_sector * fmt_params->totl_sector_cnt;
    397402    msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
    398403                         "bytes per sector: %d\ntotal sectors: %d\ntotal size: %lu\n",
    399                          dd->block_size, dd->size, total_size);
    400   }
     404                         fmt_params->bytes_per_sector, fmt_params->totl_sector_cnt, total_size);
     405  }
     406
    401407  /*
    402408   * determine number of FATs
     
    890896  char                 tmp_sec[FAT_TOTAL_MBR_SIZE];
    891897  int                  rc;
    892   rtems_disk_device   *dd        = NULL;
    893898  struct stat          stat_buf;
    894899  int                  ret_val   = 0;
     
    924929  }
    925930
    926   /* check that  device is registered as block device and lock it */
    927   if (ret_val == 0) {
    928     dd = rtems_disk_obtain(stat_buf.st_rdev);
    929     if (dd == NULL) {
    930       errno = ENOTTY;
    931       ret_val = -1;
    932     }
    933   }
    934 
    935931  /*
    936932   * compute formatting parameters
    937933   */
    938934  if (ret_val == 0) {
    939     ret_val = msdos_format_determine_fmt_params(dd,rqdata,&fmt_params);
     935    ret_val = msdos_format_determine_fmt_params(fd,rqdata,&fmt_params);
    940936  }
    941937  /*
     
    11211117    close(fd);
    11221118  }
    1123   if (dd != NULL) {
    1124     rtems_disk_release(dd);
    1125   }
     1119
    11261120  return ret_val;
    11271121}
  • cpukit/libfs/src/rfs/rtems-rfs-buffer.c

    r1024561 r796967c  
    2121#endif
    2222
     23#include <sys/stat.h>
    2324#include <inttypes.h>
    2425#include <errno.h>
     26#include <fcntl.h>
    2527
    2628#include <rtems/rfs/rtems-rfs-buffer.h>
     
    286288{
    287289  struct stat st;
     290#if RTEMS_RFS_USE_LIBBLOCK
     291  int rv;
     292#endif
    288293
    289294  if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
    290295    printf ("rtems-rfs: buffer-open: opening: %s\n", name);
    291296
    292   if (stat (name, &st) < 0)
     297  fs->device = open (name, O_RDWR);
     298  if (fs->device < 0)
     299  {
     300    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
     301      printf ("rtems-rfs: buffer-open: cannot open file\n");
     302    return ENXIO;
     303  }
     304
     305  if (fstat (fs->device, &st) < 0)
    293306  {
    294307    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
    295308      printf ("rtems-rfs: buffer-open: stat '%s' failed: %s\n",
    296309              name, strerror (errno));
    297     return ENOENT;
     310    return ENXIO;
    298311  }
    299312
     
    306319    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
    307320      printf ("rtems-rfs: buffer-open: '%s' is not a block device\n", name);
    308     return EIO;
     321    return ENXIO;
    309322  }
    310323
     
    312325   * Check that device is registred as a block device and lock it.
    313326   */
    314   fs->disk = rtems_disk_obtain (st.st_rdev);
    315   if (!fs->disk)
     327  rv = rtems_disk_fd_get_disk_device (fs->device, &fs->disk);
     328  if (rv != 0)
    316329  {
    317330    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
    318331      printf ("rtems-rfs: buffer-open: cannot obtain the disk\n");
    319     return EIO;
     332    return ENXIO;
    320333  }
    321334#else
    322   fs->device = open (name, O_RDWR);
    323   if (fs->device < 0)
    324   {
    325     if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
    326       printf ("rtems-rfs: buffer-open: cannot open file\n");
    327   }
    328335  fs->media_size = st.st_size;
    329336  strcat (fs->name, name);
     
    356363            rc, strerror (rc));
    357364
    358 #if RTEMS_RFS_USE_LIBBLOCK
    359   rtems_disk_release (fs->disk);
    360 #else
    361365  if (close (fs->device) < 0)
    362366  {
     
    366370              rc, strerror (rc));
    367371  }
    368 #endif
    369372
    370373  return rc;
  • cpukit/libfs/src/rfs/rtems-rfs-file-system.h

    r1024561 r796967c  
    132132  size_t block_size;
    133133
     134  /**
     135   * The file descriptor for device I/O.
     136   */
     137  int device;
     138
    134139#if RTEMS_RFS_USE_LIBBLOCK
    135140  /**
     
    141146#else
    142147  /**
    143    * The device number which is a the file handle for device I/O.
    144    */
    145   dev_t device;
    146 
    147   /**
    148148   * The number of blocks in the file system.
    149149   */
     
    285285 */
    286286#if RTEMS_RFS_USE_LIBBLOCK
    287 #define rtems_rfs_fs_device(_fs) ((_fs)->disk->dev)
     287#define rtems_rfs_fs_device(_fs) ((_fs)->disk)
    288288#else
    289289#define rtems_rfs_fs_device(_fs) ((_fs)->device)
  • testsuites/libtests/block02/init.c

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    4950#define BLOCK_COUNT_B 1
    5051
    51 static dev_t dev_a;
    52 
    53 static dev_t dev_b;
     52static const rtems_disk_device *dd_a;
     53
     54static const rtems_disk_device *dd_b;
    5455
    5556static volatile bool sync_done = false;
     
    6869  printk("L: try access: A0\n");
    6970
    70   sc = rtems_bdbuf_get(dev_a, 0, &bd);
     71  sc = rtems_bdbuf_get(dd_a, 0, &bd);
    7172  ASSERT_SC(sc);
    7273
     
    7576  printk("L: access: A0\n");
    7677
    77   rtems_test_assert(bd->dev == dev_a);
     78  rtems_test_assert(bd->dd == dd_a);
    7879
    7980  printk("*** END OF TEST BLOCK 2 ***\n");
     
    9192  printk("H: try access: A0\n");
    9293
    93   sc = rtems_bdbuf_get(dev_a, 0, &bd);
     94  sc = rtems_bdbuf_get(dd_a, 0, &bd);
    9495  ASSERT_SC(sc);
    9596
     
    107108  printk("H: try access: B0\n");
    108109
    109   sc = rtems_bdbuf_get(dev_b, 0, &bd);
     110  sc = rtems_bdbuf_get(dd_b, 0, &bd);
    110111  ASSERT_SC(sc);
    111112
     
    128129  rtems_status_code sc = RTEMS_SUCCESSFUL;
    129130  rtems_bdbuf_buffer *bd = NULL;
     131  dev_t dev_a = 0;
     132  dev_t dev_b = 0;
    130133
    131134  printk("\n\n*** TEST BLOCK 2 ***\n");
     
    139142  sc = ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, false, "/dev/rdb", &dev_b);
    140143  ASSERT_SC(sc);
     144
     145  dd_a = rtems_disk_obtain(dev_a);
     146  rtems_test_assert(dd_a != NULL);
     147
     148  dd_b = rtems_disk_obtain(dev_b);
     149  rtems_test_assert(dd_b != NULL);
    141150
    142151  sc = rtems_task_create(
     
    166175  ASSERT_SC(sc);
    167176
    168   sc = rtems_bdbuf_get(dev_a, 0, &bd);
     177  sc = rtems_bdbuf_get(dd_a, 0, &bd);
    169178  ASSERT_SC(sc);
    170179
  • testsuites/libtests/block03/init.c

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    4546#define BLOCK_COUNT 2
    4647
    47 static dev_t dev;
     48static const rtems_disk_device *dd;
    4849
    4950static volatile bool sync_done = false;
     
    6263  printk("L: try access: 0\n");
    6364
    64   sc = rtems_bdbuf_get(dev, 0, &bd);
     65  sc = rtems_bdbuf_get(dd, 0, &bd);
    6566  ASSERT_SC(sc);
    6667
     
    8586  printk("H: try access: 0\n");
    8687
    87   sc = rtems_bdbuf_get(dev, 0, &bd);
     88  sc = rtems_bdbuf_get(dd, 0, &bd);
    8889  ASSERT_SC(sc);
    8990
     
    101102  printk("H: try access: 1\n");
    102103
    103   sc = rtems_bdbuf_get(dev, 1, &bd);
     104  sc = rtems_bdbuf_get(dd, 1, &bd);
    104105  ASSERT_SC(sc);
    105106
     
    122123  rtems_status_code sc = RTEMS_SUCCESSFUL;
    123124  rtems_bdbuf_buffer *bd = NULL;
     125  dev_t dev = 0;
    124126
    125127  printk("\n\n*** TEST BLOCK 3 ***\n");
     
    130132  sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
    131133  ASSERT_SC(sc);
     134
     135  dd = rtems_disk_obtain(dev);
     136  rtems_test_assert(dd != NULL);
    132137
    133138  sc = rtems_task_create(
     
    157162  ASSERT_SC(sc);
    158163
    159   sc = rtems_bdbuf_get(dev, 0, &bd);
     164  sc = rtems_bdbuf_get(dd, 0, &bd);
    160165  ASSERT_SC(sc);
    161166
  • testsuites/libtests/block04/init.c

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    4546#define BLOCK_COUNT 1
    4647
    47 static dev_t dev;
     48static const rtems_disk_device *dd;
    4849
    4950static rtems_id task_id_low;
     
    5859  printk("L: try access: 0\n");
    5960
    60   sc = rtems_bdbuf_get(dev, 0, &bd);
     61  sc = rtems_bdbuf_get(dd, 0, &bd);
    6162  ASSERT_SC(sc);
    6263
     
    8485  printk("H: try access: 0\n");
    8586
    86   sc = rtems_bdbuf_get(dev, 0, &bd);
     87  sc = rtems_bdbuf_get(dd, 0, &bd);
    8788  ASSERT_SC(sc);
    8889
     
    104105{
    105106  rtems_status_code sc = RTEMS_SUCCESSFUL;
     107  dev_t dev = 0;
    106108
    107109  printk("\n\n*** TEST BLOCK 4 ***\n");
     
    112114  sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
    113115  ASSERT_SC(sc);
     116
     117  dd = rtems_disk_obtain(dev);
     118  rtems_test_assert(dd != NULL);
    114119
    115120  sc = rtems_task_create(
  • testsuites/libtests/block05/init.c

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    5758static unsigned output_level = 0;
    5859
    59 static dev_t dev_a;
    60 
    61 static dev_t dev_b;
     60static const rtems_disk_device *dd_a;
     61
     62static const rtems_disk_device *dd_b;
    6263
    6364static rtems_id task_id_init;
     
    147148  rtems_bdbuf_buffer *bd = NULL;
    148149  rtems_blkdev_bnum blk_index = 0;
    149   rtems_status_code (*get_bd)(dev_t, rtems_blkdev_bnum, rtems_bdbuf_buffer **)
    150     = NULL;
    151   dev_t dev = 0;
     150  rtems_status_code (*get_bd)(
     151    const rtems_disk_device *,
     152    rtems_blkdev_bnum,
     153    rtems_bdbuf_buffer **
     154  ) = NULL;
     155  const rtems_disk_device *dd = NULL;
    152156  size_t bds_per_group = 0;
    153157
    154158  switch (kind) {
    155159    case BLK_A0:
    156       dev = dev_a;
     160      dd = dd_a;
    157161      blk_index = 0;
    158162      bds_per_group = 2;
    159163      break;
    160164    case BLK_A1:
    161       dev = dev_a;
     165      dd = dd_a;
    162166      blk_index = 1;
    163167      bds_per_group = 2;
    164168      break;
    165169    case BLK_B0:
    166       dev = dev_b;
     170      dd = dd_b;
    167171      blk_index = 0;
    168172      bds_per_group = 1;
     
    185189  }
    186190
    187   sc = (*get_bd)(dev, blk_index, &bd);
     191  sc = (*get_bd)(dd, blk_index, &bd);
    188192  rtems_test_assert(
    189193    sc == RTEMS_SUCCESSFUL
    190       && bd->dev == dev
     194      && bd->dd == dd
    191195      && bd->block == blk_index
    192196      && bd->group->bds_per_group == bds_per_group
     
    314318  ASSERT_SC(sc);
    315319
    316   sc = rtems_bdbuf_get(dev_b, 0, &bd);
    317   rtems_test_assert(sc == RTEMS_SUCCESSFUL && bd->dev == dev_b && bd->block == 0);
     320  sc = rtems_bdbuf_get(dd_b, 0, &bd);
     321  rtems_test_assert(sc == RTEMS_SUCCESSFUL && bd->dd == dd_b && bd->block == 0);
    318322
    319323  sc = rtems_bdbuf_release(bd);
     
    351355  print(2, "F\n");
    352356
    353   sc = rtems_bdbuf_syncdev(dev_a);
    354   ASSERT_SC(sc);
    355 
    356   sc = rtems_bdbuf_syncdev(dev_b);
     357  sc = rtems_bdbuf_syncdev(dd_a);
     358  ASSERT_SC(sc);
     359
     360  sc = rtems_bdbuf_syncdev(dd_b);
    357361  ASSERT_SC(sc);
    358362}
     
    384388}
    385389
    386 rtems_status_code disk_register(
     390static void disk_register(
    387391  uint32_t block_size,
    388392  rtems_blkdev_bnum block_count,
    389   dev_t *dev_ptr
     393  const rtems_disk_device **dd_ptr
    390394)
    391395{
     
    409413  ASSERT_SC(sc);
    410414
    411   *dev_ptr = dev;
    412 
    413   return RTEMS_SUCCESSFUL;
     415  *dd_ptr = rtems_disk_obtain(dev);
     416  rtems_test_assert(*dd_ptr!= NULL);
    414417}
    415418
     
    426429  ASSERT_SC(sc);
    427430
    428   sc = disk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, &dev_a);
    429   ASSERT_SC(sc);
    430 
    431   sc = disk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, &dev_b);
    432   ASSERT_SC(sc);
     431  disk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, &dd_a);
     432
     433  disk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, &dd_b);
    433434
    434435  sc = rtems_task_create(
  • testsuites/libtests/block06/init.c

    r1024561 r796967c  
    108108  rtems_device_minor_number minor;
    109109  bool                      passed;
     110  const rtems_disk_device  *dd;
    110111} bdbuf_task_control;
    111112
     
    189190 * BDBUf wait for the wait event.
    190191 */
    191 rtems_status_code
     192static rtems_status_code
    192193bdbuf_wait (const char* who, unsigned long timeout)
    193194{
     
    341342                         bdbuf_task_control*       tc,
    342343                         rtems_id                  master,
    343                          rtems_device_major_number major)
     344                         rtems_device_major_number major,
     345                         const rtems_disk_device  *dd)
    344346{
    345347  char name[6];
     
    354356  tc->minor  = 0;
    355357  tc->passed = false;
     358  tc->dd     = dd;
    356359}
    357360
     
    609612
    610613static bool
    611 bdbuf_tests_setup_disk (rtems_device_major_number* major)
     614bdbuf_tests_setup_disk (rtems_device_major_number* major,
     615                        const rtems_disk_device **dd_ptr)
    612616{
    613617  rtems_status_code sc;
     618  bool ok;
    614619
    615620  /*
     
    621626                                 &bdbuf_disk_io_ops,
    622627                                 major);
    623 
    624   return sc == RTEMS_SUCCESSFUL;
     628  ok = sc == RTEMS_SUCCESSFUL;
     629
     630  if (ok) {
     631    *dd_ptr = rtems_disk_obtain (rtems_filesystem_make_dev_t (*major, 0));
     632    ok = *dd_ptr != NULL;
     633  }
     634
     635  return ok;
    625636}
    626637
     
    673684  for (i = 0; (i < 2) && passed; i++)
    674685  {
    675     dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    676 
    677686    bdbuf_test_printf ("%s: rtems_bdbuf_get[0]: ", tc->name);
    678     sc = rtems_bdbuf_get (device, 0, &bd);
     687    sc = rtems_bdbuf_get (tc->dd, 0, &bd);
    679688    if (!bdbuf_test_print_sc (sc, true))
    680689    {
     
    723732  for (i = 0; (i < 5) && passed; i++)
    724733  {
    725     dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    726 
    727734    bdbuf_test_printf ("%s: rtems_bdbuf_get[%d]: ", tc->name, i);
    728     sc = rtems_bdbuf_get (device, i, &bd);
     735    sc = rtems_bdbuf_get (tc->dd, i, &bd);
    729736    if (!bdbuf_test_print_sc (sc, true))
    730737      passed = false;
     
    784791  bool                passed;
    785792  rtems_bdbuf_buffer* bd;
    786   dev_t               device;
    787793
    788794  /*
     
    791797  tc->passed = false;
    792798  passed = true;
    793 
    794   device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    795799
    796800  bdbuf_disk_lock (&bdbuf_disks[tc->minor]);
     
    802806   */
    803807  bdbuf_test_printf ("%s: rtems_bdbuf_read[5]: ", tc->name);
    804   sc = rtems_bdbuf_read (device, 5, &bd);
     808  sc = rtems_bdbuf_read (tc->dd, 5, &bd);
    805809  if ((passed = bdbuf_test_print_sc (sc, true)))
    806810  {
     
    815819   */
    816820  bdbuf_test_printf ("%s: rtems_bdbuf_read[5]: ", tc->name);
    817   sc = rtems_bdbuf_read (device, 5, &bd);
     821  sc = rtems_bdbuf_read (tc->dd, 5, &bd);
    818822  if ((passed = bdbuf_test_print_sc (sc, true)))
    819823  {
     
    872876  for (i = 0; (i < num) && passed; i++)
    873877  {
    874     dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    875 
    876878    bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
    877     sc = rtems_bdbuf_read (device, i, &bd);
     879    sc = rtems_bdbuf_read (tc->dd, i, &bd);
    878880    if (!bdbuf_test_print_sc (sc, true))
    879881      passed = false;
     
    992994  for (i = 0; (i < 5) && passed; i++)
    993995  {
    994     dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    995 
    996996    bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
    997     sc = rtems_bdbuf_get (device, i, &bd);
     997    sc = rtems_bdbuf_get (tc->dd, i, &bd);
    998998    if (!bdbuf_test_print_sc (sc, true))
    999999      passed = false;
     
    10311031  rtems_bdbuf_buffer* bd;
    10321032  rtems_chain_control buffers;
    1033   dev_t               device;
    10341033
    10351034  /*
     
    10451044  bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP);
    10461045
    1047   device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    1048 
    10491046  /*
    10501047   * Get the blocks 0 -> 4 and hold them.
     
    10551052  {
    10561053    bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
    1057     sc = rtems_bdbuf_get (device, i, &bd);
     1054    sc = rtems_bdbuf_get (tc->dd, i, &bd);
    10581055    if (!bdbuf_test_print_sc (sc, true))
    10591056      passed = false;
     
    10751072    bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: ",
    10761073                       tc->name, i,
    1077                        rtems_filesystem_dev_major_t (device),
    1078                        rtems_filesystem_dev_minor_t (device));
    1079     passed = bdbuf_test_print_sc (rtems_bdbuf_syncdev (device), true);
     1074                       tc->major,
     1075                       tc->minor);
     1076    passed = bdbuf_test_print_sc (rtems_bdbuf_syncdev (tc->dd), true);
    10801077  }
    10811078
     
    10941091  rtems_chain_node*   node;
    10951092  rtems_chain_node*   pnode;
    1096   dev_t               device;
    10971093
    10981094  /*
     
    11081104  bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP);
    11091105
    1110   device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    1111 
    11121106  /*
    11131107   * Get the blocks 0 -> 4 and hold them.
     
    11181112  {
    11191113    bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
    1120     sc = rtems_bdbuf_get (device, i, &bd);
     1114    sc = rtems_bdbuf_get (tc->dd, i, &bd);
    11211115    if (!bdbuf_test_print_sc (sc, true))
    11221116      passed = false;
     
    11601154    bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: checking order\n",
    11611155                       tc->name, i,
    1162                        rtems_filesystem_dev_major_t (device),
    1163                        rtems_filesystem_dev_minor_t (device));
    1164     sc = rtems_bdbuf_syncdev (device);
     1156                       tc->major,
     1157                       tc->minor);
     1158    sc = rtems_bdbuf_syncdev (tc->dd);
    11651159    bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: ",
    11661160                       tc->name, i,
    1167                        rtems_filesystem_dev_major_t (device),
    1168                        rtems_filesystem_dev_minor_t (device));
     1161                       tc->major,
     1162                       tc->minor);
    11691163    passed = bdbuf_test_print_sc (sc, true);
    11701164  }
     
    12601254  for (i = lower; (i < upper) && passed; i++)
    12611255  {
    1262     dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
    1263 
    12641256    bdbuf_test_printf ("%s: rtems_bdbuf_get[%d]: blocking ...\n", tc->name, i);
    1265     sc = rtems_bdbuf_get (device, i, &bd);
     1257    sc = rtems_bdbuf_get (tc->dd, i, &bd);
    12661258    bdbuf_test_printf ("%s: rtems_bdbuf_get[%d]: ", tc->name, i);
    12671259    if (!bdbuf_test_print_sc (sc, true))
     
    17711763  int                       t;
    17721764  bool                      passed = true;
     1765  const rtems_disk_device *dd;
    17731766
    17741767  /*
     
    17841777   * This sets up the buffer pools.
    17851778   */
    1786   if (!bdbuf_tests_setup_disk (&major))
     1779  if (!bdbuf_tests_setup_disk (&major, &dd))
    17871780  {
    17881781    bdbuf_test_printf ("disk set up failed\n");
     
    18051798    bdbuf_task_control_init (t, &tasks[t],
    18061799                             rtems_task_self (),
    1807                              major);
     1800                             major,
     1801                             dd);
    18081802
    18091803    if (!bdbuf_tests_create_task (&tasks[t],
  • testsuites/libtests/block07/init.c

    r1024561 r796967c  
    5555#define BLOCK_COUNT 2
    5656
    57 static dev_t dev;
     57static rtems_disk_device *dd;
    5858
    5959static rtems_id task_id_low;
     
    6666{
    6767  int rv = 0;
    68   uint32_t new_block_size = BLOCK_SIZE_B;
    6968  int fd = open("/dev/rda", O_RDWR);
    7069
    7170  rtems_test_assert(fd >= 0);
    7271
    73   rv = ioctl(fd, RTEMS_BLKIO_SETBLKSIZE, &new_block_size);
     72  rv = rtems_disk_fd_set_block_size(fd, BLOCK_SIZE_B);
    7473  rtems_test_assert(rv == 0);
    7574
     
    8584  printk("L: try access: 0\n");
    8685
    87   sc = rtems_bdbuf_get(dev, 0, &bd);
     86  sc = rtems_bdbuf_get(dd, 0, &bd);
    8887  ASSERT_SC(sc);
    8988
     
    111110  printk("M: try access: 0\n");
    112111
    113   sc = rtems_bdbuf_get(dev, 0, &bd);
     112  sc = rtems_bdbuf_get(dd, 0, &bd);
    114113  ASSERT_SC(sc);
    115114
     
    137136  printk("H: try access: 0\n");
    138137
    139   sc = rtems_bdbuf_get(dev, 0, &bd);
     138  sc = rtems_bdbuf_get(dd, 0, &bd);
    140139  ASSERT_SC(sc);
    141140
     
    159158  rtems_task_priority cur_prio = 0;
    160159  rtems_bdbuf_buffer *bd = NULL;
     160  dev_t dev = 0;
    161161
    162162  printk("\n\n*** TEST BLOCK 7 ***\n");
     
    167167  sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
    168168  ASSERT_SC(sc);
     169
     170  dd = rtems_disk_obtain(dev);
     171  rtems_test_assert(dd != NULL);
    169172
    170173  sc = rtems_task_create(
     
    213216  ASSERT_SC(sc);
    214217
    215   sc = rtems_bdbuf_get(dev, 1, &bd);
     218  sc = rtems_bdbuf_get(dd, 1, &bd);
    216219  ASSERT_SC(sc);
    217220
     
    221224  printk("I: try access: 0\n");
    222225
    223   sc = rtems_bdbuf_get(dev, 0, &bd);
     226  sc = rtems_bdbuf_get(dd, 0, &bd);
    224227  ASSERT_SC(sc);
    225228
  • testsuites/libtests/block08/bdbuf_test1_1.c

    r1024561 r796967c  
    107107     * Successful read operation.
    108108     */
    109     rc = rtems_bdbuf_read(test_dev, 0, &bd1);
     109    rc = rtems_bdbuf_read(test_dd, 0, &bd1);
    110110    if (rc != RTEMS_SUCCESSFUL)
    111111    {
     
    125125     * The function shall not update user pointer.
    126126     */
    127     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd2);
     127    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd2);
    128128    if (rc != RTEMS_IO_ERROR || bd2 != NULL)
    129129    {
     
    138138     * The function shall not update user pointer.
    139139     */
    140     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd2);
     140    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd2);
    141141    if (rc != RTEMS_IO_ERROR || bd2 != NULL)
    142142    {
  • testsuites/libtests/block08/bdbuf_test1_2.c

    r1024561 r796967c  
    123123     * result this call will return an error.
    124124     */
    125     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     125    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    126126    if (rc != RTEMS_IO_ERROR || bd != NULL)
    127127    {
     
    153153     * RTEMS_IO_ERROR data transfer result.
    154154     */
    155     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     155    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    156156    if (rc != RTEMS_IO_ERROR || bd != NULL)
    157157    {
  • testsuites/libtests/block08/bdbuf_test1_3.c

    r1024561 r796967c  
    132132     * result this call will return an error.
    133133     */
    134     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     134    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    135135    if (rc != RTEMS_IO_ERROR || bd != NULL)
    136136    {
     
    161161     * Time time main task will tell driver to report success.
    162162     */
    163     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     163    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    164164    if (rc != RTEMS_SUCCESSFUL || bd == NULL)
    165165    {
  • testsuites/libtests/block08/bdbuf_test1_4.c

    r1024561 r796967c  
    126126     * will return valid buffer.
    127127     */
    128     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     128    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    129129    if (rc != RTEMS_SUCCESSFUL)
    130130    {
     
    162162     * our read operation should finish with success.
    163163     */
    164     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     164    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    165165    if (rc != RTEMS_SUCCESSFUL)
    166166    {
  • testsuites/libtests/block08/bdbuf_test1_5.c

    r1024561 r796967c  
    102102     * read blk #N on thread #1
    103103     */
    104     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     104    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    105105    if (rc != RTEMS_SUCCESSFUL)
    106106    {
     
    134134     * this buffer, so we will block waiting for buffer.
    135135     */
    136     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     136    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    137137    if (rc != RTEMS_SUCCESSFUL)
    138138    {
  • testsuites/libtests/block08/bdbuf_test2_1.c

    r1024561 r796967c  
    143143     * will return valid buffer.
    144144     */
    145     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     145    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    146146    if (rc != RTEMS_SUCCESSFUL)
    147147    {
     
    179179     * our read operation should finish with success.
    180180     */
    181     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     181    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    182182    if (rc != RTEMS_SUCCESSFUL)
    183183    {
  • testsuites/libtests/block08/bdbuf_test2_2.c

    r1024561 r796967c  
    143143     * will return valid buffer.
    144144     */
    145     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     145    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    146146    if (rc != RTEMS_SUCCESSFUL)
    147147    {
     
    179179     * our read operation should finish with success.
    180180     */
    181     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
     181    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
    182182    if (rc != RTEMS_SUCCESSFUL)
    183183    {
  • testsuites/libtests/block08/bdbuf_test3_1.c

    r1024561 r796967c  
    117117     * returned with state ACCESS_MODIFIED]
    118118     */
    119     rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_N, &bd);
     119    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_N, &bd);
    120120    if (rc != RTEMS_SUCCESSFUL)
    121121    {
     
    129129    }
    130130
    131     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     131    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    132132    if (rc != RTEMS_SUCCESSFUL)
    133133    {
     
    167167     * rtems_bdbuf_wait(pool, &pool->waiting, &pool->wait_waiters)]
    168168     */
    169     rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_M, &bd);
     169    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_M, &bd);
    170170    if (rc != RTEMS_SUCCESSFUL)
    171171    {
  • testsuites/libtests/block08/bdbuf_test3_2.c

    r1024561 r796967c  
    118118     * Call rtems_bdbuf_read(#N) to get a buffer;
    119119     */
    120     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N1, &bd);
     120    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N1, &bd);
    121121    if (rc != RTEMS_SUCCESSFUL)
    122122    {
     
    151151     * In thread #2 call get(#N2)
    152152     */
    153     rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_N2, &bd);
     153    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_N2, &bd);
    154154    if (rc != RTEMS_SUCCESSFUL)
    155155    {
     
    181181     * In thread #3 call get(#N3)
    182182     */
    183     rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_N3, &bd);
     183    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_N3, &bd);
    184184    if (rc != RTEMS_SUCCESSFUL)
    185185    {
  • testsuites/libtests/block08/bdbuf_test3_3.c

    r1024561 r796967c  
    129129     * Call rtems_bdbuf_read(#N) to get a buffer;
    130130     */
    131     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N1, &bd);
     131    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N1, &bd);
    132132    if (rc != RTEMS_SUCCESSFUL)
    133133    {
     
    162162     * In thread #2 call read(#N2)
    163163     */
    164     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N2, &bd);
     164    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N2, &bd);
    165165    if (rc != RTEMS_SUCCESSFUL)
    166166    {
     
    192192     * In thread #3 call read(#N3)
    193193     */
    194     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N3, &bd);
     194    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N3, &bd);
    195195    if (rc != RTEMS_SUCCESSFUL)
    196196    {
  • testsuites/libtests/block08/bdbuf_test4_1.c

    r1024561 r796967c  
    123123     * Call rtems_bdbuf_read(#N) in thread #1;
    124124     */
    125     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     125    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    126126    if (rc != RTEMS_SUCCESSFUL)
    127127    {
     
    159159     * We will block on this call.
    160160     */
    161     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     161    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    162162    if (rc != RTEMS_SUCCESSFUL)
    163163    {
  • testsuites/libtests/block08/bdbuf_test4_2.c

    r1024561 r796967c  
    110110     * Call rtems_bdbuf_read(#N) in thread #1;
    111111     */
    112     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     112    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    113113    if (rc != RTEMS_SUCCESSFUL)
    114114    {
     
    144144     * We will block on this call.
    145145     */
    146     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     146    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    147147    if (rc != RTEMS_SUCCESSFUL)
    148148    {
  • testsuites/libtests/block08/bdbuf_test4_3.c

    r1024561 r796967c  
    104104     * Call rtems_bdbuf_read(#N) in thread #1;
    105105     */
    106     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     106    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    107107    if (rc != RTEMS_SUCCESSFUL)
    108108    {
     
    138138     * We will block on this call.
    139139     */
    140     rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
     140    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
    141141    if (rc != RTEMS_SUCCESSFUL)
    142142    {
  • testsuites/libtests/block08/bdbuf_tests.c

    r1024561 r796967c  
    5050
    5151/** Device ID used for testing */
    52 dev_t      test_dev = (dev_t)-1;
     52const rtems_disk_device *test_dd = NULL;
    5353
    5454/** Test result variable */
     
    109109    rtems_status_code   sc;
    110110    dev_t               dev = -1;
     111    dev_t               test_dev;
    111112    unsigned int        i;
    112113
     
    151152    {
    152153        printf("Failed to find %s disk\n", TEST_DISK_NAME);
     154        return;
     155    }
     156
     157    test_dd = rtems_disk_obtain(test_dev);
     158    if (test_dd == NULL)
     159    {
     160        printf("Failed to obtain %s disk\n", TEST_DISK_NAME);
    153161        return;
    154162    }
  • testsuites/libtests/block08/bdbuf_tests.h

    r1024561 r796967c  
    8686    union {
    8787        struct driver_req {
    88             dev_t     dev;
     88            const rtems_disk_device *dd;
    8989            uint32_t  req;
    9090            void     *argp;
     
    153153
    154154/** Device ID used for testing */
    155 extern dev_t      test_dev;
     155extern const rtems_disk_device *test_dd;
    156156
    157157/**
     
    260260        WAIT_DRV_MSG(msg_);                                             \
    261261        if ((msg_)->val.driver_req.req != RTEMS_BLKIO_REQUEST ||        \
    262             (msg_)->val.driver_req.dev != test_dev ||                   \
     262            (msg_)->val.driver_req.dd != test_dd ||                   \
    263263            ((rtems_blkdev_request *)                                   \
    264264                 ((msg_)->val.driver_req.argp))->req !=                 \
     
    268268                   "req - 0x%x (0x%x), dev - %d (%d)\n",                \
    269269                   (msg_)->val.driver_req.req, RTEMS_BLKIO_REQUEST,     \
    270                    (msg_)->val.driver_req.dev, test_dev);               \
     270                   (msg_)->val.driver_req.dd, test_dd);               \
    271271            return;                                                     \
    272272        }                                                               \
  • testsuites/libtests/block08/test_disk.c

    r1024561 r796967c  
    3535test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
    3636{
    37     dev_t             dev = rtems_disk_get_device_identifier(dd);
    3837    rtems_status_code rc;
    3938    bdbuf_test_msg    msg;
     
    6766    memset(&msg, 0, sizeof(msg));
    6867    msg.type = BDBUF_TEST_MSG_TYPE_DRIVER_REQ;
    69     msg.val.driver_req.dev = dev;
     68    msg.val.driver_req.dd = dd;
    7069    msg.val.driver_req.req = req;
    7170    msg.val.driver_req.argp = argp;
  • testsuites/libtests/block09/init.c

    r1024561 r796967c  
    88
    99/*
    10  * Copyright (c) 2009
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    109110}
    110111
    111 rtems_status_code disk_register(
     112static rtems_status_code disk_register(
    112113  uint32_t block_size,
    113114  rtems_blkdev_bnum block_count,
     
    140141
    141142static void check_read(
    142   dev_t dev,
     143  const rtems_disk_device *dd,
    143144  rtems_blkdev_bnum block,
    144145  rtems_status_code expected_sc
     
    148149  rtems_bdbuf_buffer *bd = NULL;
    149150
    150   sc = rtems_bdbuf_read(dev, block, &bd);
     151  sc = rtems_bdbuf_read(dd, block, &bd);
    151152  assert(sc == expected_sc);
    152153
     
    162163  rtems_bdbuf_buffer *bd = NULL;
    163164  dev_t dev = 0;
     165  rtems_disk_device *dd = NULL;
    164166
    165167  printk("\n\n*** TEST BLOCK 9 ***\n");
     
    171173  ASSERT_SC(sc);
    172174
    173   check_read(dev, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
    174   check_read(dev, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
    175   check_read(dev, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
    176   check_read(dev, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);
     175  dd = rtems_disk_obtain(dev);
     176  assert(dd != NULL);
     177
     178  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
     179  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
     180  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
     181  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);
    177182
    178183  /* Check write IO error */
    179184
    180   sc = rtems_bdbuf_read(dev, BLOCK_WRITE_IO_ERROR, &bd);
     185  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
    181186  ASSERT_SC(sc);
    182187
     
    186191  ASSERT_SC(sc);
    187192
    188   sc = rtems_bdbuf_read(dev, BLOCK_WRITE_IO_ERROR, &bd);
     193  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
    189194  ASSERT_SC(sc);
    190195
     
    196201  /* Check write to deleted disk */
    197202
    198   sc = rtems_bdbuf_read(dev, BLOCK_READ_SUCCESSFUL, &bd);
     203  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
    199204  ASSERT_SC(sc);
    200205
     
    203208
    204209  sc = rtems_bdbuf_sync(bd);
     210  ASSERT_SC(sc);
     211
     212  sc = rtems_disk_release(dd);
    205213  ASSERT_SC(sc);
    206214
  • testsuites/libtests/block10/init.c

    r1024561 r796967c  
    5353typedef void (*release_func)(char task, rtems_bdbuf_buffer *bd);
    5454
    55 static dev_t dev;
     55static const rtems_disk_device *dd;
    5656
    5757static rtems_id task_id_init;
     
    111111}
    112112
    113 rtems_status_code disk_register(
     113static rtems_status_code disk_register(
    114114  uint32_t block_size,
    115115  rtems_blkdev_bnum block_count,
     
    148148  printk("%c: try get\n", task);
    149149
    150   sc = rtems_bdbuf_get(dev, 0, &bd);
     150  sc = rtems_bdbuf_get(dd, 0, &bd);
    151151  ASSERT_SC(sc);
    152152
     
    163163  printk("%c: try get modified\n", task);
    164164
    165   sc = rtems_bdbuf_get(dev, 0, &bd);
     165  sc = rtems_bdbuf_get(dd, 0, &bd);
    166166  ASSERT_SC(sc);
    167167
     
    169169  ASSERT_SC(sc);
    170170
    171   sc = rtems_bdbuf_get(dev, 0, &bd);
     171  sc = rtems_bdbuf_get(dd, 0, &bd);
    172172  ASSERT_SC(sc);
    173173
     
    184184  printk("%c: try read\n", task);
    185185
    186   sc = rtems_bdbuf_read(dev, 0, &bd);
     186  sc = rtems_bdbuf_read(dd, 0, &bd);
    187187  ASSERT_SC(sc);
    188188
     
    204204}
    205205
    206 void do_rel_mod(char task, rtems_bdbuf_buffer *bd)
     206static void do_rel_mod(char task, rtems_bdbuf_buffer *bd)
    207207{
    208208  rtems_status_code sc = RTEMS_SUCCESSFUL;
     
    232232  printk("%c: purge\n", task);
    233233
    234   rtems_bdbuf_purge_dev(dev);
     234  rtems_bdbuf_purge_dev(dd);
    235235}
    236236
     
    388388{
    389389  rtems_status_code sc = RTEMS_SUCCESSFUL;
     390  dev_t dev = 0;
    390391  size_t i_w = 0;
    391392  size_t i_ac = 0;
     
    402403  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
    403404  ASSERT_SC(sc);
     405
     406  dd = rtems_disk_obtain(dev);
     407  assert(dd != NULL);
    404408
    405409  sc = rtems_task_create(
  • testsuites/samples/fileio/init.c

    r1024561 r796967c  
    326326
    327327static int
    328 disk_test_set_block_size (dev_t dev, size_t size)
    329 {
    330   rtems_disk_device* dd;
    331   int                rc;
    332  
    333   dd = rtems_disk_obtain (dev);
    334   if (!dd)
    335   {
    336     printf ("error: cannot obtain disk\n");
    337     return 1;
    338   }
    339  
    340   rc = dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
    341 
    342   rtems_disk_release (dd);
    343 
    344   return rc;
     328disk_test_set_block_size (rtems_disk_device *dd, size_t size)
     329{
     330  return dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
    345331}
    346332
     
    354340  rtems_bdbuf_buffer* bd;
    355341  rtems_status_code   sc;
    356  
    357   if (disk_test_set_block_size (dev, size) < 0)
     342  int                 rv = 0;
     343  rtems_disk_device* dd;
     344 
     345  dd = rtems_disk_obtain (dev);
     346  if (!dd)
     347  {
     348    printf ("error: cannot obtain disk\n");
     349    rv = 1;
     350  }
     351 
     352  if (rv == 0 && disk_test_set_block_size (dd, size) < 0)
    358353  {
    359354    printf ("error: set block size failed: %s\n", strerror (errno));
    360     return 1;
    361   }
    362 
    363   for (block = start; block < (start + count); block++)
    364   {
    365     sc = rtems_bdbuf_read (dev, block, &bd);
    366     if (sc != RTEMS_SUCCESSFUL)
     355    rv = 1;
     356  }
     357
     358  for (block = start; rv == 0 && block < (start + count); block++)
     359  {
     360    sc = rtems_bdbuf_read (dd, block, &bd);
     361    if (sc == RTEMS_SUCCESSFUL)
     362    {
     363      ip = (uint32_t*) bd->buffer;
     364      for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
     365        *ip = (size << 16) | value;
     366
     367      sc = rtems_bdbuf_release_modified (bd);
     368      if (sc != RTEMS_SUCCESSFUL)
     369      {
     370        printf ("error: release block %d bd failed: %s\n",
     371                block, rtems_status_text (sc));
     372        rv = 1;
     373      }
     374    }
     375    else
    367376    {
    368377      printf ("error: get block %d bd failed: %s\n",
    369378              block, rtems_status_text (sc));
    370       return 1;
    371     }
    372 
    373     ip = (uint32_t*) bd->buffer;
    374     for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
    375       *ip = (size << 16) | value;
    376 
    377     sc = rtems_bdbuf_release_modified (bd);
    378     if (sc != RTEMS_SUCCESSFUL)
    379     {
    380       printf ("error: release block %d bd failed: %s\n",
    381               block, rtems_status_text (sc));
    382       return 1;
    383     }
    384   }
    385 
    386   return 0;
     379      rv = 1;
     380    }
     381  }
     382
     383  rtems_disk_release (dd);
     384
     385  return rv;
    387386}
    388387
Note: See TracChangeset for help on using the changeset viewer.