nodelist.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:13k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * JFFS2 -- Journalling Flash File System, Version 2.
  3.  *
  4.  * Copyright (C) 2001 Red Hat, Inc.
  5.  *
  6.  * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
  7.  *
  8.  * The original JFFS, from which the design for JFFS2 was derived,
  9.  * was designed and implemented by Axis Communications AB.
  10.  *
  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/
  15.  *
  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.
  20.  *
  21.  * The Original Code is JFFS2 - Journalling Flash File System, version 2
  22.  *
  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.
  33.  *
  34.  * $Id: nodelist.h,v 1.46.2.3 2002/10/11 09:04:44 dwmw2 Exp $
  35.  *
  36.  */
  37. #include <linux/config.h>
  38. #include <linux/fs.h>
  39. #include <linux/jffs2_fs_sb.h>
  40. #include <linux/jffs2_fs_i.h>
  41. #ifndef CONFIG_JFFS2_FS_DEBUG
  42. #define CONFIG_JFFS2_FS_DEBUG 2
  43. #endif
  44. #if CONFIG_JFFS2_FS_DEBUG > 0
  45. #define D1(x) x
  46. #else
  47. #define D1(x)
  48. #endif
  49. #if CONFIG_JFFS2_FS_DEBUG > 1
  50. #define D2(x) x
  51. #else
  52. #define D2(x)
  53. #endif
  54. /*
  55.   This is all we need to keep in-core for each raw node during normal
  56.   operation. As and when we do read_inode on a particular inode, we can
  57.   scan the nodes which are listed for it and build up a proper map of 
  58.   which nodes are currently valid. JFFSv1 always used to keep that whole
  59.   map in core for each inode.
  60. */
  61. struct jffs2_raw_node_ref
  62. {
  63. struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref
  64. for this inode. If this is the last, it points to the inode_cache
  65. for this inode instead. The inode_cache will have NULL in the first
  66. word so you know when you've got there :) */
  67. struct jffs2_raw_node_ref *next_phys;
  68. // __u32 ino;
  69. __u32 flash_offset;
  70. __u32 totlen;
  71. // __u16 nodetype;
  72.         /* flash_offset & 3 always has to be zero, because nodes are
  73.    always aligned at 4 bytes. So we have a couple of extra bits
  74.    to play with. So we set the least significant bit to 1 to
  75.    signify that the node is obsoleted by later nodes.
  76. */
  77. };
  78. /* 
  79.    Used for keeping track of deletion nodes &c, which can only be marked
  80.    as obsolete when the node which they mark as deleted has actually been 
  81.    removed from the flash.
  82. */
  83. struct jffs2_raw_node_ref_list {
  84. struct jffs2_raw_node_ref *rew;
  85. struct jffs2_raw_node_ref_list *next;
  86. };
  87. /* For each inode in the filesystem, we need to keep a record of
  88.    nlink, because it would be a PITA to scan the whole directory tree
  89.    at read_inode() time to calculate it, and to keep sufficient information
  90.    in the raw_node_ref (basically both parent and child inode number for 
  91.    dirent nodes) would take more space than this does. We also keep
  92.    a pointer to the first physical node which is part of this inode, too.
  93. */
  94. struct jffs2_inode_cache {
  95. struct jffs2_scan_info *scan; /* Used during scan to hold
  96. temporary lists of nodes, and later must be set to
  97. NULL to mark the end of the raw_node_ref->next_in_ino
  98. chain. */
  99. struct jffs2_inode_cache *next;
  100. struct jffs2_raw_node_ref *nodes;
  101. __u32 ino;
  102. int nlink;
  103. };
  104. struct jffs2_scan_info {
  105. struct jffs2_full_dirent *dents;
  106. struct jffs2_tmp_dnode_info *tmpnodes;
  107. };
  108. /*
  109.   Larger representation of a raw node, kept in-core only when the 
  110.   struct inode for this particular ino is instantiated.
  111. */
  112. struct jffs2_full_dnode
  113. {
  114. struct jffs2_raw_node_ref *raw;
  115. __u32 ofs; /* Don't really need this, but optimisation */
  116. __u32 size;
  117. __u32 frags; /* Number of fragments which currently refer
  118. to this node. When this reaches zero, 
  119. the node is obsolete.
  120.      */
  121. };
  122. /* 
  123.    Even larger representation of a raw node, kept in-core only while
  124.    we're actually building up the original map of which nodes go where,
  125.    in read_inode()
  126. */
  127. struct jffs2_tmp_dnode_info
  128. {
  129. struct jffs2_tmp_dnode_info *next;
  130. struct jffs2_full_dnode *fn;
  131. __u32 version;
  132. };       
  133. struct jffs2_full_dirent
  134. {
  135. struct jffs2_raw_node_ref *raw;
  136. struct jffs2_full_dirent *next;
  137. __u32 version;
  138. __u32 ino; /* == zero for unlink */
  139. unsigned int nhash;
  140. unsigned char type;
  141. unsigned char name[0];
  142. };
  143. /*
  144.   Fragments - used to build a map of which raw node to obtain 
  145.   data from for each part of the ino
  146. */
  147. struct jffs2_node_frag
  148. {
  149. struct jffs2_node_frag *next;
  150. struct jffs2_full_dnode *node; /* NULL for holes */
  151. __u32 size;
  152. __u32 ofs; /* Don't really need this, but optimisation */
  153. };
  154. struct jffs2_eraseblock
  155. {
  156. struct list_head list;
  157. int bad_count;
  158. __u32 offset; /* of this block in the MTD */
  159. __u32 used_size;
  160. __u32 dirty_size;
  161. __u32 free_size; /* Note that sector_size - free_size
  162.    is the address of the first free space */
  163. struct jffs2_raw_node_ref *first_node;
  164. struct jffs2_raw_node_ref *last_node;
  165. struct jffs2_raw_node_ref *gc_node; /* Next node to be garbage collected */
  166. /* For deletia. When a dirent node in this eraseblock is
  167.    deleted by a node elsewhere, that other node can only 
  168.    be marked as obsolete when this block is actually erased.
  169.    So we keep a list of the nodes to mark as obsolete when
  170.    the erase is completed.
  171. */
  172. // MAYBE struct jffs2_raw_node_ref_list *deletia;
  173. };
  174. #define ACCT_SANITY_CHECK(c, jeb) do { 
  175. if (jeb->used_size + jeb->dirty_size + jeb->free_size != c->sector_size) { 
  176. printk(KERN_NOTICE "Eeep. Space accounting for block at 0x%08x is screwedn", jeb->offset); 
  177. printk(KERN_NOTICE "free 0x%08x + dirty 0x%08x + used %08x != total %08xn", 
  178. jeb->free_size, jeb->dirty_size, jeb->used_size, c->sector_size); 
  179. BUG(); 
  180. if (c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size != c->flash_size) { 
  181. printk(KERN_NOTICE "Eeep. Space accounting superblock info is screwedn"); 
  182. printk(KERN_NOTICE "free 0x%08x + dirty 0x%08x + used %08x + erasing %08x + bad %08x != total %08xn", 
  183. c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size, c->flash_size); 
  184. BUG(); 
  185. } while(0)
  186. #define ACCT_PARANOIA_CHECK(jeb) do { 
  187. __u32 my_used_size = 0; 
  188. struct jffs2_raw_node_ref *ref2 = jeb->first_node; 
  189. while (ref2) { 
  190. if (!(ref2->flash_offset & 1)) 
  191. my_used_size += ref2->totlen; 
  192. ref2 = ref2->next_phys; 
  193. if (my_used_size != jeb->used_size) { 
  194. printk(KERN_NOTICE "Calculated used size %08x != stored used size %08xn", my_used_size, jeb->used_size); 
  195. BUG(); 
  196. } while(0)
  197. #define ALLOC_NORMAL 0 /* Normal allocation */
  198. #define ALLOC_DELETION 1 /* Deletion node. Best to allow it */
  199. #define ALLOC_GC 2 /* Space requested for GC. Give it or die */
  200. #define JFFS2_RESERVED_BLOCKS_BASE 3 /* Number of free blocks there must be before we... */
  201. #define JFFS2_RESERVED_BLOCKS_WRITE (JFFS2_RESERVED_BLOCKS_BASE + 2) /* ... allow a normal filesystem write */
  202. #define JFFS2_RESERVED_BLOCKS_DELETION (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... allow a normal filesystem deletion */
  203. #define JFFS2_RESERVED_BLOCKS_GCTRIGGER (JFFS2_RESERVED_BLOCKS_BASE + 3) /* ... wake up the GC thread */
  204. #define JFFS2_RESERVED_BLOCKS_GCBAD (JFFS2_RESERVED_BLOCKS_BASE + 1) /* ... pick a block from the bad_list to GC */
  205. #define JFFS2_RESERVED_BLOCKS_GCMERGE (JFFS2_RESERVED_BLOCKS_BASE) /* ... merge pages when garbage collecting */
  206. #define PAD(x) (((x)+3)&~3)
  207. static inline int jffs2_raw_ref_to_inum(struct jffs2_raw_node_ref *raw)
  208. {
  209. while(raw->next_in_ino) {
  210. raw = raw->next_in_ino;
  211. }
  212. return ((struct jffs2_inode_cache *)raw)->ino;
  213. }
  214. /* nodelist.c */
  215. D1(void jffs2_print_frag_list(struct jffs2_inode_info *f));
  216. void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list);
  217. void jffs2_add_tn_to_list(struct jffs2_tmp_dnode_info *tn, struct jffs2_tmp_dnode_info **list);
  218. int jffs2_get_inode_nodes(struct jffs2_sb_info *c, ino_t ino, struct jffs2_inode_info *f,
  219.   struct jffs2_tmp_dnode_info **tnp, struct jffs2_full_dirent **fdp,
  220.   __u32 *highest_version, __u32 *latest_mctime,
  221.   __u32 *mctime_ver);
  222. struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, int ino);
  223. void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new);
  224. void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old);
  225. void jffs2_free_ino_caches(struct jffs2_sb_info *c);
  226. void jffs2_free_raw_node_refs(struct jffs2_sb_info *c);
  227. /* nodemgmt.c */
  228. int jffs2_reserve_space(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len, int prio);
  229. int jffs2_reserve_space_gc(struct jffs2_sb_info *c, __u32 minsize, __u32 *ofs, __u32 *len);
  230. int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new, __u32 len, int dirty);
  231. void jffs2_complete_reservation(struct jffs2_sb_info *c);
  232. void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw);
  233. /* write.c */
  234. struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_inode *ri);
  235. 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);
  236. 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);
  237. /* readinode.c */
  238. void jffs2_truncate_fraglist (struct jffs2_sb_info *c, struct jffs2_node_frag **list, __u32 size);
  239. int jffs2_add_full_dnode_to_fraglist(struct jffs2_sb_info *c, struct jffs2_node_frag **list, struct jffs2_full_dnode *fn);
  240. int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn);
  241. void jffs2_read_inode (struct inode *);
  242. void jffs2_clear_inode (struct inode *);
  243. /* malloc.c */
  244. void jffs2_free_tmp_dnode_info_list(struct jffs2_tmp_dnode_info *tn);
  245. void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd);
  246. int jffs2_create_slab_caches(void);
  247. void jffs2_destroy_slab_caches(void);
  248. struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize);
  249. void jffs2_free_full_dirent(struct jffs2_full_dirent *);
  250. struct jffs2_full_dnode *jffs2_alloc_full_dnode(void);
  251. void jffs2_free_full_dnode(struct jffs2_full_dnode *);
  252. struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void);
  253. void jffs2_free_raw_dirent(struct jffs2_raw_dirent *);
  254. struct jffs2_raw_inode *jffs2_alloc_raw_inode(void);
  255. void jffs2_free_raw_inode(struct jffs2_raw_inode *);
  256. struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void);
  257. void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *);
  258. struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void);
  259. void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *);
  260. struct jffs2_node_frag *jffs2_alloc_node_frag(void);
  261. void jffs2_free_node_frag(struct jffs2_node_frag *);
  262. struct jffs2_inode_cache *jffs2_alloc_inode_cache(void);
  263. void jffs2_free_inode_cache(struct jffs2_inode_cache *);
  264. /* gc.c */
  265. int jffs2_garbage_collect_pass(struct jffs2_sb_info *c);
  266. /* background.c */
  267. int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
  268. void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
  269. void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
  270. /* dir.c */
  271. extern struct file_operations jffs2_dir_operations;
  272. extern struct inode_operations jffs2_dir_inode_operations;
  273. /* file.c */
  274. extern struct file_operations jffs2_file_operations;
  275. extern struct inode_operations jffs2_file_inode_operations;
  276. extern struct address_space_operations jffs2_file_address_operations;
  277. int jffs2_null_fsync(struct file *, struct dentry *, int);
  278. int jffs2_setattr (struct dentry *dentry, struct iattr *iattr);
  279. int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg);
  280. int jffs2_do_readpage_unlock (struct inode *inode, struct page *pg);
  281. int jffs2_readpage (struct file *, struct page *);
  282. int jffs2_prepare_write (struct file *, struct page *, unsigned, unsigned);
  283. int jffs2_commit_write (struct file *, struct page *, unsigned, unsigned);
  284. /* ioctl.c */
  285. int jffs2_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
  286. /* read.c */
  287. int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_full_dnode *fd, unsigned char *buf, int ofs, int len);
  288. /* compr.c */
  289. unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out, 
  290.      __u32 *datalen, __u32 *cdatalen);
  291. int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in, 
  292.      unsigned char *data_out, __u32 cdatalen, __u32 datalen);
  293. /* scan.c */
  294. int jffs2_scan_medium(struct jffs2_sb_info *c);
  295. /* build.c */
  296. int jffs2_build_filesystem(struct jffs2_sb_info *c);
  297. /* symlink.c */
  298. extern struct inode_operations jffs2_symlink_inode_operations;
  299. /* erase.c */
  300. void jffs2_erase_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
  301. void jffs2_erase_pending_blocks(struct jffs2_sb_info *c);
  302. void jffs2_mark_erased_blocks(struct jffs2_sb_info *c);
  303. void jffs2_erase_pending_trigger(struct jffs2_sb_info *c);
  304. /* compr_zlib.c */
  305. int jffs2_zlib_init(void);
  306. void jffs2_zlib_exit(void);