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)
194 nftl->ReplUnitTable = kmalloc_array(nftl->nb_blocks,
197 if (!nftl->ReplUnitTable) {
198 kfree(nftl->EUNtable);
203 for (i = 0; i < nftl->nb_boot_blocks; i++)
204 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
206 for (; i < nftl->nb_blocks; i++) {
207 nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED;
211 nftl->ReplUnitTable[block] = BLOCK_RESERVED;
214 for (i = 0; i < nftl->nb_blocks; i++) {
219 ret = mtd->read(nftl->mbd.mtd,
220 block * nftl->EraseSize + i +
226 kfree(nftl->ReplUnitTable);
227 kfree(nftl->EUNtable);
233 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
235 if (mtd_block_isbad(nftl->mbd.mtd,
236 i * nftl->EraseSize))
237 nftl->ReplUnitTable[i] = BLOCK_RESERVED;
240 nftl->MediaUnit = block;
259 static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len,
262 struct mtd_info *mtd = nftl->mbd.mtd;
302 int NFTL_formatblock(struct NFTLrecord *nftl, int block)
307 struct erase_info *instr = &nftl->instr;
308 struct mtd_info *mtd = nftl->mbd.mtd;
311 if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8,
326 instr->addr = block * nftl->EraseSize;
327 instr->len = nftl->EraseSize;
345 if (check_free_sectors(nftl, instr->addr, nftl->EraseSize, 1) != 0)
349 if (nftl_write_oob(mtd, block * nftl->EraseSize + SECTORSIZE +
356 mtd_block_markbad(nftl->mbd.mtd, instr->addr);
369 static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_block)
371 struct mtd_info *mtd = nftl->mbd.mtd;
377 sectors_per_block = nftl->EraseSize / SECTORSIZE;
382 block * nftl->EraseSize + i * SECTORSIZE,
393 check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE,
403 nftl->EraseSize +
414 block = nftl->ReplUnitTable[block];
415 if (!(block == BLOCK_NIL || block < nftl->nb_blocks))
417 if (block == BLOCK_NIL || block >= nftl->nb_blocks)
423 static int calc_chain_length(struct NFTLrecord *nftl, unsigned int first_block)
431 if (length >= nftl->nb_blocks) {
432 printk("nftl: length too long %d !\n", length);
436 block = nftl->ReplUnitTable[block];
437 if (!(block == BLOCK_NIL || block < nftl->nb_blocks))
439 if (block == BLOCK_NIL || block >= nftl->nb_blocks)
455 static void format_chain(struct NFTLrecord *nftl, unsigned int first_block)
462 block1 = nftl->ReplUnitTable[block];
465 if (NFTL_formatblock(nftl, block) < 0) {
467 nftl->ReplUnitTable[block] = BLOCK_RESERVED;
469 nftl->ReplUnitTable[block] = BLOCK_FREE;
475 if (!(block == BLOCK_NIL || block < nftl->nb_blocks))
477 if (block == BLOCK_NIL || block >= nftl->nb_blocks)
488 static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
490 struct mtd_info *mtd = nftl->mbd.mtd;
496 if (nftl_read_oob(mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8,
504 if (check_free_sectors (nftl, block * nftl->EraseSize, nftl->EraseSize, 1) != 0)
512 block * nftl->EraseSize + SECTORSIZE + 8, 8,
518 for (i = 0; i < nftl->EraseSize; i += SECTORSIZE) {
520 if (check_free_sectors (nftl, block * nftl->EraseSize + i,
524 if (nftl_read_oob(mtd, block * nftl->EraseSize + i,
549 static int get_fold_mark(struct NFTLrecord *nftl, unsigned int block)
551 struct mtd_info *mtd = nftl->mbd.mtd;
555 if (nftl_read_oob(mtd, block * nftl->EraseSize + 2 * SECTORSIZE + 8,