Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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.20 2001/09/18 21:33:37 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_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 | /* XXX: This is something that we should try to get rid of in the future. */ |
| 62 | #define JFFS_MODIFY_INODE 0x01 |
| 63 | #define JFFS_MODIFY_NAME 0x02 |
| 64 | #define JFFS_MODIFY_DATA 0x04 |
| 65 | #define JFFS_MODIFY_EXIST 0x08 |
| 66 | |
| 67 | struct jffs_control; |
| 68 | |
| 69 | /* The JFFS raw inode structure: Used for storage on physical media. */ |
| 70 | /* Perhaps the uid, gid, atime, mtime and ctime members should have |
| 71 | more space due to future changes in the Linux kernel. Anyhow, since |
| 72 | a user of this filesystem probably have to fix a large number of |
| 73 | other things, we have decided to not be forward compatible. */ |
| 74 | struct jffs_raw_inode |
| 75 | { |
| 76 | __u32 magic; /* A constant magic number. */ |
| 77 | __u32 ino; /* Inode number. */ |
| 78 | __u32 pino; /* Parent's inode number. */ |
| 79 | __u32 version; /* Version number. */ |
| 80 | __u32 mode; /* The file's type or mode. */ |
| 81 | __u16 uid; /* The file's owner. */ |
| 82 | __u16 gid; /* The file's group. */ |
| 83 | __u32 atime; /* Last access time. */ |
| 84 | __u32 mtime; /* Last modification time. */ |
| 85 | __u32 ctime; /* Creation time. */ |
| 86 | __u32 offset; /* Where to begin to write. */ |
| 87 | __u32 dsize; /* Size of the node's data. */ |
| 88 | __u32 rsize; /* How much are going to be replaced? */ |
| 89 | __u8 nsize; /* Name length. */ |
| 90 | __u8 nlink; /* Number of links. */ |
| 91 | __u8 spare : 6; /* For future use. */ |
| 92 | __u8 rename : 1; /* Rename to a name of an already existing file? */ |
| 93 | __u8 deleted : 1; /* Has this file been deleted? */ |
| 94 | __u8 accurate; /* The inode is obsolete if accurate == 0. */ |
| 95 | __u32 dchksum; /* Checksum for the data. */ |
| 96 | __u16 nchksum; /* Checksum for the name. */ |
| 97 | __u16 chksum; /* Checksum for the raw inode. */ |
| 98 | }; |
| 99 | |
| 100 | /* Define the offset of the accurate byte in struct jffs_raw_inode. */ |
| 101 | #define JFFS_RAW_INODE_ACCURATE_OFFSET (sizeof(struct jffs_raw_inode) \ |
| 102 | - 2 * sizeof(__u32) - sizeof(__u8)) |
| 103 | |
| 104 | /* Define the offset of the chksum member in struct jffs_raw_inode. */ |
| 105 | #define JFFS_RAW_INODE_CHKSUM_OFFSET (sizeof(struct jffs_raw_inode) \ |
| 106 | - sizeof(__u16)) |
| 107 | |
| 108 | /* Define the offset of the dchksum member in struct jffs_raw_inode. */ |
| 109 | #define JFFS_RAW_INODE_DCHKSUM_OFFSET (sizeof(struct jffs_raw_inode) \ |
| 110 | - sizeof(__u16) - sizeof(__u16) \ |
| 111 | - sizeof(__u32)) |
| 112 | |
| 113 | |
| 114 | /* The RAM representation of the node. The names of pointers to |
| 115 | jffs_nodes are very often just called `n' in the source code. */ |
| 116 | struct jffs_node |
| 117 | { |
| 118 | __u32 ino; /* Inode number. */ |
| 119 | __u32 version; /* Version number. */ |
| 120 | __u32 data_offset; /* Logic location of the data to insert. */ |
| 121 | __u32 data_size; /* The amount of data this node inserts. */ |
| 122 | __u32 removed_size; /* The amount of data that this node removes. */ |
| 123 | __u32 fm_offset; /* Physical location of the data in the actual |
| 124 | flash memory data chunk. */ |
| 125 | __u8 name_size; /* Size of the name. */ |
| 126 | struct jffs_fm *fm; /* Physical memory information. */ |
| 127 | struct jffs_node *version_prev; |
| 128 | struct jffs_node *version_next; |
| 129 | struct jffs_node *range_prev; |
| 130 | struct jffs_node *range_next; |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | /* The RAM representation of a file (plain files, directories, |
| 135 | links, etc.). Pointers to jffs_files are normally named `f' |
| 136 | in the JFFS source code. */ |
| 137 | struct jffs_file |
| 138 | { |
| 139 | __u32 ino; /* Inode number. */ |
| 140 | __u32 pino; /* Parent's inode number. */ |
| 141 | __u32 mode; /* file_type, mode */ |
| 142 | __u16 uid; /* owner */ |
| 143 | __u16 gid; /* group */ |
| 144 | __u32 atime; /* Last access time. */ |
| 145 | __u32 mtime; /* Last modification time. */ |
| 146 | __u32 ctime; /* Creation time. */ |
| 147 | __u8 nsize; /* Name length. */ |
| 148 | __u8 nlink; /* Number of links. */ |
| 149 | __u8 deleted; /* Has this file been deleted? */ |
| 150 | char *name; /* The name of this file; NULL-terminated. */ |
| 151 | __u32 size; /* The total size of the file's data. */ |
| 152 | __u32 highest_version; /* The highest version number of this file. */ |
| 153 | struct jffs_control *c; |
| 154 | struct jffs_file *parent; /* Reference to the parent directory. */ |
| 155 | struct jffs_file *children; /* Always NULL for plain files. */ |
| 156 | struct jffs_file *sibling_prev; /* Siblings in the same directory. */ |
| 157 | struct jffs_file *sibling_next; |
| 158 | struct list_head hash; /* hash list. */ |
| 159 | struct jffs_node *range_head; /* The final data. */ |
| 160 | struct jffs_node *range_tail; /* The first data. */ |
| 161 | struct jffs_node *version_head; /* The youngest node. */ |
| 162 | struct jffs_node *version_tail; /* The oldest node. */ |
| 163 | }; |
| 164 | |
| 165 | |
| 166 | /* This is just a definition of a simple list used for keeping track of |
| 167 | files deleted due to a rename. This list is only used during the |
| 168 | mounting of the file system and only if there have been rename operations |
| 169 | earlier. */ |
| 170 | struct jffs_delete_list |
| 171 | { |
| 172 | __u32 ino; |
| 173 | struct jffs_delete_list *next; |
| 174 | }; |
| 175 | |
| 176 | |
| 177 | /* A struct for the overall file system control. Pointers to |
| 178 | jffs_control structs are named `c' in the source code. */ |
| 179 | struct jffs_control |
| 180 | { |
| 181 | struct super_block *sb; /* Reference to the VFS super block. */ |
| 182 | struct jffs_file *root; /* The root directory file. */ |
| 183 | struct list_head *hash; /* Hash table for finding files by ino. */ |
| 184 | struct jffs_fmcontrol *fmc; /* Flash memory control structure. */ |
| 185 | __u32 hash_len; /* The size of the hash table. */ |
| 186 | __u32 next_ino; /* Next inode number to use for new files. */ |
| 187 | __u16 building_fs; /* Is the file system being built right now? */ |
| 188 | struct jffs_delete_list *delete_list; /* Track deleted files. */ |
| 189 | pid_t thread_pid; /* GC thread's PID */ |
| 190 | struct task_struct *gc_task; /* GC task struct */ |
| 191 | struct completion gc_thread_comp; /* GC thread exit mutex */ |
| 192 | __u32 gc_minfree_threshold; /* GC trigger thresholds */ |
| 193 | __u32 gc_maxdirty_threshold; |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | /* Used to inform about flash status. */ |
| 198 | struct jffs_flash_status |
| 199 | { |
| 200 | __u32 size; |
| 201 | __u32 used; |
| 202 | __u32 dirty; |
| 203 | __u32 begin; |
| 204 | __u32 end; |
| 205 | }; |
| 206 | |
| 207 | /* This stuff could be used for finding memory leaks. */ |
| 208 | #define JFFS_MEMORY_DEBUG 0 |
| 209 | |
| 210 | extern long no_jffs_node; |
| 211 | #if defined(JFFS_MEMORY_DEBUG) && JFFS_MEMORY_DEBUG |
| 212 | extern long no_jffs_control; |
| 213 | extern long no_jffs_raw_inode; |
| 214 | extern long no_jffs_node_ref; |
| 215 | extern long no_jffs_fm; |
| 216 | extern long no_jffs_fmcontrol; |
| 217 | extern long no_hash; |
| 218 | extern long no_name; |
| 219 | #define DJM(x) x |
| 220 | #else |
| 221 | #define DJM(x) |
| 222 | #endif |
| 223 | |
| 224 | #endif /* __LINUX_JFFS_H__ */ |