static int yaffs_ucore_device_wrapper_rd_chunk( struct yaffs_dev *dev, unsigned pageId, unsigned char *data, unsigned dataLength, unsigned char *spare, unsigned spareLength, int *eccStatus) { assert(dataLength <= DATA_SIZE); assert(spareLength <= SPARE_SIZE); *eccStatus = 0; int block_id = pageId / PAGES_PER_BLOCK; int page_in_block = pageId % PAGES_PER_BLOCK; int data_block_offset = block_id * DEVICE_BLOCK_PER_FLASH_BLOCK * DEVICE_BLOCK_SIZE + page_in_block / 2 * DEVICE_BLOCK_SIZE; int data_in_block_offset = page_in_block % 2 == 0 ? 0 : 2048; int spare_block_offset = block_id * DEVICE_BLOCK_PER_FLASH_BLOCK * DEVICE_BLOCK_SIZE + (DEVICE_BLOCK_PER_FLASH_BLOCK - 1) * DEVICE_BLOCK_SIZE; int spare_in_block_offset = page_in_block * SPARE_SIZE; char* disk_buffer = kmalloc(DEVICE_BLOCK_SIZE, 0); struct device *ucore_dev = (struct device*)dev->os_context; struct iobuf iob; if(dataLength > 0) { iobuf_init(&iob, disk_buffer, DEVICE_BLOCK_SIZE, data_block_offset); dop_io(ucore_dev, &iob, 0); memcpy(data, disk_buffer + data_in_block_offset, dataLength); } if(spareLength > 0) { iobuf_init(&iob, disk_buffer, DEVICE_BLOCK_SIZE, spare_block_offset); dop_io(ucore_dev, &iob, 0); memcpy(spare, disk_buffer + spare_in_block_offset, spareLength); } kfree(disk_buffer); return YAFFS_OK; }
static int yaffs_ucore_device_wrapper_erase(struct yaffs_dev *dev, unsigned blockId) { //if(blockId < 63) panic("No need to erase %d\n", blockId); struct device *ucore_dev = (struct device*)dev->os_context; char* disk_buffer = kmalloc(DEVICE_BLOCK_SIZE, 0); memset(disk_buffer, 0xFF, DEVICE_BLOCK_SIZE); for(int i = blockId * DEVICE_BLOCK_PER_FLASH_BLOCK; i < (blockId + 1) * DEVICE_BLOCK_PER_FLASH_BLOCK; i++) { struct iobuf iob; iob.io_base = disk_buffer; iob.io_offset = i * DEVICE_BLOCK_SIZE; iob.io_len = DEVICE_BLOCK_SIZE; iob.io_resid = DEVICE_BLOCK_SIZE; dop_io(ucore_dev, &iob, 1); } kfree(disk_buffer); return 1; }
static int sfs_init_read(struct device *dev, uint32_t blkno, void *blk_buffer) { struct iobuf __iob, *iob = iobuf_init(&__iob, blk_buffer, SFS_BLKSIZE, blkno * SFS_BLKSIZE); return dop_io(dev, iob, 0); }
/* * Called for write. Hand off to dop_io. */ static int dev_write(struct inode *node, struct iobuf *iob) { struct device *dev = vop_info(node, device); return dop_io(dev, iob, 1); }