cramfs_fs.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #if __BYTE_ORDER == __LITTLE_ENDIAN
  77. #define CRAMFS_16(x) (x)
  78. #define CRAMFS_24(x) (x)
  79. #define CRAMFS_32(x) (x)
  80. #define CRAMFS_GET_NAMELEN(x) ((x)->namelen)
  81. #define CRAMFS_GET_OFFSET(x) ((x)->offset)
  82. #define CRAMFS_SET_OFFSET(x,y) ((x)->offset = (y))
  83. #define CRAMFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
  84. #elif __BYTE_ORDER == __BIG_ENDIAN
  85. #ifdef __KERNEL__
  86. #define CRAMFS_16(x) swab16(x)
  87. #define CRAMFS_24(x) ((swab32(x)) >> 8)
  88. #define CRAMFS_32(x) swab32(x)
  89. #else /* not __KERNEL__ */
  90. #define CRAMFS_16(x) bswap_16(x)
  91. #define CRAMFS_24(x) ((bswap_32(x)) >> 8)
  92. #define CRAMFS_32(x) bswap_32(x)
  93. #endif /* not __KERNEL__ */
  94. #define CRAMFS_GET_NAMELEN(x) (((u8*)(x))[8] & 0x3f)
  95. #define CRAMFS_GET_OFFSET(x) ((CRAMFS_24(((u32*)(x))[2] & 0xffffff) << 2) |\
  96. ((((u32*)(x))[2] & 0xc0000000) >> 30))
  97. #define CRAMFS_SET_NAMELEN(x,y) (((u8*)(x))[8] = (((0x3f & (y))) | \
  98. (0xc0 & ((u8*)(x))[8])))
  99. #define CRAMFS_SET_OFFSET(x,y) (((u32*)(x))[2] = (((y) & 3) << 30) | \
  100. CRAMFS_24((((y) & 0x03ffffff) >> 2)) | \
  101. (((u32)(((u8*)(x))[8] & 0x3f)) << 24))
  102. #else
  103. #error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN"
  104. #endif
  105. /* Uncompression interfaces to the underlying zlib */
  106. int cramfs_uncompress_block(void *dst, void *src, int srclen);
  107. int cramfs_uncompress_init(void);
  108. int cramfs_uncompress_exit(void);
  109. #endif /* __CRAMFS_H */