jffs.h 8.1 KB

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