jffs2_nand_private.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef jffs2_private_h
  2. #define jffs2_private_h
  3. #include <jffs2/jffs2.h>
  4. struct b_node {
  5. struct b_node *next;
  6. };
  7. struct b_inode {
  8. struct b_inode *next;
  9. u32 offset; /* physical offset to beginning of real inode */
  10. u32 version;
  11. u32 ino;
  12. u32 isize;
  13. u32 csize;
  14. };
  15. struct b_dirent {
  16. struct b_dirent *next;
  17. u32 offset; /* physical offset to beginning of real dirent */
  18. u32 version;
  19. u32 pino;
  20. u32 ino;
  21. unsigned int nhash;
  22. unsigned char nsize;
  23. unsigned char type;
  24. };
  25. struct b_list {
  26. struct b_node *listTail;
  27. struct b_node *listHead;
  28. unsigned int listCount;
  29. struct mem_block *listMemBase;
  30. };
  31. struct b_lists {
  32. char *partOffset;
  33. struct b_list dir;
  34. struct b_list frag;
  35. };
  36. struct b_compr_info {
  37. u32 num_frags;
  38. u32 compr_sum;
  39. u32 decompr_sum;
  40. };
  41. struct b_jffs2_info {
  42. struct b_compr_info compr_info[JFFS2_NUM_COMPR];
  43. };
  44. static inline int
  45. hdr_crc(struct jffs2_unknown_node *node)
  46. {
  47. #if 1
  48. u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
  49. #else
  50. /* what's the semantics of this? why is this here? */
  51. u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
  52. crc ^= ~0;
  53. #endif
  54. if (node->hdr_crc != crc) {
  55. return 0;
  56. } else {
  57. return 1;
  58. }
  59. }
  60. static inline int
  61. dirent_crc(struct jffs2_raw_dirent *node)
  62. {
  63. if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_dirent) - 8)) {
  64. return 0;
  65. } else {
  66. return 1;
  67. }
  68. }
  69. static inline int
  70. dirent_name_crc(struct jffs2_raw_dirent *node)
  71. {
  72. if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) {
  73. return 0;
  74. } else {
  75. return 1;
  76. }
  77. }
  78. static inline int
  79. inode_crc(struct jffs2_raw_inode *node)
  80. {
  81. if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_inode) - 8)) {
  82. return 0;
  83. } else {
  84. return 1;
  85. }
  86. }
  87. /* Borrowed from include/linux/dcache.h */
  88. /* Name hashing routines. Initial hash value */
  89. /* Hash courtesy of the R5 hash in reiserfs modulo sign bits */
  90. #define init_name_hash() 0
  91. /* partial hash update function. Assume roughly 4 bits per character */
  92. static inline unsigned long
  93. partial_name_hash(unsigned long c, unsigned long prevhash)
  94. {
  95. return (prevhash + (c << 4) + (c >> 4)) * 11;
  96. }
  97. /*
  98. * Finally: cut down the number of bits to a int value (and try to avoid
  99. * losing bits)
  100. */
  101. static inline unsigned long end_name_hash(unsigned long hash)
  102. {
  103. return (unsigned int) hash;
  104. }
  105. /* Compute the hash for a name string. */
  106. static inline unsigned int
  107. full_name_hash(const unsigned char *name, unsigned int len)
  108. {
  109. unsigned long hash = init_name_hash();
  110. while (len--)
  111. hash = partial_name_hash(*name++, hash);
  112. return end_name_hash(hash);
  113. }
  114. #endif /* jffs2_private.h */