cramfs_fs.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef __CRAMFS_H
  2. #define __CRAMFS_H
  3. #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
  4. #define CRAMFS_SIGNATURE "Compressed ROMFS"
  5. /*
  6. * Width of various bitfields in struct cramfs_inode.
  7. * Primarily used to generate warnings in mkcramfs.
  8. */
  9. #define CRAMFS_MODE_WIDTH 16
  10. #define CRAMFS_UID_WIDTH 16
  11. #define CRAMFS_SIZE_WIDTH 24
  12. #define CRAMFS_GID_WIDTH 8
  13. #define CRAMFS_NAMELEN_WIDTH 6
  14. #define CRAMFS_OFFSET_WIDTH 26
  15. /*
  16. * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
  17. * path length is 63 << 2 = 252.
  18. */
  19. #define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
  20. /*
  21. * Reasonably terse representation of the inode data.
  22. */
  23. struct cramfs_inode {
  24. u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
  25. /* SIZE for device files is i_rdev */
  26. u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
  27. /* NAMELEN is the length of the file name, divided by 4 and
  28. rounded up. (cramfs doesn't support hard links.) */
  29. /* OFFSET: For symlinks and non-empty regular files, this
  30. contains the offset (divided by 4) of the file data in
  31. compressed form (starting with an array of block pointers;
  32. see README). For non-empty directories it is the offset
  33. (divided by 4) of the inode of the first file in that
  34. directory. For anything else, offset is zero. */
  35. u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
  36. };
  37. struct cramfs_info {
  38. u32 crc;
  39. u32 edition;
  40. u32 blocks;
  41. u32 files;
  42. };
  43. /*
  44. * Superblock information at the beginning of the FS.
  45. */
  46. struct cramfs_super {
  47. u32 magic; /* 0x28cd3d45 - random number */
  48. u32 size; /* length in bytes */
  49. u32 flags; /* feature flags */
  50. u32 future; /* reserved for future use */
  51. u8 signature[16]; /* "Compressed ROMFS" */
  52. struct cramfs_info fsid; /* unique filesystem info */
  53. u8 name[16]; /* user-defined name */
  54. struct cramfs_inode root; /* root inode data */
  55. };
  56. /*
  57. * Feature flags
  58. *
  59. * 0x00000000 - 0x000000ff: features that work for all past kernels
  60. * 0x00000100 - 0xffffffff: features that don't work for past kernels
  61. */
  62. #define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
  63. #define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
  64. #define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
  65. #define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
  66. #define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
  67. /*
  68. * Valid values in super.flags. Currently we refuse to mount
  69. * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be
  70. * changed to test super.future instead.
  71. */
  72. #define CRAMFS_SUPPORTED_FLAGS ( 0x000000ff \
  73. | CRAMFS_FLAG_HOLES \
  74. | CRAMFS_FLAG_WRONG_SIGNATURE \
  75. | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
  76. /*
  77. * Since cramfs is little-endian, provide macros to swab the bitfields.
  78. */
  79. #ifndef __BYTE_ORDER
  80. #if defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
  81. #define __BYTE_ORDER __LITTLE_ENDIAN
  82. #elif defined(__BIG_ENDIAN) && !defined(__LITTLE_ENDIAN)
  83. #define __BYTE_ORDER __BIG_ENDIAN
  84. #else
  85. #error "unable to define __BYTE_ORDER"
  86. #endif
  87. #endif /* not __BYTE_ORDER */
  88. #if __BYTE_ORDER == __LITTLE_ENDIAN
  89. #define CRAMFS_16(x) (x)
  90. #define CRAMFS_24(x) (x)
  91. #define CRAMFS_32(x) (x)
  92. #define CRAMFS_GET_NAMELEN(x) ((x)->namelen)
  93. #define CRAMFS_GET_OFFSET(x) ((x)->offset)
  94. #define CRAMFS_SET_OFFSET(x,y) ((x)->offset = (y))
  95. #define CRAMFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
  96. #elif __BYTE_ORDER == __BIG_ENDIAN
  97. #ifdef __KERNEL__
  98. #define CRAMFS_16(x) swab16(x)
  99. #define CRAMFS_24(x) ((swab32(x)) >> 8)
  100. #define CRAMFS_32(x) swab32(x)
  101. #else /* not __KERNEL__ */
  102. #define CRAMFS_16(x) bswap_16(x)
  103. #define CRAMFS_24(x) ((bswap_32(x)) >> 8)
  104. #define CRAMFS_32(x) bswap_32(x)
  105. #endif /* not __KERNEL__ */
  106. #define CRAMFS_GET_NAMELEN(x) (((u8*)(x))[8] & 0x3f)
  107. #define CRAMFS_GET_OFFSET(x) ((CRAMFS_24(((u32*)(x))[2] & 0xffffff) << 2) |\
  108. ((((u32*)(x))[2] & 0xc0000000) >> 30))
  109. #define CRAMFS_SET_NAMELEN(x,y) (((u8*)(x))[8] = (((0x3f & (y))) | \
  110. (0xc0 & ((u8*)(x))[8])))
  111. #define CRAMFS_SET_OFFSET(x,y) (((u32*)(x))[2] = (((y) & 3) << 30) | \
  112. CRAMFS_24((((y) & 0x03ffffff) >> 2)) | \
  113. (((u32)(((u8*)(x))[8] & 0x3f)) << 24))
  114. #else
  115. #error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN"
  116. #endif
  117. /* Uncompression interfaces to the underlying zlib */
  118. int cramfs_uncompress_block(void *dst, void *src, int srclen);
  119. int cramfs_uncompress_init(void);
  120. int cramfs_uncompress_exit(void);
  121. #endif /* __CRAMFS_H */