Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Nov 2010 16:05:05 +0000 (UTC)
From:      Olivier Houchard <cognet@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r214921 - in head/usr.sbin/makefs: . cd9660 compat ffs
Message-ID:  <201011071605.oA7G55Yh057429@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cognet
Date: Sun Nov  7 16:05:04 2010
New Revision: 214921
URL: http://svn.freebsd.org/changeset/base/214921

Log:
  Sync with the latest version from NetBSD. It notably addds ISO9660 support.
  
  Submitted by:	bapt

Added:
  head/usr.sbin/makefs/cd9660/
  head/usr.sbin/makefs/cd9660.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660.h   (contents, props changed)
  head/usr.sbin/makefs/cd9660/Makefile.inc   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_archimedes.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_archimedes.h   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_conversion.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_debug.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_eltorito.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_eltorito.h   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_strings.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/cd9660_write.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/iso9660_rrip.c   (contents, props changed)
  head/usr.sbin/makefs/cd9660/iso9660_rrip.h   (contents, props changed)
  head/usr.sbin/makefs/compat/Makefile.inc   (contents, props changed)
  head/usr.sbin/makefs/ffs.h   (contents, props changed)
  head/usr.sbin/makefs/ffs/Makefile.inc   (contents, props changed)
Modified:
  head/usr.sbin/makefs/Makefile
  head/usr.sbin/makefs/ffs.c
  head/usr.sbin/makefs/ffs/buf.c
  head/usr.sbin/makefs/ffs/ffs_alloc.c
  head/usr.sbin/makefs/ffs/mkfs.c
  head/usr.sbin/makefs/makefs.8
  head/usr.sbin/makefs/makefs.c
  head/usr.sbin/makefs/makefs.h
  head/usr.sbin/makefs/walk.c

Modified: head/usr.sbin/makefs/Makefile
==============================================================================
--- head/usr.sbin/makefs/Makefile	Sun Nov  7 15:41:41 2010	(r214920)
+++ head/usr.sbin/makefs/Makefile	Sun Nov  7 16:05:04 2010	(r214921)
@@ -1,22 +1,23 @@
 #	$FreeBSD$
 
 PROG=	makefs
+
+CFLAGS+=-I${.CURDIR}
+
+SRCS=	cd9660.c ffs.c \
+	getid.c \
+	makefs.c \
+	walk.c
 MAN=	makefs.8
 
 WARNS?=	2
 
-CFLAGS+=-I${.CURDIR}
-SRCS=	ffs.c getid.c makefs.c walk.c
+.include "${.CURDIR}/cd9660/Makefile.inc"
+.include "${.CURDIR}/ffs/Makefile.inc"
+.include "${.CURDIR}/compat/Makefile.inc"
 
-.PATH:	${.CURDIR}/ffs
-CFLAGS+=-I${.CURDIR}/ffs
 CFLAGS+=-DHAVE_STRUCT_STAT_ST_FLAGS=1
 CFLAGS+=-DHAVE_STRUCT_STAT_ST_GEN=1
-SRCS+=	buf.c ffs_alloc.c ffs_balloc.c ffs_bswap.c ffs_subr.c mkfs.c ufs_bmap.c
-
-.PATH:	${.CURDIR}/compat
-CFLAGS+=-I${.CURDIR}/compat
-SRCS+=	pwcache.c strsuftoll.c
 
 .PATH:	${.CURDIR}/../mtree
 CFLAGS+=-I${.CURDIR}/../mtree

