[rtems commit] libblock: Change bdbuf API

Joel Sherrill joel at rtems.org
Thu Mar 29 14:14:30 UTC 2012


Module:    rtems
Branch:    master
Commit:    fbb98c58edfb0fd15a7e59acea8a7ac675a582ed
Changeset: http://git.rtems.org/rtems/commit/?id=fbb98c58edfb0fd15a7e59acea8a7ac675a582ed

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Feb 28 17:19:49 2012 +0100

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.

---

 cpukit/libblock/include/rtems/bdbuf.h        |   39 ++---
 cpukit/libblock/include/rtems/bdpart.h       |   16 +-
 cpukit/libblock/src/bdbuf.c                  |  237 +++++++++-----------------
 cpukit/libblock/src/bdpart-create.c          |   13 +-
 cpukit/libblock/src/bdpart-read.c            |   65 +++++---
 cpukit/libblock/src/bdpart-register.c        |   12 +-
 cpukit/libblock/src/bdpart-write.c           |   17 ++-
 cpukit/libblock/src/blkdev.c                 |   10 +-
 cpukit/libblock/src/media.c                  |   15 ++-
 cpukit/libfs/src/dosfs/fat.c                 |   76 +++++----
 cpukit/libfs/src/dosfs/fat.h                 |    2 +-
 cpukit/libfs/src/dosfs/fat_file.c            |    2 +-
 cpukit/libfs/src/dosfs/msdos_dir.c           |    2 +-
 cpukit/libfs/src/dosfs/msdos_file.c          |    2 +-
 cpukit/libfs/src/dosfs/msdos_format.c        |   32 ++--
 cpukit/libfs/src/rfs/rtems-rfs-buffer.c      |   35 ++--
 cpukit/libfs/src/rfs/rtems-rfs-file-system.h |   12 +-
 testsuites/libtests/block02/init.c           |   35 +++--
 testsuites/libtests/block03/init.c           |   27 ++--
 testsuites/libtests/block04/init.c           |   23 ++-
 testsuites/libtests/block05/init.c           |   59 ++++---
 testsuites/libtests/block06/init.c           |   78 ++++-----
 testsuites/libtests/block07/init.c           |   19 ++-
 testsuites/libtests/block08/bdbuf_test1_1.c  |    6 +-
 testsuites/libtests/block08/bdbuf_test1_2.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test1_3.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test1_4.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test1_5.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test2_1.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test2_2.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test3_1.c  |    6 +-
 testsuites/libtests/block08/bdbuf_test3_2.c  |    6 +-
 testsuites/libtests/block08/bdbuf_test3_3.c  |    6 +-
 testsuites/libtests/block08/bdbuf_test4_1.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test4_2.c  |    4 +-
 testsuites/libtests/block08/bdbuf_test4_3.c  |    4 +-
 testsuites/libtests/block08/bdbuf_tests.c    |   10 +-
 testsuites/libtests/block08/bdbuf_tests.h    |    8 +-
 testsuites/libtests/block08/test_disk.c      |    3 +-
 testsuites/libtests/block09/init.c           |   40 +++--
 testsuites/libtests/block10/init.c           |   20 ++-
 testsuites/samples/fileio/init.c             |   67 ++++----
 42 files changed, 517 insertions(+), 519 deletions(-)

diff --git a/cpukit/libblock/include/rtems/bdbuf.h b/cpukit/libblock/include/rtems/bdbuf.h
index 37e06aa..254c745 100644
--- a/cpukit/libblock/include/rtems/bdbuf.h
+++ b/cpukit/libblock/include/rtems/bdbuf.h
@@ -301,7 +301,7 @@ typedef struct rtems_bdbuf_group rtems_bdbuf_group;
  * To manage buffers we using buffer descriptors (BD). A BD holds a buffer plus
  * a range of other information related to managing the buffer in the cache. To
  * speed-up buffer lookup descriptors are organized in AVL-Tree. The fields
- * 'dev' and 'block' are search keys.
+ * 'dd' and 'block' are search keys.
  */
 typedef struct rtems_bdbuf_buffer
 {
@@ -315,7 +315,7 @@ typedef struct rtems_bdbuf_buffer
     signed char                bal;    /**< The balance of the sub-tree */
   } avl;
 
-  dev_t             dev;        /**< device number */
+  const rtems_disk_device *dd;  /**< disk device */
 
   rtems_blkdev_bnum block;      /**< block number on the device */
 
@@ -470,8 +470,7 @@ rtems_bdbuf_init (void);
  * The block number is the linear block number. This is relative to the start
  * of the partition on the media.
  *
- * @param device [in] Device number (constructed of major and minor device
- * number).
+ * @param dd [in] The disk device.
  * @param block [in] Linear media block number.
  * @param bd [out] Reference to the buffer descriptor pointer.
  *
@@ -481,7 +480,11 @@ rtems_bdbuf_init (void);
  * @retval RTEMS_INVALID_NUMBER Invalid block size.
  */
 rtems_status_code
