[48e3190] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Julia Medvedeva
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup fs
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file udf_volume.c
|
---|
| 34 | * @brief Implementation of volume recognition operations.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <byteorder.h>
|
---|
| 38 | #include <block.h>
|
---|
| 39 | #include <libfs.h>
|
---|
| 40 | #include <errno.h>
|
---|
[38d150e] | 41 | #include <stdlib.h>
|
---|
[48e3190] | 42 | #include <str.h>
|
---|
| 43 | #include <mem.h>
|
---|
| 44 | #include <inttypes.h>
|
---|
| 45 | #include <io/log.h>
|
---|
| 46 | #include "udf.h"
|
---|
| 47 | #include "udf_volume.h"
|
---|
| 48 | #include "udf_osta.h"
|
---|
| 49 | #include "udf_cksum.h"
|
---|
| 50 | #include "udf_file.h"
|
---|
| 51 |
|
---|
| 52 | /** Convert long_ad to absolute sector position
|
---|
| 53 | *
|
---|
| 54 | * Convert address sector concerning origin of partition to position
|
---|
| 55 | * sector concerning origin of start of disk.
|
---|
| 56 | *
|
---|
| 57 | * @param instance UDF instance
|
---|
| 58 | * @param long_ad UDF long address
|
---|
| 59 | *
|
---|
| 60 | * @return Position of sector concerning origin of start of disk.
|
---|
| 61 | *
|
---|
| 62 | */
|
---|
| 63 | fs_index_t udf_long_ad_to_pos(udf_instance_t *instance, udf_long_ad_t *long_ad)
|
---|
| 64 | {
|
---|
[70253688] | 65 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Long_Ad to Pos: "
|
---|
[48e3190] | 66 | "partition_num=%" PRIu16 ", partition_block=%" PRIu32,
|
---|
| 67 | FLE16(long_ad->location.partition_num),
|
---|
| 68 | FLE32(long_ad->location.lblock_num));
|
---|
[a35b458] | 69 |
|
---|
[48e3190] | 70 | return instance->partitions[
|
---|
| 71 | FLE16(long_ad->location.partition_num)].start +
|
---|
| 72 | FLE32(long_ad->location.lblock_num);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | /** Check type and version of VRS
|
---|
| 76 | *
|
---|
| 77 | * Not exactly clear which values could have type and version.
|
---|
| 78 | *
|
---|
| 79 | * @param service_id
|
---|
| 80 | * @param addr Position sector with Volume Descriptor
|
---|
| 81 | * @param vd Returned value - Volume Descriptor.
|
---|
| 82 | *
|
---|
[cde999a] | 83 | * @return EOK on success or an error code.
|
---|
[48e3190] | 84 | *
|
---|
| 85 | */
|
---|
[b7fd2a0] | 86 | static errno_t udf_volume_recongnition_structure_test(service_id_t service_id,
|
---|
[48e3190] | 87 | aoff64_t addr, udf_vrs_descriptor_t *vd)
|
---|
| 88 | {
|
---|
| 89 | return block_read_bytes_direct(service_id, addr,
|
---|
| 90 | sizeof(udf_vrs_descriptor_t), vd);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /** Read Volume Recognition Sequence
|
---|
| 94 | *
|
---|
| 95 | * It is a first udf data which we read.
|
---|
| 96 | * It stars from fixed address VRS_ADDR = 32768 (bytes)
|
---|
| 97 | *
|
---|
| 98 | * @param service_id
|
---|
| 99 | *
|
---|
[cde999a] | 100 | * @return EOK on success or an error code.
|
---|
[48e3190] | 101 | */
|
---|
[1b20da0] | 102 | errno_t udf_volume_recongnition(service_id_t service_id)
|
---|
[48e3190] | 103 | {
|
---|
| 104 | aoff64_t addr = VRS_ADDR;
|
---|
| 105 | bool nsr_found = false;
|
---|
| 106 |
|
---|
| 107 | udf_vrs_descriptor_t *vd = malloc(sizeof(udf_vrs_descriptor_t));
|
---|
| 108 | if (!vd)
|
---|
| 109 | return ENOMEM;
|
---|
[a35b458] | 110 |
|
---|
[b7fd2a0] | 111 | errno_t rc = udf_volume_recongnition_structure_test(service_id, addr, vd);
|
---|
[48e3190] | 112 | if (rc != EOK) {
|
---|
| 113 | free(vd);
|
---|
| 114 | return rc;
|
---|
| 115 | }
|
---|
[a35b458] | 116 |
|
---|
[48e3190] | 117 | for (size_t i = 0; i < VRS_DEPTH; i++) {
|
---|
| 118 | addr += sizeof(udf_vrs_descriptor_t);
|
---|
[a35b458] | 119 |
|
---|
[48e3190] | 120 | rc = udf_volume_recongnition_structure_test(service_id, addr, vd);
|
---|
| 121 | if (rc != EOK) {
|
---|
| 122 | free(vd);
|
---|
| 123 | return rc;
|
---|
| 124 | }
|
---|
[a35b458] | 125 |
|
---|
[48e3190] | 126 | /*
|
---|
| 127 | * UDF standard identifier. According to ECMA 167 2/9.1.2
|
---|
| 128 | */
|
---|
| 129 | if ((str_lcmp(VRS_NSR2, (char *) vd->identifier, VRS_ID_LEN) == 0) ||
|
---|
| 130 | (str_lcmp(VRS_NSR3, (char *) vd->identifier, VRS_ID_LEN) == 0)) {
|
---|
| 131 | nsr_found = true;
|
---|
[70253688] | 132 | log_msg(LOG_DEFAULT, LVL_DEBUG, "VRS: NSR found");
|
---|
[48e3190] | 133 | continue;
|
---|
| 134 | }
|
---|
[a35b458] | 135 |
|
---|
[48e3190] | 136 | if (str_lcmp(VRS_END, (char *) vd->identifier, VRS_ID_LEN) == 0) {
|
---|
[70253688] | 137 | log_msg(LOG_DEFAULT, LVL_DEBUG, "VRS: end found");
|
---|
[48e3190] | 138 | break;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
[a35b458] | 141 |
|
---|
[48e3190] | 142 | free(vd);
|
---|
[a35b458] | 143 |
|
---|
[48e3190] | 144 | if (nsr_found)
|
---|
| 145 | return EOK;
|
---|
| 146 | else
|
---|
| 147 | return EINVAL;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | /** Convert descriptor tag fields from little-endian to current byte order
|
---|
| 151 | *
|
---|
| 152 | */
|
---|
[5c702a8] | 153 | static void udf_prepare_tag(udf_descriptor_tag_t *tag)
|
---|
[48e3190] | 154 | {
|
---|
| 155 | GET_LE16(tag->id);
|
---|
| 156 | GET_LE16(tag->version);
|
---|
| 157 | GET_LE16(tag->serial);
|
---|
| 158 | GET_LE16(tag->descriptor_crc);
|
---|
| 159 | GET_LE16(tag->descriptor_crc_length);
|
---|
| 160 | GET_LE32(tag->location);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[5c702a8] | 163 | /** Read AVD by using one of default sector size from array
|
---|
| 164 | *
|
---|
| 165 | * @param service_id
|
---|
| 166 | * @param avd Returned value - Anchor Volume Descriptor
|
---|
| 167 | * @param sector_size Expected sector size
|
---|
| 168 | *
|
---|
[cde999a] | 169 | * @return EOK on success or an error code.
|
---|
[5c702a8] | 170 | *
|
---|
| 171 | */
|
---|
[b7fd2a0] | 172 | static errno_t udf_get_anchor_volume_descriptor_by_ssize(service_id_t service_id,
|
---|
[5c702a8] | 173 | udf_anchor_volume_descriptor_t *avd, uint32_t sector_size)
|
---|
| 174 | {
|
---|
[b7fd2a0] | 175 | errno_t rc = block_read_bytes_direct(service_id,
|
---|
[5c702a8] | 176 | UDF_AVDP_SECTOR * sector_size,
|
---|
| 177 | sizeof(udf_anchor_volume_descriptor_t), avd);
|
---|
| 178 | if (rc != EOK)
|
---|
| 179 | return rc;
|
---|
[a35b458] | 180 |
|
---|
[5c702a8] | 181 | if (avd->tag.checksum != udf_tag_checksum((uint8_t *) &avd->tag))
|
---|
| 182 | return EINVAL;
|
---|
[a35b458] | 183 |
|
---|
[5c702a8] | 184 | // TODO: Should be tested in big-endian mode
|
---|
| 185 | udf_prepare_tag(&avd->tag);
|
---|
[a35b458] | 186 |
|
---|
[5c702a8] | 187 | if (avd->tag.id != UDF_TAG_AVDP)
|
---|
| 188 | return EINVAL;
|
---|
[a35b458] | 189 |
|
---|
[5c702a8] | 190 | GET_LE32(avd->main_extent.length);
|
---|
| 191 | GET_LE32(avd->main_extent.location);
|
---|
| 192 | GET_LE32(avd->reserve_extent.length);
|
---|
| 193 | GET_LE32(avd->reserve_extent.location);
|
---|
[a35b458] | 194 |
|
---|
[5c702a8] | 195 | return EOK;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[48e3190] | 198 | /** Identification of the sector size
|
---|
| 199 | *
|
---|
| 200 | * We try to read Anchor Volume Descriptor by using one item from
|
---|
| 201 | * sequence of default values. If we could read avd, we found sector size.
|
---|
| 202 | *
|
---|
| 203 | * @param service_id
|
---|
| 204 | * @param avd Returned value - Anchor Volume Descriptor
|
---|
| 205 | *
|
---|
[cde999a] | 206 | * @return EOK on success or an error code.
|
---|
[48e3190] | 207 | *
|
---|
| 208 | */
|
---|
[b7fd2a0] | 209 | errno_t udf_get_anchor_volume_descriptor(service_id_t service_id,
|
---|
[48e3190] | 210 | udf_anchor_volume_descriptor_t *avd)
|
---|
| 211 | {
|
---|
| 212 | uint32_t default_sector_size[] = {512, 1024, 2048, 4096, 8192, 0};
|
---|
[a35b458] | 213 |
|
---|
[48e3190] | 214 | udf_instance_t *instance;
|
---|
[b7fd2a0] | 215 | errno_t rc = fs_instance_get(service_id, (void **) &instance);
|
---|
[48e3190] | 216 | if (rc != EOK)
|
---|
| 217 | return rc;
|
---|
[a35b458] | 218 |
|
---|
[48e3190] | 219 | if (instance->sector_size) {
|
---|
| 220 | return udf_get_anchor_volume_descriptor_by_ssize(service_id, avd,
|
---|
| 221 | instance->sector_size);
|
---|
| 222 | } else {
|
---|
| 223 | size_t i = 0;
|
---|
| 224 | while (default_sector_size[i] != 0) {
|
---|
| 225 | rc = udf_get_anchor_volume_descriptor_by_ssize(service_id, avd,
|
---|
| 226 | default_sector_size[i]);
|
---|
| 227 | if (rc == EOK) {
|
---|
| 228 | instance->sector_size = default_sector_size[i];
|
---|
| 229 | return EOK;
|
---|
| 230 | }
|
---|
[a35b458] | 231 |
|
---|
[48e3190] | 232 | i++;
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
[a35b458] | 235 |
|
---|
[48e3190] | 236 | return EINVAL;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | /** Check on prevailing primary volume descriptor
|
---|
| 240 | *
|
---|
| 241 | * Some discs couldn't be rewritten and new information is identified
|
---|
| 242 | * by descriptors with same data as one of already created descriptors.
|
---|
| 243 | * We should find prevailing descriptor (descriptor with the highest number)
|
---|
| 244 | * and delete old descriptor.
|
---|
| 245 | *
|
---|
| 246 | * @param pvd Array of primary volumes descriptors
|
---|
| 247 | * @param cnt Count of items in array
|
---|
| 248 | * @param desc Descriptor which could prevail over one
|
---|
| 249 | * of descriptors in array.
|
---|
| 250 | *
|
---|
| 251 | * @return True if desc prevails over some descriptor in array
|
---|
| 252 | *
|
---|
| 253 | */
|
---|
| 254 | static bool udf_check_prevailing_pvd(udf_primary_volume_descriptor_t *pvd,
|
---|
| 255 | size_t cnt, udf_primary_volume_descriptor_t *desc)
|
---|
| 256 | {
|
---|
| 257 | for (size_t i = 0; i < cnt; i++) {
|
---|
| 258 | /*
|
---|
| 259 | * According to ECMA 167 3/8.4.3
|
---|
| 260 | * PVD, each of which has same contents of the corresponding
|
---|
| 261 | * Volume Identifier, Volume set identifier
|
---|
| 262 | * and Descriptor char set field.
|
---|
| 263 | */
|
---|
[44ecf89] | 264 | if ((memcmp((uint8_t *) pvd[i].volume_id,
|
---|
[48e3190] | 265 | (uint8_t *) desc->volume_id, 32) == 0) &&
|
---|
[44ecf89] | 266 | (memcmp((uint8_t *) pvd[i].volume_set_id,
|
---|
[48e3190] | 267 | (uint8_t *) desc->volume_set_id, 128) == 0) &&
|
---|
[44ecf89] | 268 | (memcmp((uint8_t *) &pvd[i].descriptor_charset,
|
---|
[48e3190] | 269 | (uint8_t *) &desc->descriptor_charset, 64) == 0) &&
|
---|
| 270 | (FLE32(desc->sequence_number) > FLE32(pvd[i].sequence_number))) {
|
---|
| 271 | memcpy(&pvd[i], desc, sizeof(udf_primary_volume_descriptor_t));
|
---|
| 272 | return true;
|
---|
| 273 | }
|
---|
| 274 | }
|
---|
[a35b458] | 275 |
|
---|
[48e3190] | 276 | return false;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | /** Check on prevailing logic volume descriptor
|
---|
| 280 | *
|
---|
| 281 | * Some discs couldn't be rewritten and new information is identified
|
---|
| 282 | * by descriptors with same data as one of already created descriptors.
|
---|
| 283 | * We should find prevailing descriptor (descriptor with the highest number)
|
---|
| 284 | * and delete old descriptor.
|
---|
| 285 | *
|
---|
| 286 | * @param lvd Array of logic volumes descriptors
|
---|
| 287 | * @param cnt Count of items in array
|
---|
| 288 | * @param desc Descriptor which could prevail over one
|
---|
| 289 | * of descriptors in array.
|
---|
| 290 | *
|
---|
| 291 | * @return True if desc prevails over some descriptor in array
|
---|
| 292 | *
|
---|
| 293 | */
|
---|
| 294 | static bool udf_check_prevailing_lvd(udf_logical_volume_descriptor_t *lvd,
|
---|
| 295 | size_t cnt, udf_logical_volume_descriptor_t *desc)
|
---|
| 296 | {
|
---|
| 297 | for (size_t i = 0; i < cnt; i++) {
|
---|
| 298 | /*
|
---|
| 299 | * According to ECMA 167 3/8.4.3
|
---|
| 300 | * LVD, each of which has same contents of the corresponding
|
---|
| 301 | * Logic Volume Identifier and Descriptor char set field.
|
---|
| 302 | */
|
---|
[44ecf89] | 303 | if ((memcmp((uint8_t *) lvd[i].logical_volume_id,
|
---|
[48e3190] | 304 | (uint8_t *) desc->logical_volume_id, 128) == 0) &&
|
---|
[44ecf89] | 305 | (memcmp((uint8_t *) &lvd[i].charset,
|
---|
[48e3190] | 306 | (uint8_t *) &desc->charset, 64) == 0) &&
|
---|
| 307 | (FLE32(desc->sequence_number) > FLE32(lvd[i].sequence_number))) {
|
---|
| 308 | memcpy(&lvd[i], desc, sizeof(udf_logical_volume_descriptor_t));
|
---|
| 309 | return true;
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
[a35b458] | 312 |
|
---|
[48e3190] | 313 | return false;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | /** Check on prevailing partition descriptor
|
---|
| 317 | *
|
---|
| 318 | * Some discs couldn't be rewritten and new information is identified
|
---|
| 319 | * by descriptors with same data as one of already created descriptors.
|
---|
| 320 | * We should find prevailing descriptor (descriptor with the highest number)
|
---|
| 321 | * and delete old descriptor.
|
---|
| 322 | *
|
---|
| 323 | * @param pvd Array of partition descriptors
|
---|
| 324 | * @param cnt Count of items in array
|
---|
| 325 | * @param desc Descriptor which could prevail over one
|
---|
| 326 | * of descriptors in array.
|
---|
| 327 | *
|
---|
| 328 | * @return True if desc prevails over some descriptor in array
|
---|
| 329 | *
|
---|
| 330 | */
|
---|
| 331 | static bool udf_check_prevailing_pd(udf_partition_descriptor_t *pd, size_t cnt,
|
---|
| 332 | udf_partition_descriptor_t *desc)
|
---|
| 333 | {
|
---|
| 334 | for (size_t i = 0; i < cnt; i++) {
|
---|
| 335 | /*
|
---|
| 336 | * According to ECMA 167 3/8.4.3
|
---|
| 337 | * Partition descriptors with identical Partition Number
|
---|
| 338 | */
|
---|
| 339 | if ((FLE16(pd[i].number) == FLE16(desc->number)) &&
|
---|
| 340 | (FLE32(desc->sequence_number) > FLE32(pd[i].sequence_number))) {
|
---|
| 341 | memcpy(&pd[i], desc, sizeof(udf_partition_descriptor_t));
|
---|
| 342 | return true;
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
[a35b458] | 345 |
|
---|
[48e3190] | 346 | return false;
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | /** Read information about virtual partition
|
---|
| 350 | *
|
---|
| 351 | * Fill start and length fields for partition. This function quite similar of
|
---|
| 352 | * udf_read_icd. But in this we can meet only two descriptors and
|
---|
| 353 | * we have to read only one allocator.
|
---|
| 354 | *
|
---|
| 355 | * @param instance UDF instance
|
---|
| 356 | * @param pos Position (Extended) File entry descriptor
|
---|
| 357 | * @param id Index of partition in instance::partitions array
|
---|
| 358 | *
|
---|
[cde999a] | 359 | * @return EOK on success or an error code.
|
---|
[48e3190] | 360 | *
|
---|
| 361 | */
|
---|
[b7fd2a0] | 362 | static errno_t udf_read_virtual_partition(udf_instance_t *instance, uint32_t pos,
|
---|
[48e3190] | 363 | uint32_t id)
|
---|
| 364 | {
|
---|
| 365 | block_t *block = NULL;
|
---|
[b7fd2a0] | 366 | errno_t rc = block_get(&block, instance->service_id, pos,
|
---|
[48e3190] | 367 | BLOCK_FLAGS_NONE);
|
---|
| 368 | if (rc != EOK)
|
---|
| 369 | return rc;
|
---|
[a35b458] | 370 |
|
---|
[48e3190] | 371 | udf_descriptor_tag_t *desc = (udf_descriptor_tag_t *) (block->data);
|
---|
| 372 | if (desc->checksum != udf_tag_checksum((uint8_t *) desc)) {
|
---|
| 373 | block_put(block);
|
---|
| 374 | return EINVAL;
|
---|
| 375 | }
|
---|
[a35b458] | 376 |
|
---|
[48e3190] | 377 | /*
|
---|
| 378 | * We think that we have only one allocator. It is means that virtual
|
---|
| 379 | * partition, like physical, isn't fragmented.
|
---|
| 380 | * According to doc the type of allocator is short_ad.
|
---|
| 381 | */
|
---|
| 382 | switch (FLE16(desc->id)) {
|
---|
| 383 | case UDF_FILE_ENTRY:
|
---|
[70253688] | 384 | log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: File entry descriptor found");
|
---|
[a35b458] | 385 |
|
---|
[48e3190] | 386 | udf_file_entry_descriptor_t *fed =
|
---|
| 387 | (udf_file_entry_descriptor_t *) block->data;
|
---|
| 388 | uint32_t start_alloc = FLE32(fed->ea_lenght) + UDF_FE_OFFSET;
|
---|
| 389 | udf_short_ad_t *short_d =
|
---|
| 390 | (udf_short_ad_t *) ((uint8_t *) fed + start_alloc);
|
---|
| 391 | instance->partitions[id].start = FLE32(short_d->position);
|
---|
| 392 | instance->partitions[id].lenght = FLE32(short_d->length);
|
---|
| 393 | break;
|
---|
[a35b458] | 394 |
|
---|
[48e3190] | 395 | case UDF_EFILE_ENTRY:
|
---|
[70253688] | 396 | log_msg(LOG_DEFAULT, LVL_DEBUG, "ICB: Extended file entry descriptor found");
|
---|
[a35b458] | 397 |
|
---|
[48e3190] | 398 | udf_extended_file_entry_descriptor_t *efed =
|
---|
| 399 | (udf_extended_file_entry_descriptor_t *) block->data;
|
---|
| 400 | start_alloc = FLE32(efed->ea_lenght) + UDF_EFE_OFFSET;
|
---|
| 401 | short_d = (udf_short_ad_t *) ((uint8_t *) efed + start_alloc);
|
---|
| 402 | instance->partitions[id].start = FLE32(short_d->position);
|
---|
| 403 | instance->partitions[id].lenght = FLE32(short_d->length);
|
---|
| 404 | break;
|
---|
| 405 | }
|
---|
[a35b458] | 406 |
|
---|
[48e3190] | 407 | return block_put(block);
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | /** Search partition in array of partitions
|
---|
| 411 | *
|
---|
| 412 | * Used only in function udf_fill_volume_info
|
---|
| 413 | *
|
---|
| 414 | * @param pd Array of partitions
|
---|
| 415 | * @param pd_cnt Count items in array
|
---|
| 416 | * @param id Number partition (not index) which we want to find
|
---|
| 417 | *
|
---|
| 418 | * @return Index of partition or (size_t) -1 if we didn't find anything
|
---|
| 419 | *
|
---|
| 420 | */
|
---|
| 421 | static size_t udf_find_partition(udf_partition_descriptor_t *pd, size_t pd_cnt,
|
---|
| 422 | size_t id)
|
---|
| 423 | {
|
---|
| 424 | for (size_t i = 0; i < pd_cnt; i++) {
|
---|
| 425 | if (FLE16(pd[i].number) == id)
|
---|
| 426 | return i;
|
---|
| 427 | }
|
---|
[a35b458] | 428 |
|
---|
[48e3190] | 429 | return (size_t) -1;
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | /** Fill instance structures by information about partitions and logic
|
---|
| 433 | *
|
---|
| 434 | * @param lvd Array of logic volumes descriptors
|
---|
| 435 | * @param lvd_cnt Count of items in lvd array
|
---|
| 436 | * @param pd Array of partition descriptors
|
---|
| 437 | * @param pd_cnt Count of items in pd array
|
---|
| 438 | * @param instance UDF instance
|
---|
| 439 | *
|
---|
[cde999a] | 440 | * @return EOK on success or an error code.
|
---|
[48e3190] | 441 | *
|
---|
| 442 | */
|
---|
[b7fd2a0] | 443 | static errno_t udf_fill_volume_info(udf_logical_volume_descriptor_t *lvd,
|
---|
[48e3190] | 444 | size_t lvd_cnt, udf_partition_descriptor_t *pd, size_t pd_cnt,
|
---|
| 445 | udf_instance_t *instance)
|
---|
| 446 | {
|
---|
| 447 | instance->volumes = calloc(lvd_cnt, sizeof(udf_lvolume_t));
|
---|
| 448 | if (instance->volumes == NULL)
|
---|
| 449 | return ENOMEM;
|
---|
[a35b458] | 450 |
|
---|
[48e3190] | 451 | instance->partitions = calloc(pd_cnt, sizeof(udf_partition_t));
|
---|
| 452 | if (instance->partitions == NULL) {
|
---|
| 453 | free(instance->volumes);
|
---|
| 454 | return ENOMEM;
|
---|
| 455 | }
|
---|
[a35b458] | 456 |
|
---|
[48e3190] | 457 | instance->partition_cnt = pd_cnt;
|
---|
[a35b458] | 458 |
|
---|
[48e3190] | 459 | /*
|
---|
| 460 | * Fill information about logical volumes. We will save
|
---|
| 461 | * information about all partitions placed inside each volumes.
|
---|
| 462 | */
|
---|
[a35b458] | 463 |
|
---|
[48e3190] | 464 | size_t vir_pd_cnt = 0;
|
---|
| 465 | for (size_t i = 0; i < lvd_cnt; i++) {
|
---|
| 466 | instance->volumes[i].partitions =
|
---|
| 467 | calloc(FLE32(lvd[i].number_of_partitions_maps),
|
---|
| 468 | sizeof(udf_partition_t *));
|
---|
| 469 | if (instance->volumes[i].partitions == NULL) {
|
---|
| 470 | // FIXME: Memory leak, cleanup code missing
|
---|
| 471 | return ENOMEM;
|
---|
| 472 | }
|
---|
[a35b458] | 473 |
|
---|
[48e3190] | 474 | instance->volumes[i].partition_cnt = 0;
|
---|
| 475 | instance->volumes[i].logical_block_size =
|
---|
| 476 | FLE32(lvd[i].logical_block_size);
|
---|
[a35b458] | 477 |
|
---|
[48e3190] | 478 | /*
|
---|
| 479 | * In theory we could have more than 1 logical volume. But now
|
---|
| 480 | * for current work of driver we will think that it single and all
|
---|
| 481 | * partitions from array pd belong to only first lvd
|
---|
| 482 | */
|
---|
[a35b458] | 483 |
|
---|
[48e3190] | 484 | uint8_t *idx = lvd[i].partition_map;
|
---|
| 485 | for (size_t j = 0; j < FLE32(lvd[i].number_of_partitions_maps);
|
---|
| 486 | j++) {
|
---|
| 487 | udf_type1_partition_map_t *pm1 =
|
---|
| 488 | (udf_type1_partition_map_t *) idx;
|
---|
[a35b458] | 489 |
|
---|
[48e3190] | 490 | if (pm1->partition_map_type == 1) {
|
---|
| 491 | size_t pd_num = udf_find_partition(pd, pd_cnt,
|
---|
| 492 | FLE16(pm1->partition_number));
|
---|
| 493 | if (pd_num == (size_t) -1) {
|
---|
| 494 | // FIXME: Memory leak, cleanup code missing
|
---|
| 495 | return ENOENT;
|
---|
| 496 | }
|
---|
[a35b458] | 497 |
|
---|
[48e3190] | 498 | /*
|
---|
| 499 | * Fill information about physical partitions. We will save all
|
---|
| 500 | * partitions (physical and virtual) inside one array
|
---|
| 501 | * instance::partitions
|
---|
| 502 | */
|
---|
| 503 | instance->partitions[j].access_type =
|
---|
| 504 | FLE32(pd[pd_num].access_type);
|
---|
| 505 | instance->partitions[j].lenght =
|
---|
| 506 | FLE32(pd[pd_num].length);
|
---|
| 507 | instance->partitions[j].number =
|
---|
| 508 | FLE16(pm1->partition_number);
|
---|
| 509 | instance->partitions[j].start =
|
---|
| 510 | FLE32(pd[pd_num].starting_location);
|
---|
[a35b458] | 511 |
|
---|
[48e3190] | 512 | instance->volumes[i].partitions[
|
---|
| 513 | instance->volumes[i].partition_cnt] =
|
---|
| 514 | &instance->partitions[j];
|
---|
[a35b458] | 515 |
|
---|
[70253688] | 516 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume[%" PRIun "]: partition [type %u] "
|
---|
[48e3190] | 517 | "found and filled", i, pm1->partition_map_type);
|
---|
[a35b458] | 518 |
|
---|
[48e3190] | 519 | instance->volumes[i].partition_cnt++;
|
---|
| 520 | idx += pm1->partition_map_lenght;
|
---|
| 521 | continue;
|
---|
| 522 | }
|
---|
[a35b458] | 523 |
|
---|
[48e3190] | 524 | udf_type2_partition_map_t *pm2 =
|
---|
| 525 | (udf_type2_partition_map_t *) idx;
|
---|
[a35b458] | 526 |
|
---|
[48e3190] | 527 | if (pm2->partition_map_type == 2) {
|
---|
| 528 | // TODO: check partition_ident for metadata_partition_map
|
---|
[a35b458] | 529 |
|
---|
[48e3190] | 530 | udf_metadata_partition_map_t *metadata =
|
---|
| 531 | (udf_metadata_partition_map_t *) idx;
|
---|
[a35b458] | 532 |
|
---|
[70253688] | 533 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Metadata file location=%u",
|
---|
[48e3190] | 534 | FLE32(metadata->metadata_fileloc));
|
---|
[a35b458] | 535 |
|
---|
[48e3190] | 536 | vir_pd_cnt++;
|
---|
| 537 | instance->partitions = realloc(instance->partitions,
|
---|
| 538 | (pd_cnt + vir_pd_cnt) * sizeof(udf_partition_t));
|
---|
| 539 | if (instance->partitions == NULL) {
|
---|
| 540 | // FIXME: Memory leak, cleanup code missing
|
---|
| 541 | return ENOMEM;
|
---|
| 542 | }
|
---|
[a35b458] | 543 |
|
---|
[48e3190] | 544 | instance->partition_cnt++;
|
---|
[a35b458] | 545 |
|
---|
[48e3190] | 546 | size_t pd_num = udf_find_partition(pd, pd_cnt,
|
---|
| 547 | FLE16(metadata->partition_number));
|
---|
| 548 | if (pd_num == (size_t) -1) {
|
---|
| 549 | // FIXME: Memory leak, cleanup code missing
|
---|
| 550 | return ENOENT;
|
---|
| 551 | }
|
---|
[a35b458] | 552 |
|
---|
[48e3190] | 553 | instance->partitions[j].number =
|
---|
| 554 | FLE16(metadata->partition_number);
|
---|
[b7fd2a0] | 555 | errno_t rc = udf_read_virtual_partition(instance,
|
---|
[48e3190] | 556 | FLE32(metadata->metadata_fileloc) +
|
---|
| 557 | FLE32(pd[pd_num].starting_location), j);
|
---|
| 558 | if (rc != EOK) {
|
---|
| 559 | // FIXME: Memory leak, cleanup code missing
|
---|
| 560 | return rc;
|
---|
| 561 | }
|
---|
[a35b458] | 562 |
|
---|
[48e3190] | 563 | /* Virtual partition placed inside physical */
|
---|
| 564 | instance->partitions[j].start +=
|
---|
| 565 | FLE32(pd[pd_num].starting_location);
|
---|
[a35b458] | 566 |
|
---|
[48e3190] | 567 | instance->volumes[i].partitions[
|
---|
| 568 | instance->volumes[i].partition_cnt] =
|
---|
| 569 | &instance->partitions[j];
|
---|
[a35b458] | 570 |
|
---|
[70253688] | 571 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Virtual partition: num=%d, start=%d",
|
---|
[48e3190] | 572 | instance->partitions[j].number,
|
---|
| 573 | instance->partitions[j].start);
|
---|
[70253688] | 574 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume[%" PRIun "]: partition [type %u] "
|
---|
[48e3190] | 575 | "found and filled", i, pm2->partition_map_type);
|
---|
[a35b458] | 576 |
|
---|
[48e3190] | 577 | instance->volumes[i].partition_cnt++;
|
---|
| 578 | idx += metadata->partition_map_length;
|
---|
| 579 | continue;
|
---|
| 580 | }
|
---|
[a35b458] | 581 |
|
---|
[48e3190] | 582 | /* Not type 1 nor type 2 */
|
---|
| 583 | udf_general_type_t *pm = (udf_general_type_t *) idx;
|
---|
[a35b458] | 584 |
|
---|
[70253688] | 585 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume[%" PRIun "]: partition [type %u] "
|
---|
[48e3190] | 586 | "found and skipped", i, pm->partition_map_type);
|
---|
[a35b458] | 587 |
|
---|
[48e3190] | 588 | idx += pm->partition_map_lenght;
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
[a35b458] | 591 |
|
---|
[48e3190] | 592 | return EOK;
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 | /** Read volume descriptors sequence
|
---|
| 596 | *
|
---|
| 597 | * @param service_id
|
---|
| 598 | * @param addr UDF extent descriptor (ECMA 167 3/7.1)
|
---|
| 599 | *
|
---|
[cde999a] | 600 | * @return EOK on success or an error code.
|
---|
[48e3190] | 601 | *
|
---|
| 602 | */
|
---|
[b7fd2a0] | 603 | errno_t udf_read_volume_descriptor_sequence(service_id_t service_id,
|
---|
[48e3190] | 604 | udf_extent_t addr)
|
---|
| 605 | {
|
---|
| 606 | udf_instance_t *instance;
|
---|
[b7fd2a0] | 607 | errno_t rc = fs_instance_get(service_id, (void **) &instance);
|
---|
[48e3190] | 608 | if (rc != EOK)
|
---|
| 609 | return rc;
|
---|
[a35b458] | 610 |
|
---|
[48e3190] | 611 | aoff64_t pos = addr.location;
|
---|
| 612 | aoff64_t end = pos + (addr.length / instance->sector_size) - 1;
|
---|
[a35b458] | 613 |
|
---|
[48e3190] | 614 | if (pos == end)
|
---|
| 615 | return EINVAL;
|
---|
[a35b458] | 616 |
|
---|
[48e3190] | 617 | size_t max_descriptors = ALL_UP(addr.length, instance->sector_size);
|
---|
[a35b458] | 618 |
|
---|
[48e3190] | 619 | udf_primary_volume_descriptor_t *pvd = calloc(max_descriptors,
|
---|
| 620 | sizeof(udf_primary_volume_descriptor_t));
|
---|
| 621 | if (pvd == NULL)
|
---|
| 622 | return ENOMEM;
|
---|
[a35b458] | 623 |
|
---|
[48e3190] | 624 | udf_logical_volume_descriptor_t *lvd = calloc(max_descriptors,
|
---|
| 625 | instance->sector_size);
|
---|
| 626 | if (lvd == NULL) {
|
---|
| 627 | free(pvd);
|
---|
| 628 | return ENOMEM;
|
---|
| 629 | }
|
---|
[a35b458] | 630 |
|
---|
[48e3190] | 631 | udf_partition_descriptor_t *pd = calloc(max_descriptors,
|
---|
| 632 | sizeof(udf_partition_descriptor_t));
|
---|
| 633 | if (pd == NULL) {
|
---|
| 634 | free(pvd);
|
---|
| 635 | free(lvd);
|
---|
| 636 | return ENOMEM;
|
---|
| 637 | }
|
---|
[a35b458] | 638 |
|
---|
[48e3190] | 639 | size_t pvd_cnt = 0;
|
---|
| 640 | size_t lvd_cnt = 0;
|
---|
| 641 | size_t pd_cnt = 0;
|
---|
[a35b458] | 642 |
|
---|
[48e3190] | 643 | while (pos <= end) {
|
---|
| 644 | block_t *block = NULL;
|
---|
| 645 | rc = block_get(&block, service_id, pos, BLOCK_FLAGS_NONE);
|
---|
| 646 | if (rc != EOK) {
|
---|
| 647 | free(pvd);
|
---|
| 648 | free(lvd);
|
---|
| 649 | free(pd);
|
---|
| 650 | return rc;
|
---|
| 651 | }
|
---|
[a35b458] | 652 |
|
---|
[48e3190] | 653 | udf_volume_descriptor_t *vol =
|
---|
| 654 | (udf_volume_descriptor_t *) block->data;
|
---|
[a35b458] | 655 |
|
---|
[48e3190] | 656 | switch (FLE16(vol->common.tag.id)) {
|
---|
| 657 | /* One sector size descriptors */
|
---|
| 658 | case UDF_TAG_PVD:
|
---|
[70253688] | 659 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume: Primary volume descriptor found");
|
---|
[a35b458] | 660 |
|
---|
[48e3190] | 661 | if (!udf_check_prevailing_pvd(pvd, pvd_cnt, &vol->volume)) {
|
---|
| 662 | memcpy(&pvd[pvd_cnt], &vol->volume,
|
---|
| 663 | sizeof(udf_primary_volume_descriptor_t));
|
---|
| 664 | pvd_cnt++;
|
---|
| 665 | }
|
---|
[a35b458] | 666 |
|
---|
[48e3190] | 667 | pos++;
|
---|
| 668 | break;
|
---|
[a35b458] | 669 |
|
---|
[48e3190] | 670 | case UDF_TAG_VDP:
|
---|
[70253688] | 671 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume: Volume descriptor pointer found");
|
---|
[48e3190] | 672 | pos++;
|
---|
| 673 | break;
|
---|
[a35b458] | 674 |
|
---|
[48e3190] | 675 | case UDF_TAG_IUVD:
|
---|
[70253688] | 676 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 677 | "Volume: Implementation use volume descriptor found");
|
---|
| 678 | pos++;
|
---|
| 679 | break;
|
---|
[a35b458] | 680 |
|
---|
[48e3190] | 681 | case UDF_TAG_PD:
|
---|
[70253688] | 682 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume: Partition descriptor found");
|
---|
| 683 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Partition number: %u, contents: '%.6s', "
|
---|
[48e3190] | 684 | "access type: %" PRIu32, FLE16(vol->partition.number),
|
---|
| 685 | vol->partition.contents.id, FLE32(vol->partition.access_type));
|
---|
[70253688] | 686 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Partition start: %" PRIu32 " (sector), "
|
---|
[48e3190] | 687 | "size: %" PRIu32 " (sectors)",
|
---|
| 688 | FLE32(vol->partition.starting_location),
|
---|
| 689 | FLE32(vol->partition.length));
|
---|
[a35b458] | 690 |
|
---|
[48e3190] | 691 | if (!udf_check_prevailing_pd(pd, pd_cnt, &vol->partition)) {
|
---|
| 692 | memcpy(&pd[pd_cnt], &vol->partition,
|
---|
| 693 | sizeof(udf_partition_descriptor_t));
|
---|
| 694 | pd_cnt++;
|
---|
| 695 | }
|
---|
[a35b458] | 696 |
|
---|
[48e3190] | 697 | udf_partition_header_descriptor_t *phd =
|
---|
| 698 | (udf_partition_header_descriptor_t *) vol->partition.contents_use;
|
---|
| 699 | if (FLE32(phd->unallocated_space_table.length)) {
|
---|
[70253688] | 700 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 701 | "space table: length=%" PRIu32 ", pos=%" PRIu32,
|
---|
| 702 | FLE32(phd->unallocated_space_table.length),
|
---|
| 703 | FLE32(phd->unallocated_space_table.position));
|
---|
[a35b458] | 704 |
|
---|
[48e3190] | 705 | instance->space_type = SPACE_TABLE;
|
---|
| 706 | instance->uaspace_start =
|
---|
| 707 | FLE32(vol->partition.starting_location) +
|
---|
| 708 | FLE32(phd->unallocated_space_table.position);
|
---|
| 709 | instance->uaspace_lenght =
|
---|
| 710 | FLE32(phd->unallocated_space_table.length);
|
---|
| 711 | }
|
---|
[a35b458] | 712 |
|
---|
[48e3190] | 713 | if (FLE32(phd->unallocated_space_bitmap.length)) {
|
---|
[70253688] | 714 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 715 | "space bitmap: length=%" PRIu32 ", pos=%" PRIu32,
|
---|
| 716 | FLE32(phd->unallocated_space_bitmap.length),
|
---|
| 717 | FLE32(phd->unallocated_space_bitmap.position));
|
---|
[a35b458] | 718 |
|
---|
[48e3190] | 719 | instance->space_type = SPACE_BITMAP;
|
---|
| 720 | instance->uaspace_start =
|
---|
| 721 | FLE32(vol->partition.starting_location) +
|
---|
| 722 | FLE32(phd->unallocated_space_bitmap.position);
|
---|
| 723 | instance->uaspace_lenght =
|
---|
| 724 | FLE32(phd->unallocated_space_bitmap.length);
|
---|
| 725 | }
|
---|
[a35b458] | 726 |
|
---|
[48e3190] | 727 | pos++;
|
---|
| 728 | break;
|
---|
[a35b458] | 729 |
|
---|
[48e3190] | 730 | /* Relative size descriptors */
|
---|
| 731 | case UDF_TAG_LVD:
|
---|
[70253688] | 732 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume: Logical volume descriptor found");
|
---|
[a35b458] | 733 |
|
---|
[48e3190] | 734 | aoff64_t sct =
|
---|
| 735 | ALL_UP((sizeof(udf_logical_volume_descriptor_t) +
|
---|
| 736 | FLE32(vol->logical.map_table_length)),
|
---|
| 737 | sizeof(udf_common_descriptor_t));
|
---|
| 738 | pos += sct;
|
---|
| 739 | char tmp[130];
|
---|
[a35b458] | 740 |
|
---|
[48e3190] | 741 | udf_to_unix_name(tmp, 129,
|
---|
| 742 | (char *) vol->logical.logical_volume_id, 128,
|
---|
| 743 | &vol->logical.charset);
|
---|
[a35b458] | 744 |
|
---|
[70253688] | 745 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Logical Volume ID: '%s', "
|
---|
[48e3190] | 746 | "logical block size: %" PRIu32 " (bytes)", tmp,
|
---|
| 747 | FLE32(vol->logical.logical_block_size));
|
---|
[70253688] | 748 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Map table size: %" PRIu32 " (bytes), "
|
---|
[48e3190] | 749 | "number of partition maps: %" PRIu32,
|
---|
| 750 | FLE32(vol->logical.map_table_length),
|
---|
| 751 | FLE32(vol->logical.number_of_partitions_maps));
|
---|
[a35b458] | 752 |
|
---|
[48e3190] | 753 | if (!udf_check_prevailing_lvd(lvd, lvd_cnt, &vol->logical)) {
|
---|
| 754 | memcpy(&lvd[lvd_cnt], &vol->logical,
|
---|
| 755 | sizeof(udf_logical_volume_descriptor_t) +
|
---|
| 756 | FLE32(vol->logical.map_table_length));
|
---|
| 757 | lvd_cnt++;
|
---|
| 758 | }
|
---|
[a35b458] | 759 |
|
---|
[48e3190] | 760 | break;
|
---|
[a35b458] | 761 |
|
---|
[48e3190] | 762 | case UDF_TAG_USD:
|
---|
[70253688] | 763 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume: Unallocated space descriptor found");
|
---|
[a35b458] | 764 |
|
---|
[48e3190] | 765 | sct = ALL_UP((sizeof(udf_unallocated_space_descriptor_t) +
|
---|
| 766 | FLE32(vol->unallocated.allocation_descriptors_num)*
|
---|
| 767 | sizeof(udf_extent_t)), sizeof(udf_common_descriptor_t));
|
---|
| 768 | instance->uaspace_start = pos;
|
---|
| 769 | instance->uaspace_lenght = sct;
|
---|
| 770 | instance->uasd = (udf_unallocated_space_descriptor_t *)
|
---|
| 771 | malloc(sct * instance->sector_size);
|
---|
| 772 | if (instance->uasd == NULL) {
|
---|
| 773 | // FIXME: Memory leak, cleanup missing
|
---|
| 774 | return ENOMEM;
|
---|
| 775 | }
|
---|
[a35b458] | 776 |
|
---|
[48e3190] | 777 | memcpy(instance->uasd, block->data, instance->sector_size);
|
---|
| 778 | pos += sct;
|
---|
| 779 | break;
|
---|
[a35b458] | 780 |
|
---|
[48e3190] | 781 | case UDF_TAG_LVID:
|
---|
[70253688] | 782 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[48e3190] | 783 | "Volume: Logical volume integrity descriptor found");
|
---|
[a35b458] | 784 |
|
---|
[48e3190] | 785 | pos++;
|
---|
| 786 | break;
|
---|
[a35b458] | 787 |
|
---|
[48e3190] | 788 | case UDF_TAG_TD:
|
---|
[70253688] | 789 | log_msg(LOG_DEFAULT, LVL_DEBUG, "Volume: Terminating descriptor found");
|
---|
[a35b458] | 790 |
|
---|
[48e3190] | 791 | /* Found terminating descriptor. Exiting */
|
---|
| 792 | pos = end + 1;
|
---|
| 793 | break;
|
---|
[a35b458] | 794 |
|
---|
[48e3190] | 795 | default:
|
---|
| 796 | pos++;
|
---|
| 797 | }
|
---|
[a35b458] | 798 |
|
---|
[48e3190] | 799 | rc = block_put(block);
|
---|
| 800 | if (rc != EOK) {
|
---|
| 801 | free(pvd);
|
---|
| 802 | free(lvd);
|
---|
| 803 | free(pd);
|
---|
| 804 | return rc;
|
---|
| 805 | }
|
---|
| 806 | }
|
---|
[a35b458] | 807 |
|
---|
[48e3190] | 808 | /* Fill the instance */
|
---|
| 809 | udf_fill_volume_info(lvd, lvd_cnt, pd, pd_cnt, instance);
|
---|
[a35b458] | 810 |
|
---|
[48e3190] | 811 | for (size_t i = 0; i < lvd_cnt; i++) {
|
---|
| 812 | pos = udf_long_ad_to_pos(instance,
|
---|
| 813 | (udf_long_ad_t *) &lvd[i].logical_volume_conents_use);
|
---|
[a35b458] | 814 |
|
---|
[48e3190] | 815 | block_t *block = NULL;
|
---|
| 816 | rc = block_get(&block, instance->service_id, pos,
|
---|
| 817 | BLOCK_FLAGS_NONE);
|
---|
| 818 | if (rc != EOK) {
|
---|
| 819 | // FIXME: Memory leak, cleanup missing
|
---|
| 820 | return rc;
|
---|
| 821 | }
|
---|
[a35b458] | 822 |
|
---|
[48e3190] | 823 | udf_descriptor_tag_t *desc = block->data;
|
---|
[a35b458] | 824 |
|
---|
[70253688] | 825 | log_msg(LOG_DEFAULT, LVL_DEBUG, "First tag ID=%" PRIu16, desc->id);
|
---|
[a35b458] | 826 |
|
---|
[48e3190] | 827 | if (desc->checksum != udf_tag_checksum((uint8_t *) desc)) {
|
---|
| 828 | // FIXME: Memory leak, cleanup missing
|
---|
| 829 | return EINVAL;
|
---|
| 830 | }
|
---|
[a35b458] | 831 |
|
---|
[48e3190] | 832 | udf_prepare_tag(desc);
|
---|
[a35b458] | 833 |
|
---|
[48e3190] | 834 | udf_fileset_descriptor_t *fd = block->data;
|
---|
| 835 | memcpy((uint8_t *) &instance->charset,
|
---|
| 836 | (uint8_t *) &fd->fileset_charset, sizeof(fd->fileset_charset));
|
---|
[a35b458] | 837 |
|
---|
[48e3190] | 838 | instance->volumes[i].root_dir = udf_long_ad_to_pos(instance,
|
---|
| 839 | &fd->root_dir_icb);
|
---|
| 840 | }
|
---|
[a35b458] | 841 |
|
---|
[48e3190] | 842 | free(pvd);
|
---|
| 843 | free(lvd);
|
---|
| 844 | free(pd);
|
---|
| 845 | return EOK;
|
---|
| 846 | }
|
---|
| 847 |
|
---|
| 848 | /**
|
---|
| 849 | * @}
|
---|
| 850 | */
|
---|