2 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
4 * Inspired by libvolume_id by
5 * Kay Sievers <kay.sievers@vrfy.org>
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
16 #include "bitops.h" /* swab16() */
17 #include "superblocks.h"
19 #include <libubox/md5.h>
21 struct squashfs_super_block
{
35 uint64_t id_table_start
;
36 uint64_t xattr_id_table_start
;
37 uint64_t inode_table_start
;
38 uint64_t directory_table_start
;
39 uint64_t fragment_table_start
;
40 uint64_t lookup_table_start
;
41 } __attribute__((packed
));
43 static int probe_squashfs(blkid_probe pr
, const struct blkid_idmag
*mag
)
45 md5_ctx_t ctx
= { 0 };
47 struct squashfs_super_block
*sq
;
49 sq
= blkid_probe_get_sb(pr
, mag
, struct squashfs_super_block
);
53 if (strcmp(mag
->magic
, "sqsh") == 0 ||
54 strcmp(mag
->magic
, "qshs") == 0)
55 blkid_probe_sprintf_version(pr
, "%u.%u",
56 be16_to_cpu(sq
->s_major
),
57 be16_to_cpu(sq
->s_minor
));
59 blkid_probe_sprintf_version(pr
, "%u.%u",
60 le16_to_cpu(sq
->s_major
),
61 le16_to_cpu(sq
->s_minor
));
63 md5_hash(sq
, sizeof(*sq
), &ctx
);
65 blkid_probe_sprintf_uuid(pr
, NULL
, 4, "%08x-%08x-%08x-%08x",
66 md5
[3], md5
[2], md5
[1], md5
[0]);
70 const struct blkid_idinfo squashfs_idinfo
=
73 .usage
= BLKID_USAGE_FILESYSTEM
,
74 .probefunc
= probe_squashfs
,
77 { .magic
= "sqsh", .len
= 4 }, /* BE legacy squashfs */
78 { .magic
= "hsqs", .len
= 4 }, /* LE / v4 squashfs */
81 { .magic
= "qshs", .len
= 4 }, /* BE legacy squashfs with LZMA */
82 { .magic
= "shsq", .len
= 4 }, /* LE / v4 squashfs with LZMA */