^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * JFFS2 -- Journalling Flash File System, Version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright © 2001-2007 Red Hat, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Created by David Woodhouse <dwmw2@infradead.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * For licensing information, see the file 'LICENCE' in this directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "nodelist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void jffs2_erase_block(struct jffs2_sb_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct jffs2_eraseblock *jeb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) uint32_t bad_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #ifdef __ECOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ret = jffs2_flash_erase(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) jffs2_erase_succeeded(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) bad_offset = jeb->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #else /* Linux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct erase_info *instr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) jffs2_dbg(1, "%s(): erase block %#08x (range %#08x-%#08x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) jeb->offset, jeb->offset, jeb->offset + c->sector_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) instr = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (!instr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) pr_warn("kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) list_move(&jeb->list, &c->erase_pending_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) c->erasing_size -= c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) c->dirty_size += c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) jeb->dirty_size = c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) memset(instr, 0, sizeof(*instr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) instr->addr = jeb->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) instr->len = c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ret = mtd_erase(c->mtd, instr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) jffs2_erase_succeeded(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) kfree(instr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) bad_offset = instr->fail_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) kfree(instr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #endif /* __ECOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (ret == -ENOMEM || ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Erase failed immediately. Refile it on the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) jffs2_dbg(1, "Erase at 0x%08x failed: %d. Refiling on erase_pending_list\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) jeb->offset, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) list_move(&jeb->list, &c->erase_pending_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) c->erasing_size -= c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) c->dirty_size += c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) jeb->dirty_size = c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (ret == -EROFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) pr_warn("Erase at 0x%08x failed immediately: -EROFS. Is the sector locked?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pr_warn("Erase at 0x%08x failed immediately: errno %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) jeb->offset, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) jffs2_erase_failed(c, jeb, bad_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct jffs2_eraseblock *jeb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int work_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) while (!list_empty(&c->erase_complete_list) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) !list_empty(&c->erase_pending_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!list_empty(&c->erase_complete_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) jeb = list_entry(c->erase_complete_list.next, struct jffs2_eraseblock, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) list_move(&jeb->list, &c->erase_checking_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) jffs2_mark_erased_block(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) work_done++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (!--count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) jffs2_dbg(1, "Count reached. jffs2_erase_pending_blocks leaving\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) } else if (!list_empty(&c->erase_pending_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) jeb = list_entry(c->erase_pending_list.next, struct jffs2_eraseblock, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) jffs2_dbg(1, "Starting erase of pending block 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) list_del(&jeb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) c->erasing_size += c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) c->wasted_size -= jeb->wasted_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) c->free_size -= jeb->free_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) c->used_size -= jeb->used_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) c->dirty_size -= jeb->dirty_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) jeb->wasted_size = jeb->used_size = jeb->dirty_size = jeb->free_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) jffs2_free_jeb_node_refs(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) list_add(&jeb->list, &c->erasing_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) jffs2_erase_block(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* Be nice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) jffs2_dbg(1, "jffs2_erase_pending_blocks completed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return work_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) jffs2_dbg(1, "Erase completed successfully at 0x%08x\n", jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) list_move_tail(&jeb->list, &c->erase_complete_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Wake the GC thread to mark them clean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) jffs2_garbage_collect_trigger(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) wake_up(&c->erase_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* For NAND, if the failure did not occur at the device level for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) specific physical page, don't bother updating the bad block table. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (jffs2_cleanmarker_oob(c) && (bad_offset != (uint32_t)MTD_FAIL_ADDR_UNKNOWN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* We had a device-level failure to erase. Let's see if we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) failed too many times. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!jffs2_write_nand_badblock(c, jeb, bad_offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* We'd like to give this block another try. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) list_move(&jeb->list, &c->erase_pending_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) c->erasing_size -= c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) c->dirty_size += c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) jeb->dirty_size = c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) c->erasing_size -= c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) c->bad_size += c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) list_move(&jeb->list, &c->bad_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) c->nr_erasing_blocks--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) wake_up(&c->erase_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Hmmm. Maybe we should accept the extra space it takes and make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) this a standard doubly-linked list? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct jffs2_raw_node_ref *ref, struct jffs2_eraseblock *jeb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct jffs2_inode_cache *ic = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct jffs2_raw_node_ref **prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) prev = &ref->next_in_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Walk the inode's list once, removing any nodes from this eraseblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!(*prev)->next_in_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* We're looking at the jffs2_inode_cache, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) at the end of the linked list. Stash it and continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) from the beginning of the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ic = (struct jffs2_inode_cache *)(*prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) prev = &ic->nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (SECTOR_ADDR((*prev)->flash_offset) == jeb->offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* It's in the block we're erasing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct jffs2_raw_node_ref *this;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) this = *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) *prev = this->next_in_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) this->next_in_ino = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (this == ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* Not to be deleted. Skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) prev = &((*prev)->next_in_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* PARANOIA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!ic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) JFFS2_WARNING("inode_cache/xattr_datum/xattr_ref"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) " not found in remove_node_refs()!!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) jffs2_dbg(1, "Removed nodes in range 0x%08x-0x%08x from ino #%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) jeb->offset, jeb->offset + c->sector_size, ic->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) D2({
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int i=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct jffs2_raw_node_ref *this;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) printk(KERN_DEBUG "After remove_node_refs_from_ino_list: \n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) this = ic->nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) printk(KERN_DEBUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) while(this) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) pr_cont("0x%08x(%d)->",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ref_offset(this), ref_flags(this));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (++i == 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) printk(KERN_DEBUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) i=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) this = this->next_in_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) });
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) switch (ic->class) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #ifdef CONFIG_JFFS2_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) case RAWNODE_CLASS_XATTR_DATUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) jffs2_release_xattr_datum(c, (struct jffs2_xattr_datum *)ic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case RAWNODE_CLASS_XATTR_REF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) jffs2_release_xattr_ref(c, (struct jffs2_xattr_ref *)ic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (ic->nodes == (void *)ic && ic->pino_nlink == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) jffs2_del_ino_cache(c, ic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) void jffs2_free_jeb_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct jffs2_raw_node_ref *block, *ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) jffs2_dbg(1, "Freeing all node refs for eraseblock offset 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) block = ref = jeb->first_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) while (ref) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (ref->flash_offset == REF_LINK_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ref = ref->next_in_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) jffs2_free_refblock(block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) block = ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (ref->flash_offset != REF_EMPTY_NODE && ref->next_in_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) jffs2_remove_node_refs_from_ino_list(c, ref, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* else it was a non-inode node or already removed, so don't bother */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ref++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) jeb->first_node = jeb->last_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t *bad_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) void *ebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) uint32_t ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) size_t retlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) unsigned long *wordebuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) &ebuf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (ret != -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) jffs2_dbg(1, "MTD point failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) goto do_flash_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (retlen < c->sector_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* Don't muck about if it won't let us point to the whole erase sector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) retlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mtd_unpoint(c->mtd, jeb->offset, retlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) goto do_flash_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) wordebuf = ebuf-sizeof(*wordebuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) retlen /= sizeof(*wordebuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (*++wordebuf != ~0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) } while(--retlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) mtd_unpoint(c->mtd, jeb->offset, c->sector_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (retlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) pr_warn("Newly-erased block contained word 0x%lx at offset 0x%08tx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) *wordebuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) jeb->offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) c->sector_size-retlen * sizeof(*wordebuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) do_flash_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (!ebuf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) pr_warn("Failed to allocate page buffer for verifying erase at 0x%08x. Refiling\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) jffs2_dbg(1, "Verifying erase at 0x%08x\n", jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) for (ofs = jeb->offset; ofs < jeb->offset + c->sector_size; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) uint32_t readlen = min((uint32_t)PAGE_SIZE, jeb->offset + c->sector_size - ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *bad_offset = ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ret = mtd_read(c->mtd, ofs, readlen, &retlen, ebuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) pr_warn("Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ofs, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (retlen != readlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) pr_warn("Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ofs, readlen, retlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) for (i=0; i<readlen; i += sizeof(unsigned long)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* It's OK. We know it's properly aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) unsigned long *datum = ebuf + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (*datum + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) *bad_offset += i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) pr_warn("Newly-erased block contained word 0x%lx at offset 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) *datum, *bad_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ofs += readlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) kfree(ebuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) size_t retlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) uint32_t bad_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) switch (jffs2_block_check_erase(c, jeb, &bad_offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) case -EAGAIN: goto refile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) case -EIO: goto filebad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* Write the erase complete marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) jffs2_dbg(1, "Writing erased marker to block at 0x%08x\n", jeb->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) bad_offset = jeb->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /* Cleanmarker in oob area or no cleanmarker at all ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (jffs2_cleanmarker_oob(c) || c->cleanmarker_size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (jffs2_cleanmarker_oob(c)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (jffs2_write_nand_cleanmarker(c, jeb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) goto filebad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct kvec vecs[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct jffs2_unknown_node marker = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .totlen = cpu_to_je32(c->cleanmarker_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) jffs2_prealloc_raw_node_refs(c, jeb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) marker.hdr_crc = cpu_to_je32(crc32(0, &marker, sizeof(struct jffs2_unknown_node)-4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) vecs[0].iov_base = (unsigned char *) ▮
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) vecs[0].iov_len = sizeof(marker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ret = jffs2_flash_direct_writev(c, vecs, 1, jeb->offset, &retlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (ret || retlen != sizeof(marker)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) pr_warn("Write clean marker to block at 0x%08x failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) jeb->offset, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) pr_warn("Short write to newly-erased block at 0x%08x: Wanted %zd, got %zd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) jeb->offset, sizeof(marker), retlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) goto filebad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* Everything else got zeroed before the erase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) jeb->free_size = c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) c->erasing_size -= c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) c->free_size += c->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* Account for cleanmarker now, if it's in-band */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (c->cleanmarker_size && !jffs2_cleanmarker_oob(c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL, c->cleanmarker_size, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) list_move_tail(&jeb->list, &c->free_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) c->nr_erasing_blocks--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) c->nr_free_blocks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) jffs2_dbg_acct_sanity_check_nolock(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) wake_up(&c->erase_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) filebad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) jffs2_erase_failed(c, jeb, bad_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) refile:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* Stick it back on the list from whence it came and come back later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) mutex_lock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) spin_lock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) jffs2_garbage_collect_trigger(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) list_move(&jeb->list, &c->erase_complete_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) spin_unlock(&c->erase_completion_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) mutex_unlock(&c->erase_free_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }