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