Add Block-to-character device driver

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1237 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-11-15 00:18:23 +00:00
parent f47adddbb2
commit 6aeb99bc51
5 changed files with 58 additions and 9 deletions

View File

@ -550,4 +550,6 @@
* Each NSH command can not be disabled through a configuration setting. All of these * 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 settings make the configuration of NSH potentially complex but also allow it to squeeze
into very small memory footprints. 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.

View File

@ -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 * 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 settings make the configuration of NSH potentially complex but also allow it to squeeze
into very small memory footprints. 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> pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>

View File

@ -53,7 +53,16 @@ ROOTDEPPATH = --dep-path .
MMCSDDEPPATH = --dep-path mmcsd MMCSDDEPPATH = --dep-path mmcsd
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh "$(CC)" $(TOPDIR)/drivers/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)) AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = CSRCS =
@ -64,7 +73,7 @@ ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
CSRCS += ramdisk.c CSRCS += ramdisk.c
endif endif
endif endif
CSRCS += $(NET_CSRCS) $(USBDEV_CSRCS) $(MMCSD_CSRCS) CSRCS += $(NET_CSRCS) $(USBDEV_CSRCS) $(MMCSD_CSRCS) $(BCH_CSRCS)
COBJS = $(CSRCS:.c=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
@ -72,7 +81,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libdrivers$(LIBEXT) BIN = libdrivers$(LIBEXT)
VPATH = net:usbdev:mmcsd VPATH = net:usbdev:mmcsd:bch
all: $(BIN) all: $(BIN)
@ -88,7 +97,7 @@ $(BIN): $(OBJS)
done ; ) done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(NETDEPPATH) $(USBDEVDEPPATH) $(MMCSDDEPPATH) \ @$(MKDEP) $(ROOTDEPPATH) $(NETDEPPATH) $(USBDEVDEPPATH) $(MMCSDDEPPATH) $(BCHDEPPATH) \
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@ @touch $@

View File

@ -370,8 +370,28 @@ EXTERN int lib_flushall(FAR struct streamlist *list);
* subdirectory * subdirectory
*/ */
/* Register /dev/null */
EXTERN void devnull_register(void); 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 #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)

View File

@ -53,8 +53,9 @@
*/ */
#define _FIOCBASE (0x8700) /* File system ioctl commands */ #define _FIOCBASE (0x8700) /* File system ioctl commands */
#define _BIOCBASE (0x8800) /* Block driver ioctl commands */ #define _DIOCBASE (0x8800) /* Character driver ioctl commands */
#define _SIOCBASE (0x8900) /* Socket ioctl commandss */ #define _BIOCBASE (0x8900) /* Block driver ioctl commands */
#define _SIOCBASE (0x8a00) /* Socket ioctl commandss */
/* Macros used to manage ioctl commands */ /* Macros used to manage ioctl commands */
@ -69,10 +70,25 @@
#define _FIOCVALID(c) (_IOC_TYPE(c)==_FIOCBASE) #define _FIOCVALID(c) (_IOC_TYPE(c)==_FIOCBASE)
#define _FIOC(nr) _IOC(_FIOCBASE,nr) #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, * OUT: If media is directly acccesible,
* return (void*) base address * 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 */ /* NuttX block driver ioctl definitions */