blob: 4b65afd8b0486465746465c655889092b777b051 [file] [log] [blame]
Sven-Göran Bergh6928d9f2013-01-14 02:21:41 +01001/*
2 * volume_id - reads filesystem label and uuid
3 *
4 * Copyright (C) 2012 S-G Bergh <sgb@systemasis.org>
5 *
6 * Licensed under GPLv2, see file LICENSE in this source tree.
7 */
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +02008//config:config FEATURE_VOLUMEID_SQUASHFS
9//config: bool "SquashFS filesystem"
10//config: default y
11//config: depends on VOLUMEID && FEATURE_BLKID_TYPE
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: Squashfs is a compressed read-only filesystem for Linux. Squashfs is
14//config: intended for general read-only filesystem use and in constrained block
15//config: device/memory systems (e.g. embedded systems) where low overhead is
16//config: needed.
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020017
Denys Vlasenko0c4dbd42017-09-18 16:28:43 +020018//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o
19
Sven-Göran Bergh6928d9f2013-01-14 02:21:41 +010020#include "volume_id_internal.h"
21
22struct squashfs_superblock {
23 uint32_t magic;
24/*
25 uint32_t dummy[6];
26 uint16_t major;
27 uint16_t minor;
28*/
29} PACKED;
30
31int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/)
32{
33#define off ((uint64_t)0)
34 struct squashfs_superblock *sb;
35
36 dbg("SquashFS: probing at offset 0x%llx", (unsigned long long) off);
37 sb = volume_id_get_buffer(id, off, 0x200);
38 if (!sb)
39 return -1;
40
41 // Old SquashFS (pre 4.0) can be both big and little endian, so test for both.
42 // Likewise, it is commonly used in firwmare with some non-standard signatures.
43#define pack(a,b,c,d) ( (uint32_t)((a * 256 + b) * 256 + c) * 256 + d )
44#define SIG1 pack('s','q','s','h')
45#define SIG2 pack('h','s','q','s')
46#define SIG3 pack('s','h','s','q')
47#define SIG4 pack('q','s','h','s')
48 if (sb->magic == SIG1
49 || sb->magic == SIG2
50 || sb->magic == SIG3
51 || sb->magic == SIG4
52 ) {
53 IF_FEATURE_BLKID_TYPE(id->type = "squashfs";)
54 return 0;
55 }
56
57 return -1;
58}