2011-08-23 23:57:24 +04:00
|
|
|
/* $NetBSD: cd9660.c,v 1.34 2011/08/23 19:57:24 christos Exp $ */
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
|
|
|
* Perez-Rathke and Ram Vedam. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
|
|
|
|
* Alan Perez-Rathke and Ram Vedam.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
|
|
|
|
* GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
2005-10-30 06:10:28 +03:00
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2005-08-13 05:53:01 +04:00
|
|
|
* DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
|
|
|
|
* GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
* USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 Wasabi Systems, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Luke Mewburn for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
2007-01-16 20:32:04 +03:00
|
|
|
#else
|
|
|
|
#include <sys/mount.h>
|
2005-08-13 05:53:01 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(__RCSID) && !defined(__lint)
|
2011-08-23 23:57:24 +04:00
|
|
|
__RCSID("$NetBSD: cd9660.c,v 1.34 2011/08/23 19:57:24 christos Exp $");
|
2005-08-13 05:53:01 +04:00
|
|
|
#endif /* !__lint */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include "makefs.h"
|
|
|
|
#include "cd9660.h"
|
|
|
|
#include "cd9660/iso9660_rrip.h"
|
2009-01-11 01:06:29 +03:00
|
|
|
#include "cd9660/cd9660_archimedes.h"
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
iso9660_disk diskStructure;
|
|
|
|
|
|
|
|
static void cd9660_finalize_PVD(void);
|
|
|
|
static cd9660node *cd9660_allocate_cd9660node(void);
|
|
|
|
static void cd9660_set_defaults(void);
|
|
|
|
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);
|
|
|
|
#if 0
|
|
|
|
static int cd9660_fill_extended_attribute_record(cd9660node *);
|
|
|
|
#endif
|
2005-10-25 06:22:04 +04:00
|
|
|
static void cd9660_sort_nodes(cd9660node *);
|
2010-11-19 18:47:32 +03:00
|
|
|
static int cd9660_translate_node_common(cd9660node *);
|
2005-08-13 05:53:01 +04:00
|
|
|
static int cd9660_translate_node(fsnode *, cd9660node *);
|
|
|
|
static int cd9660_compare_filename(const char *, const char *);
|
2005-10-25 06:22:04 +04:00
|
|
|
static void cd9660_sorted_child_insert(cd9660node *, cd9660node *);
|
2005-08-13 05:53:01 +04:00
|
|
|
static int cd9660_handle_collisions(cd9660node *, int);
|
|
|
|
static cd9660node *cd9660_rename_filename(cd9660node *, int, int);
|
|
|
|
static void cd9660_copy_filenames(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 *);
|
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
static void cd9660_convert_structure(fsnode *, cd9660node *, int,
|
2006-10-10 05:55:45 +04:00
|
|
|
int *, int *);
|
2005-08-13 05:53:01 +04:00
|
|
|
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);
|
|
|
|
#if 0
|
|
|
|
static int cd9660_joliet_convert_filename(const char *, char *, int);
|
|
|
|
#endif
|
|
|
|
static int cd9660_convert_filename(const char *, char *, int);
|
|
|
|
static void cd9660_populate_dot_records(cd9660node *);
|
2010-10-27 22:51:34 +04:00
|
|
|
static int64_t cd9660_compute_offsets(cd9660node *, int64_t);
|
2005-08-13 05:53:01 +04:00
|
|
|
#if 0
|
|
|
|
static int cd9660_copy_stat_info(cd9660node *, cd9660node *, int);
|
|
|
|
#endif
|
|
|
|
static cd9660node *cd9660_create_virtual_entry(const char *, cd9660node *, int,
|
|
|
|
int);
|
2007-04-07 21:14:58 +04:00
|
|
|
static cd9660node *cd9660_create_file(const char *, cd9660node *, cd9660node *);
|
|
|
|
static cd9660node *cd9660_create_directory(const char *, cd9660node *,
|
|
|
|
cd9660node *);
|
2005-08-13 05:53:01 +04:00
|
|
|
static cd9660node *cd9660_create_special_directory(u_char, cd9660node *);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate and initalize a cd9660node
|
|
|
|
* @returns struct cd9660node * Pointer to new node, or NULL on error
|
|
|
|
*/
|
|
|
|
static cd9660node *
|
|
|
|
cd9660_allocate_cd9660node(void)
|
|
|
|
{
|
|
|
|
cd9660node *temp;
|
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
if ((temp = calloc(1, sizeof(cd9660node))) == NULL)
|
|
|
|
err(EXIT_FAILURE, "%s: calloc", __func__);
|
|
|
|
TAILQ_INIT(&temp->cn_children);
|
|
|
|
temp->parent = temp->dot_record = temp->dot_dot_record = NULL;
|
|
|
|
temp->ptnext = temp->ptprev = temp->ptlast = NULL;
|
|
|
|
temp->node = NULL;
|
|
|
|
temp->isoDirRecord = NULL;
|
|
|
|
temp->isoExtAttributes = NULL;
|
|
|
|
temp->rr_real_parent = temp->rr_relocated = NULL;
|
2009-01-11 01:06:29 +03:00
|
|
|
temp->su_tail_data = NULL;
|
2005-10-25 06:22:04 +04:00
|
|
|
return temp;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int cd9660_defaults_set = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set default values for cd9660 extension to makefs
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cd9660_set_defaults(void)
|
|
|
|
{
|
|
|
|
/*Fix the sector size for now, though the spec allows for other sizes*/
|
|
|
|
diskStructure.sectorSize = 2048;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Set up defaults in our own structure */
|
2005-11-01 02:19:06 +03:00
|
|
|
diskStructure.verbose_level = 0;
|
2005-08-13 05:53:01 +04:00
|
|
|
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;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2009-01-11 01:06:29 +03:00
|
|
|
diskStructure.archimedes_enabled = 0;
|
2011-05-23 01:51:39 +04:00
|
|
|
diskStructure.chrp_boot = 0;
|
2009-01-11 01:06:29 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.include_padding_areas = 1;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Spec breaking functionality */
|
2005-10-30 06:10:28 +03:00
|
|
|
diskStructure.allow_deep_trees =
|
2005-09-12 02:03:48 +04:00
|
|
|
diskStructure.allow_start_dot =
|
|
|
|
diskStructure.allow_max_name =
|
|
|
|
diskStructure.allow_illegal_chars =
|
|
|
|
diskStructure.allow_lowercase =
|
|
|
|
diskStructure.allow_multidot =
|
|
|
|
diskStructure.omit_trailing_period = 0;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Make sure the PVD is clear */
|
|
|
|
memset(&diskStructure.primaryDescriptor, 0, 2048);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
memset(diskStructure.primaryDescriptor.publisher_id, 0x20,128);
|
|
|
|
memset(diskStructure.primaryDescriptor.preparer_id, 0x20,128);
|
|
|
|
memset(diskStructure.primaryDescriptor.application_id, 0x20,128);
|
2011-08-07 03:25:19 +04:00
|
|
|
memset(diskStructure.primaryDescriptor.copyright_file_id, 0x20,37);
|
|
|
|
memset(diskStructure.primaryDescriptor.abstract_file_id, 0x20,37);
|
|
|
|
memset(diskStructure.primaryDescriptor.bibliographic_file_id, 0x20,37);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
strcpy(diskStructure.primaryDescriptor.system_id,"NetBSD");
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_defaults_set = 1;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Boot support: Initially disabled */
|
2008-05-10 23:00:07 +04:00
|
|
|
diskStructure.has_generic_bootimage = 0;
|
|
|
|
diskStructure.generic_bootimage = NULL;
|
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.boot_image_directory = 0;
|
|
|
|
/*memset(diskStructure.boot_descriptor, 0, 2048);*/
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.is_bootable = 0;
|
2005-10-30 09:45:46 +03:00
|
|
|
TAILQ_INIT(&diskStructure.boot_images);
|
2005-08-13 05:53:01 +04:00
|
|
|
LIST_INIT(&diskStructure.boot_entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-12-19 00:03:29 +03:00
|
|
|
cd9660_prep_opts(fsinfo_t *fsopts __unused)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
cd9660_set_defaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-12-19 00:03:29 +03:00
|
|
|
cd9660_cleanup_opts(fsinfo_t *fsopts __unused)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cd9660_arguments_set_string(const char *val, const char *fieldtitle, int length,
|
|
|
|
char testmode, char * dest)
|
|
|
|
{
|
|
|
|
int len, test;
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
warnx("error: The %s requires a string argument", fieldtitle);
|
|
|
|
else if ((len = strlen(val)) <= length) {
|
|
|
|
if (testmode == 'd')
|
|
|
|
test = cd9660_valid_d_chars(val);
|
|
|
|
else
|
|
|
|
test = cd9660_valid_a_chars(val);
|
|
|
|
if (test) {
|
|
|
|
memcpy(dest, val, len);
|
|
|
|
if (test == 2)
|
|
|
|
cd9660_uppercase_characters(dest, len);
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
warnx("error: The %s must be composed of "
|
|
|
|
"%c-characters", fieldtitle, testmode);
|
|
|
|
} else
|
|
|
|
warnx("error: The %s must be at most 32 characters long",
|
|
|
|
fieldtitle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command-line parsing function
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
cd9660_parse_opts(const char *option, fsinfo_t *fsopts)
|
|
|
|
{
|
|
|
|
char *var, *val;
|
|
|
|
int rv;
|
|
|
|
/* Set up allowed options - integer options ONLY */
|
|
|
|
option_t cd9660_options[] = {
|
|
|
|
{ "l", &diskStructure.isoLevel, 1, 3, "ISO Level" },
|
|
|
|
{ "isolevel", &diskStructure.isoLevel, 1, 3, "ISO Level" },
|
|
|
|
{ "verbose", &diskStructure.verbose_level, 0, 2,
|
|
|
|
"Turns on verbose output" },
|
|
|
|
{ "v", &diskStructure.verbose_level, 0 , 2,
|
|
|
|
"Turns on verbose output"},
|
2006-10-23 01:09:47 +04:00
|
|
|
{ .name = NULL }
|
2005-08-13 05:53:01 +04:00
|
|
|
};
|
2005-08-15 10:41:06 +04:00
|
|
|
|
|
|
|
if (cd9660_defaults_set == 0)
|
|
|
|
cd9660_set_defaults();
|
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* Todo : finish implementing this, and make a function that
|
|
|
|
* parses them
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
string_option_t cd9660_string_options[] = {
|
|
|
|
{ "L", "Label", &diskStructure.primaryDescriptor.volume_id, 1, 32, "Disk Label", ISO_STRING_FILTER_DCHARS },
|
|
|
|
{ NULL }
|
|
|
|
}
|
|
|
|
*/
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
assert(option != NULL);
|
|
|
|
|
|
|
|
if (debug & DEBUG_FS_PARSE_OPTS)
|
|
|
|
printf("cd9660_parse_opts: got `%s'\n", option);
|
|
|
|
|
|
|
|
if ((var = strdup(option)) == NULL)
|
|
|
|
err(1, "allocating memory for copy of option string");
|
|
|
|
rv = 1;
|
|
|
|
|
|
|
|
val = strchr(var, '=');
|
|
|
|
if (val != NULL)
|
|
|
|
*val++ = '\0';
|
|
|
|
|
|
|
|
/* First handle options with no parameters */
|
|
|
|
if (strcmp(var, "h") == 0) {
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "applicationid")) {
|
|
|
|
rv = cd9660_arguments_set_string(val, "Application Identifier", 128, 'a',
|
|
|
|
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);
|
|
|
|
} else if (CD9660_IS_COMMAND_ARG_DUAL(var, "p", "preparer")) {
|
|
|
|
rv = cd9660_arguments_set_string(val, "Preparer Identifier",
|
|
|
|
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);
|
|
|
|
/* 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);
|
|
|
|
} else if (CD9660_IS_COMMAND_ARG(var, "bootimagedir")) {
|
|
|
|
/*
|
|
|
|
* XXXfvdl this is unused.
|
|
|
|
*/
|
|
|
|
if (val == NULL)
|
|
|
|
errx(1, "error: The Boot Image Directory parameter"
|
|
|
|
" requires a directory name\n");
|
|
|
|
else {
|
|
|
|
if ((diskStructure.boot_image_directory =
|
|
|
|
malloc(strlen(val) + 1)) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_parse_opts");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* BIG TODO: Add the max length function here */
|
|
|
|
cd9660_arguments_set_string(val, "Boot Image Directory",
|
|
|
|
12 , 'd', diskStructure.boot_image_directory);
|
|
|
|
}
|
2008-05-10 23:00:07 +04:00
|
|
|
} 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);
|
2005-08-13 05:53:01 +04:00
|
|
|
} else if (CD9660_IS_COMMAND_ARG(var, "no-trailing-padding"))
|
|
|
|
diskStructure.include_padding_areas = 0;
|
|
|
|
/* RRIP */
|
|
|
|
else if (CD9660_IS_COMMAND_ARG_DUAL(var, "R", "rockridge"))
|
|
|
|
diskStructure.rock_ridge_enabled = 1;
|
2009-01-11 01:06:29 +03:00
|
|
|
else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "archimedes"))
|
|
|
|
diskStructure.archimedes_enabled = 1;
|
2011-05-23 01:51:39 +04:00
|
|
|
else if (CD9660_IS_COMMAND_ARG(var, "chrp-boot"))
|
|
|
|
diskStructure.chrp_boot = 1;
|
2005-08-13 05:53:01 +04:00
|
|
|
else if (CD9660_IS_COMMAND_ARG_DUAL(var, "K", "keep-bad-images"))
|
|
|
|
diskStructure.keep_bad_images = 1;
|
|
|
|
else if (CD9660_IS_COMMAND_ARG(var, "allow-deep-trees"))
|
|
|
|
diskStructure.allow_deep_trees = 1;
|
|
|
|
else if (CD9660_IS_COMMAND_ARG(var, "allow-max-name"))
|
|
|
|
diskStructure.allow_max_name = 1;
|
|
|
|
else if (CD9660_IS_COMMAND_ARG(var, "allow-illegal-chars"))
|
|
|
|
diskStructure.allow_illegal_chars = 1;
|
|
|
|
else if (CD9660_IS_COMMAND_ARG(var, "allow-lowercase"))
|
|
|
|
diskStructure.allow_lowercase = 1;
|
|
|
|
else if (CD9660_IS_COMMAND_ARG(var,"allow-multidot"))
|
|
|
|
diskStructure.allow_multidot = 1;
|
|
|
|
else if (CD9660_IS_COMMAND_ARG(var, "omit-trailing-period"))
|
2005-09-12 02:01:44 +04:00
|
|
|
diskStructure.omit_trailing_period = 1;
|
2006-06-02 01:06:37 +04:00
|
|
|
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);
|
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* End of flag variables */
|
2006-06-02 01:06:37 +04:00
|
|
|
} else if (CD9660_IS_COMMAND_ARG(var, "boot-load-segment")) {
|
|
|
|
if (val == NULL) {
|
|
|
|
warnx("Option `%s' doesn't contain a value", var);
|
|
|
|
rv = 0;
|
|
|
|
} else {
|
|
|
|
cd9660_eltorito_add_boot_option(var, val);
|
|
|
|
}
|
2009-01-09 01:26:19 +03:00
|
|
|
} else {
|
|
|
|
if (val == NULL) {
|
|
|
|
warnx("Option `%s' doesn't contain a value", var);
|
|
|
|
rv = 0;
|
|
|
|
} else
|
|
|
|
rv = set_option(cd9660_options, var, val);
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (var)
|
|
|
|
free(var);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main function for cd9660_makefs
|
|
|
|
* Builds the ISO image file
|
|
|
|
* @param const char *image The image filename to create
|
|
|
|
* @param const char *dir The directory that is being read
|
|
|
|
* @param struct fsnode *root The root node of the filesystem tree
|
|
|
|
* @param struct fsinfo_t *fsopts Any options
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cd9660_makefs(const char *image, const char *dir, fsnode *root,
|
|
|
|
fsinfo_t *fsopts)
|
|
|
|
{
|
2010-10-27 22:51:34 +04:00
|
|
|
int64_t startoffset;
|
2005-08-13 05:53:01 +04:00
|
|
|
int numDirectories;
|
2010-10-27 22:51:34 +04:00
|
|
|
uint64_t pathTableSectors;
|
|
|
|
int64_t firstAvailableSector;
|
|
|
|
int64_t totalSpace;
|
2005-08-13 05:53:01 +04:00
|
|
|
int error;
|
|
|
|
cd9660node *real_root;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_makefs: ISO level is %i\n",
|
|
|
|
diskStructure.isoLevel);
|
2008-11-21 13:02:12 +03:00
|
|
|
if (diskStructure.isoLevel < 2 &&
|
|
|
|
diskStructure.allow_multidot)
|
|
|
|
errx(1, "allow-multidot requires iso level of 2\n");
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
assert(image != NULL);
|
|
|
|
assert(dir != NULL);
|
|
|
|
assert(root != NULL);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (diskStructure.displayHelp) {
|
|
|
|
/*
|
|
|
|
* Display help here - probably want to put it in
|
|
|
|
* a separate function
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.rootFilesystemPath = dir;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_makefs: image %s directory %s root %p\n",
|
|
|
|
image, dir, root);
|
|
|
|
|
|
|
|
/* Set up some constants. Later, these will be defined with options */
|
|
|
|
|
|
|
|
/* Counter needed for path tables */
|
|
|
|
numDirectories = 0;
|
|
|
|
|
|
|
|
/* Convert tree to our own format */
|
|
|
|
/* Actually, we now need to add the REAL root node, at level 0 */
|
|
|
|
|
|
|
|
real_root = cd9660_allocate_cd9660node();
|
2005-10-30 06:10:28 +03:00
|
|
|
if ((real_root->isoDirRecord =
|
2005-08-13 05:53:01 +04:00
|
|
|
malloc( sizeof(iso_directory_record_cd9660) )) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_makefs");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Leave filename blank for root */
|
|
|
|
memset(real_root->isoDirRecord->name, 0,
|
|
|
|
ISO_FILENAME_MAXLENGTH_WITH_PADDING);
|
|
|
|
|
|
|
|
real_root->level = 0;
|
|
|
|
diskStructure.rootNode = real_root;
|
|
|
|
real_root->type = CD9660_TYPE_DIR;
|
|
|
|
error = 0;
|
2005-10-25 06:22:04 +04:00
|
|
|
real_root->node = root;
|
2006-10-10 05:55:45 +04:00
|
|
|
cd9660_convert_structure(root, real_root, 1, &numDirectories, &error);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
if (TAILQ_EMPTY(&real_root->cn_children)) {
|
2005-08-13 05:53:01 +04:00
|
|
|
errx(1, "cd9660_makefs: converted directory is empty. "
|
|
|
|
"Tree conversion failed\n");
|
|
|
|
} else if (error != 0) {
|
|
|
|
errx(1, "cd9660_makefs: tree conversion failed\n");
|
|
|
|
} else {
|
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_makefs: tree converted\n");
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Add the dot and dot dot records */
|
|
|
|
cd9660_add_dot_records(real_root);
|
|
|
|
|
|
|
|
cd9660_setup_root_node();
|
|
|
|
|
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_makefs: done converting tree\n");
|
|
|
|
|
2009-01-11 01:06:29 +03:00
|
|
|
/* non-SUSP extensions */
|
|
|
|
if (diskStructure.archimedes_enabled)
|
|
|
|
archimedes_convert_tree(diskStructure.rootNode);
|
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Rock ridge / SUSP init pass */
|
2005-10-25 06:22:04 +04:00
|
|
|
if (diskStructure.rock_ridge_enabled) {
|
|
|
|
cd9660_susp_initialize(diskStructure.rootNode,
|
|
|
|
diskStructure.rootNode, NULL);
|
|
|
|
}
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/* Build path table structure */
|
|
|
|
diskStructure.pathTableLength = cd9660_generate_path_table();
|
|
|
|
|
|
|
|
pathTableSectors = CD9660_BLOCKS(diskStructure.sectorSize,
|
|
|
|
diskStructure.pathTableLength);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
firstAvailableSector = cd9660_setup_volume_descriptors();
|
|
|
|
if (diskStructure.is_bootable) {
|
|
|
|
firstAvailableSector = cd9660_setup_boot(firstAvailableSector);
|
|
|
|
if (firstAvailableSector < 0)
|
|
|
|
errx(1, "setup_boot failed");
|
|
|
|
}
|
|
|
|
/* LE first, then BE */
|
|
|
|
diskStructure.primaryLittleEndianTableSector = firstAvailableSector;
|
2005-10-30 06:10:28 +03:00
|
|
|
diskStructure.primaryBigEndianTableSector =
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.primaryLittleEndianTableSector + pathTableSectors;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Set the secondary ones to -1, not going to use them for now */
|
|
|
|
diskStructure.secondaryBigEndianTableSector = -1;
|
|
|
|
diskStructure.secondaryLittleEndianTableSector = -1;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.dataFirstSector =
|
|
|
|
diskStructure.primaryBigEndianTableSector + pathTableSectors;
|
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_makefs: Path table conversion complete. "
|
2010-10-27 22:51:34 +04:00
|
|
|
"Each table is %i bytes, or %" PRIu64 " sectors.\n",
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.pathTableLength, pathTableSectors);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
startoffset = diskStructure.sectorSize*diskStructure.dataFirstSector;
|
|
|
|
|
|
|
|
totalSpace = cd9660_compute_offsets(real_root, startoffset);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cd9660_finalize_PVD();
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Add padding sectors, just for testing purposes right now */
|
|
|
|
/* diskStructure.totalSectors+=150; */
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Debugging output */
|
|
|
|
if (diskStructure.verbose_level > 0) {
|
|
|
|
printf("cd9660_makefs: Sectors 0-15 reserved\n");
|
2010-10-27 22:51:34 +04:00
|
|
|
printf("cd9660_makefs: Primary path tables starts in sector %"
|
|
|
|
PRId64 "\n", diskStructure.primaryLittleEndianTableSector);
|
|
|
|
printf("cd9660_makefs: File data starts in sector %"
|
|
|
|
PRId64 "\n", diskStructure.dataFirstSector);
|
|
|
|
printf("cd9660_makefs: Total sectors: %"
|
|
|
|
PRId64 "\n", diskStructure.totalSectors);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-10-30 06:10:28 +03:00
|
|
|
* Add padding sectors at the end
|
2005-08-13 05:53:01 +04:00
|
|
|
* TODO: Clean this up and separate padding
|
|
|
|
*/
|
|
|
|
if (diskStructure.include_padding_areas)
|
|
|
|
diskStructure.totalSectors += 150;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_write_image(image);
|
|
|
|
|
|
|
|
if (diskStructure.verbose_level > 1) {
|
|
|
|
debug_print_volume_descriptor_information();
|
|
|
|
debug_print_tree(real_root,0);
|
|
|
|
debug_print_path_tree(real_root);
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Clean up data structures */
|
|
|
|
cd9660_free_structure(real_root);
|
|
|
|
|
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_makefs: done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generic function pointer - implement later */
|
|
|
|
typedef int (*cd9660node_func)(cd9660node *);
|
|
|
|
|
|
|
|
static void
|
|
|
|
cd9660_finalize_PVD(void)
|
|
|
|
{
|
|
|
|
time_t tim;
|
|
|
|
unsigned char *temp;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Copy the root directory record */
|
|
|
|
temp = (unsigned char *) &diskStructure.primaryDescriptor;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* In RRIP, this might be longer than 34 */
|
|
|
|
diskStructure.primaryDescriptor.root_directory_record[0] = 34;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Set up all the important numbers in the PVD */
|
|
|
|
cd9660_bothendian_dword(diskStructure.totalSectors,
|
|
|
|
(unsigned char *)diskStructure.primaryDescriptor.volume_space_size);
|
|
|
|
cd9660_bothendian_word(1,
|
|
|
|
(unsigned char *)diskStructure.primaryDescriptor.volume_set_size);
|
|
|
|
cd9660_bothendian_word(1,
|
|
|
|
(unsigned char *)
|
|
|
|
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);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.primaryDescriptor.file_structure_version[0] = 1;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* 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,
|
|
|
|
128);
|
|
|
|
cd9660_pad_string_spaces(diskStructure.primaryDescriptor.publisher_id,
|
|
|
|
128);
|
|
|
|
cd9660_pad_string_spaces(diskStructure.primaryDescriptor.preparer_id,
|
|
|
|
128);
|
|
|
|
cd9660_pad_string_spaces(diskStructure.primaryDescriptor.application_id,
|
|
|
|
128);
|
|
|
|
cd9660_pad_string_spaces(
|
2011-08-07 03:25:19 +04:00
|
|
|
diskStructure.primaryDescriptor.copyright_file_id, 37);
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_pad_string_spaces(
|
2011-08-07 03:25:19 +04:00
|
|
|
diskStructure.primaryDescriptor.abstract_file_id, 37);
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_pad_string_spaces(
|
2011-08-07 03:25:19 +04:00
|
|
|
diskStructure.primaryDescriptor.bibliographic_file_id, 37);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Setup dates */
|
|
|
|
time(&tim);
|
|
|
|
cd9660_time_8426(
|
|
|
|
(unsigned char *)diskStructure.primaryDescriptor.creation_date,
|
|
|
|
tim);
|
|
|
|
cd9660_time_8426(
|
|
|
|
(unsigned char *)diskStructure.primaryDescriptor.modification_date,
|
|
|
|
tim);
|
|
|
|
|
|
|
|
/*
|
|
|
|
cd9660_set_date(diskStructure.primaryDescriptor.expiration_date, now);
|
|
|
|
*/
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
memset(diskStructure.primaryDescriptor.expiration_date, '0' ,17);
|
|
|
|
cd9660_time_8426(
|
|
|
|
(unsigned char *)diskStructure.primaryDescriptor.effective_date,
|
|
|
|
tim);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cd9660_populate_iso_dir_record(struct _iso_directory_record_cd9660 *record,
|
|
|
|
u_char ext_attr_length, u_char flags,
|
|
|
|
u_char name_len, const char * name)
|
|
|
|
{
|
|
|
|
record->ext_attr_length[0] = ext_attr_length;
|
|
|
|
record->flags[0] = ISO_FLAG_CLEAR | flags;
|
|
|
|
record->file_unit_size[0] = 0;
|
|
|
|
record->interleave[0] = 0;
|
|
|
|
cd9660_bothendian_word(1, record->volume_sequence_number);
|
|
|
|
record->name_len[0] = name_len;
|
2008-10-30 21:43:13 +03:00
|
|
|
memset(record->name, '\0', sizeof (record->name));
|
2005-08-13 05:53:01 +04:00
|
|
|
memcpy(record->name, name, name_len);
|
|
|
|
record->length[0] = 33 + name_len;
|
|
|
|
|
|
|
|
/* Todo : better rounding */
|
|
|
|
record->length[0] += (record->length[0] & 1) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cd9660_setup_root_node(void)
|
|
|
|
{
|
|
|
|
cd9660_populate_iso_dir_record(diskStructure.rootNode->isoDirRecord,
|
|
|
|
0, ISO_FLAG_DIRECTORY, 1, "\0");
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********** SUPPORT FUNCTIONS ***********/
|
|
|
|
static int
|
|
|
|
cd9660_setup_volume_descriptors(void)
|
|
|
|
{
|
|
|
|
/* Boot volume descriptor should come second */
|
|
|
|
int sector = 16;
|
|
|
|
/* For now, a fixed 2 : PVD and terminator */
|
|
|
|
volume_descriptor *temp, *t;
|
|
|
|
|
|
|
|
/* Set up the PVD */
|
|
|
|
if ((temp = malloc(sizeof(volume_descriptor))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_setup_volume_descriptors");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
temp->volumeDescriptorData =
|
|
|
|
(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;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
sector++;
|
|
|
|
/* Set up boot support if enabled. BVD must reside in sector 17 */
|
|
|
|
if (diskStructure.is_bootable) {
|
|
|
|
if ((t = malloc(sizeof(volume_descriptor))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR(
|
|
|
|
"cd9660_setup_volume_descriptors");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((t->volumeDescriptorData = malloc(2048)) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR(
|
|
|
|
"cd9660_setup_volume_descriptors");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
temp->next = t;
|
|
|
|
temp = t;
|
|
|
|
memset(t->volumeDescriptorData, 0, 2048);
|
|
|
|
t->sector = 17;
|
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("Setting up boot volume descriptor\n");
|
2008-07-27 14:29:32 +04:00
|
|
|
cd9660_setup_boot_volume_descriptor(t);
|
2005-08-13 05:53:01 +04:00
|
|
|
sector++;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Set up the terminator */
|
|
|
|
if ((t = malloc(sizeof(volume_descriptor))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_setup_volume_descriptors");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((t->volumeDescriptorData = malloc(2048)) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_setup_volume_descriptors");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
temp->next = t;
|
|
|
|
memset(t->volumeDescriptorData, 0, 2048);
|
|
|
|
t->volumeDescriptorData[0] = ISO_VOLUME_DESCRIPTOR_TERMINATOR;
|
|
|
|
t->next = 0;
|
|
|
|
t->volumeDescriptorData[6] = 1;
|
|
|
|
t->sector = sector;
|
|
|
|
memcpy(t->volumeDescriptorData + 1,
|
|
|
|
ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
sector++;
|
|
|
|
return sector;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Populate EAR at some point. Not required, but is used by NetBSD's
|
|
|
|
* cd9660 support
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_fill_extended_attribute_record(cd9660node *node)
|
|
|
|
{
|
|
|
|
if ((node->isoExtAttributes =
|
|
|
|
malloc(sizeof(struct iso_extended_attributes))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_fill_extended_attribute_record");
|
|
|
|
exit(1);
|
|
|
|
};
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2010-11-19 18:47:32 +03:00
|
|
|
cd9660_translate_node_common(cd9660node *newnode)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
time_t tim;
|
|
|
|
int test;
|
|
|
|
u_char flag;
|
|
|
|
char temp[ISO_FILENAME_MAXLENGTH_WITH_PADDING];
|
|
|
|
|
|
|
|
/* Now populate the isoDirRecord structure */
|
|
|
|
memset(temp, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING);
|
|
|
|
|
2005-10-30 06:10:28 +03:00
|
|
|
test = cd9660_convert_filename(newnode->node->name,
|
2005-08-13 05:53:01 +04:00
|
|
|
temp, !(S_ISDIR(newnode->node->type)));
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
flag = ISO_FLAG_CLEAR;
|
|
|
|
if (S_ISDIR(newnode->node->type))
|
|
|
|
flag |= ISO_FLAG_DIRECTORY;
|
|
|
|
|
|
|
|
cd9660_populate_iso_dir_record(newnode->isoDirRecord, 0,
|
|
|
|
flag, strlen(temp), temp);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Set the various dates */
|
|
|
|
|
|
|
|
/* If we want to use the current date and time */
|
|
|
|
time(&tim);
|
|
|
|
|
|
|
|
cd9660_time_915(newnode->isoDirRecord->date, tim);
|
|
|
|
|
|
|
|
cd9660_bothendian_dword(newnode->fileDataLength,
|
|
|
|
newnode->isoDirRecord->size);
|
|
|
|
/* If the file is a link, we want to set the size to 0 */
|
|
|
|
if (S_ISLNK(newnode->node->type))
|
|
|
|
newnode->fileDataLength = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-19 18:47:32 +03:00
|
|
|
* Translate fsnode to cd9660node
|
2005-08-13 05:53:01 +04:00
|
|
|
* Translate filenames and other metadata, including dates, sizes,
|
|
|
|
* permissions, etc
|
|
|
|
* @param struct fsnode * The node generated by makefs
|
|
|
|
* @param struct cd9660node * The intermediate node to be written to
|
|
|
|
* @returns int 0 on failure, 1 on success
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_translate_node(fsnode *node, cd9660node *newnode)
|
|
|
|
{
|
|
|
|
if (node == NULL) {
|
|
|
|
if (diskStructure.verbose_level > 0)
|
|
|
|
printf("cd9660_translate_node: NULL node passed, "
|
|
|
|
"returning\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((newnode->isoDirRecord =
|
|
|
|
malloc(sizeof(iso_directory_record_cd9660))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_translate_node");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the node pointer */
|
|
|
|
newnode->node = node;
|
|
|
|
|
|
|
|
/* Set the size */
|
|
|
|
if (!(S_ISDIR(node->type)))
|
|
|
|
newnode->fileDataLength = node->inode->st.st_size;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2010-11-19 18:47:32 +03:00
|
|
|
if (cd9660_translate_node_common(newnode) == 0)
|
2005-08-13 05:53:01 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Finally, overwrite some of the values that are set by default */
|
|
|
|
cd9660_time_915(newnode->isoDirRecord->date, node->inode->st.st_mtime);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compares two ISO filenames
|
|
|
|
* @param const char * The first file name
|
|
|
|
* @param const char * The second file name
|
|
|
|
* @returns : -1 if first is less than second, 0 if they are the same, 1 if
|
|
|
|
* the second is greater than the first
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_compare_filename(const char *first, const char *second)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This can be made more optimal once it has been tested
|
|
|
|
* (the extra character, for example, is for testing)
|
|
|
|
*/
|
|
|
|
|
|
|
|
int p1 = 0;
|
|
|
|
int p2 = 0;
|
|
|
|
char c1, c2;
|
|
|
|
/* First, on the filename */
|
|
|
|
|
|
|
|
while (p1 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION-1
|
|
|
|
&& p2 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION-1) {
|
|
|
|
c1 = first[p1];
|
|
|
|
c2 = second[p2];
|
|
|
|
if (c1 == '.' && c2 =='.')
|
|
|
|
break;
|
|
|
|
else if (c1 == '.') {
|
|
|
|
p2++;
|
|
|
|
c1 = ' ';
|
|
|
|
} else if (c2 == '.') {
|
|
|
|
p1++;
|
|
|
|
c2 = ' ';
|
|
|
|
} else {
|
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c1 < c2)
|
|
|
|
return -1;
|
|
|
|
else if (c1 > c2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first[p1] == '.' && second[p2] == '.') {
|
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
while (p1 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION - 1
|
|
|
|
&& p2 < ISO_FILENAME_MAXLENGTH_BEFORE_VERSION - 1) {
|
|
|
|
c1 = first[p1];
|
|
|
|
c2 = second[p2];
|
|
|
|
if (c1 == ';' && c2 == ';')
|
|
|
|
break;
|
|
|
|
else if (c1 == ';') {
|
|
|
|
p2++;
|
|
|
|
c1 = ' ';
|
|
|
|
} else if (c2 == ';') {
|
|
|
|
p1++;
|
|
|
|
c2 = ' ';
|
|
|
|
} else {
|
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c1 < c2)
|
|
|
|
return -1;
|
|
|
|
else if (c1 > c2)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert a node into list with ISO sorting rules
|
|
|
|
* @param cd9660node * The head node of the list
|
|
|
|
* @param cd9660node * The node to be inserted
|
|
|
|
*/
|
2005-10-25 06:22:04 +04:00
|
|
|
static void
|
|
|
|
cd9660_sorted_child_insert(cd9660node *parent, cd9660node *cn_new)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
int compare;
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *cn;
|
|
|
|
struct cd9660_children_head *head = &parent->cn_children;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/* TODO: Optimize? */
|
2005-10-25 06:22:04 +04:00
|
|
|
cn_new->parent = parent;
|
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* first will either be 0, the . or the ..
|
|
|
|
* if . or .., this means no other entry may be written before first
|
|
|
|
* if 0, the new node may be inserted at the head
|
|
|
|
*/
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_FOREACH(cn, head, cn_next_child) {
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* Dont insert a node twice -
|
|
|
|
* that would cause an infinite loop
|
|
|
|
*/
|
2007-04-07 21:14:58 +04:00
|
|
|
if (cn_new == cn)
|
|
|
|
return;
|
2005-10-25 06:22:04 +04:00
|
|
|
|
|
|
|
compare = cd9660_compare_filename(cn_new->isoDirRecord->name,
|
|
|
|
cn->isoDirRecord->name);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (compare == 0)
|
2005-10-25 06:22:04 +04:00
|
|
|
compare = cd9660_compare_filename(cn_new->node->name,
|
|
|
|
cn->node->name);
|
|
|
|
|
|
|
|
if (compare < 0)
|
|
|
|
break;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-25 06:22:04 +04:00
|
|
|
if (cn == NULL)
|
|
|
|
TAILQ_INSERT_TAIL(head, cn_new, cn_next_child);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_BEFORE(cn, cn_new, cn_next_child);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-10-25 06:22:04 +04:00
|
|
|
* Called After cd9660_sorted_child_insert
|
2005-08-13 05:53:01 +04:00
|
|
|
* handles file collisions by suffixing each filname with ~n
|
|
|
|
* where n represents the files respective place in the ordering
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_handle_collisions(cd9660node *colliding, int past)
|
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *iter, *next, *prev;
|
2005-08-13 05:53:01 +04:00
|
|
|
int skip;
|
|
|
|
int delete_chars = 0;
|
|
|
|
int temp_past = past;
|
|
|
|
int temp_skip;
|
|
|
|
int flag = 0;
|
|
|
|
cd9660node *end_of_range;
|
2005-10-25 06:22:04 +04:00
|
|
|
|
|
|
|
for (iter = TAILQ_FIRST(&colliding->cn_children);
|
|
|
|
iter != NULL && (next = TAILQ_NEXT(iter, cn_next_child)) != NULL;) {
|
|
|
|
if (strcmp(iter->isoDirRecord->name,
|
|
|
|
next->isoDirRecord->name) != 0) {
|
|
|
|
iter = TAILQ_NEXT(iter, cn_next_child);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
flag = 1;
|
|
|
|
temp_skip = skip = cd9660_count_collisions(iter);
|
|
|
|
end_of_range = iter;
|
|
|
|
while (temp_skip > 0) {
|
|
|
|
temp_skip--;
|
|
|
|
end_of_range = TAILQ_NEXT(end_of_range, cn_next_child);
|
|
|
|
}
|
|
|
|
temp_past = past;
|
|
|
|
while (temp_past > 0) {
|
|
|
|
if ((next = TAILQ_NEXT(end_of_range, cn_next_child)) != NULL)
|
|
|
|
end_of_range = next;
|
|
|
|
else if ((prev = TAILQ_PREV(iter, cd9660_children_head, cn_next_child)) != NULL)
|
|
|
|
iter = prev;
|
|
|
|
else
|
|
|
|
delete_chars++;
|
|
|
|
temp_past--;
|
|
|
|
}
|
|
|
|
skip += past;
|
|
|
|
iter = cd9660_rename_filename(iter, skip, delete_chars);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
static cd9660node *
|
|
|
|
cd9660_rename_filename(cd9660node *iter, int num, int delete_chars)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int numbts, dot, semi, digit, digits, temp, powers, multiplier, count;
|
|
|
|
char *naming;
|
|
|
|
int maxlength;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (diskStructure.verbose_level > 0)
|
2005-10-30 06:10:28 +03:00
|
|
|
printf("Rename_filename called\n");
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/* TODO : A LOT of chanes regarding 8.3 filenames */
|
|
|
|
if (diskStructure.isoLevel == 1)
|
|
|
|
maxlength = 8;
|
|
|
|
else if (diskStructure.isoLevel == 2)
|
|
|
|
maxlength = 31;
|
|
|
|
else
|
|
|
|
maxlength = ISO_FILENAME_MAXLENGTH_BEFORE_VERSION;
|
|
|
|
|
2008-10-30 21:43:13 +03:00
|
|
|
tmp = malloc(ISO_FILENAME_MAXLENGTH_WITH_PADDING);
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
while (i < num) {
|
|
|
|
powers = 1;
|
|
|
|
count = 0;
|
|
|
|
digits = 1;
|
|
|
|
multiplier = 1;
|
|
|
|
while (((int)(i / powers) ) >= 10) {
|
|
|
|
digits++;
|
|
|
|
powers = powers * 10;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
naming = iter->o_name;
|
|
|
|
|
|
|
|
/*
|
|
|
|
while ((*naming != '.') && (*naming != ';')) {
|
|
|
|
naming++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
dot = -1;
|
|
|
|
semi = -1;
|
|
|
|
while (count < maxlength) {
|
|
|
|
if (*naming == '.')
|
|
|
|
dot = count;
|
|
|
|
else if (*naming == ';') {
|
|
|
|
semi = count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
naming++;
|
|
|
|
count++;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if ((count + digits) < maxlength)
|
|
|
|
numbts = count;
|
|
|
|
else
|
|
|
|
numbts = maxlength - (digits);
|
|
|
|
numbts -= delete_chars;
|
|
|
|
|
|
|
|
/* 8.3 rules - keep the extension, add before the dot */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code makes a bunch of assumptions.
|
|
|
|
* See if you can spot them all :)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (diskStructure.isoLevel == 1) {
|
|
|
|
numbts = 8 - digits - delete_chars;
|
|
|
|
if (dot < 0) {
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
} else {
|
|
|
|
if (dot < 8) {
|
|
|
|
memmove(&tmp[numbts],&tmp[dot],4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* (copying just the filename before the '.' */
|
|
|
|
memcpy(tmp, (iter->o_name), numbts);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* adding the appropriate number following the name */
|
|
|
|
temp = i;
|
|
|
|
while (digits > 0) {
|
|
|
|
digit = (int)(temp / powers);
|
|
|
|
temp = temp - digit * powers;
|
|
|
|
sprintf(&tmp[numbts] , "%d", digit);
|
|
|
|
digits--;
|
|
|
|
numbts++;
|
|
|
|
powers = powers / 10;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
while ((*naming != ';') && (numbts < maxlength)) {
|
|
|
|
tmp[numbts] = (*naming);
|
|
|
|
naming++;
|
|
|
|
numbts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp[numbts] = ';';
|
|
|
|
tmp[numbts+1] = '1';
|
2008-10-30 21:43:13 +03:00
|
|
|
tmp[numbts+2] = '\0';
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* now tmp has exactly the identifier
|
|
|
|
* we want so we'll copy it back to record
|
|
|
|
*/
|
2008-10-30 21:43:13 +03:00
|
|
|
memcpy((iter->isoDirRecord->name), tmp, numbts + 3);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
iter = TAILQ_NEXT(iter, cn_next_child);
|
2005-08-13 05:53:01 +04:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tmp);
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Todo: Figure out why these functions are nec. */
|
2005-10-30 06:10:28 +03:00
|
|
|
static void
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_copy_filenames(cd9660node *node)
|
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *cn;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
if (TAILQ_EMPTY(&node->cn_children))
|
2005-08-13 05:53:01 +04:00
|
|
|
return;
|
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
if (TAILQ_FIRST(&node->cn_children)->isoDirRecord == NULL) {
|
2005-08-13 05:53:01 +04:00
|
|
|
debug_print_tree(diskStructure.rootNode, 0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) {
|
|
|
|
cd9660_copy_filenames(cn);
|
|
|
|
memcpy(cn->o_name, cn->isoDirRecord->name,
|
2005-08-13 05:53:01 +04:00
|
|
|
ISO_FILENAME_MAXLENGTH_WITH_PADDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cd9660_sorting_nodes(cd9660node *node)
|
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *cn;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
|
|
|
|
cd9660_sorting_nodes(cn);
|
|
|
|
cd9660_sort_nodes(node);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
/* XXX Bubble sort. */
|
2005-08-13 05:53:01 +04:00
|
|
|
static void
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_sort_nodes(cd9660node *node)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *cn, *next;
|
|
|
|
|
|
|
|
do {
|
|
|
|
TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) {
|
|
|
|
if ((next = TAILQ_NEXT(cn, cn_next_child)) == NULL)
|
|
|
|
return;
|
|
|
|
else if (strcmp(next->isoDirRecord->name,
|
|
|
|
cn->isoDirRecord->name) >= 0)
|
|
|
|
continue;
|
|
|
|
TAILQ_REMOVE(&node->cn_children, next, cn_next_child);
|
2005-11-30 03:26:11 +03:00
|
|
|
TAILQ_INSERT_BEFORE(cn, next, cn_next_child);
|
2005-10-25 06:22:04 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (cn != NULL);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cd9660_count_collisions(cd9660node *copy)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *iter, *next;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
for (iter = copy;
|
|
|
|
(next = TAILQ_NEXT(iter, cn_next_child)) != NULL;
|
|
|
|
iter = next) {
|
|
|
|
if (cd9660_compare_filename(iter->isoDirRecord->name,
|
|
|
|
next->isoDirRecord->name) == 0)
|
|
|
|
count++;
|
2005-08-13 05:53:01 +04:00
|
|
|
else
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
#if 0
|
2005-10-25 06:22:04 +04:00
|
|
|
if ((next = TAILQ_NEXT(iter, cn_next_child)) != NULL) {
|
2005-10-30 06:10:28 +03:00
|
|
|
printf("cd9660_recurse_on_collision: count is %i \n", count);
|
2005-10-25 06:22:04 +04:00
|
|
|
compare = cd9660_compare_filename(iter->isoDirRecord->name,
|
|
|
|
next->isoDirRecord->name);
|
2005-08-13 05:53:01 +04:00
|
|
|
if (compare == 0) {
|
|
|
|
count++;
|
2005-10-25 06:22:04 +04:00
|
|
|
return cd9660_recurse_on_collision(next, count);
|
2005-08-13 05:53:01 +04:00
|
|
|
} else
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cd9660node *
|
|
|
|
cd9660_rrip_move_directory(cd9660node *dir)
|
|
|
|
{
|
|
|
|
char newname[9];
|
|
|
|
cd9660node *tfile;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function needs to:
|
|
|
|
* 1) Create an empty virtual file in place of the old directory
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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,
|
2007-04-07 21:14:58 +04:00
|
|
|
diskStructure.rootNode, dir);
|
2005-08-13 05:53:01 +04:00
|
|
|
if (diskStructure.rr_moved_dir == NULL)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a file with the same ORIGINAL name */
|
2007-04-07 21:14:58 +04:00
|
|
|
tfile = cd9660_create_file(dir->node->name, dir->parent, dir);
|
2005-08-13 05:53:01 +04:00
|
|
|
if (tfile == NULL)
|
|
|
|
return NULL;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
diskStructure.rock_ridge_move_count++;
|
2007-04-07 21:14:58 +04:00
|
|
|
snprintf(newname, sizeof(newname), "%08i",
|
|
|
|
diskStructure.rock_ridge_move_count);
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/* Point to old parent */
|
|
|
|
dir->rr_real_parent = dir->parent;
|
|
|
|
|
|
|
|
/* Place the placeholder file */
|
2005-10-25 06:22:04 +04:00
|
|
|
if (TAILQ_EMPTY(&dir->rr_real_parent->cn_children)) {
|
|
|
|
TAILQ_INSERT_HEAD(&dir->rr_real_parent->cn_children, tfile,
|
|
|
|
cn_next_child);
|
2005-08-13 05:53:01 +04:00
|
|
|
} else {
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_sorted_child_insert(dir->rr_real_parent, tfile);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Point to new parent */
|
|
|
|
dir->parent = diskStructure.rr_moved_dir;
|
|
|
|
|
|
|
|
/* Point the file to the moved directory */
|
|
|
|
tfile->rr_relocated = dir;
|
|
|
|
|
|
|
|
/* Actually move the directory */
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_sorted_child_insert(diskStructure.rr_moved_dir, dir);
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/* TODO: Inherit permissions / ownership (basically the entire inode) */
|
|
|
|
|
|
|
|
/* Set the new name */
|
|
|
|
memset(dir->isoDirRecord->name, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING);
|
|
|
|
strncpy(dir->isoDirRecord->name, newname, 8);
|
2011-05-29 21:07:57 +04:00
|
|
|
dir->isoDirRecord->length[0] = 34 + 8;
|
|
|
|
dir->isoDirRecord->name_len[0] = 8;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_add_dot_records(cd9660node *root)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
struct cd9660_children_head *head = &root->cn_children;
|
|
|
|
cd9660node *cn;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(cn, head, cn_next_child) {
|
|
|
|
if ((cn->type & CD9660_TYPE_DIR) == 0)
|
|
|
|
continue;
|
|
|
|
/* Recursion first */
|
|
|
|
cd9660_add_dot_records(cn);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_create_special_directory(CD9660_TYPE_DOT, root);
|
|
|
|
cd9660_create_special_directory(CD9660_TYPE_DOTDOT, root);
|
2005-08-13 05:53:01 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert node to cd9660 structure
|
|
|
|
* This function is designed to be called recursively on the root node of
|
|
|
|
* the filesystem
|
|
|
|
* Lots of recursion going on here, want to make sure it is efficient
|
|
|
|
* @param struct fsnode * The root node to be converted
|
|
|
|
* @param struct cd9660* The parent node (should not be NULL)
|
|
|
|
* @param int Current directory depth
|
|
|
|
* @param int* Running count of the number of directories that are being created
|
|
|
|
*/
|
2005-10-25 06:22:04 +04:00
|
|
|
static void
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_convert_structure(fsnode *root, cd9660node *parent_node, int level,
|
2006-10-10 05:55:45 +04:00
|
|
|
int *numDirectories, int *error)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
fsnode *iterator = root;
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *this_node;
|
2005-08-13 05:53:01 +04:00
|
|
|
int working_level;
|
|
|
|
int add;
|
|
|
|
int flag = 0;
|
|
|
|
int counter = 0;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* Newer, more efficient method, reduces recursion depth
|
|
|
|
*/
|
|
|
|
if (root == NULL) {
|
2005-10-25 06:22:04 +04:00
|
|
|
warnx("%s: root is null\n", __func__);
|
|
|
|
return;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test for an empty directory - makefs still gives us the . record */
|
|
|
|
if ((S_ISDIR(root->type)) && (root->name[0] == '.')
|
|
|
|
&& (root->name[1] == '\0')) {
|
|
|
|
root = root->next;
|
2005-10-25 06:22:04 +04:00
|
|
|
if (root == NULL)
|
|
|
|
return;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-25 06:22:04 +04:00
|
|
|
if ((this_node = cd9660_allocate_cd9660node()) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR(__func__);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* To reduce the number of recursive calls, we will iterate over
|
|
|
|
* the next pointers to the right.
|
|
|
|
*/
|
2005-10-25 06:22:04 +04:00
|
|
|
while (iterator != NULL) {
|
2005-08-13 05:53:01 +04:00
|
|
|
add = 1;
|
|
|
|
/*
|
|
|
|
* Increment the directory count if this is a directory
|
|
|
|
* Ignore "." entries. We will generate them later
|
|
|
|
*/
|
2005-10-25 06:22:04 +04:00
|
|
|
if (!S_ISDIR(iterator->type) ||
|
|
|
|
strcmp(iterator->name, ".") != 0) {
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
/* Translate the node, including its filename */
|
2005-10-25 06:22:04 +04:00
|
|
|
this_node->parent = parent_node;
|
|
|
|
cd9660_translate_node(iterator, this_node);
|
|
|
|
this_node->level = level;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
if (S_ISDIR(iterator->type)) {
|
2005-10-25 06:22:04 +04:00
|
|
|
(*numDirectories)++;
|
|
|
|
this_node->type = CD9660_TYPE_DIR;
|
2005-08-13 05:53:01 +04:00
|
|
|
working_level = level + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If at level 8, directory would be at 8
|
2005-10-30 06:10:28 +03:00
|
|
|
* and have children at 9 which is not
|
2005-08-13 05:53:01 +04:00
|
|
|
* allowed as per ISO spec
|
|
|
|
*/
|
|
|
|
if (level == 8) {
|
|
|
|
if ((!diskStructure.allow_deep_trees) &&
|
|
|
|
(!diskStructure.rock_ridge_enabled)) {
|
|
|
|
warnx("error: found entry "
|
|
|
|
"with depth greater "
|
|
|
|
"than 8.");
|
|
|
|
(*error) = 1;
|
2005-10-25 06:22:04 +04:00
|
|
|
return;
|
2005-08-13 05:53:01 +04:00
|
|
|
} else if (diskStructure.
|
|
|
|
rock_ridge_enabled) {
|
|
|
|
working_level = 3;
|
2005-10-30 06:10:28 +03:00
|
|
|
/*
|
2005-08-13 05:53:01 +04:00
|
|
|
* Moved directory is actually
|
|
|
|
* at level 2.
|
|
|
|
*/
|
2005-10-30 06:10:28 +03:00
|
|
|
this_node->level =
|
2005-08-13 05:53:01 +04:00
|
|
|
working_level - 1;
|
|
|
|
if (cd9660_rrip_move_directory(
|
2005-10-25 06:22:04 +04:00
|
|
|
this_node) == 0) {
|
2005-08-13 05:53:01 +04:00
|
|
|
warnx("Failure in "
|
|
|
|
"cd9660_rrip_"
|
|
|
|
"move_directory"
|
|
|
|
);
|
|
|
|
(*error) = 1;
|
2005-10-25 06:22:04 +04:00
|
|
|
return;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
add = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the recursive call on the children */
|
|
|
|
if (iterator->child != 0) {
|
2005-10-30 06:10:28 +03:00
|
|
|
cd9660_convert_structure(
|
2005-10-25 06:22:04 +04:00
|
|
|
iterator->child, this_node,
|
2005-08-13 05:53:01 +04:00
|
|
|
working_level,
|
2006-10-10 05:55:45 +04:00
|
|
|
numDirectories, error);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if ((*error) == 1) {
|
2005-10-25 06:22:04 +04:00
|
|
|
warnx("%s: Error on recursive "
|
|
|
|
"call", __func__);
|
|
|
|
return;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
} else {
|
2005-10-30 06:10:28 +03:00
|
|
|
/* Only directories should have children */
|
2005-08-13 05:53:01 +04:00
|
|
|
assert(iterator->child == NULL);
|
2005-10-25 06:22:04 +04:00
|
|
|
|
|
|
|
this_node->type = CD9660_TYPE_FILE;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* Finally, do a sorted insert
|
|
|
|
*/
|
|
|
|
if (add) {
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_sorted_child_insert(
|
|
|
|
parent_node, this_node);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Allocate new temp_node */
|
|
|
|
if (iterator->next != 0) {
|
2005-10-25 06:22:04 +04:00
|
|
|
this_node = cd9660_allocate_cd9660node();
|
|
|
|
if (this_node == NULL)
|
|
|
|
CD9660_MEM_ALLOC_ERROR(__func__);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator = iterator->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cd9660_handle_collisions(first_node); */
|
2005-10-25 06:22:04 +04:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* TODO: need cleanup */
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_copy_filenames(parent_node);
|
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
do {
|
2005-10-25 06:22:04 +04:00
|
|
|
flag = cd9660_handle_collisions(parent_node, counter);
|
2005-08-13 05:53:01 +04:00
|
|
|
counter++;
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_sorting_nodes(parent_node);
|
2005-08-13 05:53:01 +04:00
|
|
|
} while ((flag == 1) && (counter < 100));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up the cd9660node tree
|
|
|
|
* This is designed to be called recursively on the root node
|
|
|
|
* @param struct cd9660node *root The node to free
|
|
|
|
* @returns void
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cd9660_free_structure(cd9660node *root)
|
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *cn;
|
|
|
|
|
|
|
|
while ((cn = TAILQ_FIRST(&root->cn_children)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&root->cn_children, cn, cn_next_child);
|
|
|
|
cd9660_free_structure(cn);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-25 06:22:04 +04:00
|
|
|
free(root);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Be a little more memory conservative:
|
|
|
|
* instead of having the TAILQ_ENTRY as part of the cd9660node,
|
|
|
|
* just create a temporary structure
|
|
|
|
*/
|
|
|
|
struct ptq_entry
|
|
|
|
{
|
|
|
|
TAILQ_ENTRY(ptq_entry) ptq;
|
|
|
|
cd9660node *node;
|
|
|
|
} *n;
|
|
|
|
|
|
|
|
#define PTQUEUE_NEW(n,s,r,t){\
|
|
|
|
n = malloc(sizeof(struct s)); \
|
|
|
|
if (n == NULL) \
|
|
|
|
return r; \
|
|
|
|
n->node = t;\
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate the path tables
|
|
|
|
* The specific implementation of this function is left as an exercise to the
|
|
|
|
* programmer. It could be done recursively. Make sure you read how the path
|
|
|
|
* table has to be laid out, it has levels.
|
|
|
|
* @param struct iso9660_disk *disk The disk image
|
|
|
|
* @returns int The number of built path tables (between 1 and 4), 0 on failure
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_generate_path_table(void)
|
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *cn, *dirNode = diskStructure.rootNode;
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660node *last = dirNode;
|
|
|
|
int pathTableSize = 0; /* computed as we go */
|
|
|
|
int counter = 1; /* root gets a count of 0 */
|
|
|
|
int parentRecNum = 0; /* root's parent is '0' */
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
TAILQ_HEAD(cd9660_pt_head, ptq_entry) pt_head;
|
|
|
|
TAILQ_INIT(&pt_head);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
PTQUEUE_NEW(n, ptq_entry, -1, diskStructure.rootNode);
|
|
|
|
|
|
|
|
/* Push the root node */
|
|
|
|
TAILQ_INSERT_HEAD(&pt_head, n, ptq);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Breadth-first traversal of file structure */
|
|
|
|
while (pt_head.tqh_first != 0) {
|
|
|
|
n = pt_head.tqh_first;
|
|
|
|
dirNode = n->node;
|
|
|
|
TAILQ_REMOVE(&pt_head, pt_head.tqh_first, ptq);
|
|
|
|
free(n);
|
|
|
|
|
|
|
|
/* Update the size */
|
|
|
|
pathTableSize += ISO_PATHTABLE_ENTRY_BASESIZE
|
|
|
|
+ dirNode->isoDirRecord->name_len[0]+
|
|
|
|
(dirNode->isoDirRecord->name_len[0] % 2 == 0 ? 0 : 1);
|
|
|
|
/* includes the padding bit */
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
dirNode->ptnumber=counter;
|
|
|
|
if (dirNode != last) {
|
|
|
|
last->ptnext = dirNode;
|
|
|
|
dirNode->ptprev = last;
|
|
|
|
}
|
|
|
|
last = dirNode;
|
|
|
|
|
|
|
|
parentRecNum = 1;
|
|
|
|
if (dirNode->parent != 0)
|
|
|
|
parentRecNum = dirNode->parent->ptnumber;
|
|
|
|
|
|
|
|
/* Push children onto queue */
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_FOREACH(cn, &dirNode->cn_children, cn_next_child) {
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* Dont add the DOT and DOTDOT types to the path
|
|
|
|
* table.
|
|
|
|
*/
|
2005-10-25 06:22:04 +04:00
|
|
|
if ((cn->type != CD9660_TYPE_DOT)
|
|
|
|
&& (cn->type != CD9660_TYPE_DOTDOT)) {
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-10-25 06:22:04 +04:00
|
|
|
if (S_ISDIR(cn->node->type)) {
|
|
|
|
PTQUEUE_NEW(n, ptq_entry, -1, cn);
|
2005-08-13 05:53:01 +04:00
|
|
|
TAILQ_INSERT_TAIL(&pt_head, n, ptq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
return pathTableSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cd9660_compute_full_filename(cd9660node *node, char *buf, int level)
|
|
|
|
{
|
|
|
|
cd9660node *parent;
|
|
|
|
|
|
|
|
parent = (node->rr_real_parent == NULL ?
|
|
|
|
node->parent : node->rr_real_parent);
|
|
|
|
if (parent != NULL) {
|
|
|
|
cd9660_compute_full_filename(parent, buf, level + 1);
|
|
|
|
strcat(buf, node->node->name);
|
|
|
|
} else {
|
|
|
|
/* We are at the root */
|
|
|
|
strcat(buf, diskStructure.rootFilesystemPath);
|
|
|
|
if (buf[strlen(buf) - 1] == '/')
|
|
|
|
buf[strlen(buf) - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level != 0)
|
|
|
|
strcat(buf, "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NEW filename conversion method */
|
|
|
|
typedef int(*cd9660_filename_conversion_functor)(const char *, char *, int);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: These two functions are almost identical.
|
|
|
|
* Some code cleanup is possible here
|
2005-09-12 02:03:48 +04:00
|
|
|
*
|
|
|
|
* XXX bounds checking!
|
2005-08-13 05:53:01 +04:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_level1_convert_filename(const char *oldname, char *newname, int is_file)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ISO 9660 : 10.1
|
|
|
|
* File Name shall not contain more than 8 d or d1 characters
|
|
|
|
* File Name Extension shall not contain more than 3 d or d1 characters
|
|
|
|
* Directory Identifier shall not contain more than 8 d or d1 characters
|
|
|
|
*/
|
|
|
|
int namelen = 0;
|
|
|
|
int extlen = 0;
|
|
|
|
int found_ext = 0;
|
|
|
|
|
2011-08-23 23:57:24 +04:00
|
|
|
while (*oldname != '\0' && extlen < 3) {
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Handle period first, as it is special */
|
2011-08-23 23:57:24 +04:00
|
|
|
if (*oldname == '.') {
|
2005-08-13 05:53:01 +04:00
|
|
|
if (found_ext) {
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = '_';
|
2005-08-13 05:53:01 +04:00
|
|
|
extlen ++;
|
|
|
|
}
|
|
|
|
else {
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = '.';
|
2005-08-13 05:53:01 +04:00
|
|
|
found_ext = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2009-01-11 01:06:29 +03:00
|
|
|
/* cut RISC OS file type off ISO name */
|
|
|
|
if (diskStructure.archimedes_enabled &&
|
|
|
|
*oldname == ',' && strlen(oldname) == 4)
|
|
|
|
break;
|
2011-08-23 23:17:07 +04:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Enforce 12.3 / 8 */
|
2011-08-23 21:09:11 +04:00
|
|
|
if (namelen == 8 && !found_ext)
|
2005-08-13 05:53:01 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (islower((unsigned char)*oldname))
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = toupper((unsigned char)*oldname);
|
2005-08-13 05:53:01 +04:00
|
|
|
else if (isupper((unsigned char)*oldname)
|
2011-08-23 23:17:07 +04:00
|
|
|
|| isdigit((unsigned char)*oldname))
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = *oldname;
|
2005-08-13 05:53:01 +04:00
|
|
|
else
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = '_';
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
if (found_ext)
|
|
|
|
extlen++;
|
|
|
|
else
|
|
|
|
namelen++;
|
|
|
|
}
|
2011-08-23 23:17:07 +04:00
|
|
|
oldname++;
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-25 06:22:04 +04:00
|
|
|
if (is_file) {
|
|
|
|
if (!found_ext && !diskStructure.omit_trailing_period)
|
|
|
|
*newname++ = '.';
|
|
|
|
/* Add version */
|
|
|
|
sprintf(newname, ";%i", 1);
|
|
|
|
}
|
2005-08-13 05:53:01 +04:00
|
|
|
return namelen + extlen + found_ext;
|
|
|
|
}
|
|
|
|
|
2005-09-12 02:03:48 +04:00
|
|
|
/* XXX bounds checking! */
|
2005-08-13 05:53:01 +04:00
|
|
|
static int
|
|
|
|
cd9660_level2_convert_filename(const char *oldname, char *newname, int is_file)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ISO 9660 : 7.5.1
|
|
|
|
* File name : 0+ d or d1 characters
|
|
|
|
* separator 1 (.)
|
|
|
|
* File name extension : 0+ d or d1 characters
|
|
|
|
* separator 2 (;)
|
|
|
|
* File version number (5 characters, 1-32767)
|
|
|
|
* 1 <= Sum of File name and File name extension <= 30
|
|
|
|
*/
|
|
|
|
int namelen = 0;
|
|
|
|
int extlen = 0;
|
|
|
|
int found_ext = 0;
|
|
|
|
|
2011-08-23 21:09:11 +04:00
|
|
|
while (*oldname != '\0' && namelen + extlen < 30) {
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Handle period first, as it is special */
|
|
|
|
if (*oldname == '.') {
|
|
|
|
if (found_ext) {
|
2008-11-21 13:02:12 +03:00
|
|
|
if (diskStructure.allow_multidot) {
|
|
|
|
*newname++ = '.';
|
|
|
|
} else {
|
|
|
|
*newname++ = '_';
|
|
|
|
}
|
2005-08-13 05:53:01 +04:00
|
|
|
extlen ++;
|
|
|
|
}
|
|
|
|
else {
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = '.';
|
2005-08-13 05:53:01 +04:00
|
|
|
found_ext = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2009-01-11 01:06:29 +03:00
|
|
|
/* cut RISC OS file type off ISO name */
|
|
|
|
if (diskStructure.archimedes_enabled &&
|
|
|
|
*oldname == ',' && strlen(oldname) == 4)
|
|
|
|
break;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
if (islower((unsigned char)*oldname))
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = toupper((unsigned char)*oldname);
|
2005-08-13 05:53:01 +04:00
|
|
|
else if (isupper((unsigned char)*oldname) ||
|
|
|
|
isdigit((unsigned char)*oldname))
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = *oldname;
|
2008-11-21 13:02:12 +03:00
|
|
|
else if (diskStructure.allow_multidot &&
|
|
|
|
*oldname == '.') {
|
|
|
|
*newname++ = '.';
|
|
|
|
} else {
|
2005-09-12 02:03:48 +04:00
|
|
|
*newname++ = '_';
|
2008-11-21 13:02:12 +03:00
|
|
|
}
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
if (found_ext)
|
|
|
|
extlen++;
|
|
|
|
else
|
|
|
|
namelen++;
|
|
|
|
}
|
|
|
|
oldname ++;
|
|
|
|
}
|
2005-10-25 06:22:04 +04:00
|
|
|
if (is_file) {
|
|
|
|
if (!found_ext && !diskStructure.omit_trailing_period)
|
|
|
|
*newname++ = '.';
|
|
|
|
/* Add version */
|
|
|
|
sprintf(newname, ";%i", 1);
|
|
|
|
}
|
2005-08-13 05:53:01 +04:00
|
|
|
return namelen + extlen + found_ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int
|
|
|
|
cd9660_joliet_convert_filename(const char *oldname, char *newname, int is_file)
|
|
|
|
{
|
|
|
|
/* TODO: implement later, move to cd9660_joliet.c ?? */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a file name to ISO compliant file name
|
|
|
|
* @param char * oldname The original filename
|
|
|
|
* @param char ** newname The new file name, in the appropriate character
|
|
|
|
* set and of appropriate length
|
|
|
|
* @param int 1 if file, 0 if directory
|
|
|
|
* @returns int The length of the new string
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cd9660_convert_filename(const char *oldname, char *newname, int is_file)
|
|
|
|
{
|
|
|
|
/* NEW */
|
|
|
|
cd9660_filename_conversion_functor conversion_function = 0;
|
|
|
|
if (diskStructure.isoLevel == 1)
|
|
|
|
conversion_function = &cd9660_level1_convert_filename;
|
|
|
|
else if (diskStructure.isoLevel == 2)
|
|
|
|
conversion_function = &cd9660_level2_convert_filename;
|
|
|
|
return (*conversion_function)(oldname, newname, is_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cd9660_compute_record_size(cd9660node *node)
|
|
|
|
{
|
|
|
|
int size = node->isoDirRecord->length[0];
|
|
|
|
|
|
|
|
if (diskStructure.rock_ridge_enabled)
|
|
|
|
size += node->susp_entry_size;
|
2009-01-11 01:06:29 +03:00
|
|
|
size += node->su_tail_size;
|
|
|
|
size += size & 1; /* Ensure length of record is even. */
|
|
|
|
assert(size <= 254);
|
2005-08-13 05:53:01 +04:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cd9660_populate_dot_records(cd9660node *node)
|
|
|
|
{
|
|
|
|
node->dot_record->fileDataSector = node->fileDataSector;
|
|
|
|
memcpy(node->dot_record->isoDirRecord,node->isoDirRecord, 34);
|
|
|
|
node->dot_record->isoDirRecord->name_len[0] = 1;
|
|
|
|
node->dot_record->isoDirRecord->name[0] = 0;
|
|
|
|
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);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (node == diskStructure.rootNode) {
|
|
|
|
node->dot_dot_record->fileDataSector = node->fileDataSector;
|
|
|
|
memcpy(node->dot_dot_record->isoDirRecord,node->isoDirRecord,
|
|
|
|
34);
|
|
|
|
} else {
|
|
|
|
node->dot_dot_record->fileDataSector =
|
|
|
|
node->parent->fileDataSector;
|
|
|
|
memcpy(node->dot_dot_record->isoDirRecord,
|
|
|
|
node->parent->isoDirRecord,34);
|
|
|
|
}
|
|
|
|
node->dot_dot_record->isoDirRecord->name_len[0] = 1;
|
|
|
|
node->dot_dot_record->isoDirRecord->name[0] = 1;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @param struct cd9660node *node The node
|
|
|
|
* @param int The offset (in bytes) - SHOULD align to the beginning of a sector
|
|
|
|
* @returns int The total size of files and directory entries (should be
|
|
|
|
* a multiple of sector size)
|
|
|
|
*/
|
2010-10-27 22:51:34 +04:00
|
|
|
static int64_t
|
|
|
|
cd9660_compute_offsets(cd9660node *node, int64_t startOffset)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This function needs to compute the size of directory records and
|
|
|
|
* runs, file lengths, and set the appropriate variables both in
|
|
|
|
* cd9660node and isoDirEntry
|
|
|
|
*/
|
2010-10-27 22:51:34 +04:00
|
|
|
int64_t used_bytes = 0;
|
|
|
|
int64_t current_sector_usage = 0;
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660node *child;
|
2005-10-31 11:29:19 +03:00
|
|
|
fsinode *inode;
|
2010-10-27 22:51:34 +04:00
|
|
|
int64_t r;
|
2005-08-13 05:53:01 +04:00
|
|
|
|
|
|
|
assert(node != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE : There needs to be some special case detection for
|
|
|
|
* the "real root" node, since for it, node->node is undefined
|
|
|
|
*/
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
node->fileDataSector = -1;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (node->type & CD9660_TYPE_DIR) {
|
|
|
|
node->fileRecordSize = cd9660_compute_record_size(node);
|
|
|
|
/*Set what sector this directory starts in*/
|
|
|
|
node->fileDataSector =
|
|
|
|
CD9660_BLOCKS(diskStructure.sectorSize,startOffset);
|
2005-10-25 06:22:04 +04:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_bothendian_dword(node->fileDataSector,
|
|
|
|
node->isoDirRecord->extent);
|
2005-10-25 06:22:04 +04:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/*
|
|
|
|
* First loop over children, need to know the size of
|
|
|
|
* their directory records
|
|
|
|
*/
|
|
|
|
node->fileSectorsUsed = 1;
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_FOREACH(child, &node->cn_children, cn_next_child) {
|
2005-08-13 05:53:01 +04:00
|
|
|
node->fileDataLength +=
|
|
|
|
cd9660_compute_record_size(child);
|
|
|
|
if ((cd9660_compute_record_size(child) +
|
|
|
|
current_sector_usage) >=
|
|
|
|
diskStructure.sectorSize) {
|
|
|
|
current_sector_usage = 0;
|
|
|
|
node->fileSectorsUsed++;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
current_sector_usage +=
|
|
|
|
cd9660_compute_record_size(child);
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_bothendian_dword(node->fileSectorsUsed *
|
|
|
|
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;
|
2005-10-25 06:22:04 +04:00
|
|
|
|
|
|
|
for (child = TAILQ_NEXT(node->dot_dot_record, cn_next_child);
|
|
|
|
child != NULL; child = TAILQ_NEXT(child, cn_next_child)) {
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Directories need recursive call */
|
|
|
|
if (S_ISDIR(child->node->type)) {
|
|
|
|
r = cd9660_compute_offsets(child,
|
|
|
|
used_bytes + startOffset);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (r != -1)
|
|
|
|
used_bytes += r;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Explicitly set the . and .. records */
|
|
|
|
cd9660_populate_dot_records(node);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Finally, do another iteration to write the file data*/
|
2005-10-25 06:22:04 +04:00
|
|
|
for (child = TAILQ_NEXT(node->dot_dot_record, cn_next_child);
|
|
|
|
child != NULL;
|
|
|
|
child = TAILQ_NEXT(child, cn_next_child)) {
|
2005-08-13 05:53:01 +04:00
|
|
|
/* Files need extent set */
|
2005-10-25 06:22:04 +04:00
|
|
|
if (S_ISDIR(child->node->type))
|
|
|
|
continue;
|
|
|
|
child->fileRecordSize =
|
|
|
|
cd9660_compute_record_size(child);
|
|
|
|
|
2005-10-30 12:27:49 +03:00
|
|
|
child->fileSectorsUsed =
|
|
|
|
CD9660_BLOCKS(diskStructure.sectorSize,
|
|
|
|
child->fileDataLength);
|
|
|
|
|
2005-10-31 11:29:19 +03:00
|
|
|
inode = child->node->inode;
|
|
|
|
if ((inode->flags & FI_ALLOCATED) == 0) {
|
|
|
|
inode->ino =
|
2005-10-30 12:27:49 +03:00
|
|
|
CD9660_BLOCKS(diskStructure.sectorSize,
|
|
|
|
used_bytes + startOffset);
|
2005-10-31 11:29:19 +03:00
|
|
|
inode->flags |= FI_ALLOCATED;
|
2005-10-30 12:27:49 +03:00
|
|
|
used_bytes += child->fileSectorsUsed *
|
|
|
|
diskStructure.sectorSize;
|
2005-10-31 11:29:19 +03:00
|
|
|
} else {
|
|
|
|
INODE_WARNX(("%s: already allocated inode %d "
|
|
|
|
"data sectors at %" PRIu32, __func__,
|
|
|
|
(int)inode->st.st_ino, inode->ino));
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
2005-10-31 11:29:19 +03:00
|
|
|
child->fileDataSector = inode->ino;
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660_bothendian_dword(child->fileDataSector,
|
|
|
|
child->isoDirRecord->extent);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return used_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Might get rid of this func */
|
|
|
|
static int
|
|
|
|
cd9660_copy_stat_info(cd9660node *from, cd9660node *to, int file)
|
|
|
|
{
|
|
|
|
to->node->inode->st.st_dev = 0;
|
|
|
|
to->node->inode->st.st_ino = 0;
|
|
|
|
to->node->inode->st.st_size = 0;
|
|
|
|
to->node->inode->st.st_blksize = from->node->inode->st.st_blksize;
|
|
|
|
to->node->inode->st.st_atime = from->node->inode->st.st_atime;
|
|
|
|
to->node->inode->st.st_mtime = from->node->inode->st.st_mtime;
|
|
|
|
to->node->inode->st.st_ctime = from->node->inode->st.st_ctime;
|
|
|
|
to->node->inode->st.st_uid = from->node->inode->st.st_uid;
|
|
|
|
to->node->inode->st.st_gid = from->node->inode->st.st_gid;
|
|
|
|
to->node->inode->st.st_mode = from->node->inode->st.st_mode;
|
|
|
|
/* Clear out type */
|
|
|
|
to->node->inode->st.st_mode = to->node->inode->st.st_mode & ~(S_IFMT);
|
|
|
|
if (file)
|
|
|
|
to->node->inode->st.st_mode |= S_IFREG;
|
|
|
|
else
|
|
|
|
to->node->inode->st.st_mode |= S_IFDIR;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static cd9660node *
|
|
|
|
cd9660_create_virtual_entry(const char *name, cd9660node *parent, int file,
|
|
|
|
int insert)
|
|
|
|
{
|
|
|
|
cd9660node *temp;
|
|
|
|
fsnode * tfsnode;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
assert(parent != NULL);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
temp = cd9660_allocate_cd9660node();
|
|
|
|
if (temp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((tfsnode = malloc(sizeof(fsnode))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_create_virtual_entry");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assume for now name is a valid length */
|
|
|
|
if ((tfsnode->name = malloc(strlen(name) + 1)) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_create_virtual_entry");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((temp->isoDirRecord =
|
|
|
|
malloc(sizeof(iso_directory_record_cd9660))) == NULL) {
|
|
|
|
CD9660_MEM_ALLOC_ERROR("cd9660_create_virtual_entry");
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
strcpy(tfsnode->name, name);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
cd9660_convert_filename(tfsnode->name, temp->isoDirRecord->name, file);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
temp->node = tfsnode;
|
|
|
|
temp->parent = parent;
|
|
|
|
|
|
|
|
if (insert) {
|
|
|
|
if (temp->parent != NULL) {
|
|
|
|
temp->level = temp->parent->level + 1;
|
2005-10-25 06:22:04 +04:00
|
|
|
if (!TAILQ_EMPTY(&temp->parent->cn_children))
|
|
|
|
cd9660_sorted_child_insert(temp->parent, temp);
|
2005-08-13 05:53:01 +04:00
|
|
|
else
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_INSERT_HEAD(&temp->parent->cn_children,
|
|
|
|
temp, cn_next_child);
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->node != NULL) {
|
|
|
|
tfsnode->type = parent->node->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear out file type bits */
|
|
|
|
tfsnode->type &= ~(S_IFMT);
|
|
|
|
if (file)
|
|
|
|
tfsnode->type |= S_IFREG;
|
|
|
|
else
|
|
|
|
tfsnode->type |= S_IFDIR;
|
|
|
|
|
|
|
|
/* Indicate that there is no spec entry (inode) */
|
|
|
|
tfsnode->flags &= ~(FSNODE_F_HASSPEC);
|
|
|
|
#if 0
|
|
|
|
cd9660_copy_stat_info(parent, temp, file);
|
|
|
|
#endif
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cd9660node *
|
2007-04-07 21:14:58 +04:00
|
|
|
cd9660_create_file(const char * name, cd9660node *parent, cd9660node *me)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
cd9660node *temp;
|
|
|
|
|
|
|
|
temp = cd9660_create_virtual_entry(name,parent,1,1);
|
|
|
|
if (temp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
temp->fileDataLength = 0;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
temp->type = CD9660_TYPE_FILE | CD9660_TYPE_VIRTUAL;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2007-04-07 21:14:58 +04:00
|
|
|
if ((temp->node->inode = calloc(1, sizeof(fsinode))) == NULL)
|
|
|
|
return NULL;
|
|
|
|
*temp->node->inode = *me->node->inode;
|
|
|
|
|
2010-11-19 18:47:32 +03:00
|
|
|
if (cd9660_translate_node_common(temp) == 0)
|
2005-08-13 05:53:01 +04:00
|
|
|
return NULL;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new directory which does not exist on disk
|
|
|
|
* @param const char * name The name to assign to the directory
|
|
|
|
* @param const char * parent Pointer to the parent directory
|
|
|
|
* @returns cd9660node * Pointer to the new directory
|
|
|
|
*/
|
|
|
|
static cd9660node *
|
2007-04-07 21:14:58 +04:00
|
|
|
cd9660_create_directory(const char *name, cd9660node *parent, cd9660node *me)
|
2005-08-13 05:53:01 +04:00
|
|
|
{
|
|
|
|
cd9660node *temp;
|
|
|
|
|
|
|
|
temp = cd9660_create_virtual_entry(name,parent,0,1);
|
|
|
|
if (temp == NULL)
|
|
|
|
return NULL;
|
|
|
|
temp->node->type |= S_IFDIR;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
temp->type = CD9660_TYPE_DIR | CD9660_TYPE_VIRTUAL;
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2007-04-07 21:14:58 +04:00
|
|
|
if ((temp->node->inode = calloc(1, sizeof(fsinode))) == NULL)
|
|
|
|
return NULL;
|
|
|
|
*temp->node->inode = *me->node->inode;
|
|
|
|
|
2010-11-19 18:47:32 +03:00
|
|
|
if (cd9660_translate_node_common(temp) == 0)
|
2005-08-13 05:53:01 +04:00
|
|
|
return NULL;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cd9660node *
|
|
|
|
cd9660_create_special_directory(u_char type, cd9660node *parent)
|
|
|
|
{
|
2005-10-25 06:22:04 +04:00
|
|
|
cd9660node *temp, *first;
|
2005-08-13 05:53:01 +04:00
|
|
|
char na[2];
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
assert(parent != NULL);
|
2005-10-30 06:10:28 +03:00
|
|
|
|
2005-08-13 05:53:01 +04:00
|
|
|
if (type == CD9660_TYPE_DOT)
|
|
|
|
na[0] = 0;
|
|
|
|
else if (type == CD9660_TYPE_DOTDOT)
|
|
|
|
na[0] = 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
na[1] = 0;
|
|
|
|
if ((temp = cd9660_create_virtual_entry(na, parent, 0, 0)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
temp->parent = parent;
|
|
|
|
temp->type = type;
|
|
|
|
temp->isoDirRecord->length[0] = 34;
|
|
|
|
/* Dot record is always first */
|
|
|
|
if (type == CD9660_TYPE_DOT) {
|
|
|
|
parent->dot_record = temp;
|
2005-10-25 06:22:04 +04:00
|
|
|
TAILQ_INSERT_HEAD(&parent->cn_children, temp, cn_next_child);
|
2005-08-13 05:53:01 +04:00
|
|
|
/* DotDot should be second */
|
|
|
|
} else if (type == CD9660_TYPE_DOTDOT) {
|
|
|
|
parent->dot_dot_record = temp;
|
2005-10-25 06:22:04 +04:00
|
|
|
/*
|
|
|
|
* If the first child is the dot record, insert
|
|
|
|
* this second. Otherwise, insert it at the head.
|
|
|
|
*/
|
|
|
|
if ((first = TAILQ_FIRST(&parent->cn_children)) == NULL ||
|
|
|
|
(first->type & CD9660_TYPE_DOT) == 0) {
|
|
|
|
TAILQ_INSERT_HEAD(&parent->cn_children, temp,
|
|
|
|
cn_next_child);
|
|
|
|
} else {
|
|
|
|
TAILQ_INSERT_AFTER(&parent->cn_children, first, temp,
|
|
|
|
cn_next_child);
|
|
|
|
}
|
2005-08-13 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2008-05-10 23:00:07 +04:00
|
|
|
int
|
|
|
|
cd9660_add_generic_bootimage(const char *bootimage)
|
|
|
|
{
|
|
|
|
struct stat stbuf;
|
|
|
|
|
|
|
|
assert(bootimage != NULL);
|
|
|
|
|
|
|
|
if (*bootimage == '\0') {
|
|
|
|
warnx("Error: Boot image must be a filename");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
err(EXIT_FAILURE, "%s: lstat(\"%s\")", __func__,
|
|
|
|
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) {
|
|
|
|
printf("Generic boot image image has size %lld\n",
|
|
|
|
(long long)stbuf.st_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
diskStructure.has_generic_bootimage = 1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|