Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / drivers / mtd / inftlmount.c
index a7075c2..43fdc94 100644 (file)
@@ -1,14 +1,14 @@
-/* 
+/*
  * inftlmount.c -- INFTL mount code with extensive checks.
  *
  * Author: Greg Ungerer (gerg@snapgear.com)
  * (C) Copyright 2002-2003, Greg Ungerer (gerg@snapgear.com)
  *
  * Based heavily on the nftlmount.c code which is:
- * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 
+ * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
  * Copyright (C) 2000 Netgem S.A.
  *
- * $Id: inftlmount.c,v 1.13 2004/06/28 16:06:36 dbrown Exp $
+ * $Id: inftlmount.c,v 1.18 2005/11/07 11:14:20 gleixner Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,7 +41,7 @@
 #include <linux/mtd/inftl.h>
 #include <linux/mtd/compatmac.h>
 
-char inftlmountrev[]="$Revision: 1.13 $";
+char inftlmountrev[]="$Revision: 1.18 $";
 
 /*
  * find_boot_record: Find the INFTL Media Header and its Spare copy which
@@ -58,10 +58,9 @@ static int find_boot_record(struct INFTLrecord *inftl)
        u8 buf[SECTORSIZE];
        struct INFTLMediaHeader *mh = &inftl->MediaHdr;
        struct INFTLPartition *ip;
-       int retlen;
+       size_t retlen;
 
-       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=0x%x)\n",
-               (int)inftl);
+       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
 
         /*
         * Assume logical EraseSize == physical erasesize for starting the
@@ -223,6 +222,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
                        if (ip->Reserved0 != ip->firstUnit) {
                                struct erase_info *instr = &inftl->instr;
 
+                               instr->mtd = inftl->mbd.mtd;
+
                                /*
                                 *      Most likely this is using the
                                 *      undocumented qiuck mount feature.
@@ -272,7 +273,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
                                inftl->nb_boot_blocks);
                        return -1;
                }
-               
+
                inftl->mbd.size  = inftl->numvunits *
                        (inftl->EraseSize / SECTORSIZE);
 
@@ -288,7 +289,7 @@ static int find_boot_record(struct INFTLrecord *inftl)
                inftl->PUtable = kmalloc(inftl->nb_blocks * sizeof(u16), GFP_KERNEL);
                if (!inftl->PUtable) {
                        printk(KERN_WARNING "INFTL: allocation of PUtable "
-                               "failed (%d bytes)\n",
+                               "failed (%zd bytes)\n",
                                inftl->nb_blocks * sizeof(u16));
                        return -ENOMEM;
                }
@@ -297,11 +298,11 @@ static int find_boot_record(struct INFTLrecord *inftl)
                if (!inftl->VUtable) {
                        kfree(inftl->PUtable);
                        printk(KERN_WARNING "INFTL: allocation of VUtable "
-                               "failed (%d bytes)\n",
+                               "failed (%zd bytes)\n",
                                inftl->nb_blocks * sizeof(u16));
                        return -ENOMEM;
                }
-               
+
                /* Mark the blocks before INFTL MediaHeader as reserved */
                for (i = 0; i < inftl->nb_boot_blocks; i++)
                        inftl->PUtable[i] = BLOCK_RESERVED;
@@ -348,11 +349,12 @@ static int memcmpb(void *a, int c, int n)
 static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
        int len, int check_oob)
 {
-       int i, retlen;
        u8 buf[SECTORSIZE + inftl->mbd.mtd->oobsize];
+       size_t retlen;
+       int i;
 
-       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: check_free_sectors(inftl=0x%x,"
-               "address=0x%x,len=%d,check_oob=%d)\n", (int)inftl,
+       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: check_free_sectors(inftl=%p,"
+               "address=0x%x,len=%d,check_oob=%d)\n", inftl,
                address, len, check_oob);
 
        for (i = 0; i < len; i += SECTORSIZE) {
@@ -378,17 +380,17 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address,
  *
  * Return: 0 when succeed, -1 on error.
  *
- * ToDo: 1. Is it neceressary to check_free_sector after erasing ?? 
+ * ToDo: 1. Is it neceressary to check_free_sector after erasing ??
  */
 int INFTL_formatblock(struct INFTLrecord *inftl, int block)
 {
-       int retlen;
+       size_t retlen;
        struct inftl_unittail uci;
        struct erase_info *instr = &inftl->instr;
        int physblock;
 
-       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=0x%x,"
-               "block=%d)\n", (int)inftl, block);
+       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_formatblock(inftl=%p,"
+               "block=%d)\n", inftl, block);
 
        memset(instr, 0, sizeof(struct erase_info));
 
@@ -396,6 +398,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block)
           _first_? */
 
        /* Use async erase interface, test return code */
+       instr->mtd = inftl->mbd.mtd;
        instr->addr = block * inftl->EraseSize;
        instr->len = inftl->mbd.mtd->erasesize;
        /* Erase one physical eraseblock at a time, even though the NAND api
@@ -551,15 +554,16 @@ int INFTL_mount(struct INFTLrecord *s)
        int chain_length, do_format_chain;
        struct inftl_unithead1 h0;
        struct inftl_unittail h1;
-       int i, retlen;
+       size_t retlen;
+       int i;
        u8 *ANACtable, ANAC;
 
-       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_mount(inftl=0x%x)\n", (int)s);
+       DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_mount(inftl=%p)\n", s);
 
        /* Search for INFTL MediaHeader and Spare INFTL Media Header */
        if (find_boot_record(s) < 0) {
                printk(KERN_WARNING "INFTL: could not find valid boot record?\n");
-               return -1;
+               return -ENXIO;
        }
 
        /* Init the logical to physical table */
@@ -570,6 +574,12 @@ int INFTL_mount(struct INFTLrecord *s)
 
        /* Temporary buffer to store ANAC numbers. */
        ANACtable = kmalloc(s->nb_blocks * sizeof(u8), GFP_KERNEL);
+       if (!ANACtable) {
+               printk(KERN_WARNING "INFTL: allocation of ANACtable "
+                               "failed (%zd bytes)\n",
+                               s->nb_blocks * sizeof(u8));
+               return -ENOMEM;
+       }
        memset(ANACtable, 0, s->nb_blocks);
 
        /*
@@ -591,7 +601,7 @@ int INFTL_mount(struct INFTLrecord *s)
 
                for (chain_length = 0; ; chain_length++) {
 
-                       if ((chain_length == 0) && 
+                       if ((chain_length == 0) &&
                            (s->PUtable[block] != BLOCK_NOTEXPLORED)) {
                                /* Nothing to do here, onto next block */
                                break;
@@ -738,7 +748,7 @@ int INFTL_mount(struct INFTLrecord *s)
                                        "in virtual chain %d\n",
                                        s->PUtable[block], logical_block);
                                s->PUtable[block] = BLOCK_NIL;
-                                       
+
                        }
                        if (ANACtable[block] != ANAC) {
                                /*