summaryrefslogtreecommitdiff
path: root/nuttx/arch/sim/src/up_blockdevice.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/arch/sim/src/up_blockdevice.c')
-rw-r--r--nuttx/arch/sim/src/up_blockdevice.c128
1 files changed, 7 insertions, 121 deletions
diff --git a/nuttx/arch/sim/src/up_blockdevice.c b/nuttx/arch/sim/src/up_blockdevice.c
index 60dbcd021..243d8215f 100644
--- a/nuttx/arch/sim/src/up_blockdevice.c
+++ b/nuttx/arch/sim/src/up_blockdevice.c
@@ -1,7 +1,7 @@
/****************************************************************************
* up_blockdevice.c
*
- * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -38,11 +38,13 @@
****************************************************************************/
#include <nuttx/config.h>
+
#include <sys/types.h>
#include <string.h>
-#include <nuttx/fs.h>
#include <errno.h>
+#include <nuttx/ramdisk.h>
+
#include "up_internal.h"
/****************************************************************************
@@ -60,142 +62,26 @@
* Private Function Prototypes
****************************************************************************/
-static int up_open(FAR struct inode *inode);
-static int up_close(FAR struct inode *inode);
-static ssize_t up_read(FAR struct inode *inode, unsigned char *buffer,
- size_t start_sector, unsigned int nsectors);
-static ssize_t up_write(FAR struct inode *inode, const unsigned char *buffer,
- size_t start_sector, unsigned int nsectors);
-static int up_geometry(FAR struct inode *inode, struct geometry *geometry);
-
/****************************************************************************
* Private Data
****************************************************************************/
-static const struct block_operations g_bops =
-{
- .open = up_open,
- .close = up_close,
- .read = up_read,
- .write = up_write,
- .geometry = up_geometry,
-};
-
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
- * Name: up_open
- *
- * Description: Open the block device
- *
- ****************************************************************************/
-
-static int up_open(FAR struct inode *inode)
-{
- return OK;
-}
-
-/****************************************************************************
- * Name: up_closel
- *
- * Description: close the block device
- *
- ****************************************************************************/
-
-static int up_close(FAR struct inode *inode)
-{
- return OK;
-}
-
-/****************************************************************************
- * Name: up_read
- *
- * Description: Read the specified numer of sectors
- *
- ****************************************************************************/
-
-static ssize_t up_read(FAR struct inode *inode, unsigned char *buffer,
- size_t start_sector, unsigned int nsectors)
-{
- if (inode)
- {
- char *src = inode->i_private;
- if (src &&
- start_sector < NSECTORS &&
- start_sector + nsectors < NSECTORS)
- {
- memcpy(buffer,
- &src[start_sector*LOGICAL_SECTOR_SIZE],
- nsectors*LOGICAL_SECTOR_SIZE);
- return nsectors;
- }
- }
- return -EINVAL;
-}
-
-/****************************************************************************
- * Name: up_write
- *
- * Description: Write the specified number of sectors
- *
- ****************************************************************************/
-
-static ssize_t up_write(FAR struct inode *inode, const unsigned char *buffer,
- size_t start_sector, unsigned int nsectors)
-{
- if (inode)
- {
- char *dest = inode->i_private;
- if (dest &&
- start_sector < NSECTORS &&
- start_sector + nsectors < NSECTORS)
- {
- memcpy(&dest[start_sector*LOGICAL_SECTOR_SIZE],
- buffer,
- nsectors*LOGICAL_SECTOR_SIZE);
- return nsectors;
- }
- }
- return -EINVAL;
-}
-
-/****************************************************************************
- * Name: up_geometry
- *
- * Description: Return device geometry
- *
- ****************************************************************************/
-
-static int up_geometry(FAR struct inode *inode, struct geometry *geometry)
- {
- if (geometry)
- {
- geometry->geo_available = (inode->i_private != NULL);
- geometry->geo_mediachanged = FALSE;
- geometry->geo_writeenabled = TRUE;
- geometry->geo_nsectors = NSECTORS;
- geometry->geo_sectorsize = LOGICAL_SECTOR_SIZE;
- return OK;
- }
- return -EINVAL;
- }
-
-/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_registerblockdevice
*
- * Description: Register the simulated block device
-
+ * Description: Register the FAT ramdisk
+ *
****************************************************************************/
void up_registerblockdevice(void)
{
- /* Inode private data is a filesystem image */
- void *priv = (void*)up_deviceimage();
- (void)register_blockdriver("/dev/blkdev", &g_bops, 0, priv);
+ rd_register(0, up_deviceimage(), NSECTORS, LOGICAL_SECTOR_SIZE, TRUE);
}