From 46ffb6d33df165d694e852c781e1473e9d08e02d Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Fri, 21 Dec 2007 00:05:41 +0100 Subject: [PATCH] Fix implementation of PVD writing. --- src/ecma119.c | 65 +++++++++++++++++++++++++++++++++++++-- src/ecma119.h | 85 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 114 insertions(+), 36 deletions(-) diff --git a/src/ecma119.c b/src/ecma119.c index 0d024d0..6d62162 100644 --- a/src/ecma119.c +++ b/src/ecma119.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2007 Vreixo Formoso + * Copyright (c) 2007 Mario Danic * * This file is part of the libisofs project; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 as @@ -147,7 +148,64 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer) } /** - * Write the Primary Volume Descriptor + * Write a single directory record (ECMA-119, 9.1) + * + * @param file_id + * if >= 0, we use it instead of the filename (for "." and ".." entries). + * As a magic number, file_id == 3 means that we are writing the root + * directory record in the PVD (ECMA-119, 8.4.18) (in order to distinguish + * it from the "." entry in the root directory) + * @param len_fi + * Computed length of the file identifier. Total size of the directory + * entry will be len + 33 + padding if needed (ECMA-119, 9.1.12) + */ +static +void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id, + uint8_t *buf, size_t len_fi) +{ + uint32_t len; + uint32_t block; + uint8_t len_dr; + uint8_t f_id = (uint8_t) ((file_id == 3) ? 0 : file_id); + uint8_t *name = (file_id >= 0) ? &f_id : (uint8_t*)node->iso_name; + + struct ecma119_dir_record *rec = (struct ecma119_dir_record*)buf; + + len_dr = 33 + len_fi + (len_fi % 2); + + if (node->type == ECMA119_DIR) { + len = calc_dir_size(t, node); + block = node->info.dir.block; + } else if (node->type == ECMA119_FILE) { + len = iso_file_src_get_size(node->info.file); + block = node->info.file->block; + } else { + /* + * for nodes other than files and dirs, we set both + * len and block to 0 + */ + len = 0; + block = 0; + } + + /* + * For ".." entry we need to write the parent info! + */ + if (file_id == 1 && node->parent) + node = node->parent; + + rec->len_dr[0] = len_dr; + iso_bb(rec->block, block, 4); + iso_bb(rec->length, len, 4); + iso_datetime_7(rec->recording_time, t->now); + rec->flags[0] = (node->type == ECMA119_DIR) ? 2 : 0; + iso_bb(rec->vol_seq_number, 1, 2); + rec->len_fi[0] = len_fi; + memcpy(rec->file_id, name, len_fi); +} + +/** + * Write the Primary Volume Descriptor (ECMA-119, 8.4) */ static int ecma119_writer_write_vol_desc(IsoImageWriter *writer) @@ -198,8 +256,7 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer) iso_lsb(vol.l_path_table_pos, t->l_path_table_pos, 4); iso_msb(vol.m_path_table_pos, t->m_path_table_pos, 4); - //TODO - //write_one_dir_record(t, t->root, 3, vol->root_dir_record); + write_one_dir_record(t, t->root, 3, vol.root_dir_record, 1); if (volset_id) strncpy((char*)vol.vol_set_id, volset_id, 128); @@ -239,6 +296,8 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer) static int ecma119_writer_write_data(IsoImageWriter *writer) { + + //TODO to implement return -1; } diff --git a/src/ecma119.h b/src/ecma119.h index b3bb8a7..a69f636 100644 --- a/src/ecma119.h +++ b/src/ecma119.h @@ -82,41 +82,60 @@ struct ecma119_image { #define BP(a,b) [(b) - (a) + 1] +/* ECMA-119, 8.4 */ struct ecma119_pri_vol_desc { - uint8_t vol_desc_type BP(1, 1); - uint8_t std_identifier BP(2, 6); - uint8_t vol_desc_version BP(7, 7); - uint8_t unused1 BP(8, 8); - uint8_t system_id BP(9, 40); - uint8_t volume_id BP(41, 72); - uint8_t unused2 BP(73, 80); - uint8_t vol_space_size BP(81, 88); - uint8_t unused3 BP(89, 120); - uint8_t vol_set_size BP(121, 124); - uint8_t vol_seq_number BP(125, 128); - uint8_t block_size BP(129, 132); - uint8_t path_table_size BP(133, 140); - uint8_t l_path_table_pos BP(141, 144); - uint8_t opt_l_path_table_pos BP(145, 148); - uint8_t m_path_table_pos BP(149, 152); - uint8_t opt_m_path_table_pos BP(153, 156); - uint8_t root_dir_record BP(157, 190); - uint8_t vol_set_id BP(191, 318); - uint8_t publisher_id BP(319, 446); - uint8_t data_prep_id BP(447, 574); - uint8_t application_id BP(575, 702); - uint8_t copyright_file_id BP(703, 739); - uint8_t abstract_file_id BP(740, 776); - uint8_t bibliographic_file_id BP(777, 813); - uint8_t vol_creation_time BP(814, 830); - uint8_t vol_modification_time BP(831, 847); - uint8_t vol_expiration_time BP(848, 864); - uint8_t vol_effective_time BP(865, 881); - uint8_t file_structure_version BP(882, 882); - uint8_t reserved1 BP(883, 883); - uint8_t app_use BP(884, 1395); - uint8_t reserved2 BP(1396, 2048); + uint8_t vol_desc_type BP(1, 1); + uint8_t std_identifier BP(2, 6); + uint8_t vol_desc_version BP(7, 7); + uint8_t unused1 BP(8, 8); + uint8_t system_id BP(9, 40); + uint8_t volume_id BP(41, 72); + uint8_t unused2 BP(73, 80); + uint8_t vol_space_size BP(81, 88); + uint8_t unused3 BP(89, 120); + uint8_t vol_set_size BP(121, 124); + uint8_t vol_seq_number BP(125, 128); + uint8_t block_size BP(129, 132); + uint8_t path_table_size BP(133, 140); + uint8_t l_path_table_pos BP(141, 144); + uint8_t opt_l_path_table_pos BP(145, 148); + uint8_t m_path_table_pos BP(149, 152); + uint8_t opt_m_path_table_pos BP(153, 156); + uint8_t root_dir_record BP(157, 190); + uint8_t vol_set_id BP(191, 318); + uint8_t publisher_id BP(319, 446); + uint8_t data_prep_id BP(447, 574); + uint8_t application_id BP(575, 702); + uint8_t copyright_file_id BP(703, 739); + uint8_t abstract_file_id BP(740, 776); + uint8_t bibliographic_file_id BP(777, 813); + uint8_t vol_creation_time BP(814, 830); + uint8_t vol_modification_time BP(831, 847); + uint8_t vol_expiration_time BP(848, 864); + uint8_t vol_effective_time BP(865, 881); + uint8_t file_structure_version BP(882, 882); + uint8_t reserved1 BP(883, 883); + uint8_t app_use BP(884, 1395); + uint8_t reserved2 BP(1396, 2048); +}; + +/* ECMA-119, 9.1 */ +struct ecma119_dir_record +{ + uint8_t len_dr BP(1, 1); + uint8_t len_xa BP(2, 2); + uint8_t block BP(3, 10); + uint8_t length BP(11, 18); + uint8_t recording_time BP(19, 25); + uint8_t flags BP(26, 26); + uint8_t file_unit_size BP(27, 27); + uint8_t interleave_gap_size BP(28, 28); + uint8_t vol_seq_number BP(29, 32); + uint8_t len_fi BP(33, 33); + uint8_t file_id BP(34, 34); /* 34 to 33+len_fi */ + /* padding field (if len_fi is even) */ + /* system use (len_dr - len_su + 1 to len_dr) */ }; #endif /*LIBISO_ECMA119_H_*/