Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * JFFS2 -- Journalling Flash File System, Version 2.
0003  *
0004  * Copyright © 2001-2007 Red Hat, Inc.
0005  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
0006  *
0007  * Created by David Woodhouse <dwmw2@infradead.org>
0008  *
0009  * For licensing information, see the file 'LICENCE' in this directory.
0010  *
0011  */
0012 
0013 #ifndef _JFFS2_FS_SB
0014 #define _JFFS2_FS_SB
0015 
0016 #include <linux/types.h>
0017 #include <linux/spinlock.h>
0018 #include <linux/workqueue.h>
0019 #include <linux/completion.h>
0020 #include <linux/mutex.h>
0021 #include <linux/timer.h>
0022 #include <linux/wait.h>
0023 #include <linux/list.h>
0024 #include <linux/rwsem.h>
0025 
0026 #define JFFS2_SB_FLAG_RO 1
0027 #define JFFS2_SB_FLAG_SCANNING 2 /* Flash scanning is in progress */
0028 #define JFFS2_SB_FLAG_BUILDING 4 /* File system building is in progress */
0029 
0030 struct jffs2_inodirty;
0031 
0032 struct jffs2_mount_opts {
0033     bool override_compr;
0034     unsigned int compr;
0035 
0036     /* The size of the reserved pool. The reserved pool is the JFFS2 flash
0037      * space which may only be used by root cannot be used by the other
0038      * users. This is implemented simply by means of not allowing the
0039      * latter users to write to the file system if the amount if the
0040      * available space is less then 'rp_size'. */
0041     bool set_rp_size;
0042     unsigned int rp_size;
0043 };
0044 
0045 /* A struct for the overall file system control.  Pointers to
0046    jffs2_sb_info structs are named `c' in the source code.
0047    Nee jffs_control
0048 */
0049 struct jffs2_sb_info {
0050     struct mtd_info *mtd;
0051 
0052     uint32_t highest_ino;
0053     uint32_t check_ino;     /* *NEXT* inode to be checked */
0054 
0055     unsigned int flags;
0056 
0057     struct task_struct *gc_task;    /* GC task struct */
0058     struct completion gc_thread_start; /* GC thread start completion */
0059     struct completion gc_thread_exit; /* GC thread exit completion port */
0060 
0061     struct mutex alloc_sem;     /* Used to protect all the following
0062                        fields, and also to protect against
0063                        out-of-order writing of nodes. And GC. */
0064     uint32_t cleanmarker_size;  /* Size of an _inline_ CLEANMARKER
0065                      (i.e. zero for OOB CLEANMARKER */
0066 
0067     uint32_t flash_size;
0068     uint32_t used_size;
0069     uint32_t dirty_size;
0070     uint32_t wasted_size;
0071     uint32_t free_size;
0072     uint32_t erasing_size;
0073     uint32_t bad_size;
0074     uint32_t sector_size;
0075     uint32_t unchecked_size;
0076 
0077     uint32_t nr_free_blocks;
0078     uint32_t nr_erasing_blocks;
0079 
0080     /* Number of free blocks there must be before we... */
0081     uint8_t resv_blocks_write;  /* ... allow a normal filesystem write */
0082     uint8_t resv_blocks_deletion;   /* ... allow a normal filesystem deletion */
0083     uint8_t resv_blocks_gctrigger;  /* ... wake up the GC thread */
0084     uint8_t resv_blocks_gcbad;  /* ... pick a block from the bad_list to GC */
0085     uint8_t resv_blocks_gcmerge;    /* ... merge pages when garbage collecting */
0086     /* Number of 'very dirty' blocks before we trigger immediate GC */
0087     uint8_t vdirty_blocks_gctrigger;
0088 
0089     uint32_t nospc_dirty_size;
0090 
0091     uint32_t nr_blocks;
0092     struct jffs2_eraseblock *blocks;    /* The whole array of blocks. Used for getting blocks
0093                          * from the offset (blocks[ofs / sector_size]) */
0094     struct jffs2_eraseblock *nextblock; /* The block we're currently filling */
0095 
0096     struct jffs2_eraseblock *gcblock;   /* The block we're currently garbage-collecting */
0097 
0098     struct list_head clean_list;        /* Blocks 100% full of clean data */
0099     struct list_head very_dirty_list;   /* Blocks with lots of dirty space */
0100     struct list_head dirty_list;        /* Blocks with some dirty space */
0101     struct list_head erasable_list;     /* Blocks which are completely dirty, and need erasing */
0102     struct list_head erasable_pending_wbuf_list;    /* Blocks which need erasing but only after the current wbuf is flushed */
0103     struct list_head erasing_list;      /* Blocks which are currently erasing */
0104     struct list_head erase_checking_list;   /* Blocks which are being checked and marked */
0105     struct list_head erase_pending_list;    /* Blocks which need erasing now */
0106     struct list_head erase_complete_list;   /* Blocks which are erased and need the clean marker written to them */
0107     struct list_head free_list;     /* Blocks which are free and ready to be used */
0108     struct list_head bad_list;      /* Bad blocks. */
0109     struct list_head bad_used_list;     /* Bad blocks with valid data in. */
0110 
0111     spinlock_t erase_completion_lock;   /* Protect free_list and erasing_list
0112                            against erase completion handler */
0113     wait_queue_head_t erase_wait;       /* For waiting for erases to complete */
0114 
0115     wait_queue_head_t inocache_wq;
0116     int inocache_hashsize;
0117     struct jffs2_inode_cache **inocache_list;
0118     spinlock_t inocache_lock;
0119 
0120     /* Sem to allow jffs2_garbage_collect_deletion_dirent to
0121        drop the erase_completion_lock while it's holding a pointer
0122        to an obsoleted node. I don't like this. Alternatives welcomed. */
0123     struct mutex erase_free_sem;
0124 
0125     uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */
0126 
0127 #ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
0128     unsigned char *wbuf_verify; /* read-back buffer for verification */
0129 #endif
0130 #ifdef CONFIG_JFFS2_FS_WRITEBUFFER
0131     unsigned char *wbuf; /* Write-behind buffer for NAND flash */
0132     uint32_t wbuf_ofs;
0133     uint32_t wbuf_len;
0134     struct jffs2_inodirty *wbuf_inodes;
0135     struct rw_semaphore wbuf_sem;   /* Protects the write buffer */
0136 
0137     struct delayed_work wbuf_dwork; /* write-buffer write-out work */
0138 
0139     unsigned char *oobbuf;
0140     int oobavail; /* How many bytes are available for JFFS2 in OOB */
0141 #endif
0142 
0143     struct jffs2_summary *summary;      /* Summary information */
0144     struct jffs2_mount_opts mount_opts;
0145 
0146 #ifdef CONFIG_JFFS2_FS_XATTR
0147 #define XATTRINDEX_HASHSIZE (57)
0148     uint32_t highest_xid;
0149     uint32_t highest_xseqno;
0150     struct list_head xattrindex[XATTRINDEX_HASHSIZE];
0151     struct list_head xattr_unchecked;
0152     struct list_head xattr_dead_list;
0153     struct jffs2_xattr_ref *xref_dead_list;
0154     struct jffs2_xattr_ref *xref_temp;
0155     struct rw_semaphore xattr_sem;
0156     uint32_t xdatum_mem_usage;
0157     uint32_t xdatum_mem_threshold;
0158 #endif
0159     /* OS-private pointer for getting back to master superblock info */
0160     void *os_priv;
0161 };
0162 
0163 #endif /* _JFFS2_FS_SB */