]> err.no Git - util-linux/commitdiff
blkid: add squashfs
authorKarel Zak <kzak@redhat.com>
Thu, 4 Dec 2008 10:37:18 +0000 (11:37 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Feb 2009 22:21:49 +0000 (23:21 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/probe.c
libs/blkid/src/probers/Makefile.am
libs/blkid/src/probers/probers.h
libs/blkid/src/probers/squashfs.c [new file with mode: 0644]

index 374c34f8dd7fe4d793205b0a7d914bfb1323ea9e..29f8658daca47f0541a173b25fb108401e4ce9b4 100644 (file)
@@ -84,7 +84,7 @@ static const struct blkid_idinfo *idinfos[] =
        &ocfs2_idinfo,
        &oracleasm_idinfo,
        &vxfs_idinfo,
-       /* TODO: squashfs */
+       &squashfs_idinfo,
        /* TODO: netware */
 };
 
index 33c8ad115995b7fb130f32cb01ede675d938d661..21a4b03ceab3e5cba1175fb3f0a3adc8f3cf7a5a 100644 (file)
@@ -35,6 +35,7 @@ libprobers_a_SOURCES =        probers.h \
                        minix.c \
                        ufs.c \
                        hpfs.c \
+                       squashfs.c \
                        lvm.c
 
 all-local: $(lib_LIBRARIES)
index 8272c957dfd8ebe6461edb7ea1ef1c9f2046653d..f295fbeae9248af8da97069b170747c8d8f110fd 100644 (file)
@@ -1,17 +1,9 @@
 /*
- * probe.h - constants and on-disk structures for extracting device data
- *
- * Copyright (C) 1999 by Andries Brouwer
- * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
- * Copyright (C) 2001 by Andreas Dilger
  * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
  *
- * %Begin-Header%
  * This file may be redistributed under the terms of the
  * GNU Lesser General Public License.
- * %End-Header%
  */
-
 #ifndef _BLKID_PROBE_H
 #define _BLKID_PROBE_H
 
@@ -58,5 +50,6 @@ extern const struct blkid_idinfo lvm1_idinfo;
 extern const struct blkid_idinfo luks_idinfo;
 extern const struct blkid_idinfo highpoint37x_idinfo;
 extern const struct blkid_idinfo highpoint45x_idinfo;
+extern const struct blkid_idinfo squashfs_idinfo;
 
 #endif /* _BLKID_PROBE_H */
diff --git a/libs/blkid/src/probers/squashfs.c b/libs/blkid/src/probers/squashfs.c
new file mode 100644 (file)
index 0000000..74f53bf
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ *
+ * Inspired by libvolume_id by
+ *     Kay Sievers <kay.sievers@vrfy.org>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "bitops.h"    /* swab16() */
+#include "blkidP.h"
+
+struct sqsh_super_block {
+       uint32_t        s_magic;
+       uint32_t        inodes;
+       uint32_t        bytes_used_2;
+       uint32_t        uid_start_2;
+       uint32_t        guid_start_2;
+       uint32_t        inode_table_start_2;
+       uint32_t        directory_table_start_2;
+       uint16_t        s_major;
+       uint16_t        s_minor;
+};
+
+static int probe_squashfs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct sqsh_super_block *sq;
+
+       sq = blkid_probe_get_sb(pr, mag, struct sqsh_super_block);
+       if (!sq)
+               return -1;
+
+       if (strcmp(mag->magic, "sqsh") == 0 ||
+           strcmp(mag->magic, "qshs") == 0)
+               blkid_probe_sprintf_version(pr, "%u.%u",
+                               sq->s_major,
+                               sq->s_minor);
+       else
+               blkid_probe_sprintf_version(pr, "%u.%u",
+                               swab16(sq->s_major),
+                               swab16(sq->s_minor));
+       return 0;
+}
+
+const struct blkid_idinfo squashfs_idinfo =
+{
+       .name           = "squashfs",
+       .usage          = BLKID_USAGE_FILESYSTEM,
+       .probefunc      = probe_squashfs,
+       .magics         =
+       {
+               { .magic = "sqsh", .len = 4 },
+               { .magic = "hsqs", .len = 4 }, /* swap */
+
+               /* LZMA version */
+               { .magic = "qshs", .len = 4 },
+               { .magic = "shsq", .len = 4 }, /* swap */
+               { NULL }
+       }
+};
+
+