Lines Matching defs:nftl
16 #include <linux/mtd/nftl.h>
23 * is used for management of Erase Unit in other routines in nftl.c and nftlmount.c
25 static int find_boot_record(struct NFTLrecord *nftl)
31 struct NFTLMediaHeader *mh = &nftl->MediaHdr;
32 struct mtd_info *mtd = nftl->mbd.mtd;
40 nftl->EraseSize if there were any point in doing so. */
41 nftl->EraseSize = nftl->mbd.mtd->erasesize;
42 nftl->nb_blocks = (u32)nftl->mbd.mtd->size / nftl->EraseSize;
44 nftl->MediaUnit = BLOCK_NIL;
45 nftl->SpareMediaUnit = BLOCK_NIL;
48 for (block = 0; block < nftl->nb_blocks; block++) {
53 ret = mtd_read(mtd, block * nftl->EraseSize, SECTORSIZE,
62 block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
73 block * nftl->EraseSize, nftl->mbd.mtd->index);
79 ret = nftl_read_oob(mtd, block * nftl->EraseSize +
84 block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
94 block * nftl->EraseSize, nftl->mbd.mtd->index,
100 ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE,
104 block * nftl->EraseSize, nftl->mbd.mtd->index, ret);
111 block * nftl->EraseSize, nftl->mbd.mtd->index);
123 nftl->MediaUnit * nftl->EraseSize, block * nftl->EraseSize);
132 nftl->SpareMediaUnit = block;
135 nftl->ReplUnitTable[block] = BLOCK_RESERVED;
159 nftl->EraseSize = nftl->mbd.mtd->erasesize << (0xff - mh->UnitSizeFactor);
160 nftl->nb_blocks = (u32)nftl->mbd.mtd->size / nftl->EraseSize;
163 nftl->nb_boot_blocks = le16_to_cpu(mh->FirstPhysicalEUN);
164 if ((nftl->nb_boot_blocks + 2) >= nftl->nb_blocks) {
167 nftl->nb_boot_blocks, nftl->nb_blocks);
171 nftl->numvunits = le32_to_cpu(mh->FormattedSize) / nftl->EraseSize;
172 if (nftl->numvunits > (nftl->nb_blocks - nftl->nb_boot_blocks - 2)) {
175 nftl->numvunits, nftl->nb_blocks, nftl->nb_boot_blocks);
179 nftl->mbd.size = nftl->numvunits * (nftl->EraseSize / SECTORSIZE);
183 nftl->nb_blocks = le16_to_cpu(mh->NumEraseUnits) + le16_to_cpu(mh->FirstPhysicalEUN);
186 nftl->lastEUN = nftl->nb_blocks - 1;
189 nftl->EUNtable = kmalloc_array(nftl->nb_blocks, sizeof(u16),
191 if (!nftl->EUNtable) {
196 nftl->ReplUnitTable = kmalloc_array(nftl->nb_blocks,
199 if (!nftl->ReplUnitTable) {
200 kfree(nftl->EUNtable);
206 for (i = 0; i < nftl->nb_boot_blocks; i++)
207 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
209 for (; i < nftl->nb_blocks; i++) {
210 nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED;
214 nftl->ReplUnitTable[block] = BLOCK_RESERVED;
217 for (i = 0; i < nftl->nb_blocks; i++) {
222 ret = mtd->read(nftl->mbd.mtd,
223 block * nftl->EraseSize + i +
229 kfree(nftl->ReplUnitTable);
230 kfree(nftl->EUNtable);
236 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
238 if (mtd_block_isbad(nftl->mbd.mtd,
239 i * nftl->EraseSize))
240 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
243 nftl->MediaUnit = block;
262 static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len,
265 struct mtd_info *mtd = nftl->mbd.mtd;
305 int NFTL_formatblock(struct NFTLrecord *nftl, int block)
310 struct erase_info *instr = &nftl->instr;
311 struct mtd_info *mtd = nftl->mbd.mtd;
314 if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8,
329 instr->addr = block * nftl->EraseSize;
330 instr->len = nftl->EraseSize;
348 if (check_free_sectors(nftl, instr->addr, nftl->EraseSize, 1) != 0)
352 if (nftl_write_oob(mtd, block * nftl->EraseSize + SECTORSIZE +
359 mtd_block_markbad(nftl->mbd.mtd, instr->addr);
372 static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_block)
374 struct mtd_info *mtd = nftl->mbd.mtd;
380 sectors_per_block = nftl->EraseSize / SECTORSIZE;
385 block * nftl->EraseSize + i * SECTORSIZE,
396 check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE,
406 nftl->EraseSize +
417 block = nftl->ReplUnitTable[block];
418 if (!(block == BLOCK_NIL || block < nftl->nb_blocks))
420 if (block == BLOCK_NIL || block >= nftl->nb_blocks)
426 static int calc_chain_length(struct NFTLrecord *nftl, unsigned int first_block)
434 if (length >= nftl->nb_blocks) {
435 printk("nftl: length too long %d !\n", length);
439 block = nftl->ReplUnitTable[block];
440 if (!(block == BLOCK_NIL || block < nftl->nb_blocks))
442 if (block == BLOCK_NIL || block >= nftl->nb_blocks)
458 static void format_chain(struct NFTLrecord *nftl, unsigned int first_block)
465 block1 = nftl->ReplUnitTable[block];
468 if (NFTL_formatblock(nftl, block) < 0) {
470 nftl->ReplUnitTable[block] = BLOCK_RESERVED;
472 nftl->ReplUnitTable[block] = BLOCK_FREE;
478 if (!(block == BLOCK_NIL || block < nftl->nb_blocks))
480 if (block == BLOCK_NIL || block >= nftl->nb_blocks)
491 static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
493 struct mtd_info *mtd = nftl->mbd.mtd;
499 if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
507 if (check_free_sectors (nftl, block * nftl->EraseSize, nftl->EraseSize, 1) != 0)
515 block * nftl->EraseSize + SECTORSIZE + 8, 8,
521 for (i = 0; i < nftl->EraseSize; i += SECTORSIZE) {
523 if (check_free_sectors (nftl, block * nftl->EraseSize + i,
527 if (nftl_read_oob(mtd, block * nftl->EraseSize + i,
552 static int get_fold_mark(struct NFTLrecord *nftl, unsigned int block)
554 struct mtd_info *mtd = nftl->mbd.mtd;
558 if (nftl_read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8,