xref: /linux/include/uapi/linux/cramfs_fs.h (revision 664b0bae0b87f69bc9deb098f5e0158b9cf18e04)
1*6f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _UAPI__CRAMFS_H
3607ca46eSDavid Howells #define _UAPI__CRAMFS_H
4607ca46eSDavid Howells 
5607ca46eSDavid Howells #include <linux/types.h>
6607ca46eSDavid Howells #include <linux/magic.h>
7607ca46eSDavid Howells 
8607ca46eSDavid Howells #define CRAMFS_SIGNATURE	"Compressed ROMFS"
9607ca46eSDavid Howells 
10607ca46eSDavid Howells /*
11607ca46eSDavid Howells  * Width of various bitfields in struct cramfs_inode.
12607ca46eSDavid Howells  * Primarily used to generate warnings in mkcramfs.
13607ca46eSDavid Howells  */
14607ca46eSDavid Howells #define CRAMFS_MODE_WIDTH 16
15607ca46eSDavid Howells #define CRAMFS_UID_WIDTH 16
16607ca46eSDavid Howells #define CRAMFS_SIZE_WIDTH 24
17607ca46eSDavid Howells #define CRAMFS_GID_WIDTH 8
18607ca46eSDavid Howells #define CRAMFS_NAMELEN_WIDTH 6
19607ca46eSDavid Howells #define CRAMFS_OFFSET_WIDTH 26
20607ca46eSDavid Howells 
21607ca46eSDavid Howells /*
22607ca46eSDavid Howells  * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
23607ca46eSDavid Howells  * path length is 63 << 2 = 252.
24607ca46eSDavid Howells  */
25607ca46eSDavid Howells #define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
26607ca46eSDavid Howells 
27607ca46eSDavid Howells /*
28607ca46eSDavid Howells  * Reasonably terse representation of the inode data.
29607ca46eSDavid Howells  */
30607ca46eSDavid Howells struct cramfs_inode {
31607ca46eSDavid Howells 	__u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
32607ca46eSDavid Howells 	/* SIZE for device files is i_rdev */
33607ca46eSDavid Howells 	__u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
34607ca46eSDavid Howells 	/* NAMELEN is the length of the file name, divided by 4 and
35607ca46eSDavid Howells            rounded up.  (cramfs doesn't support hard links.) */
36607ca46eSDavid Howells 	/* OFFSET: For symlinks and non-empty regular files, this
37607ca46eSDavid Howells 	   contains the offset (divided by 4) of the file data in
38607ca46eSDavid Howells 	   compressed form (starting with an array of block pointers;
39607ca46eSDavid Howells 	   see README).  For non-empty directories it is the offset
40607ca46eSDavid Howells 	   (divided by 4) of the inode of the first file in that
41607ca46eSDavid Howells 	   directory.  For anything else, offset is zero. */
42607ca46eSDavid Howells 	__u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
43607ca46eSDavid Howells };
44607ca46eSDavid Howells 
45607ca46eSDavid Howells struct cramfs_info {
46607ca46eSDavid Howells 	__u32 crc;
47607ca46eSDavid Howells 	__u32 edition;
48607ca46eSDavid Howells 	__u32 blocks;
49607ca46eSDavid Howells 	__u32 files;
50607ca46eSDavid Howells };
51607ca46eSDavid Howells 
52607ca46eSDavid Howells /*
53607ca46eSDavid Howells  * Superblock information at the beginning of the FS.
54607ca46eSDavid Howells  */
55607ca46eSDavid Howells struct cramfs_super {
56607ca46eSDavid Howells 	__u32 magic;			/* 0x28cd3d45 - random number */
57607ca46eSDavid Howells 	__u32 size;			/* length in bytes */
58607ca46eSDavid Howells 	__u32 flags;			/* feature flags */
59607ca46eSDavid Howells 	__u32 future;			/* reserved for future use */
60607ca46eSDavid Howells 	__u8 signature[16];		/* "Compressed ROMFS" */
61607ca46eSDavid Howells 	struct cramfs_info fsid;	/* unique filesystem info */
62607ca46eSDavid Howells 	__u8 name[16];			/* user-defined name */
63607ca46eSDavid Howells 	struct cramfs_inode root;	/* root inode data */
64607ca46eSDavid Howells };
65607ca46eSDavid Howells 
66607ca46eSDavid Howells /*
67607ca46eSDavid Howells  * Feature flags
68607ca46eSDavid Howells  *
69607ca46eSDavid Howells  * 0x00000000 - 0x000000ff: features that work for all past kernels
70607ca46eSDavid Howells  * 0x00000100 - 0xffffffff: features that don't work for past kernels
71607ca46eSDavid Howells  */
72607ca46eSDavid Howells #define CRAMFS_FLAG_FSID_VERSION_2	0x00000001	/* fsid version #2 */
73607ca46eSDavid Howells #define CRAMFS_FLAG_SORTED_DIRS		0x00000002	/* sorted dirs */
74607ca46eSDavid Howells #define CRAMFS_FLAG_HOLES		0x00000100	/* support for holes */
75607ca46eSDavid Howells #define CRAMFS_FLAG_WRONG_SIGNATURE	0x00000200	/* reserved */
76607ca46eSDavid Howells #define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET	0x00000400	/* shifted root fs */
77fd4f6f2aSNicolas Pitre #define CRAMFS_FLAG_EXT_BLOCK_POINTERS	0x00000800	/* block pointer extensions */
78607ca46eSDavid Howells 
79607ca46eSDavid Howells /*
80607ca46eSDavid Howells  * Valid values in super.flags.  Currently we refuse to mount
81607ca46eSDavid Howells  * if (flags & ~CRAMFS_SUPPORTED_FLAGS).  Maybe that should be
82607ca46eSDavid Howells  * changed to test super.future instead.
83607ca46eSDavid Howells  */
84607ca46eSDavid Howells #define CRAMFS_SUPPORTED_FLAGS	( 0x000000ff \
85607ca46eSDavid Howells 				| CRAMFS_FLAG_HOLES \
86607ca46eSDavid Howells 				| CRAMFS_FLAG_WRONG_SIGNATURE \
87fd4f6f2aSNicolas Pitre 				| CRAMFS_FLAG_SHIFTED_ROOT_OFFSET \
88fd4f6f2aSNicolas Pitre 				| CRAMFS_FLAG_EXT_BLOCK_POINTERS )
89607ca46eSDavid Howells 
90fd4f6f2aSNicolas Pitre /*
91fd4f6f2aSNicolas Pitre  * Block pointer flags
92fd4f6f2aSNicolas Pitre  *
93fd4f6f2aSNicolas Pitre  * The maximum block offset that needs to be represented is roughly:
94fd4f6f2aSNicolas Pitre  *
95fd4f6f2aSNicolas Pitre  *   (1 << CRAMFS_OFFSET_WIDTH) * 4 +
96fd4f6f2aSNicolas Pitre  *   (1 << CRAMFS_SIZE_WIDTH) / PAGE_SIZE * (4 + PAGE_SIZE)
97fd4f6f2aSNicolas Pitre  *   = 0x11004000
98fd4f6f2aSNicolas Pitre  *
99fd4f6f2aSNicolas Pitre  * That leaves room for 3 flag bits in the block pointer table.
100fd4f6f2aSNicolas Pitre  */
101fd4f6f2aSNicolas Pitre #define CRAMFS_BLK_FLAG_UNCOMPRESSED	(1 << 31)
102fd4f6f2aSNicolas Pitre #define CRAMFS_BLK_FLAG_DIRECT_PTR	(1 << 30)
103fd4f6f2aSNicolas Pitre 
104fd4f6f2aSNicolas Pitre #define CRAMFS_BLK_FLAGS	( CRAMFS_BLK_FLAG_UNCOMPRESSED \
105fd4f6f2aSNicolas Pitre 				| CRAMFS_BLK_FLAG_DIRECT_PTR )
106fd4f6f2aSNicolas Pitre 
107fd4f6f2aSNicolas Pitre /*
108fd4f6f2aSNicolas Pitre  * Direct blocks are at least 4-byte aligned.
109fd4f6f2aSNicolas Pitre  * Pointers to direct blocks are shifted down by 2 bits.
110fd4f6f2aSNicolas Pitre  */
111fd4f6f2aSNicolas Pitre #define CRAMFS_BLK_DIRECT_PTR_SHIFT	2
112607ca46eSDavid Howells 
113607ca46eSDavid Howells #endif /* _UAPI__CRAMFS_H */
114