wbuf.c (0a1340c185734a57fbf4775927966ad4a1347b02) wbuf.c (7014568bad55c20b7ee4f439d78c9e875912d51f)
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 * Copyright (C) 2004 Thomas Gleixner <tglx@linutronix.de>
6 *
7 * Created by David Woodhouse <dwmw2@infradead.org>
8 * Modified debugged and enhanced by Thomas Gleixner <tglx@linutronix.de>

--- 954 unchanged lines hidden (view full) ---

963 */
964int jffs2_check_oob_empty(struct jffs2_sb_info *c,
965 struct jffs2_eraseblock *jeb, int mode)
966{
967 int i, page, ret;
968 int oobsize = c->mtd->oobsize;
969 struct mtd_oob_ops ops;
970
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 * Copyright (C) 2004 Thomas Gleixner <tglx@linutronix.de>
6 *
7 * Created by David Woodhouse <dwmw2@infradead.org>
8 * Modified debugged and enhanced by Thomas Gleixner <tglx@linutronix.de>

--- 954 unchanged lines hidden (view full) ---

963 */
964int jffs2_check_oob_empty(struct jffs2_sb_info *c,
965 struct jffs2_eraseblock *jeb, int mode)
966{
967 int i, page, ret;
968 int oobsize = c->mtd->oobsize;
969 struct mtd_oob_ops ops;
970
971 ops.len = NR_OOB_SCAN_PAGES * oobsize;
972 ops.ooblen = oobsize;
971 ops.ooblen = NR_OOB_SCAN_PAGES * oobsize;
973 ops.oobbuf = c->oobbuf;
974 ops.ooboffs = 0;
975 ops.datbuf = NULL;
976 ops.mode = MTD_OOB_PLACE;
977
978 ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops);
979 if (ret) {
980 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB "
981 "failed %d for block at %08x\n", ret, jeb->offset));
982 return ret;
983 }
984
972 ops.oobbuf = c->oobbuf;
973 ops.ooboffs = 0;
974 ops.datbuf = NULL;
975 ops.mode = MTD_OOB_PLACE;
976
977 ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops);
978 if (ret) {
979 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB "
980 "failed %d for block at %08x\n", ret, jeb->offset));
981 return ret;
982 }
983
985 if (ops.retlen < ops.len) {
984 if (ops.oobretlen < ops.ooblen) {
986 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB "
987 "returned short read (%zd bytes not %d) for block "
985 D1(printk(KERN_WARNING "jffs2_check_oob_empty(): Read OOB "
986 "returned short read (%zd bytes not %d) for block "
988 "at %08x\n", ops.retlen, ops.len, jeb->offset));
987 "at %08x\n", ops.oobretlen, ops.ooblen, jeb->offset));
989 return -EIO;
990 }
991
992 /* Special check for first page */
993 for(i = 0; i < oobsize ; i++) {
994 /* Yeah, we know about the cleanmarker. */
995 if (mode && i >= c->fsdata_pos &&
996 i < c->fsdata_pos + c->fsdata_len)
997 continue;
998
999 if (ops.oobbuf[i] != 0xFF) {
1000 D2(printk(KERN_DEBUG "Found %02x at %x in OOB for "
1001 "%08x\n", ops.oobbuf[i], i, jeb->offset));
1002 return 1;
1003 }
1004 }
1005
1006 /* we know, we are aligned :) */
988 return -EIO;
989 }
990
991 /* Special check for first page */
992 for(i = 0; i < oobsize ; i++) {
993 /* Yeah, we know about the cleanmarker. */
994 if (mode && i >= c->fsdata_pos &&
995 i < c->fsdata_pos + c->fsdata_len)
996 continue;
997
998 if (ops.oobbuf[i] != 0xFF) {
999 D2(printk(KERN_DEBUG "Found %02x at %x in OOB for "
1000 "%08x\n", ops.oobbuf[i], i, jeb->offset));
1001 return 1;
1002 }
1003 }
1004
1005 /* we know, we are aligned :) */
1007 for (page = oobsize; page < ops.len; page += sizeof(long)) {
1006 for (page = oobsize; page < ops.ooblen; page += sizeof(long)) {
1008 long dat = *(long *)(&ops.oobbuf[page]);
1009 if(dat != -1)
1010 return 1;
1011 }
1012 return 0;
1013}
1014
1015/*

--- 11 unchanged lines hidden (view full) ---

1027
1028 /* Check first if the block is bad. */
1029 if (c->mtd->block_isbad(c->mtd, offset)) {
1030 D1 (printk(KERN_WARNING "jffs2_check_nand_cleanmarker()"
1031 ": Bad block at %08x\n", jeb->offset));
1032 return 2;
1033 }
1034
1007 long dat = *(long *)(&ops.oobbuf[page]);
1008 if(dat != -1)
1009 return 1;
1010 }
1011 return 0;
1012}
1013
1014/*

--- 11 unchanged lines hidden (view full) ---

1026
1027 /* Check first if the block is bad. */
1028 if (c->mtd->block_isbad(c->mtd, offset)) {
1029 D1 (printk(KERN_WARNING "jffs2_check_nand_cleanmarker()"
1030 ": Bad block at %08x\n", jeb->offset));
1031 return 2;
1032 }
1033
1035 ops.len = oobsize;
1036 ops.ooblen = oobsize;
1037 ops.oobbuf = c->oobbuf;
1038 ops.ooboffs = 0;
1039 ops.datbuf = NULL;
1040 ops.mode = MTD_OOB_PLACE;
1041
1042 ret = c->mtd->read_oob(c->mtd, offset, &ops);
1043 if (ret) {
1044 D1 (printk(KERN_WARNING "jffs2_check_nand_cleanmarker(): "
1045 "Read OOB failed %d for block at %08x\n",
1046 ret, jeb->offset));
1047 return ret;
1048 }
1049
1034 ops.ooblen = oobsize;
1035 ops.oobbuf = c->oobbuf;
1036 ops.ooboffs = 0;
1037 ops.datbuf = NULL;
1038 ops.mode = MTD_OOB_PLACE;
1039
1040 ret = c->mtd->read_oob(c->mtd, offset, &ops);
1041 if (ret) {
1042 D1 (printk(KERN_WARNING "jffs2_check_nand_cleanmarker(): "
1043 "Read OOB failed %d for block at %08x\n",
1044 ret, jeb->offset));
1045 return ret;
1046 }
1047
1050 if (ops.retlen < ops.len) {
1048 if (ops.oobretlen < ops.ooblen) {
1051 D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): "
1052 "Read OOB return short read (%zd bytes not %d) "
1049 D1 (printk (KERN_WARNING "jffs2_check_nand_cleanmarker(): "
1050 "Read OOB return short read (%zd bytes not %d) "
1053 "for block at %08x\n", ops.retlen, ops.len,
1051 "for block at %08x\n", ops.oobretlen, ops.ooblen,
1054 jeb->offset));
1055 return -EIO;
1056 }
1057
1058 n.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
1059 n.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
1060 n.totlen = cpu_to_je32 (8);
1061 p = (unsigned char *) &n;

