xref: /netbsd-src/external/bsd/file/dist/magic/magdir/dwarfs (revision e15daa8be9575f7ad2ca804c7c7c2d7f8e182d98)
1*e15daa8bSchristos
2*e15daa8bSchristos#------------------------------------------------------------------------------
3*e15daa8bSchristos# $File: dwarfs,v 1.2 2023/05/23 13:37:32 christos Exp $
4*e15daa8bSchristos# dwarfs: file(1) magic for DwarFS File System Image files
5*e15daa8bSchristos# URL: https://github.com/mhx/dwarfs for details about DwarFS
6*e15daa8bSchristos# From: Marcus Holland-Moritz <github@mhxnet.de>
7*e15daa8bSchristos
8*e15daa8bSchristos#### DwarFS Version Macro
9*e15daa8bSchristos0			name		dwarfsversion
10*e15daa8bSchristos>&0			byte		x		\b, version %d
11*e15daa8bSchristos>&1			byte		x		\b.%d
12*e15daa8bSchristos
13*e15daa8bSchristos#### DwarFS Compression Macro
14*e15daa8bSchristos0			name		dwarfscompression
15*e15daa8bSchristos>&0			leshort		=0		\b, uncompressed
16*e15daa8bSchristos>&0			leshort		=1		\b, LZMA compression
17*e15daa8bSchristos>&0			leshort		=2		\b, ZSTD compression
18*e15daa8bSchristos>&0			leshort		=3		\b, LZ4 compression
19*e15daa8bSchristos>&0			leshort		=4		\b, LZ4HC compression
20*e15daa8bSchristos>&0			leshort		=5		\b, BROTLI compression
21*e15daa8bSchristos
22*e15daa8bSchristos#### DwarFS files without header
23*e15daa8bSchristos## We first check against a DWARFS magic at the start of the file, then
24*e15daa8bSchristos## validate by checking the block count / section type to be all zeros
25*e15daa8bSchristos## for the first block. Finally, we check that the *next* block also
26*e15daa8bSchristos## has the correct DWARFS magic.
27*e15daa8bSchristos0			string		DWARFS
28*e15daa8bSchristos>&0x2A			string/b	\0\0\0\0\0\0
29*e15daa8bSchristos>>&(&0x02.q+0x0A)	string		DWARFS		DwarFS File System Image
30*e15daa8bSchristos>>>&0			use		dwarfsversion
31*e15daa8bSchristos>>&0			use		dwarfscompression
32*e15daa8bSchristos
33*e15daa8bSchristos#### DwarFS files with header
34*e15daa8bSchristos## We search for a DWARFS magic in the first 64k of the file (images with
35*e15daa8bSchristos## headers longer than 64k won't be recognized), then  validate by checking
36*e15daa8bSchristos## the block count / section type to be all zeros for the first block.
37*e15daa8bSchristos## Finally, we check that the *next* block also has the correct DWARFS magic.
38*e15daa8bSchristos## If we find a DWARFS magic that doesn't pass validation, we continue with
39*e15daa8bSchristos## an indirect match recursively.
40*e15daa8bSchristos1			search/65536/b	DWARFS
41*e15daa8bSchristos>&0x2A			string/b	\0\0\0\0\0\0
42*e15daa8bSchristos>>&(&0x02.q+0x0A)	string		DWARFS		DwarFS File System Image (with header)
43*e15daa8bSchristos>>>&0			use		dwarfsversion
44*e15daa8bSchristos>>&0			use		dwarfscompression
45*e15daa8bSchristos>&-1			indirect	x
46