From 1c77cd0c64678a09a68218fb3bf012ed6cf57ef1 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 15 Nov 2008 00:18:23 +0000 Subject: [PATCH] Add Block-to-character device driver git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1237 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/ChangeLog | 2 ++ nuttx/Documentation/NuttX.html | 2 ++ nuttx/drivers/Makefile | 17 +++++++++++++---- nuttx/include/nuttx/fs.h | 22 +++++++++++++++++++++- nuttx/include/nuttx/ioctl.h | 24 ++++++++++++++++++++---- 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 56647921f..29405d9f6 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -550,4 +550,6 @@ * Each NSH command can not be disabled through a configuration setting. All of these settings make the configuration of NSH potentially complex but also allow it to squeeze into very small memory footprints. + * Added a block to character (BCH) driver. This is kind of the reverse of the loop + device; it allows you access a block device like a character device. diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index b32889824..9204f3454 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -1193,6 +1193,8 @@ nuttx-0.3.18 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Each NSH command can not be disabled through a configuration setting. All of these settings make the configuration of NSH potentially complex but also allow it to squeeze into very small memory footprints. + * Added a block to character (BCH) driver. This is kind of the reverse of the loop + device; it allows you access a block device like a character device. pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/drivers/Makefile b/nuttx/drivers/Makefile index 8d03a1918..dc6e43fcc 100644 --- a/nuttx/drivers/Makefile +++ b/nuttx/drivers/Makefile @@ -53,7 +53,16 @@ ROOTDEPPATH = --dep-path . MMCSDDEPPATH = --dep-path mmcsd CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/drivers/mmcsd} -ASRCS = $(NET_ASRCS) $(USBDEV_ASRCS) $(MMCSD_ASRCS) +ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) +ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) +include bch/Make.defs +ROOTDEPPATH = --dep-path . +BCHDEPPATH = --dep-path bch +CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/drivers/bch} +endif +endif + +ASRCS = $(NET_ASRCS) $(USBDEV_ASRCS) $(MMCSD_ASRCS) $(BCH_ASRCS) AOBJS = $(ASRCS:.S=$(OBJEXT)) CSRCS = @@ -64,7 +73,7 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) CSRCS += ramdisk.c endif endif -CSRCS += $(NET_CSRCS) $(USBDEV_CSRCS) $(MMCSD_CSRCS) +CSRCS += $(NET_CSRCS) $(USBDEV_CSRCS) $(MMCSD_CSRCS) $(BCH_CSRCS) COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) @@ -72,7 +81,7 @@ OBJS = $(AOBJS) $(COBJS) BIN = libdrivers$(LIBEXT) -VPATH = net:usbdev:mmcsd +VPATH = net:usbdev:mmcsd:bch all: $(BIN) @@ -88,7 +97,7 @@ $(BIN): $(OBJS) done ; ) .depend: Makefile $(SRCS) - @$(MKDEP) $(ROOTDEPPATH) $(NETDEPPATH) $(USBDEVDEPPATH) $(MMCSDDEPPATH) \ + @$(MKDEP) $(ROOTDEPPATH) $(NETDEPPATH) $(USBDEVDEPPATH) $(MMCSDDEPPATH) $(BCHDEPPATH) \ $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep @touch $@ diff --git a/nuttx/include/nuttx/fs.h b/nuttx/include/nuttx/fs.h index 6d5dd7861..8a174b011 100644 --- a/nuttx/include/nuttx/fs.h +++ b/nuttx/include/nuttx/fs.h @@ -370,8 +370,28 @@ EXTERN int lib_flushall(FAR struct streamlist *list); * subdirectory */ +/* Register /dev/null */ + EXTERN void devnull_register(void); -EXTERN int losetup(const char *name, int minor, uint16 sectsize); + +/* Setup the loop device so that it exports the file referenced by 'filename' + * as a block device. + */ + +EXTERN int losetup(const char *devname, const char *filename, uint16 sectsize, + off_t offset, boolean readonly); +EXTERN int loteardown(const char *devname); + +/* Setup so that the block driver referenced by 'blkdev' can be accessed + * similar to a character device. + */ + +EXTERN int bchdev_register(const char *blkdev, const char *chardev, boolean readonly); +EXTERN int bchdev_unregister(const char *chardev); +EXTERN int bchlib_setup(const char *blkdev, boolean readonly, FAR void **handle); +EXTERN int bchlib_teardown(FAR void *handle); +EXTERN ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t len); +EXTERN ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, size_t len); #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/include/nuttx/ioctl.h b/nuttx/include/nuttx/ioctl.h index 6ebfce997..49d9ca48e 100644 --- a/nuttx/include/nuttx/ioctl.h +++ b/nuttx/include/nuttx/ioctl.h @@ -53,8 +53,9 @@ */ #define _FIOCBASE (0x8700) /* File system ioctl commands */ -#define _BIOCBASE (0x8800) /* Block driver ioctl commands */ -#define _SIOCBASE (0x8900) /* Socket ioctl commandss */ +#define _DIOCBASE (0x8800) /* Character driver ioctl commands */ +#define _BIOCBASE (0x8900) /* Block driver ioctl commands */ +#define _SIOCBASE (0x8a00) /* Socket ioctl commandss */ /* Macros used to manage ioctl commands */ @@ -69,10 +70,25 @@ #define _FIOCVALID(c) (_IOC_TYPE(c)==_FIOCBASE) #define _FIOC(nr) _IOC(_FIOCBASE,nr) -#define FIOC_MMAP _FIOC(0x0001) /* IN: None +#define FIOC_MMAP _FIOC(0x0001) /* IN: Location to return address (void **) * OUT: If media is directly acccesible, * return (void*) base address - * of file */ + * of file + */ +/* NuttX file system ioctl definitions */ + +#define _DIOCVALID(c) (_IOC_TYPE(c)==_DIOCBASE) +#define _DIOC(nr) _IOC(_DIOCBASE,nr) + +#define DIOC_GETPRIV _DIOC(0x0001) /* IN: Location to return handle (void **) + * OUT: Reference to internal data + * structure. May have a reference + * incremented. + */ +#define DIOC_RELPRIV _DIOC(0x0003) /* IN: None + * OUT: None, reference obtained by + * FIOC_GETPRIV released. + */ /* NuttX block driver ioctl definitions */