-rtems_bdbuf_get (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
+rtems_bdbuf_get (
+  const rtems_disk_device *dd,
+  rtems_blkdev_bnum block,
+  rtems_bdbuf_buffer** bd
+);
 
 /**
  * Get the block buffer and if not already in the cache read from the disk. If
@@ -498,8 +501,7 @@ rtems_bdbuf_get (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd)
  * buffer is returned. The highest priority waiter will obtain the buffer
  * first.
  *
- * @param device [in] Device number (constructed of major and minor device
- * number).
+ * @param dd [in] The disk device.
  * @param block [in] Linear media block number.
  * @param bd [out] Reference to the buffer descriptor pointer.
  *
@@ -510,7 +512,11 @@ rtems_bdbuf_get (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd)
  * @retval RTEMS_IO_ERROR IO error.
  */
 rtems_status_code
-rtems_bdbuf_read (dev_t device, rtems_blkdev_bnum block, rtems_bdbuf_buffer** bd);
+rtems_bdbuf_read (
+  const rtems_disk_device *dd,
+  rtems_blkdev_bnum block,
+  rtems_bdbuf_buffer** bd
+);
 
 /**
  * Release the buffer obtained by a read call back to the cache. If the buffer
@@ -575,31 +581,22 @@ rtems_bdbuf_sync (rtems_bdbuf_buffer* bd);
  * @note Nesting calls to sync multiple devices will be handled sequentially. A
  * nested call will be blocked until the first sync request has complete.
  *
- * @param dev [in] Device number (constructed of major and minor device
- * number).
+ * @param dd [in] The disk device.
  *
  * @retval RTEMS_SUCCESSFUL Successful operation. 
  * @retval RTEMS_NOT_CONFIGURED Not initialized.
  * @retval RTEMS_INVALID_ID No such device.
  */
 rtems_status_code
-rtems_bdbuf_syncdev (dev_t dev);
+rtems_bdbuf_syncdev (const rtems_disk_device *dd);
 
 /**
- * @brief Purges all buffers that matches the device identifier @a dev.
+ * @brief Purges all buffers corresponding to the disk device @a dd.
  *
  * This may result in loss of data.
  */
 void
-rtems_bdbuf_purge_dev (dev_t dev);
-
-/**
- * @brief Purges all buffers that matches the device major number @a major.
- *
- * This may result in loss of data.
- */
-void
-rtems_bdbuf_purge_major (rtems_device_major_number major);
+rtems_bdbuf_purge_dev (const rtems_disk_device *dd);
 
 /** @} */
 
diff --git a/cpukit/libblock/include/rtems/bdpart.h b/cpukit/libblock/include/rtems/bdpart.h
index 907866e..873b9d3 100644
--- a/cpukit/libblock/include/rtems/bdpart.h
+++ b/cpukit/libblock/include/rtems/bdpart.h
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2009, 2010
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -398,7 +399,8 @@ static inline uint8_t rtems_bdpart_mbr_partition_type(
 
 rtems_status_code rtems_bdpart_get_disk_data(
   const char *disk_name,
-  dev_t *disk,
+  int *fd_ptr,
+  const rtems_disk_device **dd_ptr,
   rtems_blkdev_bnum *disk_end
 );
 
diff --git a/cpukit/libblock/src/bdbuf.c b/cpukit/libblock/src/bdbuf.c
index 53782e8..a5eaa95 100644
--- a/cpukit/libblock/src/bdbuf.c
+++ b/cpukit/libblock/src/bdbuf.c
@@ -19,7 +19,7 @@
  *    Rewritten to remove score mutex access. Fixes many performance
  *    issues.
  *
- * Copyright (c) 2009 embedded brains GmbH.
+ * Copyright (c) 2009-2012 embedded brains GmbH.
  *
  * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp
  */
@@ -44,7 +44,7 @@
 
 #include "rtems/bdbuf.h"
 
-#define BDBUF_INVALID_DEV ((dev_t) -1)
+#define BDBUF_INVALID_DEV NULL
 
 /*
  * Simpler label for this file.
@@ -58,7 +58,7 @@
 typedef struct rtems_bdbuf_swapout_transfer
 {
   rtems_chain_control   bds;         /**< The transfer list of BDs. */
-  dev_t                 dev;         /**< The device the transfer is for. */
+  const rtems_disk_device *dd;       /**< The device the transfer is for. */
   bool                  syncing;     /**< The data is a sync'ing. */
   rtems_blkdev_request* write_req;   /**< The write request array. */
   uint32_t              bufs_per_bd; /**< Number of buffers per bd. */
@@ -113,7 +113,7 @@ typedef struct rtems_bdbuf_cache
   rtems_id            sync_lock;         /**< Sync calls block writes. */
   bool                sync_active;       /**< True if a sync is active. */
   rtems_id            sync_requester;    /**< The sync requester. */
-  dev_t               sync_device;       /**< The device to sync and
+  const rtems_disk_device *sync_device;  /**< The device to sync and
                                           * BDBUF_INVALID_DEV not a device
                                           * sync. */
 
@@ -174,7 +174,6 @@ typedef struct rtems_bdbuf_cache
 #define RTEMS_BLKDEV_FATAL_BDBUF_STATE_0       RTEMS_BLKDEV_FATAL_ERROR(28)
 #define RTEMS_BLKDEV_FATAL_BDBUF_STATE_1       RTEMS_BLKDEV_FATAL_ERROR(29)
 #define RTEMS_BLKDEV_FATAL_BDBUF_STATE_2       RTEMS_BLKDEV_FATAL_ERROR(30)
-#define RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL      RTEMS_BLKDEV_FATAL_ERROR(31)
 
 /**
  * The events used in this code. These should be system events rather than
@@ -322,24 +321,25 @@ rtems_bdbuf_fatal (rtems_bdbuf_buf_state state, uint32_t error)
 }
 
 /**
- * Searches for the node with specified dev/block.
+ * Searches for the node with specified dd/block.
  *
  * @param root pointer to the root node of the AVL-Tree
- * @param dev device search key
+ * @param dd disk device search key
  * @param block block search key
- * @retval NULL node with the specified dev/block is not found
- * @return pointer to the node with specified dev/block
+ * @retval NULL node with the specified dd/block is not found
+ * @return pointer to the node with specified dd/block
  */
 static rtems_bdbuf_buffer *
 rtems_bdbuf_avl_search (rtems_bdbuf_buffer** root,
-                        dev_t                dev,
+                        const rtems_disk_device *dd,
                         rtems_blkdev_bnum    block)
 {
   rtems_bdbuf_buffer* p = *root;
 
-  while ((p != NULL) && ((p->dev != dev) || (p->block != block)))
+  while ((p != NULL) && ((p->dd != dd) || (p->block != block)))
   {
-    if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
+    if (((uintptr_t) p->dd < (uintptr_t) dd)
+        || ((p->dd == dd) && (p->block < block)))
     {
       p = p->avl.right;
     }
@@ -364,7 +364,7 @@ static int
 rtems_bdbuf_avl_insert(rtems_bdbuf_buffer** root,
                        rtems_bdbuf_buffer*  node)
 {
-  dev_t             dev = node->dev;
+  const rtems_disk_device *dd = node->dd;
   rtems_blkdev_bnum block = node->block;
 
   rtems_bdbuf_buffer*  p = *root;
@@ -389,7 +389,8 @@ rtems_bdbuf_avl_insert(rtems_bdbuf_buffer** root,
   {
     *buf_prev++ = p;
 
-    if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
+    if (((uintptr_t) p->dd < (uintptr_t) dd)
+        || ((p->dd == dd) && (p->block < block)))
     {
       p->avl.cache = 1;
       q = p->avl.right;
@@ -400,7 +401,7 @@ rtems_bdbuf_avl_insert(rtems_bdbuf_buffer** root,
         break;
       }
     }
-    else if ((p->dev != dev) || (p->block != block))
+    else if ((p->dd != dd) || (p->block != block))
     {
       p->avl.cache = -1;
       q = p->avl.left;
@@ -545,7 +546,7 @@ static int
 rtems_bdbuf_avl_remove(rtems_bdbuf_buffer**      root,
                        const rtems_bdbuf_buffer* node)
 {
-  dev_t             dev = node->dev;
+  const rtems_disk_device *dd = node->dd;
   rtems_blkdev_bnum block = node->block;
 
   rtems_bdbuf_buffer*  p = *root;
@@ -565,12 +566,13 @@ rtems_bdbuf_avl_remove(rtems_bdbuf_buffer**      root,
   {
     *buf_prev++ = p;
 
-    if ((p->dev < dev) || ((p->dev == dev) && (p->block < block)))
+    if (((uintptr_t) p->dd < (uintptr_t) dd)
+        || ((p->dd == dd) && (p->block < block)))
     {
       p->avl.cache = 1;
       p = p->avl.right;
     }
-    else if ((p->dev != dev) || (p->block != block))
+    else if ((p->dd != dd) || (p->block != block))
     {
       p->avl.cache = -1;
       p = p->avl.left;
@@ -1092,7 +1094,7 @@ rtems_bdbuf_discard_buffer (rtems_bdbuf_buffer *bd)
 static void
 rtems_bdbuf_add_to_modified_list_after_access (rtems_bdbuf_buffer *bd)
 {
-  if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dev)
+  if (bdbuf_cache.sync_active && bdbuf_cache.sync_device == bd->dd)
   {
     rtems_bdbuf_unlock_cache ();
 
@@ -1221,10 +1223,10 @@ rtems_bdbuf_group_realloc (rtems_bdbuf_group* group, size_t new_bds_per_group)
 
 static void
 rtems_bdbuf_setup_empty_buffer (rtems_bdbuf_buffer *bd,
-                                dev_t               dev,
+                                const rtems_disk_device *dd,
                                 rtems_blkdev_bnum   block)
 {
-  bd->dev       = dev;
+  bd->dd        = dd ;
   bd->block     = block;
   bd->avl.left  = NULL;
   bd->avl.right = NULL;
@@ -1237,7 +1239,7 @@ rtems_bdbuf_setup_empty_buffer (rtems_bdbuf_buffer *bd,
 }
 
 static rtems_bdbuf_buffer *
-rtems_bdbuf_get_buffer_from_lru_list (dev_t             dev,
+rtems_bdbuf_get_buffer_from_lru_list (const rtems_disk_device *dd,
                                       rtems_blkdev_bnum block,
                                       size_t            bds_per_group)
 {
@@ -1271,7 +1273,7 @@ rtems_bdbuf_get_buffer_from_lru_list (dev_t             dev,
 
     if (empty_bd != NULL)
     {
-      rtems_bdbuf_setup_empty_buffer (empty_bd, dev, block);
+      rtems_bdbuf_setup_empty_buffer (empty_bd, dd, block);
 
       return empty_bd;
     }
@@ -1422,7 +1424,7 @@ rtems_bdbuf_init (void)
        b < bdbuf_cache.buffer_min_count;
        b++, bd++, buffer += bdbuf_config.buffer_min)
   {
-    bd->dev    = BDBUF_INVALID_DEV;
+    bd->dd    = BDBUF_INVALID_DEV;
     bd->group  = group;
     bd->buffer = buffer;
 
@@ -1668,17 +1670,17 @@ rtems_bdbuf_sync_after_access (rtems_bdbuf_buffer *bd)
 }
 
 static rtems_bdbuf_buffer *
-rtems_bdbuf_get_buffer_for_read_ahead (dev_t             dev,
+rtems_bdbuf_get_buffer_for_read_ahead (const rtems_disk_device *dd,
                                        rtems_blkdev_bnum block,
                                        size_t            bds_per_group)
 {
   rtems_bdbuf_buffer *bd = NULL;
 
-  bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
+  bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dd, block);
 
   if (bd == NULL)
   {
-    bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
+    bd = rtems_bdbuf_get_buffer_from_lru_list (dd, block, bds_per_group);
 
     if (bd != NULL)
       rtems_bdbuf_group_obtain (bd);
@@ -1694,7 +1696,7 @@ rtems_bdbuf_get_buffer_for_read_ahead (dev_t             dev,
 }
 
 static rtems_bdbuf_buffer *
-rtems_bdbuf_get_buffer_for_access (dev_t             dev,
+rtems_bdbuf_get_buffer_for_access (const rtems_disk_device *dd,
                                    rtems_blkdev_bnum block,
                                    size_t            bds_per_group)
 {
@@ -1702,7 +1704,7 @@ rtems_bdbuf_get_buffer_for_access (dev_t             dev,
 
   do
   {
-    bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dev, block);
+    bd = rtems_bdbuf_avl_search (&bdbuf_cache.tree, dd, block);
 
     if (bd != NULL)
     {
@@ -1719,7 +1721,7 @@ rtems_bdbuf_get_buffer_for_access (dev_t             dev,
     }
     else
     {
-      bd = rtems_bdbuf_get_buffer_from_lru_list (dev, block, bds_per_group);
+      bd = rtems_bdbuf_get_buffer_from_lru_list (dd, block, bds_per_group);
 
       if (bd == NULL)
         rtems_bdbuf_wait_for_buffer ();
@@ -1734,26 +1736,14 @@ rtems_bdbuf_get_buffer_for_access (dev_t             dev,
 }
 
 static rtems_status_code
-rtems_bdbuf_obtain_disk (dev_t               dev,
+rtems_bdbuf_obtain_disk (const rtems_disk_device *dd,
                          rtems_blkdev_bnum   block,
-                         rtems_disk_device **dd_ptr,
                          rtems_blkdev_bnum  *media_block_ptr,
                          size_t             *bds_per_group_ptr)
 {
-  rtems_disk_device *dd = NULL;
-
   if (!bdbuf_cache.initialised)
     return RTEMS_NOT_CONFIGURED;
 
-  /*
-   * Do not hold the cache lock when obtaining the disk table.
-   */
-  dd = rtems_disk_obtain (dev);
-  if (dd == NULL)
-    return RTEMS_INVALID_ID;
-
-  *dd_ptr = dd;
-
   if (media_block_ptr != NULL)
   {
     /*
@@ -1766,7 +1756,6 @@ rtems_bdbuf_obtain_disk (dev_t               dev,
                                                     dd->media_block_size);
     if (mb >= dd->size)
     {
-      rtems_disk_release(dd);
       return RTEMS_INVALID_NUMBER;
     }
 
@@ -1779,7 +1768,6 @@ rtems_bdbuf_obtain_disk (dev_t               dev,
 
     if (bds_per_group == 0)
     {
-      rtems_disk_release (dd);
       return RTEMS_INVALID_NUMBER;
     }
 
@@ -1789,28 +1777,17 @@ rtems_bdbuf_obtain_disk (dev_t               dev,
   return RTEMS_SUCCESSFUL;
 }
 
-static void
-rtems_bdbuf_release_disk (rtems_disk_device *dd)
-{
-  rtems_status_code sc = RTEMS_SUCCESSFUL;
-
-  sc = rtems_disk_release (dd);
-  if (sc != RTEMS_SUCCESSFUL)
-    rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_DISK_REL);
-}
-
 rtems_status_code
-rtems_bdbuf_get (dev_t                dev,
+rtems_bdbuf_get (const rtems_disk_device *dd,
                  rtems_blkdev_bnum    block,
                  rtems_bdbuf_buffer **bd_ptr)
 {
   rtems_status_code   sc = RTEMS_SUCCESSFUL;
-  rtems_disk_device  *dd = NULL;
   rtems_bdbuf_buffer *bd = NULL;
   rtems_blkdev_bnum   media_block = 0;
   size_t              bds_per_group = 0;
 
-  sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
+  sc = rtems_bdbuf_obtain_disk (dd, block, &media_block, &bds_per_group);
   if (sc != RTEMS_SUCCESSFUL)
     return sc;
 
@@ -1821,9 +1798,9 @@ rtems_bdbuf_get (dev_t                dev,
    */
   if (rtems_bdbuf_tracer)
     printf ("bdbuf:get: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
-            media_block, block, (unsigned) dev);
+            media_block, block, (unsigned) dd->dev);
 
-  bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
+  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block, bds_per_group);
 
   switch (bd->state)
   {
@@ -1856,8 +1833,6 @@ rtems_bdbuf_get (dev_t                dev,
 
   rtems_bdbuf_unlock_cache ();
 
-  rtems_bdbuf_release_disk (dd);
-
   *bd_ptr = bd;
 
   return RTEMS_SUCCESSFUL;
@@ -1892,7 +1867,6 @@ rtems_bdbuf_create_read_request (const rtems_disk_device *dd,
   rtems_bdbuf_buffer *bd = NULL;
   rtems_blkdev_bnum   media_block_end = dd->start + dd->size;
   rtems_blkdev_bnum   media_block_count = dd->block_size / dd->media_block_size;
-  dev_t               dev = dd->dev;
   uint32_t            block_size = dd->block_size;
   uint32_t            transfer_index = 1;
   uint32_t            transfer_count = bdbuf_config.max_read_ahead_blocks + 1;
@@ -1907,7 +1881,7 @@ rtems_bdbuf_create_read_request (const rtems_disk_device *dd,
   req->status = RTEMS_RESOURCE_IN_USE;
   req->bufnum = 0;
 
-  bd = rtems_bdbuf_get_buffer_for_access (dev, media_block, bds_per_group);
+  bd = rtems_bdbuf_get_buffer_for_access (dd, media_block, bds_per_group);
 
   *bd_ptr = bd;
 
@@ -1936,7 +1910,7 @@ rtems_bdbuf_create_read_request (const rtems_disk_device *dd,
   {
     media_block += media_block_count;
 
-    bd = rtems_bdbuf_get_buffer_for_read_ahead (dev, media_block,
+    bd = rtems_bdbuf_get_buffer_for_read_ahead (dd, media_block,
                                                 bds_per_group);
 
     if (bd == NULL)
@@ -2021,18 +1995,17 @@ rtems_bdbuf_execute_transfer_request (const rtems_disk_device *dd,
 }
 
 rtems_status_code
-rtems_bdbuf_read (dev_t                dev,
+rtems_bdbuf_read (const rtems_disk_device *dd,
                   rtems_blkdev_bnum    block,
                   rtems_bdbuf_buffer **bd_ptr)
 {
   rtems_status_code     sc = RTEMS_SUCCESSFUL;
-  rtems_disk_device    *dd = NULL;
   rtems_blkdev_request *req = NULL;
   rtems_bdbuf_buffer   *bd = NULL;
   rtems_blkdev_bnum     media_block = 0;
   size_t                bds_per_group = 0;
 
-  sc = rtems_bdbuf_obtain_disk (dev, block, &dd, &media_block, &bds_per_group);
+  sc = rtems_bdbuf_obtain_disk (dd, block, &media_block, &bds_per_group);
   if (sc != RTEMS_SUCCESSFUL)
     return sc;
 
@@ -2047,7 +2020,7 @@ rtems_bdbuf_read (dev_t                dev,
 
   if (rtems_bdbuf_tracer)
     printf ("bdbuf:read: %" PRIu32 " (%" PRIu32 ") (dev = %08x)\n",
-            media_block + dd->start, block, (unsigned) dev);
+            media_block + dd->start, block, (unsigned) dd->dev);
 
   rtems_bdbuf_lock_cache ();
   rtems_bdbuf_create_read_request (dd, media_block, bds_per_group, req, &bd);
@@ -2089,7 +2062,6 @@ rtems_bdbuf_read (dev_t                dev,
     *bd_ptr = NULL;
 
   rtems_bdbuf_unlock_cache ();
-  rtems_bdbuf_release_disk (dd);
 
   return sc;
 }
@@ -2210,15 +2182,14 @@ rtems_bdbuf_sync (rtems_bdbuf_buffer *bd)
 }
 
 rtems_status_code
-rtems_bdbuf_syncdev (dev_t dev)
+rtems_bdbuf_syncdev (const rtems_disk_device *dd)
 {
   rtems_status_code  sc = RTEMS_SUCCESSFUL;
-  rtems_disk_device *dd = NULL;
 
   if (rtems_bdbuf_tracer)
-    printf ("bdbuf:syncdev: %08x\n", (unsigned) dev);
+    printf ("bdbuf:syncdev: %08x\n", (unsigned) dd->dev);
 
-  sc = rtems_bdbuf_obtain_disk (dev, 0, &dd, NULL, NULL);
+  sc = rtems_bdbuf_obtain_disk (dd, 0, NULL, NULL);
   if (sc != RTEMS_SUCCESSFUL)
     return sc;
 
@@ -2240,23 +2211,16 @@ rtems_bdbuf_syncdev (dev_t dev)
    */
   bdbuf_cache.sync_active    = true;
   bdbuf_cache.sync_requester = rtems_task_self ();
-  bdbuf_cache.sync_device    = dev;
+  bdbuf_cache.sync_device    = dd;
 
   rtems_bdbuf_wake_swapper ();
   rtems_bdbuf_unlock_cache ();
   rtems_bdbuf_wait_for_event (RTEMS_BDBUF_TRANSFER_SYNC);
   rtems_bdbuf_unlock_sync ();
-  rtems_bdbuf_release_disk (dd);
 
   return RTEMS_SUCCESSFUL;
 }
 
-static int
-rtems_bdbuf_null_disk_ioctl (rtems_disk_device *dd, uint32_t req, void *arg)
-{
-  return -1;
-}
-
 /**
  * Swapout transfer to the driver. The driver will break this I/O into groups
  * of consecutive write requests is multiple consecutive buffers are required
@@ -2268,14 +2232,9 @@ static void
 rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
 {
   rtems_chain_node *node;
-  static rtems_disk_device null_disk = {
-    .phys_dev = &null_disk,
-    .capabilities = 0,
-    .ioctl = rtems_bdbuf_null_disk_ioctl
-  };
 
   if (rtems_bdbuf_tracer)
-    printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dev);
+    printf ("bdbuf:swapout transfer: %08x\n", (unsigned) transfer->dd->dev);
 
   /*
    * If there are buffers to transfer to the media transfer them.
@@ -2294,14 +2253,7 @@ rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
      */
     uint32_t bufs_per_bd = 0;
 
-    /*
-     * Obtain the disk device. The cache's mutex has been released to avoid a
-     * dead lock.
-     */
-    rtems_disk_device *dd = rtems_disk_obtain (transfer->dev);
-
-    if (dd == NULL)
-      dd = &null_disk;
+    const rtems_disk_device *dd = transfer->dd;
 
     bufs_per_bd = dd->block_size / bdbuf_config.buffer_min;
 
@@ -2372,20 +2324,15 @@ rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
       }
     }
 
-    if (dd != &null_disk)
+    /*
+     * If sync'ing and the deivce is capability of handling a sync IO control
+     * call perform the call.
+     */
+    if (transfer->syncing &&
+        (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
     {
-      /*
-       * If sync'ing and the deivce is capability of handling a sync IO control
-       * call perform the call.
-       */
-      if (transfer->syncing &&
-          (dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_SYNC))
-      {
-        /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
-        /* How should the error be handled ? */
-      }
-      
-      rtems_disk_release (dd);
+      /* int result = */ dd->ioctl (dd->phys_dev, RTEMS_BLKDEV_REQ_SYNC, NULL);
+      /* How should the error be handled ? */
     }
   }
 }
@@ -2394,8 +2341,9 @@ rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
  * Process the modified list of buffers. There is a sync or modified list that
  * needs to be handled so we have a common function to do the work.
  *
- * @param dev The device to handle. If BDBUF_INVALID_DEV no device is selected
- * so select the device of the first buffer to be written to disk.
+ * @param dd_ptr Pointer to the device to handle. If BDBUF_INVALID_DEV no
+ * device is selected so select the device of the first buffer to be written to
+ * disk.
  * @param chain The modified chain to process.
  * @param transfer The chain to append buffers to be written too.
  * @param sync_active If true this is a sync operation so expire all timers.
@@ -2404,7 +2352,7 @@ rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
  *                    amount.
  */
 static void
-rtems_bdbuf_swapout_modified_processing (dev_t*               dev,
+rtems_bdbuf_swapout_modified_processing (const rtems_disk_device **dd_ptr,
                                          rtems_chain_control* chain,
                                          rtems_chain_control* transfer,
                                          bool                 sync_active,
@@ -2421,7 +2369,7 @@ rtems_bdbuf_swapout_modified_processing (dev_t*               dev,
     /*
      * A sync active with no valid dev means sync all.
      */
-    if (sync_active && (*dev == BDBUF_INVALID_DEV))
+    if (sync_active && (*dd_ptr == BDBUF_INVALID_DEV))
       sync_all = true;
     else
       sync_all = false;
@@ -2437,7 +2385,7 @@ rtems_bdbuf_swapout_modified_processing (dev_t*               dev,
        * @note Lots of sync requests will skew this timer. It should be based
        *       on TOD to be accurate. Does it matter ?
        */
-      if (sync_all || (sync_active && (*dev == bd->dev))
+      if (sync_all || (sync_active && (*dd_ptr == bd->dd))
           || rtems_bdbuf_has_buffer_waiters ())
         bd->hold_timer = 0;
 
@@ -2459,14 +2407,14 @@ rtems_bdbuf_swapout_modified_processing (dev_t*               dev,
       }
 
       /*
-       * This assumes we can set dev_t to BDBUF_INVALID_DEV which is just an
+       * This assumes we can set it to BDBUF_INVALID_DEV which is just an
        * assumption. Cannot use the transfer list being empty the sync dev
        * calls sets the dev to use.
        */
-      if (*dev == BDBUF_INVALID_DEV)
-        *dev = bd->dev;
+      if (*dd_ptr == BDBUF_INVALID_DEV)
+        *dd_ptr = bd->dd;
 
-      if (bd->dev == *dev)
+      if (bd->dd == *dd_ptr)
       {
         rtems_chain_node* next_node = node->next;
         rtems_chain_node* tnode = rtems_chain_tail (transfer);
@@ -2556,7 +2504,7 @@ rtems_bdbuf_swapout_processing (unsigned long                 timer_delta,
   }
 
   rtems_chain_initialize_empty (&transfer->bds);
-  transfer->dev = BDBUF_INVALID_DEV;
+  transfer->dd = BDBUF_INVALID_DEV;
   transfer->syncing = bdbuf_cache.sync_active;
   
   /*
@@ -2565,13 +2513,13 @@ rtems_bdbuf_swapout_processing (unsigned long                 timer_delta,
    * list. This means the dev is BDBUF_INVALID_DEV.
    */
   if (bdbuf_cache.sync_active)
-    transfer->dev = bdbuf_cache.sync_device;
+    transfer->dd = bdbuf_cache.sync_device;
     
   /*
    * If we have any buffers in the sync queue move them to the modified
    * list. The first sync buffer will select the device we use.
    */
-  rtems_bdbuf_swapout_modified_processing (&transfer->dev,
+  rtems_bdbuf_swapout_modified_processing (&transfer->dd,
                                            &bdbuf_cache.sync,
                                            &transfer->bds,
                                            true, false,
@@ -2580,7 +2528,7 @@ rtems_bdbuf_swapout_processing (unsigned long                 timer_delta,
   /*
    * Process the cache's modified list.
    */
-  rtems_bdbuf_swapout_modified_processing (&transfer->dev,
+  rtems_bdbuf_swapout_modified_processing (&transfer->dd,
                                            &bdbuf_cache.modified,
                                            &transfer->bds,
                                            bdbuf_cache.sync_active,
@@ -2678,7 +2626,7 @@ rtems_bdbuf_swapout_worker_task (rtems_task_argument arg)
     rtems_bdbuf_lock_cache ();
 
     rtems_chain_initialize_empty (&worker->transfer.bds);
-    worker->transfer.dev = BDBUF_INVALID_DEV;
+    worker->transfer.dd = BDBUF_INVALID_DEV;
 
     rtems_chain_append (&bdbuf_cache.swapout_workers, &worker->link);
 
@@ -2715,7 +2663,7 @@ rtems_bdbuf_swapout_workers_open (void)
     worker->transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
 
     rtems_chain_initialize_empty (&worker->transfer.bds);
-    worker->transfer.dev = BDBUF_INVALID_DEV;
+    worker->transfer.dd = BDBUF_INVALID_DEV;
 
     sc = rtems_task_create (rtems_build_name('B', 'D', 'o', 'a' + w),
                             (bdbuf_config.swapout_priority ?
@@ -2777,7 +2725,7 @@ rtems_bdbuf_swapout_task (rtems_task_argument arg)
 
   transfer.write_req = rtems_bdbuf_swapout_writereq_alloc ();
   rtems_chain_initialize_empty (&transfer.bds);
-  transfer.dev = BDBUF_INVALID_DEV;
+  transfer.dd = BDBUF_INVALID_DEV;
   transfer.syncing = false;
 
   /*
@@ -2871,12 +2819,9 @@ rtems_bdbuf_purge_list (rtems_chain_control *purge_list)
     rtems_bdbuf_wake (&bdbuf_cache.buffer_waiters);
 }
 
-typedef bool (*rtems_bdbuf_purge_compare)(dev_t a, dev_t b);
-
 static void
 rtems_bdbuf_gather_for_purge (rtems_chain_control *purge_list,
-                              rtems_bdbuf_purge_compare compare,
-                              dev_t dev)
+                              const rtems_disk_device *dd)
 {
   rtems_bdbuf_buffer *stack [RTEMS_BDBUF_AVL_MAX_HEIGHT];
   rtems_bdbuf_buffer **prev = stack;
@@ -2886,7 +2831,7 @@ rtems_bdbuf_gather_for_purge (rtems_chain_control *purge_list,
 
   while (cur != NULL)
   {
-    if ((*compare) (cur->dev, dev))
+    if (cur->dd == dd)
     {
       switch (cur->state)
       {
@@ -2950,40 +2895,14 @@ rtems_bdbuf_gather_for_purge (rtems_chain_control *purge_list,
   }
 }
 
-static void
-rtems_bdbuf_purge (rtems_bdbuf_purge_compare compare, dev_t dev)
+void
+rtems_bdbuf_purge_dev (const rtems_disk_device *dd)
 {
   rtems_chain_control purge_list;
 
   rtems_chain_initialize_empty (&purge_list);
   rtems_bdbuf_lock_cache ();
-  rtems_bdbuf_gather_for_purge (&purge_list, compare, dev);
+  rtems_bdbuf_gather_for_purge (&purge_list, dd);
   rtems_bdbuf_purge_list (&purge_list);
   rtems_bdbuf_unlock_cache ();
 }
-
-static bool
-rtems_bdbuf_purge_compare_dev (dev_t a, dev_t b)
-{
-  return a == b;
-}
-
-void
-rtems_bdbuf_purge_dev (dev_t dev)
-{
-  rtems_bdbuf_purge (rtems_bdbuf_purge_compare_dev, dev);
-}
-
-static bool
-rtems_bdbuf_purge_compare_major (dev_t a, dev_t b)
-{
-  return rtems_filesystem_dev_major_t (a) == rtems_filesystem_dev_major_t (b);
-}
-
-void
-rtems_bdbuf_purge_major (rtems_device_major_number major)
-{
-  dev_t dev = rtems_filesystem_make_dev_t (major, 0);
-
-  rtems_bdbuf_purge (rtems_bdbuf_purge_compare_major, dev);
-}
diff --git a/cpukit/libblock/src/bdpart-create.c b/cpukit/libblock/src/bdpart-create.c
index dc93522..209f78f 100644
--- a/cpukit/libblock/src/bdpart-create.c
+++ b/cpukit/libblock/src/bdpart-create.c
@@ -45,7 +45,6 @@ rtems_status_code rtems_bdpart_create(
     dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
   rtems_blkdev_bnum overhead = 0;
   rtems_blkdev_bnum free_space = 0;
-  dev_t disk = 0;
   size_t i = 0;
 
   /* Check if we have something to do */
@@ -60,7 +59,7 @@ rtems_status_code rtems_bdpart_create(
   }
 
   /* Get disk data */
-  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  sc = rtems_bdpart_get_disk_data( disk_name, NULL, NULL, &disk_end);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
@@ -142,15 +141,15 @@ rtems_status_code rtems_bdpart_create(
     /* Align partition upwards */
     s += record_space - (s % record_space);
 
+    /* Reserve space for the EBR if necessary */
+    if (count > 4 && i > 2) {
+      pos += record_space;
+    }
+
     /* Partition begin and end */
     p->begin = pos;
     pos += s;
     p->end = pos;
-
-    /* Reserve space for the EBR if necessary */
-    if (count > 4 && i > 2) {
-      p->begin += record_space;
-    }
   }
 
   /* Expand the last partition to the disk end */
diff --git a/cpukit/libblock/src/bdpart-read.c b/cpukit/libblock/src/bdpart-read.c
index 3560dbd..4604e10 100644
--- a/cpukit/libblock/src/bdpart-read.c
+++ b/cpukit/libblock/src/bdpart-read.c
@@ -23,6 +23,9 @@
 #include "config.h"
 #endif
 
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include <rtems.h>
 #include <rtems/bdbuf.h>
 #include <rtems/bdpart.h>
@@ -64,48 +67,59 @@ bool rtems_bdpart_to_mbr_partition_type(
  */
 rtems_status_code rtems_bdpart_get_disk_data(
   const char *disk_name,
-  dev_t *disk,
+  int *fd_ptr,
+  const rtems_disk_device **dd_ptr,
   rtems_blkdev_bnum *disk_end
 )
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   int rv = 0;
+  int fd = -1;
+  const rtems_disk_device *dd = NULL;
   rtems_blkdev_bnum disk_begin = 0;
   rtems_blkdev_bnum block_size = 0;
-  rtems_disk_device *dd = NULL;
-  struct stat st;
+
+  /* Open device file */
+  fd = open( disk_name, O_RDWR);
+  if (fd < 0) {
+    sc = RTEMS_INVALID_NAME;
+    goto error;
+  }
 
   /* Get disk handle */
-  rv = stat( disk_name, &st);
+  rv = rtems_disk_fd_get_disk_device( fd, &dd);
   if (rv != 0) {
-    return RTEMS_INVALID_NAME;
+    sc = RTEMS_INVALID_NAME;
+    goto error;
   }
-  *disk = st.st_rdev;
 
   /* Get disk begin, end and block size */
-  dd = rtems_disk_obtain( *disk);
-  if (dd == NULL) {
-    return RTEMS_INVALID_NAME;
-  }
   disk_begin = dd->start;
   *disk_end = dd->size;
   block_size = dd->block_size;
-  sc = rtems_disk_release( dd);
-  if (sc != RTEMS_SUCCESSFUL) {
-    return sc;
-  }
 
   /* Check block size */
   if (block_size < RTEMS_BDPART_BLOCK_SIZE) {
-    return RTEMS_IO_ERROR;
+    sc = RTEMS_IO_ERROR;
+    goto error;
   }
 
   /* Check that we have do not have a logical disk */
   if (disk_begin != 0) {
-    return RTEMS_IO_ERROR;
+    sc = RTEMS_IO_ERROR;
+    goto error;
   }
 
-  return RTEMS_SUCCESSFUL;
+error:
+
+  if (sc == RTEMS_SUCCESSFUL && fd_ptr != NULL && dd_ptr != NULL) {
+    *fd_ptr = fd;
+    *dd_ptr = dd;
+  } else {
+    close( fd);
+  }
+
+  return sc;
 }
 
 static bool rtems_bdpart_is_valid_record( const uint8_t *data)
@@ -171,7 +185,7 @@ static rtems_status_code rtems_bdpart_read_mbr_partition(
 }
 
 static rtems_status_code rtems_bdpart_read_record(
-  dev_t disk,
+  const rtems_disk_device *dd,
   rtems_blkdev_bnum index,
   rtems_bdbuf_buffer **block
 )
@@ -187,7 +201,7 @@ static rtems_status_code rtems_bdpart_read_record(
   }
 
   /* Read the record block */
-  sc = rtems_bdbuf_read( disk, index, block);
+  sc = rtems_bdbuf_read( dd, index, block);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
@@ -220,9 +234,10 @@ rtems_status_code rtems_bdpart_read(
   rtems_blkdev_bnum ep_begin = 0; /* Extended partition begin */
   rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
   rtems_blkdev_bnum disk_end = 0;
-  dev_t disk = 0;
   size_t i = 0;
   const uint8_t *data = NULL;
+  int fd = -1;
+  const rtems_disk_device *dd = NULL;
 
   /* Check parameter */
   if (format == NULL || pt == NULL || count == NULL) {
@@ -233,13 +248,13 @@ rtems_status_code rtems_bdpart_read(
   *count = 0;
 
   /* Get disk data */
-  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
 
   /* Read MBR */
-  sc = rtems_bdpart_read_record( disk, 0, &block);
+  sc = rtems_bdpart_read_record( dd, 0, &block);
   if (sc != RTEMS_SUCCESSFUL) {
     esc = sc;
     goto cleanup;
@@ -283,7 +298,7 @@ rtems_status_code rtems_bdpart_read(
     rtems_blkdev_bnum tmp = 0;
 
     /* Read EBR */
-    sc = rtems_bdpart_read_record( disk, ebr, &block);
+    sc = rtems_bdpart_read_record( dd, ebr, &block);
     if (sc != RTEMS_SUCCESSFUL) {
       esc = sc;
       goto cleanup;
@@ -340,6 +355,10 @@ rtems_status_code rtems_bdpart_read(
 
 cleanup:
 
+  if (fd >= 0) {
+    close( fd);
+  }
+
   if (block != NULL) {
     rtems_bdbuf_release( block);
   }
diff --git a/cpukit/libblock/src/bdpart-register.c b/cpukit/libblock/src/bdpart-register.c
index 172c8b4..d937e65 100644
--- a/cpukit/libblock/src/bdpart-register.c
+++ b/cpukit/libblock/src/bdpart-register.c
@@ -47,12 +47,16 @@ rtems_status_code rtems_bdpart_register(
   char *logical_disk_marker = NULL;
   size_t disk_name_size = strlen( disk_name);
   size_t i = 0;
+  int fd = -1;
+  const rtems_disk_device *dd = NULL;
 
   /* Get disk data */
-  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
+  disk = rtems_disk_get_device_identifier( dd);
+  close( fd);
 
   /* Get the disk device identifier */
   rtems_filesystem_split_dev_t( disk, major, minor);
@@ -134,12 +138,16 @@ rtems_status_code rtems_bdpart_unregister(
   dev_t disk = 0;
   dev_t logical_disk = 0;
   size_t i = 0;
+  int fd = -1;
+  const rtems_disk_device *dd = NULL;
 
   /* Get disk data */
-  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
+  disk = rtems_disk_get_device_identifier( dd);
+  close( fd);
 
   /* Get the disk device identifier */
   rtems_filesystem_split_dev_t( disk, major, minor);
diff --git a/cpukit/libblock/src/bdpart-write.c b/cpukit/libblock/src/bdpart-write.c
index 92e80a2..9cccda5 100644
--- a/cpukit/libblock/src/bdpart-write.c
+++ b/cpukit/libblock/src/bdpart-write.c
@@ -45,7 +45,7 @@ static void rtems_bdpart_write_mbr_partition(
 }
 
 static rtems_status_code rtems_bdpart_new_record(
-  dev_t disk,
+  const rtems_disk_device *dd,
   rtems_blkdev_bnum index,
   rtems_bdbuf_buffer **block
 )
@@ -61,7 +61,7 @@ static rtems_status_code rtems_bdpart_new_record(
   }
 
   /* Read the new record block (this accounts for disk block sizes > 512) */
-  sc = rtems_bdbuf_read( disk, index, block);
+  sc = rtems_bdbuf_read( dd, index, block);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
@@ -99,10 +99,11 @@ rtems_status_code rtems_bdpart_write(
   rtems_blkdev_bnum disk_end = 0;
   rtems_blkdev_bnum record_space =
     dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
-  dev_t disk = 0;
   size_t ppc = 0; /* Primary partition count */
   size_t i = 0;
   uint8_t *data = NULL;
+  int fd = -1;
+  const rtems_disk_device *dd = NULL;
 
   /* Check if we have something to do */
   if (count == 0) {
@@ -116,7 +117,7 @@ rtems_status_code rtems_bdpart_write(
   }
 
   /* Get disk data */
-  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  sc = rtems_bdpart_get_disk_data( disk_name, &fd, &dd, &disk_end);
   if (sc != RTEMS_SUCCESSFUL) {
     return sc;
   }
@@ -211,7 +212,7 @@ rtems_status_code rtems_bdpart_write(
   }
 
   /* New MBR */
-  sc = rtems_bdpart_new_record( disk, 0, &block);
+  sc = rtems_bdpart_new_record( dd, 0, &block);
   if (sc != RTEMS_SUCCESSFUL) {
     esc = sc;
     goto cleanup;
@@ -275,7 +276,7 @@ rtems_status_code rtems_bdpart_write(
 
       /* New EBR */
       ebr = p->begin - record_space;
-      sc = rtems_bdpart_new_record( disk, ebr, &block);
+      sc = rtems_bdpart_new_record( dd, ebr, &block);
       if (sc != RTEMS_SUCCESSFUL) {
         esc = sc;
         goto cleanup;
@@ -294,6 +295,10 @@ rtems_status_code rtems_bdpart_write(
 
 cleanup:
 
+  if (fd >= 0) {
+    close( fd);
+  }
+
   if (block != NULL) {
     rtems_bdbuf_sync( block);
   }
diff --git a/cpukit/libblock/src/blkdev.c b/cpukit/libblock/src/blkdev.c
index c986e69..3e950d6 100644
--- a/cpukit/libblock/src/blkdev.c
+++ b/cpukit/libblock/src/blkdev.c
@@ -46,7 +46,6 @@ rtems_blkdev_generic_read(
     uint32_t count = args->count;
     rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
     uint32_t blkofs = (uint32_t) (args->offset % block_size);
-    dev_t dev = dd->dev;
 
     args->bytes_moved = 0;
 
@@ -55,7 +54,7 @@ rtems_blkdev_generic_read(
         rtems_bdbuf_buffer *diskbuf;
         uint32_t            copy;
 
-        rc = rtems_bdbuf_read(dev, block, &diskbuf);
+        rc = rtems_bdbuf_read(dd, block, &diskbuf);
         if (rc != RTEMS_SUCCESSFUL)
             break;
         copy = block_size - blkofs;
@@ -94,7 +93,6 @@ rtems_blkdev_generic_write(
     uint32_t count = args->count;
     rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
     uint32_t blkofs = (uint32_t) (args->offset % block_size);
-    dev_t dev = dd->dev;
 
     args->bytes_moved = 0;
 
@@ -104,9 +102,9 @@ rtems_blkdev_generic_write(
         uint32_t            copy;
 
         if ((blkofs == 0) && (count >= block_size))
-            rc = rtems_bdbuf_get(dev, block, &diskbuf);
+            rc = rtems_bdbuf_get(dd, block, &diskbuf);
         else
-            rc = rtems_bdbuf_read(dev, block, &diskbuf);
+            rc = rtems_bdbuf_read(dd, block, &diskbuf);
         if (rc != RTEMS_SUCCESSFUL)
             break;
 
@@ -207,7 +205,7 @@ rtems_blkdev_generic_ioctl(
             break;
 
         case RTEMS_BLKIO_SYNCDEV:
-            rc = rtems_bdbuf_syncdev(dd->dev);
+            rc = rtems_bdbuf_syncdev(dd);
             args->ioctl_return = (uint32_t) (rc == RTEMS_SUCCESSFUL ? 0 : -1);
             break;
 
diff --git a/cpukit/libblock/src/media.c b/cpukit/libblock/src/media.c
index b4ddd6a..989f80d 100644
--- a/cpukit/libblock/src/media.c
+++ b/cpukit/libblock/src/media.c
@@ -812,15 +812,19 @@ static rtems_status_code disk_detach_worker(
 
   if (state == RTEMS_MEDIA_STATE_READY) {
     dev_t dev = 0;
+    rtems_disk_device *dd = NULL;
 
     sc = rtems_media_get_device_identifier(src, &dev);
     if (sc != RTEMS_SUCCESSFUL) {
       return RTEMS_IO_ERROR;
     }
 
-    sc = rtems_bdbuf_syncdev(dev);
-    if (sc != RTEMS_SUCCESSFUL) {
-      rsc = RTEMS_IO_ERROR;
+    dd = rtems_disk_obtain(dev);
+    if (dd != NULL) {
+      sc = rtems_bdbuf_syncdev(dd);
+      if (sc != RTEMS_SUCCESSFUL) {
+        rsc = RTEMS_IO_ERROR;
+      }
     }
 
     sc = rtems_disk_delete(dev);
@@ -828,7 +832,10 @@ static rtems_status_code disk_detach_worker(
       rsc = RTEMS_IO_ERROR;
     }
 
-    rtems_bdbuf_purge_dev(dev);
+    if (dd != NULL) {
+      rtems_bdbuf_purge_dev(dd);
+      rtems_disk_release(dd);
+    }
 
     if (rtems_filesystem_dev_minor_t(dev) == 0) {
       sc = rtems_io_unregister_driver(rtems_filesystem_dev_major_t(dev));
diff --git a/cpukit/libfs/src/dosfs/fat.c b/cpukit/libfs/src/dosfs/fat.c
index ba9ae23..39a7bac 100644
--- a/cpukit/libfs/src/dosfs/fat.c
+++ b/cpukit/libfs/src/dosfs/fat.c
@@ -37,9 +37,9 @@ fat_buf_access(fat_fs_info_t *fs_info, uint32_t   blk, int op_type,
     if (fs_info->c.state == FAT_CACHE_EMPTY)
     {
         if (op_type == FAT_OP_TYPE_READ)
-            sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf);
+            sc = rtems_bdbuf_read(fs_info->vol.dd, blk, &fs_info->c.buf);
         else
-            sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf);
+            sc = rtems_bdbuf_get(fs_info->vol.dd, blk, &fs_info->c.buf);
         if (sc != RTEMS_SUCCESSFUL)
             rtems_set_errno_and_return_minus_one(EIO);
         fs_info->c.blk_num = blk;
@@ -70,7 +70,7 @@ fat_buf_access(fat_fs_info_t *fs_info, uint32_t   blk, int op_type,
 
                 for (i = 1; i < fs_info->vol.fats; i++)
                 {
-                    sc = rtems_bdbuf_get(fs_info->vol.dev,
+                    sc = rtems_bdbuf_get(fs_info->vol.dd,
                                          fs_info->c.blk_num +
                                          fs_info->vol.fat_length * i,
                                          &b);
@@ -92,9 +92,9 @@ fat_buf_access(fat_fs_info_t *fs_info, uint32_t   blk, int op_type,
 
         }
         if (op_type == FAT_OP_TYPE_READ)
-            sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf);
+            sc = rtems_bdbuf_read(fs_info->vol.dd, blk, &fs_info->c.buf);
         else
-            sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf);
+            sc = rtems_bdbuf_get(fs_info->vol.dd, blk, &fs_info->c.buf);
         if (sc != RTEMS_SUCCESSFUL)
             rtems_set_errno_and_return_minus_one(EIO);
         fs_info->c.blk_num = blk;
@@ -133,7 +133,7 @@ fat_buf_release(fat_fs_info_t *fs_info)
 
             for (i = 1; i < fs_info->vol.fats; i++)
             {
-                sc = rtems_bdbuf_get(fs_info->vol.dev,
+                sc = rtems_bdbuf_get(fs_info->vol.dd,
                                      fs_info->c.blk_num +
                                      fs_info->vol.fat_length * i,
                                      &b);
@@ -362,27 +362,39 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
     int                 i = 0;
     rtems_bdbuf_buffer *block = NULL;
 
-    rc = stat(mt_entry->dev, &stat_buf);
-    if (rc == -1)
-        return rc;
+    vol->fd = open(mt_entry->dev, O_RDWR);
+    if (vol->fd < 0)
+    {
+        rtems_set_errno_and_return_minus_one(ENXIO);
+    }
+
+    rc = fstat(vol->fd, &stat_buf);
+    if (rc != 0)
+    {
+        close(vol->fd);
+        rtems_set_errno_and_return_minus_one(ENXIO);
+    }
 
     /* Must be a block device. */
     if (!S_ISBLK(stat_buf.st_mode))
-        rtems_set_errno_and_return_minus_one(ENOTTY);
+    {
+        close(vol->fd);
+        rtems_set_errno_and_return_minus_one(ENXIO);
+    }
 
     /* check that device is registred as block device and lock it */
-    vol->dd = rtems_disk_obtain(stat_buf.st_rdev);
-    if (vol->dd == NULL)
-        rtems_set_errno_and_return_minus_one(EIO);
-
-    vol->dev = stat_buf.st_rdev;
+    rc = rtems_disk_fd_get_disk_device(vol->fd, &vol->dd);
+    if (rc != 0) {
+        close(vol->fd);
+        rtems_set_errno_and_return_minus_one(ENXIO);
+    }
 
     /* Read boot record */
     /* FIXME: Asserts FAT_MAX_BPB_SIZE < bdbuf block size */
-    sc = rtems_bdbuf_read( vol->dev, 0, &block);
+    sc = rtems_bdbuf_read( vol->dd, 0, &block);
     if (sc != RTEMS_SUCCESSFUL)
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         rtems_set_errno_and_return_minus_one( EIO);
     }
 
@@ -391,7 +403,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
     sc = rtems_bdbuf_release( block);
     if (sc != RTEMS_SUCCESSFUL)
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         rtems_set_errno_and_return_minus_one( EIO );
     }
 
@@ -403,7 +415,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
          (vol->bps != 2048) &&
          (vol->bps != 4096))
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         rtems_set_errno_and_return_minus_one( EINVAL );
     }
 
@@ -419,7 +431,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
      */
     if (vol->spc == 0)
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         rtems_set_errno_and_return_minus_one(EINVAL);
     }
 
@@ -431,7 +443,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
      */
     if ((vol->bpc = vol->bps << vol->spc_log2) > MS_BYTES_PER_CLUSTER_LIMIT)
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         rtems_set_errno_and_return_minus_one(EINVAL);
     }
 
@@ -505,7 +517,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
         vol->info_sec = FAT_GET_BR_FAT32_FS_INFO_SECTOR(boot_rec);
         if( vol->info_sec == 0 )
         {
-            rtems_disk_release(vol->dd);
+            close(vol->fd);
             rtems_set_errno_and_return_minus_one( EINVAL );
         }
         else
@@ -514,7 +526,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
                                   FAT_FSI_LEADSIG_SIZE, fs_info_sector);
             if ( ret < 0 )
             {
-                rtems_disk_release(vol->dd);
+                close(vol->fd);
                 return -1;
             }
 
@@ -522,7 +534,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
                 FAT_FSINFO_LEAD_SIGNATURE_VALUE)
             {
                 _fat_block_release(mt_entry);
-                rtems_disk_release(vol->dd);
+                close(vol->fd);
                 rtems_set_errno_and_return_minus_one( EINVAL );
             }
             else
@@ -532,7 +544,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
                 if ( ret < 0 )
                 {
                     _fat_block_release(mt_entry);
-                    rtems_disk_release(vol->dd);
+                    close(vol->fd);
                     return -1;
                 }
 
@@ -543,7 +555,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
                 if ( rc != RC_OK )
                 {
                     _fat_block_release(mt_entry);
-                    rtems_disk_release(vol->dd);
+                    close(vol->fd);
                     return rc;
                 }
             }
@@ -566,7 +578,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
     fs_info->vhash = calloc(FAT_HASH_SIZE, sizeof(rtems_chain_control));
     if ( fs_info->vhash == NULL )
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         rtems_set_errno_and_return_minus_one( ENOMEM );
     }
 
@@ -576,7 +588,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
     fs_info->rhash = calloc(FAT_HASH_SIZE, sizeof(rtems_chain_control));
     if ( fs_info->rhash == NULL )
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         free(fs_info->vhash);
         rtems_set_errno_and_return_minus_one( ENOMEM );
     }
@@ -589,7 +601,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
     fs_info->uino = (char *)calloc(fs_info->uino_pool_size, sizeof(char));
     if ( fs_info->uino == NULL )
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         free(fs_info->vhash);
         free(fs_info->rhash);
         rtems_set_errno_and_return_minus_one( ENOMEM );
@@ -597,7 +609,7 @@ fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry)
     fs_info->sec_buf = (uint8_t *)calloc(vol->bps, sizeof(uint8_t));
     if (fs_info->sec_buf == NULL)
     {
-        rtems_disk_release(vol->dd);
+        close(vol->fd);
         free(fs_info->vhash);
         free(fs_info->rhash);
         free(fs_info->uino);
@@ -634,7 +646,7 @@ fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
 
     fat_buf_release(fs_info);
 
-    if (rtems_bdbuf_syncdev(fs_info->vol.dev) != RTEMS_SUCCESSFUL)
+    if (rtems_bdbuf_syncdev(fs_info->vol.dd) != RTEMS_SUCCESSFUL)
         rc = -1;
 
     for (i = 0; i < FAT_HASH_SIZE; i++)
@@ -660,7 +672,7 @@ fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry)
 
     free(fs_info->uino);
     free(fs_info->sec_buf);
-    rtems_disk_release(fs_info->vol.dd);
+    close(fs_info->vol.fd);
 
     if (rc)
         errno = EIO;
diff --git a/cpukit/libfs/src/dosfs/fat.h b/cpukit/libfs/src/dosfs/fat.h
index 8d62662..204095c 100644
--- a/cpukit/libfs/src/dosfs/fat.h
+++ b/cpukit/libfs/src/dosfs/fat.h
@@ -319,7 +319,7 @@ typedef struct fat_vol_s
     uint8_t            mirror;         /* mirroring enabla/disable */
     uint32_t           afat_loc;       /* active FAT location */
     uint8_t            afat;           /* the number of active FAT */
-    dev_t              dev;            /* device ID */
+    int                fd;             /* the disk device file descriptor */
     rtems_disk_device *dd;             /* disk device (see libblock) */
     void              *private_data;   /* reserved */
 } fat_vol_t;
diff --git a/cpukit/libfs/src/dosfs/fat_file.c b/cpukit/libfs/src/dosfs/fat_file.c
index 5375e90..01dabc8 100644
--- a/cpukit/libfs/src/dosfs/fat_file.c
+++ b/cpukit/libfs/src/dosfs/fat_file.c
@@ -795,7 +795,7 @@ fat_file_datasync(
         for ( i = 0; i < fs_info->vol.spc; i++ )
         {
             /* ... sync it */
-            sc = rtems_bdbuf_read(fs_info->vol.dev, (sec + i), &block);
+            sc = rtems_bdbuf_read(fs_info->vol.dd, (sec + i), &block);
             if (sc != RTEMS_SUCCESSFUL)
                 rtems_set_errno_and_return_minus_one( EIO );
 
diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c b/cpukit/libfs/src/dosfs/msdos_dir.c
index 725fd25..67a0bda 100644
--- a/cpukit/libfs/src/dosfs/msdos_dir.c
+++ b/cpukit/libfs/src/dosfs/msdos_dir.c
@@ -532,7 +532,7 @@ msdos_dir_stat(
     if (sc != RTEMS_SUCCESSFUL)
         rtems_set_errno_and_return_minus_one(EIO);
 
-    buf->st_dev = fs_info->fat.vol.dev;
+    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
     buf->st_ino = fat_fd->ino;
     buf->st_mode  = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO;
     buf->st_rdev = 0ll;
diff --git a/cpukit/libfs/src/dosfs/msdos_file.c b/cpukit/libfs/src/dosfs/msdos_file.c
index b2f98b8..7cd55b0 100644
--- a/cpukit/libfs/src/dosfs/msdos_file.c
+++ b/cpukit/libfs/src/dosfs/msdos_file.c
@@ -281,7 +281,7 @@ msdos_file_stat(
     if (sc != RTEMS_SUCCESSFUL)
         rtems_set_errno_and_return_minus_one(EIO);
 
-    buf->st_dev = fs_info->fat.vol.dev;
+    buf->st_dev = rtems_disk_get_device_identifier(fs_info->fat.vol.dd);
     buf->st_ino = fat_fd->ino;
     buf->st_mode  = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
     buf->st_rdev = 0ll;
diff --git a/cpukit/libfs/src/dosfs/msdos_format.c b/cpukit/libfs/src/dosfs/msdos_format.c
index 1394f81..2a9d090 100644
--- a/cpukit/libfs/src/dosfs/msdos_format.c
+++ b/cpukit/libfs/src/dosfs/msdos_format.c
@@ -370,7 +370,7 @@ static int msdos_format_determine_fmt_params
 +---------------------------------------------------------------------------+
 | Input Parameters:                                                         |
 \*-------------------------------------------------------------------------*/
- const rtems_disk_device            *dd,       /* disk device structure          */
+ int fd,                                       /* disk file descriptor */
  const msdos_format_request_param_t *rqdata,   /* requested fmt parameters */
  msdos_format_param_t               *fmt_params/* computed fmt parameters        */
  )
@@ -386,18 +386,24 @@ static int msdos_format_determine_fmt_params
   uint64_t total_size = 0;
 
   memset(fmt_params,0,sizeof(*fmt_params));
+
   /*
    * this one is fixed in this implementation.
    * At least one thing we don't have to magically guess...
    */
   if (ret_val == 0) {
-    fmt_params->bytes_per_sector = dd->block_size;
-    fmt_params->totl_sector_cnt  = dd->size;
-    total_size = dd->block_size * dd->size;
+    ret_val = rtems_disk_fd_get_block_size(fd, &fmt_params->bytes_per_sector);
+  }
+  if (ret_val == 0) {
+    ret_val = rtems_disk_fd_get_block_count(fd, &fmt_params->totl_sector_cnt);
+  }
+  if (ret_val == 0) {
+    total_size = fmt_params->bytes_per_sector * fmt_params->totl_sector_cnt;
     msdos_format_printf (rqdata, MSDOS_FMT_INFO_LEVEL_DETAIL,
                          "bytes per sector: %d\ntotal sectors: %d\ntotal size: %lu\n",
-                         dd->block_size, dd->size, total_size);
+                         fmt_params->bytes_per_sector, fmt_params->totl_sector_cnt, total_size);
   }
+
   /*
    * determine number of FATs
    */
@@ -889,7 +895,6 @@ int msdos_format
 {
   char                 tmp_sec[FAT_TOTAL_MBR_SIZE];
   int                  rc;
-  rtems_disk_device   *dd        = NULL;
   struct stat          stat_buf;
   int                  ret_val   = 0;
   int                  fd        = -1;
@@ -923,20 +928,11 @@ int msdos_format
     ret_val = -1;
   }
 
-  /* check that  device is registered as block device and lock it */
-  if (ret_val == 0) {
-    dd = rtems_disk_obtain(stat_buf.st_rdev);
-    if (dd == NULL) {
-      errno = ENOTTY;
-      ret_val = -1;
-    }
-  }
-
   /*
    * compute formatting parameters
    */
   if (ret_val == 0) {
-    ret_val = msdos_format_determine_fmt_params(dd,rqdata,&fmt_params);
+    ret_val = msdos_format_determine_fmt_params(fd,rqdata,&fmt_params);
   }
   /*
    * if requested, write whole disk/partition with 0xe5
@@ -1120,8 +1116,6 @@ int msdos_format
   if (fd != -1) {
     close(fd);
   }
-  if (dd != NULL) {
-    rtems_disk_release(dd);
-  }
+
   return ret_val;
 }
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer.c b/cpukit/libfs/src/rfs/rtems-rfs-buffer.c
index ea5cbb3..60f9dea 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-buffer.c
+++ b/cpukit/libfs/src/rfs/rtems-rfs-buffer.c
@@ -20,8 +20,10 @@
 #include "config.h"
 #endif
 
+#include <sys/stat.h>
 #include <inttypes.h>
 #include <errno.h>
+#include <fcntl.h>
 
 #include <rtems/rfs/rtems-rfs-buffer.h>
 #include <rtems/rfs/rtems-rfs-file-system.h>
@@ -285,16 +287,27 @@ int
 rtems_rfs_buffer_open (const char* name, rtems_rfs_file_system* fs)
 {
   struct stat st;
+#if RTEMS_RFS_USE_LIBBLOCK
+  int rv;
+#endif
 
   if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC))
     printf ("rtems-rfs: buffer-open: opening: %s\n", name);
 
-  if (stat (name, &st) < 0)
+  fs->device = open (name, O_RDWR);
+  if (fs->device < 0)
+  {
+    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
+      printf ("rtems-rfs: buffer-open: cannot open file\n");
+    return ENXIO;
+  }
+
+  if (fstat (fs->device, &st) < 0)
   {
     if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
       printf ("rtems-rfs: buffer-open: stat '%s' failed: %s\n",
               name, strerror (errno));
-    return ENOENT;
+    return ENXIO;
   }
 
 #if RTEMS_RFS_USE_LIBBLOCK
@@ -305,26 +318,20 @@ rtems_rfs_buffer_open (const char* name, rtems_rfs_file_system* fs)
   {
     if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
       printf ("rtems-rfs: buffer-open: '%s' is not a block device\n", name);
-    return EIO;
+    return ENXIO;
   }
 
   /*
    * Check that device is registred as a block device and lock it.
    */
-  fs->disk = rtems_disk_obtain (st.st_rdev);
-  if (!fs->disk)
+  rv = rtems_disk_fd_get_disk_device (fs->device, &fs->disk);
+  if (rv != 0)
   {
     if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
       printf ("rtems-rfs: buffer-open: cannot obtain the disk\n");
-    return EIO;
+    return ENXIO;
   }
 #else
-  fs->device = open (name, O_RDWR);
-  if (fs->device < 0)
-  {
-    if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_OPEN))
-      printf ("rtems-rfs: buffer-open: cannot open file\n");
-  }
   fs->media_size = st.st_size;
   strcat (fs->name, name);
 #endif
@@ -355,9 +362,6 @@ rtems_rfs_buffer_close (rtems_rfs_file_system* fs)
     printf ("rtems-rfs: buffer-close: set media block size failed: %d: %s\n",
             rc, strerror (rc));
 
-#if RTEMS_RFS_USE_LIBBLOCK
-  rtems_disk_release (fs->disk);
-#else
   if (close (fs->device) < 0)
   {
     rc = errno;
@@ -365,7 +369,6 @@ rtems_rfs_buffer_close (rtems_rfs_file_system* fs)
       printf ("rtems-rfs: buffer-close: file close failed: %d: %s\n",
               rc, strerror (rc));
   }
-#endif
 
   return rc;
 }
diff --git a/cpukit/libfs/src/rfs/rtems-rfs-file-system.h b/cpukit/libfs/src/rfs/rtems-rfs-file-system.h
index 0ceade2..96fdf6c 100644
--- a/cpukit/libfs/src/rfs/rtems-rfs-file-system.h
+++ b/cpukit/libfs/src/rfs/rtems-rfs-file-system.h
@@ -131,6 +131,11 @@ struct _rtems_rfs_file_system
    */
   size_t block_size;
 
+  /**
+   * The file descriptor for device I/O.
+   */
+  int device;
+
 #if RTEMS_RFS_USE_LIBBLOCK
   /**
    * The disk device. This is the data about the block device this file system
@@ -140,11 +145,6 @@ struct _rtems_rfs_file_system
   rtems_disk_device* disk;
 #else
   /**
-   * The device number which is a the file handle for device I/O.
-   */
-  dev_t device;
-
-  /**
    * The number of blocks in the file system.
    */
   size_t size;
@@ -284,7 +284,7 @@ struct _rtems_rfs_file_system
  * @param _fs Pointer to the file system.
  */
 #if RTEMS_RFS_USE_LIBBLOCK
-#define rtems_rfs_fs_device(_fs) ((_fs)->disk->dev)
+#define rtems_rfs_fs_device(_fs) ((_fs)->disk)
 #else
 #define rtems_rfs_fs_device(_fs) ((_fs)->device)
 #endif
diff --git a/testsuites/libtests/block02/init.c b/testsuites/libtests/block02/init.c
index 00c83a1..58b78d3 100644
--- a/testsuites/libtests/block02/init.c
+++ b/testsuites/libtests/block02/init.c
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2009
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -48,9 +49,9 @@
 
 #define BLOCK_COUNT_B 1
 
-static dev_t dev_a;
+static const rtems_disk_device *dd_a;
 
-static dev_t dev_b;
+static const rtems_disk_device *dd_b;
 
 static volatile bool sync_done = false;
 
@@ -67,14 +68,14 @@ static void task_low(rtems_task_argument arg)
 
   printk("L: try access: A0\n");
 
-  sc = rtems_bdbuf_get(dev_a, 0, &bd);
+  sc = rtems_bdbuf_get(dd_a, 0, &bd);
   ASSERT_SC(sc);
 
   rtems_test_assert(sync_done);
 
   printk("L: access: A0\n");
 
-  rtems_test_assert(bd->dev == dev_a);
+  rtems_test_assert(bd->dd == dd_a);
 
   printk("*** END OF TEST BLOCK 2 ***\n");
 
@@ -90,7 +91,7 @@ static void task_high(rtems_task_argument arg)
 
   printk("H: try access: A0\n");
 
-  sc = rtems_bdbuf_get(dev_a, 0, &bd);
+  sc = rtems_bdbuf_get(dd_a, 0, &bd);
   ASSERT_SC(sc);
 
   rtems_test_assert(sync_done);
@@ -106,7 +107,7 @@ static void task_high(rtems_task_argument arg)
 
   printk("H: try access: B0\n");
 
-  sc = rtems_bdbuf_get(dev_b, 0, &bd);
+  sc = rtems_bdbuf_get(dd_b, 0, &bd);
   ASSERT_SC(sc);
 
   printk("H: access: B0\n");
@@ -127,6 +128,8 @@ static rtems_task Init(rtems_task_argument argument)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_bdbuf_buffer *bd = NULL;
+  dev_t dev_a = 0;
+  dev_t dev_b = 0;
 
   printk("\n\n*** TEST BLOCK 2 ***\n");
 
@@ -139,6 +142,12 @@ static rtems_task Init(rtems_task_argument argument)
   sc = ramdisk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, false, "/dev/rdb", &dev_b);
   ASSERT_SC(sc);
 
+  dd_a = rtems_disk_obtain(dev_a);
+  rtems_test_assert(dd_a != NULL);
+
+  dd_b = rtems_disk_obtain(dev_b);
+  rtems_test_assert(dd_b != NULL);
+
   sc = rtems_task_create(
     rtems_build_name(' ', 'L', 'O', 'W'),
     PRIORITY_LOW,
@@ -165,7 +174,7 @@ static rtems_task Init(rtems_task_argument argument)
   sc = rtems_task_start(task_id_high, task_high, 0);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_get(dev_a, 0, &bd);
+  sc = rtems_bdbuf_get(dd_a, 0, &bd);
   ASSERT_SC(sc);
 
   sc = rtems_bdbuf_sync(bd);
diff --git a/testsuites/libtests/block03/init.c b/testsuites/libtests/block03/init.c
index f101eb7..2cfb806 100644
--- a/testsuites/libtests/block03/init.c
+++ b/testsuites/libtests/block03/init.c
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2009
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -44,7 +45,7 @@
 
 #define BLOCK_COUNT 2
 
-static dev_t dev;
+static const rtems_disk_device *dd;
 
 static volatile bool sync_done = false;
 
@@ -61,7 +62,7 @@ static void task_low(rtems_task_argument arg)
 
   printk("L: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   rtems_test_assert(sync_done);
@@ -84,7 +85,7 @@ static void task_high(rtems_task_argument arg)
 
   printk("H: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   rtems_test_assert(sync_done);
@@ -100,7 +101,7 @@ static void task_high(rtems_task_argument arg)
 
   printk("H: try access: 1\n");
 
-  sc = rtems_bdbuf_get(dev, 1, &bd);
+  sc = rtems_bdbuf_get(dd, 1, &bd);
   ASSERT_SC(sc);
 
   printk("H: access: 1\n");
@@ -121,6 +122,7 @@ static rtems_task Init(rtems_task_argument argument)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_bdbuf_buffer *bd = NULL;
+  dev_t dev = 0;
 
   printk("\n\n*** TEST BLOCK 3 ***\n");
 
@@ -130,6 +132,9 @@ static rtems_task Init(rtems_task_argument argument)
   sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
   ASSERT_SC(sc);
 
+  dd = rtems_disk_obtain(dev);
+  rtems_test_assert(dd != NULL);
+
   sc = rtems_task_create(
     rtems_build_name(' ', 'L', 'O', 'W'),
     PRIORITY_LOW,
@@ -156,7 +161,7 @@ static rtems_task Init(rtems_task_argument argument)
   sc = rtems_task_start(task_id_high, task_high, 0);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   sc = rtems_bdbuf_sync(bd);
diff --git a/testsuites/libtests/block04/init.c b/testsuites/libtests/block04/init.c
index 27b932a..ff7b204 100644
--- a/testsuites/libtests/block04/init.c
+++ b/testsuites/libtests/block04/init.c
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2009
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -44,7 +45,7 @@
 
 #define BLOCK_COUNT 1
 
-static dev_t dev;
+static const rtems_disk_device *dd;
 
 static rtems_id task_id_low;
 
@@ -57,7 +58,7 @@ static void task_low(rtems_task_argument arg)
 
   printk("L: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("L: access: 0\n");
@@ -83,7 +84,7 @@ static void task_high(rtems_task_argument arg)
 
   printk("H: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("H: access: 0\n");
@@ -103,6 +104,7 @@ static void task_high(rtems_task_argument arg)
 static rtems_task Init(rtems_task_argument argument)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
+  dev_t dev = 0;
 
   printk("\n\n*** TEST BLOCK 4 ***\n");
 
@@ -112,6 +114,9 @@ static rtems_task Init(rtems_task_argument argument)
   sc = ramdisk_register(BLOCK_SIZE, BLOCK_COUNT, false, "/dev/rda", &dev);
   ASSERT_SC(sc);
 
+  dd = rtems_disk_obtain(dev);
+  rtems_test_assert(dd != NULL);
+
   sc = rtems_task_create(
     rtems_build_name(' ', 'L', 'O', 'W'),
     PRIORITY_LOW,
diff --git a/testsuites/libtests/block05/init.c b/testsuites/libtests/block05/init.c
index e795f7e..8af26fe 100644
--- a/testsuites/libtests/block05/init.c
+++ b/testsuites/libtests/block05/init.c
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2009
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -56,9 +57,9 @@
 /* In case of trouble change this to 1 or 2 for more output */
 static unsigned output_level = 0;
 
-static dev_t dev_a;
+static const rtems_disk_device *dd_a;
 
-static dev_t dev_b;
+static const rtems_disk_device *dd_b;
 
 static rtems_id task_id_init;
 
@@ -146,24 +147,27 @@ static rtems_bdbuf_buffer *get(enum get_type type, enum blk_kind kind)
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_bdbuf_buffer *bd = NULL;
   rtems_blkdev_bnum blk_index = 0;
-  rtems_status_code (*get_bd)(dev_t, rtems_blkdev_bnum, rtems_bdbuf_buffer **)
-    = NULL;
-  dev_t dev = 0;
+  rtems_status_code (*get_bd)(
+    const rtems_disk_device *,
+    rtems_blkdev_bnum,
+    rtems_bdbuf_buffer **
+  ) = NULL;
+  const rtems_disk_device *dd = NULL;
   size_t bds_per_group = 0;
 
   switch (kind) {
     case BLK_A0:
-      dev = dev_a;
+      dd = dd_a;
       blk_index = 0;
       bds_per_group = 2;
       break;
     case BLK_A1:
-      dev = dev_a;
+      dd = dd_a;
       blk_index = 1;
       bds_per_group = 2;
       break;
     case BLK_B0:
-      dev = dev_b;
+      dd = dd_b;
       blk_index = 0;
       bds_per_group = 1;
       break;
@@ -184,10 +188,10 @@ static rtems_bdbuf_buffer *get(enum get_type type, enum blk_kind kind)
       break;
   }
 
-  sc = (*get_bd)(dev, blk_index, &bd);
+  sc = (*get_bd)(dd, blk_index, &bd);
   rtems_test_assert(
     sc == RTEMS_SUCCESSFUL
-      && bd->dev == dev
+      && bd->dd == dd
       && bd->block == blk_index
       && bd->group->bds_per_group == bds_per_group
    );
@@ -313,8 +317,8 @@ static void execute_test(unsigned i)
   sc = rtems_task_resume(task_id_high);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_get(dev_b, 0, &bd);
-  rtems_test_assert(sc == RTEMS_SUCCESSFUL && bd->dev == dev_b && bd->block == 0);
+  sc = rtems_bdbuf_get(dd_b, 0, &bd);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL && bd->dd == dd_b && bd->block == 0);
 
   sc = rtems_bdbuf_release(bd);
   ASSERT_SC(sc);
@@ -350,10 +354,10 @@ static void execute_test(unsigned i)
 
   print(2, "F\n");
 
-  sc = rtems_bdbuf_syncdev(dev_a);
+  sc = rtems_bdbuf_syncdev(dd_a);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_syncdev(dev_b);
+  sc = rtems_bdbuf_syncdev(dd_b);
   ASSERT_SC(sc);
 }
 
@@ -383,10 +387,10 @@ static int disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
   }
 }
 
-rtems_status_code disk_register(
+static void disk_register(
   uint32_t block_size,
   rtems_blkdev_bnum block_count,
-  dev_t *dev_ptr
+  const rtems_disk_device **dd_ptr
 )
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
@@ -408,9 +412,8 @@ rtems_status_code disk_register(
   );
   ASSERT_SC(sc);
 
-  *dev_ptr = dev;
-
-  return RTEMS_SUCCESSFUL;
+  *dd_ptr = rtems_disk_obtain(dev);
+  rtems_test_assert(*dd_ptr!= NULL);
 }
 
 static rtems_task Init(rtems_task_argument argument)
@@ -425,11 +428,9 @@ static rtems_task Init(rtems_task_argument argument)
   sc = rtems_disk_io_initialize();
   ASSERT_SC(sc);
 
-  sc = disk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, &dev_a);
-  ASSERT_SC(sc);
+  disk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, &dd_a);
 
-  sc = disk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, &dev_b);
-  ASSERT_SC(sc);
+  disk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, &dd_b);
 
   sc = rtems_task_create(
     rtems_build_name(' ', 'L', 'O', 'W'),
diff --git a/testsuites/libtests/block06/init.c b/testsuites/libtests/block06/init.c
index fd84049..11e26e2 100644
--- a/testsuites/libtests/block06/init.c
+++ b/testsuites/libtests/block06/init.c
@@ -107,6 +107,7 @@ typedef struct bdbuf_task_control
   rtems_device_major_number major;
   rtems_device_minor_number minor;
   bool                      passed;
+  const rtems_disk_device  *dd;
 } bdbuf_task_control;
 
 #define BDBUF_TEST_TASKS (3)
@@ -188,7 +189,7 @@ bdbuf_disk_unlock (bdbuf_disk* bdd)
 /**
  * BDBUf wait for the wait event.
  */
-rtems_status_code
+static rtems_status_code
 bdbuf_wait (const char* who, unsigned long timeout)
 {
   rtems_status_code sc;
@@ -340,7 +341,8 @@ static void
 bdbuf_task_control_init (int                       task,
                          bdbuf_task_control*       tc,
                          rtems_id                  master,
-                         rtems_device_major_number major)
+                         rtems_device_major_number major,
+                         const rtems_disk_device  *dd)
 {
   char name[6];
   sprintf (name, "bdt%d", task);
@@ -353,6 +355,7 @@ bdbuf_task_control_init (int                       task,
   tc->major  = major;
   tc->minor  = 0;
   tc->passed = false;
+  tc->dd     = dd;
 }
 
 static bool
@@ -608,9 +611,11 @@ static rtems_driver_address_table bdbuf_disk_io_ops = {
  */
 
 static bool
-bdbuf_tests_setup_disk (rtems_device_major_number* major)
+bdbuf_tests_setup_disk (rtems_device_major_number* major,
+                        const rtems_disk_device **dd_ptr)
 {
   rtems_status_code sc;
+  bool ok;
 
   /*
    * Register the disk driver.
@@ -620,8 +625,14 @@ bdbuf_tests_setup_disk (rtems_device_major_number* major)
   sc = rtems_io_register_driver (RTEMS_DRIVER_AUTO_MAJOR,
                                  &bdbuf_disk_io_ops,
                                  major);
+  ok = sc == RTEMS_SUCCESSFUL;
 
-  return sc == RTEMS_SUCCESSFUL;
+  if (ok) {
+    *dd_ptr = rtems_disk_obtain (rtems_filesystem_make_dev_t (*major, 0));
+    ok = *dd_ptr != NULL;
+  }
+
+  return ok;
 }
 
 static bool
@@ -672,10 +683,8 @@ bdbuf_tests_task_0_test_1 (bdbuf_task_control* tc)
 
   for (i = 0; (i < 2) && passed; i++)
   {
-    dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
     bdbuf_test_printf ("%s: rtems_bdbuf_get[0]: ", tc->name);
-    sc = rtems_bdbuf_get (device, 0, &bd);
+    sc = rtems_bdbuf_get (tc->dd, 0, &bd);
     if (!bdbuf_test_print_sc (sc, true))
     {
       passed = false;
@@ -722,10 +731,8 @@ bdbuf_tests_task_0_test_2 (bdbuf_task_control* tc)
 
   for (i = 0; (i < 5) && passed; i++)
   {
-    dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
     bdbuf_test_printf ("%s: rtems_bdbuf_get[%d]: ", tc->name, i);
-    sc = rtems_bdbuf_get (device, i, &bd);
+    sc = rtems_bdbuf_get (tc->dd, i, &bd);
     if (!bdbuf_test_print_sc (sc, true))
       passed = false;
 
@@ -783,7 +790,6 @@ bdbuf_tests_task_0_test_3 (bdbuf_task_control* tc)
   rtems_status_code   sc;
   bool                passed;
   rtems_bdbuf_buffer* bd;
-  dev_t               device;
 
   /*
    * Set task control's passed to false to handle a timeout.
@@ -791,8 +797,6 @@ bdbuf_tests_task_0_test_3 (bdbuf_task_control* tc)
   tc->passed = false;
   passed = true;
 
-  device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
   bdbuf_disk_lock (&bdbuf_disks[tc->minor]);
   bdbuf_disks[tc->minor].driver_action = BDBUF_DISK_NOOP;
   bdbuf_disk_unlock (&bdbuf_disks[tc->minor]);
@@ -801,7 +805,7 @@ bdbuf_tests_task_0_test_3 (bdbuf_task_control* tc)
    * Read the buffer and then release it.
    */
   bdbuf_test_printf ("%s: rtems_bdbuf_read[5]: ", tc->name);
-  sc = rtems_bdbuf_read (device, 5, &bd);
+  sc = rtems_bdbuf_read (tc->dd, 5, &bd);
   if ((passed = bdbuf_test_print_sc (sc, true)))
   {
     bdbuf_test_printf ("%s: rtems_bdbuf_release_modified[5]: ", tc->name);
@@ -814,7 +818,7 @@ bdbuf_tests_task_0_test_3 (bdbuf_task_control* tc)
    * be maintained as modified.
    */
   bdbuf_test_printf ("%s: rtems_bdbuf_read[5]: ", tc->name);
-  sc = rtems_bdbuf_read (device, 5, &bd);
+  sc = rtems_bdbuf_read (tc->dd, 5, &bd);
   if ((passed = bdbuf_test_print_sc (sc, true)))
   {
     bdbuf_test_printf ("%s: rtems_bdbuf_release[5]: ", tc->name);
@@ -871,10 +875,8 @@ bdbuf_tests_task_0_test_4 (bdbuf_task_control* tc)
 
   for (i = 0; (i < num) && passed; i++)
   {
-    dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
     bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
-    sc = rtems_bdbuf_read (device, i, &bd);
+    sc = rtems_bdbuf_read (tc->dd, i, &bd);
     if (!bdbuf_test_print_sc (sc, true))
       passed = false;
 
@@ -991,10 +993,8 @@ bdbuf_tests_task_0_test_6 (bdbuf_task_control* tc)
 
   for (i = 0; (i < 5) && passed; i++)
   {
-    dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
     bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
-    sc = rtems_bdbuf_get (device, i, &bd);
+    sc = rtems_bdbuf_get (tc->dd, i, &bd);
     if (!bdbuf_test_print_sc (sc, true))
       passed = false;
 
@@ -1030,7 +1030,6 @@ bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc)
   int                 i;
   rtems_bdbuf_buffer* bd;
   rtems_chain_control buffers;
-  dev_t               device;
 
   /*
    * Set task control's passed to false to handle a timeout.
@@ -1044,8 +1043,6 @@ bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc)
   bdbuf_clear_disk_driver_watch (tc);
   bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP);
 
-  device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
   /*
    * Get the blocks 0 -> 4 and hold them.
    */
@@ -1054,7 +1051,7 @@ bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc)
   for (i = 0; (i < 5) && passed; i++)
   {
     bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
-    sc = rtems_bdbuf_get (device, i, &bd);
+    sc = rtems_bdbuf_get (tc->dd, i, &bd);
     if (!bdbuf_test_print_sc (sc, true))
       passed = false;
 
@@ -1074,9 +1071,9 @@ bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc)
   {
     bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: ",
                        tc->name, i,
-                       rtems_filesystem_dev_major_t (device),
-                       rtems_filesystem_dev_minor_t (device));
-    passed = bdbuf_test_print_sc (rtems_bdbuf_syncdev (device), true);
+                       tc->major,
+                       tc->minor);
+    passed = bdbuf_test_print_sc (rtems_bdbuf_syncdev (tc->dd), true);
   }
 
   tc->passed = passed;
@@ -1093,7 +1090,6 @@ bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc)
   rtems_chain_control buffers;
   rtems_chain_node*   node;
   rtems_chain_node*   pnode;
-  dev_t               device;
 
   /*
    * Set task control's passed to false to handle a timeout.
@@ -1107,8 +1103,6 @@ bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc)
   bdbuf_clear_disk_driver_watch (tc);
   bdbuf_set_disk_driver_action (tc, BDBUF_DISK_NOOP);
 
-  device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
   /*
    * Get the blocks 0 -> 4 and hold them.
    */
@@ -1117,7 +1111,7 @@ bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc)
   for (i = 0; (i < 5) && passed; i++)
   {
     bdbuf_test_printf ("%s: rtems_bdbuf_read[%d]: ", tc->name, i);
-    sc = rtems_bdbuf_get (device, i, &bd);
+    sc = rtems_bdbuf_get (tc->dd, i, &bd);
     if (!bdbuf_test_print_sc (sc, true))
       passed = false;
 
@@ -1159,13 +1153,13 @@ bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc)
 
     bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: checking order\n",
                        tc->name, i,
-                       rtems_filesystem_dev_major_t (device),
-                       rtems_filesystem_dev_minor_t (device));
-    sc = rtems_bdbuf_syncdev (device);
+                       tc->major,
+                       tc->minor);
+    sc = rtems_bdbuf_syncdev (tc->dd);
     bdbuf_test_printf ("%s: rtems_bdbuf_syncdev[%d:%d]: ",
                        tc->name, i,
-                       rtems_filesystem_dev_major_t (device),
-                       rtems_filesystem_dev_minor_t (device));
+                       tc->major,
+                       tc->minor);
     passed = bdbuf_test_print_sc (sc, true);
   }
 
@@ -1259,10 +1253,8 @@ bdbuf_tests_ranged_get_release (bdbuf_task_control* tc,
 
   for (i = lower; (i < upper) && passed; i++)
   {
-    dev_t device = rtems_filesystem_make_dev_t (tc->major, tc->minor);
-
     bdbuf_test_printf ("%s: rtems_bdbuf_get[%d]: blocking ...\n", tc->name, i);
-    sc = rtems_bdbuf_get (device, i, &bd);
+    sc = rtems_bdbuf_get (tc->dd, i, &bd);
     bdbuf_test_printf ("%s: rtems_bdbuf_get[%d]: ", tc->name, i);
     if (!bdbuf_test_print_sc (sc, true))
     {
@@ -1770,6 +1762,7 @@ bdbuf_tester (void)
   rtems_task_priority       old_priority;
   int                       t;
   bool                      passed = true;
+  const rtems_disk_device *dd;
 
   /*
    * Change priority to a lower one.
@@ -1783,7 +1776,7 @@ bdbuf_tester (void)
   /*
    * This sets up the buffer pools.
    */
-  if (!bdbuf_tests_setup_disk (&major))
+  if (!bdbuf_tests_setup_disk (&major, &dd))
   {
     bdbuf_test_printf ("disk set up failed\n");
     return;
@@ -1804,7 +1797,8 @@ bdbuf_tester (void)
   {
     bdbuf_task_control_init (t, &tasks[t],
                              rtems_task_self (),
-                             major);
+                             major,
+                             dd);
 
     if (!bdbuf_tests_create_task (&tasks[t],
                                   BDBUF_TESTS_PRI_HIGH - t,
diff --git a/testsuites/libtests/block07/init.c b/testsuites/libtests/block07/init.c
index ea60a1f..969fd36 100644
--- a/testsuites/libtests/block07/init.c
+++ b/testsuites/libtests/block07/init.c
@@ -54,7 +54,7 @@
 
 #define BLOCK_COUNT 2
 
-static dev_t dev;
+static rtems_disk_device *dd;
 
 static rtems_id task_id_low;
 
@@ -65,12 +65,11 @@ static rtems_id task_id_high;
 static void change_block_size(void)
 {
   int rv = 0;
-  uint32_t new_block_size = BLOCK_SIZE_B;
   int fd = open("/dev/rda", O_RDWR);
 
   rtems_test_assert(fd >= 0);
 
-  rv = ioctl(fd, RTEMS_BLKIO_SETBLKSIZE, &new_block_size);
+  rv = rtems_disk_fd_set_block_size(fd, BLOCK_SIZE_B);
   rtems_test_assert(rv == 0);
 
   rv = close(fd);
@@ -84,7 +83,7 @@ static void task_low(rtems_task_argument arg)
 
   printk("L: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("L: access: 0\n");
@@ -110,7 +109,7 @@ static void task_mid(rtems_task_argument arg)
 
   printk("M: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("M: access: 0\n");
@@ -136,7 +135,7 @@ static void task_high(rtems_task_argument arg)
 
   printk("H: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("H: access: 0\n");
@@ -158,6 +157,7 @@ static rtems_task Init(rtems_task_argument argument)
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_task_priority cur_prio = 0;
   rtems_bdbuf_buffer *bd = NULL;
+  dev_t dev = 0;
 
   printk("\n\n*** TEST BLOCK 7 ***\n");
 
@@ -167,6 +167,9 @@ static rtems_task Init(rtems_task_argument argument)
   sc = ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, false, "/dev/rda", &dev);
   ASSERT_SC(sc);
 
+  dd = rtems_disk_obtain(dev);
+  rtems_test_assert(dd != NULL);
+
   sc = rtems_task_create(
     rtems_build_name(' ', 'L', 'O', 'W'),
     PRIORITY_LOW,
@@ -212,7 +215,7 @@ static rtems_task Init(rtems_task_argument argument)
   sc = rtems_task_suspend(task_id_high);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_get(dev, 1, &bd);
+  sc = rtems_bdbuf_get(dd, 1, &bd);
   ASSERT_SC(sc);
 
   sc = rtems_bdbuf_release(bd);
@@ -220,7 +223,7 @@ static rtems_task Init(rtems_task_argument argument)
 
   printk("I: try access: 0\n");
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("I: access: 0\n");
diff --git a/testsuites/libtests/block08/bdbuf_test1_1.c b/testsuites/libtests/block08/bdbuf_test1_1.c
index 9f3ee06..2958f27 100644
--- a/testsuites/libtests/block08/bdbuf_test1_1.c
+++ b/testsuites/libtests/block08/bdbuf_test1_1.c
@@ -106,7 +106,7 @@ bdbuf_test1_1_thread1(rtems_task_argument arg)
      * Step 1-2:
      * Successful read operation.
      */
-    rc = rtems_bdbuf_read(test_dev, 0, &bd1);
+    rc = rtems_bdbuf_read(test_dd, 0, &bd1);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -124,7 +124,7 @@ bdbuf_test1_1_thread1(rtems_task_argument arg)
      * Read operation fails with RTEMS_IO_ERROR code.
      * The function shall not update user pointer.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd2);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd2);
     if (rc != RTEMS_IO_ERROR || bd2 != NULL)
     {
         TEST_FAILED();
@@ -137,7 +137,7 @@ bdbuf_test1_1_thread1(rtems_task_argument arg)
      * Read operation fails with RTEMS_IO_ERROR code.
      * The function shall not update user pointer.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd2);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd2);
     if (rc != RTEMS_IO_ERROR || bd2 != NULL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test1_2.c b/testsuites/libtests/block08/bdbuf_test1_2.c
index 61b978c..1d5e44b 100644
--- a/testsuites/libtests/block08/bdbuf_test1_2.c
+++ b/testsuites/libtests/block08/bdbuf_test1_2.c
@@ -122,7 +122,7 @@ bdbuf_test1_2_thread1(rtems_task_argument arg)
      * driver will notify about an error, and as the
      * result this call will return an error.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_IO_ERROR || bd != NULL)
     {
         TEST_FAILED();
@@ -152,7 +152,7 @@ bdbuf_test1_2_thread2(rtems_task_argument arg)
      * But main test task will agin tell device driver to return
      * RTEMS_IO_ERROR data transfer result.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_IO_ERROR || bd != NULL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test1_3.c b/testsuites/libtests/block08/bdbuf_test1_3.c
index 9ea5b65..ab5d1dc 100644
--- a/testsuites/libtests/block08/bdbuf_test1_3.c
+++ b/testsuites/libtests/block08/bdbuf_test1_3.c
@@ -131,7 +131,7 @@ bdbuf_test1_3_thread1(rtems_task_argument arg)
      * driver will notify about an error, and as the
      * result this call will return an error.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_IO_ERROR || bd != NULL)
     {
         TEST_FAILED();
@@ -160,7 +160,7 @@ bdbuf_test1_3_thread2(rtems_task_argument arg)
      * number, bdbuf library should ask for re-read data again.
      * Time time main task will tell driver to report success.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL || bd == NULL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test1_4.c b/testsuites/libtests/block08/bdbuf_test1_4.c
index b7a4b0c..4d6e028 100644
--- a/testsuites/libtests/block08/bdbuf_test1_4.c
+++ b/testsuites/libtests/block08/bdbuf_test1_4.c
@@ -125,7 +125,7 @@ bdbuf_test1_4_thread1(rtems_task_argument arg)
      * date transfer, and as the result this call 
      * will return valid buffer.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -161,7 +161,7 @@ bdbuf_test1_4_thread2(rtems_task_argument arg)
      * On step 4 thread #1 releases buffer and as the result 
      * our read operation should finish with success. 
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test1_5.c b/testsuites/libtests/block08/bdbuf_test1_5.c
index 4e09359..c054db3 100644
--- a/testsuites/libtests/block08/bdbuf_test1_5.c
+++ b/testsuites/libtests/block08/bdbuf_test1_5.c
@@ -101,7 +101,7 @@ bdbuf_test1_5_thread1(rtems_task_argument arg)
      * Step 1:
      * read blk #N on thread #1
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -133,7 +133,7 @@ bdbuf_test1_5_thread2(rtems_task_argument arg)
      * Try to read block #N. Right now thread #1 owns
      * this buffer, so we will block waiting for buffer.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test2_1.c b/testsuites/libtests/block08/bdbuf_test2_1.c
index 6005657..435d718 100644
--- a/testsuites/libtests/block08/bdbuf_test2_1.c
+++ b/testsuites/libtests/block08/bdbuf_test2_1.c
@@ -142,7 +142,7 @@ bdbuf_test2_1_thread1(rtems_task_argument arg)
      * date transfer, and as the result this call 
      * will return valid buffer.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -178,7 +178,7 @@ bdbuf_test2_1_thread2(rtems_task_argument arg)
      * On step 4 thread #1 releases buffer and as the result 
      * our read operation should finish with success. 
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test2_2.c b/testsuites/libtests/block08/bdbuf_test2_2.c
index 394a158..5ee614c 100644
--- a/testsuites/libtests/block08/bdbuf_test2_2.c
+++ b/testsuites/libtests/block08/bdbuf_test2_2.c
@@ -142,7 +142,7 @@ bdbuf_test2_2_thread1(rtems_task_argument arg)
      * date transfer, and as the result this call 
      * will return valid buffer.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -178,7 +178,7 @@ bdbuf_test2_2_thread2(rtems_task_argument arg)
      * On step 4 thread #1 releases buffer and as the result 
      * our read operation should finish with success. 
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test3_1.c b/testsuites/libtests/block08/bdbuf_test3_1.c
index cdee6eb..592fa01 100644
--- a/testsuites/libtests/block08/bdbuf_test3_1.c
+++ b/testsuites/libtests/block08/bdbuf_test3_1.c
@@ -116,7 +116,7 @@ bdbuf_test3_1_thread1(rtems_task_argument arg)
      * [An entry is found in AVL tree, removed from modified list and 
      * returned with state ACCESS_MODIFIED]
      */
-    rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -128,7 +128,7 @@ bdbuf_test3_1_thread1(rtems_task_argument arg)
         TEST_FAILED();
     }
 
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -166,7 +166,7 @@ bdbuf_test3_1_thread2(rtems_task_argument arg)
      * this thread blocks on 
      * rtems_bdbuf_wait(pool, &pool->waiting, &pool->wait_waiters)]
      */
-    rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_M, &bd);
+    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_M, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test3_2.c b/testsuites/libtests/block08/bdbuf_test3_2.c
index b9c9775..111b57f 100644
--- a/testsuites/libtests/block08/bdbuf_test3_2.c
+++ b/testsuites/libtests/block08/bdbuf_test3_2.c
@@ -117,7 +117,7 @@ bdbuf_test3_2_thread1(rtems_task_argument arg)
      * Step 1:
      * Call rtems_bdbuf_read(#N) to get a buffer;
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N1, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N1, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -150,7 +150,7 @@ bdbuf_test3_2_thread2(rtems_task_argument arg)
      * Step 2:
      * In thread #2 call get(#N2)
      */
-    rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_N2, &bd);
+    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_N2, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -180,7 +180,7 @@ bdbuf_test3_2_thread3(rtems_task_argument arg)
      * Step 3:
      * In thread #3 call get(#N3)
      */
-    rc = rtems_bdbuf_get(test_dev, TEST_BLK_NUM_N3, &bd);
+    rc = rtems_bdbuf_get(test_dd, TEST_BLK_NUM_N3, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test3_3.c b/testsuites/libtests/block08/bdbuf_test3_3.c
index 13ac7a2..27dbfa2 100644
--- a/testsuites/libtests/block08/bdbuf_test3_3.c
+++ b/testsuites/libtests/block08/bdbuf_test3_3.c
@@ -128,7 +128,7 @@ bdbuf_test3_3_thread1(rtems_task_argument arg)
      * Step 1:
      * Call rtems_bdbuf_read(#N) to get a buffer;
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N1, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N1, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -161,7 +161,7 @@ bdbuf_test3_3_thread2(rtems_task_argument arg)
      * Step 2:
      * In thread #2 call read(#N2)
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N2, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N2, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -191,7 +191,7 @@ bdbuf_test3_3_thread3(rtems_task_argument arg)
      * Step 3:
      * In thread #3 call read(#N3)
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N3, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N3, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test4_1.c b/testsuites/libtests/block08/bdbuf_test4_1.c
index 6961c35..914216d 100644
--- a/testsuites/libtests/block08/bdbuf_test4_1.c
+++ b/testsuites/libtests/block08/bdbuf_test4_1.c
@@ -122,7 +122,7 @@ bdbuf_test4_1_thread1(rtems_task_argument arg)
      * Step 1:
      * Call rtems_bdbuf_read(#N) in thread #1;
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -158,7 +158,7 @@ bdbuf_test4_1_thread2(rtems_task_argument arg)
      * In thread #2 call rtems_bdbuf_read(#N).
      * We will block on this call.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test4_2.c b/testsuites/libtests/block08/bdbuf_test4_2.c
index 628e65e..c1d8890 100644
--- a/testsuites/libtests/block08/bdbuf_test4_2.c
+++ b/testsuites/libtests/block08/bdbuf_test4_2.c
@@ -109,7 +109,7 @@ bdbuf_test4_2_thread1(rtems_task_argument arg)
      * Step 1:
      * Call rtems_bdbuf_read(#N) in thread #1;
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -143,7 +143,7 @@ bdbuf_test4_2_thread2(rtems_task_argument arg)
      * In thread #2 call read(#N).
      * We will block on this call.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_test4_3.c b/testsuites/libtests/block08/bdbuf_test4_3.c
index 55de280..ab7861e 100644
--- a/testsuites/libtests/block08/bdbuf_test4_3.c
+++ b/testsuites/libtests/block08/bdbuf_test4_3.c
@@ -103,7 +103,7 @@ bdbuf_test4_3_thread1(rtems_task_argument arg)
      * Step 1:
      * Call rtems_bdbuf_read(#N) in thread #1;
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
@@ -137,7 +137,7 @@ bdbuf_test4_3_thread2(rtems_task_argument arg)
      * In thread #2 call rtems_bdbuf_read(#N).
      * We will block on this call.
      */
-    rc = rtems_bdbuf_read(test_dev, TEST_BLK_NUM_N, &bd);
+    rc = rtems_bdbuf_read(test_dd, TEST_BLK_NUM_N, &bd);
     if (rc != RTEMS_SUCCESSFUL)
     {
         TEST_FAILED();
diff --git a/testsuites/libtests/block08/bdbuf_tests.c b/testsuites/libtests/block08/bdbuf_tests.c
index bc6b772..f265a09 100644
--- a/testsuites/libtests/block08/bdbuf_tests.c
+++ b/testsuites/libtests/block08/bdbuf_tests.c
@@ -49,7 +49,7 @@ struct bdbuf_test_descr {
 #define TEST_SEM_ATTRIBS RTEMS_DEFAULT_ATTRIBUTES
 
 /** Device ID used for testing */
-dev_t      test_dev = (dev_t)-1;
+const rtems_disk_device *test_dd = NULL;
 
 /** Test result variable */
 bool       good_test_result = true;
@@ -108,6 +108,7 @@ run_bdbuf_tests()
     rtems_disk_device  *disk;
     rtems_status_code   sc;
     dev_t               dev = -1;
+    dev_t               test_dev;
     unsigned int        i;
 
     rtems_device_major_number  major;
@@ -153,6 +154,13 @@ run_bdbuf_tests()
         return;
     }
 
+    test_dd = rtems_disk_obtain(test_dev);
+    if (test_dd == NULL)
+    {
+        printf("Failed to obtain %s disk\n", TEST_DISK_NAME);
+        return;
+    }
+
     /*
      * On initialization test disk device driver registers
      * its RX message queue, so we just need to locate it.
diff --git a/testsuites/libtests/block08/bdbuf_tests.h b/testsuites/libtests/block08/bdbuf_tests.h
index e8affa1..ecd932f 100644
--- a/testsuites/libtests/block08/bdbuf_tests.h
+++ b/testsuites/libtests/block08/bdbuf_tests.h
@@ -85,7 +85,7 @@ typedef struct bdbuf_test_msg {
 
     union {
         struct driver_req {
-            dev_t     dev;
+            const rtems_disk_device *dd;
             uint32_t  req;
             void     *argp;
         } driver_req;
@@ -152,7 +152,7 @@ typedef struct test_ctx {
 extern test_ctx g_test_ctx;
 
 /** Device ID used for testing */
-extern dev_t      test_dev;
+extern const rtems_disk_device *test_dd;
 
 /**
  * Create a message queue for test driver that is used for
@@ -259,7 +259,7 @@ extern bool       good_test_result;
     do {                                                                \
         WAIT_DRV_MSG(msg_);                                             \
         if ((msg_)->val.driver_req.req != RTEMS_BLKIO_REQUEST ||        \
-            (msg_)->val.driver_req.dev != test_dev ||                   \
+            (msg_)->val.driver_req.dd != test_dd ||                   \
             ((rtems_blkdev_request *)                                   \
                  ((msg_)->val.driver_req.argp))->req !=                 \
                  RTEMS_BLKDEV_REQ_WRITE)                                \
@@ -267,7 +267,7 @@ extern bool       good_test_result;
             printk("Unexpected message received by disk driver: "       \
                    "req - 0x%x (0x%x), dev - %d (%d)\n",                \
                    (msg_)->val.driver_req.req, RTEMS_BLKIO_REQUEST,     \
-                   (msg_)->val.driver_req.dev, test_dev);               \
+                   (msg_)->val.driver_req.dd, test_dd);               \
             return;                                                     \
         }                                                               \
     } while (0)
diff --git a/testsuites/libtests/block08/test_disk.c b/testsuites/libtests/block08/test_disk.c
index 358b361..461914f 100644
--- a/testsuites/libtests/block08/test_disk.c
+++ b/testsuites/libtests/block08/test_disk.c
@@ -34,7 +34,6 @@ static Objects_Id testq_id = OBJECTS_ID_NONE;
 static int
 test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
 {
-    dev_t             dev = rtems_disk_get_device_identifier(dd);
     rtems_status_code rc;
     bdbuf_test_msg    msg;
     size_t            msg_size;
@@ -66,7 +65,7 @@ test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
 
     memset(&msg, 0, sizeof(msg));
     msg.type = BDBUF_TEST_MSG_TYPE_DRIVER_REQ;
-    msg.val.driver_req.dev = dev;
+    msg.val.driver_req.dd = dd;
     msg.val.driver_req.req = req;
     msg.val.driver_req.argp = argp;
 
diff --git a/testsuites/libtests/block09/init.c b/testsuites/libtests/block09/init.c
index 5d7a8b7..b7426c3 100644
--- a/testsuites/libtests/block09/init.c
+++ b/testsuites/libtests/block09/init.c
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2009
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -108,7 +109,7 @@ static int disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
   }
 }
 
-rtems_status_code disk_register(
+static rtems_status_code disk_register(
   uint32_t block_size,
   rtems_blkdev_bnum block_count,
   dev_t *dev_ptr
@@ -139,7 +140,7 @@ rtems_status_code disk_register(
 }
 
 static void check_read(
-  dev_t dev,
+  const rtems_disk_device *dd,
   rtems_blkdev_bnum block,
   rtems_status_code expected_sc
 )
@@ -147,7 +148,7 @@ static void check_read(
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_bdbuf_buffer *bd = NULL;
 
-  sc = rtems_bdbuf_read(dev, block, &bd);
+  sc = rtems_bdbuf_read(dd, block, &bd);
   assert(sc == expected_sc);
 
   if (sc == RTEMS_SUCCESSFUL) {
@@ -161,6 +162,7 @@ static rtems_task Init(rtems_task_argument argument)
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_bdbuf_buffer *bd = NULL;
   dev_t dev = 0;
+  rtems_disk_device *dd = NULL;
 
   printk("\n\n*** TEST BLOCK 9 ***\n");
 
@@ -170,14 +172,17 @@ static rtems_task Init(rtems_task_argument argument)
   sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
   ASSERT_SC(sc);
 
-  check_read(dev, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
-  check_read(dev, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
-  check_read(dev, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
-  check_read(dev, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);
+  dd = rtems_disk_obtain(dev);
+  assert(dd != NULL);
+
+  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
+  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
+  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
+  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);
 
   /* Check write IO error */
 
-  sc = rtems_bdbuf_read(dev, BLOCK_WRITE_IO_ERROR, &bd);
+  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
   ASSERT_SC(sc);
 
   bd->buffer [0] = 1;
@@ -185,7 +190,7 @@ static rtems_task Init(rtems_task_argument argument)
   sc = rtems_bdbuf_sync(bd);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_read(dev, BLOCK_WRITE_IO_ERROR, &bd);
+  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
   ASSERT_SC(sc);
 
   assert(bd->buffer [0] == 0);
@@ -195,7 +200,7 @@ static rtems_task Init(rtems_task_argument argument)
 
   /* Check write to deleted disk */
 
-  sc = rtems_bdbuf_read(dev, BLOCK_READ_SUCCESSFUL, &bd);
+  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
   ASSERT_SC(sc);
 
   sc = rtems_disk_delete(dev);
@@ -204,6 +209,9 @@ static rtems_task Init(rtems_task_argument argument)
   sc = rtems_bdbuf_sync(bd);
   ASSERT_SC(sc);
 
+  sc = rtems_disk_release(dd);
+  ASSERT_SC(sc);
+
   printk("*** END OF TEST BLOCK 9 ***\n");
 
   exit(0);
diff --git a/testsuites/libtests/block10/init.c b/testsuites/libtests/block10/init.c
index 18af160..80ca98e 100644
--- a/testsuites/libtests/block10/init.c
+++ b/testsuites/libtests/block10/init.c
@@ -52,7 +52,7 @@ typedef rtems_bdbuf_buffer *(*access_func)(char task);
 
 typedef void (*release_func)(char task, rtems_bdbuf_buffer *bd);
 
-static dev_t dev;
+static const rtems_disk_device *dd;
 
 static rtems_id task_id_init;
 
@@ -110,7 +110,7 @@ static int disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
   }
 }
 
-rtems_status_code disk_register(
+static rtems_status_code disk_register(
   uint32_t block_size,
   rtems_blkdev_bnum block_count,
   dev_t *dev_ptr
@@ -147,7 +147,7 @@ static rtems_bdbuf_buffer *do_get(char task)
 
   printk("%c: try get\n", task);
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("%c: get\n", task);
@@ -162,13 +162,13 @@ static rtems_bdbuf_buffer *do_get_mod(char task)
 
   printk("%c: try get modified\n", task);
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   sc = rtems_bdbuf_release_modified(bd);
   ASSERT_SC(sc);
 
-  sc = rtems_bdbuf_get(dev, 0, &bd);
+  sc = rtems_bdbuf_get(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("%c: get modified\n", task);
@@ -183,7 +183,7 @@ static rtems_bdbuf_buffer *do_read(char task)
 
   printk("%c: try read\n", task);
 
-  sc = rtems_bdbuf_read(dev, 0, &bd);
+  sc = rtems_bdbuf_read(dd, 0, &bd);
   ASSERT_SC(sc);
 
   printk("%c: read\n", task);
@@ -203,7 +203,7 @@ static void do_rel(char task, rtems_bdbuf_buffer *bd)
   printk("%c: release done\n", task);
 }
 
-void do_rel_mod(char task, rtems_bdbuf_buffer *bd)
+static void do_rel_mod(char task, rtems_bdbuf_buffer *bd)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
 
@@ -231,7 +231,7 @@ static void purge(char task)
 {
   printk("%c: purge\n", task);
 
-  rtems_bdbuf_purge_dev(dev);
+  rtems_bdbuf_purge_dev(dd);
 }
 
 static void task_purger(rtems_task_argument arg)
@@ -387,6 +387,7 @@ static const char *purger_assoc_table [PURGER_COUNT] = {
 static rtems_task Init(rtems_task_argument argument)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
+  dev_t dev = 0;
   size_t i_w = 0;
   size_t i_ac = 0;
   size_t i_rel = 0;
@@ -402,6 +403,9 @@ static rtems_task Init(rtems_task_argument argument)
   sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
   ASSERT_SC(sc);
 
+  dd = rtems_disk_obtain(dev);
+  assert(dd != NULL);
+
   sc = rtems_task_create(
     rtems_build_name('P', 'U', 'R', 'G'),
     PRIORITY_HIGH,
diff --git a/testsuites/samples/fileio/init.c b/testsuites/samples/fileio/init.c
index f8c33fc..5c63744 100644
--- a/testsuites/samples/fileio/init.c
+++ b/testsuites/samples/fileio/init.c
@@ -325,23 +325,9 @@ shell_bdbuf_trace (int argc, char* argv[])
 }
 
 static int
-disk_test_set_block_size (dev_t dev, size_t size)
+disk_test_set_block_size (rtems_disk_device *dd, size_t size)
 {
-  rtems_disk_device* dd;
-  int                rc;
-  
-  dd = rtems_disk_obtain (dev);
-  if (!dd)
-  {
-    printf ("error: cannot obtain disk\n");
-    return 1;
-  }
-  
-  rc = dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
-
-  rtems_disk_release (dd);
-
-  return rc;
+  return dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
 }
 
 static int
@@ -353,37 +339,50 @@ disk_test_write_blocks (dev_t dev, int start, int count, size_t size)
   int                 i;
   rtems_bdbuf_buffer* bd;
   rtems_status_code   sc;
+  int                 rv = 0;
+  rtems_disk_device* dd;
+  
+  dd = rtems_disk_obtain (dev);
+  if (!dd)
+  {
+    printf ("error: cannot obtain disk\n");
+    rv = 1;
+  }
   
-  if (disk_test_set_block_size (dev, size) < 0)
+  if (rv == 0 && disk_test_set_block_size (dd, size) < 0)
   {
     printf ("error: set block size failed: %s\n", strerror (errno));
-    return 1;
+    rv = 1;
   }
 
-  for (block = start; block < (start + count); block++)
+  for (block = start; rv == 0 && block < (start + count); block++)
   {
-    sc = rtems_bdbuf_read (dev, block, &bd);
-    if (sc != RTEMS_SUCCESSFUL)
+    sc = rtems_bdbuf_read (dd, block, &bd);
+    if (sc == RTEMS_SUCCESSFUL)
     {
-      printf ("error: get block %d bd failed: %s\n",
-              block, rtems_status_text (sc));
-      return 1;
-    }
+      ip = (uint32_t*) bd->buffer;
+      for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
+        *ip = (size << 16) | value;
 
-    ip = (uint32_t*) bd->buffer;
-    for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
-      *ip = (size << 16) | value;
-
-    sc = rtems_bdbuf_release_modified (bd);
-    if (sc != RTEMS_SUCCESSFUL)
+      sc = rtems_bdbuf_release_modified (bd);
+      if (sc != RTEMS_SUCCESSFUL)
+      {
+        printf ("error: release block %d bd failed: %s\n",
+                block, rtems_status_text (sc));
+        rv = 1;
+      }
+    }
+    else
     {
-      printf ("error: release block %d bd failed: %s\n",
+      printf ("error: get block %d bd failed: %s\n",
               block, rtems_status_text (sc));
-      return 1;
+      rv = 1;
     }
   }
 
-  return 0;
+  rtems_disk_release (dd);
+
+  return rv;
 }
 
 static int




More information about the vc mailing list