1/*
2 * JFFS -- Journalling 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.h,v 1.1.1.1 2008/10/15 03:27:30 james26_jang 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_H__
21#define __LINUX_JFFS_H__
22
23#include <linux/types.h>
24#include <linux/completion.h>
25
26#define JFFS_VERSION_STRING "1.0"
27
28/* This is a magic number that is used as an identification number for
29   this file system.  It is written to the super_block structure.  */
30#define JFFS_MAGIC_SB_BITMASK 0x07c0  /* 1984 */
31
32/* This is a magic number that every on-flash raw inode begins with.  */
33#define JFFS_MAGIC_BITMASK 0x34383931 /* "1984" */
34
35/* These two bitmasks are the valid ones for the flash memories we have
36   for the moment.  */
37#define JFFS_EMPTY_BITMASK 0xffffffff
38#define JFFS_DIRTY_BITMASK 0x00000000
39
40/* This is the inode number of the root node.  */
41#define JFFS_MIN_INO 1
42
43/* How many slots in the file hash table should we have?  */
44#define JFFS_HASH_SIZE 40
45
46/* Don't use more than 254 bytes as the maximum allowed length of a file's
47   name due to errors that could occur during the scanning of the flash
48   memory. In fact, a name length of 255 or 0xff, could be the result of
49   an uncompleted write.  For instance, if a raw inode is written to the
50   flash memory and there is a power lossage just before the length of
51   the name is written, the length 255 would be interpreted as an illegal
52   value.  */
53#define JFFS_MAX_NAME_LEN 254
54
55/* Commands for ioctl().  */
56#define JFFS_IOCTL_MAGIC 't'
57#define JFFS_PRINT_HASH _IO(JFFS_IOCTL_MAGIC, 90)
58#define JFFS_PRINT_TREE _IO(JFFS_IOCTL_MAGIC, 91)
59#define JFFS_GET_STATUS _IO(JFFS_IOCTL_MAGIC, 92)
60
61#define JFFS_MODIFY_INODE 0x01
62#define JFFS_MODIFY_NAME  0x02
63#define JFFS_MODIFY_DATA  0x04
64#define JFFS_MODIFY_EXIST 0x08
65
66struct jffs_control;
67
68/* The JFFS raw inode structure: Used for storage on physical media.  */
69/* Perhaps the uid, gid, atime, mtime and ctime members should have
70   more space due to future changes in the Linux kernel. Anyhow, since
71   a user of this filesystem probably have to fix a large number of
72   other things, we have decided to not be forward compatible.  */
73struct jffs_raw_inode
74{
75	__u32 magic;      /* A constant magic number.  */
76	__u32 ino;        /* Inode number.  */
77	__u32 pino;       /* Parent's inode number.  */
78	__u32 version;    /* Version number.  */
79	__u32 mode;       /* The file's type or mode.  */
80	__u16 uid;        /* The file's owner.  */
81	__u16 gid;        /* The file's group.  */
82	__u32 atime;      /* Last access time.  */
83	__u32 mtime;      /* Last modification time.  */
84	__u32 ctime;      /* Creation time.  */
85	__u32 offset;     /* Where to begin to write.  */
86	__u32 dsize;      /* Size of the node's data.  */
87	__u32 rsize;      /* How much are going to be replaced?  */
88	__u8 nsize;       /* Name length.  */
89	__u8 nlink;       /* Number of links.  */
90	__u8 spare : 6;   /* For future use.  */
91	__u8 rename : 1;  /* Rename to a name of an already existing file?  */
92	__u8 deleted : 1; /* Has this file been deleted?  */
93	__u8 accurate;    /* The inode is obsolete if accurate == 0.  */
94	__u32 dchksum;    /* Checksum for the data.  */
95	__u16 nchksum;    /* Checksum for the name.  */
96	__u16 chksum;     /* Checksum for the raw inode.  */
97};
98
99/* Define the offset of the accurate byte in struct jffs_raw_inode.  */
100#define JFFS_RAW_INODE_ACCURATE_OFFSET (sizeof(struct jffs_raw_inode) \
101					- 2 * sizeof(__u32) - sizeof(__u8))
102
103/* Define the offset of the chksum member in struct jffs_raw_inode.  */
104#define JFFS_RAW_INODE_CHKSUM_OFFSET (sizeof(struct jffs_raw_inode) \
105				      - sizeof(__u16))
106
107/* Define the offset of the dchksum member in struct jffs_raw_inode.  */
108#define JFFS_RAW_INODE_DCHKSUM_OFFSET (sizeof(struct jffs_raw_inode)   \
109				       - sizeof(__u16) - sizeof(__u16) \
110				       - sizeof(__u32))
111
112
113/* The RAM representation of the node.  The names of pointers to
114   jffs_nodes are very often just called `n' in the source code.  */
115struct jffs_node
116{
117	__u32 ino;          /* Inode number.  */
118	__u32 version;      /* Version number.  */
119	__u32 data_offset;  /* Logic location of the data to insert.  */
120	__u32 data_size;    /* The amount of data this node inserts.  */
121	__u32 removed_size; /* The amount of data that this node removes.  */
122	__u32 fm_offset;    /* Physical location of the data in the actual
123			       flash memory data chunk.  */
124	__u8 name_size;     /* Size of the name.  */
125	struct jffs_fm *fm; /* Physical memory information.  */
126	struct jffs_node *version_prev;
127	struct jffs_node *version_next;
128	struct jffs_node *range_prev;
129	struct jffs_node *range_next;
130};
131
132
133/* The RAM representation of a file (plain files, directories,
134   links, etc.).  Pointers to jffs_files are normally named `f'
135   in the JFFS source code.  */
136struct jffs_file
137{
138	__u32 ino;    /* Inode number.  */
139	__u32 pino;   /* Parent's inode number.  */
140	__u32 mode;   /* file_type, mode  */
141	__u16 uid;    /* owner  */
142	__u16 gid;    /* group  */
143	__u32 atime;  /* Last access time.  */
144	__u32 mtime;  /* Last modification time.  */
145	__u32 ctime;  /* Creation time.  */
146	__u8 nsize;   /* Name length.  */
147	__u8 nlink;   /* Number of links.  */
148	__u8 deleted; /* Has this file been deleted?  */
149	char *name;   /* The name of this file; NULL-terminated.  */
150	__u32 size;   /* The total size of the file's data.  */
151	__u32 highest_version; /* The highest version number of this file.  */
152	struct jffs_control *c;
153	struct jffs_file *parent;   /* Reference to the parent directory.  */
154	struct jffs_file *children; /* Always NULL for plain files.  */
155	struct jffs_file *sibling_prev; /* Siblings in the same directory.  */
156	struct jffs_file *sibling_next;
157	struct list_head hash;    /* hash list.  */
158	struct jffs_node *range_head;   /* The final data.  */
159	struct jffs_node *range_tail;   /* The first data.  */
160	struct jffs_node *version_head; /* The youngest node.  */
161	struct jffs_node *version_tail; /* The oldest node.  */
162};
163
164
165/* This is just a definition of a simple list used for keeping track of
166   files deleted due to a rename.  This list is only used during the
167   mounting of the file system and only if there have been rename operations
168   earlier.  */
169struct jffs_delete_list
170{
171	__u32 ino;
172	struct jffs_delete_list *next;
173};
174
175
176/* A struct for the overall file system control.  Pointers to
177   jffs_control structs are named `c' in the source code.  */
178struct jffs_control
179{
180	struct super_block *sb;		/* Reference to the VFS super block.  */
181	struct jffs_file *root;		/* The root directory file.  */
182	struct list_head *hash;		/* Hash table for finding files by ino.  */
183	struct jffs_fmcontrol *fmc;	/* Flash memory control structure.  */
184	__u32 hash_len;			/* The size of the hash table.  */
185	__u32 next_ino;			/* Next inode number to use for new files.  */
186	__u16 building_fs;		/* Is the file system being built right now?  */
187	struct jffs_delete_list *delete_list; /* Track deleted files.  */
188	pid_t thread_pid;		/* GC thread's PID */
189	struct task_struct *gc_task;	/* GC task struct */
190	struct completion gc_thread_comp; /* GC thread exit mutex */
191	__u32 gc_minfree_threshold;	/* GC trigger thresholds */
192	__u32 gc_maxdirty_threshold;
193};
194
195
196/* Used to inform about flash status.  */
197struct jffs_flash_status
198{
199	__u32 size;
200	__u32 used;
201	__u32 dirty;
202	__u32 begin;
203	__u32 end;
204};
205
206/* This stuff could be used for finding memory leaks.  */
207#define JFFS_MEMORY_DEBUG 0
208
209extern long no_jffs_node;
210extern long no_jffs_file;
211#if defined(JFFS_MEMORY_DEBUG) && JFFS_MEMORY_DEBUG
212extern long no_jffs_control;
213extern long no_jffs_raw_inode;
214extern long no_jffs_node_ref;
215extern long no_jffs_fm;
216extern long no_jffs_fmcontrol;
217extern long no_hash;
218extern long no_name;
219#define DJM(x) x
220#else
221#define DJM(x)
222#endif
223
224#endif /* __LINUX_JFFS_H__ */
225