static int blk_read(void *buf, int len, const char *path, int offset) { void *handle; int ret; ret = bchlib_setup(path, true, &handle); if (ret) { return ret; } ret = bchlib_read(handle, buf, offset, len); bchlib_teardown(handle); return ret; }
static ssize_t bch_read(FAR struct file *filep, FAR char *buffer, size_t len) { FAR struct inode *inode = filep->f_inode; FAR struct bchlib_s *bch; int ret; DEBUGASSERT(inode && inode->i_private); bch = (FAR struct bchlib_s *)inode->i_private; bchlib_semtake(bch); ret = bchlib_read(bch, buffer, filep->f_pos, len); if (ret > 0) { filep->f_pos += len; } bchlib_semgive(bch); return ret; }
static int dd_readblk(struct dd_s *dd) { ssize_t nbytes; off_t offset = dd->sector * dd->sectsize; nbytes = bchlib_read(DD_INHANDLE, (char*)dd->buffer, offset, dd->sectsize); if (nbytes < 0) { FAR struct nsh_vtbl_s *vtbl = dd->vtbl; nsh_output(vtbl, g_fmtcmdfailed, g_dd, "bshlib_read", NSH_ERRNO_OF(-nbytes)); return ERROR; } /* bchlib_read return 0 on attempts to write past the end of the device. */ dd->nbytes = nbytes; dd->eof = (nbytes == 0); return OK; }