]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/cramfs.h
Merge branch 'meson-more-build-options' of https://github.com/jwillikers/util-linux
[thirdparty/util-linux.git] / disk-utils / cramfs.h
CommitLineData
06f25585 1/*
9e95aa12
KZ
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
06f25585
DB
4 * cramfs_common - cramfs common code
5 *
6 * Copyright (c) 2008 Roy Peled, the.roy.peled -at- gmail
cd42d02f 7 * Copyright (c) 2004-2006 by Juliane Holzt, kju -at- fqdn.org
06f25585
DB
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
06f25585 18 */
63cccae4
KZ
19#ifndef __CRAMFS_H
20#define __CRAMFS_H
21
d51f37a3 22#include <stdint.h>
63cccae4
KZ
23
24#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
25#define CRAMFS_SIGNATURE "Compressed ROMFS"
26
27/*
28 * Width of various bitfields in struct cramfs_inode.
29 * Primarily used to generate warnings in mkcramfs.
30 */
31#define CRAMFS_MODE_WIDTH 16
32#define CRAMFS_UID_WIDTH 16
33#define CRAMFS_SIZE_WIDTH 24
34#define CRAMFS_GID_WIDTH 8
35#define CRAMFS_NAMELEN_WIDTH 6
36#define CRAMFS_OFFSET_WIDTH 26
37
06f25585 38#ifndef HOST_IS_BIG_ENDIAN
83b418c1 39#define HOST_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
06f25585 40#endif
63cccae4
KZ
41
42/*
43 * Reasonably terse representation of the inode data.
44 */
45struct cramfs_inode {
d51f37a3 46 uint32_t mode:16, uid:16;
63cccae4 47 /* SIZE for device files is i_rdev */
d51f37a3 48 uint32_t size:24, gid:8;
22eef91a
SK
49 /*
50 * NAMELEN is the length of the file name, divided by 4 and
51 * rounded up. (cramfs doesn't support hard links.)
52 *
53 * OFFSET: For symlinks and non-empty regular files, this
54 * contains the offset (divided by 4) of the file data in
55 * compressed form (starting with an array of block pointers;
56 * see README). For non-empty directories it is the offset
57 * (divided by 4) of the inode of the first file in that
58 * directory. For anything else, offset is zero.
59 */
d51f37a3 60 uint32_t namelen:6, offset:26;
63cccae4
KZ
61};
62
63struct cramfs_info {
22eef91a
SK
64 uint32_t crc;
65 uint32_t edition;
66 uint32_t blocks;
67 uint32_t files;
63cccae4
KZ
68};
69
70/*
71 * Superblock information at the beginning of the FS.
72 */
73struct cramfs_super {
d51f37a3
SK
74 uint32_t magic; /* 0x28cd3d45 - random number */
75 uint32_t size; /* Not used. mkcramfs currently
22eef91a 76 writes a constant 1<<16 here. */
d51f37a3
SK
77 uint32_t flags; /* 0 */
78 uint32_t future; /* 0 */
79 uint8_t signature[16]; /* "Compressed ROMFS" */
63cccae4 80 struct cramfs_info fsid;/* unique filesystem info */
d51f37a3 81 uint8_t name[16]; /* user-defined name */
63cccae4
KZ
82 struct cramfs_inode root; /* Root inode data */
83};
84
22eef91a
SK
85#define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
86#define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
87#define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
88#define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
89#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
63cccae4
KZ
90
91/*
92 * Valid values in super.flags. Currently we refuse to mount
93 * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be
94 * changed to test super.future instead.
95 */
96#define CRAMFS_SUPPORTED_FLAGS (0xff)
97
98/* Uncompression interfaces to the underlying zlib */
99int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
100int cramfs_uncompress_init(void);
101int cramfs_uncompress_exit(void);
102
d51f37a3 103uint32_t u32_toggle_endianness(int big_endian, uint32_t what);
06f25585 104void super_toggle_endianness(int from_big_endian, struct cramfs_super *super);
22eef91a
SK
105void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in,
106 struct cramfs_inode *inode_out);
107void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in,
108 struct cramfs_inode *inode_out);
06f25585 109
63cccae4 110#endif