Index: head/usr.sbin/makefs/cd9660.h =================================================================== --- head/usr.sbin/makefs/cd9660.h +++ head/usr.sbin/makefs/cd9660.h @@ -310,9 +310,6 @@ } iso9660_disk; -/******** GLOBAL VARIABLES ***********/ -extern iso9660_disk diskStructure; - /************ FUNCTIONS **************/ int cd9660_valid_a_chars(const char *); int cd9660_valid_d_chars(const char *); @@ -331,25 +328,27 @@ /*** Boot Functions ***/ int cd9660_write_generic_bootimage(FILE *); -int cd9660_add_generic_bootimage(const char *); -int cd9660_write_boot(FILE *); -int cd9660_add_boot_disk(const char *); -int cd9660_eltorito_add_boot_option(const char *, const char *); -int cd9660_setup_boot(int); -int cd9660_setup_boot_volume_descriptor(volume_descriptor *); +int cd9660_add_generic_bootimage(iso9660_disk *, const char *); +int cd9660_write_boot(iso9660_disk *, FILE *); +int cd9660_add_boot_disk(iso9660_disk *, const char *); +int cd9660_eltorito_add_boot_option(iso9660_disk *, const char *, + const char *); +int cd9660_setup_boot(iso9660_disk *, int); +int cd9660_setup_boot_volume_descriptor(iso9660_disk *, + volume_descriptor *); /*** Write Functions ***/ -int cd9660_write_image(const char *image); -int cd9660_copy_file(FILE *, off_t, const char *); +int cd9660_write_image(iso9660_disk *, const char *image); +int cd9660_copy_file(iso9660_disk *, FILE *, off_t, const char *); void cd9660_compute_full_filename(cd9660node *, char *); -int cd9660_compute_record_size(cd9660node *); +int cd9660_compute_record_size(iso9660_disk *, cd9660node *); /* Debugging functions */ -void debug_print_tree(cd9660node *,int); +void debug_print_tree(iso9660_disk *, cd9660node *,int); void debug_print_path_tree(cd9660node *); -void debug_print_volume_descriptor_information(void); +void debug_print_volume_descriptor_information(iso9660_disk *); void debug_dump_to_xml_ptentry(path_table_entry *,int, int); void debug_dump_to_xml_path_table(FILE *, off_t, int, int); void debug_dump_to_xml(FILE *); Index: head/usr.sbin/makefs/cd9660.c =================================================================== --- head/usr.sbin/makefs/cd9660.c +++ head/usr.sbin/makefs/cd9660.c @@ -109,58 +109,59 @@ #include "cd9660/iso9660_rrip.h" #include "cd9660/cd9660_archimedes.h" -/* - * Global variables - */ -iso9660_disk diskStructure; - -static void cd9660_finalize_PVD(void); +static void cd9660_finalize_PVD(iso9660_disk *); static cd9660node *cd9660_allocate_cd9660node(void); -static void cd9660_set_defaults(void); +static void cd9660_set_defaults(iso9660_disk *); static int cd9660_arguments_set_string(const char *, const char *, int, char, char *); static void cd9660_populate_iso_dir_record( struct _iso_directory_record_cd9660 *, u_char, u_char, u_char, const char *); -static void cd9660_setup_root_node(void); -static int cd9660_setup_volume_descriptors(void); +static void cd9660_setup_root_node(iso9660_disk *); +static int cd9660_setup_volume_descriptors(iso9660_disk *); #if 0 static int cd9660_fill_extended_attribute_record(cd9660node *); #endif static void cd9660_sort_nodes(cd9660node *); -static int cd9660_translate_node_common(cd9660node *); -static int cd9660_translate_node(fsnode *, cd9660node *); +static int cd9660_translate_node_common(iso9660_disk *, cd9660node *); +static int cd9660_translate_node(iso9660_disk *, fsnode *, cd9660node *); static int cd9660_compare_filename(const char *, const char *); static void cd9660_sorted_child_insert(cd9660node *, cd9660node *); -static int cd9660_handle_collisions(cd9660node *, int); -static cd9660node *cd9660_rename_filename(cd9660node *, int, int); -static void cd9660_copy_filenames(cd9660node *); +static int cd9660_handle_collisions(iso9660_disk *, cd9660node *, int); +static cd9660node *cd9660_rename_filename(iso9660_disk *, cd9660node *, int, + int); +static void cd9660_copy_filenames(iso9660_disk *, cd9660node *); static void cd9660_sorting_nodes(cd9660node *); static int cd9660_count_collisions(cd9660node *); -static cd9660node *cd9660_rrip_move_directory(cd9660node *); -static int cd9660_add_dot_records(cd9660node *); +static cd9660node *cd9660_rrip_move_directory(iso9660_disk *, cd9660node *); +static int cd9660_add_dot_records(iso9660_disk *, cd9660node *); -static void cd9660_convert_structure(fsnode *, cd9660node *, int, +static void cd9660_convert_structure(iso9660_disk *, fsnode *, cd9660node *, int, int *, int *); static void cd9660_free_structure(cd9660node *); -static int cd9660_generate_path_table(void); -static int cd9660_level1_convert_filename(const char *, char *, int); -static int cd9660_level2_convert_filename(const char *, char *, int); +static int cd9660_generate_path_table(iso9660_disk *); +static int cd9660_level1_convert_filename(iso9660_disk *, const char *, char *, + int); +static int cd9660_level2_convert_filename(iso9660_disk *, const char *, char *, + int); #if 0 -static int cd9660_joliet_convert_filename(const char *, char *, int); +static int cd9660_joliet_convert_filename(iso9660_disk *, const char *, char *, + int); #endif -static int cd9660_convert_filename(const char *, char *, int); -static void cd9660_populate_dot_records(cd9660node *); -static int64_t cd9660_compute_offsets(cd9660node *, int64_t); +static int cd9660_convert_filename(iso9660_disk *, const char *, char *, int); +static void cd9660_populate_dot_records(iso9660_disk *, cd9660node *); +static int64_t cd9660_compute_offsets(iso9660_disk *, cd9660node *, int64_t); #if 0 static int cd9660_copy_stat_info(cd9660node *, cd9660node *, int); #endif -static cd9660node *cd9660_create_virtual_entry(const char *, cd9660node *, int, - int); -static cd9660node *cd9660_create_file(const char *, cd9660node *, cd9660node *); -static cd9660node *cd9660_create_directory(const char *, cd9660node *, +static cd9660node *cd9660_create_virtual_entry(iso9660_disk *, const char *, + cd9660node *, int, int); +static cd9660node *cd9660_create_file(iso9660_disk *, const char *, + cd9660node *, cd9660node *); +static cd9660node *cd9660_create_directory(iso9660_disk *, const char *, + cd9660node *, cd9660node *); +static cd9660node *cd9660_create_special_directory(iso9660_disk *, u_char, cd9660node *); -static cd9660node *cd9660_create_special_directory(u_char, cd9660node *); /* @@ -191,72 +192,79 @@ * Set default values for cd9660 extension to makefs */ static void -cd9660_set_defaults(void) +cd9660_set_defaults(iso9660_disk *diskStructure) { /*Fix the sector size for now, though the spec allows for other sizes*/ - diskStructure.sectorSize = 2048; + diskStructure->sectorSize = 2048; /* Set up defaults in our own structure */ - diskStructure.verbose_level = 0; - diskStructure.keep_bad_images = 0; - diskStructure.follow_sym_links = 0; - diskStructure.isoLevel = 2; - - diskStructure.rock_ridge_enabled = 0; - diskStructure.rock_ridge_renamed_dir_name = 0; - diskStructure.rock_ridge_move_count = 0; - diskStructure.rr_moved_dir = 0; + diskStructure->verbose_level = 0; + diskStructure->keep_bad_images = 0; + diskStructure->follow_sym_links = 0; + diskStructure->isoLevel = 2; + + diskStructure->rock_ridge_enabled = 0; + diskStructure->rock_ridge_renamed_dir_name = 0; + diskStructure->rock_ridge_move_count = 0; + diskStructure->rr_moved_dir = 0; - diskStructure.archimedes_enabled = 0; - diskStructure.chrp_boot = 0; + diskStructure->archimedes_enabled = 0; + diskStructure->chrp_boot = 0; - diskStructure.include_padding_areas = 1; + diskStructure->include_padding_areas = 1; /* Spec breaking functionality */ - diskStructure.allow_deep_trees = - diskStructure.allow_start_dot = - diskStructure.allow_max_name = - diskStructure.allow_illegal_chars = - diskStructure.allow_lowercase = - diskStructure.allow_multidot = - diskStructure.omit_trailing_period = 0; + diskStructure->allow_deep_trees = + diskStructure->allow_start_dot = + diskStructure->allow_max_name = + diskStructure->allow_illegal_chars = + diskStructure->allow_lowercase = + diskStructure->allow_multidot = + diskStructure->omit_trailing_period = 0; /* Make sure the PVD is clear */ - memset(&diskStructure.primaryDescriptor, 0, 2048); + memset(&diskStructure->primaryDescriptor, 0, 2048); - memset(diskStructure.primaryDescriptor.publisher_id, 0x20,128); - memset(diskStructure.primaryDescriptor.preparer_id, 0x20,128); - memset(diskStructure.primaryDescriptor.application_id, 0x20,128); - memset(diskStructure.primaryDescriptor.copyright_file_id, 0x20,37); - memset(diskStructure.primaryDescriptor.abstract_file_id, 0x20,37); - memset(diskStructure.primaryDescriptor.bibliographic_file_id, 0x20,37); + memset(diskStructure->primaryDescriptor.publisher_id, 0x20,128); + memset(diskStructure->primaryDescriptor.preparer_id, 0x20,128); + memset(diskStructure->primaryDescriptor.application_id, 0x20,128); + memset(diskStructure->primaryDescriptor.copyright_file_id, 0x20,37); + memset(diskStructure->primaryDescriptor.abstract_file_id, 0x20,37); + memset(diskStructure->primaryDescriptor.bibliographic_file_id, 0x20,37); - strcpy(diskStructure.primaryDescriptor.system_id, "FreeBSD"); + strcpy(diskStructure->primaryDescriptor.system_id, "FreeBSD"); cd9660_defaults_set = 1; /* Boot support: Initially disabled */ - diskStructure.has_generic_bootimage = 0; - diskStructure.generic_bootimage = NULL; + diskStructure->has_generic_bootimage = 0; + diskStructure->generic_bootimage = NULL; - diskStructure.boot_image_directory = 0; - /*memset(diskStructure.boot_descriptor, 0, 2048);*/ + diskStructure->boot_image_directory = 0; + /*memset(diskStructure->boot_descriptor, 0, 2048);*/ - diskStructure.is_bootable = 0; - TAILQ_INIT(&diskStructure.boot_images); - LIST_INIT(&diskStructure.boot_entries); + diskStructure->is_bootable = 0; + TAILQ_INIT(&diskStructure->boot_images); + LIST_INIT(&diskStructure->boot_entries); } void -cd9660_prep_opts(fsinfo_t *fsopts __unused) +cd9660_prep_opts(fsinfo_t *fsopts) { - cd9660_set_defaults(); + iso9660_disk *diskStructure; + + if ((diskStructure = calloc(1, sizeof(*diskStructure))) == NULL) + err(EXIT_FAILURE, "%s: calloc", __func__); + + fsopts->fs_specific = diskStructure; + + cd9660_set_defaults(diskStructure); } void -cd9660_cleanup_opts(fsinfo_t *fsopts __unused) +cd9660_cleanup_opts(fsinfo_t *fsopts) { - + free(fsopts->fs_specific); } static int @@ -295,20 +303,19 @@ { char *var, *val; int rv; + iso9660_disk *diskStructure = fsopts->fs_specific; + /* Set up allowed options - integer options ONLY */ option_t cd9660_options[] = { - { "l", &diskStructure.isoLevel, 1, 2, "ISO Level" }, - { "isolevel", &diskStructure.isoLevel, 1, 2, "ISO Level" }, - { "verbose", &diskStructure.verbose_level, 0, 2, + { "l", &diskStructure->isoLevel, 1, 2, "ISO Level" }, + { "isolevel", &diskStructure->isoLevel, 1, 2, "ISO Level" }, + { "verbose", &diskStructure->verbose_level, 0, 2, "Turns on verbose output" }, - { "v", &diskStructure.verbose_level, 0 , 2, + { "v", &diskStructure->verbose_level, 0 , 2, "Turns on verbose output"}, { .name = NULL } }; - if (cd9660_defaults_set == 0) - cd9660_set_defaults(); - /* * Todo : finish implementing this, and make a function that * parses them @@ -335,33 +342,33 @@ /* First handle options with no parameters */ if (strcmp(var, "h") == 0) { - diskStructure.displayHelp = 1; + diskStructure->displayHelp = 1; rv = 1; } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "S", "follow-symlinks")) { /* this is not handled yet */ - diskStructure.follow_sym_links = 1; + diskStructure->follow_sym_links = 1; rv = 1; } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "L", "label")) { rv = cd9660_arguments_set_string(val, "Disk Label", 32, 'd', - diskStructure.primaryDescriptor.volume_id); + diskStructure->primaryDescriptor.volume_id); } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "applicationid")) { rv = cd9660_arguments_set_string(val, "Application Identifier", 128, 'a', - diskStructure.primaryDescriptor.application_id); + diskStructure->primaryDescriptor.application_id); } else if(CD9660_IS_COMMAND_ARG_DUAL(var, "P", "publisher")) { rv = cd9660_arguments_set_string(val, "Publisher Identifier", - 128, 'a', diskStructure.primaryDescriptor.publisher_id); + 128, 'a', diskStructure->primaryDescriptor.publisher_id); } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "p", "preparer")) { rv = cd9660_arguments_set_string(val, "Preparer Identifier", - 128, 'a', diskStructure.primaryDescriptor.preparer_id); + 128, 'a', diskStructure->primaryDescriptor.preparer_id); } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "V", "volumeid")) { rv = cd9660_arguments_set_string(val, "Volume Set Identifier", - 128, 'a', diskStructure.primaryDescriptor.volume_set_id); + 128, 'a', diskStructure->primaryDescriptor.volume_set_id); /* Boot options */ } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "B", "bootimage")) { if (val == NULL) warnx("error: The Boot Image parameter requires a valid boot information string"); else - rv = cd9660_add_boot_disk(val); + rv = cd9660_add_boot_disk(diskStructure, val); } else if (CD9660_IS_COMMAND_ARG(var, "bootimagedir")) { /* * XXXfvdl this is unused. @@ -370,7 +377,7 @@ errx(1, "error: The Boot Image Directory parameter" " requires a directory name\n"); else { - if ((diskStructure.boot_image_directory = + if ((diskStructure->boot_image_directory = malloc(strlen(val) + 1)) == NULL) { CD9660_MEM_ALLOC_ERROR("cd9660_parse_opts"); exit(1); @@ -378,40 +385,40 @@ /* BIG TODO: Add the max length function here */ cd9660_arguments_set_string(val, "Boot Image Directory", - 12 , 'd', diskStructure.boot_image_directory); + 12 , 'd', diskStructure->boot_image_directory); } } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "G", "generic-bootimage")) { if (val == NULL) warnx("error: The Boot Image parameter requires a valid boot information string"); else - rv = cd9660_add_generic_bootimage(val); + rv = cd9660_add_generic_bootimage(diskStructure, val); } else if (CD9660_IS_COMMAND_ARG(var, "no-trailing-padding")) - diskStructure.include_padding_areas = 0; + diskStructure->include_padding_areas = 0; /* RRIP */ else if (CD9660_IS_COMMAND_ARG_DUAL(var, "R", "rockridge")) - diskStructure.rock_ridge_enabled = 1; + diskStructure->rock_ridge_enabled = 1; else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "archimedes")) - diskStructure.archimedes_enabled = 1; + diskStructure->archimedes_enabled = 1; else if (CD9660_IS_COMMAND_ARG(var, "chrp-boot")) - diskStructure.chrp_boot = 1; + diskStructure->chrp_boot = 1; else if (CD9660_IS_COMMAND_ARG_DUAL(var, "K", "keep-bad-images")) - diskStructure.keep_bad_images = 1; + diskStructure->keep_bad_images = 1; else if (CD9660_IS_COMMAND_ARG(var, "allow-deep-trees")) - diskStructure.allow_deep_trees = 1; + diskStructure->allow_deep_trees = 1; else if (CD9660_IS_COMMAND_ARG(var, "allow-max-name")) - diskStructure.allow_max_name = 1; + diskStructure->allow_max_name = 1; else if (CD9660_IS_COMMAND_ARG(var, "allow-illegal-chars")) - diskStructure.allow_illegal_chars = 1; + diskStructure->allow_illegal_chars = 1; else if (CD9660_IS_COMMAND_ARG(var, "allow-lowercase")) - diskStructure.allow_lowercase = 1; + diskStructure->allow_lowercase = 1; else if (CD9660_IS_COMMAND_ARG(var,"allow-multidot")) - diskStructure.allow_multidot = 1; + diskStructure->allow_multidot = 1; else if (CD9660_IS_COMMAND_ARG(var, "omit-trailing-period")) - diskStructure.omit_trailing_period = 1; + diskStructure->omit_trailing_period = 1; else if (CD9660_IS_COMMAND_ARG(var, "no-emul-boot") || CD9660_IS_COMMAND_ARG(var, "no-boot") || CD9660_IS_COMMAND_ARG(var, "hard-disk-boot")) { - cd9660_eltorito_add_boot_option(var, 0); + cd9660_eltorito_add_boot_option(diskStructure, var, 0); /* End of flag variables */ } else if (CD9660_IS_COMMAND_ARG(var, "boot-load-segment")) { @@ -419,7 +426,8 @@ warnx("Option `%s' doesn't contain a value", var); rv = 0; } else { - cd9660_eltorito_add_boot_option(var, val); + cd9660_eltorito_add_boot_option(diskStructure, var, + val); } } else { if (val == NULL) { @@ -452,19 +460,20 @@ int64_t totalSpace; int error; cd9660node *real_root; + iso9660_disk *diskStructure = fsopts->fs_specific; - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("cd9660_makefs: ISO level is %i\n", - diskStructure.isoLevel); - if (diskStructure.isoLevel < 2 && - diskStructure.allow_multidot) + diskStructure->isoLevel); + if (diskStructure->isoLevel < 2 && + diskStructure->allow_multidot) errx(1, "allow-multidot requires iso level of 2\n"); assert(image != NULL); assert(dir != NULL); assert(root != NULL); - if (diskStructure.displayHelp) { + if (diskStructure->displayHelp) { /* * Display help here - probably want to put it in * a separate function @@ -472,7 +481,7 @@ return; } - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("cd9660_makefs: image %s directory %s root %p\n", image, dir, root); @@ -496,11 +505,12 @@ ISO_FILENAME_MAXLENGTH_WITH_PADDING); real_root->level = 0; - diskStructure.rootNode = real_root; + diskStructure->rootNode = real_root; real_root->type = CD9660_TYPE_DIR; error = 0; real_root->node = root; - cd9660_convert_structure(root, real_root, 1, &numDirectories, &error); + cd9660_convert_structure(diskStructure, root, real_root, 1, + &numDirectories, &error); if (TAILQ_EMPTY(&real_root->cn_children)) { errx(1, "cd9660_makefs: converted directory is empty. " @@ -508,109 +518,111 @@ } else if (error != 0) { errx(1, "cd9660_makefs: tree conversion failed\n"); } else { - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("cd9660_makefs: tree converted\n"); } /* Add the dot and dot dot records */ - cd9660_add_dot_records(real_root); + cd9660_add_dot_records(diskStructure, real_root); - cd9660_setup_root_node(); + cd9660_setup_root_node(diskStructure); - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("cd9660_makefs: done converting tree\n"); /* non-SUSP extensions */ - if (diskStructure.archimedes_enabled) - archimedes_convert_tree(diskStructure.rootNode); + if (diskStructure->archimedes_enabled) + archimedes_convert_tree(diskStructure->rootNode); /* Rock ridge / SUSP init pass */ - if (diskStructure.rock_ridge_enabled) { - cd9660_susp_initialize(diskStructure.rootNode, - diskStructure.rootNode, NULL); + if (diskStructure->rock_ridge_enabled) { + cd9660_susp_initialize(diskStructure, diskStructure->rootNode, + diskStructure->rootNode, NULL); } /* Build path table structure */ - diskStructure.pathTableLength = cd9660_generate_path_table(); + diskStructure->pathTableLength = cd9660_generate_path_table( + diskStructure); - pathTableSectors = CD9660_BLOCKS(diskStructure.sectorSize, - diskStructure.pathTableLength); + pathTableSectors = CD9660_BLOCKS(diskStructure->sectorSize, + diskStructure->pathTableLength); - firstAvailableSector = cd9660_setup_volume_descriptors(); - if (diskStructure.is_bootable) { - firstAvailableSector = cd9660_setup_boot(firstAvailableSector); + firstAvailableSector = cd9660_setup_volume_descriptors(diskStructure); + if (diskStructure->is_bootable) { + firstAvailableSector = cd9660_setup_boot(diskStructure, + firstAvailableSector); if (firstAvailableSector < 0) errx(1, "setup_boot failed"); } /* LE first, then BE */ - diskStructure.primaryLittleEndianTableSector = firstAvailableSector; - diskStructure.primaryBigEndianTableSector = - diskStructure.primaryLittleEndianTableSector + pathTableSectors; + diskStructure->primaryLittleEndianTableSector = firstAvailableSector; + diskStructure->primaryBigEndianTableSector = + diskStructure->primaryLittleEndianTableSector + pathTableSectors; /* Set the secondary ones to -1, not going to use them for now */ - diskStructure.secondaryBigEndianTableSector = -1; - diskStructure.secondaryLittleEndianTableSector = -1; + diskStructure->secondaryBigEndianTableSector = -1; + diskStructure->secondaryLittleEndianTableSector = -1; - diskStructure.dataFirstSector = - diskStructure.primaryBigEndianTableSector + pathTableSectors; - if (diskStructure.verbose_level > 0) + diskStructure->dataFirstSector = + diskStructure->primaryBigEndianTableSector + pathTableSectors; + if (diskStructure->verbose_level > 0) printf("cd9660_makefs: Path table conversion complete. " "Each table is %i bytes, or %" PRIu64 " sectors.\n", - diskStructure.pathTableLength, pathTableSectors); + diskStructure->pathTableLength, pathTableSectors); - startoffset = diskStructure.sectorSize*diskStructure.dataFirstSector; + startoffset = diskStructure->sectorSize*diskStructure->dataFirstSector; - totalSpace = cd9660_compute_offsets(real_root, startoffset); + totalSpace = cd9660_compute_offsets(diskStructure, real_root, startoffset); - diskStructure.totalSectors = diskStructure.dataFirstSector + - CD9660_BLOCKS(diskStructure.sectorSize, totalSpace); + diskStructure->totalSectors = diskStructure->dataFirstSector + + CD9660_BLOCKS(diskStructure->sectorSize, totalSpace); /* Disabled until pass 1 is done */ - if (diskStructure.rock_ridge_enabled) { - diskStructure.susp_continuation_area_start_sector = - diskStructure.totalSectors; - diskStructure.totalSectors += - CD9660_BLOCKS(diskStructure.sectorSize, - diskStructure.susp_continuation_area_size); - cd9660_susp_finalize(diskStructure.rootNode); + if (diskStructure->rock_ridge_enabled) { + diskStructure->susp_continuation_area_start_sector = + diskStructure->totalSectors; + diskStructure->totalSectors += + CD9660_BLOCKS(diskStructure->sectorSize, + diskStructure->susp_continuation_area_size); + cd9660_susp_finalize(diskStructure, diskStructure->rootNode); } - cd9660_finalize_PVD(); + cd9660_finalize_PVD(diskStructure); /* Add padding sectors, just for testing purposes right now */ - /* diskStructure.totalSectors+=150; */ + /* diskStructure->totalSectors+=150; */ /* Debugging output */ - if (diskStructure.verbose_level > 0) { + if (diskStructure->verbose_level > 0) { printf("cd9660_makefs: Sectors 0-15 reserved\n"); printf("cd9660_makefs: Primary path tables starts in sector %" - PRId64 "\n", diskStructure.primaryLittleEndianTableSector); + PRId64 "\n", diskStructure->primaryLittleEndianTableSector); printf("cd9660_makefs: File data starts in sector %" - PRId64 "\n", diskStructure.dataFirstSector); + PRId64 "\n", diskStructure->dataFirstSector); printf("cd9660_makefs: Total sectors: %" - PRId64 "\n", diskStructure.totalSectors); + PRId64 "\n", diskStructure->totalSectors); } /* * Add padding sectors at the end * TODO: Clean this up and separate padding */ - if (diskStructure.include_padding_areas) - diskStructure.totalSectors += 150; + if (diskStructure->include_padding_areas) + diskStructure->totalSectors += 150; - cd9660_write_image(image); + cd9660_write_image(diskStructure, image); - if (diskStructure.verbose_level > 1) { - debug_print_volume_descriptor_information(); - debug_print_tree(real_root,0); + if (diskStructure->verbose_level > 1) { + debug_print_volume_descriptor_information(diskStructure); + debug_print_tree(diskStructure, real_root, 0); debug_print_path_tree(real_root); } /* Clean up data structures */ cd9660_free_structure(real_root); - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("cd9660_makefs: done\n"); } @@ -618,76 +630,77 @@ typedef int (*cd9660node_func)(cd9660node *); static void -cd9660_finalize_PVD(void) +cd9660_finalize_PVD(iso9660_disk *diskStructure) { time_t tstamp = stampst.st_ino ? stampst.st_mtime : time(NULL); /* root should be a fixed size of 34 bytes since it has no name */ - memcpy(diskStructure.primaryDescriptor.root_directory_record, - diskStructure.rootNode->dot_record->isoDirRecord, 34); + memcpy(diskStructure->primaryDescriptor.root_directory_record, + diskStructure->rootNode->dot_record->isoDirRecord, 34); /* In RRIP, this might be longer than 34 */ - diskStructure.primaryDescriptor.root_directory_record[0] = 34; + diskStructure->primaryDescriptor.root_directory_record[0] = 34; /* Set up all the important numbers in the PVD */ - cd9660_bothendian_dword(diskStructure.totalSectors, - (unsigned char *)diskStructure.primaryDescriptor.volume_space_size); + cd9660_bothendian_dword(diskStructure->totalSectors, + (unsigned char *)diskStructure->primaryDescriptor.volume_space_size); cd9660_bothendian_word(1, - (unsigned char *)diskStructure.primaryDescriptor.volume_set_size); + (unsigned char *)diskStructure->primaryDescriptor.volume_set_size); cd9660_bothendian_word(1, (unsigned char *) - diskStructure.primaryDescriptor.volume_sequence_number); - cd9660_bothendian_word(diskStructure.sectorSize, + diskStructure->primaryDescriptor.volume_sequence_number); + cd9660_bothendian_word(diskStructure->sectorSize, (unsigned char *) - diskStructure.primaryDescriptor.logical_block_size); - cd9660_bothendian_dword(diskStructure.pathTableLength, - (unsigned char *)diskStructure.primaryDescriptor.path_table_size); - - cd9660_731(diskStructure.primaryLittleEndianTableSector, - (u_char *)diskStructure.primaryDescriptor.type_l_path_table); - cd9660_732(diskStructure.primaryBigEndianTableSector, - (u_char *)diskStructure.primaryDescriptor.type_m_path_table); + diskStructure->primaryDescriptor.logical_block_size); + cd9660_bothendian_dword(diskStructure->pathTableLength, + (unsigned char *)diskStructure->primaryDescriptor.path_table_size); + + cd9660_731(diskStructure->primaryLittleEndianTableSector, + (u_char *)diskStructure->primaryDescriptor.type_l_path_table); + cd9660_732(diskStructure->primaryBigEndianTableSector, + (u_char *)diskStructure->primaryDescriptor.type_m_path_table); - diskStructure.primaryDescriptor.file_structure_version[0] = 1; + diskStructure->primaryDescriptor.file_structure_version[0] = 1; /* Pad all strings with spaces instead of nulls */ - cd9660_pad_string_spaces(diskStructure.primaryDescriptor.volume_id, 32); - cd9660_pad_string_spaces(diskStructure.primaryDescriptor.system_id, 32); - cd9660_pad_string_spaces(diskStructure.primaryDescriptor.volume_set_id, + cd9660_pad_string_spaces(diskStructure->primaryDescriptor.volume_id, 32); + cd9660_pad_string_spaces(diskStructure->primaryDescriptor.system_id, 32); + cd9660_pad_string_spaces(diskStructure->primaryDescriptor.volume_set_id, 128); - cd9660_pad_string_spaces(diskStructure.primaryDescriptor.publisher_id, + cd9660_pad_string_spaces(diskStructure->primaryDescriptor.publisher_id, 128); - cd9660_pad_string_spaces(diskStructure.primaryDescriptor.preparer_id, + cd9660_pad_string_spaces(diskStructure->primaryDescriptor.preparer_id, 128); - cd9660_pad_string_spaces(diskStructure.primaryDescriptor.application_id, + cd9660_pad_string_spaces(diskStructure->primaryDescriptor.application_id, 128); cd9660_pad_string_spaces( - diskStructure.primaryDescriptor.copyright_file_id, 37); + diskStructure->primaryDescriptor.copyright_file_id, 37); cd9660_pad_string_spaces( - diskStructure.primaryDescriptor.abstract_file_id, 37); + diskStructure->primaryDescriptor.abstract_file_id, 37); cd9660_pad_string_spaces( - diskStructure.primaryDescriptor.bibliographic_file_id, 37); + diskStructure->primaryDescriptor.bibliographic_file_id, 37); /* Setup dates */ cd9660_time_8426( - (unsigned char *)diskStructure.primaryDescriptor.creation_date, + (unsigned char *)diskStructure->primaryDescriptor.creation_date, tstamp); cd9660_time_8426( - (unsigned char *)diskStructure.primaryDescriptor.modification_date, + (unsigned char *)diskStructure->primaryDescriptor.modification_date, tstamp); #if 0 - cd9660_set_date(diskStructure.primaryDescriptor.expiration_date, + cd9660_set_date(diskStructure->primaryDescriptor.expiration_date, tstamp); #endif - memset(diskStructure.primaryDescriptor.expiration_date, '0', 16); - diskStructure.primaryDescriptor.expiration_date[16] = 0; + memset(diskStructure->primaryDescriptor.expiration_date, '0', 16); + diskStructure->primaryDescriptor.expiration_date[16] = 0; + cd9660_time_8426( - (unsigned char *)diskStructure.primaryDescriptor.effective_date, + (unsigned char *)diskStructure->primaryDescriptor.effective_date, tstamp); /* make this sane */ - cd9660_time_915(diskStructure.rootNode->dot_record->isoDirRecord->date, + cd9660_time_915(diskStructure->rootNode->dot_record->isoDirRecord->date, tstamp); } @@ -711,16 +724,16 @@ } static void -cd9660_setup_root_node(void) +cd9660_setup_root_node(iso9660_disk *diskStructure) { - cd9660_populate_iso_dir_record(diskStructure.rootNode->isoDirRecord, + cd9660_populate_iso_dir_record(diskStructure->rootNode->isoDirRecord, 0, ISO_FLAG_DIRECTORY, 1, "\0"); } /*********** SUPPORT FUNCTIONS ***********/ static int -cd9660_setup_volume_descriptors(void) +cd9660_setup_volume_descriptors(iso9660_disk *diskStructure) { /* Boot volume descriptor should come second */ int sector = 16; @@ -734,17 +747,17 @@ } temp->volumeDescriptorData = - (unsigned char *)&diskStructure.primaryDescriptor; + (unsigned char *)&diskStructure->primaryDescriptor; temp->volumeDescriptorData[0] = ISO_VOLUME_DESCRIPTOR_PVD; temp->volumeDescriptorData[6] = 1; temp->sector = sector; memcpy(temp->volumeDescriptorData + 1, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); - diskStructure.firstVolumeDescriptor = temp; + diskStructure->firstVolumeDescriptor = temp; sector++; /* Set up boot support if enabled. BVD must reside in sector 17 */ - if (diskStructure.is_bootable) { + if (diskStructure->is_bootable) { if ((t = malloc(sizeof(volume_descriptor))) == NULL) { CD9660_MEM_ALLOC_ERROR( "cd9660_setup_volume_descriptors"); @@ -759,9 +772,9 @@ temp = t; memset(t->volumeDescriptorData, 0, 2048); t->sector = 17; - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Setting up boot volume descriptor\n"); - cd9660_setup_boot_volume_descriptor(t); + cd9660_setup_boot_volume_descriptor(diskStructure, t); sector++; } @@ -807,7 +820,7 @@ #endif static int -cd9660_translate_node_common(cd9660node *newnode) +cd9660_translate_node_common(iso9660_disk *diskStructure, cd9660node *newnode) { time_t tstamp = stampst.st_ino ? stampst.st_mtime : time(NULL); int test; @@ -817,7 +830,7 @@ /* Now populate the isoDirRecord structure */ memset(temp, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING); - test = cd9660_convert_filename(newnode->node->name, + test = cd9660_convert_filename(diskStructure, newnode->node->name, temp, !(S_ISDIR(newnode->node->type))); flag = ISO_FLAG_CLEAR; @@ -851,10 +864,11 @@ * @returns int 0 on failure, 1 on success */ static int -cd9660_translate_node(fsnode *node, cd9660node *newnode) +cd9660_translate_node(iso9660_disk *diskStructure, fsnode *node, + cd9660node *newnode) { if (node == NULL) { - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("cd9660_translate_node: NULL node passed, " "returning\n"); return 0; @@ -872,7 +886,7 @@ if (!(S_ISDIR(node->type))) newnode->fileDataLength = node->inode->st.st_size; - if (cd9660_translate_node_common(newnode) == 0) + if (cd9660_translate_node_common(diskStructure, newnode) == 0) return 0; /* Finally, overwrite some of the values that are set by default */ @@ -1006,7 +1020,8 @@ * where n represents the files respective place in the ordering */ static int -cd9660_handle_collisions(cd9660node *colliding, int past) +cd9660_handle_collisions(iso9660_disk *diskStructure, cd9660node *colliding, + int past) { cd9660node *iter, *next, *prev; int skip; @@ -1041,14 +1056,16 @@ temp_past--; } skip += past; - iter = cd9660_rename_filename(iter, skip, delete_chars); + iter = cd9660_rename_filename(diskStructure, iter, skip, + delete_chars); } return flag; } static cd9660node * -cd9660_rename_filename(cd9660node *iter, int num, int delete_chars) +cd9660_rename_filename(iso9660_disk *diskStructure, cd9660node *iter, int num, + int delete_chars) { int i = 0; int numbts, digit, digits, temp, powers, count; @@ -1056,14 +1073,14 @@ int maxlength; char *tmp; - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Rename_filename called\n"); - assert(1 <= diskStructure.isoLevel && diskStructure.isoLevel <= 2); + assert(1 <= diskStructure->isoLevel && diskStructure->isoLevel <= 2); /* TODO : A LOT of chanes regarding 8.3 filenames */ - if (diskStructure.isoLevel == 1) + if (diskStructure->isoLevel == 1) maxlength = 8; - else if (diskStructure.isoLevel == 2) + else if (diskStructure->isoLevel == 2) maxlength = 31; else maxlength = ISO_FILENAME_MAXLENGTH_BEFORE_VERSION; @@ -1109,7 +1126,7 @@ */ /* - if (diskStructure.isoLevel == 1) { + if (diskStructure->isoLevel == 1) { numbts = 8 - digits - delete_chars; if (dot < 0) { @@ -1161,7 +1178,7 @@ /* Todo: Figure out why these functions are nec. */ static void -cd9660_copy_filenames(cd9660node *node) +cd9660_copy_filenames(iso9660_disk *diskStructure, cd9660node *node) { cd9660node *cn; @@ -1169,12 +1186,12 @@ return; if (TAILQ_FIRST(&node->cn_children)->isoDirRecord == NULL) { - debug_print_tree(diskStructure.rootNode, 0); + debug_print_tree(diskStructure, diskStructure->rootNode, 0); exit(1); } TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) { - cd9660_copy_filenames(cn); + cd9660_copy_filenames(diskStructure, cn); memcpy(cn->o_name, cn->isoDirRecord->name, ISO_FILENAME_MAXLENGTH_WITH_PADDING); } @@ -1241,7 +1258,7 @@ } static cd9660node * -cd9660_rrip_move_directory(cd9660node *dir) +cd9660_rrip_move_directory(iso9660_disk *diskStructure, cd9660node *dir) { char newname[9]; cd9660node *tfile; @@ -1252,28 +1269,29 @@ * 2) Point the virtual file to the new directory * 3) Point the relocated directory to its old parent * 4) Move the directory specified by dir into rr_moved_dir, - * and rename it to "diskStructure.rock_ridge_move_count" (as a string) + * and rename it to "diskStructure->rock_ridge_move_count" (as a string) */ /* First see if the moved directory even exists */ - if (diskStructure.rr_moved_dir == NULL) { - diskStructure.rr_moved_dir = - cd9660_create_directory(ISO_RRIP_DEFAULT_MOVE_DIR_NAME, - diskStructure.rootNode, dir); - if (diskStructure.rr_moved_dir == NULL) + if (diskStructure->rr_moved_dir == NULL) { + diskStructure->rr_moved_dir = cd9660_create_directory( + diskStructure, ISO_RRIP_DEFAULT_MOVE_DIR_NAME, + diskStructure->rootNode, dir); + if (diskStructure->rr_moved_dir == NULL) return 0; - cd9660_time_915(diskStructure.rr_moved_dir->isoDirRecord->date, + cd9660_time_915(diskStructure->rr_moved_dir->isoDirRecord->date, stampst.st_ino ? stampst.st_mtime : start_time.tv_sec); } /* Create a file with the same ORIGINAL name */ - tfile = cd9660_create_file(dir->node->name, dir->parent, dir); + tfile = cd9660_create_file(diskStructure, dir->node->name, dir->parent, + dir); if (tfile == NULL) return NULL; - diskStructure.rock_ridge_move_count++; + diskStructure->rock_ridge_move_count++; snprintf(newname, sizeof(newname), "%08i", - diskStructure.rock_ridge_move_count); + diskStructure->rock_ridge_move_count); /* Point to old parent */ dir->rr_real_parent = dir->parent; @@ -1287,13 +1305,13 @@ } /* Point to new parent */ - dir->parent = diskStructure.rr_moved_dir; + dir->parent = diskStructure->rr_moved_dir; /* Point the file to the moved directory */ tfile->rr_relocated = dir; /* Actually move the directory */ - cd9660_sorted_child_insert(diskStructure.rr_moved_dir, dir); + cd9660_sorted_child_insert(diskStructure->rr_moved_dir, dir); /* TODO: Inherit permissions / ownership (basically the entire inode) */ @@ -1307,7 +1325,7 @@ } static int -cd9660_add_dot_records(cd9660node *root) +cd9660_add_dot_records(iso9660_disk *diskStructure, cd9660node *root) { struct cd9660_children_head *head = &root->cn_children; cd9660node *cn; @@ -1316,10 +1334,11 @@ if ((cn->type & CD9660_TYPE_DIR) == 0) continue; /* Recursion first */ - cd9660_add_dot_records(cn); + cd9660_add_dot_records(diskStructure, cn); } - cd9660_create_special_directory(CD9660_TYPE_DOT, root); - cd9660_create_special_directory(CD9660_TYPE_DOTDOT, root); + cd9660_create_special_directory(diskStructure, CD9660_TYPE_DOT, root); + cd9660_create_special_directory(diskStructure, CD9660_TYPE_DOTDOT, + root); return 1; } @@ -1334,8 +1353,8 @@ * @param int* Running count of the number of directories that are being created */ static void -cd9660_convert_structure(fsnode *root, cd9660node *parent_node, int level, - int *numDirectories, int *error) +cd9660_convert_structure(iso9660_disk *diskStructure, fsnode *root, + cd9660node *parent_node, int level, int *numDirectories, int *error) { fsnode *iterator = root; cd9660node *this_node; @@ -1378,7 +1397,8 @@ /* Translate the node, including its filename */ this_node->parent = parent_node; - cd9660_translate_node(iterator, this_node); + cd9660_translate_node(diskStructure, iterator, + this_node); this_node->level = level; if (S_ISDIR(iterator->type)) { @@ -1392,14 +1412,14 @@ * allowed as per ISO spec */ if (level == 8) { - if ((!diskStructure.allow_deep_trees) && - (!diskStructure.rock_ridge_enabled)) { + if ((!diskStructure->allow_deep_trees) && + (!diskStructure->rock_ridge_enabled)) { warnx("error: found entry " "with depth greater " "than 8."); (*error) = 1; return; - } else if (diskStructure. + } else if (diskStructure-> rock_ridge_enabled) { working_level = 3; /* @@ -1409,6 +1429,7 @@ this_node->level = working_level - 1; if (cd9660_rrip_move_directory( + diskStructure, this_node) == NULL) { warnx("Failure in " "cd9660_rrip_" @@ -1423,8 +1444,8 @@ /* Do the recursive call on the children */ if (iterator->child != NULL) { - cd9660_convert_structure( - iterator->child, this_node, + cd9660_convert_structure(diskStructure, + iterator->child, this_node, working_level, numDirectories, error); @@ -1463,10 +1484,11 @@ /* cd9660_handle_collisions(first_node); */ /* TODO: need cleanup */ - cd9660_copy_filenames(parent_node); + cd9660_copy_filenames(diskStructure, parent_node); do { - flag = cd9660_handle_collisions(parent_node, counter); + flag = cd9660_handle_collisions(diskStructure, parent_node, + counter); counter++; cd9660_sorting_nodes(parent_node); } while ((flag == 1) && (counter < 100)); @@ -1517,9 +1539,9 @@ * @returns int The number of built path tables (between 1 and 4), 0 on failure */ static int -cd9660_generate_path_table(void) +cd9660_generate_path_table(iso9660_disk *diskStructure) { - cd9660node *cn, *dirNode = diskStructure.rootNode; + cd9660node *cn, *dirNode = diskStructure->rootNode; cd9660node *last = dirNode; int pathTableSize = 0; /* computed as we go */ int counter = 1; /* root gets a count of 0 */ @@ -1527,7 +1549,7 @@ TAILQ_HEAD(cd9660_pt_head, ptq_entry) pt_head; TAILQ_INIT(&pt_head); - PTQUEUE_NEW(n, ptq_entry, -1, diskStructure.rootNode); + PTQUEUE_NEW(n, ptq_entry, -1, diskStructure->rootNode); /* Push the root node */ TAILQ_INSERT_HEAD(&pt_head, n, ptq); @@ -1585,7 +1607,8 @@ } /* NEW filename conversion method */ -typedef int(*cd9660_filename_conversion_functor)(const char *, char *, int); +typedef int(*cd9660_filename_conversion_functor)(iso9660_disk *, const char *, + char *, int); /* @@ -1595,7 +1618,8 @@ * XXX bounds checking! */ static int -cd9660_level1_convert_filename(const char *oldname, char *newname, int is_file) +cd9660_level1_convert_filename(iso9660_disk *diskStructure, const char *oldname, + char *newname, int is_file) { /* * ISO 9660 : 10.1 @@ -1620,7 +1644,7 @@ } } else { /* cut RISC OS file type off ISO name */ - if (diskStructure.archimedes_enabled && + if (diskStructure->archimedes_enabled && *oldname == ',' && strlen(oldname) == 4) break; @@ -1644,7 +1668,7 @@ oldname++; } if (is_file) { - if (!found_ext && !diskStructure.omit_trailing_period) + if (!found_ext && !diskStructure->omit_trailing_period) *newname++ = '.'; /* Add version */ sprintf(newname, ";%i", 1); @@ -1654,7 +1678,8 @@ /* XXX bounds checking! */ static int -cd9660_level2_convert_filename(const char *oldname, char *newname, int is_file) +cd9660_level2_convert_filename(iso9660_disk *diskStructure, const char *oldname, + char *newname, int is_file) { /* * ISO 9660 : 7.5.1 @@ -1673,7 +1698,7 @@ /* Handle period first, as it is special */ if (*oldname == '.') { if (found_ext) { - if (diskStructure.allow_multidot) { + if (diskStructure->allow_multidot) { *newname++ = '.'; } else { *newname++ = '_'; @@ -1686,7 +1711,7 @@ } } else { /* cut RISC OS file type off ISO name */ - if (diskStructure.archimedes_enabled && + if (diskStructure->archimedes_enabled && *oldname == ',' && strlen(oldname) == 4) break; @@ -1695,7 +1720,7 @@ else if (isupper((unsigned char)*oldname) || isdigit((unsigned char)*oldname)) *newname++ = *oldname; - else if (diskStructure.allow_multidot && + else if (diskStructure->allow_multidot && *oldname == '.') { *newname++ = '.'; } else { @@ -1710,7 +1735,7 @@ oldname ++; } if (is_file) { - if (!found_ext && !diskStructure.omit_trailing_period) + if (!found_ext && !diskStructure->omit_trailing_period) *newname++ = '.'; /* Add version */ sprintf(newname, ";%i", 1); @@ -1720,7 +1745,8 @@ #if 0 static int -cd9660_joliet_convert_filename(const char *oldname, char *newname, int is_file) +cd9660_joliet_convert_filename(iso9660_disk *diskStructure, const char *oldname, + char *newname, int is_file) { /* TODO: implement later, move to cd9660_joliet.c ?? */ } @@ -1736,24 +1762,25 @@ * @returns int The length of the new string */ static int -cd9660_convert_filename(const char *oldname, char *newname, int is_file) +cd9660_convert_filename(iso9660_disk *diskStructure, const char *oldname, + char *newname, int is_file) { - assert(1 <= diskStructure.isoLevel && diskStructure.isoLevel <= 2); + assert(1 <= diskStructure->isoLevel && diskStructure->isoLevel <= 2); /* NEW */ cd9660_filename_conversion_functor conversion_function = NULL; - if (diskStructure.isoLevel == 1) + if (diskStructure->isoLevel == 1) conversion_function = &cd9660_level1_convert_filename; - else if (diskStructure.isoLevel == 2) + else if (diskStructure->isoLevel == 2) conversion_function = &cd9660_level2_convert_filename; - return (*conversion_function)(oldname, newname, is_file); + return (*conversion_function)(diskStructure, oldname, newname, is_file); } int -cd9660_compute_record_size(cd9660node *node) +cd9660_compute_record_size(iso9660_disk *diskStructure, cd9660node *node) { int size = node->isoDirRecord->length[0]; - if (diskStructure.rock_ridge_enabled) + if (diskStructure->rock_ridge_enabled) size += node->susp_entry_size; size += node->su_tail_size; size += size & 1; /* Ensure length of record is even. */ @@ -1762,7 +1789,7 @@ } static void -cd9660_populate_dot_records(cd9660node *node) +cd9660_populate_dot_records(iso9660_disk *diskStructure, cd9660node *node) { node->dot_record->fileDataSector = node->fileDataSector; memcpy(node->dot_record->isoDirRecord,node->isoDirRecord, 34); @@ -1771,9 +1798,9 @@ node->dot_record->isoDirRecord->name[1] = 0; node->dot_record->isoDirRecord->length[0] = 34; node->dot_record->fileRecordSize = - cd9660_compute_record_size(node->dot_record); + cd9660_compute_record_size(diskStructure, node->dot_record); - if (node == diskStructure.rootNode) { + if (node == diskStructure->rootNode) { node->dot_dot_record->fileDataSector = node->fileDataSector; memcpy(node->dot_dot_record->isoDirRecord,node->isoDirRecord, 34); @@ -1788,7 +1815,7 @@ node->dot_dot_record->isoDirRecord->name[1] = 0; node->dot_dot_record->isoDirRecord->length[0] = 34; node->dot_dot_record->fileRecordSize = - cd9660_compute_record_size(node->dot_dot_record); + cd9660_compute_record_size(diskStructure, node->dot_dot_record); } /* @@ -1798,7 +1825,8 @@ * a multiple of sector size) */ static int64_t -cd9660_compute_offsets(cd9660node *node, int64_t startOffset) +cd9660_compute_offsets(iso9660_disk *diskStructure, cd9660node *node, + int64_t startOffset) { /* * This function needs to compute the size of directory records and @@ -1822,10 +1850,11 @@ node->fileDataSector = -1; if (node->type & CD9660_TYPE_DIR) { - node->fileRecordSize = cd9660_compute_record_size(node); + node->fileRecordSize = cd9660_compute_record_size( + diskStructure, node); /*Set what sector this directory starts in*/ node->fileDataSector = - CD9660_BLOCKS(diskStructure.sectorSize,startOffset); + CD9660_BLOCKS(diskStructure->sectorSize,startOffset); cd9660_bothendian_dword(node->fileDataSector, node->isoDirRecord->extent); @@ -1837,32 +1866,32 @@ node->fileSectorsUsed = 1; TAILQ_FOREACH(child, &node->cn_children, cn_next_child) { node->fileDataLength += - cd9660_compute_record_size(child); - if ((cd9660_compute_record_size(child) + + cd9660_compute_record_size(diskStructure, child); + if ((cd9660_compute_record_size(diskStructure, child) + current_sector_usage) >= - diskStructure.sectorSize) { + diskStructure->sectorSize) { current_sector_usage = 0; node->fileSectorsUsed++; } current_sector_usage += - cd9660_compute_record_size(child); + cd9660_compute_record_size(diskStructure, child); } cd9660_bothendian_dword(node->fileSectorsUsed * - diskStructure.sectorSize,node->isoDirRecord->size); + diskStructure->sectorSize,node->isoDirRecord->size); /* * This should point to the sector after the directory * record (or, the first byte in that sector) */ - used_bytes += node->fileSectorsUsed * diskStructure.sectorSize; + used_bytes += node->fileSectorsUsed * diskStructure->sectorSize; for (child = TAILQ_NEXT(node->dot_dot_record, cn_next_child); child != NULL; child = TAILQ_NEXT(child, cn_next_child)) { /* Directories need recursive call */ if (S_ISDIR(child->node->type)) { - r = cd9660_compute_offsets(child, + r = cd9660_compute_offsets(diskStructure, child, used_bytes + startOffset); if (r != -1) @@ -1873,7 +1902,7 @@ } /* Explicitly set the . and .. records */ - cd9660_populate_dot_records(node); + cd9660_populate_dot_records(diskStructure, node); /* Finally, do another iteration to write the file data*/ for (child = TAILQ_NEXT(node->dot_dot_record, cn_next_child); @@ -1883,20 +1912,20 @@ if (S_ISDIR(child->node->type)) continue; child->fileRecordSize = - cd9660_compute_record_size(child); + cd9660_compute_record_size(diskStructure, child); child->fileSectorsUsed = - CD9660_BLOCKS(diskStructure.sectorSize, + CD9660_BLOCKS(diskStructure->sectorSize, child->fileDataLength); inode = child->node->inode; if ((inode->flags & FI_ALLOCATED) == 0) { inode->ino = - CD9660_BLOCKS(diskStructure.sectorSize, + CD9660_BLOCKS(diskStructure->sectorSize, used_bytes + startOffset); inode->flags |= FI_ALLOCATED; used_bytes += child->fileSectorsUsed * - diskStructure.sectorSize; + diskStructure->sectorSize; } else { INODE_WARNX(("%s: already allocated inode %d " "data sectors at %" PRIu32, __func__, @@ -1937,8 +1966,8 @@ #endif static cd9660node * -cd9660_create_virtual_entry(const char *name, cd9660node *parent, int file, - int insert) +cd9660_create_virtual_entry(iso9660_disk *diskStructure, const char *name, + cd9660node *parent, int file, int insert) { cd9660node *temp; fsnode * tfsnode; @@ -1968,7 +1997,8 @@ strcpy(tfsnode->name, name); - cd9660_convert_filename(tfsnode->name, temp->isoDirRecord->name, file); + cd9660_convert_filename(diskStructure, tfsnode->name, + temp->isoDirRecord->name, file); temp->node = tfsnode; temp->parent = parent; @@ -2004,11 +2034,12 @@ } static cd9660node * -cd9660_create_file(const char * name, cd9660node *parent, cd9660node *me) +cd9660_create_file(iso9660_disk *diskStructure, const char *name, + cd9660node *parent, cd9660node *me) { cd9660node *temp; - temp = cd9660_create_virtual_entry(name,parent,1,1); + temp = cd9660_create_virtual_entry(diskStructure, name, parent, 1, 1); if (temp == NULL) return NULL; @@ -2020,7 +2051,7 @@ return NULL; *temp->node->inode = *me->node->inode; - if (cd9660_translate_node_common(temp) == 0) + if (cd9660_translate_node_common(diskStructure, temp) == 0) return NULL; return temp; } @@ -2032,11 +2063,12 @@ * @returns cd9660node * Pointer to the new directory */ static cd9660node * -cd9660_create_directory(const char *name, cd9660node *parent, cd9660node *me) +cd9660_create_directory(iso9660_disk *diskStructure, const char *name, + cd9660node *parent, cd9660node *me) { cd9660node *temp; - temp = cd9660_create_virtual_entry(name,parent,0,1); + temp = cd9660_create_virtual_entry(diskStructure, name, parent, 0, 1); if (temp == NULL) return NULL; temp->node->type |= S_IFDIR; @@ -2047,13 +2079,14 @@ return NULL; *temp->node->inode = *me->node->inode; - if (cd9660_translate_node_common(temp) == 0) + if (cd9660_translate_node_common(diskStructure, temp) == 0) return NULL; return temp; } static cd9660node * -cd9660_create_special_directory(u_char type, cd9660node *parent) +cd9660_create_special_directory(iso9660_disk *diskStructure, u_char type, + cd9660node *parent) { cd9660node *temp, *first; char na[2]; @@ -2068,7 +2101,8 @@ return 0; na[1] = 0; - if ((temp = cd9660_create_virtual_entry(na, parent, 0, 0)) == NULL) + if ((temp = cd9660_create_virtual_entry(diskStructure, na, parent, + 0, 0)) == NULL) return NULL; temp->parent = parent; @@ -2099,7 +2133,7 @@ } int -cd9660_add_generic_bootimage(const char *bootimage) +cd9660_add_generic_bootimage(iso9660_disk *diskStructure, const char *bootimage) { struct stat stbuf; @@ -2110,27 +2144,27 @@ return 0; } - if ((diskStructure.generic_bootimage = strdup(bootimage)) == NULL) { + if ((diskStructure->generic_bootimage = strdup(bootimage)) == NULL) { warn("%s: strdup", __func__); return 0; } /* Get information about the file */ - if (lstat(diskStructure.generic_bootimage, &stbuf) == -1) + if (lstat(diskStructure->generic_bootimage, &stbuf) == -1) err(EXIT_FAILURE, "%s: lstat(\"%s\")", __func__, - diskStructure.generic_bootimage); + diskStructure->generic_bootimage); if (stbuf.st_size > 32768) { warnx("Error: Boot image must be no greater than 32768 bytes"); return 0; } - if (diskStructure.verbose_level > 0) { + if (diskStructure->verbose_level > 0) { printf("Generic boot image image has size %lld\n", (long long)stbuf.st_size); } - diskStructure.has_generic_bootimage = 1; + diskStructure->has_generic_bootimage = 1; return 1; } Index: head/usr.sbin/makefs/cd9660/cd9660_debug.c =================================================================== --- head/usr.sbin/makefs/cd9660/cd9660_debug.c +++ head/usr.sbin/makefs/cd9660/cd9660_debug.c @@ -83,7 +83,7 @@ } void -debug_print_tree(cd9660node *node, int level) +debug_print_tree(iso9660_disk *diskStructure, cd9660node *node, int level) { #if !HAVE_NBTOOL_CONFIG_H cd9660node *cn; @@ -111,10 +111,10 @@ node->fileDataSector + node->fileSectorsUsed - 1); } - if (diskStructure.rock_ridge_enabled) + if (diskStructure->rock_ridge_enabled) debug_print_susp_attrs(node, level + 1); TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) - debug_print_tree(cn, level + 1); + debug_print_tree(diskStructure, cn, level + 1); #else printf("Sorry, debugging is not supported in host-tools mode.\n"); #endif @@ -141,9 +141,9 @@ } void -debug_print_volume_descriptor_information(void) +debug_print_volume_descriptor_information(iso9660_disk *diskStructure) { - volume_descriptor *tmp = diskStructure.firstVolumeDescriptor; + volume_descriptor *tmp = diskStructure->firstVolumeDescriptor; char temp[CD9660_SECTOR_SIZE]; printf("==Listing Volume Descriptors==\n"); Index: head/usr.sbin/makefs/cd9660/cd9660_eltorito.c =================================================================== --- head/usr.sbin/makefs/cd9660/cd9660_eltorito.c +++ head/usr.sbin/makefs/cd9660/cd9660_eltorito.c @@ -55,7 +55,7 @@ #endif int -cd9660_add_boot_disk(const char *boot_info) +cd9660_add_boot_disk(iso9660_disk *diskStructure, const char *boot_info) { struct stat stbuf; const char *mode_msg; @@ -89,7 +89,7 @@ *filename++ = '\0'; - if (diskStructure.verbose_level > 0) { + if (diskStructure->verbose_level > 0) { printf("Found bootdisk with system %s, and filename %s\n", sysname, filename); } @@ -151,14 +151,14 @@ break; } - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("%s\n", mode_msg); new_image->size = stbuf.st_size; new_image->num_sectors = - howmany(new_image->size, diskStructure.sectorSize) * - howmany(diskStructure.sectorSize, 512); - if (diskStructure.verbose_level > 0) { + howmany(new_image->size, diskStructure->sectorSize) * + howmany(diskStructure->sectorSize, 512); + if (diskStructure->verbose_level > 0) { printf("New image has size %d, uses %d 512-byte sectors\n", new_image->size, new_image->num_sectors); } @@ -168,27 +168,28 @@ /* Add boot disk */ /* Group images for the same platform together. */ - TAILQ_FOREACH(tmp_image, &diskStructure.boot_images, image_list) { + TAILQ_FOREACH(tmp_image, &diskStructure->boot_images, image_list) { if (tmp_image->system != new_image->system) break; } if (tmp_image == NULL) { - TAILQ_INSERT_HEAD(&diskStructure.boot_images, new_image, + TAILQ_INSERT_HEAD(&diskStructure->boot_images, new_image, image_list); } else TAILQ_INSERT_BEFORE(tmp_image, new_image, image_list); - new_image->serialno = diskStructure.image_serialno++; + new_image->serialno = diskStructure->image_serialno++; /* TODO : Need to do anything about the boot image in the tree? */ - diskStructure.is_bootable = 1; + diskStructure->is_bootable = 1; return 1; } int -cd9660_eltorito_add_boot_option(const char *option_string, const char *value) +cd9660_eltorito_add_boot_option(iso9660_disk *diskStructure, + const char *option_string, const char *value) { char *eptr; struct cd9660_boot_image *image; @@ -196,8 +197,8 @@ assert(option_string != NULL); /* Find the last image added */ - TAILQ_FOREACH(image, &diskStructure.boot_images, image_list) { - if (image->serialno + 1 == diskStructure.image_serialno) + TAILQ_FOREACH(image, &diskStructure->boot_images, image_list) { + if (image->serialno + 1 == diskStructure->image_serialno) break; } if (image == NULL) @@ -351,7 +352,7 @@ * Set up the BVD, Boot catalog, and the boot entries, but do no writing */ int -cd9660_setup_boot(int first_sector) +cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector) { int sector; int used_sectors; @@ -365,14 +366,14 @@ x86_head = mac_head = ppc_head = NULL; /* If there are no boot disks, don't bother building boot information */ - if (TAILQ_EMPTY(&diskStructure.boot_images)) + if (TAILQ_EMPTY(&diskStructure->boot_images)) return 0; /* Point to catalog: For now assume it consumes one sector */ ELTORITO_DPRINTF(("Boot catalog will go in sector %d\n", first_sector)); - diskStructure.boot_catalog_sector = first_sector; + diskStructure->boot_catalog_sector = first_sector; cd9660_bothendian_dword(first_sector, - diskStructure.boot_descriptor->boot_catalog_pointer); + diskStructure->boot_descriptor->boot_catalog_pointer); /* Step 1: Generate boot catalog */ /* Step 1a: Validation entry */ @@ -387,16 +388,16 @@ num_entries = 1; used_sectors = 0; - TAILQ_FOREACH(tmp_disk, &diskStructure.boot_images, image_list) { + TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) { used_sectors += tmp_disk->num_sectors; /* One default entry per image */ num_entries++; } - catalog_sectors = howmany(num_entries * 0x20, diskStructure.sectorSize); + catalog_sectors = howmany(num_entries * 0x20, diskStructure->sectorSize); used_sectors += catalog_sectors; - if (diskStructure.verbose_level > 0) { + if (diskStructure->verbose_level > 0) { printf("%s: there will be %i entries consuming %i sectors. " "Catalog is %i sectors\n", __func__, num_entries, used_sectors, catalog_sectors); @@ -404,16 +405,16 @@ /* Populate sector numbers */ sector = first_sector + catalog_sectors; - TAILQ_FOREACH(tmp_disk, &diskStructure.boot_images, image_list) { + TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) { tmp_disk->sector = sector; sector += tmp_disk->num_sectors; } - LIST_INSERT_HEAD(&diskStructure.boot_entries, valid_entry, ll_struct); + LIST_INSERT_HEAD(&diskStructure->boot_entries, valid_entry, ll_struct); /* Step 1b: Initial/default entry */ /* TODO : PARAM */ - tmp_disk = TAILQ_FIRST(&diskStructure.boot_images); + tmp_disk = TAILQ_FIRST(&diskStructure->boot_images); default_entry = cd9660_boot_setup_default_entry(tmp_disk); if (default_entry == NULL) { warnx("Error: memory allocation failed in cd9660_setup_boot"); @@ -483,7 +484,8 @@ } int -cd9660_setup_boot_volume_descriptor(volume_descriptor *bvd) +cd9660_setup_boot_volume_descriptor(iso9660_disk *diskStructure, + volume_descriptor *bvd) { boot_volume_descriptor *bvdData = (boot_volume_descriptor*)bvd->volumeDescriptorData; @@ -493,7 +495,7 @@ bvdData->version[0] = 1; memcpy(bvdData->boot_system_identifier, ET_ID, 23); memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); - diskStructure.boot_descriptor = + diskStructure->boot_descriptor = (boot_volume_descriptor*) bvd->volumeDescriptorData; return 1; } @@ -588,7 +590,7 @@ } int -cd9660_write_boot(FILE *fd) +cd9660_write_boot(iso9660_disk *diskStructure, FILE *fd) { struct boot_catalog_entry *e; struct cd9660_boot_image *t; @@ -596,16 +598,16 @@ int mbr_partitions = 0; /* write boot catalog */ - if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector * - diskStructure.sectorSize, SEEK_SET) == -1) + if (fseeko(fd, (off_t)diskStructure->boot_catalog_sector * + diskStructure->sectorSize, SEEK_SET) == -1) err(1, "fseeko"); - if (diskStructure.verbose_level > 0) { + if (diskStructure->verbose_level > 0) { printf("Writing boot catalog to sector %" PRId64 "\n", - diskStructure.boot_catalog_sector); + diskStructure->boot_catalog_sector); } - LIST_FOREACH(e, &diskStructure.boot_entries, ll_struct) { - if (diskStructure.verbose_level > 0) { + LIST_FOREACH(e, &diskStructure->boot_entries, ll_struct) { + if (diskStructure->verbose_level > 0) { printf("Writing catalog entry of type %d\n", e->entry_type); } @@ -615,16 +617,16 @@ */ fwrite(&(e->entry_data.VE), 1, 32, fd); } - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Finished writing boot catalog\n"); /* copy boot images */ - TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { - if (diskStructure.verbose_level > 0) { + TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) { + if (diskStructure->verbose_level > 0) { printf("Writing boot image from %s to sectors %d\n", t->filename, t->sector); } - cd9660_copy_file(fd, t->sector, t->filename); + cd9660_copy_file(diskStructure, fd, t->sector, t->filename); if (t->system == ET_SYS_MAC) apm_partitions++; @@ -633,7 +635,7 @@ } /* some systems need partition tables as well */ - if (mbr_partitions > 0 || diskStructure.chrp_boot) { + if (mbr_partitions > 0 || diskStructure->chrp_boot) { uint16_t sig; fseek(fd, 0x1fe, SEEK_SET); @@ -643,18 +645,18 @@ mbr_partitions = 0; /* Write ISO9660 descriptor, enclosing the whole disk */ - if (diskStructure.chrp_boot) + if (diskStructure->chrp_boot) cd9660_write_mbr_partition_entry(fd, mbr_partitions++, - 0, diskStructure.totalSectors * - (diskStructure.sectorSize / 512), 0x96); + 0, diskStructure->totalSectors * + (diskStructure->sectorSize / 512), 0x96); /* Write all partition entries */ - TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { + TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) { if (t->system != ET_SYS_PPC) continue; cd9660_write_mbr_partition_entry(fd, mbr_partitions++, - t->sector * (diskStructure.sectorSize / 512), - t->num_sectors * (diskStructure.sectorSize / 512), + t->sector * (diskStructure->sectorSize / 512), + t->num_sectors * (diskStructure->sectorSize / 512), 0x41 /* PReP Boot */); } } @@ -672,8 +674,8 @@ apm16 = htobe16(512); fwrite(&apm16, sizeof(apm16), 1, fd); /* Device block count */ - apm32 = htobe32(diskStructure.totalSectors * - (diskStructure.sectorSize / 512)); + apm32 = htobe32(diskStructure->totalSectors * + (diskStructure->sectorSize / 512)); fwrite(&apm32, sizeof(apm32), 1, fd); /* Device type/id */ apm16 = htobe16(1); @@ -689,20 +691,20 @@ /* Write all partition entries */ apm_partitions = 0; - TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { + TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) { if (t->system != ET_SYS_MAC) continue; cd9660_write_apm_partition_entry(fd, 1 + apm_partitions++, total_parts, - t->sector * (diskStructure.sectorSize / 512), - t->num_sectors * (diskStructure.sectorSize / 512), + t->sector * (diskStructure->sectorSize / 512), + t->num_sectors * (diskStructure->sectorSize / 512), 512, "CD Boot", "Apple_Bootstrap"); } /* Write ISO9660 descriptor, enclosing the whole disk */ cd9660_write_apm_partition_entry(fd, 2 + apm_partitions, - total_parts, 0, diskStructure.totalSectors * - (diskStructure.sectorSize / 512), 512, "ISO9660", + total_parts, 0, diskStructure->totalSectors * + (diskStructure->sectorSize / 512), 512, "ISO9660", "CD_ROM_Mode_1"); } Index: head/usr.sbin/makefs/cd9660/cd9660_write.c =================================================================== --- head/usr.sbin/makefs/cd9660/cd9660_write.c +++ head/usr.sbin/makefs/cd9660/cd9660_write.c @@ -38,15 +38,16 @@ #include __FBSDID("$FreeBSD$"); -static int cd9660_write_volume_descriptors(FILE *); -static int cd9660_write_path_table(FILE *, off_t, int); -static int cd9660_write_path_tables(FILE *); -static int cd9660_write_file(FILE *, cd9660node *); -static int cd9660_write_filedata(FILE *, off_t, const unsigned char *, int); +static int cd9660_write_volume_descriptors(iso9660_disk *, FILE *); +static int cd9660_write_path_table(iso9660_disk *, FILE *, off_t, int); +static int cd9660_write_path_tables(iso9660_disk *, FILE *); +static int cd9660_write_file(iso9660_disk *, FILE *, cd9660node *); +static int cd9660_write_filedata(iso9660_disk *, FILE *, off_t, + const unsigned char *, int); #if 0 static int cd9660_write_buffered(FILE *, off_t, int, const unsigned char *); #endif -static void cd9660_write_rr(FILE *, cd9660node *, off_t, off_t); +static void cd9660_write_rr(iso9660_disk *, FILE *, cd9660node *, off_t, off_t); /* * Write the image @@ -55,7 +56,7 @@ * @returns int 1 on success, 0 on failure */ int -cd9660_write_image(const char* image) +cd9660_write_image(iso9660_disk *diskStructure, const char* image) { FILE *fd; int status; @@ -66,12 +67,12 @@ image); } - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Writing image\n"); - if (diskStructure.has_generic_bootimage) { - status = cd9660_copy_file(fd, 0, - diskStructure.generic_bootimage); + if (diskStructure->has_generic_bootimage) { + status = cd9660_copy_file(diskStructure, fd, 0, + diskStructure->generic_bootimage); if (status == 0) { warnx("%s: Error writing generic boot image", __func__); @@ -80,70 +81,71 @@ } /* Write the volume descriptors */ - status = cd9660_write_volume_descriptors(fd); + status = cd9660_write_volume_descriptors(diskStructure, fd); if (status == 0) { warnx("%s: Error writing volume descriptors to image", __func__); goto cleanup_bad_image; } - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Volume descriptors written\n"); /* * Write the path tables: there are actually four, but right * now we are only concearned with two. */ - status = cd9660_write_path_tables(fd); + status = cd9660_write_path_tables(diskStructure, fd); if (status == 0) { warnx("%s: Error writing path tables to image", __func__); goto cleanup_bad_image; } - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Path tables written\n"); /* Write the directories and files */ - status = cd9660_write_file(fd, diskStructure.rootNode); + status = cd9660_write_file(diskStructure, fd, diskStructure->rootNode); if (status == 0) { warnx("%s: Error writing files to image", __func__); goto cleanup_bad_image; } - if (diskStructure.is_bootable) { - cd9660_write_boot(fd); + if (diskStructure->is_bootable) { + cd9660_write_boot(diskStructure, fd); } /* Write padding bits. This is temporary */ memset(buf, 0, CD9660_SECTOR_SIZE); - cd9660_write_filedata(fd, diskStructure.totalSectors - 1, buf, 1); + cd9660_write_filedata(diskStructure, fd, + diskStructure->totalSectors - 1, buf, 1); - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Files written\n"); fclose(fd); - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Image closed\n"); return 1; cleanup_bad_image: fclose(fd); - if (!diskStructure.keep_bad_images) + if (!diskStructure->keep_bad_images) unlink(image); - if (diskStructure.verbose_level > 0) + if (diskStructure->verbose_level > 0) printf("Bad image cleaned up\n"); return 0; } static int -cd9660_write_volume_descriptors(FILE *fd) +cd9660_write_volume_descriptors(iso9660_disk *diskStructure, FILE *fd) { - volume_descriptor *vd_temp = diskStructure.firstVolumeDescriptor; + volume_descriptor *vd_temp = diskStructure->firstVolumeDescriptor; int pos; while (vd_temp != NULL) { - pos = vd_temp->sector * diskStructure.sectorSize; - cd9660_write_filedata(fd, vd_temp->sector, + pos = vd_temp->sector * diskStructure->sectorSize; + cd9660_write_filedata(diskStructure, fd, vd_temp->sector, vd_temp->volumeDescriptorData, 1); vd_temp = vd_temp->next; } @@ -159,26 +161,27 @@ * @returns int 1 on success, 0 on failure */ static int -cd9660_write_path_table(FILE *fd, off_t sector, int mode) +cd9660_write_path_table(iso9660_disk *diskStructure, FILE *fd, off_t sector, + int mode) { - int path_table_sectors = CD9660_BLOCKS(diskStructure.sectorSize, - diskStructure.pathTableLength); + int path_table_sectors = CD9660_BLOCKS(diskStructure->sectorSize, + diskStructure->pathTableLength); unsigned char *buffer; unsigned char *buffer_head; int len, ret; path_table_entry temp_entry; cd9660node *ptcur; - buffer = malloc(diskStructure.sectorSize * path_table_sectors); + buffer = malloc(diskStructure->sectorSize * path_table_sectors); if (buffer == NULL) { warnx("%s: Memory allocation error allocating buffer", __func__); return 0; } buffer_head = buffer; - memset(buffer, 0, diskStructure.sectorSize * path_table_sectors); + memset(buffer, 0, diskStructure->sectorSize * path_table_sectors); - ptcur = diskStructure.rootNode; + ptcur = diskStructure->rootNode; while (ptcur != NULL) { memset(&temp_entry, 0, sizeof(path_table_entry)); @@ -213,7 +216,7 @@ ptcur = ptcur->ptnext; } - ret = cd9660_write_filedata(fd, sector, buffer_head, + ret = cd9660_write_filedata(diskStructure, fd, sector, buffer_head, path_table_sectors); free(buffer_head); return ret; @@ -235,14 +238,14 @@ * @returns int 0 on failure, 1 on success */ static int -cd9660_write_path_tables(FILE *fd) +cd9660_write_path_tables(iso9660_disk *diskStructure, FILE *fd) { - if (cd9660_write_path_table(fd, - diskStructure.primaryLittleEndianTableSector, LITTLE_ENDIAN) == 0) + if (cd9660_write_path_table(diskStructure, fd, + diskStructure->primaryLittleEndianTableSector, LITTLE_ENDIAN) == 0) return 0; - if (cd9660_write_path_table(fd, - diskStructure.primaryBigEndianTableSector, BIG_ENDIAN) == 0) + if (cd9660_write_path_table(diskStructure, fd, + diskStructure->primaryBigEndianTableSector, BIG_ENDIAN) == 0) return 0; /* @TODO: handle remaining two path tables */ @@ -261,7 +264,7 @@ * @returns int 0 on failure, 1 on success */ static int -cd9660_write_file(FILE *fd, cd9660node *writenode) +cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode) { char *buf; char *temp_file_name; @@ -281,7 +284,7 @@ memset(temp_file_name, 0, CD9660MAXPATH + 1); - buf = malloc(diskStructure.sectorSize); + buf = malloc(diskStructure->sectorSize); if (buf == NULL) err(EXIT_FAILURE, "%s: malloc", __func__); @@ -299,7 +302,8 @@ if (writenode->node->contents == NULL) cd9660_compute_full_filename(writenode, temp_file_name); - ret = cd9660_copy_file(fd, writenode->fileDataSector, + ret = cd9660_copy_file(diskStructure, fd, + writenode->fileDataSector, (writenode->node->contents != NULL) ? writenode->node->contents : temp_file_name); if (ret == 0) @@ -318,7 +322,7 @@ */ cur_sector_offset = 0; working_sector = writenode->fileDataSector; - if (fseeko(fd, working_sector * diskStructure.sectorSize, + if (fseeko(fd, working_sector * diskStructure->sectorSize, SEEK_SET) == -1) err(1, "fseeko"); @@ -335,27 +339,27 @@ sizeof(iso_directory_record_cd9660)); temp_record.length[0] = - cd9660_compute_record_size(temp); + cd9660_compute_record_size(diskStructure, temp); if (temp_record.length[0] + cur_sector_offset >= - diskStructure.sectorSize) { + diskStructure->sectorSize) { cur_sector_offset = 0; working_sector++; /* Seek to the next sector. */ if (fseeko(fd, working_sector * - diskStructure.sectorSize, SEEK_SET) == -1) + diskStructure->sectorSize, SEEK_SET) == -1) err(1, "fseeko"); } /* Write out the basic ISO directory record */ written = fwrite(&temp_record, 1, temp->isoDirRecord->length[0], fd); - if (diskStructure.rock_ridge_enabled) { - cd9660_write_rr(fd, temp, + if (diskStructure->rock_ridge_enabled) { + cd9660_write_rr(diskStructure, fd, temp, cur_sector_offset, working_sector); } if (fseeko(fd, working_sector * - diskStructure.sectorSize + cur_sector_offset + + diskStructure->sectorSize + cur_sector_offset + temp_record.length[0] - temp->su_tail_size, SEEK_SET) == -1) err(1, "fseeko"); @@ -374,7 +378,7 @@ * Recurse on children. */ TAILQ_FOREACH(temp, &writenode->cn_children, cn_next_child) { - if ((ret = cd9660_write_file(fd, temp)) == 0) + if ((ret = cd9660_write_file(diskStructure, fd, temp)) == 0) goto out; } } @@ -399,24 +403,24 @@ * is written, the rest should be set to 0. */ static int -cd9660_write_filedata(FILE *fd, off_t sector, const unsigned char *buf, - int numsecs) +cd9660_write_filedata(iso9660_disk *diskStructure, FILE *fd, off_t sector, + const unsigned char *buf, int numsecs) { off_t curpos; size_t success; curpos = ftello(fd); - if (fseeko(fd, sector * diskStructure.sectorSize, SEEK_SET) == -1) + if (fseeko(fd, sector * diskStructure->sectorSize, SEEK_SET) == -1) err(1, "fseeko"); - success = fwrite(buf, diskStructure.sectorSize * numsecs, 1, fd); + success = fwrite(buf, diskStructure->sectorSize * numsecs, 1, fd); if (fseeko(fd, curpos, SEEK_SET) == -1) err(1, "fseeko"); if (success == 1) - success = diskStructure.sectorSize * numsecs; + success = diskStructure->sectorSize * numsecs; return success; } @@ -433,12 +437,13 @@ #endif int -cd9660_copy_file(FILE *fd, off_t start_sector, const char *filename) +cd9660_copy_file(iso9660_disk *diskStructure, FILE *fd, off_t start_sector, + const char *filename) { FILE *rf; int bytes_read; off_t sector = start_sector; - int buf_size = diskStructure.sectorSize; + int buf_size = diskStructure->sectorSize; char *buf; buf = malloc(buf_size); @@ -451,10 +456,10 @@ return 0; } - if (diskStructure.verbose_level > 1) + if (diskStructure->verbose_level > 1) printf("Writing file: %s\n",filename); - if (fseeko(fd, start_sector * diskStructure.sectorSize, SEEK_SET) == -1) + if (fseeko(fd, start_sector * diskStructure->sectorSize, SEEK_SET) == -1) err(1, "fseeko"); while (!feof(rf)) { @@ -482,13 +487,14 @@ } static void -cd9660_write_rr(FILE *fd, cd9660node *writenode, off_t offset, off_t sector) +cd9660_write_rr(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode, + off_t offset, off_t sector) { int in_ca = 0; struct ISO_SUSP_ATTRIBUTES *myattr; offset += writenode->isoDirRecord->length[0]; - if (fseeko(fd, sector * diskStructure.sectorSize + offset, SEEK_SET) == + if (fseeko(fd, sector * diskStructure->sectorSize + offset, SEEK_SET) == -1) err(1, "fseeko"); /* Offset now points at the end of the record */ @@ -502,9 +508,9 @@ * Point the offset to the start of this * record's CE area */ - if (fseeko(fd, ((off_t)diskStructure. + if (fseeko(fd, ((off_t)diskStructure-> susp_continuation_area_start_sector * - diskStructure.sectorSize) + diskStructure->sectorSize) + writenode->susp_entry_ce_start, SEEK_SET) == -1) err(1, "fseeko"); @@ -518,7 +524,7 @@ * where we should be. */ if (in_ca) - if (fseeko(fd, sector * diskStructure.sectorSize + offset, + if (fseeko(fd, sector * diskStructure->sectorSize + offset, SEEK_SET) == -1) err(1, "fseeko"); } Index: head/usr.sbin/makefs/cd9660/iso9660_rrip.h =================================================================== --- head/usr.sbin/makefs/cd9660/iso9660_rrip.h +++ head/usr.sbin/makefs/cd9660/iso9660_rrip.h @@ -217,10 +217,10 @@ ((int) ((entry)->attr.su_entry.SP.h.length[0])) /* Recursive function - move later to func pointer code*/ -int cd9660_susp_finalize(cd9660node *); +int cd9660_susp_finalize(iso9660_disk *, cd9660node *); /* These two operate on single nodes */ -int cd9660_susp_finalize_node(cd9660node *); +int cd9660_susp_finalize_node(iso9660_disk *, cd9660node *); int cd9660_rrip_finalize_node(cd9660node *); /* POSIX File attribute */ @@ -272,15 +272,17 @@ /* Helper functions */ /* Common SUSP/RRIP functions */ -int cd9660_susp_initialize(cd9660node *, cd9660node *, cd9660node *); -int cd9660_susp_initialize_node(cd9660node *); +int cd9660_susp_initialize(iso9660_disk *, cd9660node *, cd9660node *, + cd9660node *); +int cd9660_susp_initialize_node(iso9660_disk *, cd9660node *); struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_create_node(int, int, const char *, int); struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_add_entry(cd9660node *, struct ISO_SUSP_ATTRIBUTES *, struct ISO_SUSP_ATTRIBUTES *, int); /* RRIP specific functions */ -int cd9660_rrip_initialize_node(cd9660node *, cd9660node *, cd9660node *); +int cd9660_rrip_initialize_node(iso9660_disk *, cd9660node *, cd9660node *, + cd9660node *); void cd9660_createSL(cd9660node *); /* Functions that probably can be removed */ Index: head/usr.sbin/makefs/cd9660/iso9660_rrip.c =================================================================== --- head/usr.sbin/makefs/cd9660/iso9660_rrip.c +++ head/usr.sbin/makefs/cd9660/iso9660_rrip.c @@ -47,12 +47,13 @@ #include "iso9660_rrip.h" static void cd9660_rrip_initialize_inode(cd9660node *); -static int cd9660_susp_handle_continuation(cd9660node *); -static int cd9660_susp_handle_continuation_common(cd9660node *, int); +static int cd9660_susp_handle_continuation(iso9660_disk *, cd9660node *); +static int cd9660_susp_handle_continuation_common(iso9660_disk *, cd9660node *, + int); int -cd9660_susp_initialize(cd9660node *node, cd9660node *parent, - cd9660node *grandparent) +cd9660_susp_initialize(iso9660_disk *diskStructure, cd9660node *node, + cd9660node *parent, cd9660node *grandparent) { cd9660node *cn; int r; @@ -69,11 +70,11 @@ TAILQ_INIT(&(node->dot_dot_record->head)); /* SUSP specific entries here */ - if ((r = cd9660_susp_initialize_node(node)) < 0) + if ((r = cd9660_susp_initialize_node(diskStructure, node)) < 0) return r; /* currently called cd9660node_rrip_init_links */ - r = cd9660_rrip_initialize_node(node, parent, grandparent); + r = cd9660_rrip_initialize_node(diskStructure, node, parent, grandparent); if (r < 0) return r; @@ -84,35 +85,35 @@ * This should be called after all extensions. After * this is called, no new records should be added. */ - if ((r = cd9660_susp_handle_continuation(node)) < 0) + if ((r = cd9660_susp_handle_continuation(diskStructure, node)) < 0) return r; /* Recurse on children. */ TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) { - if ((r = cd9660_susp_initialize(cn, node, parent)) < 0) + if ((r = cd9660_susp_initialize(diskStructure, cn, node, parent)) < 0) return 0; } return 1; } int -cd9660_susp_finalize(cd9660node *node) +cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node) { cd9660node *temp; int r; assert(node != NULL); - if (node == diskStructure.rootNode) - diskStructure.susp_continuation_area_current_free = 0; + if (node == diskStructure->rootNode) + diskStructure->susp_continuation_area_current_free = 0; - if ((r = cd9660_susp_finalize_node(node)) < 0) + if ((r = cd9660_susp_finalize_node(diskStructure, node)) < 0) return r; if ((r = cd9660_rrip_finalize_node(node)) < 0) return r; TAILQ_FOREACH(temp, &node->cn_children, cn_next_child) { - if ((r = cd9660_susp_finalize(temp)) < 0) + if ((r = cd9660_susp_finalize(diskStructure, temp)) < 0) return r; } return 1; @@ -132,15 +133,15 @@ * CE (continuation area) */ int -cd9660_susp_finalize_node(cd9660node *node) +cd9660_susp_finalize_node(iso9660_disk *diskStructure, cd9660node *node) { struct ISO_SUSP_ATTRIBUTES *t; /* Handle CE counters */ if (node->susp_entry_ce_length > 0) { node->susp_entry_ce_start = - diskStructure.susp_continuation_area_current_free; - diskStructure.susp_continuation_area_current_free += + diskStructure->susp_continuation_area_current_free; + diskStructure->susp_continuation_area_current_free += node->susp_entry_ce_length; } @@ -149,12 +150,12 @@ t->entry_type != SUSP_ENTRY_SUSP_CE) continue; cd9660_bothendian_dword( - diskStructure. + diskStructure-> susp_continuation_area_start_sector, t->attr.su_entry.CE.ca_sector); cd9660_bothendian_dword( - diskStructure. + diskStructure-> susp_continuation_area_start_sector, t->attr.su_entry.CE.ca_sector); cd9660_bothendian_dword(node->susp_entry_ce_start, @@ -199,7 +200,8 @@ } static int -cd9660_susp_handle_continuation_common(cd9660node *node, int space) +cd9660_susp_handle_continuation_common(iso9660_disk *diskStructure, + cd9660node *node, int space) { int ca_used, susp_used, susp_used_pre_ce, working; struct ISO_SUSP_ATTRIBUTES *temp, *pre_ce, *last, *CE, *ST; @@ -272,18 +274,18 @@ node->susp_entry_size = susp_used; node->susp_entry_ce_length = ca_used; - diskStructure.susp_continuation_area_size += ca_used; + diskStructure->susp_continuation_area_size += ca_used; return 1; } /* See if a continuation entry is needed for each of the different types */ static int -cd9660_susp_handle_continuation(cd9660node *node) +cd9660_susp_handle_continuation(iso9660_disk *diskStructure, cd9660node *node) { assert (node != NULL); /* Entry */ - if (cd9660_susp_handle_continuation_common( + if (cd9660_susp_handle_continuation_common(diskStructure, node,(int)(node->isoDirRecord->length[0])) < 0) return 0; @@ -291,7 +293,7 @@ } int -cd9660_susp_initialize_node(cd9660node *node) +cd9660_susp_initialize_node(iso9660_disk *diskStructure, cd9660node *node) { struct ISO_SUSP_ATTRIBUTES *temp; @@ -307,7 +309,7 @@ /* Check for root directory, add SP and ER if needed. */ if (node->type & CD9660_TYPE_DOT) { - if (node->parent == diskStructure.rootNode) { + if (node->parent == diskStructure->rootNode) { temp = cd9660node_susp_create_node(SUSP_TYPE_SUSP, SUSP_ENTRY_SUSP_SP, "SP", SUSP_LOC_DOT); cd9660_susp_sp(temp, node); @@ -366,8 +368,8 @@ } int -cd9660_rrip_initialize_node(cd9660node *node, cd9660node *parent, - cd9660node *grandparent) +cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node, + cd9660node *parent, cd9660node *grandparent) { struct ISO_SUSP_ATTRIBUTES *current = NULL; @@ -378,7 +380,7 @@ * Handle ER - should be the only entry to appear on * a "." record */ - if (node->parent == diskStructure.rootNode) { + if (node->parent == diskStructure->rootNode) { cd9660_susp_ER(node, 1, SUSP_RRIP_ER_EXT_ID, SUSP_RRIP_ER_EXT_DES, SUSP_RRIP_ER_EXT_SRC); } @@ -416,7 +418,7 @@ * * The rr_moved_dir needs to be assigned a NM record as well. */ - if (node == diskStructure.rr_moved_dir) { + if (node == diskStructure->rr_moved_dir) { cd9660_rrip_add_NM(node, RRIP_DEFAULT_MOVE_DIR_NAME); } else if ((node->node != NULL) &&