1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020 Bootlin
5 * Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
8 #ifndef SQFS_FILESYSTEM_H
9 #define SQFS_FILESYSTEM_H
11 #include <asm/unaligned.h>
15 #define SQFS_UNCOMPRESSED_DATA 0x0002
16 #define SQFS_MAGIC_NUMBER 0x73717368
17 /* The three first members of squashfs_dir_index make a total of 12 bytes */
18 #define SQFS_DIR_INDEX_BASE_LENGTH 12
19 /* size of metadata (inode and directory) blocks */
20 #define SQFS_METADATA_BLOCK_SIZE 8192
21 /* Max. number of fragment entries in a metadata block is 512 */
22 #define SQFS_MAX_ENTRIES 512
23 /* Metadata blocks start by a 2-byte length header */
24 #define SQFS_HEADER_SIZE 2
25 #define SQFS_LREG_INODE_MIN_SIZE 56
26 #define SQFS_DIR_HEADER_SIZE 12
27 #define SQFS_MISC_ENTRY_TYPE -1
28 #define SQFS_EMPTY_FILE_SIZE 3
29 #define SQFS_STOP_READDIR 1
30 #define SQFS_EMPTY_DIR -1
32 * A directory entry object has a fixed length of 8 bytes, corresponding to its
33 * first four members, plus the size of the entry name, which is equal to
34 * 'entry_name' + 1 bytes.
36 #define SQFS_ENTRY_BASE_LENGTH 8
38 #define SQFS_DIR_TYPE 1
39 #define SQFS_REG_TYPE 2
40 #define SQFS_SYMLINK_TYPE 3
41 #define SQFS_BLKDEV_TYPE 4
42 #define SQFS_CHRDEV_TYPE 5
43 #define SQFS_FIFO_TYPE 6
44 #define SQFS_SOCKET_TYPE 7
45 #define SQFS_LDIR_TYPE 8
46 #define SQFS_LREG_TYPE 9
47 #define SQFS_LSYMLINK_TYPE 10
48 #define SQFS_LBLKDEV_TYPE 11
49 #define SQFS_LCHRDEV_TYPE 12
50 #define SQFS_LFIFO_TYPE 13
51 #define SQFS_LSOCKET_TYPE 14
53 struct squashfs_super_block {
67 __le64 id_table_start;
68 __le64 xattr_id_table_start;
69 __le64 inode_table_start;
70 __le64 directory_table_start;
71 __le64 fragment_table_start;
72 __le64 export_table_start;
75 struct squashfs_directory_index {
82 struct squashfs_base_inode {
91 struct squashfs_ipc_inode {
101 struct squashfs_lipc_inode {
112 struct squashfs_dev_inode {
123 struct squashfs_ldev_inode {
135 struct squashfs_symlink_inode {
147 struct squashfs_reg_inode {
158 __le32 block_list[0];
161 struct squashfs_lreg_inode {
175 __le32 block_list[0];
178 struct squashfs_dir_inode {
192 struct squashfs_ldir_inode {
206 struct squashfs_directory_index index[0];
209 union squashfs_inode {
210 struct squashfs_base_inode *base;
211 struct squashfs_dev_inode *dev;
212 struct squashfs_ldev_inode *ldev;
213 struct squashfs_symlink_inode *symlink;
214 struct squashfs_reg_inode *reg;
215 struct squashfs_lreg_inode *lreg;
216 struct squashfs_dir_inode *dir;
217 struct squashfs_ldir_inode *ldir;
218 struct squashfs_ipc_inode *ipc;
219 struct squashfs_lipc_inode *lipc;
222 struct squashfs_directory_entry {
230 struct squashfs_directory_header {
236 struct squashfs_fragment_block_entry {
242 struct squashfs_dir_stream {
243 struct fs_dir_stream fs_dirs;
244 struct fs_dirent dentp;
246 * 'size' is the uncompressed size of the entire listing, including
247 * headers. 'entry_count' is the number of entries following a
248 * specific header. Both variables are decremented in sqfs_readdir() so
249 * the function knows when the end of the directory is reached.
253 /* SquashFS structures */
254 struct squashfs_directory_header *dir_header;
255 struct squashfs_directory_entry *entry;
257 * 'table' points to a position into the directory table. Both 'table'
258 * and 'inode' are defined for the first time in sqfs_opendir().
259 * 'table's value changes in sqfs_readdir().
261 unsigned char *table;
262 union squashfs_inode i;
263 struct squashfs_dir_inode i_dir;
264 struct squashfs_ldir_inode i_ldir;
266 * References to the tables' beginnings. They are assigned in
267 * sqfs_opendir() and freed in sqfs_closedir().
269 unsigned char *inode_table;
270 unsigned char *dir_table;
273 struct squashfs_file_info {
274 /* File size in bytes (uncompressed) */
276 /* Reference to list of data blocks's sizes */
278 /* Offset into the fragment block */
280 /* Offset in which the data blocks begin */
282 /* Is file fragmented? */
284 /* Compressed fragment */
288 void *sqfs_find_inode(void *inode_table, int inode_number, __le32 inode_count,
291 int sqfs_dir_offset(void *dir_i, u32 *m_list, int m_count);
293 int sqfs_read_metablock(unsigned char *file_mapping, int offset,
294 bool *compressed, u32 *data_size);
296 bool sqfs_is_empty_dir(void *dir_i);
298 bool sqfs_is_dir(u16 type);
300 #endif /* SQFS_FILESYSTEM_H */