📄 nodelist.h
字号:
/* * JFFS2 -- Journalling Flash File System, Version 2. * * Copyright © 2001-2007 Red Hat, Inc. * * Created by David Woodhouse <dwmw2@infradead.org> * * For licensing information, see the file 'LICENCE' in this directory. * */#ifndef __JFFS2_NODELIST_H__#define __JFFS2_NODELIST_H__#include <linux/fs.h>#include <linux/types.h>#include <linux/jffs2.h>#include "jffs2_fs_sb.h"#include "jffs2_fs_i.h"#include "xattr.h"#include "acl.h"#include "summary.h"#ifdef __ECOS#include "os-ecos.h"#else#include <linux/mtd/compatmac.h> /* For compatibility with older kernels */#include "os-linux.h"#endif#define JFFS2_NATIVE_ENDIAN/* Note we handle mode bits conversion from JFFS2 (i.e. Linux) to/from whatever OS we're actually running on here too. */#if defined(JFFS2_NATIVE_ENDIAN)#define cpu_to_je16(x) ((jint16_t){x})#define cpu_to_je32(x) ((jint32_t){x})#define cpu_to_jemode(x) ((jmode_t){os_to_jffs2_mode(x)})#define constant_cpu_to_je16(x) ((jint16_t){x})#define constant_cpu_to_je32(x) ((jint32_t){x})#define je16_to_cpu(x) ((x).v16)#define je32_to_cpu(x) ((x).v32)#define jemode_to_cpu(x) (jffs2_to_os_mode((x).m))#elif defined(JFFS2_BIG_ENDIAN)#define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)})#define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)})#define cpu_to_jemode(x) ((jmode_t){cpu_to_be32(os_to_jffs2_mode(x))})#define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_be16(x)})#define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_be32(x)})#define je16_to_cpu(x) (be16_to_cpu(x.v16))#define je32_to_cpu(x) (be32_to_cpu(x.v32))#define jemode_to_cpu(x) (be32_to_cpu(jffs2_to_os_mode((x).m)))#elif defined(JFFS2_LITTLE_ENDIAN)#define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)})#define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)})#define cpu_to_jemode(x) ((jmode_t){cpu_to_le32(os_to_jffs2_mode(x))})#define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_le16(x)})#define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_le32(x)})#define je16_to_cpu(x) (le16_to_cpu(x.v16))#define je32_to_cpu(x) (le32_to_cpu(x.v32))#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m)))#else#error wibble#endif/* The minimal node header size */#define JFFS2_MIN_NODE_HEADER sizeof(struct jffs2_raw_dirent)/* This is all we need to keep in-core for each raw node during normal operation. As and when we do read_inode on a particular inode, we can scan the nodes which are listed for it and build up a proper map of which nodes are currently valid. JFFSv1 always used to keep that whole map in core for each inode.*/struct jffs2_raw_node_ref{ struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref for this object. If this _is_ the last, it points to the inode_cache, xattr_ref or xattr_datum instead. The common part of those structures has NULL in the first word. See jffs2_raw_ref_to_ic() below */ uint32_t flash_offset;#define TEST_TOTLEN#ifdef TEST_TOTLEN uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */#endif};#define REF_LINK_NODE ((int32_t)-1)#define REF_EMPTY_NODE ((int32_t)-2)/* Use blocks of about 256 bytes */#define REFS_PER_BLOCK ((255/sizeof(struct jffs2_raw_node_ref))-1)static inline struct jffs2_raw_node_ref *ref_next(struct jffs2_raw_node_ref *ref){ ref++; /* Link to another block of refs */ if (ref->flash_offset == REF_LINK_NODE) { ref = ref->next_in_ino; if (!ref) return ref; } /* End of chain */ if (ref->flash_offset == REF_EMPTY_NODE) return NULL; return ref;}static inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw){ while(raw->next_in_ino) raw = raw->next_in_ino; /* NB. This can be a jffs2_xattr_datum or jffs2_xattr_ref and not actually a jffs2_inode_cache. Check ->class */ return ((struct jffs2_inode_cache *)raw);} /* flash_offset & 3 always has to be zero, because nodes are always aligned at 4 bytes. So we have a couple of extra bits to play with, which indicate the node's status; see below: */#define REF_UNCHECKED 0 /* We haven't yet checked the CRC or built its inode */#define REF_OBSOLETE 1 /* Obsolete, can be completely ignored */#define REF_PRISTINE 2 /* Completely clean. GC without looking */#define REF_NORMAL 3 /* Possibly overlapped. Read the page and write again on GC */#define ref_flags(ref) ((ref)->flash_offset & 3)#define ref_offset(ref) ((ref)->flash_offset & ~3)#define ref_obsolete(ref) (((ref)->flash_offset & 3) == REF_OBSOLETE)#define mark_ref_normal(ref) do { (ref)->flash_offset = ref_offset(ref) | REF_NORMAL; } while(0)/* Dirent nodes should be REF_PRISTINE only if they are not a deletion dirent. Deletion dirents should be REF_NORMAL so that GC gets to throw them away when appropriate */#define dirent_node_state(rd) ( (je32_to_cpu((rd)->ino)?REF_PRISTINE:REF_NORMAL) )/* NB: REF_PRISTINE for an inode-less node (ref->next_in_ino == NULL) indicates it is an unknown node of type JFFS2_NODETYPE_RWCOMPAT_COPY, so it'll get copied. If you need to do anything different to GC inode-less nodes, then you need to modify gc.c accordingly. *//* For each inode in the filesystem, we need to keep a record of nlink, because it would be a PITA to scan the whole directory tree at read_inode() time to calculate it, and to keep sufficient information in the raw_node_ref (basically both parent and child inode number for dirent nodes) would take more space than this does. We also keep a pointer to the first physical node which is part of this inode, too.*/struct jffs2_inode_cache { /* First part of structure is shared with other objects which can terminate the raw node refs' next_in_ino list -- which currently struct jffs2_xattr_datum and struct jffs2_xattr_ref. */ struct jffs2_full_dirent *scan_dents; /* Used during scan to hold temporary lists of dirents, and later must be set to NULL to mark the end of the raw_node_ref->next_in_ino chain. */ struct jffs2_raw_node_ref *nodes; uint8_t class; /* It's used for identification */ /* end of shared structure */ uint8_t flags; uint16_t state; uint32_t ino; struct jffs2_inode_cache *next;#ifdef CONFIG_JFFS2_FS_XATTR struct jffs2_xattr_ref *xref;#endif int nlink;};/* Inode states for 'state' above. We need the 'GC' state to prevent someone from doing a read_inode() while we're moving a 'REF_PRISTINE' node without going through all the iget() nonsense */#define INO_STATE_UNCHECKED 0 /* CRC checks not yet done */#define INO_STATE_CHECKING 1 /* CRC checks in progress */#define INO_STATE_PRESENT 2 /* In core */#define INO_STATE_CHECKEDABSENT 3 /* Checked, cleared again */#define INO_STATE_GC 4 /* GCing a 'pristine' node */#define INO_STATE_READING 5 /* In read_inode() */#define INO_STATE_CLEARING 6 /* In clear_inode() */#define INO_FLAGS_XATTR_CHECKED 0x01 /* has no duplicate xattr_ref */#define RAWNODE_CLASS_INODE_CACHE 0#define RAWNODE_CLASS_XATTR_DATUM 1#define RAWNODE_CLASS_XATTR_REF 2#define INOCACHE_HASHSIZE 128#define write_ofs(c) ((c)->nextblock->offset + (c)->sector_size - (c)->nextblock->free_size)/* Larger representation of a raw node, kept in-core only when the struct inode for this particular ino is instantiated.*/struct jffs2_full_dnode{ struct jffs2_raw_node_ref *raw; uint32_t ofs; /* The offset to which the data of this node belongs */ uint32_t size; uint32_t frags; /* Number of fragments which currently refer to this node. When this reaches zero, the node is obsolete. */};/* Even larger representation of a raw node, kept in-core only while we're actually building up the original map of which nodes go where, in read_inode()*/struct jffs2_tmp_dnode_info{ struct rb_node rb; struct jffs2_full_dnode *fn; uint32_t version; uint32_t data_crc; uint32_t partial_crc; uint16_t csize; uint16_t overlapped;};/* Temporary data structure used during readinode. */struct jffs2_readinode_info{ struct rb_root tn_root; struct jffs2_tmp_dnode_info *mdata_tn; uint32_t highest_version; uint32_t latest_mctime;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -