blob: 079b6cc31a57bf9bed79205f0dd080b0b78d5e50 [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 */
8
Sven-Göran Bergh6928d9f2013-01-14 02:21:41 +01009//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o
10
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020011//config:
12//config:config FEATURE_VOLUMEID_SQUASHFS
13//config: bool "SquashFS filesystem"
14//config: default y
15//config: depends on VOLUMEID && FEATURE_BLKID_TYPE
16//config: help
17//config: Squashfs is a compressed read-only filesystem for Linux. Squashfs is
18//config: intended for general read-only filesystem use and in constrained block
19//config: device/memory systems (e.g. embedded systems) where low overhead is
20//config: needed.
21//config:
22
Sven-Göran Bergh6928d9f2013-01-14 02:21:41 +010023#include "volume_id_internal.h"
24
25struct squashfs_superblock {
26 uint32_t magic;
27/*
28 uint32_t dummy[6];
29 uint16_t major;
30 uint16_t minor;
31*/
32} PACKED;
33
34int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/)
35{
36#define off ((uint64_t)0)
37 struct squashfs_superblock *sb;
38
39 dbg("SquashFS: probing at offset 0x%llx", (unsigned long long) off);
40 sb = volume_id_get_buffer(id, off, 0x200);
41 if (!sb)
42 return -1;
43
44 // Old SquashFS (pre 4.0) can be both big and little endian, so test for both.
45 // Likewise, it is commonly used in firwmare with some non-standard signatures.
46#define pack(a,b,c,d) ( (uint32_t)((a * 256 + b) * 256 + c) * 256 + d )
47#define SIG1 pack('s','q','s','h')
48#define SIG2 pack('h','s','q','s')
49#define SIG3 pack('s','h','s','q')
50#define SIG4 pack('q','s','h','s')
51 if (sb->magic == SIG1
52 || sb->magic == SIG2
53 || sb->magic == SIG3
54 || sb->magic == SIG4
55 ) {
56 IF_FEATURE_BLKID_TYPE(id->type = "squashfs";)
57 return 0;
58 }
59
60 return -1;
61}