Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * JFFS -- Journaling Flash File System, Linux implementation. |
| 3 | * |
| 4 | * Copyright (C) 1999, 2000 Axis Communications AB. |
| 5 | * |
| 6 | * Created by Finn Hakansson <finn@axis.com>. |
| 7 | * |
| 8 | * This is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * $Id: jffs_fm.h,v 1.13 2001/01/11 12:03:25 dwmw2 Exp $ |
| 14 | * |
| 15 | * Ported to Linux 2.3.x and MTD: |
| 16 | * Copyright (C) 2000 Alexander Larsson (alex@cendio.se), Cendio Systems AB |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef __LINUX_JFFS_FM_H__ |
| 21 | #define __LINUX_JFFS_FM_H__ |
| 22 | |
Ingo Molnar | 1eb0d67 | 2006-03-23 03:00:40 -0800 | [diff] [blame] | 23 | #include <linux/config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/types.h> |
| 25 | #include <linux/jffs.h> |
| 26 | #include <linux/mtd/mtd.h> |
Ingo Molnar | 1eb0d67 | 2006-03-23 03:00:40 -0800 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /* The alignment between two nodes in the flash memory. */ |
| 30 | #define JFFS_ALIGN_SIZE 4 |
| 31 | |
| 32 | /* Mark the on-flash space as obsolete when appropriate. */ |
| 33 | #define JFFS_MARK_OBSOLETE 0 |
| 34 | |
| 35 | #ifndef CONFIG_JFFS_FS_VERBOSE |
| 36 | #define CONFIG_JFFS_FS_VERBOSE 1 |
| 37 | #endif |
| 38 | |
| 39 | #if CONFIG_JFFS_FS_VERBOSE > 0 |
| 40 | #define D(x) x |
| 41 | #define D1(x) D(x) |
| 42 | #else |
| 43 | #define D(x) |
| 44 | #define D1(x) |
| 45 | #endif |
| 46 | |
| 47 | #if CONFIG_JFFS_FS_VERBOSE > 1 |
| 48 | #define D2(x) D(x) |
| 49 | #else |
| 50 | #define D2(x) |
| 51 | #endif |
| 52 | |
| 53 | #if CONFIG_JFFS_FS_VERBOSE > 2 |
| 54 | #define D3(x) D(x) |
| 55 | #else |
| 56 | #define D3(x) |
| 57 | #endif |
| 58 | |
| 59 | #define ASSERT(x) x |
| 60 | |
| 61 | /* How many padding bytes should be inserted between two chunks of data |
| 62 | on the flash? */ |
| 63 | #define JFFS_GET_PAD_BYTES(size) ( (JFFS_ALIGN_SIZE-1) & -(__u32)(size) ) |
| 64 | #define JFFS_PAD(size) ( (size + (JFFS_ALIGN_SIZE-1)) & ~(JFFS_ALIGN_SIZE-1) ) |
| 65 | |
| 66 | |
| 67 | |
| 68 | struct jffs_node_ref |
| 69 | { |
| 70 | struct jffs_node *node; |
| 71 | struct jffs_node_ref *next; |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | /* The struct jffs_fm represents a chunk of data in the flash memory. */ |
| 76 | struct jffs_fm |
| 77 | { |
| 78 | __u32 offset; |
| 79 | __u32 size; |
| 80 | struct jffs_fm *prev; |
| 81 | struct jffs_fm *next; |
| 82 | struct jffs_node_ref *nodes; /* USED if != 0. */ |
| 83 | }; |
| 84 | |
| 85 | struct jffs_fmcontrol |
| 86 | { |
| 87 | __u32 flash_size; |
| 88 | __u32 used_size; |
| 89 | __u32 dirty_size; |
| 90 | __u32 free_size; |
| 91 | __u32 sector_size; |
| 92 | __u32 min_free_size; /* The minimum free space needed to be able |
| 93 | to perform garbage collections. */ |
| 94 | __u32 max_chunk_size; /* The maximum size of a chunk of data. */ |
| 95 | struct mtd_info *mtd; |
| 96 | struct jffs_control *c; |
| 97 | struct jffs_fm *head; |
| 98 | struct jffs_fm *tail; |
| 99 | struct jffs_fm *head_extra; |
| 100 | struct jffs_fm *tail_extra; |
Ingo Molnar | 1eb0d67 | 2006-03-23 03:00:40 -0800 | [diff] [blame] | 101 | struct mutex biglock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /* Notice the two members head_extra and tail_extra in the jffs_control |
| 105 | structure above. Those are only used during the scanning of the flash |
| 106 | memory; while the file system is being built. If the data in the flash |
| 107 | memory is organized like |
| 108 | |
| 109 | +----------------+------------------+----------------+ |
| 110 | | USED / DIRTY | FREE | USED / DIRTY | |
| 111 | +----------------+------------------+----------------+ |
| 112 | |
| 113 | then the scan is split in two parts. The first scanned part of the |
| 114 | flash memory is organized through the members head and tail. The |
| 115 | second scanned part is organized with head_extra and tail_extra. When |
| 116 | the scan is completed, the two lists are merged together. The jffs_fm |
| 117 | struct that head_extra references is the logical beginning of the |
| 118 | flash memory so it will be referenced by the head member. */ |
| 119 | |
| 120 | |
| 121 | |
| 122 | struct jffs_fmcontrol *jffs_build_begin(struct jffs_control *c, int unit); |
| 123 | void jffs_build_end(struct jffs_fmcontrol *fmc); |
| 124 | void jffs_cleanup_fmcontrol(struct jffs_fmcontrol *fmc); |
| 125 | |
| 126 | int jffs_fmalloc(struct jffs_fmcontrol *fmc, __u32 size, |
| 127 | struct jffs_node *node, struct jffs_fm **result); |
| 128 | int jffs_fmfree(struct jffs_fmcontrol *fmc, struct jffs_fm *fm, |
| 129 | struct jffs_node *node); |
| 130 | |
| 131 | __u32 jffs_free_size1(struct jffs_fmcontrol *fmc); |
| 132 | __u32 jffs_free_size2(struct jffs_fmcontrol *fmc); |
| 133 | void jffs_sync_erase(struct jffs_fmcontrol *fmc, int erased_size); |
| 134 | struct jffs_fm *jffs_cut_node(struct jffs_fmcontrol *fmc, __u32 size); |
| 135 | struct jffs_node *jffs_get_oldest_node(struct jffs_fmcontrol *fmc); |
| 136 | long jffs_erasable_size(struct jffs_fmcontrol *fmc); |
| 137 | struct jffs_fm *jffs_fmalloced(struct jffs_fmcontrol *fmc, __u32 offset, |
| 138 | __u32 size, struct jffs_node *node); |
| 139 | int jffs_add_node(struct jffs_node *node); |
| 140 | void jffs_fmfree_partly(struct jffs_fmcontrol *fmc, struct jffs_fm *fm, |
| 141 | __u32 size); |
| 142 | |
Adrian Bunk | 94c9eca | 2005-06-25 14:59:06 -0700 | [diff] [blame] | 143 | #if CONFIG_JFFS_FS_VERBOSE > 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | void jffs_print_fmcontrol(struct jffs_fmcontrol *fmc); |
Adrian Bunk | 94c9eca | 2005-06-25 14:59:06 -0700 | [diff] [blame] | 145 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | #if 0 |
| 147 | void jffs_print_node_ref(struct jffs_node_ref *ref); |
| 148 | #endif /* 0 */ |
| 149 | |
| 150 | #endif /* __LINUX_JFFS_FM_H__ */ |