]> err.no Git - util-linux/commitdiff
blkid: add iso9600
authorKarel Zak <kzak@redhat.com>
Mon, 13 Oct 2008 14:06:03 +0000 (16:06 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Feb 2009 22:21:46 +0000 (23:21 +0100)
Notes:

- the original libblkid does not make difference between High Sierra and
the standard iso9660 (the superblock is different). This bugs is fixed.

- the original libblkid does not detect for MS Joliet Extension.
This bugs is fixed.

Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/probe.c
libs/blkid/src/probers/Makefile.am
libs/blkid/src/probers/iso9660.c [new file with mode: 0644]
libs/blkid/src/probers/probers.h

index 3ea81052b48d30be35b413fef84a33f91da3756e..a379d5c5ae26ff11352df02f41bc557c4343b607 100644 (file)
@@ -66,7 +66,8 @@ static const struct blkid_idinfo *idinfos[] =
        &jbd_idinfo,
        &hfsplus_idinfo,
        &hfs_idinfo,
-       &ntfs_idinfo
+       &ntfs_idinfo,
+       &iso9660_idinfo
 };
 
 #ifndef ARRAY_SIZE
index f19a82eef87032e50241c16603edc67f6f782d59..7a1c34f230fc8c0e4b60b066f98101c5092499f9 100644 (file)
@@ -25,6 +25,7 @@ libprobers_a_SOURCES =        probers.h \
                        reiserfs.c \
                        romfs.c \
                        ntfs.c \
-                       hfs.c
+                       hfs.c \
+                       iso9660.c
 
 all-local: $(lib_LIBRARIES)
diff --git a/libs/blkid/src/probers/iso9660.c b/libs/blkid/src/probers/iso9660.c
new file mode 100644 (file)
index 0000000..441b320
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 1999 by Andries Brouwer
+ * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
+ * Copyright (C) 2001 by Andreas Dilger
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stdint.h>
+
+#include "blkidP.h"
+
+struct iso_volume_descriptor {
+       unsigned char   vd_type;
+       unsigned char   vd_id[5];
+       unsigned char   vd_version;
+       unsigned char   flags;
+       unsigned char   system_id[32];
+       unsigned char   volume_id[32];
+       unsigned char   unused[8];
+       unsigned char   space_size[8];
+       unsigned char   escape_sequences[8];
+};
+
+#define ISO_SUPERBLOCK_OFFSET          0x8000
+#define ISO_SECTOR_SIZE                        0x800
+#define ISO_VD_OFFSET                  (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
+#define ISO_VD_SUPPLEMENTARY           0x2
+#define ISO_VD_END                     0xff
+#define ISO_VD_MAX                     16
+
+struct high_sierra_volume_descriptor {
+       unsigned char   foo[8];
+       unsigned char   type;
+       unsigned char   id[5];
+       unsigned char   version;
+       unsigned char   unused1;
+       unsigned char   system_id[32];
+       unsigned char   volume_id[32];
+};
+
+/* old High Sierra format */
+static int probe_iso9660_hsfs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct high_sierra_volume_descriptor *iso;
+
+       iso = blkid_probe_get_sb(pr, mag, struct high_sierra_volume_descriptor);
+       if (!iso)
+               return -1;
+
+       blkid_probe_set_version(pr, "High Sierra");
+       blkid_probe_set_label(pr, iso->volume_id, sizeof(iso->volume_id));
+       return 0;
+}
+
+/* iso9660 [+ Microsoft Joliet Extension] */
+static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       struct iso_volume_descriptor *iso;
+       unsigned char label[32];
+       int i;
+       int vd_offset;
+
+       if (strcmp(mag->magic, "CDROM") == 0)
+               return probe_iso9660_hsfs(pr, mag);
+
+       iso = blkid_probe_get_sb(pr, mag, struct iso_volume_descriptor);
+       if (!iso)
+               return -1;
+
+       memcpy(label, iso->volume_id, sizeof(label));
+
+       /* Joliet Extension */
+       vd_offset = ISO_VD_OFFSET;
+       for (i = 0; i < ISO_VD_MAX; i++) {
+               uint8_t svd_label[64];
+
+               iso = (struct iso_volume_descriptor *)
+                       blkid_probe_get_buffer(pr,
+                                       vd_offset,
+                                       sizeof(struct iso_volume_descriptor));
+
+               if (iso == NULL || iso->vd_type == ISO_VD_END)
+                       break;
+               if (iso->vd_type != ISO_VD_SUPPLEMENTARY)
+                       continue;
+
+               if (memcmp(iso->escape_sequences, "%/@", 3) == 0 ||
+                   memcmp(iso->escape_sequences, "%/C", 3) == 0 ||
+                   memcmp(iso->escape_sequences, "%/E", 3) == 0) {
+
+                       blkid_probe_set_utf8label(pr,
+                                       iso->volume_id,
+                                       sizeof(svd_label),
+                                       BLKID_ENC_UTF16BE);
+
+                       blkid_probe_set_version(pr, "Joliet Extension");
+                       goto has_label;
+               }
+               vd_offset += ISO_SECTOR_SIZE;
+       }
+
+       /* Joliet not found, let use standard iso label */
+       blkid_probe_set_label(pr, label, sizeof(label));
+
+has_label:
+       return 0;
+}
+
+
+const struct blkid_idinfo iso9660_idinfo =
+{
+       .name           = "iso9660",
+       .usage          = BLKID_USAGE_FILESYSTEM,
+       .probefunc      = probe_iso9660,
+       .magics         =
+       {
+               { .magic = "CD001", .len = 5, .kboff = 32, .sboff = 1 },
+               { .magic = "CDROM", .len = 5, .kboff = 32, .sboff = 9 },
+               { NULL }
+       }
+};
+
index 35180e6a4d6bfee1a7626142224780904765528d..378c673cbd9e25c7b30f929879fe0694cf9876ce 100644 (file)
@@ -46,6 +46,6 @@ extern const struct blkid_idinfo reiser4_idinfo;
 extern const struct blkid_idinfo hfs_idinfo;
 extern const struct blkid_idinfo hfsplus_idinfo;
 extern const struct blkid_idinfo ntfs_idinfo;
-
+extern const struct blkid_idinfo iso9660_idinfo;
 
 #endif /* _BLKID_PROBE_H */