blob: 9ee6ad29eff5de856f5401464346a5b110324bc3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
23#include <linux/types.h>
24#include <linux/jffs.h>
25#include <linux/mtd/mtd.h>
Ingo Molnar1eb0d672006-03-23 03:00:40 -080026#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/* The alignment between two nodes in the flash memory. */
29#define JFFS_ALIGN_SIZE 4
30
31/* Mark the on-flash space as obsolete when appropriate. */
32#define JFFS_MARK_OBSOLETE 0
33
34#ifndef CONFIG_JFFS_FS_VERBOSE
35#define CONFIG_JFFS_FS_VERBOSE 1
36#endif
37
38#if CONFIG_JFFS_FS_VERBOSE > 0
39#define D(x) x
40#define D1(x) D(x)
41#else
42#define D(x)
43#define D1(x)
44#endif
45
46#if CONFIG_JFFS_FS_VERBOSE > 1
47#define D2(x) D(x)
48#else
49#define D2(x)
50#endif
51
52#if CONFIG_JFFS_FS_VERBOSE > 2
53#define D3(x) D(x)
54#else
55#define D3(x)
56#endif
57
58#define ASSERT(x) x
59
60/* How many padding bytes should be inserted between two chunks of data
61 on the flash? */
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) )
64
65
66
67struct jffs_node_ref
68{
69 struct jffs_node *node;
70 struct jffs_node_ref *next;
71};
72
73
74/* The struct jffs_fm represents a chunk of data in the flash memory. */
75struct jffs_fm
76{
77 __u32 offset;
78 __u32 size;
79 struct jffs_fm *prev;
80 struct jffs_fm *next;
81 struct jffs_node_ref *nodes; /* USED if != 0. */
82};
83
84struct jffs_fmcontrol
85{
86 __u32 flash_size;
87 __u32 used_size;
88 __u32 dirty_size;
89 __u32 free_size;
90 __u32 sector_size;
91 __u32 min_free_size; /* The minimum free space needed to be able
92 to perform garbage collections. */
93 __u32 max_chunk_size; /* The maximum size of a chunk of data. */
94 struct mtd_info *mtd;
95 struct jffs_control *c;
96 struct jffs_fm *head;
97 struct jffs_fm *tail;
98 struct jffs_fm *head_extra;
99 struct jffs_fm *tail_extra;
Ingo Molnar1eb0d672006-03-23 03:00:40 -0800100 struct mutex biglock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
103/* Notice the two members head_extra and tail_extra in the jffs_control
104 structure above. Those are only used during the scanning of the flash
105 memory; while the file system is being built. If the data in the flash
106 memory is organized like
107
108 +----------------+------------------+----------------+
109 | USED / DIRTY | FREE | USED / DIRTY |
110 +----------------+------------------+----------------+
111
112 then the scan is split in two parts. The first scanned part of the
113 flash memory is organized through the members head and tail. The
114 second scanned part is organized with head_extra and tail_extra. When
115 the scan is completed, the two lists are merged together. The jffs_fm
116 struct that head_extra references is the logical beginning of the
117 flash memory so it will be referenced by the head member. */
118
119
120
121struct jffs_fmcontrol *jffs_build_begin(struct jffs_control *c, int unit);
122void jffs_build_end(struct jffs_fmcontrol *fmc);
123void jffs_cleanup_fmcontrol(struct jffs_fmcontrol *fmc);
124
125int jffs_fmalloc(struct jffs_fmcontrol *fmc, __u32 size,
126 struct jffs_node *node, struct jffs_fm **result);
127int jffs_fmfree(struct jffs_fmcontrol *fmc, struct jffs_fm *fm,
128 struct jffs_node *node);
129
130__u32 jffs_free_size1(struct jffs_fmcontrol *fmc);
131__u32 jffs_free_size2(struct jffs_fmcontrol *fmc);
132void jffs_sync_erase(struct jffs_fmcontrol *fmc, int erased_size);
133struct jffs_fm *jffs_cut_node(struct jffs_fmcontrol *fmc, __u32 size);
134struct jffs_node *jffs_get_oldest_node(struct jffs_fmcontrol *fmc);
135long jffs_erasable_size(struct jffs_fmcontrol *fmc);
136struct jffs_fm *jffs_fmalloced(struct jffs_fmcontrol *fmc, __u32 offset,
137 __u32 size, struct jffs_node *node);
138int jffs_add_node(struct jffs_node *node);
139void jffs_fmfree_partly(struct jffs_fmcontrol *fmc, struct jffs_fm *fm,
140 __u32 size);
141
Adrian Bunk94c9eca2005-06-25 14:59:06 -0700142#if CONFIG_JFFS_FS_VERBOSE > 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143void jffs_print_fmcontrol(struct jffs_fmcontrol *fmc);
Adrian Bunk94c9eca2005-06-25 14:59:06 -0700144#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#if 0
146void jffs_print_node_ref(struct jffs_node_ref *ref);
147#endif /* 0 */
148
149#endif /* __LINUX_JFFS_FM_H__ */