From 896834002a51a38c579232da39a5d84545658d29 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 9 Nov 2015 11:47:25 -0600 Subject: [PATCH] BCH driver should forward ioctl commands to the contained block driver --- ChangeLog | 3 +++ drivers/bch/bch_internal.h | 20 ++++++++++---------- drivers/bch/bchdev_driver.c | 21 ++++++++++++++++++++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8dd774237..2ac723d871 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11074,3 +11074,6 @@ * arch/arm/src/samv7: The QSPI FLASH driver is now functional. This driver operates in the memory-mapped, Serial Memory Mode (SMM) (2015-11-07). + * drivers/bch: Block-to-character (BCH) driver should forward ioctl() + calls to the contained block driver (2015-11-09). + diff --git a/drivers/bch/bch_internal.h b/drivers/bch/bch_internal.h index 3a12c50c9b..653a2767b0 100644 --- a/drivers/bch/bch_internal.h +++ b/drivers/bch/bch_internal.h @@ -61,18 +61,18 @@ struct bchlib_s { - struct inode *inode; /* I-node of the block driver */ - sem_t sem; /* For atomic accesses to this structure */ - size_t nsectors; /* Number of sectors supported by the device */ - size_t sector; /* The current sector in the buffer */ - uint16_t sectsize; /* The size of one sector on the device */ - uint8_t refs; /* Number of references */ - bool dirty; /* Data has been written to the buffer */ - bool readonly; /* true: Only read operations are supported */ - FAR uint8_t *buffer; /* One sector buffer */ + FAR struct inode *inode; /* I-node of the block driver */ + sem_t sem; /* For atomic accesses to this structure */ + size_t nsectors; /* Number of sectors supported by the device */ + size_t sector; /* The current sector in the buffer */ + uint16_t sectsize; /* The size of one sector on the device */ + uint8_t refs; /* Number of references */ + bool dirty; /* Data has been written to the buffer */ + bool readonly; /* true: Only read operations are supported */ + FAR uint8_t *buffer; /* One sector buffer */ #if defined(CONFIG_BCH_ENCRYPTION) - uint8_t key[CONFIG_BCH_ENCRYPTION_KEY_SIZE]; /* Encryption key */ + uint8_t key[CONFIG_BCH_ENCRYPTION_KEY_SIZE]; /* Encryption key */ #endif }; diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c index 7bf5f54ed9..14ee267d99 100644 --- a/drivers/bch/bchdev_driver.c +++ b/drivers/bch/bchdev_driver.c @@ -302,6 +302,8 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(inode && inode->i_private); bch = (FAR struct bchlib_s *)inode->i_private; + /* Is this a request to get the private data structure */ + if (cmd == DIOC_GETPRIV) { FAR struct bchlib_s **bchr = (FAR struct bchlib_s **)((uintptr_t)arg); @@ -319,7 +321,10 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) bchlib_semgive(bch); } -#if defined(CONFIG_BCH_ENCRYPTION) + +#ifdef CONFIG_BCH_ENCRYPTION + /* Is this a request to set the encryption key? */ + else if (cmd == DIOC_SETKEY) { memcpy(bch->key, (FAR void *)arg, CONFIG_BCH_ENCRYPTION_KEY_SIZE); @@ -327,6 +332,20 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } #endif + /* Otherwise, pass the IOCTL command on to the contained block driver */ + + else + { + FAR struct inode *bchinode = bch->inode; + + /* Does the block driver support the ioctl method? */ + + if (bchinode->u.i_bops->ioctl != NULL) + { + ret = bchinode->u.i_bops->ioctl(bchinode, cmd, arg); + } + } + return ret; }