--- 22 unchanged lines hidden (view full) ---

1084 struct jffs2_unknown_node n;
1085 int ret;
1086 struct mtd_oob_ops ops;
1087
1088 n.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
1089 n.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER);
1090 n.totlen = cpu_to_je32(8);
1091
1052 jeb->offset));
1053 return -EIO;
1054 }
1055
1056 n.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
1057 n.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
1058 n.totlen = cpu_to_je32 (8);
1059 p = (unsigned char *) &n;

--- 22 unchanged lines hidden (view full) ---

1082 struct jffs2_unknown_node n;
1083 int ret;
1084 struct mtd_oob_ops ops;
1085
1086 n.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
1087 n.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER);
1088 n.totlen = cpu_to_je32(8);
1089
1092 ops.len = c->fsdata_len;
1093 ops.ooblen = c->fsdata_len;;
1090 ops.ooblen = c->fsdata_len;
1094 ops.oobbuf = (uint8_t *)&n;
1095 ops.ooboffs = c->fsdata_pos;
1096 ops.datbuf = NULL;
1097 ops.mode = MTD_OOB_PLACE;
1098
1099 ret = c->mtd->write_oob(c->mtd, jeb->offset, &ops);
1100
1101 if (ret) {
1102 D1(printk(KERN_WARNING "jffs2_write_nand_cleanmarker(): "
1103 "Write failed for block at %08x: error %d\n",
1104 jeb->offset, ret));
1105 return ret;
1106 }
1091 ops.oobbuf = (uint8_t *)&n;
1092 ops.ooboffs = c->fsdata_pos;
1093 ops.datbuf = NULL;
1094 ops.mode = MTD_OOB_PLACE;
1095
1096 ret = c->mtd->write_oob(c->mtd, jeb->offset, &ops);
1097
1098 if (ret) {
1099 D1(printk(KERN_WARNING "jffs2_write_nand_cleanmarker(): "
1100 "Write failed for block at %08x: error %d\n",
1101 jeb->offset, ret));
1102 return ret;
1103 }
1107 if (ops.retlen != ops.len) {
1104 if (ops.oobretlen != ops.ooblen) {
1108 D1(printk(KERN_WARNING "jffs2_write_nand_cleanmarker(): "
1109 "Short write for block at %08x: %zd not %d\n",
1105 D1(printk(KERN_WARNING "jffs2_write_nand_cleanmarker(): "
1106 "Short write for block at %08x: %zd not %d\n",
1110 jeb->offset, ops.retlen, ops.len));
1107 jeb->offset, ops.oobretlen, ops.ooblen));
1111 return -EIO;
1112 }
1113 return 0;
1114}
1115
1116/*
1117 * On NAND we try to mark this block bad. If the block was erased more
1118 * than MAX_ERASE_FAILURES we mark it finaly bad.

--- 160 unchanged lines hidden ---
1108 return -EIO;
1109 }
1110 return 0;
1111}
1112
1113/*
1114 * On NAND we try to mark this block bad. If the block was erased more
1115 * than MAX_ERASE_FAILURES we mark it finaly bad.

--- 160 unchanged lines hidden ---