diff options
Diffstat (limited to 'drivers/mtd/nftlmount.c')
-rw-r--r-- | drivers/mtd/nftlmount.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index 84afd9029f53..3b104ebb219a 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * NFTL mount code with extensive checks | 2 | * NFTL mount code with extensive checks |
3 | * | 3 | * |
4 | * Author: Fabrice Bellard (fabrice.bellard@netgem.com) | 4 | * Author: Fabrice Bellard (fabrice.bellard@netgem.com) |
5 | * Copyright (C) 2000 Netgem S.A. | 5 | * Copyright (C) 2000 Netgem S.A. |
6 | * | 6 | * |
7 | * $Id: nftlmount.c,v 1.40 2004/11/22 14:38:29 kalev Exp $ | 7 | * $Id: nftlmount.c,v 1.41 2005/11/07 11:14:21 gleixner Exp $ |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | #define SECTORSIZE 512 | 32 | #define SECTORSIZE 512 |
33 | 33 | ||
34 | char nftlmountrev[]="$Revision: 1.40 $"; | 34 | char nftlmountrev[]="$Revision: 1.41 $"; |
35 | 35 | ||
36 | /* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the | 36 | /* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the |
37 | * various device information of the NFTL partition and Bad Unit Table. Update | 37 | * various device information of the NFTL partition and Bad Unit Table. Update |
@@ -47,7 +47,7 @@ static int find_boot_record(struct NFTLrecord *nftl) | |||
47 | struct NFTLMediaHeader *mh = &nftl->MediaHdr; | 47 | struct NFTLMediaHeader *mh = &nftl->MediaHdr; |
48 | unsigned int i; | 48 | unsigned int i; |
49 | 49 | ||
50 | /* Assume logical EraseSize == physical erasesize for starting the scan. | 50 | /* Assume logical EraseSize == physical erasesize for starting the scan. |
51 | We'll sort it out later if we find a MediaHeader which says otherwise */ | 51 | We'll sort it out later if we find a MediaHeader which says otherwise */ |
52 | /* Actually, we won't. The new DiskOnChip driver has already scanned | 52 | /* Actually, we won't. The new DiskOnChip driver has already scanned |
53 | the MediaHeader and adjusted the virtual erasesize it presents in | 53 | the MediaHeader and adjusted the virtual erasesize it presents in |
@@ -83,9 +83,9 @@ static int find_boot_record(struct NFTLrecord *nftl) | |||
83 | if (retlen < 6 || memcmp(buf, "ANAND", 6)) { | 83 | if (retlen < 6 || memcmp(buf, "ANAND", 6)) { |
84 | /* ANAND\0 not found. Continue */ | 84 | /* ANAND\0 not found. Continue */ |
85 | #if 0 | 85 | #if 0 |
86 | printk(KERN_DEBUG "ANAND header not found at 0x%x in mtd%d\n", | 86 | printk(KERN_DEBUG "ANAND header not found at 0x%x in mtd%d\n", |
87 | block * nftl->EraseSize, nftl->mbd.mtd->index); | 87 | block * nftl->EraseSize, nftl->mbd.mtd->index); |
88 | #endif | 88 | #endif |
89 | continue; | 89 | continue; |
90 | } | 90 | } |
91 | 91 | ||
@@ -103,7 +103,7 @@ static int find_boot_record(struct NFTLrecord *nftl) | |||
103 | */ | 103 | */ |
104 | if (le16_to_cpu(h1.EraseMark | h1.EraseMark1) != ERASE_MARK) { | 104 | if (le16_to_cpu(h1.EraseMark | h1.EraseMark1) != ERASE_MARK) { |
105 | printk(KERN_NOTICE "ANAND header found at 0x%x in mtd%d, but erase mark not present (0x%04x,0x%04x instead)\n", | 105 | printk(KERN_NOTICE "ANAND header found at 0x%x in mtd%d, but erase mark not present (0x%04x,0x%04x instead)\n", |
106 | block * nftl->EraseSize, nftl->mbd.mtd->index, | 106 | block * nftl->EraseSize, nftl->mbd.mtd->index, |
107 | le16_to_cpu(h1.EraseMark), le16_to_cpu(h1.EraseMark1)); | 107 | le16_to_cpu(h1.EraseMark), le16_to_cpu(h1.EraseMark1)); |
108 | continue; | 108 | continue; |
109 | } | 109 | } |
@@ -175,7 +175,7 @@ device is already correct. | |||
175 | nftl->nb_boot_blocks = le16_to_cpu(mh->FirstPhysicalEUN); | 175 | nftl->nb_boot_blocks = le16_to_cpu(mh->FirstPhysicalEUN); |
176 | if ((nftl->nb_boot_blocks + 2) >= nftl->nb_blocks) { | 176 | if ((nftl->nb_boot_blocks + 2) >= nftl->nb_blocks) { |
177 | printk(KERN_NOTICE "NFTL Media Header sanity check failed:\n"); | 177 | printk(KERN_NOTICE "NFTL Media Header sanity check failed:\n"); |
178 | printk(KERN_NOTICE "nb_boot_blocks (%d) + 2 > nb_blocks (%d)\n", | 178 | printk(KERN_NOTICE "nb_boot_blocks (%d) + 2 > nb_blocks (%d)\n", |
179 | nftl->nb_boot_blocks, nftl->nb_blocks); | 179 | nftl->nb_boot_blocks, nftl->nb_blocks); |
180 | return -1; | 180 | return -1; |
181 | } | 181 | } |
@@ -187,7 +187,7 @@ device is already correct. | |||
187 | nftl->numvunits, nftl->nb_blocks, nftl->nb_boot_blocks); | 187 | nftl->numvunits, nftl->nb_blocks, nftl->nb_boot_blocks); |
188 | return -1; | 188 | return -1; |
189 | } | 189 | } |
190 | 190 | ||
191 | nftl->mbd.size = nftl->numvunits * (nftl->EraseSize / SECTORSIZE); | 191 | nftl->mbd.size = nftl->numvunits * (nftl->EraseSize / SECTORSIZE); |
192 | 192 | ||
193 | /* If we're not using the last sectors in the device for some reason, | 193 | /* If we're not using the last sectors in the device for some reason, |
@@ -210,12 +210,12 @@ device is already correct. | |||
210 | printk(KERN_NOTICE "NFTL: allocation of ReplUnitTable failed\n"); | 210 | printk(KERN_NOTICE "NFTL: allocation of ReplUnitTable failed\n"); |
211 | return -ENOMEM; | 211 | return -ENOMEM; |
212 | } | 212 | } |
213 | 213 | ||
214 | /* mark the bios blocks (blocks before NFTL MediaHeader) as reserved */ | 214 | /* mark the bios blocks (blocks before NFTL MediaHeader) as reserved */ |
215 | for (i = 0; i < nftl->nb_boot_blocks; i++) | 215 | for (i = 0; i < nftl->nb_boot_blocks; i++) |
216 | nftl->ReplUnitTable[i] = BLOCK_RESERVED; | 216 | nftl->ReplUnitTable[i] = BLOCK_RESERVED; |
217 | /* mark all remaining blocks as potentially containing data */ | 217 | /* mark all remaining blocks as potentially containing data */ |
218 | for (; i < nftl->nb_blocks; i++) { | 218 | for (; i < nftl->nb_blocks; i++) { |
219 | nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED; | 219 | nftl->ReplUnitTable[i] = BLOCK_NOTEXPLORED; |
220 | } | 220 | } |
221 | 221 | ||
@@ -245,12 +245,12 @@ The new DiskOnChip driver already scanned the bad block table. Just query it. | |||
245 | if (nftl->mbd.mtd->block_isbad(nftl->mbd.mtd, i * nftl->EraseSize)) | 245 | if (nftl->mbd.mtd->block_isbad(nftl->mbd.mtd, i * nftl->EraseSize)) |
246 | nftl->ReplUnitTable[i] = BLOCK_RESERVED; | 246 | nftl->ReplUnitTable[i] = BLOCK_RESERVED; |
247 | } | 247 | } |
248 | 248 | ||
249 | nftl->MediaUnit = block; | 249 | nftl->MediaUnit = block; |
250 | boot_record_count++; | 250 | boot_record_count++; |
251 | 251 | ||
252 | } /* foreach (block) */ | 252 | } /* foreach (block) */ |
253 | 253 | ||
254 | return boot_record_count?0:-1; | 254 | return boot_record_count?0:-1; |
255 | } | 255 | } |
256 | 256 | ||
@@ -265,7 +265,7 @@ static int memcmpb(void *a, int c, int n) | |||
265 | } | 265 | } |
266 | 266 | ||
267 | /* check_free_sector: check if a free sector is actually FREE, i.e. All 0xff in data and oob area */ | 267 | /* check_free_sector: check if a free sector is actually FREE, i.e. All 0xff in data and oob area */ |
268 | static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len, | 268 | static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int len, |
269 | int check_oob) | 269 | int check_oob) |
270 | { | 270 | { |
271 | int i; | 271 | int i; |
@@ -293,7 +293,7 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int | |||
293 | * | 293 | * |
294 | * Return: 0 when succeed, -1 on error. | 294 | * Return: 0 when succeed, -1 on error. |
295 | * | 295 | * |
296 | * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? | 296 | * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? |
297 | */ | 297 | */ |
298 | int NFTL_formatblock(struct NFTLrecord *nftl, int block) | 298 | int NFTL_formatblock(struct NFTLrecord *nftl, int block) |
299 | { | 299 | { |
@@ -385,7 +385,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b | |||
385 | /* verify that the sector is really free. If not, mark | 385 | /* verify that the sector is really free. If not, mark |
386 | as ignore */ | 386 | as ignore */ |
387 | if (memcmpb(&bci, 0xff, 8) != 0 || | 387 | if (memcmpb(&bci, 0xff, 8) != 0 || |
388 | check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE, | 388 | check_free_sectors(nftl, block * nftl->EraseSize + i * SECTORSIZE, |
389 | SECTORSIZE, 0) != 0) { | 389 | SECTORSIZE, 0) != 0) { |
390 | printk("Incorrect free sector %d in block %d: " | 390 | printk("Incorrect free sector %d in block %d: " |
391 | "marking it as ignored\n", | 391 | "marking it as ignored\n", |
@@ -486,7 +486,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) | |||
486 | size_t retlen; | 486 | size_t retlen; |
487 | 487 | ||
488 | /* check erase mark. */ | 488 | /* check erase mark. */ |
489 | if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, | 489 | if (MTD_READOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, |
490 | &retlen, (char *)&h1) < 0) | 490 | &retlen, (char *)&h1) < 0) |
491 | return -1; | 491 | return -1; |
492 | 492 | ||
@@ -501,7 +501,7 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block) | |||
501 | h1.EraseMark = cpu_to_le16(ERASE_MARK); | 501 | h1.EraseMark = cpu_to_le16(ERASE_MARK); |
502 | h1.EraseMark1 = cpu_to_le16(ERASE_MARK); | 502 | h1.EraseMark1 = cpu_to_le16(ERASE_MARK); |
503 | h1.WearInfo = cpu_to_le32(0); | 503 | h1.WearInfo = cpu_to_le32(0); |
504 | if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, | 504 | if (MTD_WRITEOOB(nftl->mbd.mtd, block * nftl->EraseSize + SECTORSIZE + 8, 8, |
505 | &retlen, (char *)&h1) < 0) | 505 | &retlen, (char *)&h1) < 0) |
506 | return -1; | 506 | return -1; |
507 | } else { | 507 | } else { |
@@ -582,9 +582,9 @@ int NFTL_mount(struct NFTLrecord *s) | |||
582 | 582 | ||
583 | for (;;) { | 583 | for (;;) { |
584 | /* read the block header. If error, we format the chain */ | 584 | /* read the block header. If error, we format the chain */ |
585 | if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, 8, | 585 | if (MTD_READOOB(s->mbd.mtd, block * s->EraseSize + 8, 8, |
586 | &retlen, (char *)&h0) < 0 || | 586 | &retlen, (char *)&h0) < 0 || |
587 | MTD_READOOB(s->mbd.mtd, block * s->EraseSize + SECTORSIZE + 8, 8, | 587 | MTD_READOOB(s->mbd.mtd, block * s->EraseSize + SECTORSIZE + 8, 8, |
588 | &retlen, (char *)&h1) < 0) { | 588 | &retlen, (char *)&h1) < 0) { |
589 | s->ReplUnitTable[block] = BLOCK_NIL; | 589 | s->ReplUnitTable[block] = BLOCK_NIL; |
590 | do_format_chain = 1; | 590 | do_format_chain = 1; |
@@ -639,7 +639,7 @@ int NFTL_mount(struct NFTLrecord *s) | |||
639 | first_logical_block = logical_block; | 639 | first_logical_block = logical_block; |
640 | } else { | 640 | } else { |
641 | if (logical_block != first_logical_block) { | 641 | if (logical_block != first_logical_block) { |
642 | printk("Block %d: incorrect logical block: %d expected: %d\n", | 642 | printk("Block %d: incorrect logical block: %d expected: %d\n", |
643 | block, logical_block, first_logical_block); | 643 | block, logical_block, first_logical_block); |
644 | /* the chain is incorrect : we must format it, | 644 | /* the chain is incorrect : we must format it, |
645 | but we need to read it completly */ | 645 | but we need to read it completly */ |
@@ -668,7 +668,7 @@ int NFTL_mount(struct NFTLrecord *s) | |||
668 | s->ReplUnitTable[block] = BLOCK_NIL; | 668 | s->ReplUnitTable[block] = BLOCK_NIL; |
669 | break; | 669 | break; |
670 | } else if (rep_block >= s->nb_blocks) { | 670 | } else if (rep_block >= s->nb_blocks) { |
671 | printk("Block %d: referencing invalid block %d\n", | 671 | printk("Block %d: referencing invalid block %d\n", |
672 | block, rep_block); | 672 | block, rep_block); |
673 | do_format_chain = 1; | 673 | do_format_chain = 1; |
674 | s->ReplUnitTable[block] = BLOCK_NIL; | 674 | s->ReplUnitTable[block] = BLOCK_NIL; |
@@ -688,7 +688,7 @@ int NFTL_mount(struct NFTLrecord *s) | |||
688 | s->ReplUnitTable[block] = rep_block; | 688 | s->ReplUnitTable[block] = rep_block; |
689 | s->EUNtable[first_logical_block] = BLOCK_NIL; | 689 | s->EUNtable[first_logical_block] = BLOCK_NIL; |
690 | } else { | 690 | } else { |
691 | printk("Block %d: referencing block %d already in another chain\n", | 691 | printk("Block %d: referencing block %d already in another chain\n", |
692 | block, rep_block); | 692 | block, rep_block); |
693 | /* XXX: should handle correctly fold in progress chains */ | 693 | /* XXX: should handle correctly fold in progress chains */ |
694 | do_format_chain = 1; | 694 | do_format_chain = 1; |
@@ -710,7 +710,7 @@ int NFTL_mount(struct NFTLrecord *s) | |||
710 | } else { | 710 | } else { |
711 | unsigned int first_block1, chain_to_format, chain_length1; | 711 | unsigned int first_block1, chain_to_format, chain_length1; |
712 | int fold_mark; | 712 | int fold_mark; |
713 | 713 | ||
714 | /* valid chain : get foldmark */ | 714 | /* valid chain : get foldmark */ |
715 | fold_mark = get_fold_mark(s, first_block); | 715 | fold_mark = get_fold_mark(s, first_block); |
716 | if (fold_mark == 0) { | 716 | if (fold_mark == 0) { |
@@ -729,9 +729,9 @@ int NFTL_mount(struct NFTLrecord *s) | |||
729 | if (first_block1 != BLOCK_NIL) { | 729 | if (first_block1 != BLOCK_NIL) { |
730 | /* XXX: what to do if same length ? */ | 730 | /* XXX: what to do if same length ? */ |
731 | chain_length1 = calc_chain_length(s, first_block1); | 731 | chain_length1 = calc_chain_length(s, first_block1); |
732 | printk("Two chains at blocks %d (len=%d) and %d (len=%d)\n", | 732 | printk("Two chains at blocks %d (len=%d) and %d (len=%d)\n", |
733 | first_block1, chain_length1, first_block, chain_length); | 733 | first_block1, chain_length1, first_block, chain_length); |
734 | 734 | ||
735 | if (chain_length >= chain_length1) { | 735 | if (chain_length >= chain_length1) { |
736 | chain_to_format = first_block1; | 736 | chain_to_format = first_block1; |
737 | s->EUNtable[first_logical_block] = first_block; | 737 | s->EUNtable[first_logical_block] = first_block; |