bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | struct 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 | |
| 31 | static int probe_squashfs(blkid_probe pr, const struct blkid_idmag *mag) |
| 32 | { |
| 33 | struct sqsh_super_block *sq; |
| 34 | |
| 35 | sq = blkid_probe_get_sb(pr, mag, struct sqsh_super_block); |
| 36 | if (!sq) |
| 37 | return -1; |
| 38 | |
| 39 | if (strcmp(mag->magic, "sqsh") == 0 || |
| 40 | strcmp(mag->magic, "qshs") == 0) |
| 41 | blkid_probe_sprintf_version(pr, "%u.%u", |
| 42 | sq->s_major, |
| 43 | sq->s_minor); |
| 44 | else |
| 45 | blkid_probe_sprintf_version(pr, "%u.%u", |
| 46 | swab16(sq->s_major), |
| 47 | swab16(sq->s_minor)); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | const struct blkid_idinfo squashfs_idinfo = |
| 52 | { |
| 53 | .name = "squashfs", |
| 54 | .usage = BLKID_USAGE_FILESYSTEM, |
| 55 | .probefunc = probe_squashfs, |
| 56 | .magics = |
| 57 | { |
| 58 | { .magic = "sqsh", .len = 4 }, |
| 59 | { .magic = "hsqs", .len = 4 }, /* swap */ |
| 60 | |
| 61 | /* LZMA version */ |
| 62 | { .magic = "qshs", .len = 4 }, |
| 63 | { .magic = "shsq", .len = 4 }, /* swap */ |
| 64 | { NULL } |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | |