iso9660.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include "volume_id_internal.h"
  21. #define ISO_SUPERBLOCK_OFFSET 0x8000
  22. #define ISO_SECTOR_SIZE 0x800
  23. #define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
  24. #define ISO_VD_PRIMARY 0x1
  25. #define ISO_VD_SUPPLEMENTARY 0x2
  26. #define ISO_VD_END 0xff
  27. #define ISO_VD_MAX 16
  28. struct iso_volume_descriptor {
  29. uint8_t vd_type;
  30. uint8_t vd_id[5];
  31. uint8_t vd_version;
  32. uint8_t flags;
  33. uint8_t system_id[32];
  34. uint8_t volume_id[32];
  35. uint8_t unused[8];
  36. uint8_t space_size[8];
  37. uint8_t escape_sequences[8];
  38. } PACKED;
  39. struct high_sierra_volume_descriptor {
  40. uint8_t foo[8];
  41. uint8_t type;
  42. uint8_t id[4];
  43. uint8_t version;
  44. } PACKED;
  45. int FAST_FUNC volume_id_probe_iso9660(struct volume_id *id /*,uint64_t off*/)
  46. {
  47. #define off ((uint64_t)0)
  48. uint8_t *buf;
  49. struct iso_volume_descriptor *is;
  50. struct high_sierra_volume_descriptor *hs;
  51. dbg("probing at offset 0x%llx", (unsigned long long) off);
  52. buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
  53. if (buf == NULL)
  54. return -1;
  55. is = (struct iso_volume_descriptor *) buf;
  56. if (memcmp(is->vd_id, "CD001", 5) == 0) {
  57. int vd_offset;
  58. int i;
  59. dbg("read label from PVD");
  60. // volume_id_set_label_raw(id, is->volume_id, 32);
  61. volume_id_set_label_string(id, is->volume_id, 32);
  62. dbg("looking for SVDs");
  63. vd_offset = ISO_VD_OFFSET;
  64. for (i = 0; i < ISO_VD_MAX; i++) {
  65. uint8_t svd_label[64];
  66. is = volume_id_get_buffer(id, off + vd_offset, 0x200);
  67. if (is == NULL || is->vd_type == ISO_VD_END)
  68. break;
  69. if (is->vd_type != ISO_VD_SUPPLEMENTARY)
  70. continue;
  71. dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset));
  72. if (memcmp(is->escape_sequences, "%/@", 3) == 0
  73. || memcmp(is->escape_sequences, "%/C", 3) == 0
  74. || memcmp(is->escape_sequences, "%/E", 3) == 0
  75. ) {
  76. dbg("Joliet extension found");
  77. volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32);
  78. if (memcmp(id->label, svd_label, 16) == 0) {
  79. dbg("SVD label is identical, use the possibly longer PVD one");
  80. break;
  81. }
  82. // volume_id_set_label_raw(id, is->volume_id, 32);
  83. volume_id_set_label_string(id, svd_label, 32);
  84. // strcpy(id->type_version, "Joliet Extension");
  85. goto found;
  86. }
  87. vd_offset += ISO_SECTOR_SIZE;
  88. }
  89. goto found;
  90. }
  91. hs = (struct high_sierra_volume_descriptor *) buf;
  92. if (memcmp(hs->id, "CDROM", 5) == 0) {
  93. // strcpy(id->type_version, "High Sierra");
  94. goto found;
  95. }
  96. return -1;
  97. found:
  98. // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
  99. // id->type = "iso9660";
  100. return 0;
  101. }