Module Name:    src
Committed By:   snj
Date:           Sat Jan  2 06:34:15 UTC 2010

Modified Files:
        src/usr.sbin/makefs [netbsd-5-0]: cd9660.c cd9660.h
        src/usr.sbin/makefs/cd9660 [netbsd-5-0]: cd9660_write.c iso9660_rrip.c
            iso9660_rrip.h

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #1198):
        usr.sbin/makefs/cd9660.c: revision 1.25 via patch
        usr.sbin/makefs/cd9660.h: revision 1.13 via patch
        usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
        usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
        usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support.  I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way.  Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it?  It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.


To generate a diff of this commit:
cvs rdiff -u -r1.22.2.1 -r1.22.2.1.2.1 src/usr.sbin/makefs/cd9660.c
cvs rdiff -u -r1.12 -r1.12.6.1 src/usr.sbin/makefs/cd9660.h
cvs rdiff -u -r1.9 -r1.9.6.1 src/usr.sbin/makefs/cd9660/cd9660_write.c
cvs rdiff -u -r1.4.20.3 -r1.4.20.4 src/usr.sbin/makefs/cd9660/iso9660_rrip.c
cvs rdiff -u -r1.4 -r1.4.28.1 src/usr.sbin/makefs/cd9660/iso9660_rrip.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makefs/cd9660.c
diff -u src/usr.sbin/makefs/cd9660.c:1.22.2.1 src/usr.sbin/makefs/cd9660.c:1.22.2.1.2.1
--- src/usr.sbin/makefs/cd9660.c:1.22.2.1	Mon Feb  2 03:32:34 2009
+++ src/usr.sbin/makefs/cd9660.c	Sat Jan  2 06:34:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660.c,v 1.22.2.1 2009/02/02 03:32:34 snj Exp $	*/
+/*	$NetBSD: cd9660.c,v 1.22.2.1.2.1 2010/01/02 06:34:15 snj Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -103,7 +103,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660.c,v 1.22.2.1 2009/02/02 03:32:34 snj Exp $");
+__RCSID("$NetBSD: cd9660.c,v 1.22.2.1.2.1 2010/01/02 06:34:15 snj Exp $");
 #endif  /* !__lint */
 
 #include <string.h>
@@ -187,6 +187,7 @@
 	temp->isoDirRecord = NULL;
 	temp->isoExtAttributes = NULL;
 	temp->rr_real_parent = temp->rr_relocated = NULL;
+	temp->su_tail_data = NULL;
 	return temp;
 }
 
@@ -1759,6 +1760,9 @@
 
 	if (diskStructure.rock_ridge_enabled)
 		size += node->susp_entry_size;
+	size += node->su_tail_size;
+	size += size & 1; /* Ensure length of record is even. */
+	assert(size <= 254);
 	return size;
 }
 

Index: src/usr.sbin/makefs/cd9660.h
diff -u src/usr.sbin/makefs/cd9660.h:1.12 src/usr.sbin/makefs/cd9660.h:1.12.6.1
--- src/usr.sbin/makefs/cd9660.h:1.12	Sun Jul 27 10:29:32 2008
+++ src/usr.sbin/makefs/cd9660.h	Sat Jan  2 06:34:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660.h,v 1.12 2008/07/27 10:29:32 reinoud Exp $	*/
+/*	$NetBSD: cd9660.h,v 1.12.6.1 2010/01/02 06:34:15 snj Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -208,6 +208,10 @@
 	int susp_dot_ce_length;
 	int susp_dot_dot_ce_length;
 
+	/* Data to put at the end of the System Use field */
+	int su_tail_size;
+	char *su_tail_data;
+
 	/*** PATH TABLE STUFF ***/
 	int level;			/*depth*/
 	int ptnumber;

Index: src/usr.sbin/makefs/cd9660/cd9660_write.c
diff -u src/usr.sbin/makefs/cd9660/cd9660_write.c:1.9 src/usr.sbin/makefs/cd9660/cd9660_write.c:1.9.6.1
--- src/usr.sbin/makefs/cd9660/cd9660_write.c:1.9	Sat May 10 19:00:07 2008
+++ src/usr.sbin/makefs/cd9660/cd9660_write.c	Sat Jan  2 06:34:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_write.c,v 1.9 2008/05/10 19:00:07 skrll Exp $	*/
+/*	$NetBSD: cd9660_write.c,v 1.9.6.1 2010/01/02 06:34:15 snj Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: cd9660_write.c,v 1.9 2008/05/10 19:00:07 skrll Exp $");
+__RCSID("$NetBSD: cd9660_write.c,v 1.9.6.1 2010/01/02 06:34:15 snj Exp $");
 #endif  /* !__lint */
 
 static int cd9660_write_volume_descriptors(FILE *);
@@ -48,7 +48,7 @@
 #if 0
 static int cd9660_write_buffered(FILE *, int, int, const unsigned char*);
 #endif
