xref: /OK3568_Linux_fs/kernel/fs/jffs2/jffs2_fs_sb.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * JFFS2 -- Journalling Flash File System, Version 2.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright © 2001-2007 Red Hat, Inc.
5*4882a593Smuzhiyun  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Created by David Woodhouse <dwmw2@infradead.org>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * For licensing information, see the file 'LICENCE' in this directory.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #ifndef _JFFS2_FS_SB
14*4882a593Smuzhiyun #define _JFFS2_FS_SB
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <linux/types.h>
17*4882a593Smuzhiyun #include <linux/spinlock.h>
18*4882a593Smuzhiyun #include <linux/workqueue.h>
19*4882a593Smuzhiyun #include <linux/completion.h>
20*4882a593Smuzhiyun #include <linux/mutex.h>
21*4882a593Smuzhiyun #include <linux/timer.h>
22*4882a593Smuzhiyun #include <linux/wait.h>
23*4882a593Smuzhiyun #include <linux/list.h>
24*4882a593Smuzhiyun #include <linux/rwsem.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #define JFFS2_SB_FLAG_RO 1
27*4882a593Smuzhiyun #define JFFS2_SB_FLAG_SCANNING 2 /* Flash scanning is in progress */
28*4882a593Smuzhiyun #define JFFS2_SB_FLAG_BUILDING 4 /* File system building is in progress */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun struct jffs2_inodirty;
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct jffs2_mount_opts {
33*4882a593Smuzhiyun 	bool override_compr;
34*4882a593Smuzhiyun 	unsigned int compr;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	/* The size of the reserved pool. The reserved pool is the JFFS2 flash
37*4882a593Smuzhiyun 	 * space which may only be used by root cannot be used by the other
38*4882a593Smuzhiyun 	 * users. This is implemented simply by means of not allowing the
39*4882a593Smuzhiyun 	 * latter users to write to the file system if the amount if the
40*4882a593Smuzhiyun 	 * available space is less then 'rp_size'. */
41*4882a593Smuzhiyun 	bool set_rp_size;
42*4882a593Smuzhiyun 	unsigned int rp_size;
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* A struct for the overall file system control.  Pointers to
46*4882a593Smuzhiyun    jffs2_sb_info structs are named `c' in the source code.
47*4882a593Smuzhiyun    Nee jffs_control
48*4882a593Smuzhiyun */
49*4882a593Smuzhiyun struct jffs2_sb_info {
50*4882a593Smuzhiyun 	struct mtd_info *mtd;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	uint32_t highest_ino;
53*4882a593Smuzhiyun 	uint32_t check_ino;		/* *NEXT* inode to be checked */
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	unsigned int flags;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	struct task_struct *gc_task;	/* GC task struct */
58*4882a593Smuzhiyun 	struct completion gc_thread_start; /* GC thread start completion */
59*4882a593Smuzhiyun 	struct completion gc_thread_exit; /* GC thread exit completion port */
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	struct mutex alloc_sem;		/* Used to protect all the following
62*4882a593Smuzhiyun 					   fields, and also to protect against
63*4882a593Smuzhiyun 					   out-of-order writing of nodes. And GC. */
64*4882a593Smuzhiyun 	uint32_t cleanmarker_size;	/* Size of an _inline_ CLEANMARKER
65*4882a593Smuzhiyun 					 (i.e. zero for OOB CLEANMARKER */
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	uint32_t flash_size;
68*4882a593Smuzhiyun 	uint32_t used_size;
69*4882a593Smuzhiyun 	uint32_t dirty_size;
70*4882a593Smuzhiyun 	uint32_t wasted_size;
71*4882a593Smuzhiyun 	uint32_t free_size;
72*4882a593Smuzhiyun 	uint32_t erasing_size;
73*4882a593Smuzhiyun 	uint32_t bad_size;
74*4882a593Smuzhiyun 	uint32_t sector_size;
75*4882a593Smuzhiyun 	uint32_t unchecked_size;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	uint32_t nr_free_blocks;
78*4882a593Smuzhiyun 	uint32_t nr_erasing_blocks;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	/* Number of free blocks there must be before we... */
81*4882a593Smuzhiyun 	uint8_t resv_blocks_write;	/* ... allow a normal filesystem write */
82*4882a593Smuzhiyun 	uint8_t resv_blocks_deletion;	/* ... allow a normal filesystem deletion */
83*4882a593Smuzhiyun 	uint8_t resv_blocks_gctrigger;	/* ... wake up the GC thread */
84*4882a593Smuzhiyun 	uint8_t resv_blocks_gcbad;	/* ... pick a block from the bad_list to GC */
85*4882a593Smuzhiyun 	uint8_t resv_blocks_gcmerge;	/* ... merge pages when garbage collecting */
86*4882a593Smuzhiyun 	/* Number of 'very dirty' blocks before we trigger immediate GC */
87*4882a593Smuzhiyun 	uint8_t vdirty_blocks_gctrigger;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 	uint32_t nospc_dirty_size;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	uint32_t nr_blocks;
92*4882a593Smuzhiyun 	struct jffs2_eraseblock *blocks;	/* The whole array of blocks. Used for getting blocks
93*4882a593Smuzhiyun 						 * from the offset (blocks[ofs / sector_size]) */
94*4882a593Smuzhiyun 	struct jffs2_eraseblock *nextblock;	/* The block we're currently filling */
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	struct jffs2_eraseblock *gcblock;	/* The block we're currently garbage-collecting */
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	struct list_head clean_list;		/* Blocks 100% full of clean data */
99*4882a593Smuzhiyun 	struct list_head very_dirty_list;	/* Blocks with lots of dirty space */
100*4882a593Smuzhiyun 	struct list_head dirty_list;		/* Blocks with some dirty space */
101*4882a593Smuzhiyun 	struct list_head erasable_list;		/* Blocks which are completely dirty, and need erasing */
102*4882a593Smuzhiyun 	struct list_head erasable_pending_wbuf_list;	/* Blocks which need erasing but only after the current wbuf is flushed */
103*4882a593Smuzhiyun 	struct list_head erasing_list;		/* Blocks which are currently erasing */
104*4882a593Smuzhiyun 	struct list_head erase_checking_list;	/* Blocks which are being checked and marked */
105*4882a593Smuzhiyun 	struct list_head erase_pending_list;	/* Blocks which need erasing now */
106*4882a593Smuzhiyun 	struct list_head erase_complete_list;	/* Blocks which are erased and need the clean marker written to them */
107*4882a593Smuzhiyun 	struct list_head free_list;		/* Blocks which are free and ready to be used */
108*4882a593Smuzhiyun 	struct list_head bad_list;		/* Bad blocks. */
109*4882a593Smuzhiyun 	struct list_head bad_used_list;		/* Bad blocks with valid data in. */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	spinlock_t erase_completion_lock;	/* Protect free_list and erasing_list
112*4882a593Smuzhiyun 						   against erase completion handler */
113*4882a593Smuzhiyun 	wait_queue_head_t erase_wait;		/* For waiting for erases to complete */
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	wait_queue_head_t inocache_wq;
116*4882a593Smuzhiyun 	int inocache_hashsize;
117*4882a593Smuzhiyun 	struct jffs2_inode_cache **inocache_list;
118*4882a593Smuzhiyun 	spinlock_t inocache_lock;
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	/* Sem to allow jffs2_garbage_collect_deletion_dirent to
121*4882a593Smuzhiyun 	   drop the erase_completion_lock while it's holding a pointer
122*4882a593Smuzhiyun 	   to an obsoleted node. I don't like this. Alternatives welcomed. */
123*4882a593Smuzhiyun 	struct mutex erase_free_sem;
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun 	uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
128*4882a593Smuzhiyun 	unsigned char *wbuf_verify; /* read-back buffer for verification */
129*4882a593Smuzhiyun #endif
130*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_FS_WRITEBUFFER
131*4882a593Smuzhiyun 	unsigned char *wbuf; /* Write-behind buffer for NAND flash */
132*4882a593Smuzhiyun 	uint32_t wbuf_ofs;
133*4882a593Smuzhiyun 	uint32_t wbuf_len;
134*4882a593Smuzhiyun 	struct jffs2_inodirty *wbuf_inodes;
135*4882a593Smuzhiyun 	struct rw_semaphore wbuf_sem;	/* Protects the write buffer */
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	struct delayed_work wbuf_dwork; /* write-buffer write-out work */
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 	unsigned char *oobbuf;
140*4882a593Smuzhiyun 	int oobavail; /* How many bytes are available for JFFS2 in OOB */
141*4882a593Smuzhiyun #endif
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	struct jffs2_summary *summary;		/* Summary information */
144*4882a593Smuzhiyun 	struct jffs2_mount_opts mount_opts;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_FS_XATTR
147*4882a593Smuzhiyun #define XATTRINDEX_HASHSIZE	(57)
148*4882a593Smuzhiyun 	uint32_t highest_xid;
149*4882a593Smuzhiyun 	uint32_t highest_xseqno;
150*4882a593Smuzhiyun 	struct list_head xattrindex[XATTRINDEX_HASHSIZE];
151*4882a593Smuzhiyun 	struct list_head xattr_unchecked;
152*4882a593Smuzhiyun 	struct list_head xattr_dead_list;
153*4882a593Smuzhiyun 	struct jffs2_xattr_ref *xref_dead_list;
154*4882a593Smuzhiyun 	struct jffs2_xattr_ref *xref_temp;
155*4882a593Smuzhiyun 	struct rw_semaphore xattr_sem;
156*4882a593Smuzhiyun 	uint32_t xdatum_mem_usage;
157*4882a593Smuzhiyun 	uint32_t xdatum_mem_threshold;
158*4882a593Smuzhiyun #endif
159*4882a593Smuzhiyun 	/* OS-private pointer for getting back to master superblock info */
160*4882a593Smuzhiyun 	void *os_priv;
161*4882a593Smuzhiyun };
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun #endif /* _JFFS2_FS_SB */
164