From 796967c3df40a51a9028bc83d1a4b6dbeae07c3f Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 28 Feb 2012 17:19:49 +0100 Subject: 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/libfs/src/rfs/rtems-rfs-buffer.c | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'cpukit/libfs/src/rfs/rtems-rfs-buffer.c') diff --git a/cpukit/libfs/src/rfs/rtems-rfs-buffer.c b/cpukit/libfs/src/rfs/rtems-rfs-buffer.c index ea5cbb3fb3..60f9deae32 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 #include #include +#include #include #include @@ -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; } -- cgit v1.2.3