cramfs_fs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI__CRAMFS_H
  3. #define _UAPI__CRAMFS_H
  4. #include <linux/types.h>
  5. #include <linux/magic.h>
  6. #define CRAMFS_SIGNATURE "Compressed ROMFS"
  7. /*
  8. * Width of various bitfields in struct cramfs_inode.
  9. * Primarily used to generate warnings in mkcramfs.
  10. */
  11. #define CRAMFS_MODE_WIDTH 16
  12. #define CRAMFS_UID_WIDTH 16
  13. #define CRAMFS_SIZE_WIDTH 24
  14. #define CRAMFS_GID_WIDTH 8
  15. #define CRAMFS_NAMELEN_WIDTH 6
  16. #define CRAMFS_OFFSET_WIDTH 26
  17. /*
  18. * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
  19. * path length is 63 << 2 = 252.
  20. */
  21. #define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
  22. /*
  23. * Reasonably terse representation of the inode data.
  24. */
  25. struct cramfs_inode {
  26. __u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
  27. /* SIZE for device files is i_rdev */
  28. __u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
  29. /* NAMELEN is the length of the file name, divided by 4 and
  30. rounded up. (cramfs doesn't support hard links.) */
  31. /* OFFSET: For symlinks and non-empty regular files, this
  32. contains the offset (divided by 4) of the file data in
  33. compressed form (starting with an array of block pointers;
  34. see README). For non-empty directories it is the offset
  35. (divided by 4) of the inode of the first file in that
  36. directory. For anything else, offset is zero. */
  37. __u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
  38. };
  39. struct cramfs_info {
  40. __u32 crc;
  41. __u32 edition;
  42. __u32 blocks;
  43. __u32 files;
  44. };
  45. /*
  46. * Superblock information at the beginning of the FS.
  47. */
  48. struct cramfs_super {
  49. __u32 magic; /* 0x28cd3d45 - random number */
  50. __u32 size; /* length in bytes */
  51. __u32 flags; /* feature flags */
  52. __u32 future; /* reserved for future use */
  53. __u8 signature[16]; /* "Compressed ROMFS" */
  54. struct cramfs_info fsid; /* unique filesystem info */
  55. __u8 name[16]; /* user-defined name */
  56. struct cramfs_inode root; /* root inode data */
  57. };
  58. /*
  59. * Feature flags
  60. *
  61. * 0x00000000 - 0x000000ff: features that work for all past kernels
  62. * 0x00000100 - 0xffffffff: features that don't work for past kernels
  63. */
  64. #define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
  65. #define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
  66. #define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
  67. #define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
  68. #define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
  69. #define CRAMFS_FLAG_EXT_BLOCK_POINTERS 0x00000800 /* block pointer extensions */
  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. | CRAMFS_FLAG_EXT_BLOCK_POINTERS )
  80. /*
  81. * Block pointer flags
  82. *
  83. * The maximum block offset that needs to be represented is roughly:
  84. *
  85. * (1 << CRAMFS_OFFSET_WIDTH) * 4 +
  86. * (1 << CRAMFS_SIZE_WIDTH) / PAGE_SIZE * (4 + PAGE_SIZE)
  87. * = 0x11004000
  88. *
  89. * That leaves room for 3 flag bits in the block pointer table.
  90. */
  91. #define CRAMFS_BLK_FLAG_UNCOMPRESSED (1 << 31)
  92. #define CRAMFS_BLK_FLAG_DIRECT_PTR (1 << 30)
  93. #define CRAMFS_BLK_FLAGS ( CRAMFS_BLK_FLAG_UNCOMPRESSED \
  94. | CRAMFS_BLK_FLAG_DIRECT_PTR )
  95. /*
  96. * Direct blocks are at least 4-byte aligned.
  97. * Pointers to direct blocks are shifted down by 2 bits.
  98. */
  99. #define CRAMFS_BLK_DIRECT_PTR_SHIFT 2
  100. #endif /* _UAPI__CRAMFS_H */