Implementation of function to write the PVD.

The directory entry for the root directory is still missing.
This commit is contained in:
Vreixo Formoso 2007-12-18 21:55:01 +01:00
parent 2dc15ab164
commit 5eb3a7e038
2 changed files with 141 additions and 4 deletions

View File

@ -36,6 +36,7 @@ void ecma119_image_free(Ecma119Image *t)
writer->free_data(writer); writer->free_data(writer);
free(writer); free(writer);
} }
free(t->input_charset);
free(t->writers); free(t->writers);
free(t); free(t);
} }
@ -137,6 +138,7 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
target->curblock += div_up(path_table_size, BLOCK_SIZE); target->curblock += div_up(path_table_size, BLOCK_SIZE);
target->m_path_table_pos = target->curblock; target->m_path_table_pos = target->curblock;
target->curblock += div_up(path_table_size, BLOCK_SIZE); target->curblock += div_up(path_table_size, BLOCK_SIZE);
target->path_table_size = path_table_size;
/* ...and free path table cache, as we do not need it at all */ /* ...and free path table cache, as we do not need it at all */
free(pathlist); free(pathlist);
@ -144,11 +146,94 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
return ISO_SUCCESS; return ISO_SUCCESS;
} }
/**
* Write the Primary Volume Descriptor
*/
static static
int ecma119_writer_write_vol_desc(IsoImageWriter *writer) int ecma119_writer_write_vol_desc(IsoImageWriter *writer)
{ {
//TODO to implement IsoImage *image;
return -1; Ecma119Image *t;
struct ecma119_pri_vol_desc vol;
char *vol_id, *pub_id, *data_id, *volset_id;
char *system_id, *application_id, *copyright_file_id;
char *abstract_file_id, *biblio_file_id;
if (writer == NULL) {
return ISO_MEM_ERROR;
}
t = writer->target;
image = t->image;
memset(&vol, 0, sizeof(struct ecma119_pri_vol_desc));
str2d_char(image->volume_id, t->input_charset, &vol_id);
str2a_char(image->publisher_id, t->input_charset, &pub_id);
str2a_char(image->data_preparer_id, t->input_charset, &data_id);
str2d_char(image->volset_id, t->input_charset, &volset_id);
str2a_char(image->system_id, t->input_charset, &system_id);
str2a_char(image->application_id, t->input_charset, &application_id);
str2d_char(image->copyright_file_id, t->input_charset, &copyright_file_id);
str2d_char(image->abstract_file_id, t->input_charset, &abstract_file_id);
str2d_char(image->biblio_file_id, t->input_charset, &biblio_file_id);
vol.vol_desc_type[0] = 1;
memcpy(vol.std_identifier, "CD001", 5);
vol.vol_desc_version[0] = 1;
if (system_id)
strncpy((char*)vol.system_id, system_id, 32);
else
/* put linux by default? */
memcpy(vol.system_id, "LINUX", 5);
if (vol_id)
strncpy((char*)vol.volume_id, vol_id, 32);
iso_bb(vol.vol_space_size, t->vol_space_size, 4);
iso_bb(vol.vol_set_size, 1, 2);
iso_bb(vol.vol_seq_number, 1, 2);
iso_bb(vol.block_size, BLOCK_SIZE, 2);
iso_bb(vol.path_table_size, t->path_table_size, 4);
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);
if (volset_id)
strncpy((char*)vol.vol_set_id, volset_id, 128);
if (pub_id)
strncpy((char*)vol.publisher_id, pub_id, 128);
if (data_id)
strncpy((char*)vol.data_prep_id, data_id, 128);
if (application_id)
strncpy((char*)vol.application_id, application_id, 128);
if (copyright_file_id)
strncpy((char*)vol.copyright_file_id, copyright_file_id, 37);
if (abstract_file_id)
strncpy((char*)vol.abstract_file_id, abstract_file_id, 37);
if (biblio_file_id)
strncpy((char*)vol.bibliographic_file_id, biblio_file_id, 37);
iso_datetime_17(vol.vol_creation_time, t->now);
iso_datetime_17(vol.vol_modification_time, t->now);
iso_datetime_17(vol.vol_effective_time, t->now);
vol.file_structure_version[0] = 1;
free(vol_id);
free(volset_id);
free(pub_id);
free(data_id);
free(system_id);
free(application_id);
free(copyright_file_id);
free(abstract_file_id);
free(biblio_file_id);
/* Finally write the Volume Descriptor */
return iso_write(t, &vol, sizeof(struct ecma119_pri_vol_desc));
} }
static static
@ -215,6 +300,8 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
target->sort_files = opts->sort_files; target->sort_files = opts->sort_files;
target->now = time(NULL); target->now = time(NULL);
target->ms_block = 0;
target->input_charset = strdup("UTF-8"); //TODO
/* /*
* 2. Based on those options, create needed writers: iso, joliet... * 2. Based on those options, create needed writers: iso, joliet...
@ -224,7 +311,7 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
* current block. * current block.
* Finally, create Writer for files. * Finally, create Writer for files.
*/ */
target->curblock = 16; target->curblock = target->ms_block + 16;
/* the number of writers is dependent of the extensions */ /* the number of writers is dependent of the extensions */
target->writers = malloc(2 * sizeof(void*)); target->writers = malloc(2 * sizeof(void*));
@ -258,6 +345,14 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
} }
} }
/*
* The volume space size is just the size of the last session, in
* case of ms images.
*/
target->total_size = (target->curblock - target->ms_block) * BLOCK_SIZE;
target->vol_space_size = target->curblock - target->ms_block;
/* 4. Start writting thread */ /* 4. Start writting thread */

View File

@ -45,11 +45,13 @@ struct ecma119_image {
int sort_files; /**< if sort files or not. Sorting is based of int sort_files; /**< if sort files or not. Sorting is based of
* the weight of each file */ * the weight of each file */
char *input_charset;
uint32_t ms_block; /**< start block for a ms image */
time_t now; /**< Time at which writing began. */ time_t now; /**< Time at which writing began. */
off_t total_size; /**< Total size of the output. This only off_t total_size; /**< Total size of the output. This only
* includes the current volume. */ * includes the current volume. */
//uint32_t vol_space_size; uint32_t vol_space_size;
/* /*
* Block being processed, either during image writing or structure * Block being processed, either during image writing or structure
@ -62,6 +64,7 @@ struct ecma119_image {
* and needed for path table computation in a efficient way * and needed for path table computation in a efficient way
*/ */
size_t ndirs; size_t ndirs;
uint32_t path_table_size;
uint32_t l_path_table_pos; uint32_t l_path_table_pos;
uint32_t m_path_table_pos; uint32_t m_path_table_pos;
@ -77,4 +80,43 @@ struct ecma119_image {
int rdfd; /* read from here */ int rdfd; /* read from here */
}; };
#define BP(a,b) [(b) - (a) + 1]
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);
};
#endif /*LIBISO_ECMA119_H_*/ #endif /*LIBISO_ECMA119_H_*/