diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-11-15 16:36:32 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-11-15 16:36:32 +0000 |
commit | 9334df87efdf6925fc6289cdca69e3e5ec81f118 (patch) | |
tree | 5a154cfc0654f7bf377686a56406ef1901e91e2b /nuttx/drivers/bch/bchlib_read.c | |
parent | a53de1f10c52bc787111ef7091f909f9ccdd53ac (diff) | |
download | px4-nuttx-9334df87efdf6925fc6289cdca69e3e5ec81f118.tar.gz px4-nuttx-9334df87efdf6925fc6289cdca69e3e5ec81f118.tar.bz2 px4-nuttx-9334df87efdf6925fc6289cdca69e3e5ec81f118.zip |
NSH dd command test with block devices
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1242 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/bch/bchlib_read.c')
-rw-r--r-- | nuttx/drivers/bch/bchlib_read.c | 134 |
1 files changed, 1 insertions, 133 deletions
diff --git a/nuttx/drivers/bch/bchlib_read.c b/nuttx/drivers/bch/bchlib_read.c index 7af72ce8a..d2301d439 100644 --- a/nuttx/drivers/bch/bchlib_read.c +++ b/nuttx/drivers/bch/bchlib_read.c @@ -85,7 +85,7 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t len) { - FAR struct bchlib_s *bch; + FAR struct bchlib_s *bch = (FAR struct bchlib_s *)handle; size_t nsectors; size_t sector; uint16 sectoffset; @@ -202,135 +202,3 @@ ssize_t bchlib_read(FAR void *handle, FAR char *buffer, size_t offset, size_t le return bytesread; } - -/**************************************************************************** - * Name: bchlib_write - * - * Description: - * Write to the block device set-up by bchlib_setup as if it were a character - * device. - * - ****************************************************************************/ - -ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, size_t len) -{ - FAR struct bchlib_s *bch; - size_t nsectors; - size_t sector; - uint16 sectoffset; - size_t nbytes; - size_t byteswritten; - int ret; - - /* Get rid of this special case right away */ - - if (len < 1) - { - return 0; - } - - /* Convert the file position into a sector number an offset. */ - - sector = offset / bch->sectsize; - sectoffset = offset - sector * bch->sectsize; - - if (sector >= bch->nsectors) - { - return -EFBIG; - } - - /* Write the initial partial sector */ - - byteswritten = 0; - if (sectoffset > 0) - { - /* Read the full sector into the sector buffer */ - - bchlib_readsector(bch, sector); - - /* Copy the tail end of the sector from the user buffer */ - - if (sectoffset + len > bch->sectsize) - { - nbytes = bch->sectsize - sectoffset; - } - else - { - nbytes = len; - } - - memcpy(&bch->buffer[sectoffset], buffer, nbytes); - bch->dirty = TRUE; - - /* Adjust pointers and counts */ - - sectoffset = 0; - sector++; - - if (sector >= bch->nsectors) - { - return nbytes; - } - - byteswritten = nbytes; - buffer += nbytes; - len -= nbytes; - } - - /* Then write all of the full sectors following the partial sector */ - - if (len >= bch->sectsize ) - { - nsectors = len / bch->sectsize; - if (sector + nsectors > bch->nsectors) - { - nsectors = bch->nsectors - sector; - } - - /* Write the contiguous sectors */ - - ret = bch->inode->u.i_bops->write(bch->inode, bch->buffer, sector, nsectors); - if (ret < 0) - { - fdbg("Write failed: %d\n"); - return ret; - } - - /* Adjust pointers and counts */ - - sectoffset = 0; - sector += nsectors; - - nbytes = nsectors * bch->sectsize; - byteswritten += nbytes; - - if (sector >= bch->nsectors) - { - return byteswritten; - } - - buffer += nbytes; - len -= nbytes; - } - - /* Then write any partial final sector */ - - if (len > 0) - { - /* Read the sector into the sector buffer */ - - bchlib_readsector(bch, sector); - - /* Copy the head end of the sector from the user buffer */ - - memcpy(bch->buffer, buffer, len); - bch->dirty = TRUE; - - /* Adjust counts */ - - byteswritten += len; - } - - return byteswritten; -} - |