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