int nandmtd_WriteChunkToNAND(struct yaffs_dev *dev, int chunkInNAND, const u8 *data, const struct yaffs_spare *spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->driver_context); struct mtd_oob_ops ops; size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->data_bytes_per_chunk; u8 spareAsBytes[8]; /* OOB */ if (data && !spare) retval = mtd->write(mtd, addr, dev->data_bytes_per_chunk, &dummy, data); else if (spare) { if (dev->param.use_nand_ecc) { translate_spare2oob(spare, spareAsBytes); ops.mode = MTD_OOB_AUTO; ops.ooblen = 8; /* temp hack */ } else { ops.mode = MTD_OOB_RAW; ops.ooblen = YAFFS_BYTES_PER_SPARE; } ops.len = data ? dev->data_bytes_per_chunk : ops.ooblen; ops.datbuf = (u8 *)data; ops.ooboffs = 0; ops.oobbuf = spareAsBytes; retval = mtd->write_oob(mtd, addr, &ops); } if (retval == 0) return YAFFS_OK; else return YAFFS_FAIL; }
int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) retval = mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy, data); else if (spare) { if (dev->useNANDECC) { translate_spare2oob(spare, spareAsBytes); ops.mode = MTD_OOB_AUTO; ops.ooblen = 8; /* temp hack */ } else { ops.mode = MTD_OOB_RAW; ops.ooblen = YAFFS_BYTES_PER_SPARE; } ops.len = data ? dev->nDataBytesPerChunk : ops.ooblen; ops.datbuf = (u8 *)data; ops.ooboffs = 0; ops.oobbuf = spareAsBytes; retval = mtd->write_oob(mtd, addr, &ops); } #else __u8 *spareAsBytes = (__u8 *) spare; if (data && spare) { if (dev->useNANDECC) retval = mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, &dummy, data, spareAsBytes, &yaffs_oobinfo); else retval = mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, &dummy, data, spareAsBytes, &yaffs_noeccinfo); } else { if (data) retval = mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy, data); if (spare) retval = mtd->write_oob(mtd, addr, YAFFS_BYTES_PER_SPARE, &dummy, spareAsBytes); } #endif if (retval == 0) return YAFFS_OK; else return YAFFS_FAIL; }