blob: 8ed28385fb13b0c094bd6d427722181266d9a602 [file] [log] [blame]
bigbiff7b4c7a62015-01-01 19:44:14 -05001/*
2 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
3 *
4 * Inspired by libvolume_id by
5 * Kay Sievers <kay.sievers@vrfy.org>
6 *
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
9 */
10#include <stdio.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <string.h>
14#include <stdint.h>
15
16#include "bitops.h" /* swab16() */
17#include "superblocks.h"
18
19struct sqsh_super_block {
20 uint32_t s_magic;
21 uint32_t inodes;
22 uint32_t bytes_used_2;
23 uint32_t uid_start_2;
24 uint32_t guid_start_2;
25 uint32_t inode_table_start_2;
26 uint32_t directory_table_start_2;
27 uint16_t s_major;
28 uint16_t s_minor;
29} __attribute__((packed));
30
31static int probe_squashfs(blkid_probe pr, const struct blkid_idmag *mag)
32{
33 struct sqsh_super_block *sq;
34 uint16_t major;
35 uint16_t minor;
36
37 sq = blkid_probe_get_sb(pr, mag, struct sqsh_super_block);
38 if (!sq)
39 return errno ? -errno : 1;
40
41 major = le16_to_cpu(sq->s_major);
42 minor = le16_to_cpu(sq->s_minor);
43 if (major < 4)
44 return 1;
45
46 blkid_probe_sprintf_version(pr, "%u.%u", major, minor);
47
48 return 0;
49}
50
51static int probe_squashfs3(blkid_probe pr, const struct blkid_idmag *mag)
52{
53 struct sqsh_super_block *sq;
54 uint16_t major;
55 uint16_t minor;
56
57 sq = blkid_probe_get_sb(pr, mag, struct sqsh_super_block);
58 if (!sq)
59 return errno ? -errno : 1;
60
61 if (strcmp(mag->magic, "sqsh") == 0) {
62 major = be16_to_cpu(sq->s_major);
63 minor = be16_to_cpu(sq->s_minor);
64 } else {
65 major = le16_to_cpu(sq->s_major);
66 minor = le16_to_cpu(sq->s_minor);
67 }
68
69 if (major > 3)
70 return 1;
71
72 blkid_probe_sprintf_version(pr, "%u.%u", major, minor);
73
74 return 0;
75}
76
77const struct blkid_idinfo squashfs_idinfo =
78{
79 .name = "squashfs",
80 .usage = BLKID_USAGE_FILESYSTEM,
81 .probefunc = probe_squashfs,
82 .magics =
83 {
84 { .magic = "hsqs", .len = 4 },
85 { NULL }
86 }
87};
88
89const struct blkid_idinfo squashfs3_idinfo =
90{
91 .name = "squashfs3",
92 .usage = BLKID_USAGE_FILESYSTEM,
93 .probefunc = probe_squashfs3,
94 .magics =
95 {
96 { .magic = "sqsh", .len = 4 }, /* big endian */
97 { .magic = "hsqs", .len = 4 }, /* little endian */
98 { NULL }
99 }
100};
101