@@ -137,6 +137,8 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
137137 }
138138 }
139139 spin_unlock (& c -> erase_completion_lock );
140+ if (!ret )
141+ ret = jffs2_prealloc_raw_node_refs (c , 1 );
140142 if (ret )
141143 up (& c -> alloc_sem );
142144 return ret ;
@@ -158,6 +160,9 @@ int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
158160 }
159161 }
160162 spin_unlock (& c -> erase_completion_lock );
163+ if (!ret )
164+ ret = jffs2_prealloc_raw_node_refs (c , 1 );
165+
161166 return ret ;
162167}
163168
@@ -381,30 +386,30 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
381386 * Must be called with the alloc_sem held.
382387 */
383388
384- int jffs2_add_physical_node_ref (struct jffs2_sb_info * c , struct jffs2_raw_node_ref * new ,
385- uint32_t len , struct jffs2_inode_cache * ic )
389+ struct jffs2_raw_node_ref * jffs2_add_physical_node_ref (struct jffs2_sb_info * c ,
390+ uint32_t ofs , uint32_t len ,
391+ struct jffs2_inode_cache * ic )
386392{
387393 struct jffs2_eraseblock * jeb ;
394+ struct jffs2_raw_node_ref * new ;
388395
389- jeb = & c -> blocks [new -> flash_offset / c -> sector_size ];
390- #ifdef TEST_TOTLEN
391- new -> __totlen = len ;
392- #endif
396+ jeb = & c -> blocks [ofs / c -> sector_size ];
393397
394- D1 (printk (KERN_DEBUG "jffs2_add_physical_node_ref(): Node at 0x%x(%d), size 0x%x\n" , ref_offset (new ), ref_flags (new ), len ));
398+ D1 (printk (KERN_DEBUG "jffs2_add_physical_node_ref(): Node at 0x%x(%d), size 0x%x\n" ,
399+ ofs & ~3 , ofs & 3 , len ));
395400#if 1
396- /* we could get some obsolete nodes after nextblock was refiled
397- in wbuf.c */
398- if ((c -> nextblock || !ref_obsolete (new ))
399- && (jeb != c -> nextblock || ref_offset (new ) != jeb -> offset + (c -> sector_size - jeb -> free_size ))) {
401+ /* Allow non-obsolete nodes only to be added at the end of c->nextblock,
402+ if c->nextblock is set. Note that wbuf.c will file obsolete nodes
403+ even after refiling c->nextblock */
404+ if ((c -> nextblock || ((ofs & 3 ) != REF_OBSOLETE ))
405+ && (jeb != c -> nextblock || (ofs & ~3 ) != jeb -> offset + (c -> sector_size - jeb -> free_size ))) {
400406 printk (KERN_WARNING "argh. node added in wrong place\n" );
401- jffs2_free_raw_node_ref (new );
402- return - EINVAL ;
407+ return ERR_PTR (- EINVAL );
403408 }
404409#endif
405410 spin_lock (& c -> erase_completion_lock );
406411
407- jffs2_link_node_ref (c , jeb , new , len , ic );
412+ new = jffs2_link_node_ref (c , jeb , ofs , len , ic );
408413
409414 if (!jeb -> free_size && !jeb -> dirty_size && !ISDIRTY (jeb -> wasted_size )) {
410415 /* If it lives on the dirty_list, jffs2_reserve_space will put it there */
@@ -425,7 +430,7 @@ int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_r
425430
426431 spin_unlock (& c -> erase_completion_lock );
427432
428- return 0 ;
433+ return new ;
429434}
430435
431436
@@ -697,7 +702,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
697702 }
698703 spin_unlock (& c -> erase_completion_lock );
699704
700- jffs2_free_raw_node_ref (n );
705+ __jffs2_free_raw_node_ref (n );
701706 }
702707
703708 /* Also merge with the previous node in the list, if there is one
@@ -722,7 +727,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
722727 jeb -> gc_node = p ;
723728 }
724729 p -> next_phys = ref -> next_phys ;
725- jffs2_free_raw_node_ref (ref );
730+ __jffs2_free_raw_node_ref (ref );
726731 }
727732 spin_unlock (& c -> erase_completion_lock );
728733 }
0 commit comments