162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * JFFS2 -- Journalling Flash File System, Version 2. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright © 2001-2007 Red Hat, Inc. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Created by David Woodhouse <dwmw2@infradead.org> 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * For licensing information, see the file 'LICENCE' in this directory. 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifndef __JFFS2_NODELIST_H__ 1362306a36Sopenharmony_ci#define __JFFS2_NODELIST_H__ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/fs.h> 1662306a36Sopenharmony_ci#include <linux/types.h> 1762306a36Sopenharmony_ci#include <linux/jffs2.h> 1862306a36Sopenharmony_ci#include "jffs2_fs_sb.h" 1962306a36Sopenharmony_ci#include "jffs2_fs_i.h" 2062306a36Sopenharmony_ci#include "xattr.h" 2162306a36Sopenharmony_ci#include "acl.h" 2262306a36Sopenharmony_ci#include "summary.h" 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#ifdef __ECOS 2562306a36Sopenharmony_ci#include "os-ecos.h" 2662306a36Sopenharmony_ci#else 2762306a36Sopenharmony_ci#include "os-linux.h" 2862306a36Sopenharmony_ci#endif 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define JFFS2_NATIVE_ENDIAN 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* Note we handle mode bits conversion from JFFS2 (i.e. Linux) to/from 3362306a36Sopenharmony_ci whatever OS we're actually running on here too. */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#if defined(JFFS2_NATIVE_ENDIAN) 3662306a36Sopenharmony_ci#define cpu_to_je16(x) ((jint16_t){x}) 3762306a36Sopenharmony_ci#define cpu_to_je32(x) ((jint32_t){x}) 3862306a36Sopenharmony_ci#define cpu_to_jemode(x) ((jmode_t){os_to_jffs2_mode(x)}) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define constant_cpu_to_je16(x) ((jint16_t){x}) 4162306a36Sopenharmony_ci#define constant_cpu_to_je32(x) ((jint32_t){x}) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define je16_to_cpu(x) ((x).v16) 4462306a36Sopenharmony_ci#define je32_to_cpu(x) ((x).v32) 4562306a36Sopenharmony_ci#define jemode_to_cpu(x) (jffs2_to_os_mode((x).m)) 4662306a36Sopenharmony_ci#elif defined(JFFS2_BIG_ENDIAN) 4762306a36Sopenharmony_ci#define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)}) 4862306a36Sopenharmony_ci#define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)}) 4962306a36Sopenharmony_ci#define cpu_to_jemode(x) ((jmode_t){cpu_to_be32(os_to_jffs2_mode(x))}) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_be16(x)}) 5262306a36Sopenharmony_ci#define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_be32(x)}) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define je16_to_cpu(x) (be16_to_cpu(x.v16)) 5562306a36Sopenharmony_ci#define je32_to_cpu(x) (be32_to_cpu(x.v32)) 5662306a36Sopenharmony_ci#define jemode_to_cpu(x) (be32_to_cpu(jffs2_to_os_mode((x).m))) 5762306a36Sopenharmony_ci#elif defined(JFFS2_LITTLE_ENDIAN) 5862306a36Sopenharmony_ci#define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)}) 5962306a36Sopenharmony_ci#define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)}) 6062306a36Sopenharmony_ci#define cpu_to_jemode(x) ((jmode_t){cpu_to_le32(os_to_jffs2_mode(x))}) 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_le16(x)}) 6362306a36Sopenharmony_ci#define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_le32(x)}) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define je16_to_cpu(x) (le16_to_cpu(x.v16)) 6662306a36Sopenharmony_ci#define je32_to_cpu(x) (le32_to_cpu(x.v32)) 6762306a36Sopenharmony_ci#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m))) 6862306a36Sopenharmony_ci#else 6962306a36Sopenharmony_ci#error wibble 7062306a36Sopenharmony_ci#endif 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* The minimal node header size */ 7362306a36Sopenharmony_ci#define JFFS2_MIN_NODE_HEADER sizeof(struct jffs2_raw_dirent) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* 7662306a36Sopenharmony_ci This is all we need to keep in-core for each raw node during normal 7762306a36Sopenharmony_ci operation. As and when we do read_inode on a particular inode, we can 7862306a36Sopenharmony_ci scan the nodes which are listed for it and build up a proper map of 7962306a36Sopenharmony_ci which nodes are currently valid. JFFSv1 always used to keep that whole 8062306a36Sopenharmony_ci map in core for each inode. 8162306a36Sopenharmony_ci*/ 8262306a36Sopenharmony_cistruct jffs2_raw_node_ref 8362306a36Sopenharmony_ci{ 8462306a36Sopenharmony_ci struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref 8562306a36Sopenharmony_ci for this object. If this _is_ the last, it points to the inode_cache, 8662306a36Sopenharmony_ci xattr_ref or xattr_datum instead. The common part of those structures 8762306a36Sopenharmony_ci has NULL in the first word. See jffs2_raw_ref_to_ic() below */ 8862306a36Sopenharmony_ci uint32_t flash_offset; 8962306a36Sopenharmony_ci#undef TEST_TOTLEN 9062306a36Sopenharmony_ci#ifdef TEST_TOTLEN 9162306a36Sopenharmony_ci uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */ 9262306a36Sopenharmony_ci#endif 9362306a36Sopenharmony_ci}; 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci#define REF_LINK_NODE ((int32_t)-1) 9662306a36Sopenharmony_ci#define REF_EMPTY_NODE ((int32_t)-2) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/* Use blocks of about 256 bytes */ 9962306a36Sopenharmony_ci#define REFS_PER_BLOCK ((255/sizeof(struct jffs2_raw_node_ref))-1) 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistatic inline struct jffs2_raw_node_ref *ref_next(struct jffs2_raw_node_ref *ref) 10262306a36Sopenharmony_ci{ 10362306a36Sopenharmony_ci ref++; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci /* Link to another block of refs */ 10662306a36Sopenharmony_ci if (ref->flash_offset == REF_LINK_NODE) { 10762306a36Sopenharmony_ci ref = ref->next_in_ino; 10862306a36Sopenharmony_ci if (!ref) 10962306a36Sopenharmony_ci return ref; 11062306a36Sopenharmony_ci } 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci /* End of chain */ 11362306a36Sopenharmony_ci if (ref->flash_offset == REF_EMPTY_NODE) 11462306a36Sopenharmony_ci return NULL; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci return ref; 11762306a36Sopenharmony_ci} 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_cistatic inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw) 12062306a36Sopenharmony_ci{ 12162306a36Sopenharmony_ci while(raw->next_in_ino) 12262306a36Sopenharmony_ci raw = raw->next_in_ino; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci /* NB. This can be a jffs2_xattr_datum or jffs2_xattr_ref and 12562306a36Sopenharmony_ci not actually a jffs2_inode_cache. Check ->class */ 12662306a36Sopenharmony_ci return ((struct jffs2_inode_cache *)raw); 12762306a36Sopenharmony_ci} 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci /* flash_offset & 3 always has to be zero, because nodes are 13062306a36Sopenharmony_ci always aligned at 4 bytes. So we have a couple of extra bits 13162306a36Sopenharmony_ci to play with, which indicate the node's status; see below: */ 13262306a36Sopenharmony_ci#define REF_UNCHECKED 0 /* We haven't yet checked the CRC or built its inode */ 13362306a36Sopenharmony_ci#define REF_OBSOLETE 1 /* Obsolete, can be completely ignored */ 13462306a36Sopenharmony_ci#define REF_PRISTINE 2 /* Completely clean. GC without looking */ 13562306a36Sopenharmony_ci#define REF_NORMAL 3 /* Possibly overlapped. Read the page and write again on GC */ 13662306a36Sopenharmony_ci#define ref_flags(ref) ((ref)->flash_offset & 3) 13762306a36Sopenharmony_ci#define ref_offset(ref) ((ref)->flash_offset & ~3) 13862306a36Sopenharmony_ci#define ref_obsolete(ref) (((ref)->flash_offset & 3) == REF_OBSOLETE) 13962306a36Sopenharmony_ci#define mark_ref_normal(ref) do { (ref)->flash_offset = ref_offset(ref) | REF_NORMAL; } while(0) 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci/* Dirent nodes should be REF_PRISTINE only if they are not a deletion 14262306a36Sopenharmony_ci dirent. Deletion dirents should be REF_NORMAL so that GC gets to 14362306a36Sopenharmony_ci throw them away when appropriate */ 14462306a36Sopenharmony_ci#define dirent_node_state(rd) ( (je32_to_cpu((rd)->ino)?REF_PRISTINE:REF_NORMAL) ) 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci/* NB: REF_PRISTINE for an inode-less node (ref->next_in_ino == NULL) indicates 14762306a36Sopenharmony_ci it is an unknown node of type JFFS2_NODETYPE_RWCOMPAT_COPY, so it'll get 14862306a36Sopenharmony_ci copied. If you need to do anything different to GC inode-less nodes, then 14962306a36Sopenharmony_ci you need to modify gc.c accordingly. */ 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci/* For each inode in the filesystem, we need to keep a record of 15262306a36Sopenharmony_ci nlink, because it would be a PITA to scan the whole directory tree 15362306a36Sopenharmony_ci at read_inode() time to calculate it, and to keep sufficient information 15462306a36Sopenharmony_ci in the raw_node_ref (basically both parent and child inode number for 15562306a36Sopenharmony_ci dirent nodes) would take more space than this does. We also keep 15662306a36Sopenharmony_ci a pointer to the first physical node which is part of this inode, too. 15762306a36Sopenharmony_ci*/ 15862306a36Sopenharmony_cistruct jffs2_inode_cache { 15962306a36Sopenharmony_ci /* First part of structure is shared with other objects which 16062306a36Sopenharmony_ci can terminate the raw node refs' next_in_ino list -- which 16162306a36Sopenharmony_ci currently struct jffs2_xattr_datum and struct jffs2_xattr_ref. */ 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci struct jffs2_full_dirent *scan_dents; /* Used during scan to hold 16462306a36Sopenharmony_ci temporary lists of dirents, and later must be set to 16562306a36Sopenharmony_ci NULL to mark the end of the raw_node_ref->next_in_ino 16662306a36Sopenharmony_ci chain. */ 16762306a36Sopenharmony_ci struct jffs2_raw_node_ref *nodes; 16862306a36Sopenharmony_ci uint8_t class; /* It's used for identification */ 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci /* end of shared structure */ 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci uint8_t flags; 17362306a36Sopenharmony_ci uint16_t state; 17462306a36Sopenharmony_ci uint32_t ino; 17562306a36Sopenharmony_ci struct jffs2_inode_cache *next; 17662306a36Sopenharmony_ci#ifdef CONFIG_JFFS2_FS_XATTR 17762306a36Sopenharmony_ci struct jffs2_xattr_ref *xref; 17862306a36Sopenharmony_ci#endif 17962306a36Sopenharmony_ci uint32_t pino_nlink; /* Directories store parent inode 18062306a36Sopenharmony_ci here; other inodes store nlink. 18162306a36Sopenharmony_ci Zero always means that it's 18262306a36Sopenharmony_ci completely unlinked. */ 18362306a36Sopenharmony_ci}; 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/* Inode states for 'state' above. We need the 'GC' state to prevent 18662306a36Sopenharmony_ci someone from doing a read_inode() while we're moving a 'REF_PRISTINE' 18762306a36Sopenharmony_ci node without going through all the iget() nonsense */ 18862306a36Sopenharmony_ci#define INO_STATE_UNCHECKED 0 /* CRC checks not yet done */ 18962306a36Sopenharmony_ci#define INO_STATE_CHECKING 1 /* CRC checks in progress */ 19062306a36Sopenharmony_ci#define INO_STATE_PRESENT 2 /* In core */ 19162306a36Sopenharmony_ci#define INO_STATE_CHECKEDABSENT 3 /* Checked, cleared again */ 19262306a36Sopenharmony_ci#define INO_STATE_GC 4 /* GCing a 'pristine' node */ 19362306a36Sopenharmony_ci#define INO_STATE_READING 5 /* In read_inode() */ 19462306a36Sopenharmony_ci#define INO_STATE_CLEARING 6 /* In clear_inode() */ 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci#define INO_FLAGS_XATTR_CHECKED 0x01 /* has no duplicate xattr_ref */ 19762306a36Sopenharmony_ci#define INO_FLAGS_IS_DIR 0x02 /* is a directory */ 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#define RAWNODE_CLASS_INODE_CACHE 0 20062306a36Sopenharmony_ci#define RAWNODE_CLASS_XATTR_DATUM 1 20162306a36Sopenharmony_ci#define RAWNODE_CLASS_XATTR_REF 2 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci#define INOCACHE_HASHSIZE_MIN 128 20462306a36Sopenharmony_ci#define INOCACHE_HASHSIZE_MAX 1024 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci#define write_ofs(c) ((c)->nextblock->offset + (c)->sector_size - (c)->nextblock->free_size) 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci/* 20962306a36Sopenharmony_ci Larger representation of a raw node, kept in-core only when the 21062306a36Sopenharmony_ci struct inode for this particular ino is instantiated. 21162306a36Sopenharmony_ci*/ 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_cistruct jffs2_full_dnode 21462306a36Sopenharmony_ci{ 21562306a36Sopenharmony_ci struct jffs2_raw_node_ref *raw; 21662306a36Sopenharmony_ci uint32_t ofs; /* The offset to which the data of this node belongs */ 21762306a36Sopenharmony_ci uint32_t size; 21862306a36Sopenharmony_ci uint32_t frags; /* Number of fragments which currently refer 21962306a36Sopenharmony_ci to this node. When this reaches zero, 22062306a36Sopenharmony_ci the node is obsolete. */ 22162306a36Sopenharmony_ci}; 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* 22462306a36Sopenharmony_ci Even larger representation of a raw node, kept in-core only while 22562306a36Sopenharmony_ci we're actually building up the original map of which nodes go where, 22662306a36Sopenharmony_ci in read_inode() 22762306a36Sopenharmony_ci*/ 22862306a36Sopenharmony_cistruct jffs2_tmp_dnode_info 22962306a36Sopenharmony_ci{ 23062306a36Sopenharmony_ci struct rb_node rb; 23162306a36Sopenharmony_ci struct jffs2_full_dnode *fn; 23262306a36Sopenharmony_ci uint32_t version; 23362306a36Sopenharmony_ci uint32_t data_crc; 23462306a36Sopenharmony_ci uint32_t partial_crc; 23562306a36Sopenharmony_ci uint32_t csize; 23662306a36Sopenharmony_ci uint16_t overlapped; 23762306a36Sopenharmony_ci}; 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci/* Temporary data structure used during readinode. */ 24062306a36Sopenharmony_cistruct jffs2_readinode_info 24162306a36Sopenharmony_ci{ 24262306a36Sopenharmony_ci struct rb_root tn_root; 24362306a36Sopenharmony_ci struct jffs2_tmp_dnode_info *mdata_tn; 24462306a36Sopenharmony_ci uint32_t highest_version; 24562306a36Sopenharmony_ci uint32_t latest_mctime; 24662306a36Sopenharmony_ci uint32_t mctime_ver; 24762306a36Sopenharmony_ci struct jffs2_full_dirent *fds; 24862306a36Sopenharmony_ci struct jffs2_raw_node_ref *latest_ref; 24962306a36Sopenharmony_ci}; 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_cistruct jffs2_full_dirent 25262306a36Sopenharmony_ci{ 25362306a36Sopenharmony_ci union { 25462306a36Sopenharmony_ci struct jffs2_raw_node_ref *raw; 25562306a36Sopenharmony_ci struct jffs2_inode_cache *ic; /* Just during part of build */ 25662306a36Sopenharmony_ci }; 25762306a36Sopenharmony_ci struct jffs2_full_dirent *next; 25862306a36Sopenharmony_ci uint32_t version; 25962306a36Sopenharmony_ci uint32_t ino; /* == zero for unlink */ 26062306a36Sopenharmony_ci unsigned int nhash; 26162306a36Sopenharmony_ci unsigned char type; 26262306a36Sopenharmony_ci unsigned char name[]; 26362306a36Sopenharmony_ci}; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci/* 26662306a36Sopenharmony_ci Fragments - used to build a map of which raw node to obtain 26762306a36Sopenharmony_ci data from for each part of the ino 26862306a36Sopenharmony_ci*/ 26962306a36Sopenharmony_cistruct jffs2_node_frag 27062306a36Sopenharmony_ci{ 27162306a36Sopenharmony_ci struct rb_node rb; 27262306a36Sopenharmony_ci struct jffs2_full_dnode *node; /* NULL for holes */ 27362306a36Sopenharmony_ci uint32_t size; 27462306a36Sopenharmony_ci uint32_t ofs; /* The offset to which this fragment belongs */ 27562306a36Sopenharmony_ci}; 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_cistruct jffs2_eraseblock 27862306a36Sopenharmony_ci{ 27962306a36Sopenharmony_ci struct list_head list; 28062306a36Sopenharmony_ci int bad_count; 28162306a36Sopenharmony_ci uint32_t offset; /* of this block in the MTD */ 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci uint32_t unchecked_size; 28462306a36Sopenharmony_ci uint32_t used_size; 28562306a36Sopenharmony_ci uint32_t dirty_size; 28662306a36Sopenharmony_ci uint32_t wasted_size; 28762306a36Sopenharmony_ci uint32_t free_size; /* Note that sector_size - free_size 28862306a36Sopenharmony_ci is the address of the first free space */ 28962306a36Sopenharmony_ci uint32_t allocated_refs; 29062306a36Sopenharmony_ci struct jffs2_raw_node_ref *first_node; 29162306a36Sopenharmony_ci struct jffs2_raw_node_ref *last_node; 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ci struct jffs2_raw_node_ref *gc_node; /* Next node to be garbage collected */ 29462306a36Sopenharmony_ci}; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_cistatic inline int jffs2_blocks_use_vmalloc(struct jffs2_sb_info *c) 29762306a36Sopenharmony_ci{ 29862306a36Sopenharmony_ci return ((c->flash_size / c->sector_size) * sizeof (struct jffs2_eraseblock)) > (128 * 1024); 29962306a36Sopenharmony_ci} 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci#define ref_totlen(a, b, c) __jffs2_ref_totlen((a), (b), (c)) 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ci#define ALLOC_NORMAL 0 /* Normal allocation */ 30462306a36Sopenharmony_ci#define ALLOC_DELETION 1 /* Deletion node. Best to allow it */ 30562306a36Sopenharmony_ci#define ALLOC_GC 2 /* Space requested for GC. Give it or die */ 30662306a36Sopenharmony_ci#define ALLOC_NORETRY 3 /* For jffs2_write_dnode: On failure, return -EAGAIN instead of retrying */ 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci/* How much dirty space before it goes on the very_dirty_list */ 30962306a36Sopenharmony_ci#define VERYDIRTY(c, size) ((size) >= ((c)->sector_size / 2)) 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci/* check if dirty space is more than 255 Byte */ 31262306a36Sopenharmony_ci#define ISDIRTY(size) ((size) > sizeof (struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN) 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci#define PAD(x) (((x)+3)&~3) 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_cistatic inline int jffs2_encode_dev(union jffs2_device_node *jdev, dev_t rdev) 31762306a36Sopenharmony_ci{ 31862306a36Sopenharmony_ci if (old_valid_dev(rdev)) { 31962306a36Sopenharmony_ci jdev->old_id = cpu_to_je16(old_encode_dev(rdev)); 32062306a36Sopenharmony_ci return sizeof(jdev->old_id); 32162306a36Sopenharmony_ci } else { 32262306a36Sopenharmony_ci jdev->new_id = cpu_to_je32(new_encode_dev(rdev)); 32362306a36Sopenharmony_ci return sizeof(jdev->new_id); 32462306a36Sopenharmony_ci } 32562306a36Sopenharmony_ci} 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_cistatic inline struct jffs2_node_frag *frag_first(struct rb_root *root) 32862306a36Sopenharmony_ci{ 32962306a36Sopenharmony_ci struct rb_node *node = rb_first(root); 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci if (!node) 33262306a36Sopenharmony_ci return NULL; 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_ci return rb_entry(node, struct jffs2_node_frag, rb); 33562306a36Sopenharmony_ci} 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_cistatic inline struct jffs2_node_frag *frag_last(struct rb_root *root) 33862306a36Sopenharmony_ci{ 33962306a36Sopenharmony_ci struct rb_node *node = rb_last(root); 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci if (!node) 34262306a36Sopenharmony_ci return NULL; 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci return rb_entry(node, struct jffs2_node_frag, rb); 34562306a36Sopenharmony_ci} 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci#define frag_next(frag) rb_entry(rb_next(&(frag)->rb), struct jffs2_node_frag, rb) 34862306a36Sopenharmony_ci#define frag_prev(frag) rb_entry(rb_prev(&(frag)->rb), struct jffs2_node_frag, rb) 34962306a36Sopenharmony_ci#define frag_parent(frag) rb_entry(rb_parent(&(frag)->rb), struct jffs2_node_frag, rb) 35062306a36Sopenharmony_ci#define frag_left(frag) rb_entry((frag)->rb.rb_left, struct jffs2_node_frag, rb) 35162306a36Sopenharmony_ci#define frag_right(frag) rb_entry((frag)->rb.rb_right, struct jffs2_node_frag, rb) 35262306a36Sopenharmony_ci#define frag_erase(frag, list) rb_erase(&frag->rb, list) 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci#define tn_next(tn) rb_entry(rb_next(&(tn)->rb), struct jffs2_tmp_dnode_info, rb) 35562306a36Sopenharmony_ci#define tn_prev(tn) rb_entry(rb_prev(&(tn)->rb), struct jffs2_tmp_dnode_info, rb) 35662306a36Sopenharmony_ci#define tn_parent(tn) rb_entry(rb_parent(&(tn)->rb), struct jffs2_tmp_dnode_info, rb) 35762306a36Sopenharmony_ci#define tn_left(tn) rb_entry((tn)->rb.rb_left, struct jffs2_tmp_dnode_info, rb) 35862306a36Sopenharmony_ci#define tn_right(tn) rb_entry((tn)->rb.rb_right, struct jffs2_tmp_dnode_info, rb) 35962306a36Sopenharmony_ci#define tn_erase(tn, list) rb_erase(&tn->rb, list) 36062306a36Sopenharmony_ci#define tn_last(list) rb_entry(rb_last(list), struct jffs2_tmp_dnode_info, rb) 36162306a36Sopenharmony_ci#define tn_first(list) rb_entry(rb_first(list), struct jffs2_tmp_dnode_info, rb) 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci/* nodelist.c */ 36462306a36Sopenharmony_civoid jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list); 36562306a36Sopenharmony_civoid jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state); 36662306a36Sopenharmony_cistruct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino); 36762306a36Sopenharmony_civoid jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new); 36862306a36Sopenharmony_civoid jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old); 36962306a36Sopenharmony_civoid jffs2_free_ino_caches(struct jffs2_sb_info *c); 37062306a36Sopenharmony_civoid jffs2_free_raw_node_refs(struct jffs2_sb_info *c); 37162306a36Sopenharmony_cistruct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset); 37262306a36Sopenharmony_civoid jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c_delete); 37362306a36Sopenharmony_ciint jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn); 37462306a36Sopenharmony_ciuint32_t jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size); 37562306a36Sopenharmony_cistruct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c, 37662306a36Sopenharmony_ci struct jffs2_eraseblock *jeb, 37762306a36Sopenharmony_ci uint32_t ofs, uint32_t len, 37862306a36Sopenharmony_ci struct jffs2_inode_cache *ic); 37962306a36Sopenharmony_ciextern uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, 38062306a36Sopenharmony_ci struct jffs2_eraseblock *jeb, 38162306a36Sopenharmony_ci struct jffs2_raw_node_ref *ref); 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci/* nodemgmt.c */ 38462306a36Sopenharmony_ciint jffs2_thread_should_wake(struct jffs2_sb_info *c); 38562306a36Sopenharmony_ciint jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, 38662306a36Sopenharmony_ci uint32_t *len, int prio, uint32_t sumsize); 38762306a36Sopenharmony_ciint jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, 38862306a36Sopenharmony_ci uint32_t *len, uint32_t sumsize); 38962306a36Sopenharmony_cistruct jffs2_raw_node_ref *jffs2_add_physical_node_ref(struct jffs2_sb_info *c, 39062306a36Sopenharmony_ci uint32_t ofs, uint32_t len, 39162306a36Sopenharmony_ci struct jffs2_inode_cache *ic); 39262306a36Sopenharmony_civoid jffs2_complete_reservation(struct jffs2_sb_info *c); 39362306a36Sopenharmony_civoid jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw); 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci/* write.c */ 39662306a36Sopenharmony_ciint jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri); 39762306a36Sopenharmony_ci 39862306a36Sopenharmony_cistruct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 39962306a36Sopenharmony_ci struct jffs2_raw_inode *ri, const unsigned char *data, 40062306a36Sopenharmony_ci uint32_t datalen, int alloc_mode); 40162306a36Sopenharmony_cistruct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 40262306a36Sopenharmony_ci struct jffs2_raw_dirent *rd, const unsigned char *name, 40362306a36Sopenharmony_ci uint32_t namelen, int alloc_mode); 40462306a36Sopenharmony_ciint jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 40562306a36Sopenharmony_ci struct jffs2_raw_inode *ri, unsigned char *buf, 40662306a36Sopenharmony_ci uint32_t offset, uint32_t writelen, uint32_t *retlen); 40762306a36Sopenharmony_ciint jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, 40862306a36Sopenharmony_ci struct jffs2_raw_inode *ri, const struct qstr *qstr); 40962306a36Sopenharmony_ciint jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, 41062306a36Sopenharmony_ci int namelen, struct jffs2_inode_info *dead_f, uint32_t time); 41162306a36Sopenharmony_ciint jffs2_do_link(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, 41262306a36Sopenharmony_ci uint8_t type, const char *name, int namelen, uint32_t time); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ci/* readinode.c */ 41662306a36Sopenharmony_ciint jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 41762306a36Sopenharmony_ci uint32_t ino, struct jffs2_raw_inode *latest_node); 41862306a36Sopenharmony_ciint jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic); 41962306a36Sopenharmony_civoid jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f); 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci/* malloc.c */ 42262306a36Sopenharmony_ciint jffs2_create_slab_caches(void); 42362306a36Sopenharmony_civoid jffs2_destroy_slab_caches(void); 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_cistruct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize); 42662306a36Sopenharmony_civoid jffs2_free_full_dirent(struct jffs2_full_dirent *); 42762306a36Sopenharmony_cistruct jffs2_full_dnode *jffs2_alloc_full_dnode(void); 42862306a36Sopenharmony_civoid jffs2_free_full_dnode(struct jffs2_full_dnode *); 42962306a36Sopenharmony_cistruct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void); 43062306a36Sopenharmony_civoid jffs2_free_raw_dirent(struct jffs2_raw_dirent *); 43162306a36Sopenharmony_cistruct jffs2_raw_inode *jffs2_alloc_raw_inode(void); 43262306a36Sopenharmony_civoid jffs2_free_raw_inode(struct jffs2_raw_inode *); 43362306a36Sopenharmony_cistruct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void); 43462306a36Sopenharmony_civoid jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *); 43562306a36Sopenharmony_ciint jffs2_prealloc_raw_node_refs(struct jffs2_sb_info *c, 43662306a36Sopenharmony_ci struct jffs2_eraseblock *jeb, int nr); 43762306a36Sopenharmony_civoid jffs2_free_refblock(struct jffs2_raw_node_ref *); 43862306a36Sopenharmony_cistruct jffs2_node_frag *jffs2_alloc_node_frag(void); 43962306a36Sopenharmony_civoid jffs2_free_node_frag(struct jffs2_node_frag *); 44062306a36Sopenharmony_cistruct jffs2_inode_cache *jffs2_alloc_inode_cache(void); 44162306a36Sopenharmony_civoid jffs2_free_inode_cache(struct jffs2_inode_cache *); 44262306a36Sopenharmony_ci#ifdef CONFIG_JFFS2_FS_XATTR 44362306a36Sopenharmony_cistruct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void); 44462306a36Sopenharmony_civoid jffs2_free_xattr_datum(struct jffs2_xattr_datum *); 44562306a36Sopenharmony_cistruct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void); 44662306a36Sopenharmony_civoid jffs2_free_xattr_ref(struct jffs2_xattr_ref *); 44762306a36Sopenharmony_ci#endif 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci/* gc.c */ 45062306a36Sopenharmony_ciint jffs2_garbage_collect_pass(struct jffs2_sb_info *c); 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ci/* read.c */ 45362306a36Sopenharmony_ciint jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 45462306a36Sopenharmony_ci struct jffs2_full_dnode *fd, unsigned char *buf, 45562306a36Sopenharmony_ci int ofs, int len); 45662306a36Sopenharmony_ciint jffs2_read_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 45762306a36Sopenharmony_ci unsigned char *buf, uint32_t offset, uint32_t len); 45862306a36Sopenharmony_cichar *jffs2_getlink(struct jffs2_sb_info *c, struct jffs2_inode_info *f); 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_ci/* scan.c */ 46162306a36Sopenharmony_ciint jffs2_scan_medium(struct jffs2_sb_info *c); 46262306a36Sopenharmony_civoid jffs2_rotate_lists(struct jffs2_sb_info *c); 46362306a36Sopenharmony_cistruct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uint32_t ino); 46462306a36Sopenharmony_ciint jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 46562306a36Sopenharmony_ciint jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t size); 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ci/* build.c */ 46862306a36Sopenharmony_ciint jffs2_do_mount_fs(struct jffs2_sb_info *c); 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci/* erase.c */ 47162306a36Sopenharmony_ciint jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count); 47262306a36Sopenharmony_civoid jffs2_free_jeb_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci#ifdef CONFIG_JFFS2_FS_WRITEBUFFER 47562306a36Sopenharmony_ci/* wbuf.c */ 47662306a36Sopenharmony_ciint jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino); 47762306a36Sopenharmony_ciint jffs2_flush_wbuf_pad(struct jffs2_sb_info *c); 47862306a36Sopenharmony_ciint jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 47962306a36Sopenharmony_ciint jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb); 48062306a36Sopenharmony_ci#endif 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_ci#include "debug.h" 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ci#endif /* __JFFS2_NODELIST_H__ */ 485