2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
8 * The original JFFS, from which the design for JFFS2 was derived,
9 * was designed and implemented by Axis Communications AB.
11 * The contents of this file are subject to the Red Hat eCos Public
12 * License Version 1.1 (the "Licence"); you may not use this file
13 * except in compliance with the Licence. You may obtain a copy of
14 * the Licence at http://www.redhat.com/
16 * Software distributed under the Licence is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
18 * See the Licence for the specific language governing rights and
19 * limitations under the Licence.
21 * The Original Code is JFFS2 - Journalling Flash File System, version 2
23 * Alternatively, the contents of this file may be used under the
24 * terms of the GNU General Public License version 2 (the "GPL"), in
25 * which case the provisions of the GPL are applicable instead of the
26 * above. If you wish to allow the use of your version of this file
27 * only under the terms of the GPL and not to allow others to use your
28 * version of this file under the RHEPL, indicate your decision by
29 * deleting the provisions above and replace them with the notice and
30 * other provisions required by the GPL. If you do not delete the
31 * provisions above, a recipient may use your version of this file
32 * under either the RHEPL or the GPL.
34 * $Id: nodelist.h,v 1.1.1.1 2005/04/11 02:50:46 jack Exp $
38 #include <linux/config.h>
41 #include <linux/jffs2_fs_sb.h>
42 #include <linux/jffs2_fs_i.h>
44 #ifndef CONFIG_JFFS2_FS_DEBUG
45 #define CONFIG_JFFS2_FS_DEBUG 2
48 #if CONFIG_JFFS2_FS_DEBUG > 0
54 #if CONFIG_JFFS2_FS_DEBUG > 1
61 This is all we need to keep in-core for each raw node during normal
62 operation. As and when we do read_inode on a particular inode, we can
63 scan the nodes which are listed for it and build up a proper map of
64 which nodes are currently valid. JFFSv1 always used to keep that whole
65 map in core for each inode.
67 struct jffs2_raw_node_ref
69 struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref
70 for this inode. If this is the last, it points to the inode_cache
71 for this inode instead. The inode_cache will have NULL in the first
72 word so you know when you've got there :) */
73 struct jffs2_raw_node_ref *next_phys;
79 /* flash_offset & 3 always has to be zero, because nodes are
80 always aligned at 4 bytes. So we have a couple of extra bits
81 to play with. So we set the least significant bit to 1 to
82 signify that the node is obsoleted by later nodes.
87 Used for keeping track of deletion nodes &c, which can only be marked
88 as obsolete when the node which they mark as deleted has actually been
89 removed from the flash.
91 struct jffs2_raw_node_ref_list {
92 struct jffs2_raw_node_ref *rew;
93 struct jffs2_raw_node_ref_list *next;
96 /* For each inode in the filesystem, we need to keep a record of
97 nlink, because it would be a PITA to scan the whole directory tree
98 at read_inode() time to calculate it, and to keep sufficient information
99 in the raw_node_ref (basically both parent and child inode number for
100 dirent nodes) would take more space than this does. We also keep
101 a pointer to the first physical node which is part of this inode, too.
103 struct jffs2_inode_cache {
104 struct jffs2_scan_info *scan; /* Used during scan to hold
105 temporary lists of nodes, and later must be set to
106 NULL to mark the end of the raw_node_ref->next_in_ino
108 struct jffs2_inode_cache *next;
109 struct jffs2_raw_node_ref *nodes;
114 struct jffs2_scan_info {
115 struct jffs2_full_dirent *dents;
116 struct jffs2_tmp_dnode_info *tmpnodes;
119 Larger representation of a raw node, kept in-core only when the
120 struct inode for this particular ino is instantiated.
123 struct jffs2_full_dnode
125 struct jffs2_raw_node_ref *raw;
126 __u32 ofs; /* Don't really need this, but optimisation */
128 __u32 frags; /* Number of fragments which currently refer
129 to this node. When this reaches zero,
130 the node is obsolete.
135 Even larger representation of a raw node, kept in-core only while
136 we're actually building up the original map of which nodes go where,
139 struct jffs2_tmp_dnode_info
141 struct jffs2_tmp_dnode_info *next;
142 struct jffs2_full_dnode *fn;
146 struct jffs2_full_dirent
148 struct jffs2_raw_node_ref *raw;
149 struct jffs2_full_dirent *next;
151 __u32 ino; /* == zero for unlink */
154 unsigned char name[0];
157 Fragments - used to build a map of which raw node to obtain
158 data from for each part of the ino
160 struct jffs2_node_frag
162 struct jffs2_node_frag *next;
163 struct jffs2_full_dnode *node; /* NULL for holes */
165 __u32 ofs; /* Don't really need this, but optimisation */
168 struct jffs2_eraseblock
170 struct list_head list;
172 __u32 offset; /* of this block in the MTD */
176 __u32 free_size; /* Note that sector_size - free_size
177 is the address of the first free space */
178 struct jffs2_raw_node_ref *first_node;
179 struct jffs2_raw_node_ref *last_node;
181 struct jffs2_raw_node_ref *gc_node; /* Next node to be garbage collected */
183 /* For deletia. When a dirent node in this eraseblock is
184 deleted by a node elsewhere, that other node can only
185 be marked as obsolete when this block is actually erased.
186 So we keep a list of the nodes to mark as obsolete when
187 the erase is completed.
189 // MAYBE struct jffs2_raw_node_ref_list *deletia;
192 #define ACCT_SANITY_CHECK(c, jeb) do { \
193 if (jeb->used_size + jeb->dirty_size + jeb->free_size != c->sector_size) { \
194 printk(KERN_NOTICE "Eeep. Space accounting for block at 0x%08x is screwed\n", jeb->offset); \
195 printk(KERN_NOTICE "free 0x%08x + dirty 0x%08x + used %08x != total %08x\n", \
196 jeb->free_size, jeb->dirty_size, jeb->used_size, c->sector_size); \
199 if (c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size != c->flash_size) { \
200 printk(KERN_NOTICE "Eeep. Space accounting superblock info is screwed\n"); \
201 printk(KERN_NOTICE "free 0x%08x + dirty 0x%08x + used %08x + erasing %08x + bad %08x != total %08x\n", \
202 c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size, c->flash_size); \
207 #define ACCT_PARANOIA_CHECK(jeb) do { \
208 __u32 my_used_size = 0; \
209 struct jffs2_raw_node_ref *ref2 = jeb->first_node; \
211 if (!(ref2->flash_offset & 1)) \
212 my_used_size += ref2->totlen; \
213 ref2 = ref2->next_phys; \
215 if (my_used_size != jeb->used_size) { \
216 printk(KERN_NOTICE "Calculated used size %08x != stored used size %08x\n", my_used_size, jeb->used_size); \
222 #define ALLOC_NORMAL 0 /* Normal allocation */
223 #define ALLOC_DELETION 1 /* Deletion node. Best to allow it */
224 #define ALLOC_GC 2 /* Space requested for GC. Give it or die */
226 #define JFFS2_RESERVED_BLOCKS_BASE 3 /* Number of free blocks there must be before we... */
227 #define JFFS2_RESERVED_BLOCKS_WRITE (JFFS2_RESERVED_BLOCKS_BASE + 2) /* ... allow a normal filesystem write */
228 #define JFFS2_RESERVED_BLOCKS_DELETION (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... allow a normal filesystem deletion */
229 #define JFFS2_RESERVED_BLOCKS_GCTRIGGER (JFFS2_RESERVED_BLOCKS_BASE + 3) /* ... wake up the GC thread */
230 #define JFFS2_RESERVED_BLOCKS_GCBAD (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... pick a block from the bad_list to GC */
231 #define JFFS2_RESERVED_BLOCKS_GCMERGE (JFFS2_RESERVED_BLOCKS_BASE) /* ... merge pages when garbage collecting */
234 #define ALLOC_NORMAL 0 /* Normal allocation */
235 #define ALLOC_DELETION 1 /* Deletion node. Best to allow it */
236 #define ALLOC_GC 2 /* Space requested for GC. Give it or die */
238 #define JFFS2_RESERVED_BLOCKS_BASE 0 /* Number of free blocks there must be before we... */
239 #define JFFS2_RESERVED_BLOCKS_WRITE (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... allow a normal filesystem write */
240 #define JFFS2_RESERVED_BLOCKS_DELETION (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... allow a normal filesystem deletion */
241 #define JFFS2_RESERVED_BLOCKS_GCTRIGGER (JFFS2_RESERVED_BLOCKS_BASE + 2) /* ... wake up the GC thread */
242 #define JFFS2_RESERVED_BLOCKS_GCBAD (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... pick a block from the bad_list to GC */
243 #define JFFS2_RESERVED_BLOCKS_GCMERGE (JFFS2_RESERVED_BLOCKS_BASE) /* ... merge pages when garbage collecting */
247 #define PAD(x) (((x)+3)&~3)
249 static inline int jffs2_raw_ref_to_inum(struct jffs2_raw_node_ref *raw)
251 while(raw->next_in_ino) {
252 raw = raw->next_in_ino;
255 return ((struct jffs2_inode_cache *)raw)->ino;
259 D1(void jffs2_print_frag_list(struct jffs2_inode_info *f));
260 void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list);
261 void jffs2_add_tn_to_list(struct jffs2_tmp_dnode_info *tn, struct jffs2_tmp_dnode_info **list);
262 int jffs2_get_inode_nodes(struct jffs2_sb_info *c, ino_t ino, struct jffs2_inode_info *f,
263 struct jffs2_tmp_dnode_info **tnp, struct jffs2_full_dirent **fdp,
264 __u32 *highest_version, __u32 *latest_mctime,
266 struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, int ino);
267 void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new);
268 void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old);
269 void jffs2_free_ino_caches(struct jffs2_sb_info *c);
270 void jffs2_free_raw_node_refs(struct jffs2_sb_info *c);
273 int jffs2_reserve_space(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len, int prio);
274 int jffs2_reserve_space_gc(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len);
275 int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new, __u32 len, int dirty);
276 void jffs2_complete_reservation(struct jffs2_sb_info *c);
277 void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw);
280 struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_inode *ri);
281 struct jffs2_full_dnode *jffs2_write_dnode(struct inode *inode, struct jffs2_raw_inode *ri, const unsigned char *data, __u32 datalen, __u32 flash_ofs, __u32 *writelen);
282 struct jffs2_full_dirent *jffs2_write_dirent(struct inode *inode, struct jffs2_raw_dirent *rd, const unsigned char *name, __u32 namelen, __u32 flash_ofs, __u32 *writelen);
285 void jffs2_truncate_fraglist (struct jffs2_sb_info *c, struct jffs2_node_frag **list, __u32 size);
286 int jffs2_add_full_dnode_to_fraglist(struct jffs2_sb_info *c, struct jffs2_node_frag **list, struct jffs2_full_dnode *fn);
287 int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn);
288 void jffs2_read_inode (struct inode *);
289 void jffs2_clear_inode (struct inode *);
292 void jffs2_free_tmp_dnode_info_list(struct jffs2_tmp_dnode_info *tn);
293 void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd);
295 int jffs2_create_slab_caches(void);
296 void jffs2_destroy_slab_caches(void);
298 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize);
299 void jffs2_free_full_dirent(struct jffs2_full_dirent *);
300 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void);
301 void jffs2_free_full_dnode(struct jffs2_full_dnode *);
302 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void);
303 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *);
304 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void);
305 void jffs2_free_raw_inode(struct jffs2_raw_inode *);
306 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void);
307 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *);
308 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void);
309 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *);
310 struct jffs2_node_frag *jffs2_alloc_node_frag(void);
311 void jffs2_free_node_frag(struct jffs2_node_frag *);
312 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void);
313 void jffs2_free_inode_cache(struct jffs2_inode_cache *);
316 int jffs2_garbage_collect_pass(struct jffs2_sb_info *c);
319 int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
320 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
321 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
324 extern struct file_operations jffs2_dir_operations;
325 extern struct inode_operations jffs2_dir_inode_operations;
328 extern struct file_operations jffs2_file_operations;
329 extern struct inode_operations jffs2_file_inode_operations;
330 extern struct address_space_operations jffs2_file_address_operations;
331 int jffs2_null_fsync(struct file *, struct dentry *, int);
332 int jffs2_setattr (struct dentry *dentry, struct iattr *iattr);
333 int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg);
334 int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg);
335 int jffs2_readpage (struct file *, struct page *);
336 int jffs2_prepare_write (struct file *, struct page *, unsigned, unsigned);
337 int jffs2_commit_write (struct file *, struct page *, unsigned, unsigned);
340 int jffs2_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
343 int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_full_dnode *fd, unsigned char *buf, int ofs, int len);
346 unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out,
347 __u32 *datalen, __u32 *cdatalen);
348 int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in,
349 unsigned char *data_out, __u32 cdatalen, __u32 datalen);
352 int jffs2_scan_medium(struct jffs2_sb_info *c);
355 int jffs2_build_filesystem(struct jffs2_sb_info *c);
358 extern struct inode_operations jffs2_symlink_inode_operations;
361 void jffs2_erase_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
362 void jffs2_erase_pending_blocks(struct jffs2_sb_info *c);
363 void jffs2_mark_erased_blocks(struct jffs2_sb_info *c);
364 void jffs2_erase_pending_trigger(struct jffs2_sb_info *c);
367 int jffs2_zlib_init(void);
368 void jffs2_zlib_exit(void);