cramfs_fs.h 4.3 KB

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