Add yaffs2 file system: Third patchset
cover Add yaffs2 file system: Third patchset
This is the third submission of a yaffs2 patchset.
I would like to thank everyone that has given comments so far. They have been most helpful.
I would like to thank CELF and Google for sponsoring the effort to get yaffs2 mainlined.
This code is patched from 3788df745cd72e035c0c991157cb727a8ecb1f17 at git://www.aleph1.co.uk/yaffs2.
This patch set takes onboard almost all the comments provided since the last set of patches. Most noteably :
* Removal of kernel locking
* Removal of some debugging /proc entries
* Use of kernel hweight8/32() functions.
This code ran various tests for the whole night with no problems seen.
Comments/feedback welcome, but I'm hopefully getting pretty close to acceptance :-).
-- Charles
PATCH 1/8 Add yaffs2 file system: allocator, attribs, bitmap code
--- fs/yaffs2/yaffs_allocator.c | 397 +++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_allocator.h | 30 ++++ fs/yaffs2/yaffs_attribs.c | 124 ++++++++++++++ fs/yaffs2/yaffs_attribs.h | 28 +++ fs/yaffs2/yaffs_bitmap.c | 104 +++++++++++ fs/yaffs2/yaffs_bitmap.h | 33 ++++ 6 files changed, 716 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_allocator.c create mode 100644 fs/yaffs2/yaffs_allocator.h create mode 100644 fs/yaffs2/yaffs_attribs.c create mode 100644 fs/yaffs2/yaffs_attribs.h create mode 100644 fs/yaffs2/yaffs_bitmap.c create mode 100644 fs/yaffs2/yaffs_bitmap.h
fs/yaffs2/yaffs_allocator.c new file +397 -0
@@ -0,0 +1,397 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_allocator.h" +#include "yaffs_guts.h" +#include "yaffs_trace.h" +#include "yportenv.h" + +#ifdef CONFIG_YAFFS_YMALLOC_ALLOCATOR + +void yaffs_deinit_raw_tnodes_and_objs (struct yaffs_dev *dev) +{ + dev = dev; +} + +void yaffs_init_raw_tnodes_and_objs (struct yaffs_dev *dev) +{ + dev = dev; +} + +struct yaffs_tnode *yaffs_alloc_raw_tnode (struct yaffs_dev *dev) +{ +return (struct yaffs_tnode *)YMALLOC (dev->tnode_size); +} + +void yaffs_free_raw_tnode (struct yaffs_dev *dev,struct yaffs_tnode *tn) +{ + dev = dev; +YFREE (tn); +} + +void yaffs_init_raw_objs (struct yaffs_dev *dev) +{ + dev = dev; +} + +void yaffs_deinit_raw_objs (struct yaffs_dev *dev) +{ + dev = dev; +} + +struct yaffs_obj *yaffs_alloc_raw_obj (struct yaffs_dev *dev) +{ + dev = dev; +return (struct yaffs_obj *)YMALLOC (sizeof (struct yaffs_obj )); +} + +void yaffs_free_raw_obj (struct yaffs_dev *dev,struct yaffs_obj *obj) +{ + + dev = dev; +YFREE (obj); +} + +#else + +struct yaffs_tnode_list { +struct yaffs_tnode_list *next; +struct yaffs_tnode *tnodes; +}; + +struct yaffs_obj_list { +struct yaffs_obj_list *next; +struct yaffs_obj *objects; +}; + +struct yaffs_allocator { +int n_tnodes_created; +struct yaffs_tnode *free_tnodes; +int n_free_tnodes; +struct yaffs_tnode_list *alloc_tnode_list; + +int n_obj_created; +struct yaffs_obj *free_objs; +int n_free_objects; + +struct yaffs_obj_list *allocated_obj_list; +}; + +static void yaffs_deinit_raw_tnodes (struct yaffs_dev *dev) +{ + +struct yaffs_allocator *allocator = + (struct yaffs_allocator *)dev->allocator; + +struct yaffs_tnode_list *tmp; + +if (!allocator) { +YBUG (); +return ; + } + +while (allocator->alloc_tnode_list) { + tmp = allocator->alloc_tnode_list->next; + +YFREE (allocator->alloc_tnode_list->tnodes); +YFREE (allocator->alloc_tnode_list); + allocator->alloc_tnode_list = tmp; + + } + + allocator->free_tnodes =NULL ; + allocator->n_free_tnodes =0 ; + allocator->n_tnodes_created =0 ; +} + +static void yaffs_init_raw_tnodes (struct yaffs_dev *dev) +{ +struct yaffs_allocator *allocator = dev->allocator; + +if (allocator) { + allocator->alloc_tnode_list =NULL ; + allocator->free_tnodes =NULL ; + allocator->n_free_tnodes =0 ; + allocator->n_tnodes_created =0 ; + }else { +YBUG (); + } +} + +static int yaffs_create_tnodes (struct yaffs_dev *dev,int n_tnodes) +{ +struct yaffs_allocator *allocator = + (struct yaffs_allocator *)dev->allocator; +int i; +struct yaffs_tnode *new_tnodes; +u8 *mem; +struct yaffs_tnode *curr; +struct yaffs_tnode *next; +struct yaffs_tnode_list *tnl; + +if (!allocator) { +YBUG (); +return YAFFS_FAIL ; + } + +if (n_tnodes <1 ) +return YAFFS_OK ; + +/* make these things */ + + new_tnodes =YMALLOC (n_tnodes * dev->tnode_size); + mem = (u8 *) new_tnodes; + +if (!new_tnodes) { +T (YAFFS_TRACE_ERROR , + (TSTR ("yaffs: Could not allocate Tnodes" TENDSTR ))); +return YAFFS_FAIL ; + } + +/* New hookup for wide tnodes */ +for (i =0 ; i < n_tnodes -1 ; i++) { + curr = (struct yaffs_tnode *)&mem[i * dev->tnode_size]; + next = (struct yaffs_tnode *)&mem[(i +1 ) * dev->tnode_size]; + curr->internal[0 ] = next; + } + + curr = (struct yaffs_tnode *)&mem[(n_tnodes -1 ) * dev->tnode_size]; + curr->internal[0 ] = allocator->free_tnodes; + allocator->free_tnodes = (struct yaffs_tnode *)mem; + + allocator->n_free_tnodes += n_tnodes; + allocator->n_tnodes_created += n_tnodes; + +/* Now add this bunch of tnodes to a list for freeing up. +* NB If we can't add this to the management list it isn't fatal +* but it just means we can't free this bunch of tnodes later. +*/ + + tnl =YMALLOC (sizeof (struct yaffs_tnode_list )); +if (!tnl) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("yaffs: Could not add tnodes to management list" TENDSTR ))); +return YAFFS_FAIL ; + }else { + tnl->tnodes = new_tnodes; + tnl->next = allocator->alloc_tnode_list; + allocator->alloc_tnode_list = tnl; + } + +T (YAFFS_TRACE_ALLOCATE , (TSTR ("yaffs: Tnodes added" TENDSTR ))); + +return YAFFS_OK ; +} + +struct yaffs_tnode *yaffs_alloc_raw_tnode (struct yaffs_dev *dev) +{ +struct yaffs_allocator *allocator = + (struct yaffs_allocator *)dev->allocator; +struct yaffs_tnode *tn =NULL ; + +if (!allocator) { +YBUG (); +return NULL ; + } + +/* If there are none left make more */ +if (!allocator->free_tnodes) +yaffs_create_tnodes (dev,YAFFS_ALLOCATION_NTNODES ); + +if (allocator->free_tnodes) { + tn = allocator->free_tnodes; + allocator->free_tnodes = allocator->free_tnodes->internal[0 ]; + allocator->n_free_tnodes--; + } + +return tn; +} + +/* FreeTnode frees up a tnode and puts it back on the free list */ +void yaffs_free_raw_tnode (struct yaffs_dev *dev,struct yaffs_tnode *tn) +{ +struct yaffs_allocator *allocator = dev->allocator; + +if (!allocator) { +YBUG (); +return ; + } + +if (tn) { + tn->internal[0 ] = allocator->free_tnodes; + allocator->free_tnodes = tn; + allocator->n_free_tnodes++; + } + dev->checkpoint_blocks_required =0 ;/* force recalculation */ +} + +static void yaffs_init_raw_objs (struct yaffs_dev *dev) +{ +struct yaffs_allocator *allocator = dev->allocator; + +if (allocator) { + allocator->allocated_obj_list =NULL ; + allocator->free_objs =NULL ; + allocator->n_free_objects =0 ; + }else { +YBUG (); + } +} + +static void yaffs_deinit_raw_objs (struct yaffs_dev *dev) +{ +struct yaffs_allocator *allocator = dev->allocator; +struct yaffs_obj_list *tmp; + +if (!allocator) { +YBUG (); +return ; + } + +while (allocator->allocated_obj_list) { + tmp = allocator->allocated_obj_list->next; +YFREE (allocator->allocated_obj_list->objects); +YFREE (allocator->allocated_obj_list); + + allocator->allocated_obj_list = tmp; + } + + allocator->free_objs =NULL ; + allocator->n_free_objects =0 ; + allocator->n_obj_created =0 ; +} + +static int yaffs_create_free_objs (struct yaffs_dev *dev,int n_obj) +{ +struct yaffs_allocator *allocator = dev->allocator; + +int i; +struct yaffs_obj *new_objs; +struct yaffs_obj_list *list; + +if (!allocator) { +YBUG (); +return YAFFS_FAIL ; + } + +if (n_obj <1 ) +return YAFFS_OK ; + +/* make these things */ + new_objs =YMALLOC (n_obj *sizeof (struct yaffs_obj )); + list =YMALLOC (sizeof (struct yaffs_obj_list )); + +if (!new_objs || !list) { +if (new_objs) { +YFREE (new_objs); + new_objs =NULL ; + } +if (list) { +YFREE (list); + list =NULL ; + } +T (YAFFS_TRACE_ALLOCATE , + (TSTR ("yaffs: Could not allocate more objects" TENDSTR ))); +return YAFFS_FAIL ; + } + +/* Hook them into the free list */ +for (i =0 ; i < n_obj -1 ; i++) { + new_objs[i].siblings.next = + (struct list_head *)(&new_objs[i +1 ]); + } + + new_objs[n_obj -1 ].siblings.next = (void *)allocator->free_objs; + allocator->free_objs = new_objs; + allocator->n_free_objects += n_obj; + allocator->n_obj_created += n_obj; + +/* Now add this bunch of Objects to a list for freeing up. */ + + list->objects = new_objs; + list->next = allocator->allocated_obj_list; + allocator->allocated_obj_list = list; + +return YAFFS_OK ; +} + +struct yaffs_obj *yaffs_alloc_raw_obj (struct yaffs_dev *dev) +{ +struct yaffs_obj *obj =NULL ; +struct yaffs_allocator *allocator = dev->allocator; + +if (!allocator) { +YBUG (); +return obj; + } + +/* If there are none left make more */ +if (!allocator->free_objs) +yaffs_create_free_objs (dev,YAFFS_ALLOCATION_NOBJECTS ); + +if (allocator->free_objs) { + obj = allocator->free_objs; + allocator->free_objs = + (struct yaffs_obj *)(allocator->free_objs->siblings.next); + allocator->n_free_objects--; + } + +return obj; +} + +void yaffs_free_raw_obj (struct yaffs_dev *dev,struct yaffs_obj *obj) +{ + +struct yaffs_allocator *allocator = dev->allocator; + +if (!allocator) +YBUG (); +else { +/* Link into the free list. */ + obj->siblings.next = (struct list_head *)(allocator->free_objs); + allocator->free_objs = obj; + allocator->n_free_objects++; + } +} + +void yaffs_deinit_raw_tnodes_and_objs (struct yaffs_dev *dev) +{ +if (dev->allocator) { +yaffs_deinit_raw_tnodes (dev); +yaffs_deinit_raw_objs (dev); + +YFREE (dev->allocator); + dev->allocator =NULL ; + }else { +YBUG (); + } +} + +void yaffs_init_raw_tnodes_and_objs (struct yaffs_dev *dev) +{ +struct yaffs_allocator *allocator; + +if (!dev->allocator) { + allocator =YMALLOC (sizeof (struct yaffs_allocator )); +if (allocator) { + dev->allocator = allocator; +yaffs_init_raw_tnodes (dev); +yaffs_init_raw_objs (dev); + } + }else { +YBUG (); + } +} + +#endif
fs/yaffs2/yaffs_allocator.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_ALLOCATOR_H__ +#define __YAFFS_ALLOCATOR_H__ + +#include "yaffs_guts.h" + +void yaffs_init_raw_tnodes_and_objs (struct yaffs_dev *dev); +void yaffs_deinit_raw_tnodes_and_objs (struct yaffs_dev *dev); + +struct yaffs_tnode *yaffs_alloc_raw_tnode (struct yaffs_dev *dev); +void yaffs_free_raw_tnode (struct yaffs_dev *dev,struct yaffs_tnode *tn); + +struct yaffs_obj *yaffs_alloc_raw_obj (struct yaffs_dev *dev); +void yaffs_free_raw_obj (struct yaffs_dev *dev,struct yaffs_obj *obj); + +#endif
fs/yaffs2/yaffs_attribs.c new file +124 -0
124 lines not on this page · raw message
fs/yaffs2/yaffs_attribs.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_ATTRIBS_H__ +#define __YAFFS_ATTRIBS_H__ + +#include "yaffs_guts.h" + +void yaffs_load_attribs (struct yaffs_obj *obj,struct yaffs_obj_hdr *oh); +void yaffs_load_attribs_oh (struct yaffs_obj_hdr *oh,struct yaffs_obj *obj); +void yaffs_attribs_init (struct yaffs_obj *obj,u32 gid,u32 uid,u32 rdev); +void yaffs_load_current_time (struct yaffs_obj *obj,int do_a,int do_c); +int yaffs_set_attribs (struct yaffs_obj *obj,struct iattr *attr); +int yaffs_get_attribs (struct yaffs_obj *obj,struct iattr *attr); + +#endif
fs/yaffs2/yaffs_bitmap.c new file +104 -0
104 lines not on this page · raw message
fs/yaffs2/yaffs_bitmap.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +/* +* Chunk bitmap manipulations +*/ + +#ifndef __YAFFS_BITMAP_H__ +#define __YAFFS_BITMAP_H__ + +#include "yaffs_guts.h" + +void yaffs_verify_chunk_bit_id (struct yaffs_dev *dev,int blk,int chunk); +void yaffs_clear_chunk_bits (struct yaffs_dev *dev,int blk); +void yaffs_clear_chunk_bit (struct yaffs_dev *dev,int blk,int chunk); +void yaffs_set_chunk_bit (struct yaffs_dev *dev,int blk,int chunk); +int yaffs_check_chunk_bit (struct yaffs_dev *dev,int blk,int chunk); +int yaffs_still_some_chunks (struct yaffs_dev *dev,int blk); +int yaffs_count_chunk_bits (struct yaffs_dev *dev,int blk); + +#endif
Signature · 1 line
1.7.1
Re: [PATCH 1/8] Add yaffs2 file system: allocator, attribs, bitmap code
fs/yaffs2/yaffs_attribs.c line 40
Quoted 3 lines · Charles Manning
fs/yaffs2/yaffs_attribs.c new file +3
-0+void yaffs_load_current_time (struct yaffs_obj *obj,int do_a,int do_c) +{ + obj->yst_mtime =Y_CURRENT_TIME ;
^
fs/yaffs2/yaffs_attribs.c line 42
Quoted 2 lines
fs/yaffs2/yaffs_attribs.c new file +2
-0+if (do_a) + obj->yst_atime = obj->yst_atime;
^ ^
fs/yaffs2/yaffs_attribs.c line 44
Quoted 2 lines
fs/yaffs2/yaffs_attribs.c new file +2
-0+if (do_c) + obj->yst_ctime = obj->yst_atime;
^ ^
Review
Quoted 2 lines
(quoted diff) +2
-0+} +
Funny bug.
Marcin
Re: [PATCH 1/8] Add yaffs2 file system: allocator, attribs, bitmap code
Quoted 17 lines · On Friday 03 December 2010 07:14:04 Marcin Slusarz wrote:
fs/yaffs2/yaffs_attribs.c line 40
Quoted 3 lines · Charles Manning
fs/yaffs2/yaffs_attribs.c new file +3
-0+void yaffs_load_current_time (struct yaffs_obj *obj,int do_a,int do_c) +{ + obj->yst_mtime =Y_CURRENT_TIME ;^fs/yaffs2/yaffs_attribs.c line 42
Quoted 2 lines
fs/yaffs2/yaffs_attribs.c new file +2
-0+if (do_a) + obj->yst_atime = obj->yst_atime;^ ^
fs/yaffs2/yaffs_attribs.c line 44
Quoted 2 lines
fs/yaffs2/yaffs_attribs.c new file +2
-0+if (do_c) + obj->yst_ctime = obj->yst_atime;^ ^
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+} +Funny bug.
Thanks.
I shall fix this in yaffs git right away.
The power of open source!
Re: [PATCH 1/8] Add yaffs2 file system: allocator, attribs, bitmap code
In reply to Charles ManningQuoted 31 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>--- fs/yaffs2/yaffs_allocator.c | 397 +++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_allocator.h | 30 ++++ fs/yaffs2/yaffs_attribs.c | 124 ++++++++++++++ fs/yaffs2/yaffs_attribs.h | 28 +++ fs/yaffs2/yaffs_bitmap.c | 104 +++++++++++ fs/yaffs2/yaffs_bitmap.h | 33 ++++ 6 files changed, 716 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_allocator.c create mode 100644 fs/yaffs2/yaffs_allocator.h create mode 100644 fs/yaffs2/yaffs_attribs.c create mode 100644 fs/yaffs2/yaffs_attribs.h create mode 100644 fs/yaffs2/yaffs_bitmap.c create mode 100644 fs/yaffs2/yaffs_bitmap.hfs/yaffs2/yaffs_allocator.c new file +9
-0@@ -0,0 +1,397 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify
fs/yaffs2/yaffs_allocator.c line 19
Quoted 10 lines
fs/yaffs2/yaffs_allocator.c new file +10
-0+* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_allocator.h" +#include "yaffs_guts.h" +#include "yaffs_trace.h" +#include "yportenv.h" + +#ifdef CONFIG_YAFFS_YMALLOC_ALLOCATOR
This doesn't appear to be defined anywhere and is not in Kconfig. Is this just a wrapper for support on other operating systems or does it can it be used on Linux for debugging? In the former case it should probably removed and in the latter it should probably have a comment explaining why you would want to define it.
<snip>
fs/yaffs2/yaffs_allocator.c line 27
Quoted 8 lines
fs/yaffs2/yaffs_allocator.c new file +8
-0+ +#include "yaffs_bitmap.h" +#include "yaffs_trace.h" +/* +* Chunk bitmap manipulations +*/ + +static Y_INLINE u8 *yaffs_block_bits(struct yaffs_dev *dev, int blk)
Should just use inline.
<snip>
fs/yaffs2/yaffs_allocator.c line 33
Quoted 6 lines
fs/yaffs2/yaffs_allocator.c new file +6
-0+ +int yaffs_still_some_chunks (struct yaffs_dev *dev,int blk) +{ +u8 *blk_bits =yaffs_block_bits (dev, blk); +int i; +for (i =0 ; i < dev->chunk_bit_stride; i++) {
Nitpick: You should have a blank line between variable declarations and start of code.
<snip>
Quoted 7 lines
fs/yaffs2/yaffs_allocator.c new file +7
-0+int yaffs_count_chunk_bits (struct yaffs_dev *dev,int blk) +{ +u8 *blk_bits =yaffs_block_bits (dev, blk); +int i; +int n =0 ; +for (i =0 ; i < dev->chunk_bit_stride; i++) { +u8 x = *blk_bits;
fs/yaffs2/yaffs_allocator.c line 50
Quoted 10 lines
fs/yaffs2/yaffs_allocator.c new file +10
-0+while (x) { +if (x &1 ) + n++; + x >>=1 ; + } + + blk_bits++; + } +return n; +}
This is possibly more concise as a for loop. Also moving the definitions all to the top of the file and combining same types definitions on one line reduces this function to:
int yaffs_count_chunk_bits(struct yaffs_dev *dev, int blk)
{
u8 x, *blk_bits = yaffs_block_bits(dev, blk);
int i, n = 0;
for (i = 0; i < dev->chunk_bit_stride; i++, blk_bits++)
for (x = *blk_bits; x; x >>= 1)
if (x & 1)
n++;
return n;
}~Ryan
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre Ryan Mallon 5 Amuri Park, 404 Barbadoes St [email protected] PO Box 13 889, Christchurch 8013 http://www.bluewatersys.com New Zealand Phone: +64 3 3779127 Freecall: Australia 1800 148 751 Fax: +64 3 3779135 USA 1800 261 2934
Re: [PATCH 1/8] Add yaffs2 file system: allocator, attribs, bitmap code
Quoted 104 lines · Ryan Mallon
Quoted 31 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
fs/yaffs2/yaffs_allocator.c | 397 +++++++++++++++++++++++++++++++++++++++++++fs/yaffs2/yaffs_allocator.h| 30 ++++
fs/yaffs2/yaffs_attribs.c | 124 ++++++++++++++fs/yaffs2/yaffs_attribs.h| 28 +++
fs/yaffs2/yaffs_bitmap.c | 104 +++++++++++fs/yaffs2/yaffs_bitmap.h| 33 ++++6 files changed, 716 insertions(+), 0 deletions(-)create mode 100644
fs/yaffs2/yaffs_allocator.c
create mode 100644fs/yaffs2/yaffs_allocator.h
create mode 100644fs/yaffs2/yaffs_attribs.c
create mode 100644fs/yaffs2/yaffs_attribs.h
create mode 100644fs/yaffs2/yaffs_bitmap.c
create mode 100644fs/yaffs2/yaffs_bitmap.hfs/yaffs2/yaffs_allocator.c new file +9
-0@@ -0,0 +1,397 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify fs/yaffs2/yaffs_allocator.c line 19
Quoted 10 lines
fs/yaffs2/yaffs_allocator.c new file +10
-0+* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_allocator.h" +#include "yaffs_guts.h" +#include "yaffs_trace.h" +#include "yportenv.h" + +#ifdef CONFIG_YAFFS_YMALLOC_ALLOCATOR This doesn't appear to be defined anywhere and is not in
Kconfig. Is this just a wrapper for support on other operating systems or does it can it be used on Linux for debugging? In the former case it should probably removed and in the latter it should probably have a comment explaining why you would want to define it.<snip>
fs/yaffs2/yaffs_allocator.c line 27
Quoted 8 lines
fs/yaffs2/yaffs_allocator.c new file +8
-0+ +#include "yaffs_bitmap.h" +#include "yaffs_trace.h" +/* +* Chunk bitmap manipulations +*/ + +static Y_INLINE u8 *yaffs_block_bits(struct yaffs_dev *dev, int blk)Should just use inline.
<snip>
fs/yaffs2/yaffs_allocator.c line 33
Quoted 6 lines
fs/yaffs2/yaffs_allocator.c new file +6
-0+ +int yaffs_still_some_chunks (struct yaffs_dev *dev,int blk) +{ + u8 *blk_bits = yaffs_block_bits(dev, blk); + int i; + for (i = 0; i < dev->chunk_bit_stride; i++) {Nitpick: You should have a blank line between variable declarations and start of code.
<snip>
Quoted 7 lines
fs/yaffs2/yaffs_allocator.c new file +7
-0+int yaffs_count_chunk_bits (struct yaffs_dev *dev,int blk) +{ + u8 *blk_bits = yaffs_block_bits(dev, blk); + int i; + int n = 0; + for (i = 0; i < dev->chunk_bit_stride; i++) { + u8 x = *blk_bits;fs/yaffs2/yaffs_allocator.c line 50
Quoted 10 lines
fs/yaffs2/yaffs_allocator.c new file +10
-0+ while (x) { + if (x & 1) + n++; + x >>= 1; + } + + blk_bits++; + } + return n; +}This is possibly more concise as a for loop. Also moving the definitions all to the top of the file and combining same types definitions on one line reduces this function to:
int
yaffs_count_chunk_bits(struct yaffs_dev *dev, int blk){
u8 x,*blk_bits=yaffs_block_bits(dev, blk); int i, n = 0;
Quoted 7 lines
for (i = 0; i <
dev->chunk_bit_stride; i++, blk_bits++) for (x =*blk_bits; x; x >>= 1)
if (x & 1)
n++;return n;
}
Actually, how about using the standard hamming weight function? This adds a dependency on linux/bitops.h, but seems to be carefully crafted to be as fast as possible based on the available hardware.
int yaffs_count_chunk_bits(struct yaffs_dev *dev, int blk)
{
u8 *blk_bits = yaffs_block_bits(dev, blk);
int i, n = 0;
for (i = 0; i < dev->chunk_bit_stride; i++, blk_bits++)
n += hweight8(*blk_bits);
return n;
}Kevin Granade
Quoted 17 lines
~Ryan
--
Bluewater Systems Ltd - ARM Technology Solution CentreRyan Mallon 5 Amuri Park, 404 Barbadoes St [email protected] PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com New Zealand
Phone: +64 3 3779127 Freecall: Australia 1800 148 751
Fax: +64 3 3779135 USA 1800 261 2934
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
PATCH 2/8 Add yaffs2 file system: checkpoint and ecc code
In reply to Charles Manning--- fs/yaffs2/yaffs_checkptrw.c | 420 +++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_checkptrw.h | 33 ++++ fs/yaffs2/yaffs_ecc.c | 298 ++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_ecc.h | 44 +++++ 4 files changed, 795 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_checkptrw.c create mode 100644 fs/yaffs2/yaffs_checkptrw.h create mode 100644 fs/yaffs2/yaffs_ecc.c create mode 100644 fs/yaffs2/yaffs_ecc.h
fs/yaffs2/yaffs_checkptrw.c new file +420 -0
@@ -0,0 +1,420 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_checkptrw.h" +#include "yaffs_getblockinfo.h" + +static int yaffs2_checkpt_space_ok (struct yaffs_dev *dev) +{ +int blocks_avail = dev->n_erased_blocks - dev->param.n_reserved_blocks; + +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("checkpt blocks available = %d" TENDSTR ), blocks_avail)); + +return (blocks_avail <=0 ) ?0 :1 ; +} + +static int yaffs_checkpt_erase (struct yaffs_dev *dev) +{ +int i; + +if (!dev->param.erase_fn) +return 0 ; +T (YAFFS_TRACE_CHECKPOINT , (TSTR ("checking blocks %d to %d" TENDSTR ), + dev->internal_start_block, + dev->internal_end_block)); + +for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) { +struct yaffs_block_info *bi =yaffs_get_block_info (dev, i); +if (bi->block_state ==YAFFS_BLOCK_STATE_CHECKPOINT ) { +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("erasing checkpt block %d" TENDSTR ), i)); + + dev->n_erasures++; + +if (dev->param. +erase_fn (dev, + i - dev->block_offset/* realign */ )) { + bi->block_state =YAFFS_BLOCK_STATE_EMPTY ; + dev->n_erased_blocks++; + dev->n_free_chunks += + dev->param.chunks_per_block; + }else { + dev->param.bad_block_fn (dev, i); + bi->block_state =YAFFS_BLOCK_STATE_DEAD ; + } + } + } + + dev->blocks_in_checkpt =0 ; + +return 1 ; +} + +static void yaffs2_checkpt_find_erased_block (struct yaffs_dev *dev) +{ +int i; +int blocks_avail = dev->n_erased_blocks - dev->param.n_reserved_blocks; +T (YAFFS_TRACE_CHECKPOINT , + (TSTR + ("allocating checkpt block: erased %d reserved %d avail %d next %d " +TENDSTR ), dev->n_erased_blocks, dev->param.n_reserved_blocks, + blocks_avail, dev->checkpt_next_block)); + +if (dev->checkpt_next_block >=0 && + dev->checkpt_next_block <= dev->internal_end_block && + blocks_avail >0 ) { + +for (i = dev->checkpt_next_block; i <= dev->internal_end_block; + i++) { +struct yaffs_block_info *bi = +yaffs_get_block_info (dev, i); +if (bi->block_state ==YAFFS_BLOCK_STATE_EMPTY ) { + dev->checkpt_next_block = i +1 ; + dev->checkpt_cur_block = i; +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("allocating checkpt block %d" TENDSTR ), + i)); +return ; + } + } + } +T (YAFFS_TRACE_CHECKPOINT , (TSTR ("out of checkpt blocks" TENDSTR ))); + + dev->checkpt_next_block =-1 ; + dev->checkpt_cur_block =-1 ; +} + +static void yaffs2_checkpt_find_block (struct yaffs_dev *dev) +{ +int i; +struct yaffs_ext_tags tags; + +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("find next checkpt block: start: blocks %d next %d" TENDSTR ), + dev->blocks_in_checkpt, dev->checkpt_next_block)); + +if (dev->blocks_in_checkpt < dev->checkpt_max_blocks) +for (i = dev->checkpt_next_block; i <= dev->internal_end_block; + i++) { +int chunk = i * dev->param.chunks_per_block; +int realigned_chunk = chunk - dev->chunk_offset; + + dev->param.read_chunk_tags_fn (dev, realigned_chunk, +NULL , &tags); +T (YAFFS_TRACE_CHECKPOINT , + (TSTR + ("find next checkpt block: search: block %d oid %d seq %d eccr %d" +TENDSTR ), i, tags.obj_id, tags.seq_number, + tags.ecc_result)); + +if (tags.seq_number ==YAFFS_SEQUENCE_CHECKPOINT_DATA ) { +/* Right kind of block */ + dev->checkpt_next_block = tags.obj_id; + dev->checkpt_cur_block = i; + dev->checkpt_block_list[dev-> + blocks_in_checkpt] = i; + dev->blocks_in_checkpt++; +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("found checkpt block %d" TENDSTR ), i)); +return ; + } + } + +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("found no more checkpt blocks" TENDSTR ))); + + dev->checkpt_next_block =-1 ; + dev->checkpt_cur_block =-1 ; +} + +int yaffs2_checkpt_open (struct yaffs_dev *dev,int writing) +{ + + dev->checkpt_open_write = writing; + +/* Got the functions we need? */ +if (!dev->param.write_chunk_tags_fn || + !dev->param.read_chunk_tags_fn || + !dev->param.erase_fn || !dev->param.bad_block_fn) +return 0 ; + +if (writing && !yaffs2_checkpt_space_ok (dev)) +return 0 ; + +if (!dev->checkpt_buffer) + dev->checkpt_buffer = +YMALLOC_DMA (dev->param.total_bytes_per_chunk); +if (!dev->checkpt_buffer) +return 0 ; + + dev->checkpt_page_seq =0 ; + dev->checkpt_byte_count =0 ; + dev->checkpt_sum =0 ; + dev->checkpt_xor =0 ; + dev->checkpt_cur_block =-1 ; + dev->checkpt_cur_chunk =-1 ; + dev->checkpt_next_block = dev->internal_start_block; + +/* Erase all the blocks in the checkpoint area */ +if (writing) { +memset (dev->checkpt_buffer,0 , dev->data_bytes_per_chunk); + dev->checkpt_byte_offs =0 ; +return yaffs_checkpt_erase (dev); + }else { +int i; +/* Set to a value that will kick off a read */ + dev->checkpt_byte_offs = dev->data_bytes_per_chunk; +/* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully) +* going to be way more than we need */ + dev->blocks_in_checkpt =0 ; + dev->checkpt_max_blocks = + (dev->internal_end_block - dev->internal_start_block) /16 + +2 ; + dev->checkpt_block_list = +YMALLOC (sizeof (int ) * dev->checkpt_max_blocks); +if (!dev->checkpt_block_list) +return 0 ; + +for (i =0 ; i < dev->checkpt_max_blocks; i++) + dev->checkpt_block_list[i] =-1 ; + } + +return 1 ; +} + +int yaffs2_get_checkpt_sum (struct yaffs_dev *dev,u32 * sum) +{ +u32 composite_sum; + composite_sum = (dev->checkpt_sum <<8 ) | (dev->checkpt_xor &0xFF ); + *sum = composite_sum; +return 1 ; +} + +static int yaffs2_checkpt_flush_buffer (struct yaffs_dev *dev) +{ +int chunk; +int realigned_chunk; + +struct yaffs_ext_tags tags; + +if (dev->checkpt_cur_block <0 ) { +yaffs2_checkpt_find_erased_block (dev); + dev->checkpt_cur_chunk =0 ; + } + +if (dev->checkpt_cur_block <0 ) +return 0 ; + + tags.is_deleted =0 ; + tags.obj_id = dev->checkpt_next_block;/* Hint to next place to look */ + tags.chunk_id = dev->checkpt_page_seq +1 ; + tags.seq_number =YAFFS_SEQUENCE_CHECKPOINT_DATA ; + tags.n_bytes = dev->data_bytes_per_chunk; +if (dev->checkpt_cur_chunk ==0 ) { +/* First chunk we write for the block? Set block state to +checkpoint */ +struct yaffs_block_info *bi = +yaffs_get_block_info (dev, dev->checkpt_cur_block); + bi->block_state =YAFFS_BLOCK_STATE_CHECKPOINT ; + dev->blocks_in_checkpt++; + } + + chunk = + dev->checkpt_cur_block * dev->param.chunks_per_block + + dev->checkpt_cur_chunk; + +T (YAFFS_TRACE_CHECKPOINT , + (TSTR + ("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR ), + chunk, dev->checkpt_cur_block, dev->checkpt_cur_chunk, tags.obj_id, + tags.chunk_id)); + + realigned_chunk = chunk - dev->chunk_offset; + + dev->n_page_writes++; + + dev->param.write_chunk_tags_fn (dev, realigned_chunk, + dev->checkpt_buffer, &tags); + dev->checkpt_byte_offs =0 ; + dev->checkpt_page_seq++; + dev->checkpt_cur_chunk++; +if (dev->checkpt_cur_chunk >= dev->param.chunks_per_block) { + dev->checkpt_cur_chunk =0 ; + dev->checkpt_cur_block =-1 ; + } +memset (dev->checkpt_buffer,0 , dev->data_bytes_per_chunk); + +return 1 ; +} + +int yaffs2_checkpt_wr (struct yaffs_dev *dev,const void *data,int n_bytes) +{ +int i =0 ; +int ok =1 ; + +u8 *data_bytes = (u8 *) data; + +if (!dev->checkpt_buffer) +return 0 ; + +if (!dev->checkpt_open_write) +return -1 ; + +while (i < n_bytes && ok) { + dev->checkpt_buffer[dev->checkpt_byte_offs] = *data_bytes; + dev->checkpt_sum += *data_bytes; + dev->checkpt_xor ^= *data_bytes; + + dev->checkpt_byte_offs++; + i++; + data_bytes++; + dev->checkpt_byte_count++; + +if (dev->checkpt_byte_offs <0 || + dev->checkpt_byte_offs >= dev->data_bytes_per_chunk) + ok =yaffs2_checkpt_flush_buffer (dev); + } + +return i; +} + +int yaffs2_checkpt_rd (struct yaffs_dev *dev,void *data,int n_bytes) +{ +int i =0 ; +int ok =1 ; +struct yaffs_ext_tags tags; + +int chunk; +int realigned_chunk; + +u8 *data_bytes = (u8 *) data; + +if (!dev->checkpt_buffer) +return 0 ; + +if (dev->checkpt_open_write) +return -1 ; + +while (i < n_bytes && ok) { + +if (dev->checkpt_byte_offs <0 || + dev->checkpt_byte_offs >= dev->data_bytes_per_chunk) { + +if (dev->checkpt_cur_block <0 ) { +yaffs2_checkpt_find_block (dev); + dev->checkpt_cur_chunk =0 ; + } + +if (dev->checkpt_cur_block <0 ) + ok =0 ; +else { + chunk = dev->checkpt_cur_block * + dev->param.chunks_per_block + + dev->checkpt_cur_chunk; + + realigned_chunk = chunk - dev->chunk_offset; + + dev->n_page_reads++; + +/* read in the next chunk */ + dev->param.read_chunk_tags_fn (dev, + realigned_chunk, + dev-> + checkpt_buffer, + &tags); + +if (tags.chunk_id != (dev->checkpt_page_seq +1 ) + || tags.ecc_result >YAFFS_ECC_RESULT_FIXED + || tags.seq_number != +YAFFS_SEQUENCE_CHECKPOINT_DATA ) + ok =0 ; + + dev->checkpt_byte_offs =0 ; + dev->checkpt_page_seq++; + dev->checkpt_cur_chunk++; + +if (dev->checkpt_cur_chunk >= + dev->param.chunks_per_block) + dev->checkpt_cur_block =-1 ; + } + } + +if (ok) { + *data_bytes = + dev->checkpt_buffer[dev->checkpt_byte_offs]; + dev->checkpt_sum += *data_bytes; + dev->checkpt_xor ^= *data_bytes; + dev->checkpt_byte_offs++; + i++; + data_bytes++; + dev->checkpt_byte_count++; + } + } + +return i; +} + +int yaffs_checkpt_close (struct yaffs_dev *dev) +{ + +if (dev->checkpt_open_write) { +if (dev->checkpt_byte_offs !=0 ) +yaffs2_checkpt_flush_buffer (dev); + }else if (dev->checkpt_block_list) { +int i; +for (i =0 ; + i < dev->blocks_in_checkpt + && dev->checkpt_block_list[i] >=0 ; i++) { +int blk = dev->checkpt_block_list[i]; +struct yaffs_block_info *bi =NULL ; +if (dev->internal_start_block <= blk + && blk <= dev->internal_end_block) + bi =yaffs_get_block_info (dev, blk); +if (bi && bi->block_state ==YAFFS_BLOCK_STATE_EMPTY ) + bi->block_state =YAFFS_BLOCK_STATE_CHECKPOINT ; +else { +/* Todo this looks odd... */ + } + } +YFREE (dev->checkpt_block_list); + dev->checkpt_block_list =NULL ; + } + + dev->n_free_chunks -= + dev->blocks_in_checkpt * dev->param.chunks_per_block; + dev->n_erased_blocks -= dev->blocks_in_checkpt; + +T (YAFFS_TRACE_CHECKPOINT , (TSTR ("checkpoint byte count %d" TENDSTR ), + dev->checkpt_byte_count)); + +if (dev->checkpt_buffer) { +/* free the buffer */ +YFREE (dev->checkpt_buffer); + dev->checkpt_buffer =NULL ; +return 1 ; + }else { +return 0 ; + } +} + +int yaffs2_checkpt_invalidate_stream (struct yaffs_dev *dev) +{ +/* Erase the checkpoint data */ + +T (YAFFS_TRACE_CHECKPOINT , + (TSTR ("checkpoint invalidate of %d blocks" TENDSTR ), + dev->blocks_in_checkpt)); + +return yaffs_checkpt_erase (dev); +}
fs/yaffs2/yaffs_checkptrw.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_CHECKPTRW_H__ +#define __YAFFS_CHECKPTRW_H__ + +#include "yaffs_guts.h" + +int yaffs2_checkpt_open (struct yaffs_dev *dev,int writing); + +int yaffs2_checkpt_wr (struct yaffs_dev *dev,const void *data,int n_bytes); + +int yaffs2_checkpt_rd (struct yaffs_dev *dev,void *data,int n_bytes); + +int yaffs2_get_checkpt_sum (struct yaffs_dev *dev,u32 * sum); + +int yaffs_checkpt_close (struct yaffs_dev *dev); + +int yaffs2_checkpt_invalidate_stream (struct yaffs_dev *dev); + +#endif
fs/yaffs2/yaffs_ecc.c new file +298 -0
298 lines not on this page · raw message
fs/yaffs2/yaffs_ecc.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 2/8] Add yaffs2 file system: checkpoint and ecc code
Quoted 12 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>--- fs/yaffs2/yaffs_checkptrw.c | 420 +++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_checkptrw.h | 33 ++++ fs/yaffs2/yaffs_ecc.c | 298 ++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_ecc.h | 44 +++++ 4 files changed, 795 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_checkptrw.c create mode 100644 fs/yaffs2/yaffs_checkptrw.h create mode 100644 fs/yaffs2/yaffs_ecc.c create mode 100644 fs/yaffs2/yaffs_ecc.h
Just a few small comments below.
[...]
fs/yaffs2/yaffs_checkptrw.c line 202
Quoted 7 lines
fs/yaffs2/yaffs_checkptrw.c new file +7
-0+int yaffs2_get_checkpt_sum (struct yaffs_dev *dev,u32 * sum) +{ +u32 composite_sum; + composite_sum = (dev->checkpt_sum <<8 ) | (dev->checkpt_xor &0xFF ); + *sum = composite_sum; +return 1 ; +}
Why not get rid of the redundant local variable and simply do
*sum = (dev->checkpt_sum << 8) | (dev->checkpt_xor & 0xFF);
??
[...]
fs/yaffs2/yaffs_checkptrw.c line 266
Quoted 6 lines
fs/yaffs2/yaffs_checkptrw.c new file +6
-0+int yaffs2_checkpt_wr (struct yaffs_dev *dev,const void *data,int n_bytes) +{ +int i =0 ; +int ok =1 ; + +u8 *data_bytes = (u8 *) data;
'data' is a 'const void *' and this casts away const. Probably fine, just makes my toes curl.
[...]
fs/yaffs2/yaffs_checkptrw.c line 301
Quoted 10 lines
fs/yaffs2/yaffs_checkptrw.c new file +10
-0+int yaffs2_checkpt_rd (struct yaffs_dev *dev,void *data,int n_bytes) +{ +int i =0 ; +int ok =1 ; +struct yaffs_ext_tags tags; + +int chunk; +int realigned_chunk; + +u8 *data_bytes = (u8 *) data;
here you are not casting away const, but since 'data' is a void pointer the cast is just completely superfluous and should just go away.
[...]
fs/yaffs2/yaffs_checkptrw.c line 321
Quoted 3 lines
fs/yaffs2/yaffs_checkptrw.c new file +3
-0+if (dev->checkpt_cur_block <0 ) + ok =0 ; +else {
Nitpicking, but this should be
if (dev->checkpt_cur_block < 0) {
ok = 0;
} else {
...curly brace on both branches since it's used on one of them (according to CodingStyle).
[...]
Quoted 11 lines
fs/yaffs2/yaffs_checkptrw.c new file +11
-0+int yaffs_checkpt_close (struct yaffs_dev *dev) +{ + +if (dev->checkpt_open_write) { +if (dev->checkpt_byte_offs !=0 ) +yaffs2_checkpt_flush_buffer (dev); + }else if (dev->checkpt_block_list) { +int i; +for (i =0 ; + i < dev->blocks_in_checkpt + && dev->checkpt_block_list[i] >=0 ; i++) {
fs/yaffs2/yaffs_checkptrw.c line 388
Quoted 10 lines
fs/yaffs2/yaffs_checkptrw.c new file +10
-0+int blk = dev->checkpt_block_list[i]; +struct yaffs_block_info *bi =NULL ; +if (dev->internal_start_block <= blk + && blk <= dev->internal_end_block) + bi =yaffs_get_block_info (dev, blk); +if (bi && bi->block_state ==YAFFS_BLOCK_STATE_EMPTY ) + bi->block_state =YAFFS_BLOCK_STATE_CHECKPOINT ; +else { +/* Todo this looks odd... */ + }
1) nitpicking about curly braces again (see above).
2) try grep'ing the source for "todo", "xxx", "fixme" and similar, then check the age of those comments. If things like this are not addressed (by other than a "todo" comment) on initial commit they stand a good chance of never getting addressed...
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
PATCH 3/8 Add yaffs2 file system: guts code
In reply to Charles Manning--- fs/yaffs2/yaffs_guts.c | 5236 ++++++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_guts.h | 915 ++++++++ fs/yaffs2/yaffs_yaffs1.c | 437 ++++ fs/yaffs2/yaffs_yaffs1.h | 22 + fs/yaffs2/yaffs_yaffs2.c | 1620 ++++++++++++++ fs/yaffs2/yaffs_yaffs2.h | 39 + 6 files changed, 8269 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_guts.c create mode 100644 fs/yaffs2/yaffs_guts.h create mode 100644 fs/yaffs2/yaffs_yaffs1.c create mode 100644 fs/yaffs2/yaffs_yaffs1.h create mode 100644 fs/yaffs2/yaffs_yaffs2.c create mode 100644 fs/yaffs2/yaffs_yaffs2.h
fs/yaffs2/yaffs_guts.c new file +5236 -0
@@ -0,0 +1,5236 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yportenv.h" +#include "yaffs_trace.h" + +#include "yaffs_guts.h" +#include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" + +#include "yaffs_tagscompat.h" + +#include "yaffs_nand.h" + +#include "yaffs_yaffs1.h" +#include "yaffs_yaffs2.h" +#include "yaffs_bitmap.h" +#include "yaffs_verify.h" + +#include "yaffs_nand.h" +#include "yaffs_packedtags2.h" + +#include "yaffs_nameval.h" +#include "yaffs_allocator.h" + +#include "yaffs_attribs.h" + +/* Note YAFFS_GC_GOOD_ENOUGH must be <= YAFFS_GC_PASSIVE_THRESHOLD */ +#define YAFFS_GC_GOOD_ENOUGH 2 +#define YAFFS_GC_PASSIVE_THRESHOLD 4 + +#include "yaffs_ecc.h" + +/* Robustification (if it ever comes about...) */ +static void yaffs_retire_block (struct yaffs_dev *dev,int flash_block); +static void yaffs_handle_chunk_wr_error (struct yaffs_dev *dev,int nand_chunk, +int erased_ok); +static void yaffs_handle_chunk_wr_ok (struct yaffs_dev *dev,int nand_chunk, +const u8 * data, +const struct yaffs_ext_tags *tags); +static void yaffs_handle_chunk_update (struct yaffs_dev *dev,int nand_chunk, +const struct yaffs_ext_tags *tags); + +/* Other local prototypes */ +static void yaffs_update_parent (struct yaffs_obj *obj); +static int yaffs_unlink_obj (struct yaffs_obj *obj); +static int yaffs_obj_cache_dirty (struct yaffs_obj *obj); + +static int yaffs_write_new_chunk (struct yaffs_dev *dev, +const u8 * buffer, +struct yaffs_ext_tags *tags,int use_reserver); + +static struct yaffs_obj *yaffs_new_obj (struct yaffs_dev *dev,int number, +enum yaffs_obj_type type); + +static int yaffs_apply_xattrib_mod (struct yaffs_obj *obj,char *buffer, +struct yaffs_xattr_mod *xmod); + +static void yaffs_remove_obj_from_dir (struct yaffs_obj *obj); +static int yaffs_generic_obj_del (struct yaffs_obj *in); + +static int yaffs_check_chunk_erased (struct yaffs_dev *dev,int nand_chunk); + +static int yaffs_unlink_worker (struct yaffs_obj *obj); + +static int yaffs_tags_match (const struct yaffs_ext_tags *tags,int obj_id, +int chunk_obj); + +static int yaffs_alloc_chunk (struct yaffs_dev *dev,int use_reserver, +struct yaffs_block_info **block_ptr); + +static void yaffs_check_obj_details_loaded (struct yaffs_obj *in); + +static void yaffs_invalidate_whole_cache (struct yaffs_obj *in); +static void yaffs_invalidate_chunk_cache (struct yaffs_obj *object, +int chunk_id); + +static int yaffs_find_chunk_in_file (struct yaffs_obj *in,int inode_chunk, +struct yaffs_ext_tags *tags); + +static int yaffs_verify_chunk_written (struct yaffs_dev *dev, +int nand_chunk, +const u8 * data, +struct yaffs_ext_tags *tags); + +static void yaffs_load_name_from_oh (struct yaffs_dev *dev,YCHAR * name, +const YCHAR * oh_name,int buff_size); +static void yaffs_load_oh_from_name (struct yaffs_dev *dev,YCHAR * oh_name, +const YCHAR * name); + +/* Function to calculate chunk and offset */ + +static void yaffs_addr_to_chunk (struct yaffs_dev *dev,loff_t addr, +int *chunk_out,u32 * offset_out) +{ +int chunk; +u32 offset; + + chunk = (u32) (addr >> dev->chunk_shift); + +if (dev->chunk_div ==1 ) { +/* easy power of 2 case */ + offset = (u32) (addr & dev->chunk_mask); + }else { +/* Non power-of-2 case */ + +loff_t chunk_base; + + chunk /= dev->chunk_div; + + chunk_base = ((loff_t ) chunk) * dev->data_bytes_per_chunk; + offset = (u32) (addr - chunk_base); + } + + *chunk_out = chunk; + *offset_out = offset; +} + +/* Function to return the number of shifts for a power of 2 greater than or +* equal to the given number +* Note we don't try to cater for all possible numbers and this does not have to +* be hellishly efficient. +*/ + +static u32 calc_shifts_ceiling (u32 x) +{ +int extra_bits; +int shifts; + + shifts = extra_bits =0 ; + +while (x >1 ) { +if (x &1 ) + extra_bits++; + x >>=1 ; + shifts++; + } + +if (extra_bits) + shifts++; + +return shifts; +} + +/* Function to return the number of shifts to get a 1 in bit 0 +*/ + +static u32 calc_shifts (u32 x) +{ +u32 shifts; + + shifts =0 ; + +if (!x) +return 0 ; + +while (!(x &1 )) { + x >>=1 ; + shifts++; + } + +return shifts; +} + +/* +* Temporary buffer manipulations. +*/ + +static int yaffs_init_tmp_buffers (struct yaffs_dev *dev) +{ +int i; +u8 *buf = (u8 *)1 ; + +memset (dev->temp_buffer,0 ,sizeof (dev->temp_buffer)); + +for (i =0 ; buf && i <YAFFS_N_TEMP_BUFFERS ; i++) { + dev->temp_buffer[i].line =0 ;/* not in use */ + dev->temp_buffer[i].buffer = buf = +YMALLOC_DMA (dev->param.total_bytes_per_chunk); + } + +return buf ?YAFFS_OK :YAFFS_FAIL ; +} + +u8 *yaffs_get_temp_buffer (struct yaffs_dev * dev,int line_no) +{ +int i, j; + + dev->temp_in_use++; +if (dev->temp_in_use > dev->max_temp) + dev->max_temp = dev->temp_in_use; + +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) { +if (dev->temp_buffer[i].line ==0 ) { + dev->temp_buffer[i].line = line_no; +if ((i +1 ) > dev->max_temp) { + dev->max_temp = i +1 ; +for (j =0 ; j <= i; j++) + dev->temp_buffer[j].max_line = + dev->temp_buffer[j].line; + } + +return dev->temp_buffer[i].buffer; + } + } + +T (YAFFS_TRACE_BUFFERS , + (TSTR ("Out of temp buffers at line %d, other held by lines:" ), + line_no)); +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) +T (YAFFS_TRACE_BUFFERS , + (TSTR (" %d " ), dev->temp_buffer[i].line)); + +T (YAFFS_TRACE_BUFFERS , (TSTR (" " TENDSTR ))); + +/* +* If we got here then we have to allocate an unmanaged one +* This is not good. +*/ + + dev->unmanaged_buffer_allocs++; +return YMALLOC (dev->data_bytes_per_chunk); + +} + +void yaffs_release_temp_buffer (struct yaffs_dev *dev,u8 * buffer,int line_no) +{ +int i; + + dev->temp_in_use--; + +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) { +if (dev->temp_buffer[i].buffer == buffer) { + dev->temp_buffer[i].line =0 ; +return ; + } + } + +if (buffer) { +/* assume it is an unmanaged one. */ +T (YAFFS_TRACE_BUFFERS , + (TSTR ("Releasing unmanaged temp buffer in line %d" TENDSTR ), + line_no)); +YFREE (buffer); + dev->unmanaged_buffer_deallocs++; + } + +} + +/* +* Determine if we have a managed buffer. +*/ +int yaffs_is_managed_tmp_buffer (struct yaffs_dev *dev,const u8 * buffer) +{ +int i; + +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) { +if (dev->temp_buffer[i].buffer == buffer) +return 1 ; + } + +for (i =0 ; i < dev->param.n_caches; i++) { +if (dev->cache[i].data == buffer) +return 1 ; + } + +if (buffer == dev->checkpt_buffer) +return 1 ; + +T (YAFFS_TRACE_ALWAYS , + (TSTR ("yaffs: unmaged buffer detected.\n" TENDSTR ))); +return 0 ; +} + +/* +* Verification code +*/ + +/* +* Simple hash function. Needs to have a reasonable spread +*/ + +static Y_INLINE int yaffs_hash_fn(int n) +{ + n =abs (n); +return n %YAFFS_NOBJECT_BUCKETS ; +} + +/* +* Access functions to useful fake objects. +* Note that root might have a presence in NAND if permissions are set. +*/ + +struct yaffs_obj *yaffs_root (struct yaffs_dev *dev) +{ +return dev->root_dir; +} + +struct yaffs_obj *yaffs_lost_n_found (struct yaffs_dev *dev) +{ +return dev->lost_n_found; +} + +/* +* Erased NAND checking functions +*/ + +int yaffs_check_ff (u8 * buffer,int n_bytes) +{ +/* Horrible, slow implementation */ +while (n_bytes--) { +if (*buffer !=0xFF ) +return 0 ; + buffer++; + } +return 1 ; +} + +static int yaffs_check_chunk_erased (struct yaffs_dev *dev,int nand_chunk) +{ +int retval =YAFFS_OK ; +u8 *data =yaffs_get_temp_buffer (dev, __LINE__); +struct yaffs_ext_tags tags; +int result; + + result =yaffs_rd_chunk_tags_nand (dev, nand_chunk, data, &tags); + +if (tags.ecc_result >YAFFS_ECC_RESULT_NO_ERROR ) + retval =YAFFS_FAIL ; + +if (!yaffs_check_ff (data, dev->data_bytes_per_chunk) || tags.chunk_used) { +T (YAFFS_TRACE_NANDACCESS , + (TSTR ("Chunk %d not erased" TENDSTR ), nand_chunk)); + retval =YAFFS_FAIL ; + } + +yaffs_release_temp_buffer (dev, data, __LINE__); + +return retval; + +} + +static int yaffs_verify_chunk_written (struct yaffs_dev *dev, +int nand_chunk, +const u8 * data, +struct yaffs_ext_tags *tags) +{ +int retval =YAFFS_OK ; +struct yaffs_ext_tags temp_tags; +u8 *buffer =yaffs_get_temp_buffer (dev, __LINE__); +int result; + + result =yaffs_rd_chunk_tags_nand (dev, nand_chunk, buffer, &temp_tags); +if (memcmp (buffer, data, dev->data_bytes_per_chunk) || + temp_tags.obj_id != tags->obj_id || + temp_tags.chunk_id != tags->chunk_id || + temp_tags.n_bytes != tags->n_bytes) + retval =YAFFS_FAIL ; + +yaffs_release_temp_buffer (dev, buffer, __LINE__); + +return retval; +} + +static int yaffs_write_new_chunk (struct yaffs_dev *dev, +const u8 * data, +struct yaffs_ext_tags *tags,int use_reserver) +{ +int attempts =0 ; +int write_ok =0 ; +int chunk; + +yaffs2_checkpt_invalidate (dev); + +do { +struct yaffs_block_info *bi =0 ; +int erased_ok =0 ; + + chunk =yaffs_alloc_chunk (dev, use_reserver, &bi); +if (chunk <0 ) { +/* no space */ +break ; + } + +/* First check this chunk is erased, if it needs +* checking. The checking policy (unless forced +* always on) is as follows: +* +* Check the first page we try to write in a block. +* If the check passes then we don't need to check any +* more. If the check fails, we check again... +* If the block has been erased, we don't need to check. +* +* However, if the block has been prioritised for gc, +* then we think there might be something odd about +* this block and stop using it. +* +* Rationale: We should only ever see chunks that have +* not been erased if there was a partially written +* chunk due to power loss. This checking policy should +* catch that case with very few checks and thus save a +* lot of checks that are most likely not needed. +* +* Mods to the above +* If an erase check fails or the write fails we skip the +* rest of the block. +*/ + +/* let's give it a try */ + attempts++; + +if (dev->param.always_check_erased) + bi->skip_erased_check =0 ; + +if (!bi->skip_erased_check) { + erased_ok =yaffs_check_chunk_erased (dev, chunk); +if (erased_ok !=YAFFS_OK ) { +T (YAFFS_TRACE_ERROR , + (TSTR ("**>> yaffs chunk %d was not erased" +TENDSTR ), chunk)); + +/* If not erased, delete this one, +* skip rest of block and +* try another chunk */ +yaffs_chunk_del (dev, chunk,1 , __LINE__); +yaffs_skip_rest_of_block (dev); +continue ; + } + } + + write_ok =yaffs_wr_chunk_tags_nand (dev, chunk, data, tags); + +if (!bi->skip_erased_check) + write_ok = +yaffs_verify_chunk_written (dev, chunk, data, tags); + +if (write_ok !=YAFFS_OK ) { +/* Clean up aborted write, skip to next block and +* try another chunk */ +yaffs_handle_chunk_wr_error (dev, chunk, erased_ok); +continue ; + } + + bi->skip_erased_check =1 ; + +/* Copy the data into the robustification buffer */ +yaffs_handle_chunk_wr_ok (dev, chunk, data, tags); + + }while (write_ok !=YAFFS_OK && + (yaffs_wr_attempts <=0 || attempts <= yaffs_wr_attempts)); + +if (!write_ok) + chunk =-1 ; + +if (attempts >1 ) { +T (YAFFS_TRACE_ERROR , + (TSTR ("**>> yaffs write required %d attempts" TENDSTR ), + attempts)); + + dev->n_retired_writes += (attempts -1 ); + } + +return chunk; +} + +/* +* Block retiring for handling a broken block. +*/ + +static void yaffs_retire_block (struct yaffs_dev *dev,int flash_block) +{ +struct yaffs_block_info *bi =yaffs_get_block_info (dev, flash_block); + +yaffs2_checkpt_invalidate (dev); + +yaffs2_clear_oldest_dirty_seq (dev, bi); + +if (yaffs_mark_bad (dev, flash_block) !=YAFFS_OK ) { +if (yaffs_erase_block (dev, flash_block) !=YAFFS_OK ) { +T (YAFFS_TRACE_ALWAYS , + (TSTR + ("yaffs: Failed to mark bad and erase block %d" +TENDSTR ), flash_block)); + }else { +struct yaffs_ext_tags tags; +int chunk_id = + flash_block * dev->param.chunks_per_block; + +u8 *buffer =yaffs_get_temp_buffer (dev, __LINE__); + +memset (buffer,0xff , dev->data_bytes_per_chunk); +yaffs_init_tags (&tags); + tags.seq_number =YAFFS_SEQUENCE_BAD_BLOCK ; +if (dev->param.write_chunk_tags_fn (dev, chunk_id - + dev->chunk_offset, + buffer, + &tags) !=YAFFS_OK ) +T (YAFFS_TRACE_ALWAYS , + (TSTR + ("yaffs: Failed to " +TCONT ("write bad block marker to block %d" ) + TENDSTR), flash_block)); + +yaffs_release_temp_buffer (dev, buffer, __LINE__); + } + } + + bi->block_state =YAFFS_BLOCK_STATE_DEAD ; + bi->gc_prioritise =0 ; + bi->needs_retiring =0 ; + + dev->n_retired_blocks++; +} + +/* +* Functions for robustisizing TODO +* +*/ + +static void yaffs_handle_chunk_wr_ok (struct yaffs_dev *dev,int nand_chunk, +const u8 * data, +const struct yaffs_ext_tags *tags) +{ + dev = dev; + nand_chunk = nand_chunk; + data = data; + tags = tags; +} + +static void yaffs_handle_chunk_update (struct yaffs_dev *dev,int nand_chunk, +const struct yaffs_ext_tags *tags) +{ + dev = dev; + nand_chunk = nand_chunk; + tags = tags; +} + +void yaffs_handle_chunk_error (struct yaffs_dev *dev, +struct yaffs_block_info *bi) +{ +if (!bi->gc_prioritise) { + bi->gc_prioritise =1 ; + dev->has_pending_prioritised_gc =1 ; + bi->chunk_error_strikes++; + +if (bi->chunk_error_strikes >3 ) { + bi->needs_retiring =1 ;/* Too many stikes, so retire this */ +T (YAFFS_TRACE_ALWAYS , + (TSTR ("yaffs: Block struck out" TENDSTR ))); + + } + } +} + +static void yaffs_handle_chunk_wr_error (struct yaffs_dev *dev,int nand_chunk, +int erased_ok) +{ +int flash_block = nand_chunk / dev->param.chunks_per_block; +struct yaffs_block_info *bi =yaffs_get_block_info (dev, flash_block); + +yaffs_handle_chunk_error (dev, bi); + +if (erased_ok) { +/* Was an actual write failure, so mark the block for retirement */ + bi->needs_retiring =1 ; +T (YAFFS_TRACE_ERROR |YAFFS_TRACE_BAD_BLOCKS , + (TSTR ("**>> Block %d needs retiring" TENDSTR ), flash_block)); + } + +/* Delete the chunk */ +yaffs_chunk_del (dev, nand_chunk,1 , __LINE__); +yaffs_skip_rest_of_block (dev); +} + +/*---------------- Name handling functions ------------*/ + +static u16 yaffs_calc_name_sum (const YCHAR * name) +{ +u16 sum =0 ; +u16 i =1 ; + +const YUCHAR *bname = (const YUCHAR *)name; +if (bname) { +while ((*bname) && (i < (YAFFS_MAX_NAME_LENGTH /2 ))) { + +/* 0x1f mask is case insensitive */ + sum += ((*bname) &0x1f ) * i; + i++; + bname++; + } + } +return sum; +} + +void yaffs_set_obj_name (struct yaffs_obj *obj,const YCHAR * name) +{ +#ifndef CONFIG_YAFFS_NO_SHORT_NAMES +memset (obj->short_name,0 ,sizeof (obj->short_name)); +if (name && +yaffs_strnlen (name,YAFFS_SHORT_NAME_LENGTH +1 ) <= +YAFFS_SHORT_NAME_LENGTH ) +yaffs_strcpy (obj->short_name, name); +else + obj->short_name[0 ] =_Y ('\0' ); +#endif + obj->sum =yaffs_calc_name_sum (name); +} + +void yaffs_set_obj_name_from_oh (struct yaffs_obj *obj, +const struct yaffs_obj_hdr *oh) +{ +#ifdef CONFIG_YAFFS_AUTO_UNICODE +YCHAR tmp_name[YAFFS_MAX_NAME_LENGTH +1 ]; +memset (tmp_name,0 ,sizeof (tmp_name)); +yaffs_load_name_from_oh (obj->my_dev, tmp_name, oh->name, +YAFFS_MAX_NAME_LENGTH +1 ); +yaffs_set_obj_name (obj, tmp_name); +#else +yaffs_set_obj_name (obj, oh->name); +#endif +} + +/*-------------------- TNODES ------------------- + +* List of spare tnodes +* The list is hooked together using the first pointer +* in the tnode. +*/ + +struct yaffs_tnode *yaffs_get_tnode (struct yaffs_dev *dev) +{ +struct yaffs_tnode *tn =yaffs_alloc_raw_tnode (dev); +if (tn) { +memset (tn,0 , dev->tnode_size); + dev->n_tnodes++; + } + + dev->checkpoint_blocks_required =0 ;/* force recalculation */ + +return tn; +} + +/* FreeTnode frees up a tnode and puts it back on the free list */ +static void yaffs_free_tnode (struct yaffs_dev *dev,struct yaffs_tnode *tn) +{ +yaffs_free_raw_tnode (dev, tn); + dev->n_tnodes--; + dev->checkpoint_blocks_required =0 ;/* force recalculation */ +} + +static void yaffs_deinit_tnodes_and_objs (struct yaffs_dev *dev) +{ +yaffs_deinit_raw_tnodes_and_objs (dev); + dev->n_obj =0 ; + dev->n_tnodes =0 ; +} + +void yaffs_load_tnode_0 (struct yaffs_dev *dev,struct yaffs_tnode *tn, +unsigned pos,unsigned val) +{ +u32 *map = (u32 *) tn; +u32 bit_in_map; +u32 bit_in_word; +u32 word_in_map; +u32 mask; + + pos &=YAFFS_TNODES_LEVEL0_MASK ; + val >>= dev->chunk_grp_bits; + + bit_in_map = pos * dev->tnode_width; + word_in_map = bit_in_map /32 ; + bit_in_word = bit_in_map & (32 -1 ); + + mask = dev->tnode_mask << bit_in_word; + + map[word_in_map] &= ~mask; + map[word_in_map] |= (mask & (val << bit_in_word)); + +if (dev->tnode_width > (32 - bit_in_word)) { + bit_in_word = (32 - bit_in_word); + word_in_map++;; + mask = + dev->tnode_mask >> (/*dev->tnode_width - */ bit_in_word); + map[word_in_map] &= ~mask; + map[word_in_map] |= (mask & (val >> bit_in_word)); + } +} + +u32 yaffs_get_group_base (struct yaffs_dev *dev,struct yaffs_tnode *tn, +unsigned pos) +{ +u32 *map = (u32 *) tn; +u32 bit_in_map; +u32 bit_in_word; +u32 word_in_map; +u32 val; + + pos &=YAFFS_TNODES_LEVEL0_MASK ; + + bit_in_map = pos * dev->tnode_width; + word_in_map = bit_in_map /32 ; + bit_in_word = bit_in_map & (32 -1 ); + + val = map[word_in_map] >> bit_in_word; + +if (dev->tnode_width > (32 - bit_in_word)) { + bit_in_word = (32 - bit_in_word); + word_in_map++;; + val |= (map[word_in_map] << bit_in_word); + } + + val &= dev->tnode_mask; + val <<= dev->chunk_grp_bits; + +return val; +} + +/* ------------------- End of individual tnode manipulation -----------------*/ + +/* ---------Functions to manipulate the look-up tree (made up of tnodes) ------ +* The look up tree is represented by the top tnode and the number of top_level +* in the tree. 0 means only the level 0 tnode is in the tree. +*/ + +/* FindLevel0Tnode finds the level 0 tnode, if one exists. */ +struct yaffs_tnode *yaffs_find_tnode_0 (struct yaffs_dev *dev, +struct yaffs_file_var *file_struct, +u32 chunk_id) +{ +struct yaffs_tnode *tn = file_struct->top; +u32 i; +int required_depth; +int level = file_struct->top_level; + + dev = dev; + +/* Check sane level and chunk Id */ +if (level <0 || level >YAFFS_TNODES_MAX_LEVEL ) +return NULL ; + +if (chunk_id >YAFFS_MAX_CHUNK_ID ) +return NULL ; + +/* First check we're tall enough (ie enough top_level) */ + + i = chunk_id >>YAFFS_TNODES_LEVEL0_BITS ; + required_depth =0 ; +while (i) { + i >>=YAFFS_TNODES_INTERNAL_BITS ; + required_depth++; + } + +if (required_depth > file_struct->top_level) +return NULL ;/* Not tall enough, so we can't find it */ + +/* Traverse down to level 0 */ +while (level >0 && tn) { + tn = tn->internal[(chunk_id >> + (YAFFS_TNODES_LEVEL0_BITS + + (level -1 ) * +YAFFS_TNODES_INTERNAL_BITS )) & +YAFFS_TNODES_INTERNAL_MASK ]; + level--; + } + +return tn; +} + +/* AddOrFindLevel0Tnode finds the level 0 tnode if it exists, otherwise first expands the tree. +* This happens in two steps: +* 1. If the tree isn't tall enough, then make it taller. +* 2. Scan down the tree towards the level 0 tnode adding tnodes if required. +* +* Used when modifying the tree. +* +* If the tn argument is NULL, then a fresh tnode will be added otherwise the specified tn will +* be plugged into the ttree. +*/ + +struct yaffs_tnode *yaffs_add_find_tnode_0 (struct yaffs_dev *dev, +struct yaffs_file_var *file_struct, +u32 chunk_id, +struct yaffs_tnode *passed_tn) +{ +int required_depth; +int i; +int l; +struct yaffs_tnode *tn; + +u32 x; + +/* Check sane level and page Id */ +if (file_struct->top_level <0 + || file_struct->top_level >YAFFS_TNODES_MAX_LEVEL ) +return NULL ; + +if (chunk_id >YAFFS_MAX_CHUNK_ID ) +return NULL ; + +/* First check we're tall enough (ie enough top_level) */ + + x = chunk_id >>YAFFS_TNODES_LEVEL0_BITS ; + required_depth =0 ; +while (x) { + x >>=YAFFS_TNODES_INTERNAL_BITS ; + required_depth++; + } + +if (required_depth > file_struct->top_level) { +/* Not tall enough, gotta make the tree taller */ +for (i = file_struct->top_level; i < required_depth; i++) { + + tn =yaffs_get_tnode (dev); + +if (tn) { + tn->internal[0 ] = file_struct->top; + file_struct->top = tn; + file_struct->top_level++; + }else { +T (YAFFS_TRACE_ERROR , + (TSTR ("yaffs: no more tnodes" TENDSTR ))); +return NULL ; + } + } + } + +/* Traverse down to level 0, adding anything we need */ + + l = file_struct->top_level; + tn = file_struct->top; + +if (l >0 ) { +while (l >0 && tn) { + x = (chunk_id >> + (YAFFS_TNODES_LEVEL0_BITS + + (l -1 ) *YAFFS_TNODES_INTERNAL_BITS )) & +YAFFS_TNODES_INTERNAL_MASK ; + +if ((l >1 ) && !tn->internal[x]) { +/* Add missing non-level-zero tnode */ + tn->internal[x] =yaffs_get_tnode (dev); +if (!tn->internal[x]) +return NULL ; + }else if (l ==1 ) { +/* Looking from level 1 at level 0 */ +if (passed_tn) { +/* If we already have one, then release it. */ +if (tn->internal[x]) +yaffs_free_tnode (dev, + tn-> + internal[x]); + tn->internal[x] = passed_tn; + + }else if (!tn->internal[x]) { +/* Don't have one, none passed in */ + tn->internal[x] =yaffs_get_tnode (dev); +if (!tn->internal[x]) +return NULL ; + } + } + + tn = tn->internal[x]; + l--; + } + }else { +/* top is level 0 */ +if (passed_tn) { +memcpy (tn, passed_tn, + (dev->tnode_width *YAFFS_NTNODES_LEVEL0 ) /8 ); +yaffs_free_tnode (dev, passed_tn); + } + } + +return tn; +} + +static int yaffs_find_chunk_in_group (struct yaffs_dev *dev,int the_chunk, +struct yaffs_ext_tags *tags,int obj_id, +int inode_chunk) +{ +int j; + +for (j =0 ; the_chunk && j < dev->chunk_grp_size; j++) { +if (yaffs_check_chunk_bit + (dev, the_chunk / dev->param.chunks_per_block, + the_chunk % dev->param.chunks_per_block)) { + +if (dev->chunk_grp_size ==1 ) +return the_chunk; +else { +yaffs_rd_chunk_tags_nand (dev, the_chunk,NULL , + tags); +if (yaffs_tags_match (tags, obj_id, inode_chunk)) { +/* found it; */ +return the_chunk; + } + } + } + the_chunk++; + } +return -1 ; +} + +static void yaffs_soft_del_chunk (struct yaffs_dev *dev,int chunk) +{ +struct yaffs_block_info *the_block; +unsigned block_no; + +T (YAFFS_TRACE_DELETION , (TSTR ("soft delete chunk %d" TENDSTR ), chunk)); + + block_no = chunk / dev->param.chunks_per_block; + the_block =yaffs_get_block_info (dev, block_no); +if (the_block) { + the_block->soft_del_pages++; + dev->n_free_chunks++; +yaffs2_update_oldest_dirty_seq (dev, block_no, the_block); + } +} + +/* SoftDeleteWorker scans backwards through the tnode tree and soft deletes all the chunks in the file. +* All soft deleting does is increment the block's softdelete count and pulls the chunk out +* of the tnode. +* Thus, essentially this is the same as DeleteWorker except that the chunks are soft deleted. +*/ + +static int yaffs_soft_del_worker (struct yaffs_obj *in,struct yaffs_tnode *tn, +u32 level,int chunk_offset) +{ +int i; +int the_chunk; +int all_done =1 ; +struct yaffs_dev *dev = in->my_dev; + +if (tn) { +if (level >0 ) { + +for (i =YAFFS_NTNODES_INTERNAL -1 ; all_done && i >=0 ; + i--) { +if (tn->internal[i]) { + all_done = +yaffs_soft_del_worker (in, + tn->internal + [i], + level -1 , + (chunk_offset + << +YAFFS_TNODES_INTERNAL_BITS ) + + i); +if (all_done) { +yaffs_free_tnode (dev, + tn->internal + [i]); + tn->internal[i] =NULL ; + }else { +/* Hoosterman... how could this happen? */ + } + } + } +return (all_done) ?1 :0 ; + }else if (level ==0 ) { + +for (i =YAFFS_NTNODES_LEVEL0 -1 ; i >=0 ; i--) { + the_chunk =yaffs_get_group_base (dev, tn, i); +if (the_chunk) { +/* Note this does not find the real chunk, only the chunk group. +* We make an assumption that a chunk group is not larger than +* a block. +*/ +yaffs_soft_del_chunk (dev, the_chunk); +yaffs_load_tnode_0 (dev, tn, i,0 ); + } + + } +return 1 ; + + } + + } + +return 1 ; + +} + +static void yaffs_soft_del_file (struct yaffs_obj *obj) +{ +if (obj->deleted && + obj->variant_type ==YAFFS_OBJECT_TYPE_FILE && !obj->soft_del) { +if (obj->n_data_chunks <=0 ) { +/* Empty file with no duplicate object headers, just delete it immediately */ +yaffs_free_tnode (obj->my_dev, + obj->variant.file_variant.top); + obj->variant.file_variant.top =NULL ; +T (YAFFS_TRACE_TRACING , + (TSTR ("yaffs: Deleting empty file %d" TENDSTR ), + obj->obj_id)); +yaffs_generic_obj_del (obj); + }else { +yaffs_soft_del_worker (obj, + obj->variant.file_variant.top, + obj->variant. + file_variant.top_level,0 ); + obj->soft_del =1 ; + } + } +} + +/* Pruning removes any part of the file structure tree that is beyond the +* bounds of the file (ie that does not point to chunks). +* +* A file should only get pruned when its size is reduced. +* +* Before pruning, the chunks must be pulled from the tree and the +* level 0 tnode entries must be zeroed out. +* Could also use this for file deletion, but that's probably better handled +* by a special case. +* +* This function is recursive. For levels > 0 the function is called again on +* any sub-tree. For level == 0 we just check if the sub-tree has data. +* If there is no data in a subtree then it is pruned. +*/ + +static struct yaffs_tnode *yaffs_prune_worker (struct yaffs_dev *dev, +struct yaffs_tnode *tn,u32 level, +int del0) +{ +int i; +int has_data; + +if (tn) { + has_data =0 ; + +if (level >0 ) { +for (i =0 ; i <YAFFS_NTNODES_INTERNAL ; i++) { +if (tn->internal[i]) { + tn->internal[i] = +yaffs_prune_worker (dev, + tn->internal[i], + level -1 , + (i == +0 ) ? del0 :1 ); + } + +if (tn->internal[i]) + has_data++; + } + }else { +int tnode_size_u32 = dev->tnode_size /sizeof (u32); +u32 *map = (u32 *) tn; + +for (i =0 ; !has_data && i < tnode_size_u32; i++) { +if (map[i]) + has_data++; + } + } + +if (has_data ==0 && del0) { +/* Free and return NULL */ + +yaffs_free_tnode (dev, tn); + tn =NULL ; + } + + } + +return tn; + +} + +static int yaffs_prune_tree (struct yaffs_dev *dev, +struct yaffs_file_var *file_struct) +{ +int i; +int has_data; +int done =0 ; +struct yaffs_tnode *tn; + +if (file_struct->top_level >0 ) { + file_struct->top = +yaffs_prune_worker (dev, file_struct->top, + file_struct->top_level,0 ); + +/* Now we have a tree with all the non-zero branches NULL but the height +* is the same as it was. +* Let's see if we can trim internal tnodes to shorten the tree. +* We can do this if only the 0th element in the tnode is in use +* (ie all the non-zero are NULL) +*/ + +while (file_struct->top_level && !done) { + tn = file_struct->top; + + has_data =0 ; +for (i =1 ; i <YAFFS_NTNODES_INTERNAL ; i++) { +if (tn->internal[i]) + has_data++; + } + +if (!has_data) { + file_struct->top = tn->internal[0 ]; + file_struct->top_level--; +yaffs_free_tnode (dev, tn); + }else { + done =1 ; + } + } + } + +return YAFFS_OK ; +} + +/*-------------------- End of File Structure functions.-------------------*/ + +/* AllocateEmptyObject gets us a clean Object. Tries to make allocate more if we run out */ +static struct yaffs_obj *yaffs_alloc_empty_obj (struct yaffs_dev *dev) +{ +struct yaffs_obj *obj =yaffs_alloc_raw_obj (dev); + +if (obj) { + dev->n_obj++; + +/* Now sweeten it up... */ + +memset (obj,0 ,sizeof (struct yaffs_obj )); + obj->being_created =1 ; + + obj->my_dev = dev; + obj->hdr_chunk =0 ; + obj->variant_type =YAFFS_OBJECT_TYPE_UNKNOWN ; +INIT_LIST_HEAD (&(obj->hard_links)); +INIT_LIST_HEAD (&(obj->hash_link)); +INIT_LIST_HEAD (&obj->siblings); + +/* Now make the directory sane */ +if (dev->root_dir) { + obj->parent = dev->root_dir; +list_add (&(obj->siblings), + &dev->root_dir->variant.dir_variant.children); + } + +/* Add it to the lost and found directory. +* NB Can't put root or lost-n-found in lost-n-found so +* check if lost-n-found exists first +*/ +if (dev->lost_n_found) +yaffs_add_obj_to_dir (dev->lost_n_found, obj); + + obj->being_created =0 ; + } + + dev->checkpoint_blocks_required =0 ;/* force recalculation */ + +return obj; +} + +static struct yaffs_obj *yaffs_create_fake_dir (struct yaffs_dev *dev, +int number,u32 mode) +{ + +struct yaffs_obj *obj = +yaffs_new_obj (dev, number,YAFFS_OBJECT_TYPE_DIRECTORY ); +if (obj) { + obj->fake =1 ;/* it is fake so it might have no NAND presence... */ + obj->rename_allowed =0 ;/* ... and we're not allowed to rename it... */ + obj->unlink_allowed =0 ;/* ... or unlink it */ + obj->deleted =0 ; + obj->unlinked =0 ; + obj->yst_mode = mode; + obj->my_dev = dev; + obj->hdr_chunk =0 ;/* Not a valid chunk. */ + } + +return obj; + +} + +static void yaffs_unhash_obj (struct yaffs_obj *obj) +{ +int bucket; +struct yaffs_dev *dev = obj->my_dev; + +/* If it is still linked into the bucket list, free from the list */ +if (!list_empty (&obj->hash_link)) { +list_del_init (&obj->hash_link); + bucket =yaffs_hash_fn (obj->obj_id); + dev->obj_bucket[bucket].count--; + } +} + +/* FreeObject frees up a Object and puts it back on the free list */ +static void yaffs_free_obj (struct yaffs_obj *obj) +{ +struct yaffs_dev *dev = obj->my_dev; + +T (YAFFS_TRACE_OS , + (TSTR ("FreeObject %p inode %p" TENDSTR ), obj, obj->my_inode)); + +if (!obj) +YBUG (); +if (obj->parent) +YBUG (); +if (!list_empty (&obj->siblings)) +YBUG (); + +if (obj->my_inode) { +/* We're still hooked up to a cached inode. +* Don't delete now, but mark for later deletion +*/ + obj->defered_free =1 ; +return ; + } + +yaffs_unhash_obj (obj); + +yaffs_free_raw_obj (dev, obj); + dev->n_obj--; + dev->checkpoint_blocks_required =0 ;/* force recalculation */ +} + +void yaffs_handle_defered_free (struct yaffs_obj *obj) +{ +if (obj->defered_free) +yaffs_free_obj (obj); +} + +static void yaffs_init_tnodes_and_objs (struct yaffs_dev *dev) +{ +int i; + + dev->n_obj =0 ; + dev->n_tnodes =0 ; + +yaffs_init_raw_tnodes_and_objs (dev); + +for (i =0 ; i <YAFFS_NOBJECT_BUCKETS ; i++) { +INIT_LIST_HEAD (&dev->obj_bucket[i].list); + dev->obj_bucket[i].count =0 ; + } +} + +static int yaffs_find_nice_bucket (struct yaffs_dev *dev) +{ +int i; +int l =999 ; +int lowest =999999 ; + +/* Search for the shortest list or one that +* isn't too long. +*/ + +for (i =0 ; i <10 && lowest >4 ; i++) { + dev->bucket_finder++; + dev->bucket_finder %=YAFFS_NOBJECT_BUCKETS ; +if (dev->obj_bucket[dev->bucket_finder].count < lowest) { + lowest = dev->obj_bucket[dev->bucket_finder].count; + l = dev->bucket_finder; + } + + } + +return l; +} + +static int yaffs_new_obj_id (struct yaffs_dev *dev) +{ +int bucket =yaffs_find_nice_bucket (dev); + +/* Now find an object value that has not already been taken +* by scanning the list. +*/ + +int found =0 ; +struct list_head *i; + +u32 n = (u32 ) bucket; + +/* yaffs_check_obj_hash_sane(); */ + +while (!found) { + found =1 ; + n +=YAFFS_NOBJECT_BUCKETS ; +if (1 || dev->obj_bucket[bucket].count >0 ) { +list_for_each (i, &dev->obj_bucket[bucket].list) { +/* If there is already one in the list */ + if (i && list_entry(i, struct yaffs_obj, + hash_link)->obj_id == n) { + found =0 ; + } + } + } + } + +return n; +} + +static void yaffs_hash_obj (struct yaffs_obj *in) +{ +int bucket =yaffs_hash_fn (in->obj_id); +struct yaffs_dev *dev = in->my_dev; + +list_add (&in->hash_link, &dev->obj_bucket[bucket].list); + dev->obj_bucket[bucket].count++; +} + +struct yaffs_obj *yaffs_find_by_number (struct yaffs_dev *dev,u32 number) +{ +int bucket =yaffs_hash_fn (number); +struct list_head *i; +struct yaffs_obj *in; + +list_for_each (i, &dev->obj_bucket[bucket].list) { +/* Look if it is in the list */ +if (i) { + in = list_entry(i, struct yaffs_obj, hash_link); +if (in->obj_id == number) { + +/* Don't tell the VFS about this one if it is defered free */ +if (in->defered_free) +return NULL ; + +return in; + } + } + } + +return NULL ; +} + +struct yaffs_obj *yaffs_new_obj (struct yaffs_dev *dev,int number, +enum yaffs_obj_type type) +{ +struct yaffs_obj *the_obj =NULL ; +struct yaffs_tnode *tn =NULL ; + +if (number <0 ) + number =yaffs_new_obj_id (dev); + +if (type ==YAFFS_OBJECT_TYPE_FILE ) { + tn =yaffs_get_tnode (dev); +if (!tn) +return NULL ; + } + + the_obj =yaffs_alloc_empty_obj (dev); +if (!the_obj) { +if (tn) +yaffs_free_tnode (dev, tn); +return NULL ; + } + +if (the_obj) { + the_obj->fake =0 ; + the_obj->rename_allowed =1 ; + the_obj->unlink_allowed =1 ; + the_obj->obj_id = number; +yaffs_hash_obj (the_obj); + the_obj->variant_type = type; +yaffs_load_current_time (the_obj,1 ,1 ); + +switch (type) { +case YAFFS_OBJECT_TYPE_FILE : + the_obj->variant.file_variant.file_size =0 ; + the_obj->variant.file_variant.scanned_size =0 ; + the_obj->variant.file_variant.shrink_size = ~0 ;/* max */ + the_obj->variant.file_variant.top_level =0 ; + the_obj->variant.file_variant.top = tn; +break ; +case YAFFS_OBJECT_TYPE_DIRECTORY : +INIT_LIST_HEAD (&the_obj->variant.dir_variant.children); +INIT_LIST_HEAD (&the_obj->variant.dir_variant.dirty); +break ; +case YAFFS_OBJECT_TYPE_SYMLINK : +case YAFFS_OBJECT_TYPE_HARDLINK : +case YAFFS_OBJECT_TYPE_SPECIAL : +/* No action required */ +break ; +case YAFFS_OBJECT_TYPE_UNKNOWN : +/* todo this should not happen */ +break ; + } + } + +return the_obj; +} + +struct yaffs_obj *yaffs_find_or_create_by_number (struct yaffs_dev *dev, +int number, +enum yaffs_obj_type type) +{ +struct yaffs_obj *the_obj =NULL ; + +if (number >0 ) + the_obj =yaffs_find_by_number (dev, number); + +if (!the_obj) + the_obj =yaffs_new_obj (dev, number, type); + +return the_obj; + +} + +YCHAR *yaffs_clone_str (const YCHAR * str) +{ +YCHAR *new_str =NULL ; +int len; + +if (!str) + str =_Y ("" ); + + len =yaffs_strnlen (str,YAFFS_MAX_ALIAS_LENGTH ); + new_str =YMALLOC ((len +1 ) *sizeof (YCHAR )); +if (new_str) { +yaffs_strncpy (new_str, str, len); + new_str[len] =0 ; + } +return new_str; + +} + +/* +* Mknod (create) a new object. +* equiv_obj only has meaning for a hard link; +* alias_str only has meaning for a symlink. +* rdev only has meaning for devices (a subset of special objects) +*/ + +static struct yaffs_obj *yaffs_create_obj (enum yaffs_obj_type type, +struct yaffs_obj *parent, +const YCHAR * name, +u32 mode, +u32 uid, +u32 gid, +struct yaffs_obj *equiv_obj, +const YCHAR * alias_str,u32 rdev) +{ +struct yaffs_obj *in; +YCHAR *str =NULL ; + +struct yaffs_dev *dev = parent->my_dev; + +/* Check if the entry exists. If it does then fail the call since we don't want a dup. */ +if (yaffs_find_by_name (parent, name)) +return NULL ; + +if (type ==YAFFS_OBJECT_TYPE_SYMLINK ) { + str =yaffs_clone_str (alias_str); +if (!str) +return NULL ; + } + + in =yaffs_new_obj (dev,-1 , type); + +if (!in) { +if (str) +YFREE (str); +return NULL ; + } + +if (in) { + in->hdr_chunk =0 ; + in->valid =1 ; + in->variant_type = type; + + in->yst_mode = mode; + +yaffs_attribs_init (in, gid, uid, rdev); + + in->n_data_chunks =0 ; + +yaffs_set_obj_name (in, name); + in->dirty =1 ; + +yaffs_add_obj_to_dir (parent, in); + + in->my_dev = parent->my_dev; + +switch (type) { +case YAFFS_OBJECT_TYPE_SYMLINK : + in->variant.symlink_variant.alias = str; +break ; +case YAFFS_OBJECT_TYPE_HARDLINK : + in->variant.hardlink_variant.equiv_obj = equiv_obj; + in->variant.hardlink_variant.equiv_id = + equiv_obj->obj_id; +list_add (&in->hard_links, &equiv_obj->hard_links); +break ; +case YAFFS_OBJECT_TYPE_FILE : +case YAFFS_OBJECT_TYPE_DIRECTORY : +case YAFFS_OBJECT_TYPE_SPECIAL : +case YAFFS_OBJECT_TYPE_UNKNOWN : +/* do nothing */ +break ; + } + +if (yaffs_update_oh (in, name,0 ,0 ,0 ,NULL ) <0 ) { +/* Could not create the object header, fail the creation */ +yaffs_del_obj (in); + in =NULL ; + } + +yaffs_update_parent (parent); + } + +return in; +} + +struct yaffs_obj *yaffs_create_file (struct yaffs_obj *parent, +const YCHAR * name,u32 mode,u32 uid, +u32 gid) +{ +return yaffs_create_obj (YAFFS_OBJECT_TYPE_FILE , parent, name, mode, + uid, gid,NULL ,NULL ,0 ); +} + +struct yaffs_obj *yaffs_create_dir (struct yaffs_obj *parent,const YCHAR * name, +u32 mode,u32 uid,u32 gid) +{ +return yaffs_create_obj (YAFFS_OBJECT_TYPE_DIRECTORY , parent, name, + mode, uid, gid,NULL ,NULL ,0 ); +} + +struct yaffs_obj *yaffs_create_special (struct yaffs_obj *parent, +const YCHAR * name,u32 mode,u32 uid, +u32 gid,u32 rdev) +{ +return yaffs_create_obj (YAFFS_OBJECT_TYPE_SPECIAL , parent, name, mode, + uid, gid,NULL ,NULL , rdev); +} + +struct yaffs_obj *yaffs_create_symlink (struct yaffs_obj *parent, +const YCHAR * name,u32 mode,u32 uid, +u32 gid,const YCHAR * alias) +{ +return yaffs_create_obj (YAFFS_OBJECT_TYPE_SYMLINK , parent, name, mode, + uid, gid,NULL , alias,0 ); +} + +/* yaffs_link_obj returns the object id of the equivalent object.*/ +struct yaffs_obj *yaffs_link_obj (struct yaffs_obj *parent,const YCHAR * name, +struct yaffs_obj *equiv_obj) +{ +/* Get the real object in case we were fed a hard link as an equivalent object */ + equiv_obj =yaffs_get_equivalent_obj (equiv_obj); + +if (yaffs_create_obj + (YAFFS_OBJECT_TYPE_HARDLINK , parent, name,0 ,0 ,0 , + equiv_obj,NULL ,0 )) { +return equiv_obj; + }else { +return NULL ; + } + +} + +static int yaffs_change_obj_name (struct yaffs_obj *obj, +struct yaffs_obj *new_dir, +const YCHAR * new_name,int force,int shadows) +{ +int unlink_op; +int del_op; + +struct yaffs_obj *existing_target; + +if (new_dir ==NULL ) + new_dir = obj->parent;/* use the old directory */ + +if (new_dir->variant_type !=YAFFS_OBJECT_TYPE_DIRECTORY ) { +T (YAFFS_TRACE_ALWAYS , + (TSTR + ("tragedy: yaffs_change_obj_name: new_dir is not a directory" +TENDSTR ))); +YBUG (); + } + +/* TODO: Do we need this different handling for YAFFS2 and YAFFS1?? */ +if (obj->my_dev->param.is_yaffs2) + unlink_op = (new_dir == obj->my_dev->unlinked_dir); +else + unlink_op = (new_dir == obj->my_dev->unlinked_dir + && obj->variant_type ==YAFFS_OBJECT_TYPE_FILE ); + + del_op = (new_dir == obj->my_dev->del_dir); + + existing_target =yaffs_find_by_name (new_dir, new_name); + +/* If the object is a file going into the unlinked directory, +* then it is OK to just stuff it in since duplicate names are allowed. +* else only proceed if the new name does not exist and if we're putting +* it into a directory. +*/ +if ((unlink_op || + del_op || + force || + (shadows >0 ) || + !existing_target) && + new_dir->variant_type ==YAFFS_OBJECT_TYPE_DIRECTORY ) { +yaffs_set_obj_name (obj, new_name); + obj->dirty =1 ; + +yaffs_add_obj_to_dir (new_dir, obj); + +if (unlink_op) + obj->unlinked =1 ; + +/* If it is a deletion then we mark it as a shrink for gc purposes. */ +if (yaffs_update_oh (obj, new_name,0 , del_op, shadows,NULL ) >= +0 ) +return YAFFS_OK ; + } + +return YAFFS_FAIL ; +} + + +/* Note: +* If old_name is NULL then we take old_dir as the object to be renamed. +*/ +int yaffs_rename_obj (struct yaffs_obj *old_dir,const YCHAR * old_name, +struct yaffs_obj *new_dir,const YCHAR * new_name) +{ +struct yaffs_obj *obj =NULL ; +struct yaffs_obj *existing_target =NULL ; +int force =0 ; +int result; +struct yaffs_dev *dev; + +if (!old_dir || old_dir->variant_type !=YAFFS_OBJECT_TYPE_DIRECTORY ) +YBUG (); +if (!new_dir || new_dir->variant_type !=YAFFS_OBJECT_TYPE_DIRECTORY ) +YBUG (); + + dev = old_dir->my_dev; + +#ifdef CONFIG_YAFFS_CASE_INSENSITIVE +/* Special case for case insemsitive systems. +* While look-up is case insensitive, the name isn't. +* Therefore we might want to change x.txt to X.txt +*/ +if (old_dir == new_dir && + old_name && new_name && +yaffs_strcmp (old_name, new_name) ==0 ) + force =1 ; +#endif + +if (yaffs_strnlen (new_name,YAFFS_MAX_NAME_LENGTH +1 ) > +YAFFS_MAX_NAME_LENGTH ) +/* ENAMETOOLONG */ +return YAFFS_FAIL ; + +if (old_name) + obj =yaffs_find_by_name (old_dir, old_name); +else { + obj = old_dir; + old_dir = obj->parent; + } + + +if (obj && obj->rename_allowed) { + +/* Now do the handling for an existing target, if there is one */ + + existing_target =yaffs_find_by_name (new_dir, new_name); +if (yaffs_is_non_empty_dir (existing_target)){ +return YAFFS_FAIL ;/* ENOTEMPTY */ + }else if (existing_target && existing_target != obj) { +/* Nuke the target first, using shadowing, +* but only if it isn't the same object. +* +* Note we must disable gc otherwise it can mess up the shadowing. +* +*/ + dev->gc_disable =1 ; +yaffs_change_obj_name (obj, new_dir, new_name, force, + existing_target->obj_id); + existing_target->is_shadowed =1 ; +yaffs_unlink_obj (existing_target); + dev->gc_disable =0 ; + } + + result =yaffs_change_obj_name (obj, new_dir, new_name,1 ,0 ); + +yaffs_update_parent (old_dir); +if (new_dir != old_dir) +yaffs_update_parent (new_dir); + +return result; + } +return YAFFS_FAIL ; +} + +/*------------------------- Block Management and Page Allocation ----------------*/ + +static int yaffs_init_blocks (struct yaffs_dev *dev) +{ +int n_blocks = dev->internal_end_block - dev->internal_start_block +1 ; + + dev->block_info =NULL ; + dev->chunk_bits =NULL ; + + dev->alloc_block =-1 ;/* force it to get a new one */ + +/* If the first allocation strategy fails, thry the alternate one */ + dev->block_info =YMALLOC (n_blocks *sizeof (struct yaffs_block_info )); +if (!dev->block_info) { + dev->block_info = +YMALLOC_ALT (n_blocks *sizeof (struct yaffs_block_info )); + dev->block_info_alt =1 ; + }else { + dev->block_info_alt =0 ; + } + +if (dev->block_info) { +/* Set up dynamic blockinfo stuff. */ + dev->chunk_bit_stride = (dev->param.chunks_per_block +7 ) /8 ;/* round up bytes */ + dev->chunk_bits =YMALLOC (dev->chunk_bit_stride * n_blocks); +if (!dev->chunk_bits) { + dev->chunk_bits = +YMALLOC_ALT (dev->chunk_bit_stride * n_blocks); + dev->chunk_bits_alt =1 ; + }else { + dev->chunk_bits_alt =0 ; + } + } + +if (dev->block_info && dev->chunk_bits) { +memset (dev->block_info,0 , + n_blocks *sizeof (struct yaffs_block_info )); +memset (dev->chunk_bits,0 , dev->chunk_bit_stride * n_blocks); +return YAFFS_OK ; + } + +return YAFFS_FAIL ; +} + +static void yaffs_deinit_blocks (struct yaffs_dev *dev) +{ +if (dev->block_info_alt && dev->block_info) +YFREE_ALT (dev->block_info); +else if (dev->block_info) +YFREE (dev->block_info); + + dev->block_info_alt =0 ; + + dev->block_info =NULL ; + +if (dev->chunk_bits_alt && dev->chunk_bits) +YFREE_ALT (dev->chunk_bits); +else if (dev->chunk_bits) +YFREE (dev->chunk_bits); + dev->chunk_bits_alt =0 ; + dev->chunk_bits =NULL ; +} + +void yaffs_block_became_dirty (struct yaffs_dev *dev,int block_no) +{ +struct yaffs_block_info *bi =yaffs_get_block_info (dev, block_no); + +int erased_ok =0 ; + +/* If the block is still healthy erase it and mark as clean. +* If the block has had a data failure, then retire it. +*/ + +T (YAFFS_TRACE_GC |YAFFS_TRACE_ERASE , + (TSTR ("yaffs_block_became_dirty block %d state %d %s" TENDSTR ), + block_no, bi->block_state, + (bi->needs_retiring) ?"needs retiring" :"" )); + +yaffs2_clear_oldest_dirty_seq (dev, bi); + + bi->block_state =YAFFS_BLOCK_STATE_DIRTY ; + +/* If this is the block being garbage collected then stop gc'ing this block */ +if (block_no == dev->gc_block) + dev->gc_block =0 ; + +/* If this block is currently the best candidate for gc then drop as a candidate */ +if (block_no == dev->gc_dirtiest) { + dev->gc_dirtiest =0 ; + dev->gc_pages_in_use =0 ; + } + +if (!bi->needs_retiring) { +yaffs2_checkpt_invalidate (dev); + erased_ok =yaffs_erase_block (dev, block_no); +if (!erased_ok) { + dev->n_erase_failures++; +T (YAFFS_TRACE_ERROR |YAFFS_TRACE_BAD_BLOCKS , + (TSTR ("**>> Erasure failed %d" TENDSTR ), block_no)); + } + } + +if (erased_ok && + ((yaffs_trace_mask &YAFFS_TRACE_ERASE ) + || !yaffs_skip_verification (dev))) { +int i; +for (i =0 ; i < dev->param.chunks_per_block; i++) { +if (!yaffs_check_chunk_erased + (dev, block_no * dev->param.chunks_per_block + i)) { +T (YAFFS_TRACE_ERROR , + (TSTR + (">>Block %d erasure supposedly OK, but chunk %d not erased" +TENDSTR ), block_no, i)); + } + } + } + +if (erased_ok) { +/* Clean it up... */ + bi->block_state =YAFFS_BLOCK_STATE_EMPTY ; + bi->seq_number =0 ; + dev->n_erased_blocks++; + bi->pages_in_use =0 ; + bi->soft_del_pages =0 ; + bi->has_shrink_hdr =0 ; + bi->skip_erased_check =1 ;/* This is clean, so no need to check */ + bi->gc_prioritise =0 ; +yaffs_clear_chunk_bits (dev, block_no); + +T (YAFFS_TRACE_ERASE , + (TSTR ("Erased block %d" TENDSTR ), block_no)); + }else { + dev->n_free_chunks -= dev->param.chunks_per_block;/* We lost a block of free space */ + +yaffs_retire_block (dev, block_no); +T (YAFFS_TRACE_ERROR |YAFFS_TRACE_BAD_BLOCKS , + (TSTR ("**>> Block %d retired" TENDSTR ), block_no)); + } +} + +static int yaffs_find_alloc_block (struct yaffs_dev *dev) +{ +int i; + +struct yaffs_block_info *bi; + +if (dev->n_erased_blocks <1 ) { +/* Hoosterman we've got a problem. +* Can't get space to gc +*/ +T (YAFFS_TRACE_ERROR , + (TSTR ("yaffs tragedy: no more erased blocks" TENDSTR ))); + +return -1 ; + } + +/* Find an empty block. */ + +for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) { + dev->alloc_block_finder++; +if (dev->alloc_block_finder < dev->internal_start_block + || dev->alloc_block_finder > dev->internal_end_block) { + dev->alloc_block_finder = dev->internal_start_block; + } + + bi =yaffs_get_block_info (dev, dev->alloc_block_finder); + +if (bi->block_state ==YAFFS_BLOCK_STATE_EMPTY ) { + bi->block_state =YAFFS_BLOCK_STATE_ALLOCATING ; + dev->seq_number++; + bi->seq_number = dev->seq_number; + dev->n_erased_blocks--; +T (YAFFS_TRACE_ALLOCATE , + (TSTR ("Allocated block %d, seq %d, %d left" TENDSTR ), + dev->alloc_block_finder, dev->seq_number, + dev->n_erased_blocks)); +return dev->alloc_block_finder; + } + } + +T (YAFFS_TRACE_ALWAYS , + (TSTR + ("yaffs tragedy: no more erased blocks, but there should have been %d" +TENDSTR ), dev->n_erased_blocks)); + +return -1 ; +} + +/* +* Check if there's space to allocate... +* Thinks.... do we need top make this ths same as yaffs_get_free_chunks()? +*/ +int yaffs_check_alloc_available (struct yaffs_dev *dev,int n_chunks) +{ +int reserved_chunks; +int reserved_blocks = dev->param.n_reserved_blocks; +int checkpt_blocks; + + checkpt_blocks =yaffs_calc_checkpt_blocks_required (dev); + + reserved_chunks = + ((reserved_blocks + checkpt_blocks) * dev->param.chunks_per_block); + +return (dev->n_free_chunks > (reserved_chunks + n_chunks)); +} + +static int yaffs_alloc_chunk (struct yaffs_dev *dev,int use_reserver, +struct yaffs_block_info **block_ptr) +{ +int ret_val; +struct yaffs_block_info *bi; + +if (dev->alloc_block <0 ) { +/* Get next block to allocate off */ + dev->alloc_block =yaffs_find_alloc_block (dev); + dev->alloc_page =0 ; + } + +if (!use_reserver && !yaffs_check_alloc_available (dev,1 )) { +/* Not enough space to allocate unless we're allowed to use the reserve. */ +return -1 ; + } + +if (dev->n_erased_blocks < dev->param.n_reserved_blocks + && dev->alloc_page ==0 ) { +T (YAFFS_TRACE_ALLOCATE , (TSTR ("Allocating reserve" TENDSTR ))); + } + +/* Next page please.... */ +if (dev->alloc_block >=0 ) { + bi =yaffs_get_block_info (dev, dev->alloc_block); + + ret_val = (dev->alloc_block * dev->param.chunks_per_block) + + dev->alloc_page; + bi->pages_in_use++; +yaffs_set_chunk_bit (dev, dev->alloc_block, dev->alloc_page); + + dev->alloc_page++; + + dev->n_free_chunks--; + +/* If the block is full set the state to full */ +if (dev->alloc_page >= dev->param.chunks_per_block) { + bi->block_state =YAFFS_BLOCK_STATE_FULL ; + dev->alloc_block =-1 ; + } + +if (block_ptr) + *block_ptr = bi; + +return ret_val; + } + +T (YAFFS_TRACE_ERROR , + (TSTR ("!!!!!!!!! Allocator out !!!!!!!!!!!!!!!!!" TENDSTR ))); + +return -1 ; +} + +static int yaffs_get_erased_chunks (struct yaffs_dev *dev) +{ +int n; + + n = dev->n_erased_blocks * dev->param.chunks_per_block; + +if (dev->alloc_block >0 ) + n += (dev->param.chunks_per_block - dev->alloc_page); + +return n; + +} + +/* +* yaffs_skip_rest_of_block() skips over the rest of the allocation block +* if we don't want to write to it. +*/ +void yaffs_skip_rest_of_block (struct yaffs_dev *dev) +{ +if (dev->alloc_block >0 ) { +struct yaffs_block_info *bi = +yaffs_get_block_info (dev, dev->alloc_block); +if (bi->block_state ==YAFFS_BLOCK_STATE_ALLOCATING ) { + bi->block_state =YAFFS_BLOCK_STATE_FULL ; + dev->alloc_block =-1 ; + } + } +} + +static int yaffs_gc_block (struct yaffs_dev *dev,int block,int whole_block) +{ +int old_chunk; +int new_chunk; +int mark_flash; +int ret_val =YAFFS_OK ; +int i; +int is_checkpt_block; +int matching_chunk; +int max_copies; + +int chunks_before =yaffs_get_erased_chunks (dev); +int chunks_after; + +struct yaffs_ext_tags tags; + +struct yaffs_block_info *bi =yaffs_get_block_info (dev, block); + +struct yaffs_obj *object; + + is_checkpt_block = (bi->block_state ==YAFFS_BLOCK_STATE_CHECKPOINT ); + +T (YAFFS_TRACE_TRACING , + (TSTR + ("Collecting block %d, in use %d, shrink %d, whole_block %d" +TENDSTR ), block, bi->pages_in_use, bi->has_shrink_hdr, + whole_block)); + +/*yaffs_verify_free_chunks(dev); */ + +if (bi->block_state ==YAFFS_BLOCK_STATE_FULL ) + bi->block_state =YAFFS_BLOCK_STATE_COLLECTING ; + + bi->has_shrink_hdr =0 ;/* clear the flag so that the block can erase */ + + dev->gc_disable =1 ; + +if (is_checkpt_block || !yaffs_still_some_chunks (dev, block)) { +T (YAFFS_TRACE_TRACING , + (TSTR + ("Collecting block %d that has no chunks in use" TENDSTR ), + block)); +yaffs_block_became_dirty (dev, block); + }else { + +u8 *buffer =yaffs_get_temp_buffer (dev, __LINE__); + +yaffs_verify_blk (dev, bi, block); + + max_copies = (whole_block) ? dev->param.chunks_per_block :5 ; + old_chunk = block * dev->param.chunks_per_block + dev->gc_chunk; + +for (/* init already done */ ; + ret_val ==YAFFS_OK && + dev->gc_chunk < dev->param.chunks_per_block && + (bi->block_state ==YAFFS_BLOCK_STATE_COLLECTING ) && + max_copies >0 ; dev->gc_chunk++, old_chunk++) { +if (yaffs_check_chunk_bit (dev, block, dev->gc_chunk)) { + +/* This page is in use and might need to be copied off */ + + max_copies--; + + mark_flash =1 ; + +yaffs_init_tags (&tags); + +yaffs_rd_chunk_tags_nand (dev, old_chunk, + buffer, &tags); + + object =yaffs_find_by_number (dev, tags.obj_id); + +T (YAFFS_TRACE_GC_DETAIL , + (TSTR + ("Collecting chunk in block %d, %d %d %d " +TENDSTR ), dev->gc_chunk, tags.obj_id, + tags.chunk_id, tags.n_bytes)); + +if (object && !yaffs_skip_verification (dev)) { +if (tags.chunk_id ==0 ) + matching_chunk = + object->hdr_chunk; +else if (object->soft_del) + matching_chunk = old_chunk;/* Defeat the test */ +else + matching_chunk = +yaffs_find_chunk_in_file + (object, tags.chunk_id, +NULL ); + +if (old_chunk != matching_chunk) +T (YAFFS_TRACE_ERROR , + (TSTR + ("gc: page in gc mismatch: %d %d %d %d" +TENDSTR ), old_chunk, + matching_chunk, tags.obj_id, + tags.chunk_id)); + + } + +if (!object) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("page %d in gc has no object: %d %d %d " +TENDSTR ), old_chunk, + tags.obj_id, tags.chunk_id, + tags.n_bytes)); + } + +if (object && + object->deleted && + object->soft_del && tags.chunk_id !=0 ) { +/* Data chunk in a soft deleted file, throw it away +* It's a soft deleted data chunk, +* No need to copy this, just forget about it and +* fix up the object. +*/ + +/* Free chunks already includes softdeleted chunks. +* How ever this chunk is going to soon be really deleted +* which will increment free chunks. +* We have to decrement free chunks so this works out properly. +*/ + dev->n_free_chunks--; + bi->soft_del_pages--; + + object->n_data_chunks--; + +if (object->n_data_chunks <=0 ) { +/* remeber to clean up the object */ + dev->gc_cleanup_list[dev-> + n_clean_ups] + = tags.obj_id; + dev->n_clean_ups++; + } + mark_flash =0 ; + }else if (0 ) { +/* Todo object && object->deleted && object->n_data_chunks == 0 */ +/* Deleted object header with no data chunks. +* Can be discarded and the file deleted. +*/ + object->hdr_chunk =0 ; +yaffs_free_tnode (object->my_dev, + object-> + variant.file_variant. + top); + object->variant.file_variant.top =NULL ; +yaffs_generic_obj_del (object); + + }else if (object) { +/* It's either a data chunk in a live file or +* an ObjectHeader, so we're interested in it. +* NB Need to keep the ObjectHeaders of deleted files +* until the whole file has been deleted off +*/ + tags.serial_number++; + + dev->n_gc_copies++; + +if (tags.chunk_id ==0 ) { +/* It is an object Id, +* We need to nuke the shrinkheader flags first +* Also need to clean up shadowing. +* We no longer want the shrink_header flag since its work is done +* and if it is left in place it will mess up scanning. +*/ + +struct yaffs_obj_hdr *oh; + oh = (struct yaffs_obj_hdr *) + buffer; + + oh->is_shrink =0 ; + tags.extra_is_shrink =0 ; + + oh->shadows_obj =0 ; + oh->inband_shadowed_obj_id =0 ; + tags.extra_shadows =0 ; + +/* Update file size */ +if (object->variant_type == +YAFFS_OBJECT_TYPE_FILE ) { + oh->file_size = + object->variant. + file_variant. + file_size; + tags.extra_length = + oh->file_size; + } + +yaffs_verify_oh (object, oh, + &tags,1 ); + new_chunk = +yaffs_write_new_chunk (dev, + (u8 *) + oh, + &tags, +1 ); + }else { + new_chunk = +yaffs_write_new_chunk (dev, + buffer, + &tags, +1 ); + } + +if (new_chunk <0 ) { + ret_val =YAFFS_FAIL ; + }else { + +/* Ok, now fix up the Tnodes etc. */ + +if (tags.chunk_id ==0 ) { +/* It's a header */ + object->hdr_chunk = + new_chunk; + object->serial = + tags.serial_number; + }else { +/* It's a data chunk */ +int ok; + ok =yaffs_put_chunk_in_file (object, tags.chunk_id, new_chunk,0 ); + } + } + } + +if (ret_val ==YAFFS_OK ) +yaffs_chunk_del (dev, old_chunk, + mark_flash, __LINE__); + + } + } + +yaffs_release_temp_buffer (dev, buffer, __LINE__); + + } + +yaffs_verify_collected_blk (dev, bi, block); + +if (bi->block_state ==YAFFS_BLOCK_STATE_COLLECTING ) { +/* +* The gc did not complete. Set block state back to FULL +* because checkpointing does not restore gc. +*/ + bi->block_state =YAFFS_BLOCK_STATE_FULL ; + }else { +/* The gc completed. */ +/* Do any required cleanups */ +for (i =0 ; i < dev->n_clean_ups; i++) { +/* Time to delete the file too */ + object = +yaffs_find_by_number (dev, dev->gc_cleanup_list[i]); +if (object) { +yaffs_free_tnode (dev, + object->variant. + file_variant.top); + object->variant.file_variant.top =NULL ; +T (YAFFS_TRACE_GC , + (TSTR + ("yaffs: About to finally delete object %d" +TENDSTR ), object->obj_id)); +yaffs_generic_obj_del (object); + object->my_dev->n_deleted_files--; + } + + } + + chunks_after =yaffs_get_erased_chunks (dev); +if (chunks_before >= chunks_after) { +T (YAFFS_TRACE_GC , + (TSTR + ("gc did not increase free chunks before %d after %d" +TENDSTR ), chunks_before, chunks_after)); + } + dev->gc_block =0 ; + dev->gc_chunk =0 ; + dev->n_clean_ups =0 ; + } + + dev->gc_disable =0 ; + +return ret_val; +} + +/* +* FindBlockForgarbageCollection is used to select the dirtiest block (or close enough) +* for garbage collection. +*/ + +static unsigned yaffs_find_gc_block (struct yaffs_dev *dev, +int aggressive,int background) +{ +int i; +int iterations; +unsigned selected =0 ; +int prioritised =0 ; +int prioritised_exist =0 ; +struct yaffs_block_info *bi; +int threshold; + +/* First let's see if we need to grab a prioritised block */ +if (dev->has_pending_prioritised_gc && !aggressive) { + dev->gc_dirtiest =0 ; + bi = dev->block_info; +for (i = dev->internal_start_block; + i <= dev->internal_end_block && !selected; i++) { + +if (bi->gc_prioritise) { + prioritised_exist =1 ; +if (bi->block_state ==YAFFS_BLOCK_STATE_FULL && +yaffs_block_ok_for_gc (dev, bi)) { + selected = i; + prioritised =1 ; + } + } + bi++; + } + +/* +* If there is a prioritised block and none was selected then +* this happened because there is at least one old dirty block gumming +* up the works. Let's gc the oldest dirty block. +*/ + +if (prioritised_exist && + !selected && dev->oldest_dirty_block >0 ) + selected = dev->oldest_dirty_block; + +if (!prioritised_exist)/* None found, so we can clear this */ + dev->has_pending_prioritised_gc =0 ; + } + +/* If we're doing aggressive GC then we are happy to take a less-dirty block, and +* search harder. +* else (we're doing a leasurely gc), then we only bother to do this if the +* block has only a few pages in use. +*/ + +if (!selected) { +int pages_used; +int n_blocks = + dev->internal_end_block - dev->internal_start_block +1 ; +if (aggressive) { + threshold = dev->param.chunks_per_block; + iterations = n_blocks; + }else { +int max_threshold; + +if (background) + max_threshold = dev->param.chunks_per_block /2 ; +else + max_threshold = dev->param.chunks_per_block /8 ; + +if (max_threshold <YAFFS_GC_PASSIVE_THRESHOLD ) + max_threshold =YAFFS_GC_PASSIVE_THRESHOLD ; + + threshold = background ? (dev->gc_not_done +2 ) *2 :0 ; +if (threshold <YAFFS_GC_PASSIVE_THRESHOLD ) + threshold =YAFFS_GC_PASSIVE_THRESHOLD ; +if (threshold > max_threshold) + threshold = max_threshold; + + iterations = n_blocks /16 +1 ; +if (iterations >100 ) + iterations =100 ; + } + +for (i =0 ; + i < iterations && + (dev->gc_dirtiest <1 || + dev->gc_pages_in_use >YAFFS_GC_GOOD_ENOUGH ); i++) { + dev->gc_block_finder++; +if (dev->gc_block_finder < dev->internal_start_block || + dev->gc_block_finder > dev->internal_end_block) + dev->gc_block_finder = + dev->internal_start_block; + + bi =yaffs_get_block_info (dev, dev->gc_block_finder); + + pages_used = bi->pages_in_use - bi->soft_del_pages; + +if (bi->block_state ==YAFFS_BLOCK_STATE_FULL && + pages_used < dev->param.chunks_per_block && + (dev->gc_dirtiest <1 + || pages_used < dev->gc_pages_in_use) + &&yaffs_block_ok_for_gc (dev, bi)) { + dev->gc_dirtiest = dev->gc_block_finder; + dev->gc_pages_in_use = pages_used; + } + } + +if (dev->gc_dirtiest >0 && dev->gc_pages_in_use <= threshold) + selected = dev->gc_dirtiest; + } + +/* +* If nothing has been selected for a while, try selecting the oldest dirty +* because that's gumming up the works. +*/ + +if (!selected && dev->param.is_yaffs2 && + dev->gc_not_done >= (background ?10 :20 )) { +yaffs2_find_oldest_dirty_seq (dev); +if (dev->oldest_dirty_block >0 ) { + selected = dev->oldest_dirty_block; + dev->gc_dirtiest = selected; + dev->oldest_dirty_gc_count++; + bi =yaffs_get_block_info (dev, selected); + dev->gc_pages_in_use = + bi->pages_in_use - bi->soft_del_pages; + }else { + dev->gc_not_done =0 ; + } + } + +if (selected) { +T (YAFFS_TRACE_GC , + (TSTR + ("GC Selected block %d with %d free, prioritised:%d" +TENDSTR ), selected, + dev->param.chunks_per_block - dev->gc_pages_in_use, + prioritised)); + + dev->n_gc_blocks++; +if (background) + dev->bg_gcs++; + + dev->gc_dirtiest =0 ; + dev->gc_pages_in_use =0 ; + dev->gc_not_done =0 ; +if (dev->refresh_skip >0 ) + dev->refresh_skip--; + }else { + dev->gc_not_done++; +T (YAFFS_TRACE_GC , + (TSTR + ("GC none: finder %d skip %d threshold %d dirtiest %d using %d oldest %d%s" +TENDSTR ), dev->gc_block_finder, dev->gc_not_done, threshold, + dev->gc_dirtiest, dev->gc_pages_in_use, + dev->oldest_dirty_block, background ?" bg" :"" )); + } + +return selected; +} + +/* New garbage collector +* If we're very low on erased blocks then we do aggressive garbage collection +* otherwise we do "leasurely" garbage collection. +* Aggressive gc looks further (whole array) and will accept less dirty blocks. +* Passive gc only inspects smaller areas and will only accept more dirty blocks. +* +* The idea is to help clear out space in a more spread-out manner. +* Dunno if it really does anything useful. +*/ +static int yaffs_check_gc (struct yaffs_dev *dev,int background) +{ +int aggressive =0 ; +int gc_ok =YAFFS_OK ; +int max_tries =0 ; +int min_erased; +int erased_chunks; +int checkpt_block_adjust; + +if (dev->param.gc_control && (dev->param.gc_control (dev) &1 ) ==0 ) +return YAFFS_OK ; + +if (dev->gc_disable) { +/* Bail out so we don't get recursive gc */ +return YAFFS_OK ; + } + +/* This loop should pass the first time. +* We'll only see looping here if the collection does not increase space. +*/ + +do { + max_tries++; + + checkpt_block_adjust =yaffs_calc_checkpt_blocks_required (dev); + + min_erased = + dev->param.n_reserved_blocks + checkpt_block_adjust +1 ; + erased_chunks = + dev->n_erased_blocks * dev->param.chunks_per_block; + +/* If we need a block soon then do aggressive gc. */ +if (dev->n_erased_blocks < min_erased) + aggressive =1 ; +else { +if (!background + && erased_chunks > (dev->n_free_chunks /4 )) +break ; + +if (dev->gc_skip >20 ) + dev->gc_skip =20 ; +if (erased_chunks < dev->n_free_chunks /2 || + dev->gc_skip <1 || background) + aggressive =0 ; +else { + dev->gc_skip--; +break ; + } + } + + dev->gc_skip =5 ; + +/* If we don't already have a block being gc'd then see if we should start another */ + +if (dev->gc_block <1 && !aggressive) { + dev->gc_block =yaffs2_find_refresh_block (dev); + dev->gc_chunk =0 ; + dev->n_clean_ups =0 ; + } +if (dev->gc_block <1 ) { + dev->gc_block = +yaffs_find_gc_block (dev, aggressive, background); + dev->gc_chunk =0 ; + dev->n_clean_ups =0 ; + } + +if (dev->gc_block >0 ) { + dev->all_gcs++; +if (!aggressive) + dev->passive_gc_count++; + +T (YAFFS_TRACE_GC , + (TSTR + ("yaffs: GC n_erased_blocks %d aggressive %d" +TENDSTR ), dev->n_erased_blocks, aggressive)); + + gc_ok =yaffs_gc_block (dev, dev->gc_block, aggressive); + } + +if (dev->n_erased_blocks < (dev->param.n_reserved_blocks) + && dev->gc_block >0 ) { +T (YAFFS_TRACE_GC , + (TSTR + ("yaffs: GC !!!no reclaim!!! n_erased_blocks %d after try %d block %d" +TENDSTR ), dev->n_erased_blocks, max_tries, + dev->gc_block)); + } + }while ((dev->n_erased_blocks < dev->param.n_reserved_blocks) && + (dev->gc_block >0 ) && (max_tries <2 )); + +return aggressive ? gc_ok :YAFFS_OK ; +} + +/* +* yaffs_bg_gc() +* Garbage collects. Intended to be called from a background thread. +* Returns non-zero if at least half the free chunks are erased. +*/ +int yaffs_bg_gc (struct yaffs_dev *dev,unsigned urgency) +{ +int erased_chunks = dev->n_erased_blocks * dev->param.chunks_per_block; + +T (YAFFS_TRACE_BACKGROUND , (TSTR ("Background gc %u" TENDSTR ), urgency)); + +yaffs_check_gc (dev,1 ); +return erased_chunks > dev->n_free_chunks /2 ; +} + +/*------------------------- TAGS --------------------------------*/ + +static int yaffs_tags_match (const struct yaffs_ext_tags *tags,int obj_id, +int chunk_obj) +{ +return (tags->chunk_id == chunk_obj && + tags->obj_id == obj_id && !tags->is_deleted) ?1 :0 ; + +} + +/*-------------------- Data file manipulation -----------------*/ + +static int yaffs_find_chunk_in_file (struct yaffs_obj *in,int inode_chunk, +struct yaffs_ext_tags *tags) +{ +/*Get the Tnode, then get the level 0 offset chunk offset */ +struct yaffs_tnode *tn; +int the_chunk =-1 ; +struct yaffs_ext_tags local_tags; +int ret_val =-1 ; + +struct yaffs_dev *dev = in->my_dev; + +if (!tags) { +/* Passed a NULL, so use our own tags space */ + tags = &local_tags; + } + + tn =yaffs_find_tnode_0 (dev, &in->variant.file_variant, inode_chunk); + +if (tn) { + the_chunk =yaffs_get_group_base (dev, tn, inode_chunk); + + ret_val = +yaffs_find_chunk_in_group (dev, the_chunk, tags, in->obj_id, + inode_chunk); + } +return ret_val; +} + +static int yaffs_find_del_file_chunk (struct yaffs_obj *in,int inode_chunk, +struct yaffs_ext_tags *tags) +{ +/* Get the Tnode, then get the level 0 offset chunk offset */ +struct yaffs_tnode *tn; +int the_chunk =-1 ; +struct yaffs_ext_tags local_tags; + +struct yaffs_dev *dev = in->my_dev; +int ret_val =-1 ; + +if (!tags) { +/* Passed a NULL, so use our own tags space */ + tags = &local_tags; + } + + tn =yaffs_find_tnode_0 (dev, &in->variant.file_variant, inode_chunk); + +if (tn) { + + the_chunk =yaffs_get_group_base (dev, tn, inode_chunk); + + ret_val = +yaffs_find_chunk_in_group (dev, the_chunk, tags, in->obj_id, + inode_chunk); + +/* Delete the entry in the filestructure (if found) */ +if (ret_val !=-1 ) +yaffs_load_tnode_0 (dev, tn, inode_chunk,0 ); + } + +return ret_val; +} + +int yaffs_put_chunk_in_file (struct yaffs_obj *in,int inode_chunk, +int nand_chunk,int in_scan) +{ +/* NB in_scan is zero unless scanning. +* For forward scanning, in_scan is > 0; +* for backward scanning in_scan is < 0 +* +* nand_chunk = 0 is a dummy insert to make sure the tnodes are there. +*/ + +struct yaffs_tnode *tn; +struct yaffs_dev *dev = in->my_dev; +int existing_cunk; +struct yaffs_ext_tags existing_tags; +struct yaffs_ext_tags new_tags; +unsigned existing_serial, new_serial; + +if (in->variant_type !=YAFFS_OBJECT_TYPE_FILE ) { +/* Just ignore an attempt at putting a chunk into a non-file during scanning +* If it is not during Scanning then something went wrong! +*/ +if (!in_scan) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("yaffs tragedy:attempt to put data chunk into a non-file" +TENDSTR ))); +YBUG (); + } + +yaffs_chunk_del (dev, nand_chunk,1 , __LINE__); +return YAFFS_OK ; + } + + tn =yaffs_add_find_tnode_0 (dev, + &in->variant.file_variant, + inode_chunk,NULL ); +if (!tn) +return YAFFS_FAIL ; + +if (!nand_chunk) +/* Dummy insert, bail now */ +return YAFFS_OK ; + + existing_cunk =yaffs_get_group_base (dev, tn, inode_chunk); + +if (in_scan !=0 ) { +/* If we're scanning then we need to test for duplicates +* NB This does not need to be efficient since it should only ever +* happen when the power fails during a write, then only one +* chunk should ever be affected. +* +* Correction for YAFFS2: This could happen quite a lot and we need to think about efficiency! TODO +* Update: For backward scanning we don't need to re-read tags so this is quite cheap. +*/ + +if (existing_cunk >0 ) { +/* NB Right now existing chunk will not be real chunk_id if the chunk group size > 1 +* thus we have to do a FindChunkInFile to get the real chunk id. +* +* We have a duplicate now we need to decide which one to use: +* +* Backwards scanning YAFFS2: The old one is what we use, dump the new one. +* Forward scanning YAFFS2: The new one is what we use, dump the old one. +* YAFFS1: Get both sets of tags and compare serial numbers. +*/ + +if (in_scan >0 ) { +/* Only do this for forward scanning */ +yaffs_rd_chunk_tags_nand (dev, + nand_chunk, +NULL , &new_tags); + +/* Do a proper find */ + existing_cunk = +yaffs_find_chunk_in_file (in, inode_chunk, + &existing_tags); + } + +if (existing_cunk <=0 ) { +/*Hoosterman - how did this happen? */ + +T (YAFFS_TRACE_ERROR , + (TSTR + ("yaffs tragedy: existing chunk < 0 in scan" +TENDSTR ))); + + } + +/* NB The deleted flags should be false, otherwise the chunks will +* not be loaded during a scan +*/ + +if (in_scan >0 ) { + new_serial = new_tags.serial_number; + existing_serial = existing_tags.serial_number; + } + +if ((in_scan >0 ) && + (existing_cunk <=0 || + ((existing_serial +1 ) &3 ) == new_serial)) { +/* Forward scanning. +* Use new +* Delete the old one and drop through to update the tnode +*/ +yaffs_chunk_del (dev, existing_cunk,1 , + __LINE__); + }else { +/* Backward scanning or we want to use the existing one +* Use existing. +* Delete the new one and return early so that the tnode isn't changed +*/ +yaffs_chunk_del (dev, nand_chunk,1 , __LINE__); +return YAFFS_OK ; + } + } + + } + +if (existing_cunk ==0 ) + in->n_data_chunks++; + +yaffs_load_tnode_0 (dev, tn, inode_chunk, nand_chunk); + +return YAFFS_OK ; +} + +static int yaffs_rd_data_obj (struct yaffs_obj *in,int inode_chunk,u8 * buffer) +{ +int nand_chunk =yaffs_find_chunk_in_file (in, inode_chunk,NULL ); + +if (nand_chunk >=0 ) +return yaffs_rd_chunk_tags_nand (in->my_dev, nand_chunk, + buffer,NULL ); +else { +T (YAFFS_TRACE_NANDACCESS , + (TSTR ("Chunk %d not found zero instead" TENDSTR ), + nand_chunk)); +/* get sane (zero) data if you read a hole */ +memset (buffer,0 , in->my_dev->data_bytes_per_chunk); +return 0 ; + } + +} + +void yaffs_chunk_del (struct yaffs_dev *dev,int chunk_id,int mark_flash, +int lyn) +{ +int block; +int page; +struct yaffs_ext_tags tags; +struct yaffs_block_info *bi; + +if (chunk_id <=0 ) +return ; + + dev->n_deletions++; + block = chunk_id / dev->param.chunks_per_block; + page = chunk_id % dev->param.chunks_per_block; + +if (!yaffs_check_chunk_bit (dev, block, page)) +T (YAFFS_TRACE_VERIFY , + (TSTR ("Deleting invalid chunk %d" TENDSTR ), chunk_id)); + + bi =yaffs_get_block_info (dev, block); + +yaffs2_update_oldest_dirty_seq (dev, block, bi); + +T (YAFFS_TRACE_DELETION , + (TSTR ("line %d delete of chunk %d" TENDSTR ), lyn, chunk_id)); + +if (!dev->param.is_yaffs2 && mark_flash && + bi->block_state !=YAFFS_BLOCK_STATE_COLLECTING ) { + +yaffs_init_tags (&tags); + + tags.is_deleted =1 ; + +yaffs_wr_chunk_tags_nand (dev, chunk_id,NULL , &tags); +yaffs_handle_chunk_update (dev, chunk_id, &tags); + }else { + dev->n_unmarked_deletions++; + } + +/* Pull out of the management area. +* If the whole block became dirty, this will kick off an erasure. +*/ +if (bi->block_state ==YAFFS_BLOCK_STATE_ALLOCATING || + bi->block_state ==YAFFS_BLOCK_STATE_FULL || + bi->block_state ==YAFFS_BLOCK_STATE_NEEDS_SCANNING || + bi->block_state ==YAFFS_BLOCK_STATE_COLLECTING ) { + dev->n_free_chunks++; + +yaffs_clear_chunk_bit (dev, block, page); + + bi->pages_in_use--; + +if (bi->pages_in_use ==0 && + !bi->has_shrink_hdr && + bi->block_state !=YAFFS_BLOCK_STATE_ALLOCATING && + bi->block_state !=YAFFS_BLOCK_STATE_NEEDS_SCANNING ) { +yaffs_block_became_dirty (dev, block); + } + + } + +} + +static int yaffs_wr_data_obj (struct yaffs_obj *in,int inode_chunk, +const u8 * buffer,int n_bytes,int use_reserve) +{ +/* Find old chunk Need to do this to get serial number +* Write new one and patch into tree. +* Invalidate old tags. +*/ + +int prev_chunk_id; +struct yaffs_ext_tags prev_tags; + +int new_chunk_id; +struct yaffs_ext_tags new_tags; + +struct yaffs_dev *dev = in->my_dev; + +yaffs_check_gc (dev,0 ); + +/* Get the previous chunk at this location in the file if it exists. +* If it does not exist then put a zero into the tree. This creates +* the tnode now, rather than later when it is harder to clean up. +*/ + prev_chunk_id =yaffs_find_chunk_in_file (in, inode_chunk, &prev_tags); +if (prev_chunk_id <1 && + !yaffs_put_chunk_in_file (in, inode_chunk,0 ,0 )) +return 0 ; + +/* Set up new tags */ +yaffs_init_tags (&new_tags); + + new_tags.chunk_id = inode_chunk; + new_tags.obj_id = in->obj_id; + new_tags.serial_number = + (prev_chunk_id >0 ) ? prev_tags.serial_number +1 :1 ; + new_tags.n_bytes = n_bytes; + +if (n_bytes <1 || n_bytes > dev->param.total_bytes_per_chunk) { +T (YAFFS_TRACE_ERROR , + (TSTR ("Writing %d bytes to chunk!!!!!!!!!" TENDSTR ), + n_bytes)); +YBUG (); + } + + new_chunk_id = +yaffs_write_new_chunk (dev, buffer, &new_tags, use_reserve); + +if (new_chunk_id >0 ) { +yaffs_put_chunk_in_file (in, inode_chunk, new_chunk_id,0 ); + +if (prev_chunk_id >0 ) +yaffs_chunk_del (dev, prev_chunk_id,1 , __LINE__); + +yaffs_verify_file_sane (in); + } +return new_chunk_id; + +} + +/* UpdateObjectHeader updates the header on NAND for an object. +* If name is not NULL, then that new name is used. +*/ +int yaffs_update_oh (struct yaffs_obj *in,const YCHAR * name,int force, +int is_shrink,int shadows,struct yaffs_xattr_mod *xmod) +{ + +struct yaffs_block_info *bi; + +struct yaffs_dev *dev = in->my_dev; + +int prev_chunk_id; +int ret_val =0 ; +int result =0 ; + +int new_chunk_id; +struct yaffs_ext_tags new_tags; +struct yaffs_ext_tags old_tags; +const YCHAR *alias =NULL ; + +u8 *buffer =NULL ; +YCHAR old_name[YAFFS_MAX_NAME_LENGTH +1 ]; + +struct yaffs_obj_hdr *oh =NULL ; + +yaffs_strcpy (old_name,_Y ("silly old name" )); + +if (!in->fake || in == dev->root_dir ||/* The root_dir should also be saved */ + force || xmod) { + +yaffs_check_gc (dev,0 ); +yaffs_check_obj_details_loaded (in); + + buffer =yaffs_get_temp_buffer (in->my_dev, __LINE__); + oh = (struct yaffs_obj_hdr *)buffer; + + prev_chunk_id = in->hdr_chunk; + +if (prev_chunk_id >0 ) { + result =yaffs_rd_chunk_tags_nand (dev, prev_chunk_id, + buffer, &old_tags); + +yaffs_verify_oh (in, oh, &old_tags,0 ); + +memcpy (old_name, oh->name,sizeof (oh->name)); +memset (buffer,0xFF ,sizeof (struct yaffs_obj_hdr )); + }else { +memset (buffer,0xFF , dev->data_bytes_per_chunk); + } + + oh->type = in->variant_type; + oh->yst_mode = in->yst_mode; + oh->shadows_obj = oh->inband_shadowed_obj_id = shadows; + +yaffs_load_attribs_oh (oh, in); + +if (in->parent) + oh->parent_obj_id = in->parent->obj_id; +else + oh->parent_obj_id =0 ; + +if (name && *name) { +memset (oh->name,0 ,sizeof (oh->name)); +yaffs_load_oh_from_name (dev, oh->name, name); + }else if (prev_chunk_id >0 ) { +memcpy (oh->name, old_name,sizeof (oh->name)); + }else { +memset (oh->name,0 ,sizeof (oh->name)); + } + + oh->is_shrink = is_shrink; + +switch (in->variant_type) { +case YAFFS_OBJECT_TYPE_UNKNOWN : +/* Should not happen */ +break ; +case YAFFS_OBJECT_TYPE_FILE : + oh->file_size = + (oh->parent_obj_id ==YAFFS_OBJECTID_DELETED + || oh->parent_obj_id == +YAFFS_OBJECTID_UNLINKED ) ?0 : in-> + variant.file_variant.file_size; +break ; +case YAFFS_OBJECT_TYPE_HARDLINK : + oh->equiv_id = in->variant.hardlink_variant.equiv_id; +break ; +case YAFFS_OBJECT_TYPE_SPECIAL : +/* Do nothing */ +break ; +case YAFFS_OBJECT_TYPE_DIRECTORY : +/* Do nothing */ +break ; +case YAFFS_OBJECT_TYPE_SYMLINK : + alias = in->variant.symlink_variant.alias; +if (!alias) + alias =_Y ("no alias" ); +yaffs_strncpy (oh->alias, alias,YAFFS_MAX_ALIAS_LENGTH ); + oh->alias[YAFFS_MAX_ALIAS_LENGTH ] =0 ; +break ; + } + +/* process any xattrib modifications */ +if (xmod) +yaffs_apply_xattrib_mod (in, (char *)buffer, xmod); + +/* Tags */ +yaffs_init_tags (&new_tags); + in->serial++; + new_tags.chunk_id =0 ; + new_tags.obj_id = in->obj_id; + new_tags.serial_number = in->serial; + +/* Add extra info for file header */
Lines of this file are not shown. View the raw message.
fs/yaffs2/yaffs_guts.h new file +915 -0
915 lines not on this page · raw message
fs/yaffs2/yaffs_yaffs1.c new file +437 -0
437 lines not on this page · raw message
fs/yaffs2/yaffs_yaffs2.c new file +1620 -0
1,620 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH 3/8] Add yaffs2 file system: guts code
On Tuesday 30 November 2010 22:57:29 Charles Manning wrote:
I think I made these comments before, not sure what happened to them...
fs/yaffs2/yaffs_guts.c line 52
Quoted 10 lines
fs/yaffs2/yaffs_guts.c new file +10
-0+ +/* Robustification (if it ever comes about...) */ +static void yaffs_retire_block (struct yaffs_dev *dev,int flash_block); +static void yaffs_handle_chunk_wr_error (struct yaffs_dev *dev,int nand_chunk, +int erased_ok); +static void yaffs_handle_chunk_wr_ok (struct yaffs_dev *dev,int nand_chunk, +const u8 * data, +const struct yaffs_ext_tags *tags); +static void yaffs_handle_chunk_update (struct yaffs_dev *dev,int nand_chunk, +const struct yaffs_ext_tags *tags);
It would be better to reorder the functions in each file so that you don't need forward declarations. This generally makes reading the code easier because it is what people expect to see. It also makes it clearer where you have possible recursions in the code.
fs/yaffs2/yaffs_guts.c line 224
Quoted 9 lines
fs/yaffs2/yaffs_guts.c new file +9
-0+ +T (YAFFS_TRACE_BUFFERS , + (TSTR ("Out of temp buffers at line %d, other held by lines:" ), + line_no)); +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) +T (YAFFS_TRACE_BUFFERS , + (TSTR (" %d " ), dev->temp_buffer[i].line)); + +T (YAFFS_TRACE_BUFFERS , (TSTR (" " TENDSTR )));
The tracing functions are rather obscure. I would recommend dropping them all for now, in order to get the code included. At a later stage, you can add standard trace points.
fs/yaffs2/yaffs_guts.c line 232
Quoted 1 line
fs/yaffs2/yaffs_guts.c new file +1
-0+return YMALLOC (dev->data_bytes_per_chunk);
In general, don't wrap standard kernel API functions with your own abstractions, just use kmalloc here for instance.
It is rather annoying when you want to understand code and it calls nonstandard functions that do almost the same that the standard API does.
If you find something lacking in the existing API, feel free to make suggestions for improving it. Either it is a good idea and everyone will be happy about the useful new interface, or it is a bad idea and you shouldn't be using it in the first place.
Arnd
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 4 lines · On Wednesday 01 December 2010 11:23:53 you wrote:
On Tuesday 30 November 2010 22:57:29 Charles Manning wrote:
I think I made these comments before, not sure what happened to them...
Quoted 15 lines
Quoted 10 lines
fs/yaffs2/yaffs_guts.c new file +4
-0+ +/* Robustification (if it ever comes about...) */ +static void yaffs_retire_block (struct yaffs_dev *dev,int flash_block); +static void yaffs_handle_chunk_wr_error(struct yaffs_dev *dev, int
nand_chunk, + interased_ok);
+static void yaffs_handle_chunk_wr_ok(structyaffs_dev*dev, intnand_chunk, + const u8 * data,(quoted diff) +2
-0+ const struct yaffs_ext_tags *tags); +static void yaffs_handle_chunk_update(struct yaffs_dev *dev, int
nand_chunk, + const structyaffs_ext_tags*tags);It would be better to reorder the functions in each file so that you don't need forward declarations. This generally makes reading the code easier because it is what people expect to see. It also makes it clearer where you have possible recursions in the code.
Hmmm..
I too prefer minimal use of forward declaration.
Some of them are because I copied the layout of existing kernel code which uses fwd declarations a lot. eg. fs/jffs2/dir.c and many of the examples in Rubini & Corbet.
Quoted 13 lines
fs/yaffs2/yaffs_guts.c line 224
Quoted 10 lines
fs/yaffs2/yaffs_guts.c new file +9
-0+ +T (YAFFS_TRACE_BUFFERS , + (TSTR ("Out of temp buffers at line %d, other held by lines:" ), + line_no)); +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) +T (YAFFS_TRACE_BUFFERS , + (TSTR (" %d " ), dev->temp_buffer[i].line)); + +T (YAFFS_TRACE_BUFFERS , (TSTR (" " TENDSTR )));The tracing functions are rather obscure. I would recommend dropping them all for now, in order to get the code included.
Yup that was a very ugly bunch of hackery to make WinCE unicode work.
I think I can pull the var-arg-foo to replace these with
yaffs_trace(YAFFS_TRACE_BUFFERS,
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");
Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
Quoted 4 lines
At a later
stage, you can add standard trace points.fs/yaffs2/yaffs_guts.c line 232
Quoted 1 line
fs/yaffs2/yaffs_guts.c new file +1
-0+return YMALLOC (dev->data_bytes_per_chunk);
I'm getting rid of those..
The reason for thew wrapping was to make portable code.
I'm replacing these with kmalloc() and then providing kmalloc() which is just a wrapped malloc() for non-Linux use.
I am hoping to reduce this to YCHAR, _Y() and maybe one or two others.
-- Charles
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 7 lines · Charles Manning
Quoted 5 lines · On Wednesday 01 December 2010 11:23:53 you wrote:
On Tuesday 30 November 2010 22:57:29 Charles Manning wrote:
It would be better to reorder the functions in each file so that you don't need forward declarations. This generally makes reading the code easier because it is what people expect to see. It also makes it clearer where you have possible recursions in the code.
Quoted 5 lines
Hmmm..
I too prefer minimal use of forward declaration.
Some of them are because I copied the layout of existing kernel code which uses fwd declarations a lot. eg.fs/jffs2/dir.cand many of the examples in Rubini & Corbet.
There is not much point in changing the legacy code that's already in the kernel, but let's try to keep it clean for new code. We have a lot of bad examples for coding style that we wouldn't merge these days.
In this case, it should be an obvious change with no real downsides.
Quoted 17 lines
Quoted 11 lines
fs/yaffs2/yaffs_guts.c line 224
Quoted 8 lines
fs/yaffs2/yaffs_guts.c new file +8
-0+T (YAFFS_TRACE_BUFFERS , + (TSTR ("Out of temp buffers at line %d, other held by lines:" ), + line_no)); +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) +T (YAFFS_TRACE_BUFFERS , + (TSTR (" %d " ), dev->temp_buffer[i].line)); + +T (YAFFS_TRACE_BUFFERS , (TSTR (" " TENDSTR )));The tracing functions are rather obscure. I would recommend dropping them all for now, in order to get the code included.
Yup that was a very ugly bunch of hackery to make WinCE unicode work.
I think I can pull the var-arg-foo to replace these with
yaffs_trace(YAFFS_TRACE_BUFFERS,
Quoted 8 lines
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the yaffs_trace() function would be much better than the T() macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.
The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Please have a look at how ext4, gfs2 and xfs do tracing.
Quoted 11 lines
Quoted 4 lines
At a later
stage, you can add standard trace points.fs/yaffs2/yaffs_guts.c line 232
Quoted 1 line
fs/yaffs2/yaffs_guts.c new file +1
-0+return YMALLOC (dev->data_bytes_per_chunk);I'm getting rid of those..
The reason for thew wrapping was to make portable code.
I'm replacing these with
kmalloc()and then providingkmalloc()which is just a wrappedmalloc()for non-Linux use.
Ok, excellent!
Quoted 1 line
I am hoping to reduce this to YCHAR,
_Y()and maybe one or two others.
Ok. Maybe rename YCHAR to ychar to make it stick out less, and add a comment to the definition why you need it then.
Arnd
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 14 lines · On Tuesday 07 December 2010 01:55:43 Arnd Bergmann wrote:
Quoted 7 lines · Charles Manning
Quoted 5 lines · On Wednesday 01 December 2010 11:23:53 you wrote:
On Tuesday 30 November 2010 22:57:29 Charles Manning wrote:
It would be better to reorder the functions in each file so that you don't need forward declarations. This generally makes reading the code easier because it is what people expect to see. It also makes it clearer where you have possible recursions in the code.Quoted 5 lines
Hmmm..
I too prefer minimal use of forward declaration.
Some of them are because I copied the layout of existing kernel code which uses fwd declarations a lot. eg.fs/jffs2/dir.cand many of the examples in Rubini & Corbet.
Quoted 5 lines
There is not much point in changing the legacy code that's already in the kernel, but let's try to keep it clean for new code. We have a lot of bad examples for coding style that we wouldn't merge these days.
In this case, it should be an obvious change with no real downsides.
Arnd thanks for your input, I appreciate it immensely.
Is this objection to forward declarations just your personal taste or is this a real issue?
I can't find any references to forward declarations in any of the coding style docs. I would therefore expect it to be an issue of little consequence. Perhaps I did not look in the right places.
It is perhaps also worth considering that yaffs has been in use for 8 years and is more widely used than many of the file systems already in the kernel and thus, by some measures, does constitute legacy code.
Quoted 36 lines
Quoted 18 lines
Quoted 12 lines
fs/yaffs2/yaffs_guts.c line 224
Quoted 9 lines
fs/yaffs2/yaffs_guts.c new file +8
-0+T (YAFFS_TRACE_BUFFERS , + (TSTR ("Out of temp buffers at line %d, other held by lines:" ), + line_no)); +for (i =0 ; i <YAFFS_N_TEMP_BUFFERS ; i++) +T (YAFFS_TRACE_BUFFERS , + (TSTR (" %d " ), dev->temp_buffer[i].line)); + +T (YAFFS_TRACE_BUFFERS , (TSTR (" " TENDSTR )));The tracing functions are rather obscure. I would recommend dropping them all for now, in order to get the code included.
Yup that was a very ugly bunch of hackery to make WinCE unicode work.
I think I can pull the var-arg-foo to replace these with
yaffs_trace(YAFFS_TRACE_BUFFERS,
Quoted 8 lines
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the
yaffs_trace()function would be much better than theT()macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Quoted 6 lines
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Please have a look at how ext4, gfs2 and xfs do tracing.
Looking in Linus' tree, all of those contain custom tracing of the form I propose.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
At a later
stage, you can add standard trace points.Quoted 8 lines
Quoted 1 line
fs/yaffs2/yaffs_guts.c line 232
Quoted 1 line
fs/yaffs2/yaffs_guts.c new file +1
-0+return YMALLOC (dev->data_bytes_per_chunk);I'm getting rid of those..
The reason for thew wrapping was to make portable code.
I'm replacing these with
kmalloc()and then providingkmalloc()which is just a wrappedmalloc()for non-Linux use.
Quoted 6 lines
Ok, excellent!
Quoted 1 line
I am hoping to reduce this to YCHAR,
_Y()and maybe one or two others.Ok. Maybe rename YCHAR to ychar to make it stick out less, and add a comment to the definition why you need it then.
Can do.
Thanks.
-- Charles
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 19 lines · Charles Manning
Quoted 18 lines · On Tuesday 07 December 2010 01:55:43 Arnd Bergmann wrote:
Quoted 7 lines · Charles Manning
Quoted 5 lines · On Wednesday 01 December 2010 11:23:53 you wrote:
On Tuesday 30 November 2010 22:57:29 Charles Manning wrote:
It would be better to reorder the functions in each file so that you don't need forward declarations. This generally makes reading the code easier because it is what people expect to see. It also makes it clearer where you have possible recursions in the code.Quoted 5 lines
Hmmm..
I too prefer minimal use of forward declaration.
Some of them are because I copied the layout of existing kernel code which uses fwd declarations a lot. eg.fs/jffs2/dir.cand many of the examples in Rubini & Corbet.There is not much point in changing the legacy code that's already in the kernel, but let's try to keep it clean for new code. We have a lot of bad examples for coding style that we wouldn't merge these days.
Quoted 7 lines
Quoted 1 line
In this case, it should be an obvious change with no real downsides.
Arnd thanks for your input, I appreciate it immensely.
Is this objection to forward declarations just your personal taste or is this a real issue?
I can only speak for myself here (which obviously makes this comment a "personal taste thing). I personally hate all those forward declarations and whenever I'm modifying kernel code I try to see if I can move stuff around to get rid of some.
We have to live with what's already in the tree, but there's no reason to add more gunk. It's easy to just re-order functions to get rid of the forward declarations, so why not just do that - makes it so much nicer to read (now and in the future - by thousands of people).
Quoted 4 lines
I can't find any references to forward declarations in any of the coding style docs. I would therefore expect it to be an issue of little consequence. Perhaps I did not look in the right places.
I don't think it's written in stone anywhere, it's just one of those thiings where one alternative is obviously so much nicer than the other...
Quoted 4 lines
It is perhaps also worth considering that yaffs has been in use for 8 years and is more widely used than many of the file systems already in the kernel and thus, by some measures, does constitute legacy code.
In terms of mainline Linux kernel inclusion it does not.
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
Re: [PATCH 3/8] Add yaffs2 file system: guts code
In reply to Charles ManningQuoted 21 lines · On Monday 06 December 2010 23:13:51 Charles Manning wrote:
Quoted 14 lines · On Tuesday 07 December 2010 01:55:43 Arnd Bergmann wrote:
Quoted 7 lines · Charles Manning
Quoted 5 lines · On Wednesday 01 December 2010 11:23:53 you wrote:
On Tuesday 30 November 2010 22:57:29 Charles Manning wrote:
It would be better to reorder the functions in each file so that you don't need forward declarations. This generally makes reading the code easier because it is what people expect to see. It also makes it clearer where you have possible recursions in the code.Quoted 5 lines
Hmmm..
I too prefer minimal use of forward declaration.
Some of them are because I copied the layout of existing kernel code which uses fwd declarations a lot. eg.fs/jffs2/dir.cand many of the examples in Rubini & Corbet.Quoted 5 lines
There is not much point in changing the legacy code that's already in the kernel, but let's try to keep it clean for new code. We have a lot of bad examples for coding style that we wouldn't merge these days.
In this case, it should be an obvious change with no real downsides.
Quoted 8 lines
Arnd thanks for your input, I appreciate it immensely.
Is this objection to forward declarations just your personal taste or is this a real issue?
I can't find any references to forward declarations in any of the coding style docs. I would therefore expect it to be an issue of little consequence. Perhaps I did not look in the right places.
It's not very important and a lot of people don't care, though I have never seen anyone argue in favour of adding forward declarations. I consider it similar to the argument about function sizes: We don't have a hard limit about how many lines a function is allowed to have, and there are some cases where it makes sense to have a really long function, but you can tell how much effort people put into making code readable when you see a multi-page function that could easily be split into reasonable smaller ones. Code readability is mostly subjective, just like taste, but with some experience, you see when something is done wrong.
Quoted 3 lines
It is perhaps also worth considering that yaffs has been in use for 8 years and is more widely used than many of the file systems already in the kernel and thus, by some measures, does constitute legacy code.
I see this argument a lot about code that gets upstream after a long time. My counterargument to this is that often enough the reason for being outside of mainline is that the code was written in obscure ways to start with ;-)
In general, the initial merge of new code is the only time we can really influence code from other people. Once it gets merged, I'm going to have a really hard time making the maintainers change it again in fundamental ways.
Quoted 24 lines
Quoted 24 lines
Quoted 9 lines
yaffs_trace(YAFFS_TRACE_BUFFERS,
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the
yaffs_trace()function would be much better than theT()macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Quoted 4 lines
Quoted 1 line
Please have a look at how ext4, gfs2 and xfs do tracing.
Looking in Linus' tree, all of those contain custom tracing of the form I propose.
Hmm, yes I guess that's right...
I was specifically talking about the include/trace/* based trace events as something to look at, not the random printk based tracing stuff. Maybe Steven or Frederic can give some more insight on that.
Arnd
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 26 lines · Arnd Bergmann
Quoted 26 lines
Quoted 25 lines
Quoted 9 lines
yaffs_trace(YAFFS_TRACE_BUFFERS,
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the
yaffs_trace()function would be much better than theT()macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Please have a look at how ext4, gfs2 and xfs do tracing.
Quoted 9 lines
Quoted 2 lines
Looking in Linus' tree, all of those contain custom tracing of the form I propose.
Hmm, yes I guess that's right...
I was specifically talking about the
include/trace/*based trace events as something to look at, not the random printk based tracing stuff. Maybe Steven or Frederic can give some more insight on that.
What are all those T() functions? Some look like they should be replaced with printk(KERN_* "") functions, some others for tracing (I guess the ones with YAFFS_TRACE_TRACING).
ext4, gfs and xfs all have converted to the TRACE_EVENT() methods. When you have this, you get tracing for free. The work with both ftrace and perf. You can look at the samples/trace_events/ code for examples.
Note, if you use TRACE_EVENT() and you want to debug even more, you can simply add trace_printk() and that will also appear in your tracing output.
-- Steve
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 35 lines · On Tuesday 07 December 2010 13:47:43 Steven Rostedt wrote:
Quoted 34 lines · Arnd Bergmann
Quoted 27 lines
Quoted 27 lines
Quoted 10 lines
yaffs_trace(YAFFS_TRACE_BUFFERS,
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the
yaffs_trace()function would be much better than theT()macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Quoted 4 lines
Quoted 1 line
Please have a look at how ext4, gfs2 and xfs do tracing.
Looking in Linus' tree, all of those contain custom tracing of the form I propose.
Hmm, yes I guess that's right...
Quoted 7 lines
Quoted 3 lines
I was specifically talking about the
include/trace/*based trace events as something to look at, not the random printk based tracing stuff. Maybe Steven or Frederic can give some more insight on that.What are all those
T()functions? Some look like they should be replaced withprintk(KERN_* "")functions, some others for tracing (I guess the ones withYAFFS_TRACE_TRACING).
Yes those are very ugly. That is why I proposed changing them to
yaffs_trace(bit, "format", args).
That gives printk tracing which I can select on the fly by enabling the selected bits in the bitmask. eg. If I want to see the OS calls and the mtd accesses then I enable YAFFS_TRACE_MTD and YAFFS_TRACE_OS and only those grace groups get spat out.
People find this very handy, especially during system integration, so I am loath to lose it. It is simple and it works.
Will it not be acceptable to just leave in the printk-style messages and perhaps addTRACE_EVENT later?
Quoted 10 lines
ext4, gfs and xfs all have converted to the
TRACE_EVENT()methods. When you have this, you get tracing for free. The work with both ftrace and perf. You can look at thesamples/trace_events/code for examples.Note, if you use
TRACE_EVENT()and you want to debug even more, you can simply addtrace_printk()and that will also appear in your tracing output.From what I see, ext4 uses both
trace_eventand wrapped printk tracing, some
right alongside eachother so it is a duplication - not a replacement.
YAFFS has approx 500 trace lines in it. Some of those would make sense to attach to TRACE_EVENT() , but most not. trace/events/ext4.h has 1172 lines for around 28 events (== 40-odd lines per event).
Still reading everything I can find on this (inc, your LWN articles) to get an understanding of what capabilities these give me and what heuristic should be used to define trace points vs printks.
-- Charles
Re: [PATCH 3/8] Add yaffs2 file system: guts code
[ Adding Ted to Cc ]
Quoted 48 lines · Charles Manning
Quoted 35 lines · On Tuesday 07 December 2010 13:47:43 Steven Rostedt wrote:
Quoted 34 lines · Arnd Bergmann
Quoted 27 lines
Quoted 27 lines
Quoted 10 lines
yaffs_trace(YAFFS_TRACE_BUFFERS,
"Out of temp buffers at line %d, other held by lines:",line_no); for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) yaffs_trace(YAFFS_TRACE_BUFFERS," %d ", dev->temp_buffer[i].line);
yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the
yaffs_trace()function would be much better than theT()macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Quoted 4 lines
Quoted 1 line
Please have a look at how ext4, gfs2 and xfs do tracing.
Looking in Linus' tree, all of those contain custom tracing of the form I propose.
Hmm, yes I guess that's right...
Quoted 7 lines
Quoted 3 lines
I was specifically talking about the
include/trace/*based trace events as something to look at, not the random printk based tracing stuff. Maybe Steven or Frederic can give some more insight on that.What are all those
T()functions? Some look like they should be replaced withprintk(KERN_* "")functions, some others for tracing (I guess the ones withYAFFS_TRACE_TRACING).Yes those are very ugly. That is why I proposed changing them to
yaffs_trace(bit, "format", args).
Quoted 7 lines
That gives printk tracing which I can select on the fly by enabling the selected bits in the bitmask. eg. If I want to see the OS calls and the mtd accesses then I enable
YAFFS_TRACE_MTDandYAFFS_TRACE_OSand only those grace groups get spat out.People find this very handy, especially during system integration, so I am loath to lose it. It is simple and it works.
Adding the TRACE_EVENT() code is also simple too ;)
With TRACE_EVENT() you will get the advantage of jump_lables (with newer compilers). That is, there's no "if (bit & SOME_MASK) trace();" logic. A nop is placed in the code and no compares are needed. When tracing is enabled, the nop is changed to a jmp to the trace.
If you still use your own tracer, you could still use the internal ring_buffer code.
Quoted 16 lines
Will it not be acceptable to just leave in the printk-style messages and perhaps
addTRACE_EVENTlater?Quoted 8 lines
ext4, gfs and xfs all have converted to the
TRACE_EVENT()methods. When you have this, you get tracing for free. The work with both ftrace and perf. You can look at thesamples/trace_events/code for examples.Note, if you use
TRACE_EVENT()and you want to debug even more, you can simply addtrace_printk()and that will also appear in your tracing output.From what I see, ext4 uses both
trace_eventand wrapped printk tracing, some right alongside eachother so it is a duplication - not a replacement.
Quoted 7 lines
YAFFS has approx 500 trace lines in it. Some of those would make sense to attach to
TRACE_EVENT(), but most not.trace/events/ext4.hhas 1172 lines for around 28 events (== 40-odd lines per event).Still reading everything I can find on this (inc, your LWN articles) to get an understanding of what capabilities these give me and what heuristic should be used to define trace points vs printks.
Printks go to the console. You should not do that unless it is an error that the admin should notice. There's also levels of printks that you can do:
KERN_ERR, KERN_WARING, KERN_INFO, KERN_DEBUG, etc.
But again, these go to the users console and into the message logs. If it is something that is a high activity this can slow down the system as printk's are synchronous. That is, they don't continue work until they finished writing. If you have a serial console, that could really slow things down.
printk's should not be used for real debugging anyway. But putting it into a tracepoint, then it opens up lots of options.
Your T(YAFFS_TRACE_ALWAYS, ...) look like good candidates for printks.
TRACE_EVENTS() are those that just want to analyze what is happening in the system.
-- Steve
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 57 lines · On Wednesday 08 December 2010 03:49:30 Steven Rostedt wrote:
[ Adding Ted to Cc ]
Quoted 54 lines · Charles Manning
Quoted 36 lines · On Tuesday 07 December 2010 13:47:43 Steven Rostedt wrote:
Quoted 35 lines · Arnd Bergmann
Quoted 28 lines
Quoted 28 lines
Quoted 11 lines
yaffs_trace(YAFFS_TRACE_BUFFERS,
"Out of temp buffers at line %d, other held by
lines:",line_no); for (i = 0; i <YAFFS_N_TEMP_BUFFERS; i++)
yaffs_trace(YAFFS_TRACE_BUFFERS," %d ",
dev->temp_buffer[i].line);yaffs_trace(YAFFS_TRACE_BUFFERS, "\n");Would that be OK?
I am loath to have to pull out useful code then plug it back in again.
I don't think the
yaffs_trace()function would be much better than theT()macro, I was talking more about the fact that you have your own nonstandard tracing infrastructure than the ugliness of the interface.The point of pulling it out now would be force you to rethink the tracing. If you think that you'd arrive at the same conclusion, just save the diff between the code with and without tracing so you can submit that patch again later.
Having some sort of tracing is clearly useful, but it's also not essential for the basic yaffs2 operation. We want to keep a consistent way of presenting trace points across the kernel, so as long as you do it differently, your code is going to be viewed with some suspicion.
Quoted 4 lines
Quoted 1 line
Please have a look at how ext4, gfs2 and xfs do tracing.
Looking in Linus' tree, all of those contain custom tracing of the form I propose.
Hmm, yes I guess that's right...
Quoted 7 lines
Quoted 3 lines
I was specifically talking about the
include/trace/*based trace events as something to look at, not the random printk based tracing stuff. Maybe Steven or Frederic can give some more insight on that.What are all those
T()functions? Some look like they should be replaced withprintk(KERN_* "")functions, some others for tracing (I guess the ones withYAFFS_TRACE_TRACING).Yes those are very ugly. That is why I proposed changing them to
yaffs_trace(bit, "format", args).That gives printk tracing which I can select on the fly by enabling the selected bits in the bitmask. eg. If I want to see the OS calls and the mtd accesses then I enable
YAFFS_TRACE_MTDandYAFFS_TRACE_OSand only those grace groups get spat out.
Quoted 4 lines
Quoted 2 lines
People find this very handy, especially during system integration, so I am loath to lose it. It is simple and it works.
Adding the
TRACE_EVENT()code is also simple too ;)
For 500 traces?
Please remember that yaffs is typically used in embedded systems - not big iron servers . Typical kernel sizes are between 1 and 3MB. Pretty much all the big iron features get turned off.
Quoted 1 line
From your LWN article it would seem that adding
TRACE_EVENT()would podge up
the kernel somewhat.
Quoted 28 lines
With
TRACE_EVENT()you will get the advantage ofjump_lables(with newer compilers). That is, there's no "if (bit &SOME_MASK)trace();" logic. A nop is placed in the code and no compares are needed. When tracing is enabled, the nop is changed to a jmp to the trace.If you still use your own tracer, you could still use the internal
ring_buffercode.Quoted 19 lines
Will it not be acceptable to just leave in the printk-style messages and perhaps
addTRACE_EVENTlater?Quoted 7 lines
ext4, gfs and xfs all have converted to the
TRACE_EVENT()methods. When you have this, you get tracing for free. The work with both ftrace and perf. You can look at thesamples/trace_events/code for examples.Note, if you use
TRACE_EVENT()and you want to debug even more, you can simply addtrace_printk()and that will also appear in your tracing output.From what I see, ext4 uses both
trace_eventand wrapped printk tracing, some right alongside eachother so it is a duplication - not a replacement.YAFFS has approx 500 trace lines in it. Some of those would make sense to attach to
TRACE_EVENT(), but most not.trace/events/ext4.hhas 1172 lines for around 28 events (== 40-odd lines per event).
Quoted 6 lines
Quoted 3 lines
Still reading everything I can find on this (inc, your LWN articles) to get an understanding of what capabilities these give me and what heuristic should be used to define trace points vs printks.
Printks go to the console. You should not do that unless it is an error that the admin should notice.
Yaffs is used in embedded systems (eg. phones). There is no operator. The only people that ever look at dmesg and the log are engineers during integration/testing.
Quoted 11 lines
There's also levels of printks that you
can do:
KERN_ERR,KERN_WARING,KERN_INFO,KERN_DEBUG, etc.But again, these go to the users console and into the message logs. If
it is something that is a high activity this can slow down the system as printk's are synchronous. That is, they don't continue work until they finished writing. If you have a serial console, that could really slow things down.
That is exactly why I use the bitmasks to be able to be able to select sets of messages to be enabled. [btw: Enabling sets of traces seems to be a feature that TRACE_EVENT() lacks, or perhaps I have not read enough].
The trace mask allows you to set up a test case very easily and delivers the output where it is readily available.
Quoted 8 lines
printk's should not be used for real debugging anyway. But putting it into a tracepoint, then it opens up lots of options.
Your
T(YAFFS_TRACE_ALWAYS, ...)look like good candidates for printks.
TRACE_EVENTS()are those that just want to analyze what is happening in the system.
All, well almost all, embedded systems have printk. Many don't have TRACE.
People using yaffs do not want to lose what they already have and like the way tracing is set up.
What I propose is just rewriting the current trace mechanism so the code looks cleaner.
-- Charles
Re: [PATCH 3/8] Add yaffs2 file system: guts code
Quoted 3 lines · Charles Manning
Quoted 1 line
Adding the
TRACE_EVENT()code is also simple too ;)For 500 traces?
Are all of them for the BUFFER code?
Quoted 4 lines
Please remember that yaffs is typically used in embedded systems - not big iron servers . Typical kernel sizes are between 1 and 3MB. Pretty much all the big iron features get turned off.
OK then what about just using printk(KERN_DEBUG, ...)
Quoted 3 lines
Yaffs is used in embedded systems (eg. phones). There is no operator. The only people that ever look at dmesg and the log are engineers during integration/testing.
OK, then use pr_debug(), these can even be compiled out of the kernel for production.
Quoted 13 lines
Quoted 4 lines
There's also levels of printks that you
can do:Quoted 8 lines
KERN_ERR,KERN_WARING,KERN_INFO,KERN_DEBUG, etc.But again, these go to the users console and into the message logs. If
it is something that is a high activity this can slow down the system as printk's are synchronous. That is, they don't continue work until they finished writing. If you have a serial console, that could really slow things down.
Quoted 3 lines
That is exactly why I use the bitmasks to be able to be able to select sets of messages to be enabled. [btw: Enabling sets of traces seems to be a feature that
TRACE_EVENT()lacks, or perhaps I have not read enough].
You can group trace_events into TRACE_SYSTEMS, and then enable a bunch of events under which system they are in. I thought about making this into a hierarchy, but have yet seen the true need for that.
Quoted 13 lines
The trace mask allows you to set up a test case very easily and delivers the output where it is readily available.
Quoted 8 lines
printk's should not be used for real debugging anyway. But putting it into a tracepoint, then it opens up lots of options.
Your
T(YAFFS_TRACE_ALWAYS, ...)look like good candidates for printks.
TRACE_EVENTS()are those that just want to analyze what is happening in the system.
Quoted 7 lines
All, well almost all, embedded systems have printk. Many don't have TRACE.
People using yaffs do not want to lose what they already have and like the way tracing is set up.
What I propose is just rewriting the current trace mechanism so the code looks cleaner.
Fine, as it seems special purpose for embedded devices.
-- Steve
PATCH 4/8 Add yaffs2 file system: tags handling code
In reply to Charles Manning--- fs/yaffs2/yaffs_packedtags1.c | 53 +++++ fs/yaffs2/yaffs_packedtags1.h | 39 ++++ fs/yaffs2/yaffs_packedtags2.c | 197 +++++++++++++++++++ fs/yaffs2/yaffs_packedtags2.h | 47 +++++ fs/yaffs2/yaffs_tagscompat.c | 429 +++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_tagscompat.h | 36 ++++ 6 files changed, 801 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_packedtags1.c create mode 100644 fs/yaffs2/yaffs_packedtags1.h create mode 100644 fs/yaffs2/yaffs_packedtags2.c create mode 100644 fs/yaffs2/yaffs_packedtags2.h create mode 100644 fs/yaffs2/yaffs_tagscompat.c create mode 100644 fs/yaffs2/yaffs_tagscompat.h
fs/yaffs2/yaffs_packedtags1.c new file +53 -0
@@ -0,0 +1,53 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_packedtags1.h" +#include "yportenv.h" + +void yaffs_pack_tags1 (struct yaffs_packed_tags1 *pt, +const struct yaffs_ext_tags *t) +{ + pt->chunk_id = t->chunk_id; + pt->serial_number = t->serial_number; + pt->n_bytes = t->n_bytes; + pt->obj_id = t->obj_id; + pt->ecc =0 ; + pt->deleted = (t->is_deleted) ?0 :1 ; + pt->unused_stuff =0 ; + pt->should_be_ff =0xFFFFFFFF ; + +} + +void yaffs_unpack_tags1 (struct yaffs_ext_tags *t, +const struct yaffs_packed_tags1 *pt) +{ +static const u8 all_ff[] = + {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff , +0xff + }; + +if (memcmp (all_ff, pt,sizeof (struct yaffs_packed_tags1 ))) { + t->block_bad =0 ; +if (pt->should_be_ff !=0xFFFFFFFF ) + t->block_bad =1 ; + t->chunk_used =1 ; + t->obj_id = pt->obj_id; + t->chunk_id = pt->chunk_id; + t->n_bytes = pt->n_bytes; + t->ecc_result =YAFFS_ECC_RESULT_NO_ERROR ; + t->is_deleted = (pt->deleted) ?0 :1 ; + t->serial_number = pt->serial_number; + }else { +memset (t,0 ,sizeof (struct yaffs_ext_tags )); + } +}
fs/yaffs2/yaffs_packedtags1.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +/* This is used to pack YAFFS1 tags, not YAFFS2 tags. */ + +#ifndef __YAFFS_PACKEDTAGS1_H__ +#define __YAFFS_PACKEDTAGS1_H__ + +#include "yaffs_guts.h" + +struct yaffs_packed_tags1 { +unsigned chunk_id:20 ; +unsigned serial_number:2 ; +unsigned n_bytes:10 ; +unsigned obj_id:18 ; +unsigned ecc:12 ; +unsigned deleted:1 ; +unsigned unused_stuff:1 ; +unsigned should_be_ff; + +}; + +void yaffs_pack_tags1 (struct yaffs_packed_tags1 *pt, +const struct yaffs_ext_tags *t); +void yaffs_unpack_tags1 (struct yaffs_ext_tags *t, +const struct yaffs_packed_tags1 *pt); +#endif
fs/yaffs2/yaffs_packedtags2.c new file +197 -0
197 lines not on this page · raw message
fs/yaffs2/yaffs_packedtags2.h new file +47 -0
47 lines not on this page · raw message
fs/yaffs2/yaffs_tagscompat.c new file +429 -0
429 lines not on this page · raw message
fs/yaffs2/yaffs_tagscompat.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_TAGSCOMPAT_H__ +#define __YAFFS_TAGSCOMPAT_H__ + +#include "yaffs_guts.h" +int yaffs_tags_compat_wr (struct yaffs_dev *dev, +int nand_chunk, +const u8 * data,const struct yaffs_ext_tags *tags); +int yaffs_tags_compat_rd (struct yaffs_dev *dev, +int nand_chunk, +u8 * data,struct yaffs_ext_tags *tags); +int yaffs_tags_compat_mark_bad (struct yaffs_dev *dev,int block_no); +int yaffs_tags_compat_query_block (struct yaffs_dev *dev, +int block_no, +enum yaffs_block_state *state, +u32 * seq_number); + +void yaffs_calc_tags_ecc (struct yaffs_tags *tags); +int yaffs_check_tags_ecc (struct yaffs_tags *tags); +int yaffs_count_bits (u8 byte); + +#endif
Signature · 1 line
1.7.1
Re: [PATCH 4/8] Add yaffs2 file system: tags handling code
A few small comments inline below.
Quoted 397 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>--- fs/yaffs2/yaffs_packedtags1.c | 53 +++++ fs/yaffs2/yaffs_packedtags1.h | 39 ++++ fs/yaffs2/yaffs_packedtags2.c | 197 +++++++++++++++++++ fs/yaffs2/yaffs_packedtags2.h | 47 +++++ fs/yaffs2/yaffs_tagscompat.c | 429 +++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_tagscompat.h | 36 ++++ 6 files changed, 801 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_packedtags1.c create mode 100644 fs/yaffs2/yaffs_packedtags1.h create mode 100644 fs/yaffs2/yaffs_packedtags2.c create mode 100644 fs/yaffs2/yaffs_packedtags2.h create mode 100644 fs/yaffs2/yaffs_tagscompat.c create mode 100644 fs/yaffs2/yaffs_tagscompat.hfs/yaffs2/yaffs_packedtags1.c new file +53
-0@@ -0,0 +1,53 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_packedtags1.h" +#include "yportenv.h" + +void yaffs_pack_tags1 (struct yaffs_packed_tags1 *pt, +const struct yaffs_ext_tags *t) +{ + pt->chunk_id = t->chunk_id; + pt->serial_number = t->serial_number; + pt->n_bytes = t->n_bytes; + pt->obj_id = t->obj_id; + pt->ecc =0 ; + pt->deleted = (t->is_deleted) ?0 :1 ; + pt->unused_stuff =0 ; + pt->should_be_ff =0xFFFFFFFF ; + +} + +void yaffs_unpack_tags1 (struct yaffs_ext_tags *t, +const struct yaffs_packed_tags1 *pt) +{ +static const u8 all_ff[] = + {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff , +0xff + }; + +if (memcmp (all_ff, pt,sizeof (struct yaffs_packed_tags1 ))) { + t->block_bad =0 ; +if (pt->should_be_ff !=0xFFFFFFFF ) + t->block_bad =1 ; + t->chunk_used =1 ; + t->obj_id = pt->obj_id; + t->chunk_id = pt->chunk_id; + t->n_bytes = pt->n_bytes; + t->ecc_result =YAFFS_ECC_RESULT_NO_ERROR ; + t->is_deleted = (pt->deleted) ?0 :1 ; + t->serial_number = pt->serial_number; + }else { +memset (t,0 ,sizeof (struct yaffs_ext_tags )); + } +}fs/yaffs2/yaffs_packedtags1.h new file +39
-0@@ -0,0 +1,39 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +/* This is used to pack YAFFS1 tags, not YAFFS2 tags. */ + +#ifndef __YAFFS_PACKEDTAGS1_H__ +#define __YAFFS_PACKEDTAGS1_H__ + +#include "yaffs_guts.h" + +struct yaffs_packed_tags1 { +unsigned chunk_id:20 ; +unsigned serial_number:2 ; +unsigned n_bytes:10 ; +unsigned obj_id:18 ; +unsigned ecc:12 ; +unsigned deleted:1 ; +unsigned unused_stuff:1 ; +unsigned should_be_ff; + +}; + +void yaffs_pack_tags1 (struct yaffs_packed_tags1 *pt, +const struct yaffs_ext_tags *t); +void yaffs_unpack_tags1 (struct yaffs_ext_tags *t, +const struct yaffs_packed_tags1 *pt); +#endif fs/yaffs2/yaffs_packedtags2.c new file +197
-0@@ -0,0 +1,197 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_packedtags2.h" +#include "yportenv.h" +#include "yaffs_trace.h" +#include "yaffs_tagsvalidity.h" + +/* This code packs a set of extended tags into a binary structure for +* NAND storage +*/ + +/* Some of the information is "extra" struff which can be packed in to +* speed scanning +* This is defined by having the EXTRA_HEADER_INFO_FLAG set. +*/ + +/* Extra flags applied to chunk_id */ + +#define EXTRA_HEADER_INFO_FLAG 0x80000000 +#define EXTRA_SHRINK_FLAG 0x40000000 +#define EXTRA_SHADOWS_FLAG 0x20000000 +#define EXTRA_SPARE_FLAGS 0x10000000 + +#define ALL_EXTRA_FLAGS 0xF0000000 + +/* Also, the top 4 bits of the object Id are set to the object type. */ +#define EXTRA_OBJECT_TYPE_SHIFT (28) +#define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT) + +static void yaffs_dump_packed_tags2_tags_only (const struct +yaffs_packed_tags2_tags_only *ptt) +{ +T (YAFFS_TRACE_MTD , + (TSTR ("packed tags obj %d chunk %d byte %d seq %d" TENDSTR ), + ptt->obj_id, ptt->chunk_id, ptt->n_bytes, ptt->seq_number)); +} + +static void yaffs_dump_packed_tags2 (const struct yaffs_packed_tags2 *pt) +{ +yaffs_dump_packed_tags2_tags_only (&pt->t); +} + +static void yaffs_dump_tags2 (const struct yaffs_ext_tags *t) +{ +T (YAFFS_TRACE_MTD , + (TSTR + ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d" +TENDSTR ), t->ecc_result, t->block_bad, t->chunk_used, t->obj_id, + t->chunk_id, t->n_bytes, t->is_deleted, t->serial_number, + t->seq_number)); + +} + +void yaffs_pack_tags2_tags_only (struct yaffs_packed_tags2_tags_only *ptt, +const struct yaffs_ext_tags *t) +{ + ptt->chunk_id = t->chunk_id; + ptt->seq_number = t->seq_number; + ptt->n_bytes = t->n_bytes; + ptt->obj_id = t->obj_id; + +if (t->chunk_id ==0 && t->extra_available) { +/* Store the extra header info instead */ +/* We save the parent object in the chunk_id */ + ptt->chunk_id =EXTRA_HEADER_INFO_FLAG | t->extra_parent_id; +if (t->extra_is_shrink) + ptt->chunk_id |=EXTRA_SHRINK_FLAG ; +if (t->extra_shadows) + ptt->chunk_id |=EXTRA_SHADOWS_FLAG ; + + ptt->obj_id &= ~EXTRA_OBJECT_TYPE_MASK ; + ptt->obj_id |= (t->extra_obj_type <<EXTRA_OBJECT_TYPE_SHIFT ); + +if (t->extra_obj_type ==YAFFS_OBJECT_TYPE_HARDLINK ) + ptt->n_bytes = t->extra_equiv_id; +else if (t->extra_obj_type ==YAFFS_OBJECT_TYPE_FILE ) + ptt->n_bytes = t->extra_length; +else + ptt->n_bytes =0 ; + } + +yaffs_dump_packed_tags2_tags_only (ptt); +yaffs_dump_tags2 (t); +} + +void yaffs_pack_tags2 (struct yaffs_packed_tags2 *pt, +const struct yaffs_ext_tags *t,int tags_ecc) +{ +yaffs_pack_tags2_tags_only (&pt->t, t); + +if (tags_ecc) +yaffs_ecc_calc_other ((unsigned char *)&pt->t, +sizeof (struct +yaffs_packed_tags2_tags_only ), + &pt->ecc); +} + +void yaffs_unpack_tags2_tags_only (struct yaffs_ext_tags *t, +struct yaffs_packed_tags2_tags_only *ptt) +{ + +memset (t,0 ,sizeof (struct yaffs_ext_tags )); + +yaffs_init_tags (t); + +if (ptt->seq_number !=0xFFFFFFFF ) { + t->block_bad =0 ; + t->chunk_used =1 ; + t->obj_id = ptt->obj_id; + t->chunk_id = ptt->chunk_id; + t->n_bytes = ptt->n_bytes; + t->is_deleted =0 ; + t->serial_number =0 ; + t->seq_number = ptt->seq_number; + +/* Do extra header info stuff */ + +if (ptt->chunk_id &EXTRA_HEADER_INFO_FLAG ) { + t->chunk_id =0 ; + t->n_bytes =0 ; + + t->extra_available =1 ; + t->extra_parent_id = + ptt->chunk_id & (~(ALL_EXTRA_FLAGS )); + t->extra_is_shrink = + (ptt->chunk_id &EXTRA_SHRINK_FLAG ) ?1 :0 ; + t->extra_shadows = + (ptt->chunk_id &EXTRA_SHADOWS_FLAG ) ?1 :0 ; + t->extra_obj_type = + ptt->obj_id >>EXTRA_OBJECT_TYPE_SHIFT ; + t->obj_id &= ~EXTRA_OBJECT_TYPE_MASK ; + +if (t->extra_obj_type ==YAFFS_OBJECT_TYPE_HARDLINK ) + t->extra_equiv_id = ptt->n_bytes; +else + t->extra_length = ptt->n_bytes; + } + } + +yaffs_dump_packed_tags2_tags_only (ptt); +yaffs_dump_tags2 (t); + +} + +void yaffs_unpack_tags2 (struct yaffs_ext_tags *t,struct yaffs_packed_tags2 *pt, +int tags_ecc) +{ + +enum yaffs_ecc_result ecc_result =YAFFS_ECC_RESULT_NO_ERROR ; + +if (pt->t.seq_number !=0xFFFFFFFF && tags_ecc) { +/* Chunk is in use and we need to do ECC */ + +struct yaffs_ecc_other ecc; +int result; +yaffs_ecc_calc_other ((unsigned char *)&pt->t, +sizeof (struct +yaffs_packed_tags2_tags_only ), + &ecc); + result = +yaffs_ecc_correct_other ((unsigned char *)&pt->t, +sizeof (struct +yaffs_packed_tags2_tags_only ), + &pt->ecc, &ecc); +switch (result) { +case 0 : + ecc_result =YAFFS_ECC_RESULT_NO_ERROR ; +break ; +case 1 : + ecc_result =YAFFS_ECC_RESULT_FIXED ; +break ; +case -1 : + ecc_result =YAFFS_ECC_RESULT_UNFIXED ; +break ; +default : + ecc_result =YAFFS_ECC_RESULT_UNKNOWN ; + } + } + +yaffs_unpack_tags2_tags_only (t, &pt->t); + + t->ecc_result = ecc_result; + +yaffs_dump_packed_tags2 (pt); +yaffs_dump_tags2 (t); +}fs/yaffs2/yaffs_packedtags2.h new file +47
-0@@ -0,0 +1,47 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +/* This is used to pack YAFFS2 tags, not YAFFS1tags. */ + +#ifndef __YAFFS_PACKEDTAGS2_H__ +#define __YAFFS_PACKEDTAGS2_H__ + +#include "yaffs_guts.h" +#include "yaffs_ecc.h" + +struct yaffs_packed_tags2_tags_only { +unsigned seq_number; +unsigned obj_id; +unsigned chunk_id; +unsigned n_bytes; +}; + +struct yaffs_packed_tags2 { +struct yaffs_packed_tags2_tags_only t; +struct yaffs_ecc_other ecc; +}; + +/* Full packed tags with ECC, used for oob tags */ +void yaffs_pack_tags2 (struct yaffs_packed_tags2 *pt, +const struct yaffs_ext_tags *t,int tags_ecc); +void yaffs_unpack_tags2 (struct yaffs_ext_tags *t,struct yaffs_packed_tags2 *pt, +int tags_ecc); + +/* Only the tags part (no ECC for use with inband tags */ +void yaffs_pack_tags2_tags_only (struct yaffs_packed_tags2_tags_only *pt, +const struct yaffs_ext_tags *t); +void yaffs_unpack_tags2_tags_only (struct yaffs_ext_tags *t, +struct yaffs_packed_tags2_tags_only *pt); +#endif fs/yaffs2/yaffs_tagscompat.c new file +15
-0@@ -0,0 +1,429 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_guts.h" +#include "yaffs_tagscompat.h"
fs/yaffs2/yaffs_tagscompat.c line 25
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+#include "yaffs_ecc.h" +#include "yaffs_getblockinfo.h" +#include "yaffs_trace.h" + +static void yaffs_handle_rd_data_error (struct yaffs_dev *dev,int nand_chunk); + + +/********** Tags ECC calculations *********/ + +void yaffs_calc_ecc (const u8 * data,struct yaffs_spare *spare)
void yaffs_calc_ecc(const u8 *data, struct yaffs_spare *spare)
Quoted 41 lines
fs/yaffs2/yaffs_tagscompat.c new file +41
-0+{ +yaffs_ecc_cacl (data, spare->ecc1); +yaffs_ecc_cacl (&data[256 ], spare->ecc2); +} + +void yaffs_calc_tags_ecc (struct yaffs_tags *tags) +{ +/* Calculate an ecc */ + +unsigned char *b = ((union yaffs_tags_union *)tags)->as_bytes; +unsigned i, j; +unsigned ecc =0 ; +unsigned bit =0 ; + + tags->ecc =0 ; + +for (i =0 ; i <8 ; i++) { +for (j =1 ; j &0xff ; j <<=1 ) { + bit++; +if (b[i] & j) + ecc ^= bit; + } + } + + tags->ecc = ecc; + +} + +int yaffs_check_tags_ecc (struct yaffs_tags *tags) +{ +unsigned ecc = tags->ecc; + +yaffs_calc_tags_ecc (tags); + + ecc ^= tags->ecc; + +if (ecc && ecc <=64 ) { +/* TODO: Handle the failure better. Retire? */ +unsigned char *b = ((union yaffs_tags_union *)tags)->as_bytes; + + ecc--;
fs/yaffs2/yaffs_tagscompat.c line 76
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+ + b[ecc /8 ] ^= (1 << (ecc &7 )); + +/* Now recvalc the ecc */ +yaffs_calc_tags_ecc (tags); + +return 1 ;/* recovered error */ + }else if (ecc) { +/* Wierd ecc failure value */ +/* TODO Need to do somethiong here */
You misspelled "something".
Quoted 46 lines
fs/yaffs2/yaffs_tagscompat.c new file +46
-0+return -1 ;/* unrecovered error */ + } + +return 0 ; +} + +/********** Tags **********/ + +static void yaffs_load_tags_to_spare (struct yaffs_spare *spare_ptr, +struct yaffs_tags *tags_ptr) +{ +union yaffs_tags_union *tu = (union yaffs_tags_union *)tags_ptr; + +yaffs_calc_tags_ecc (tags_ptr); + + spare_ptr->tb0 = tu->as_bytes[0 ]; + spare_ptr->tb1 = tu->as_bytes[1 ]; + spare_ptr->tb2 = tu->as_bytes[2 ]; + spare_ptr->tb3 = tu->as_bytes[3 ]; + spare_ptr->tb4 = tu->as_bytes[4 ]; + spare_ptr->tb5 = tu->as_bytes[5 ]; + spare_ptr->tb6 = tu->as_bytes[6 ]; + spare_ptr->tb7 = tu->as_bytes[7 ]; +} + +static void yaffs_get_tags_from_spare (struct yaffs_dev *dev, +struct yaffs_spare *spare_ptr, +struct yaffs_tags *tags_ptr) +{ +union yaffs_tags_union *tu = (union yaffs_tags_union *)tags_ptr; +int result; + + tu->as_bytes[0 ] = spare_ptr->tb0; + tu->as_bytes[1 ] = spare_ptr->tb1; + tu->as_bytes[2 ] = spare_ptr->tb2; + tu->as_bytes[3 ] = spare_ptr->tb3; + tu->as_bytes[4 ] = spare_ptr->tb4; + tu->as_bytes[5 ] = spare_ptr->tb5; + tu->as_bytes[6 ] = spare_ptr->tb6; + tu->as_bytes[7 ] = spare_ptr->tb7; + + result =yaffs_check_tags_ecc (tags_ptr); +if (result >0 ) + dev->n_tags_ecc_fixed++; +else if (result <0 ) + dev->n_tags_ecc_unfixed++;
fs/yaffs2/yaffs_tagscompat.c line 132
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+} + +static void yaffs_spare_init (struct yaffs_spare *spare) +{ +memset (spare,0xFF ,sizeof (struct yaffs_spare )); +} + +static int yaffs_wr_nand (struct yaffs_dev *dev, +int nand_chunk,const u8 * data, +struct yaffs_spare *spare)
static int yaffs_wr_nand(struct yaffs_dev *dev,
int nand_chunk, const u8 *data, struct yaffs_spare *spare)
Quoted 7 lines
fs/yaffs2/yaffs_tagscompat.c new file +7
-0+{ +if (nand_chunk < dev->param.start_block * dev->param.chunks_per_block) { +T (YAFFS_TRACE_ERROR , + (TSTR ("**>> yaffs chunk %d is not valid" TENDSTR ), + nand_chunk)); +return YAFFS_FAIL ; + }
fs/yaffs2/yaffs_tagscompat.c line 149
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+ +return dev->param.write_chunk_fn (dev, nand_chunk, data, spare); +} + +static int yaffs_rd_chunk_nand (struct yaffs_dev *dev, +int nand_chunk, +u8 * data, +struct yaffs_spare *spare, +enum yaffs_ecc_result *ecc_result, +int correct_errors)
static int yaffs_rd_chunk_nand(struct yaffs_dev *dev,
int nand_chunk,
u8 *data,
struct yaffs_spare *spare, enum yaffs_ecc_result *ecc_result, int correct_errors)
Quoted 135 lines
fs/yaffs2/yaffs_tagscompat.c new file +135
-0+{ +int ret_val; +struct yaffs_spare local_spare; + +if (!spare && data) { +/* If we don't have a real spare, then we use a local one. */ +/* Need this for the calculation of the ecc */ + spare = &local_spare; + } + +if (!dev->param.use_nand_ecc) { + ret_val = + dev->param.read_chunk_fn (dev, nand_chunk, data, spare); +if (data && correct_errors) { +/* Do ECC correction */ +/* Todo handle any errors */ +int ecc_result1, ecc_result2; +u8 calc_ecc[3 ]; + +yaffs_ecc_cacl (data, calc_ecc); + ecc_result1 = +yaffs_ecc_correct (data, spare->ecc1, calc_ecc); +yaffs_ecc_cacl (&data[256 ], calc_ecc); + ecc_result2 = +yaffs_ecc_correct (&data[256 ], spare->ecc2, + calc_ecc); + +if (ecc_result1 >0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>yaffs ecc error fix performed on chunk %d:0" +TENDSTR ), nand_chunk)); + dev->n_ecc_fixed++; + }else if (ecc_result1 <0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>yaffs ecc error unfixed on chunk %d:0" +TENDSTR ), nand_chunk)); + dev->n_ecc_unfixed++; + } + +if (ecc_result2 >0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>yaffs ecc error fix performed on chunk %d:1" +TENDSTR ), nand_chunk)); + dev->n_ecc_fixed++; + }else if (ecc_result2 <0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>yaffs ecc error unfixed on chunk %d:1" +TENDSTR ), nand_chunk)); + dev->n_ecc_unfixed++; + } + +if (ecc_result1 || ecc_result2) { +/* We had a data problem on this page */ +yaffs_handle_rd_data_error (dev, nand_chunk); + } + +if (ecc_result1 <0 || ecc_result2 <0 ) + *ecc_result =YAFFS_ECC_RESULT_UNFIXED ; +else if (ecc_result1 >0 || ecc_result2 >0 ) + *ecc_result =YAFFS_ECC_RESULT_FIXED ; +else + *ecc_result =YAFFS_ECC_RESULT_NO_ERROR ; + } + }else { +/* Must allocate enough memory for spare+2*sizeof(int) */ +/* for ecc results from device. */ +struct yaffs_nand_spare nspare; + +memset (&nspare,0 ,sizeof (nspare)); + + ret_val = dev->param.read_chunk_fn (dev, nand_chunk, data, + (struct yaffs_spare *) + &nspare); +memcpy (spare, &nspare,sizeof (struct yaffs_spare )); +if (data && correct_errors) { +if (nspare.eccres1 >0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>mtd ecc error fix performed on chunk %d:0" +TENDSTR ), nand_chunk)); + }else if (nspare.eccres1 <0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>mtd ecc error unfixed on chunk %d:0" +TENDSTR ), nand_chunk)); + } + +if (nspare.eccres2 >0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>mtd ecc error fix performed on chunk %d:1" +TENDSTR ), nand_chunk)); + }else if (nspare.eccres2 <0 ) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>>mtd ecc error unfixed on chunk %d:1" +TENDSTR ), nand_chunk)); + } + +if (nspare.eccres1 || nspare.eccres2) { +/* We had a data problem on this page */ +yaffs_handle_rd_data_error (dev, nand_chunk); + } + +if (nspare.eccres1 <0 || nspare.eccres2 <0 ) + *ecc_result =YAFFS_ECC_RESULT_UNFIXED ; +else if (nspare.eccres1 >0 || nspare.eccres2 >0 ) + *ecc_result =YAFFS_ECC_RESULT_FIXED ; +else + *ecc_result =YAFFS_ECC_RESULT_NO_ERROR ; + + } + } +return ret_val; +} + +/* +* Functions for robustisizing +*/ + +static void yaffs_handle_rd_data_error (struct yaffs_dev *dev,int nand_chunk) +{ +int flash_block = nand_chunk / dev->param.chunks_per_block; + +/* Mark the block for retirement */ +yaffs_get_block_info (dev, + flash_block + dev->block_offset)->needs_retiring = +1 ; +T (YAFFS_TRACE_ERROR |YAFFS_TRACE_BAD_BLOCKS , + (TSTR ("**>>Block %d marked for retirement" TENDSTR ), flash_block)); +
fs/yaffs2/yaffs_tagscompat.c line 294
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+/* TODO: +* Just do a garbage collection on the affected block +* then retire the block +* NB recursion +*/ +} + +int yaffs_tags_compat_wr (struct yaffs_dev *dev, +int nand_chunk, +const u8 * data,const struct yaffs_ext_tags *ext_tags)
int yaffs_tags_compat_wr(struct yaffs_dev *dev,
int nand_chunk,
const u8 *data, const struct yaffs_ext_tags *ext_tags)
Quoted 24 lines
fs/yaffs2/yaffs_tagscompat.c new file +24
-0+{ +struct yaffs_spare spare; +struct yaffs_tags tags; + +yaffs_spare_init (&spare); + +if (ext_tags->is_deleted) + spare.page_status =0 ; +else { + tags.obj_id = ext_tags->obj_id; + tags.chunk_id = ext_tags->chunk_id; + + tags.n_bytes_lsb = ext_tags->n_bytes &0x3ff ; + +if (dev->data_bytes_per_chunk >=1024 ) + tags.n_bytes_msb = (ext_tags->n_bytes >>10 ) &3 ; +else + tags.n_bytes_msb =3 ; + + tags.serial_number = ext_tags->serial_number; + +if (!dev->param.use_nand_ecc && data) +yaffs_calc_ecc (data, &spare); +
fs/yaffs2/yaffs_tagscompat.c line 328
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+yaffs_load_tags_to_spare (&spare, &tags); + + } + +return yaffs_wr_nand (dev, nand_chunk, data, &spare); +} + +int yaffs_tags_compat_rd (struct yaffs_dev *dev, +int nand_chunk, +u8 * data,struct yaffs_ext_tags *ext_tags)
int yaffs_tags_compat_rd(struct yaffs_dev *dev,
int nand_chunk,
u8 *data, struct yaffs_ext_tags *ext_tags)
Quoted 58 lines
fs/yaffs2/yaffs_tagscompat.c new file +58
-0+{ + +struct yaffs_spare spare; +struct yaffs_tags tags; +enum yaffs_ecc_result ecc_result =YAFFS_ECC_RESULT_UNKNOWN ; + +static struct yaffs_spare spare_ff; +static int init; + +if (!init) { +memset (&spare_ff,0xFF ,sizeof (spare_ff)); + init =1 ; + } + +if (yaffs_rd_chunk_nand (dev, nand_chunk, data, &spare, &ecc_result,1 )) { +/* ext_tags may be NULL */ +if (ext_tags) { + +int deleted = + (hweight8 (spare.page_status) <7 ) ?1 :0 ; + + ext_tags->is_deleted = deleted; + ext_tags->ecc_result = ecc_result; + ext_tags->block_bad =0 ;/* We're reading it */ +/* therefore it is not a bad block */ + ext_tags->chunk_used = + (memcmp (&spare_ff, &spare,sizeof (spare_ff)) != +0 ) ?1 :0 ; + +if (ext_tags->chunk_used) { +yaffs_get_tags_from_spare (dev, &spare, &tags); + + ext_tags->obj_id = tags.obj_id; + ext_tags->chunk_id = tags.chunk_id; + ext_tags->n_bytes = tags.n_bytes_lsb; + +if (dev->data_bytes_per_chunk >=1024 ) + ext_tags->n_bytes |= + (((unsigned )tags. + n_bytes_msb) <<10 ); + + ext_tags->serial_number = tags.serial_number; + } + } + +return YAFFS_OK ; + }else { +return YAFFS_FAIL ; + } +} + +int yaffs_tags_compat_mark_bad (struct yaffs_dev *dev,int flash_block) +{ + +struct yaffs_spare spare; + +memset (&spare,0xff ,sizeof (struct yaffs_spare )); +
fs/yaffs2/yaffs_tagscompat.c line 396
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.c new file +10
-0+ spare.block_status ='Y' ; + +yaffs_wr_nand (dev, flash_block * dev->param.chunks_per_block,NULL , + &spare); +yaffs_wr_nand (dev, flash_block * dev->param.chunks_per_block +1 , +NULL , &spare); + +return YAFFS_OK ; + +}
Why does this function have a blank line at the beginning and at the end? Just remove those.
On a more serious note; while reviewing these patches I've seen a lot of functions that return int but only ever return a single fixed value. I can see the point of this for some of them since they are ment to be assigned to function pointers that expect a specific signature, but for some I'm left wondering if they really shouldn't just be returning 'void'...
fs/yaffs2/yaffs_tagscompat.c line 401
Quoted 5 lines
fs/yaffs2/yaffs_tagscompat.c new file +5
-0+ +int yaffs_tags_compat_query_block (struct yaffs_dev *dev, +int block_no, +enum yaffs_block_state *state, +u32 * seq_number)
int yaffs_tags_compat_query_block(struct yaffs_dev *dev,
int block_no,
enum yaffs_block_state *state, u32 *seq_number)
Quoted 46 lines
fs/yaffs2/yaffs_tagscompat.c new file +28
-0+{ + +struct yaffs_spare spare0, spare1; +static struct yaffs_spare spare_ff; +static int init; +enum yaffs_ecc_result dummy; + +if (!init) { +memset (&spare_ff,0xFF ,sizeof (spare_ff)); + init =1 ; + } + + *seq_number =0 ; + +yaffs_rd_chunk_nand (dev, block_no * dev->param.chunks_per_block,NULL , + &spare0, &dummy,1 ); +yaffs_rd_chunk_nand (dev, block_no * dev->param.chunks_per_block +1 , +NULL , &spare1, &dummy,1 ); + +if (hweight8 (spare0.block_status & spare1.block_status) <7 ) + *state =YAFFS_BLOCK_STATE_DEAD ; +else if (memcmp (&spare_ff, &spare0,sizeof (spare_ff)) ==0 ) + *state =YAFFS_BLOCK_STATE_EMPTY ; +else + *state =YAFFS_BLOCK_STATE_NEEDS_SCANNING ; + +return YAFFS_OK ; +}fs/yaffs2/yaffs_tagscompat.h new file +12
-0@@ -0,0 +1,36 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +*
fs/yaffs2/yaffs_tagscompat.h line 22
Quoted 10 lines
fs/yaffs2/yaffs_tagscompat.h new file +10
-0+* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_TAGSCOMPAT_H__ +#define __YAFFS_TAGSCOMPAT_H__ + +#include "yaffs_guts.h" +int yaffs_tags_compat_wr (struct yaffs_dev *dev, +int nand_chunk, +const u8 * data,const struct yaffs_ext_tags *tags);
int yaffs_tags_compat_wr(struct yaffs_dev *dev,
int nand_chunk,
const u8 *data, const struct yaffs_ext_tags *tags);fs/yaffs2/yaffs_tagscompat.h line 25
Quoted 3 lines
fs/yaffs2/yaffs_tagscompat.h new file +3
-0+int yaffs_tags_compat_rd (struct yaffs_dev *dev, +int nand_chunk, +u8 * data,struct yaffs_ext_tags *tags);
int yaffs_tags_compat_rd(struct yaffs_dev *dev,
int nand_chunk,
u8 *data, struct yaffs_ext_tags *tags);fs/yaffs2/yaffs_tagscompat.h line 30
Quoted 5 lines
fs/yaffs2/yaffs_tagscompat.h new file +5
-0+int yaffs_tags_compat_mark_bad (struct yaffs_dev *dev,int block_no); +int yaffs_tags_compat_query_block (struct yaffs_dev *dev, +int block_no, +enum yaffs_block_state *state, +u32 * seq_number);
int yaffs_tags_compat_query_block(struct yaffs_dev *dev,
int block_no,
enum yaffs_block_state *state, u32 *seq_number);
Quoted 7 lines
fs/yaffs2/yaffs_tagscompat.h new file +6
-0+ +void yaffs_calc_tags_ecc (struct yaffs_tags *tags); +int yaffs_check_tags_ecc (struct yaffs_tags *tags); +int yaffs_count_bits (u8 byte); + +#endif
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
PATCH 5/8 Add yaffs2 file system: mtd and flash handling code
In reply to Charles Manning--- fs/yaffs2/yaffs_mtdif.c | 54 ++++++++ fs/yaffs2/yaffs_mtdif.h | 23 ++++ fs/yaffs2/yaffs_mtdif1.c | 331 ++++++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_mtdif1.h | 29 ++++ fs/yaffs2/yaffs_mtdif2.c | 226 +++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_mtdif2.h | 29 ++++ fs/yaffs2/yaffs_nand.c | 128 ++++++++++++++++++ fs/yaffs2/yaffs_nand.h | 38 ++++++ 8 files changed, 858 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_mtdif.c create mode 100644 fs/yaffs2/yaffs_mtdif.h create mode 100644 fs/yaffs2/yaffs_mtdif1.c create mode 100644 fs/yaffs2/yaffs_mtdif1.h create mode 100644 fs/yaffs2/yaffs_mtdif2.c create mode 100644 fs/yaffs2/yaffs_mtdif2.h create mode 100644 fs/yaffs2/yaffs_nand.c create mode 100644 fs/yaffs2/yaffs_nand.h
fs/yaffs2/yaffs_mtdif.c new file +54 -0
@@ -0,0 +1,54 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yportenv.h" + +#include "yaffs_mtdif.h" + +#include "linux/mtd/mtd.h" +#include "linux/types.h" +#include "linux/time.h" +#include "linux/mtd/nand.h" + +#include "yaffs_linux.h" + +int nandmtd_erase_block (struct yaffs_dev *dev,int block_no) +{ +struct mtd_info *mtd =yaffs_dev_to_mtd (dev); +u32 addr = + ((loff_t ) block_no) * dev->param.total_bytes_per_chunk + * dev->param.chunks_per_block; +struct erase_info ei; + +int retval =0 ; + + ei.mtd = mtd; + ei.addr = addr; + ei.len = dev->param.total_bytes_per_chunk * dev->param.chunks_per_block; + ei.time =1000 ; + ei.retries =2 ; + ei.callback =NULL ; + ei.priv = (u_long ) dev; + + retval = mtd->erase (mtd, &ei); + +if (retval ==0 ) +return YAFFS_OK ; +else +return YAFFS_FAIL ; +} + +int nandmtd_initialise (struct yaffs_dev *dev) +{ +return YAFFS_OK ; +}
fs/yaffs2/yaffs_mtdif.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_MTDIF_H__ +#define __YAFFS_MTDIF_H__ + +#include "yaffs_guts.h" + +int nandmtd_erase_block (struct yaffs_dev *dev,int block_no); +int nandmtd_initialise (struct yaffs_dev *dev); +#endif
fs/yaffs2/yaffs_mtdif1.c new file +331 -0
331 lines not on this page · raw message
fs/yaffs2/yaffs_mtdif1.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* YAFFS: Yet another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_MTDIF1_H__ +#define __YAFFS_MTDIF1_H__ + +int nandmtd1_write_chunk_tags (struct yaffs_dev *dev,int nand_chunk, +const u8 * data, +const struct yaffs_ext_tags *tags); + +int nandmtd1_read_chunk_tags (struct yaffs_dev *dev,int nand_chunk, +u8 * data,struct yaffs_ext_tags *tags); + +int nandmtd1_mark_block_bad (struct yaffs_dev *dev,int block_no); + +int nandmtd1_query_block (struct yaffs_dev *dev,int block_no, +enum yaffs_block_state *state,u32 * seq_number); + +#endif
fs/yaffs2/yaffs_mtdif2.c new file +226 -0
226 lines not on this page · raw message
fs/yaffs2/yaffs_mtdif2.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_MTDIF2_H__ +#define __YAFFS_MTDIF2_H__ + +#include "yaffs_guts.h" +int nandmtd2_write_chunk_tags (struct yaffs_dev *dev,int nand_chunk, +const u8 * data, +const struct yaffs_ext_tags *tags); +int nandmtd2_read_chunk_tags (struct yaffs_dev *dev,int nand_chunk, +u8 * data,struct yaffs_ext_tags *tags); +int nandmtd2_mark_block_bad (struct yaffs_dev *dev,int block_no); +int nandmtd2_query_block (struct yaffs_dev *dev,int block_no, +enum yaffs_block_state *state,u32 * seq_number); + +#endif
fs/yaffs2/yaffs_nand.c new file +128 -0
128 lines not on this page · raw message
fs/yaffs2/yaffs_nand.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_NAND_H__ +#define __YAFFS_NAND_H__ +#include "yaffs_guts.h" + +int yaffs_rd_chunk_tags_nand (struct yaffs_dev *dev,int nand_chunk, +u8 * buffer,struct yaffs_ext_tags *tags); + +int yaffs_wr_chunk_tags_nand (struct yaffs_dev *dev, +int nand_chunk, +const u8 * buffer,struct yaffs_ext_tags *tags); + +int yaffs_mark_bad (struct yaffs_dev *dev,int block_no); + +int yaffs_query_init_block_state (struct yaffs_dev *dev, +int block_no, +enum yaffs_block_state *state, +unsigned *seq_number); + +int yaffs_erase_block (struct yaffs_dev *dev,int flash_block); + +int yaffs_init_nand (struct yaffs_dev *dev); + +#endif
Signature · 1 line
1.7.1
Re: [PATCH 5/8] Add yaffs2 file system: mtd and flash handling code
Quoted 2 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
[...]
fs/yaffs2/yaffs_mtdif.c line 23
Quoted 10 lines
fs/yaffs2/yaffs_mtdif.c new file +10
-0+#include "yportenv.h" + +#include "yaffs_mtdif.h" + +#include "linux/mtd/mtd.h" +#include "linux/types.h" +#include "linux/time.h" +#include "linux/mtd/nand.h" + +#include "yaffs_linux.h"
Small thing, but why these blank lines between includes?
fs/yaffs2/yaffs_mtdif.c line 33
Quoted 10 lines
fs/yaffs2/yaffs_mtdif.c new file +10
-0+ +int nandmtd_erase_block (struct yaffs_dev *dev,int block_no) +{ +struct mtd_info *mtd =yaffs_dev_to_mtd (dev); +u32 addr = + ((loff_t ) block_no) * dev->param.total_bytes_per_chunk + * dev->param.chunks_per_block; +struct erase_info ei; + +int retval =0 ;
Why not kill the blank line before "int retval = 0;" ?
Quoted 5 lines
fs/yaffs2/yaffs_mtdif.c new file +5
-0+ + ei.mtd = mtd; + ei.addr = addr; + ei.len = dev->param.total_bytes_per_chunk * dev->param.chunks_per_block; + ei.time =1000 ;
fs/yaffs2/yaffs_mtdif.c line 48
Quoted 10 lines
fs/yaffs2/yaffs_mtdif.c new file +10
-0+ ei.retries =2 ; + ei.callback =NULL ; + ei.priv = (u_long ) dev; + + retval = mtd->erase (mtd, &ei); + +if (retval ==0 ) +return YAFFS_OK ; +else +return YAFFS_FAIL ;
Personal preference thing I guess, but I couldn't help thinking
return mtd->erase(mtd, &ei) ? YAFFS_FAIL : YAFFS_OK;
[...]
fs/yaffs2/yaffs_mtdif1.c line 261
Quoted 2 lines
fs/yaffs2/yaffs_mtdif1.c new file +2
-0+ retval = mtd->block_markbad (mtd, (loff_t ) blocksize * block_no); +return (retval) ?YAFFS_FAIL :YAFFS_OK ;
Pointless parenthesis.
[...]
Quoted 6 lines
fs/yaffs2/yaffs_mtdif2.c new file +6
-0+ +/* mtd interface for YAFFS2 */ + +#include "yportenv.h" +#include "yaffs_trace.h" +
fs/yaffs2/yaffs_mtdif2.c line 28
Quoted 10 lines
fs/yaffs2/yaffs_mtdif2.c new file +10
-0+#include "yaffs_mtdif2.h" + +#include "linux/mtd/mtd.h" +#include "linux/types.h" +#include "linux/time.h" + +#include "yaffs_packedtags2.h" + +#include "yaffs_linux.h" +
Again the blank lines between includes - why?
I can see grouping the "linux/..." includes and the rest and then put a blank line between the two, but the above just looks like a waste of vertical screen space to me.
[...]
fs/yaffs2/yaffs_mtdif2.c line 72
Quoted 4 lines
fs/yaffs2/yaffs_mtdif2.c new file +4
-0+yaffs_pack_tags2_tags_only (pt2tp, tags); + }else { +yaffs_pack_tags2 (&pt, tags, !dev->param.no_tags_ecc); + }
spaces used for indentation where tabs should have been.
[...]
fs/yaffs2/yaffs_nand.c line 121
Quoted 12 lines
fs/yaffs2/yaffs_nand.c new file +12
-0+int yaffs_erase_block (struct yaffs_dev *dev,int flash_block) +{ +int result; + + flash_block -= dev->block_offset; + + dev->n_erasures++; + + result = dev->param.erase_fn (dev, flash_block); + +return result; +}
How about
int yaffs_erase_block(struct yaffs_dev *dev, int flash_block)
{
flash_block -= dev->block_offset;
dev->n_erasures++;
return dev->param.erase_fn(dev, flash_block);
}Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
PATCH 6/8 Add yaffs2 file system: xattrib code
In reply to Charles Manning--- fs/yaffs2/yaffs_nameval.c | 201 +++++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_nameval.h | 28 ++++++ 2 files changed, 229 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_nameval.c create mode 100644 fs/yaffs2/yaffs_nameval.h
fs/yaffs2/yaffs_nameval.c new file +201 -0
@@ -0,0 +1,201 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +/* +* This simple implementation of a name-value store assumes a small number of values and fits +* into a small finite buffer. +* +* Each attribute is stored as a record: +* sizeof(int) bytes record size. +* strnlen+1 bytes name null terminated. +* nbytes value. +* ---------- +* total size stored in record size +* +* This code has not been tested with unicode yet. +*/ + +#include "yaffs_nameval.h" + +#include "yportenv.h" + +static int nval_find (const char *xb,int xb_size,const YCHAR * name, +int *exist_size) +{ +int pos =0 ; +int size; + +memcpy (&size, xb,sizeof (int )); +while (size >0 && (size < xb_size) && (pos + size < xb_size)) { +if (yaffs_strncmp + ((YCHAR *) (xb + pos +sizeof (int )), name, size) ==0 ) { +if (exist_size) + *exist_size = size; +return pos; + } + pos += size; +if (pos < xb_size -sizeof (int )) +memcpy (&size, xb + pos,sizeof (int )); +else + size =0 ; + } +if (exist_size) + *exist_size =0 ; +return -1 ; +} + +static int nval_used (const char *xb,int xb_size) +{ +int pos =0 ; +int size; + +memcpy (&size, xb + pos,sizeof (int )); +while (size >0 && (size < xb_size) && (pos + size < xb_size)) { + pos += size; +if (pos < xb_size -sizeof (int )) +memcpy (&size, xb + pos,sizeof (int )); +else + size =0 ; + } +return pos; +} + +int nval_del (char *xb,int xb_size,const YCHAR * name) +{ +int pos =nval_find (xb, xb_size, name,NULL ); +int size; + +if (pos >=0 && pos < xb_size) { +/* Find size, shift rest over this record, then zero out the rest of buffer */ +memcpy (&size, xb + pos,sizeof (int )); +memcpy (xb + pos, xb + pos + size, xb_size - (pos + size)); +memset (xb + (xb_size - size),0 , size); +return 0 ; + }else { +return -ENODATA ; + } +} + +int nval_set (char *xb,int xb_size,const YCHAR * name,const char *buf, +int bsize,int flags) +{ +int pos; +int namelen =yaffs_strnlen (name, xb_size); +int reclen; +int size_exist =0 ; +int space; +int start; + + pos =nval_find (xb, xb_size, name, &size_exist); + +if (flags &XATTR_CREATE && pos >=0 ) +return -EEXIST ; +if (flags &XATTR_REPLACE && pos <0 ) +return -ENODATA ; + + start =nval_used (xb, xb_size); + space = xb_size - start + size_exist; + + reclen = (sizeof (int ) + namelen +1 + bsize); + +if (reclen > space) +return -ENOSPC ; + +if (pos >=0 ) { +nval_del (xb, xb_size, name); + start =nval_used (xb, xb_size); + } + + pos = start; + +memcpy (xb + pos, &reclen,sizeof (int )); + pos +=sizeof (int ); +yaffs_strncpy ((YCHAR *) (xb + pos), name, reclen); + pos += (namelen +1 ); +memcpy (xb + pos, buf, bsize); +return 0 ; +} + +int nval_get (const char *xb,int xb_size,const YCHAR * name,char *buf, +int bsize) +{ +int pos =nval_find (xb, xb_size, name,NULL ); +int size; + +if (pos >=0 && pos < xb_size) { + +memcpy (&size, xb + pos,sizeof (int )); + pos +=sizeof (int );/* advance past record length */ + size -=sizeof (int ); + +/* Advance over name string */ +while (xb[pos] && size >0 && pos < xb_size) { + pos++; + size--; + } +/*Advance over NUL */ + pos++; + size--; + +if (size <= bsize) { +memcpy (buf, xb + pos, size); +return size; + } + + } +if (pos >=0 ) +return -ERANGE ; +else +return -ENODATA ; +} + +int nval_list (const char *xb,int xb_size,char *buf,int bsize) +{ +int pos =0 ; +int size; +int name_len; +int ncopied =0 ; +int filled =0 ; + +memcpy (&size, xb + pos,sizeof (int )); +while (size >sizeof (int ) && size <= xb_size && (pos + size) < xb_size + && !filled) { + pos +=sizeof (int ); + size -=sizeof (int ); + name_len =yaffs_strnlen ((YCHAR *) (xb + pos), size); +if (ncopied + name_len +1 < bsize) { +memcpy (buf, xb + pos, name_len *sizeof (YCHAR )); + buf += name_len; + *buf ='\0' ; + buf++; +if (sizeof (YCHAR ) >1 ) { + *buf ='\0' ; + buf++; + } + ncopied += (name_len +1 ); + }else { + filled =1 ; + } + pos += size; +if (pos < xb_size -sizeof (int )) +memcpy (&size, xb + pos,sizeof (int )); +else + size =0 ; + } +return ncopied; +} + +int nval_hasvalues (const char *xb,int xb_size) +{ +return nval_used (xb, xb_size) >0 ; +}
fs/yaffs2/yaffs_nameval.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __NAMEVAL_H__ +#define __NAMEVAL_H__ + +#include "yportenv.h" + +int nval_del (char *xb,int xb_size,const YCHAR * name); +int nval_set (char *xb,int xb_size,const YCHAR * name,const char *buf, +int bsize,int flags); +int nval_get (const char *xb,int xb_size,const YCHAR * name,char *buf, +int bsize); +int nval_list (const char *xb,int xb_size,char *buf,int bsize); +int nval_hasvalues (const char *xb,int xb_size); +#endif
Signature · 1 line
1.7.1
Re: [PATCH 6/8] Add yaffs2 file system: xattrib code
A few minor comments can be found below.
Quoted 91 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>--- fs/yaffs2/yaffs_nameval.c | 201 +++++++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_nameval.h | 28 ++++++ 2 files changed, 229 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_nameval.c create mode 100644 fs/yaffs2/yaffs_nameval.hfs/yaffs2/yaffs_nameval.c new file +77
-0@@ -0,0 +1,201 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +/* +* This simple implementation of a name-value store assumes a small number of values and fits +* into a small finite buffer. +* +* Each attribute is stored as a record: +* sizeof(int) bytes record size. +* strnlen+1 bytes name null terminated. +* nbytes value. +* ---------- +* total size stored in record size +* +* This code has not been tested with unicode yet. +*/ + +#include "yaffs_nameval.h" + +#include "yportenv.h" + +static int nval_find (const char *xb,int xb_size,const YCHAR * name, +int *exist_size) +{ +int pos =0 ; +int size; + +memcpy (&size, xb,sizeof (int )); +while (size >0 && (size < xb_size) && (pos + size < xb_size)) { +if (yaffs_strncmp + ((YCHAR *) (xb + pos +sizeof (int )), name, size) ==0 ) { +if (exist_size) + *exist_size = size; +return pos; + } + pos += size; +if (pos < xb_size -sizeof (int )) +memcpy (&size, xb + pos,sizeof (int )); +else + size =0 ; + } +if (exist_size) + *exist_size =0 ; +return -1 ; +} + +static int nval_used (const char *xb,int xb_size) +{ +int pos =0 ; +int size; + +memcpy (&size, xb + pos,sizeof (int )); +while (size >0 && (size < xb_size) && (pos + size < xb_size)) { + pos += size; +if (pos < xb_size -sizeof (int )) +memcpy (&size, xb + pos,sizeof (int )); +else + size =0 ; + } +return pos; +} + +int nval_del (char *xb,int xb_size,const YCHAR * name) +{ +int pos =nval_find (xb, xb_size, name,NULL ); +int size; +
fs/yaffs2/yaffs_nameval.c line 87
Quoted 10 lines
fs/yaffs2/yaffs_nameval.c new file +10
-0+if (pos >=0 && pos < xb_size) { +/* Find size, shift rest over this record, then zero out the rest of buffer */ +memcpy (&size, xb + pos,sizeof (int )); +memcpy (xb + pos, xb + pos + size, xb_size - (pos + size)); +memset (xb + (xb_size - size),0 , size); +return 0 ; + }else { +return -ENODATA ; + } +}
Why not get rid of the 'else' branch and simply write this as
int nval_del(char *xb, int xb_size, const YCHAR *name)
{
int pos = nval_find(xb, xb_size, name, NULL);
int size;
if (pos >= 0 && pos < xb_size) {
/* Find size, shift rest over this record, then zero out the rest of buffer */
memcpy(&size, xb + pos, sizeof(int));
memcpy(xb + pos, xb + pos + size, xb_size - (pos + size));
memset(xb + (xb_size - size), 0, size);
return 0;
}
return -ENODATA;
}fs/yaffs2/yaffs_nameval.c line 89
Quoted 2 lines
fs/yaffs2/yaffs_nameval.c new file +2
-0+ +int nval_set(char *xb, int xb_size, const YCHAR * name, const char *buf,
^^^^^
Why this insistance on making pointer variables look like multiplication...?
int* foo; // prefered by many C++ people
int *foo; // prefered by many C people
int * foo; // just plain ugly
(this is not the only location, but I'm not going to point out any more)
Quoted 89 lines
fs/yaffs2/yaffs_nameval.c new file +89
-0+ int bsize, int flags) +{ + int pos; +int namelen =yaffs_strnlen (name, xb_size); +int reclen; +int size_exist =0 ; +int space; +int start; + + pos =nval_find (xb, xb_size, name, &size_exist); + +if (flags &XATTR_CREATE && pos >=0 ) +return -EEXIST ; +if (flags &XATTR_REPLACE && pos <0 ) +return -ENODATA ; + + start =nval_used (xb, xb_size); + space = xb_size - start + size_exist; + + reclen = (sizeof (int ) + namelen +1 + bsize); + +if (reclen > space) +return -ENOSPC ; + +if (pos >=0 ) { +nval_del (xb, xb_size, name); + start =nval_used (xb, xb_size); + } + + pos = start; + +memcpy (xb + pos, &reclen,sizeof (int )); + pos +=sizeof (int ); +yaffs_strncpy ((YCHAR *) (xb + pos), name, reclen); + pos += (namelen +1 ); +memcpy (xb + pos, buf, bsize); +return 0 ; +} + +int nval_get (const char *xb,int xb_size,const YCHAR * name,char *buf, +int bsize) +{ +int pos =nval_find (xb, xb_size, name,NULL ); +int size; + +if (pos >=0 && pos < xb_size) { + +memcpy (&size, xb + pos,sizeof (int )); + pos +=sizeof (int );/* advance past record length */ + size -=sizeof (int ); + +/* Advance over name string */ +while (xb[pos] && size >0 && pos < xb_size) { + pos++; + size--; + } +/*Advance over NUL */ + pos++; + size--; + +if (size <= bsize) { +memcpy (buf, xb + pos, size); +return size; + } + + } +if (pos >=0 ) +return -ERANGE ; +else +return -ENODATA ; +} + +int nval_list (const char *xb,int xb_size,char *buf,int bsize) +{ +int pos =0 ; +int size; +int name_len; +int ncopied =0 ; +int filled =0 ; + +memcpy (&size, xb + pos,sizeof (int )); +while (size >sizeof (int ) && size <= xb_size && (pos + size) < xb_size + && !filled) { + pos +=sizeof (int ); + size -=sizeof (int ); + name_len =yaffs_strnlen ((YCHAR *) (xb + pos), size); +if (ncopied + name_len +1 < bsize) { +memcpy (buf, xb + pos, name_len *sizeof (YCHAR )); + buf += name_len;
fs/yaffs2/yaffs_nameval.c line 188
Quoted 10 lines
fs/yaffs2/yaffs_nameval.c new file +10
-0+ *buf ='\0' ; + buf++; +if (sizeof (YCHAR ) >1 ) { + *buf ='\0' ; + buf++; + } + ncopied += (name_len +1 ); + }else { + filled =1 ; + }
Trivial little nit. The line above this comment is indented with spaces, not tabs as it should be.
Quoted 48 lines
fs/yaffs2/yaffs_nameval.c new file +13
-0+ pos += size; +if (pos < xb_size -sizeof (int )) +memcpy (&size, xb + pos,sizeof (int )); +else + size =0 ; + } +return ncopied; +} + +int nval_hasvalues (const char *xb,int xb_size) +{ +return nval_used (xb, xb_size) >0 ; +}fs/yaffs2/yaffs_nameval.h new file +28
-0@@ -0,0 +1,28 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __NAMEVAL_H__ +#define __NAMEVAL_H__ + +#include "yportenv.h" + +int nval_del (char *xb,int xb_size,const YCHAR * name); +int nval_set (char *xb,int xb_size,const YCHAR * name,const char *buf, +int bsize,int flags); +int nval_get (const char *xb,int xb_size,const YCHAR * name,char *buf, +int bsize); +int nval_list (const char *xb,int xb_size,char *buf,int bsize); +int nval_hasvalues (const char *xb,int xb_size); +#endif
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
PATCH 7/8 Add yaffs2 file system: verification code and other headers
In reply to Charles Manning--- fs/yaffs2/yaffs_getblockinfo.h | 36 +++ fs/yaffs2/yaffs_linux.h | 41 +++ fs/yaffs2/yaffs_tagsvalidity.c | 27 ++ fs/yaffs2/yaffs_tagsvalidity.h | 23 ++ fs/yaffs2/yaffs_trace.h | 59 +++++ fs/yaffs2/yaffs_verify.c | 546 ++++++++++++++++++++++++++++++++++++++++ fs/yaffs2/yaffs_verify.h | 43 ++++ fs/yaffs2/yportenv.h | 91 +++++++ 8 files changed, 866 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/yaffs_getblockinfo.h create mode 100644 fs/yaffs2/yaffs_linux.h create mode 100644 fs/yaffs2/yaffs_tagsvalidity.c create mode 100644 fs/yaffs2/yaffs_tagsvalidity.h create mode 100644 fs/yaffs2/yaffs_trace.h create mode 100644 fs/yaffs2/yaffs_verify.c create mode 100644 fs/yaffs2/yaffs_verify.h create mode 100644 fs/yaffs2/yportenv.h
fs/yaffs2/yaffs_getblockinfo.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_GETBLOCKINFO_H__ +#define __YAFFS_GETBLOCKINFO_H__ + +#include "yaffs_guts.h" +#include "yaffs_trace.h" + +/* Function to manipulate block info */ +static Y_INLINE struct yaffs_block_info *yaffs_get_block_info(struct yaffs_dev + *dev,int blk) +{ +if (blk < dev->internal_start_block || blk > dev->internal_end_block) { +T (YAFFS_TRACE_ERROR , + (TSTR + ("**>> yaffs: get_block_info block %d is not valid" TENDSTR ), + blk)); +YBUG (); + } +return &dev->block_info[blk - dev->internal_start_block]; +} + +#endif
fs/yaffs2/yaffs_linux.h new file +41 -0
41 lines not on this page · raw message
fs/yaffs2/yaffs_tagsvalidity.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* YAFFS: Yet Another Flash File System. A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include "yaffs_tagsvalidity.h" + +void yaffs_init_tags (struct yaffs_ext_tags *tags) +{ +memset (tags,0 ,sizeof (struct yaffs_ext_tags )); + tags->validity0 =0xAAAAAAAA ; + tags->validity1 =0x55555555 ; +} + +int yaffs_validate_tags (struct yaffs_ext_tags *tags) +{ +return (tags->validity0 ==0xAAAAAAAA && tags->validity1 ==0x55555555 ); + +}
fs/yaffs2/yaffs_tagsvalidity.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YAFFS_TAGS_VALIDITY_H__ +#define __YAFFS_TAGS_VALIDITY_H__ + +#include "yaffs_guts.h" + +void yaffs_init_tags (struct yaffs_ext_tags *tags); +int yaffs_validate_tags (struct yaffs_ext_tags *tags); +#endif
fs/yaffs2/yaffs_trace.h new file +59 -0
59 lines not on this page · raw message
fs/yaffs2/yaffs_verify.c new file +546 -0
546 lines not on this page · raw message
fs/yaffs2/yaffs_verify.h new file +43 -0
43 lines not on this page · raw message
fs/yaffs2/yportenv.h new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 7/8] Add yaffs2 file system: verification code and other headers
Quoted 2 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
<snip>
Quoted 63 lines
fs/yaffs2/yportenv.h new file +57
-0@@ -0,0 +1,91 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. +* +* Copyright (C) 2002-2010 Aleph One Ltd. +* for Toby Churchill Ltd and Brightstar Engineering +* +* Created by Charles Manning <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 2.1 as +* published by the Free Software Foundation. +* +* Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. +*/ + +#ifndef __YPORTENV_LINUX_H__ +#define __YPORTENV_LINUX_H__ + +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/xattr.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/fs.h> +#include <linux/stat.h> +#include <linux/sort.h> +#include <linux/bitops.h> + +#define YCHAR char +#define YUCHAR unsigned char +#define _Y (x) x +#define yaffs_strcat (a, b) strcat(a, b) +#define yaffs_strcpy (a, b) strcpy(a, b) +#define yaffs_strncpy (a, b, c) strncpy(a, b, c) +#define yaffs_strncmp (a, b, c) strncmp(a, b, c) +#define yaffs_strnlen (s,m) strnlen(s,m) +#define yaffs_sprintf sprintf +#define yaffs_toupper (a) toupper(a) +#define yaffs_sort (base, n, sz, cmp_fn) sort(base, n, sz, cmp_fn, NULL) + +#define Y_INLINE __inline__ + +#define YAFFS_LOSTNFOUND_NAME "lost+found" +#define YAFFS_LOSTNFOUND_PREFIX "obj" + +#define YMALLOC (x) kmalloc(x, GFP_NOFS) +#define YFREE (x) kfree(x) +#define YMALLOC_ALT (x) vmalloc(x) +#define YFREE_ALT (x) vfree(x) +#define YMALLOC_DMA (x) YMALLOC(x) + +#define YYIELD () schedule()
fs/yaffs2/yportenv.h line 67
Quoted 10 lines
fs/yaffs2/yportenv.h new file +10
-0+#define Y_DUMP_STACK () dump_stack() + +#define YAFFS_ROOT_MODE 0755 +#define YAFFS_LOSTNFOUND_MODE 0700 + +#define Y_CURRENT_TIME CURRENT_TIME.tv_sec +#define Y_TIME_CONVERT (x) (x).tv_sec + +#define yaffs_sum_cmp (x, y) ((x) == (y)) +#define yaffs_strcmp (a, b) strcmp(a, b)
You should try and remove the wrappers for as many of these as possible. I know the wrappers are there for portability to other operating systems, but for mainlining in Linux it makes the code more complex.
fs/yaffs2/yportenv.h line 76
Quoted 7 lines
fs/yaffs2/yportenv.h new file +7
-0+#define TENDSTR "\n" +#define TSTR (x) KERN_DEBUG x +#define TCONT (x) x +#define TOUT (p) printk p + +#define compile_time_assertion (assertion) \ + ({ int x = __builtin_choose_expr(assertion, 0, (void)0); (void) x; })
Can you use BUILD_BUG_ON?
fs/yaffs2/yportenv.h line 80
Quoted 3 lines
fs/yaffs2/yportenv.h new file +3
-0+#ifndef Y_DUMP_STACK +#define Y_DUMP_STACK () do { } while (0) +#endif
Y_DUMP_STACK is defined above so this ifdef is useless?
fs/yaffs2/yportenv.h line 88
Quoted 7 lines
fs/yaffs2/yportenv.h new file +7
-0+#ifndef YBUG +#define YBUG () do {\ + T(YAFFS_TRACE_BUG,\ + (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\ + __LINE__));\ + Y_DUMP_STACK();\ +} while (0)
This macro name should possibly be changed since its name implies that it does the same thing as BUG().
~Ryan
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre Ryan Mallon 5 Amuri Park, 404 Barbadoes St [email protected] PO Box 13 889, Christchurch 8013 http://www.bluewatersys.com New Zealand Phone: +64 3 3779127 Freecall: Australia 1800 148 751 Fax: +64 3 3779135 USA 1800 261 2934
Re: [PATCH 7/8] Add yaffs2 file system: verification code and other headers
Quoted 75 lines · On Friday 03 December 2010 09:00:18 Ryan Mallon wrote:
Quoted 2 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
<snip>
Quoted 69 lines
fs/yaffs2/yportenv.h new file +2
-0@@ -0,0 +1,91 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. + *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */fs/yaffs2/yportenv.h new file +49
-0+ +#ifndef __YPORTENV_LINUX_H__ +#define __YPORTENV_LINUX_H__ + +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/xattr.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/fs.h> +#include <linux/stat.h> +#include <linux/sort.h> +#include <linux/bitops.h> + +#define YCHAR char +#define YUCHAR unsigned char +#define _Y (x) x +#define yaffs_strcat (a, b) strcat(a, b) +#define yaffs_strcpy (a, b) strcpy(a, b) +#define yaffs_strncpy (a, b, c) strncpy(a, b, c) +#define yaffs_strncmp (a, b, c) strncmp(a, b, c) +#define yaffs_strnlen (s,m) strnlen(s,m) +#define yaffs_sprintf sprintf +#define yaffs_toupper (a) toupper(a) +#define yaffs_sort (base, n, sz, cmp_fn) sort(base, n, sz, cmp_fn, NULL) + +#define Y_INLINE __inline__ + +#define YAFFS_LOSTNFOUND_NAME "lost+found" +#define YAFFS_LOSTNFOUND_PREFIX "obj" + +#define YMALLOC (x) kmalloc(x, GFP_NOFS) +#define YFREE (x) kfree(x) +#define YMALLOC_ALT (x) vmalloc(x) +#define YFREE_ALT (x) vfree(x) +#define YMALLOC_DMA (x) YMALLOC(x) + +#define YYIELD () schedule() +#define Y_DUMP_STACK () dump_stack() + +#define YAFFS_ROOT_MODE 0755 +#define YAFFS_LOSTNFOUND_MODE 0700 + +#define Y_CURRENT_TIME CURRENT_TIME.tv_sec
Quoted 8 lines
fs/yaffs2/yportenv.h line 68
Quoted 4 lines
fs/yaffs2/yportenv.h new file +4
-0+#define Y_TIME_CONVERT (x) (x).tv_sec + +#define yaffs_sum_cmp (x, y) ((x) == (y)) +#define yaffs_strcmp (a, b) strcmp(a, b)You should try and remove the wrappers for as many of these as possible. I know the wrappers are there for portability to other operating systems, but for mainlining in Linux it makes the code more complex.
Thus far I have tried to keep all the code directly compilable for WinCE and Linux.
I did some investigation over the weekend and I am pretty sure that if I preserve just a few of these macros, YCHAR in particular, I can eliminate almost everything else and just run the code through a sed script to generate the WiNCE version.
I'll do that for the next release.
Charles
Re: [PATCH 7/8] Add yaffs2 file system: verification code and other headers
Quoted 85 lines · Charles Manning
Quoted 75 lines · On Friday 03 December 2010 09:00:18 Ryan Mallon wrote:
Quoted 2 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
<snip>
Quoted 69 lines
fs/yaffs2/yportenv.h new file +2
-0@@ -0,0 +1,91 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. + *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */fs/yaffs2/yportenv.h new file +49
-0+ +#ifndef __YPORTENV_LINUX_H__ +#define __YPORTENV_LINUX_H__ + +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/xattr.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/fs.h> +#include <linux/stat.h> +#include <linux/sort.h> +#include <linux/bitops.h> + +#define YCHAR char +#define YUCHAR unsigned char +#define _Y (x) x +#define yaffs_strcat (a, b) strcat(a, b) +#define yaffs_strcpy (a, b) strcpy(a, b) +#define yaffs_strncpy (a, b, c) strncpy(a, b, c) +#define yaffs_strncmp (a, b, c) strncmp(a, b, c) +#define yaffs_strnlen (s,m) strnlen(s,m) +#define yaffs_sprintf sprintf +#define yaffs_toupper (a) toupper(a) +#define yaffs_sort (base, n, sz, cmp_fn) sort(base, n, sz, cmp_fn, NULL) + +#define Y_INLINE __inline__ + +#define YAFFS_LOSTNFOUND_NAME "lost+found" +#define YAFFS_LOSTNFOUND_PREFIX "obj" + +#define YMALLOC (x) kmalloc(x, GFP_NOFS) +#define YFREE (x) kfree(x) +#define YMALLOC_ALT (x) vmalloc(x) +#define YFREE_ALT (x) vfree(x) +#define YMALLOC_DMA (x) YMALLOC(x) + +#define YYIELD () schedule() +#define Y_DUMP_STACK () dump_stack() + +#define YAFFS_ROOT_MODE 0755 +#define YAFFS_LOSTNFOUND_MODE 0700 + +#define Y_CURRENT_TIME CURRENT_TIME.tv_secQuoted 8 lines
fs/yaffs2/yportenv.h line 68
Quoted 4 lines
fs/yaffs2/yportenv.h new file +4
-0+#define Y_TIME_CONVERT (x) (x).tv_sec + +#define yaffs_sum_cmp (x, y) ((x) == (y)) +#define yaffs_strcmp (a, b) strcmp(a, b)You should try and remove the wrappers for as many of these as possible. I know the wrappers are there for portability to other operating systems, but for mainlining in Linux it makes the code more complex.
Quoted 7 lines
Thus far I have tried to keep all the code directly compilable for WinCE and Linux.
I did some investigation over the weekend and I am pretty sure that if I preserve just a few of these macros, YCHAR in particular, I can eliminate almost everything else and just run the code through a sed script to generate the WiNCE version.
Could YCHAR and YUCHAR be replaced by s8 and u8?
~Ryan
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre Ryan Mallon 5 Amuri Park, 404 Barbadoes St [email protected] PO Box 13 889, Christchurch 8013 http://www.bluewatersys.com New Zealand Phone: +64 3 3779127 Freecall: Australia 1800 148 751 Fax: +64 3 3779135 USA 1800 261 2934
Re: [PATCH 7/8] Add yaffs2 file system: verification code and other headers
Quoted 89 lines · On Monday 06 December 2010 10:45:44 Ryan Mallon wrote:
Quoted 88 lines · Charles Manning
Quoted 75 lines · On Friday 03 December 2010 09:00:18 Ryan Mallon wrote:
Quoted 2 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
<snip>
Quoted 69 lines
fs/yaffs2/yportenv.h new file +2
-0@@ -0,0 +1,91 @@ +/* +* YAFFS: Yet another Flash File System . A NAND-flash specific file system. + *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */fs/yaffs2/yportenv.h new file +30
-0+ +#ifndef __YPORTENV_LINUX_H__ +#define __YPORTENV_LINUX_H__ + +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/sched.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/xattr.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/fs.h> +#include <linux/stat.h> +#include <linux/sort.h> +#include <linux/bitops.h> + +#define YCHAR char +#define YUCHAR unsigned char +#define _Y (x) x +#define yaffs_strcat (a, b) strcat(a, b) +#define yaffs_strcpy (a, b) strcpy(a, b) +#define yaffs_strncpy (a, b, c) strncpy(a, b, c) +#define yaffs_strncmp (a, b, c) strncmp(a, b, c) +#define yaffs_strnlen (s,m) strnlen(s,m) +#define yaffs_sprintf sprintf +#define yaffs_toupper (a) toupper(a) +#define yaffs_sort (base, n, sz, cmp_fn) sort(base, n, sz, cmp_fn,NULL) +
fs/yaffs2/yportenv.h new file +18
-0+#define Y_INLINE __inline__ + +#define YAFFS_LOSTNFOUND_NAME "lost+found" +#define YAFFS_LOSTNFOUND_PREFIX "obj" + +#define YMALLOC (x) kmalloc(x, GFP_NOFS) +#define YFREE (x) kfree(x) +#define YMALLOC_ALT (x) vmalloc(x) +#define YFREE_ALT (x) vfree(x) +#define YMALLOC_DMA (x) YMALLOC(x) + +#define YYIELD () schedule() +#define Y_DUMP_STACK () dump_stack() + +#define YAFFS_ROOT_MODE 0755 +#define YAFFS_LOSTNFOUND_MODE 0700 + +#define Y_CURRENT_TIME CURRENT_TIME.tv_secQuoted 8 lines
fs/yaffs2/yportenv.h line 68
Quoted 4 lines
fs/yaffs2/yportenv.h new file +4
-0+#define Y_TIME_CONVERT (x) (x).tv_sec + +#define yaffs_sum_cmp (x, y) ((x) == (y)) +#define yaffs_strcmp (a, b) strcmp(a, b)You should try and remove the wrappers for as many of these as possible. I know the wrappers are there for portability to other operating systems, but for mainlining in Linux it makes the code more complex.
Thus far I have tried to keep all the code directly compilable for WinCE and Linux.
Quoted 6 lines
Quoted 4 lines
I did some investigation over the weekend and I am pretty sure that if I preserve just a few of these macros, YCHAR in particular, I can eliminate almost everything else and just run the code through a sed script to generate the WiNCE version.
Could YCHAR and YUCHAR be replaced by s8 and u8?
Not without dropping the WinCE usage. WinCE uses a 16-bit wchar.
There are already places where yaffs uses single byte types (eg. buffers) so just changing all chars to wchars will not work.
Using s8 as distinct from char and translating s8 into wchar is too subtle, IMHO.
I think I can get it down to YCHAR and _Y() as a wrapper around strings to be translated, or very close.
-- Charles
Quoted 2 lines
~Ryan
Re: [PATCH 7/8] Add yaffs2 file system: verification code and other headers
In reply to Charles ManningQuoted 46 lines · Charles Manning
fs/yaffs2/yportenv.h new file +46
-0+#define YCHAR char +#define YUCHAR unsigned char +#define _Y (x) x +#define yaffs_strcat (a, b) strcat(a, b) +#define yaffs_strcpy (a, b) strcpy(a, b) +#define yaffs_strncpy (a, b, c) strncpy(a, b, c) +#define yaffs_strncmp (a, b, c) strncmp(a, b, c) +#define yaffs_strnlen (s,m) strnlen(s,m) +#define yaffs_sprintf sprintf +#define yaffs_toupper (a) toupper(a) + +#define yaffs_sort (base, n, sz, cmp_fn) sort(base, n, sz, cmp_fn, NULL) + +#define Y_INLINE __inline__ + +#define YAFFS_LOSTNFOUND_NAME "lost+found" +#define YAFFS_LOSTNFOUND_PREFIX "obj" + +#define YMALLOC (x) kmalloc(x, GFP_NOFS) +#define YFREE (x) kfree(x) +#define YMALLOC_ALT (x) vmalloc(x) +#define YFREE_ALT (x) vfree(x) +#define YMALLOC_DMA (x) YMALLOC(x) + +#define YYIELD () schedule() +#define Y_DUMP_STACK () dump_stack() + +#define YAFFS_ROOT_MODE 0755 +#define YAFFS_LOSTNFOUND_MODE 0700 + +#define Y_CURRENT_TIME CURRENT_TIME.tv_sec +#define Y_TIME_CONVERT (x) (x).tv_sec + +#define yaffs_sum_cmp (x, y) ((x) == (y)) +#define yaffs_strcmp (a, b) strcmp(a, b) + +#define TENDSTR "\n" +#define TSTR (x) KERN_DEBUG x +#define TCONT (x) x +#define TOUT (p) printk p + +#define compile_time_assertion (assertion) \ + ({ int x = __builtin_choose_expr(assertion, 0, (void)0); (void) x; }) + +#ifndef Y_DUMP_STACK +#define Y_DUMP_STACK () do { } while (0)
fs/yaffs2/yportenv.h line 89
Quoted 10 lines
fs/yaffs2/yportenv.h new file +10
-0+#endif + +#ifndef YBUG +#define YBUG () do {\ + T(YAFFS_TRACE_BUG,\ + (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),\ + __LINE__));\ + Y_DUMP_STACK();\ +} while (0) +#endif
Please drop these wrapper macros.
PATCH 8/8 Add yaffs2 file system: VFS glue code, hook into kernel tree building
In reply to Charles Manning--- MAINTAINERS | 8 + fs/Kconfig | 1 + fs/Makefile | 1 + fs/yaffs2/Kconfig | 161 +++ fs/yaffs2/Makefile | 17 + fs/yaffs2/yaffs_vfs.c | 2917 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 3105 insertions(+), 0 deletions(-) create mode 100644 fs/yaffs2/Kconfig create mode 100644 fs/yaffs2/Makefile create mode 100644 fs/yaffs2/yaffs_vfs.c
MAINTAINERS +8 -0
@@ -6666,6 +6666,14 @@ S: Maintained F: drivers/net/hamradio/yam* F: include/linux/yam.h +YAFFS2 FILESYSTEM +M: Charles Manning <[email protected]> +L: [email protected] +S: Maintained +F: fs/yaffs2/ +T: git git://www.aleph1.co.uk/yaffs2 +W: http://www.yaffs.net/ + YEALINK PHONE DRIVER M: Henk Vergonet <[email protected]> L: [email protected]
fs/Kconfig +1 -0
@@ -176,6 +176,7 @@ source "fs/hfsplus/Kconfig" source "fs/befs/Kconfig" source "fs/bfs/Kconfig" source "fs/efs/Kconfig" +source "fs/yaffs2/Kconfig" source "fs/jffs2/Kconfig" # UBIFS File system configuration source "fs/ubifs/Kconfig"
fs/Makefile +1 -0
@@ -121,3 +121,4 @@ obj-$(CONFIG_BTRFS_FS) += btrfs/ obj-$(CONFIG_GFS2_FS) += gfs2/ obj-$(CONFIG_EXOFS_FS) += exofs/ obj-$(CONFIG_CEPH_FS) += ceph/ +obj-$(CONFIG_YAFFS_FS) += yaffs2/
fs/yaffs2/Kconfig new file +161 -0
161 lines not on this page · raw message
fs/yaffs2/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +# +# Makefile for the linux YAFFS filesystem routines. +# + +obj-$(CONFIG_YAFFS_FS) += yaffs.o + +yaffs-y := yaffs_ecc.o yaffs_vfs.o yaffs_guts.o yaffs_checkptrw.o +yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o +yaffs-y += yaffs_tagscompat.o yaffs_tagsvalidity.o +yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o +yaffs-y += yaffs_nameval.o yaffs_attribs.o +yaffs-y += yaffs_allocator.o +yaffs-y += yaffs_yaffs1.o +yaffs-y += yaffs_yaffs2.o +yaffs-y += yaffs_bitmap.o +yaffs-y += yaffs_verify.o +
fs/yaffs2/yaffs_vfs.c new file +2917 -0
2,797 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH 8/8] Add yaffs2 file system: VFS glue code, hook into kernel tree building
fs/yaffs2/yaffs_vfs.c line 63
Quoted 2 lines · Charles Manning
fs/yaffs2/yaffs_vfs.c new file +2
-0+#define UnlockPage (p) unlock_page(p) +#define Page_Uptodate (page) test_bit(PG_uptodate, &(page)->flags)
You should never be testing page flags by hand, outside mm code.
Why aren't you using PageUptodate()?
Re: [PATCH 8/8] Add yaffs2 file system: VFS glue code, hook into kernel tree building
In reply to Charles ManningQuoted 2 lines · Charles Manning
Signed-off-by Charles Manning <[email protected]>---
<snip>
fs/yaffs2/Kconfig line 3
Quoted 3 lines
fs/yaffs2/Kconfig new file +3
-0+# +# YAFFS file system configurations +#
There are still too many config options...
Quoted 65 lines
fs/yaffs2/Kconfig new file +65
-0+config YAFFS_FS + tristate "YAFFS2 file system support" + default n + depends on MTD_BLOCK + select YAFFS_YAFFS1 + select YAFFS_YAFFS2 + help + YAFFS2, or Yet Another Flash Filing System, is a filing system + optimised for NAND Flash chips. + + To compile the YAFFS2 file system support as a module, choose M + here: the module will be called yaffs2. + + If unsure, say N. + + Further information on YAFFS2 is available at + <http://www.aleph1.co.uk/yaffs/>. + +config YAFFS_YAFFS1 + bool "512 byte / page devices" + depends on YAFFS_FS + default y + help + Enable YAFFS1 support -- yaffs for 512 byte / page devices + + Not needed for 2K-page devices. + + If unsure, say Y. + +config YAFFS_9BYTE_TAGS + bool "Use older-style on-NAND data format with pageStatus byte" + depends on YAFFS_YAFFS1 + default n + help + + Older-style on-NAND data format has a "pageStatus" byte to record + chunk/page state. This byte is zero when the page is discarded. + Choose this option if you have existing on-NAND data using this + format that you need to continue to support. New data written + also uses the older-style format. Note: Use of this option + generally requires that MTD's oob layout be adjusted to use the + older-style format. See notes on tags formats and MTD versions + in yaffs_mtdif1.c. + + If unsure, say N. + +config YAFFS_DOES_ECC + bool "Lets Yaffs do its own ECC" + depends on YAFFS_FS && YAFFS_YAFFS1 && !YAFFS_9BYTE_TAGS + default n + help + This enables Yaffs to use its own ECC functions instead of using + the ones from the generic MTD-NAND driver. + + If unsure, say N. + +config YAFFS_ECC_WRONG_ORDER + bool "Use the same ecc byte order as Steven Hill's nand_ecc.c" + depends on YAFFS_FS && YAFFS_DOES_ECC && !YAFFS_9BYTE_TAGS + default n + help + This makes yaffs_ecc.c use the same ecc byte order as Steven + Hill's nand_ecc.c. If not set, then you get the same ecc byte + order as SmartMedia. +
fs/yaffs2/Kconfig line 79
Quoted 10 lines
fs/yaffs2/Kconfig new file +10
-0+ If unsure, say N. + +config YAFFS_YAFFS2 + bool "2048 byte (or larger) / page devices" + depends on YAFFS_FS + default y + help + Enable YAFFS2 support -- yaffs for >= 2K bytes per page devices + + If unsure, say Y.
How much additional code do the YAFFS1 and YAFFS2 options add? If the added size is minimal maybe its better to remove these options and just always support both yaffs and yaffs2?
fs/yaffs2/Kconfig line 89
Quoted 9 lines
fs/yaffs2/Kconfig new file +9
-0+config YAFFS_AUTO_YAFFS2 + bool "Autoselect yaffs2 format" + depends on YAFFS_YAFFS2 + default y + help + Without this, you need to explicitely use yaffs2 as the file + system type. With this, you can say "yaffs" and yaffs or yaffs2 + will be used depending on the device page size (yaffs on + 512-byte page devices, yaffs2 on 2K page devices).
Could this option be removed and have the default behaviour auto-detect when specifying "yaffs", and have "yaffs1" and "yaffs2" specify the filesystem explicitly?
Quoted 44 lines
fs/yaffs2/Kconfig new file +44
-0+ + If unsure, say Y. + +config YAFFS_DISABLE_TAGS_ECC + bool "Disable YAFFS from doing ECC on tags by default" + depends on YAFFS_FS && YAFFS_YAFFS2 + default n + help + This defaults Yaffs to using its own ECC calculations on tags instead of + just relying on the MTD. + This behavior can also be overridden with tags_ecc_on and + tags_ecc_off mount options. + + If unsure, say N. + +config YAFFS_ALWAYS_CHECK_CHUNK_ERASED + bool "Force chunk erase check" + depends on YAFFS_FS + default n + help + Normally YAFFS only checks chunks before writing until an erased + chunk is found. This helps to detect any partially written + chunks that might have happened due to power loss. + + Enabling this forces on the test that chunks are erased in flash + before writing to them. This takes more time but is potentially + a bit more secure. + + Suggest setting Y during development and ironing out driver + issues etc. Suggest setting to N if you want faster writing. + + If unsure, say Y. + +config YAFFS_EMPTY_LOST_AND_FOUND + bool "Empty lost and found on boot" + depends on YAFFS_FS + default n + help + If this is enabled then the contents of lost and found is + automatically dumped at mount. + + If unsure, say N. + +config YAFFS_DISABLE_BLOCK_REFRESHING
fs/yaffs2/Kconfig line 143
Quoted 10 lines
fs/yaffs2/Kconfig new file +10
-0+ bool "Disable yaffs2 block refreshing" + depends on YAFFS_FS + default n + help + If this is set, then block refreshing is disabled. + Block refreshing infrequently refreshes the oldest block in + a yaffs2 file system. This mechanism helps to refresh flash to + mitigate against data loss. This is particularly useful for MLC. + + If unsure, say N.
Some of the Kconfig options are enabling features and some are disabling features which is a bit confusing.
This option, and some of the others, looks like it could be replaced by a sysfs tuneable to set the refresh_period. This would give much greater control over this option.
fs/yaffs2/Kconfig line 153
Quoted 9 lines
fs/yaffs2/Kconfig new file +9
-0+config YAFFS_DISABLE_BACKGROUND + bool "Disable yaffs2 background processing" + depends on YAFFS_FS + default n + help + If this is set, then background processing is disabled. + Background processing makes many foreground activities faster. + + If unsure, say N.
Why would you enable this config option?
fs/yaffs2/Kconfig line 161
Quoted 7 lines
fs/yaffs2/Kconfig new file +7
-0+config YAFFS_XATTR + bool "Enable yaffs2 xattr support" + depends on YAFFS_FS + default y + help + If this is set then yaffs2 will provide xattr support. + If unsure, say Y.
Why would you disable this config option?
~Ryan
Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre Ryan Mallon 5 Amuri Park, 404 Barbadoes St [email protected] PO Box 13 889, Christchurch 8013 http://www.bluewatersys.com New Zealand Phone: +64 3 3779127 Freecall: Australia 1800 148 751 Fax: +64 3 3779135 USA 1800 261 2934