Added: head/usr.sbin/makefs/cd9660.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/usr.sbin/makefs/cd9660.c	Sun Nov  7 16:05:04 2010	(r214921)
@@ -0,0 +1,2154 @@
+/*	$NetBSD: cd9660.c,v 1.27 2010/10/27 18:51:34 christos Exp $	*/
+
+/*
+ * 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
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * 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.
+ *
+  */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#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"
+#include "cd9660/cd9660_archimedes.h"
+
+/*
+ * 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
+static void cd9660_sort_nodes(cd9660node *);
+static int cd9960_translate_node_common(cd9660node *);
+static int cd9660_translate_node(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 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 void cd9660_convert_structure(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);
+#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 *);
+static int64_t cd9660_compute_offsets(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 *,
+    cd9660node *);
+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;
+
+	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;
+	temp->su_tail_data = NULL;
+	return temp;
+}
+
+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;
+
+	/* 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.archimedes_enabled = 0;
+
+	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;
+
+	/* Make sure the PVD is clear */
+	memset(&diskStructure.primaryDescriptor, 0, 2048);
+
+	memset(diskStructure.primaryDescriptor.volume_set_id,	0x20,32);
+	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,128);
+	memset(diskStructure.primaryDescriptor.abstract_file_id, 0x20,128);
+	memset(diskStructure.primaryDescriptor.bibliographic_file_id, 0x20,128);
+
+	strcpy(diskStructure.primaryDescriptor.system_id,"NetBSD");
+
+	cd9660_defaults_set = 1;
+
+	/* Boot support: Initially disabled */
+	diskStructure.has_generic_bootimage = 0;
+	diskStructure.generic_bootimage = NULL;
+
+	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);
+}
+
+void
+cd9660_prep_opts(fsinfo_t *fsopts __unused)
+{
+	cd9660_set_defaults();
+}
+
+void
+cd9660_cleanup_opts(fsinfo_t *fsopts __unused)
+{
+
+}
+
+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"},
+		{ .name = NULL }
+	};
+
+	if (cd9660_defaults_set == 0)
+		cd9660_set_defaults();
+
+	/*
+	 * 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 }
+	}
+	*/
+
+	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);
+			}
+
+			/* BIG TODO: Add the max length function here */
+			cd9660_arguments_set_string(val, "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);
+	} 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;
+	else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "archimedes"))
+		diskStructure.archimedes_enabled = 1;
+	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"))
+		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);
+		
+		/* End of flag variables */
+        } 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);
+		}
+	} else {
+		if (val == NULL) {
+			warnx("Option `%s' doesn't contain a value", var);
+			rv = 0;
+		} else
+			rv = set_option(cd9660_options, var, val);
+	}
+
+	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)
+{
+	int64_t startoffset;
+	int numDirectories;
+	uint64_t pathTableSectors;
+	int64_t firstAvailableSector;
+	int64_t totalSpace;
+	int error;
+	cd9660node *real_root;
+
+	if (diskStructure.verbose_level > 0)
+		printf("cd9660_makefs: ISO level is %i\n",
+		    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) {
+		/*
+		 * Display help here - probably want to put it in
+		 * a separate function
+		 */
+		return;
+	}
+
+	diskStructure.rootFilesystemPath = dir;
+
+	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();
+	if ((real_root->isoDirRecord =
+		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;
+	real_root->node = root;
+	cd9660_convert_structure(root, real_root, 1, &numDirectories, &error);
+
+	if (TAILQ_EMPTY(&real_root->cn_children)) {
+		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");
+	}
+
+	/* 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");
+
+	/* non-SUSP extensions */
+	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);
+	}
+
+	/* Build path table structure */
+	diskStructure.pathTableLength = cd9660_generate_path_table();
+
+	pathTableSectors = CD9660_BLOCKS(diskStructure.sectorSize,
+		diskStructure.pathTableLength);
+
+	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;
+	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.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);
+
+	startoffset = diskStructure.sectorSize*diskStructure.dataFirstSector;
+
+	totalSpace = cd9660_compute_offsets(real_root, startoffset);
+
+	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();
+
+	/* Add padding sectors, just for testing purposes right now */
+	/* diskStructure.totalSectors+=150; */
+
+	/* Debugging output */
+	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);
+		printf("cd9660_makefs: File data starts in sector %"
+		    PRId64 "\n", diskStructure.dataFirstSector);
+		printf("cd9660_makefs: Total sectors: %"
+		    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;
+
+	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);
+	}
+
+	/* 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;
+
+	/* Copy the root directory record */
+	temp = (unsigned char *) &diskStructure.primaryDescriptor;
+
+	/* 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;
+
+	/* 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);
+
+	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,
+	    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(
+	    diskStructure.primaryDescriptor.copyright_file_id, 128);
+	cd9660_pad_string_spaces(
+		diskStructure.primaryDescriptor.abstract_file_id, 128);
+	cd9660_pad_string_spaces(
+		diskStructure.primaryDescriptor.bibliographic_file_id, 128);
+
+	/* 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);
+	*/
+
+	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;
+	memset(record->name, '\0', sizeof (record->name));
+	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");
+
+}
+
+/*********** 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;
+
+	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");
+		cd9660_setup_boot_volume_descriptor(t);
+		sector++;
+	}
+
+	/* 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);
+	}
+
+	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);
+
+	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);
+	};
+
+	return 1;
+}
+#endif
+
+static int
+cd9960_translate_node_common(cd9660node *newnode)
+{
+	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);
+
+	test = cd9660_convert_filename(newnode->node->name,
+		temp, !(S_ISDIR(newnode->node->type)));
+
+	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);
+
+	/* 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;
+}
+
+/*
+ * Translate fsnode to cd9960node
+ * 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;
+
+	if (cd9960_translate_node_common(newnode) == 0)
+		return 0;
+
+	/* Finally, overwrite some of the values that are set by default */
+	cd9660_time_915(newnode->isoDirRecord->date, node->inode->st.st_mtime);
+
+	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
+ */

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011071605.oA7G55Yh057429>