2 * JFFS -- Journaling Flash File System, Linux implementation.
4 * Copyright (C) 1999, 2000 Axis Communications AB.
6 * Created by Finn Hakansson <finn@axis.com>.
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.
13 * $Id: jffs_fm.h,v 1.13 2001/01/11 12:03:25 dwmw2 Exp $
15 * Ported to Linux 2.3.x and MTD:
16 * Copyright (C) 2000 Alexander Larsson (alex@cendio.se), Cendio Systems AB
20 #ifndef __LINUX_JFFS_FM_H__
21 #define __LINUX_JFFS_FM_H__
23 #include <linux/types.h>
24 #include <linux/jffs.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/config.h>
28 /* The alignment between two nodes in the flash memory. */
29 #define JFFS_ALIGN_SIZE 4
31 /* Mark the on-flash space as obsolete when appropriate. */
32 #define JFFS_MARK_OBSOLETE 0
34 #ifndef CONFIG_JFFS_FS_VERBOSE
35 #define CONFIG_JFFS_FS_VERBOSE 1
38 #if CONFIG_JFFS_FS_VERBOSE > 0
46 #if CONFIG_JFFS_FS_VERBOSE > 1
52 #if CONFIG_JFFS_FS_VERBOSE > 2
60 /* How many padding bytes should be inserted between two chunks of data
62 #define JFFS_GET_PAD_BYTES(size) ( (JFFS_ALIGN_SIZE-1) & -(__u32)(size) )
63 #define JFFS_PAD(size) ( (size + (JFFS_ALIGN_SIZE-1)) & ~(JFFS_ALIGN_SIZE-1) )
67 void jffs_free_fm(struct jffs_fm *n);
68 struct jffs_fm *jffs_alloc_fm(void);
73 struct jffs_node *node;
74 struct jffs_node_ref *next;
78 /* The struct jffs_fm represents a chunk of data in the flash memory. */
85 struct jffs_node_ref *nodes; /* USED if != 0. */
95 __u32 min_free_size; /* The minimum free space needed to be able
96 to perform garbage collections. */
97 __u32 max_chunk_size; /* The maximum size of a chunk of data. */
99 struct jffs_control *c;
100 struct jffs_fm *head;
101 struct jffs_fm *tail;
102 struct jffs_fm *head_extra;
103 struct jffs_fm *tail_extra;
104 struct semaphore biglock;
107 /* Notice the two members head_extra and tail_extra in the jffs_control
108 structure above. Those are only used during the scanning of the flash
109 memory; while the file system is being built. If the data in the flash
110 memory is organized like
112 +----------------+------------------+----------------+
113 | USED / DIRTY | FREE | USED / DIRTY |
114 +----------------+------------------+----------------+
116 then the scan is split in two parts. The first scanned part of the
117 flash memory is organized through the members head and tail. The
118 second scanned part is organized with head_extra and tail_extra. When
119 the scan is completed, the two lists are merged together. The jffs_fm
120 struct that head_extra references is the logical beginning of the
121 flash memory so it will be referenced by the head member. */
125 struct jffs_fmcontrol *jffs_build_begin(struct jffs_control *c, int unit);
126 void jffs_build_end(struct jffs_fmcontrol *fmc);
127 void jffs_cleanup_fmcontrol(struct jffs_fmcontrol *fmc);
129 int jffs_fmalloc(struct jffs_fmcontrol *fmc, __u32 size,
130 struct jffs_node *node, struct jffs_fm **result);
131 int jffs_fmfree(struct jffs_fmcontrol *fmc, struct jffs_fm *fm,
132 struct jffs_node *node);
134 __u32 jffs_free_size1(struct jffs_fmcontrol *fmc);
135 __u32 jffs_free_size2(struct jffs_fmcontrol *fmc);
136 void jffs_sync_erase(struct jffs_fmcontrol *fmc, int erased_size);
137 struct jffs_fm *jffs_cut_node(struct jffs_fmcontrol *fmc, __u32 size);
138 struct jffs_node *jffs_get_oldest_node(struct jffs_fmcontrol *fmc);
139 long jffs_erasable_size(struct jffs_fmcontrol *fmc);
140 struct jffs_fm *jffs_fmalloced(struct jffs_fmcontrol *fmc, __u32 offset,
141 __u32 size, struct jffs_node *node);
142 int jffs_add_node(struct jffs_node *node);
143 void jffs_fmfree_partly(struct jffs_fmcontrol *fmc, struct jffs_fm *fm,
146 void jffs_print_fmcontrol(struct jffs_fmcontrol *fmc);
147 void jffs_print_fm(struct jffs_fm *fm);
148 void jffs_print_node_ref(struct jffs_node_ref *ref);
150 #endif /* __LINUX_JFFS_FM_H__ */