--- zzzz-none-000/linux-2.4.17/fs/jffs2/nodemgmt.c 2001-10-04 22:13:18.000000000 +0000 +++ sangam-fb-322/linux-2.4.17/fs/jffs2/nodemgmt.c 2004-11-24 13:22:18.000000000 +0000 @@ -1,7 +1,7 @@ /* * JFFS2 -- Journalling Flash File System, Version 2. * - * Copyright (C) 2001 Red Hat, Inc. + * Copyright (C) 2001, 2002 Red Hat, Inc. * * Created by David Woodhouse * @@ -31,17 +31,44 @@ * provisions above, a recipient may use your version of this file * under either the RHEPL or the GPL. * - * $Id: nodemgmt.c,v 1.45 2001/09/20 08:05:05 dwmw2 Exp $ + * $Id: nodemgmt.c,v 1.1.1.1 2003/06/23 22:18:37 jharrell Exp $ * */ #include #include -#include #include #include #include "nodelist.h" +/* Bias the free block calculations to reduce jitter. If we've already + GC'd enough of the current gc_block that we can fit the remainder + into the end of the block we're filling, require one fewer free + block than we otherwise would. +*/ +static inline int jffs2_reserve_bias(struct jffs2_sb_info *c) +{ + __u32 gc_ofs; + + if (!c->gcblock) + return 0; + + D1(if (!c->gcblock->gc_node) BUG()); + + if (!c->nextblock) + return 0; + + gc_ofs = c->gcblock->gc_node->flash_offset & ~(c->sector_size - 1); + + if (gc_ofs > c->nextblock->free_size) { + /* We're already far enough through the GC to fit the + remainder of gc_block into nextblock */ + D1(printk(KERN_DEBUG "jffs2_reserve_bias returns 1. gc_ofs 0x%08x, nextblock->free_size 0x%08x\n", gc_ofs, c->nextblock->free_size)); + return 1; + } + return 0; +} + /** * jffs2_reserve_space - request physical space to write nodes to flash * @c: superblock info @@ -62,9 +89,9 @@ * for the requested allocation. */ -static int jffs2_do_reserve_space(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len); +static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len); -int jffs2_reserve_space(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len, int prio) +int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len, int prio) { int ret = -EAGAIN; int blocksneeded = JFFS2_RESERVED_BLOCKS_WRITE; @@ -83,7 +110,7 @@ /* this needs a little more thought */ while(ret == -EAGAIN) { - while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) { + while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded - jffs2_reserve_bias(c)) { int ret; up(&c->alloc_sem); @@ -122,7 +149,7 @@ return ret; } -int jffs2_reserve_space_gc(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len) +int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len) { int ret = -EAGAIN; minsize = PAD(minsize); @@ -141,7 +168,7 @@ } /* Called with alloc sem _and_ erase_completion_lock */ -static int jffs2_do_reserve_space(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len) +static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len) { struct jffs2_eraseblock *jeb = c->nextblock; @@ -227,7 +254,7 @@ * Must be called with the alloc_sem held. */ -int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new, __u32 len, int dirty) +int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new, uint32_t len, int dirty) { struct jffs2_eraseblock *jeb; @@ -286,7 +313,7 @@ int blocknr; struct jffs2_unknown_node n; int ret; - ssize_t retlen; + size_t retlen; if(!ref) { printk(KERN_NOTICE "EEEEEK. jffs2_mark_node_obsolete called with NULL node\n"); @@ -349,11 +376,11 @@ if (c->mtd->type != MTD_NORFLASH && c->mtd->type != MTD_RAM) return; - if (OFNI_BS_2SFFJ(c)->s_flags & MS_RDONLY) + if (jffs2_is_readonly(c)) return; D1(printk(KERN_DEBUG "obliterating obsoleted node at 0x%08x\n", ref->flash_offset &~3)); - ret = c->mtd->read(c->mtd, ref->flash_offset &~3, sizeof(n), &retlen, (char *)&n); + ret = jffs2_flash_read(c, ref->flash_offset &~3, sizeof(n), &retlen, (char *)&n); if (ret) { printk(KERN_WARNING "Read error reading from obsoleted node at 0x%08x: %d\n", ref->flash_offset &~3, ret); return; @@ -371,7 +398,7 @@ return; } n.nodetype &= ~JFFS2_NODE_ACCURATE; - ret = c->mtd->write(c->mtd, ref->flash_offset&~3, sizeof(n), &retlen, (char *)&n); + ret = jffs2_flash_write(c, ref->flash_offset&~3, sizeof(n), &retlen, (char *)&n); if (ret) { printk(KERN_WARNING "Write error in obliterating obsoleted node at 0x%08x: %d\n", ref->flash_offset &~3, ret); return;