summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-02-28 17:19:49 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-03-13 12:24:18 +0100
commit796967c3df40a51a9028bc83d1a4b6dbeae07c3f (patch)
treeedd7251883f74506a69f76e6e9fbf173de195f50 /cpukit/libfs
parentlibblock: Documentation (diff)
downloadrtems-796967c3df40a51a9028bc83d1a4b6dbeae07c3f.tar.bz2
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.
Diffstat (limited to 'cpukit/libfs')
-rw-r--r--cpukit/libfs/src/dosfs/fat.c76
-rw-r--r--cpukit/libfs/src/dosfs/fat.h2
-rw-r--r--cpukit/libfs/src/dosfs/fat_file.c2
-rw-r--r--cpukit/libfs/src/dosfs/msdos_dir.c2
-rw-r--r--cpukit/libfs/src/dosfs/msdos_file.c2
-rw-r--r--cpukit/libfs/src/dosfs/msdos_format.c32
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-buffer.c35
-rw-r--r--cpukit/libfs/src/rfs/rtems-rfs-file-system.h12
8 files changed, 86 insertions, 77 deletions
diff --git a/cpukit/libfs/src/dosfs/fat.c b/cpukit/libfs/src/dosfs/fat.c
index ba9ae23e86..39a7bacb24 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 8d62662c10..204095cae2 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 5375e90336..01dabc8f80 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 725fd254d0..67a0bdaaa9 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 b2f98b890d..7cd55b0494 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 1394f811c4..2a9d09048f 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 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 <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 0ceade228e..96fdf6c9ab 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