-static int cd9660_write_rr(FILE *, cd9660node *, int, int);
+static void cd9660_write_rr(FILE *, cd9660node *, int, int);
 
 /*
  * Write the image
@@ -271,7 +271,7 @@
 	int written;
 	iso_directory_record_cd9660 temp_record;
 	cd9660node *temp;
-	int ca = 0, rv = 0;
+	int rv = 0;
 
 	/* Todo : clean up variables */
 
@@ -343,31 +343,27 @@
 				    working_sector * diskStructure.sectorSize,
 				    SEEK_SET);
 			}
-
-			written = fwrite(&temp_record, 1, temp_record.length[0],
-			    fd);
-			ca = 0;
+			/* Write out the basic ISO directory record */
+			written = fwrite(&temp_record, 1,
+			    temp->isoDirRecord->length[0], fd);
 			if (diskStructure.rock_ridge_enabled) {
-				ca = cd9660_write_rr(fd, temp,
+				cd9660_write_rr(fd, temp,
 				    cur_sector_offset, working_sector);
 			}
-
+			fseek(fd,
+			    working_sector * diskStructure.sectorSize +
+			    cur_sector_offset + temp_record.length[0] -
+			    temp->su_tail_size,
+			    SEEK_SET);
+			if (temp->su_tail_size > 0)
+				fwrite(temp->su_tail_data, 1,
+				    temp->su_tail_size, fd);
 			if (ferror(fd)) {
 				warnx("%s: write error", __func__);
 				goto out;
 			}
 			cur_sector_offset += temp_record.length[0];
 
-			/*
-			 * If we had to go the the continuation area,
-			 * head back to where we should be.
-			 */
-			if (ca) {
-				fseek(fd,
-				    working_sector * diskStructure.sectorSize +
-					cur_sector_offset,
-				    SEEK_SET);
-			}
 		}
 
 		/*
@@ -476,37 +472,39 @@
 	return 1;
 }
 
-static int
+static void
 cd9660_write_rr(FILE *fd, cd9660node *writenode, int offset, int sector)
 {
 	int in_ca = 0;
 	struct ISO_SUSP_ATTRIBUTES *myattr;
 
 	offset += writenode->isoDirRecord->length[0];
-
+	fseek(fd, sector * diskStructure.sectorSize + offset, SEEK_SET);
 	/* Offset now points at the end of the record */
 	TAILQ_FOREACH(myattr, &writenode->head, rr_ll) {
-		fseek(fd,
-		    in_ca ? offset : sector*diskStructure.sectorSize + offset,
-		    SEEK_SET);
 		fwrite(&(myattr->attr), CD9660_SUSP_ENTRY_SIZE(myattr), 1, fd);
 
-		offset += CD9660_SUSP_ENTRY_SIZE(myattr);
 		if (!in_ca) {
-			if ((myattr->susp_type == SUSP_TYPE_SUSP) &&
-			    (myattr->entry_type == SUSP_ENTRY_SUSP_CE)) {
+			offset += CD9660_SUSP_ENTRY_SIZE(myattr);
+			if (myattr->last_in_suf) {
 				/*
 				 * Point the offset to the start of this
 				 * record's CE area
 				 */
-				offset = (diskStructure.
-					  susp_continuation_area_start_sector *
-					    diskStructure.sectorSize)
-					+ writenode->susp_entry_ce_start;
+				fseek(fd, (diskStructure.
+					susp_continuation_area_start_sector *
+					diskStructure.sectorSize)
+				    + writenode->susp_entry_ce_start,
+				    SEEK_SET);
 				in_ca = 1;
 			}
 		}
 	}
 
-	return in_ca;
+	/*
+	 * If we had to go the the continuation area, head back to
+	 * where we should be.
+	 */
+	if (in_ca)
+		fseek(fd, sector * diskStructure.sectorSize + offset, SEEK_SET);
 }

Index: src/usr.sbin/makefs/cd9660/iso9660_rrip.c
diff -u src/usr.sbin/makefs/cd9660/iso9660_rrip.c:1.4.20.3 src/usr.sbin/makefs/cd9660/iso9660_rrip.c:1.4.20.4
--- src/usr.sbin/makefs/cd9660/iso9660_rrip.c:1.4.20.3	Sat Jan  2 06:28:26 2010
+++ src/usr.sbin/makefs/cd9660/iso9660_rrip.c	Sat Jan  2 06:34:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: iso9660_rrip.c,v 1.4.20.3 2010/01/02 06:28:26 snj Exp $	*/
+/*	$NetBSD: iso9660_rrip.c,v 1.4.20.4 2010/01/02 06:34:15 snj Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: iso9660_rrip.c,v 1.4.20.3 2010/01/02 06:28:26 snj Exp $");
+__RCSID("$NetBSD: iso9660_rrip.c,v 1.4.20.4 2010/01/02 06:34:15 snj Exp $");
 #endif  /* !__lint */
 
 static void cd9660_rrip_initialize_inode(cd9660node *);
@@ -200,13 +200,17 @@
 static int
 cd9660_susp_handle_continuation_common(cd9660node *node, int space)
 {
-	int ca_used, susp_used, susp_used_last = 0, working;
-	struct ISO_SUSP_ATTRIBUTES *temp, *last = NULL, *CE;
+	int ca_used, susp_used, susp_used_pre_ce, working;
+	struct ISO_SUSP_ATTRIBUTES *temp, *pre_ce, *last, *CE, *ST;
 
+	pre_ce = last = NULL;
 	working = 254 - space;
+	if (node->su_tail_size > 0)
+		/* Allow 4 bytes for "ST" record. */
+		working -= node->su_tail_size + 4;
 	/* printf("There are %i bytes to work with\n",working); */
 
-	susp_used = 0;
+	susp_used_pre_ce = susp_used = 0;
 	ca_used = 0;
 	TAILQ_FOREACH(temp, &node->head, rr_ll) {
 		if (working < 0)
@@ -216,15 +220,17 @@
 		 * CD9660_SUSP_ENTRY_SIZE(temp));
 		 */
 		working -= CD9660_SUSP_ENTRY_SIZE(temp);
-		if (working >= 0)
+		if (working >= 0) {
+			last = temp;
 			susp_used += CD9660_SUSP_ENTRY_SIZE(temp);
+		}
 		if (working >= 28) {
 			/*
 			 * Remember the last entry after which we
 			 * could insert a "CE" entry.
 			 */
-			last = temp;
-			susp_used_last = susp_used;
+			pre_ce = last;
+			susp_used_pre_ce = susp_used;
 		}
 	}
 
@@ -234,16 +240,34 @@
 			SUSP_ENTRY_SUSP_CE, "CE", SUSP_LOC_ENTRY);
 		cd9660_susp_ce(CE, node);
 		/* This will automatically insert at the appropriate location */
-		TAILQ_INSERT_AFTER(&node->head, last, CE, rr_ll);
-		susp_used = susp_used_last + 28;
-
+		if (pre_ce != NULL)
+			TAILQ_INSERT_AFTER(&node->head, pre_ce, CE, rr_ll);
+		else
+			TAILQ_INSERT_HEAD(&node->head, CE, rr_ll);
+		last = CE;
+		susp_used = susp_used_pre_ce + 28;
 		/* Count how much CA data is necessary */
-		for (temp = TAILQ_NEXT(CE, rr_ll); temp != NULL;
+		for (temp = TAILQ_NEXT(last, rr_ll); temp != NULL;
 		     temp = TAILQ_NEXT(temp, rr_ll)) {
 			ca_used += CD9660_SUSP_ENTRY_SIZE(temp);
 		}
 	}
 
+	/* An ST entry is needed */
+	if (node->su_tail_size > 0) {
+		ST = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
+		    SUSP_ENTRY_SUSP_ST, "ST", SUSP_LOC_ENTRY);
+		cd9660_susp_st(ST, node);
+		if (last != NULL)
+			TAILQ_INSERT_AFTER(&node->head, last, ST, rr_ll);
+		else
+			TAILQ_INSERT_HEAD(&node->head, ST, rr_ll);
+		last = ST;
+		susp_used += 4;
+	}
+	if (last != NULL)
+		last->last_in_suf = 1;
+
 	node->susp_entry_size = susp_used;
 	node->susp_entry_ce_length = ca_used;
 
@@ -439,6 +463,7 @@
 
 	temp->susp_type = susp_type;
 	temp->entry_type = entry_type;
+	temp->last_in_suf = 0;
 	/* Phase this out */
 	temp->type_of[0] = type_id[0];
 	temp->type_of[1] = type_id[1];

Index: src/usr.sbin/makefs/cd9660/iso9660_rrip.h
diff -u src/usr.sbin/makefs/cd9660/iso9660_rrip.h:1.4 src/usr.sbin/makefs/cd9660/iso9660_rrip.h:1.4.28.1
--- src/usr.sbin/makefs/cd9660/iso9660_rrip.h:1.4	Wed Feb  1 22:19:35 2006
+++ src/usr.sbin/makefs/cd9660/iso9660_rrip.h	Sat Jan  2 06:34:15 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: iso9660_rrip.h,v 1.4 2006/02/01 22:19:35 dyoung Exp $	*/
+/*	$NetBSD: iso9660_rrip.h,v 1.4.28.1 2010/01/02 06:34:15 snj Exp $	*/
 
 /*
  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -203,6 +203,7 @@
 	SUSP_ENTRIES attr;
 	int type;
 	char type_of[2];
+	char last_in_suf;	/* last entry in the System Use Field? */
 	/* Dan's addons - will merge later. This allows use of a switch */
 	char susp_type; 	/* SUSP or RRIP */
 	char entry_type;	/* Record type */

Reply via email to