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.
This commit is contained in:
bjh21 2009-01-10 22:06:29 +00:00
parent 67cbe60826
commit f8474b32a7
9 changed files with 288 additions and 52 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.22 2008/08/29 00:02:25 gmcgarry Exp $
# $NetBSD: Makefile,v 1.23 2009/01/10 22:06:29 bjh21 Exp $
#
.include <bsd.own.mk>
@ -6,7 +6,7 @@
PROG= makefs
SRCS= buf.c \
cd9660.c cd9660_strings.c cd9660_debug.c cd9660_eltorito.c \
cd9660_write.c cd9660_conversion.c iso9660_rrip.c \
cd9660_write.c cd9660_conversion.c iso9660_rrip.c cd9660_archimedes.c \
ffs.c ffs_alloc.c ffs_balloc.c ffs_bswap.c ffs_subr.c ffs_tables.c \
getid.c \
makefs.c misc.c mkfs.c \

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd9660.c,v 1.24 2009/01/08 22:26:19 bjh21 Exp $ */
/* $NetBSD: cd9660.c,v 1.25 2009/01/10 22:06:29 bjh21 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.24 2009/01/08 22:26:19 bjh21 Exp $");
__RCSID("$NetBSD: cd9660.c,v 1.25 2009/01/10 22:06:29 bjh21 Exp $");
#endif /* !__lint */
#include <string.h>
@ -114,6 +114,7 @@ __RCSID("$NetBSD: cd9660.c,v 1.24 2009/01/08 22:26:19 bjh21 Exp $");
#include "makefs.h"
#include "cd9660.h"
#include "cd9660/iso9660_rrip.h"
#include "cd9660/cd9660_archimedes.h"
/*
* Global variables
@ -187,6 +188,7 @@ cd9660_allocate_cd9660node(void)
temp->isoDirRecord = NULL;
temp->isoExtAttributes = NULL;
temp->rr_real_parent = temp->rr_relocated = NULL;
temp->su_tail_data = NULL;
return temp;
}
@ -212,6 +214,8 @@ cd9660_set_defaults(void)
diskStructure.rock_ridge_move_count = 0;
diskStructure.rr_moved_dir = 0;
diskStructure.archimedes_enabled = 0;
diskStructure.include_padding_areas = 1;
/* Spec breaking functionality */
@ -394,6 +398,8 @@ cd9660_parse_opts(const char *option, fsinfo_t *fsopts)
/* 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"))
@ -524,6 +530,10 @@ cd9660_makefs(const char *image, const char *dir, fsnode *root,
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,
@ -1634,6 +1644,10 @@ cd9660_level1_convert_filename(const char *oldname, char *newname, int is_file)
found_ext = 1;
}
} else {
/* cut RISC OS file type off ISO name */
if (diskStructure.archimedes_enabled &&
*oldname == ',' && strlen(oldname) == 4)
break;
/* Enforce 12.3 / 8 */
if (((namelen == 8) && !found_ext) ||
(found_ext && extlen == 3)) {
@ -1697,6 +1711,10 @@ cd9660_level2_convert_filename(const char *oldname, char *newname, int is_file)
found_ext = 1;
}
} else {
/* cut RISC OS file type off ISO name */
if (diskStructure.archimedes_enabled &&
*oldname == ',' && strlen(oldname) == 4)
break;
if ((namelen + extlen) == 30)
break;
@ -1764,6 +1782,9 @@ cd9660_compute_record_size(cd9660node *node)
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;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd9660.h,v 1.12 2008/07/27 10:29:32 reinoud Exp $ */
/* $NetBSD: cd9660.h,v 1.13 2009/01/10 22:06:29 bjh21 Exp $ */
/*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@ -208,6 +208,10 @@ typedef struct _cd9660node {
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;
@ -283,6 +287,7 @@ typedef struct _iso9660_disk {
int rock_ridge_move_count;
cd9660node *rr_moved_dir;
int archimedes_enabled;
/* Spec breaking options */
u_char allow_deep_trees;

View File

@ -0,0 +1,132 @@
/* $NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
/*-
* Copyright (c) 1998, 2009 Ben Harris
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* cd9660_archimedes.c - support for RISC OS "ARCHIMEDES" extension
*
* RISC OS CDFS looks for a special block at the end of the System Use
* Field for each file. If present, this contains the RISC OS load
* and exec address (used to hold the file timestamp and type), the
* file attributes, and a flag indicating whether the first character
* of the filename should be replaced with '!' (since many special
* RISC OS filenames do).
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
__RCSID("$NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $");
#endif /* !__lint */
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "makefs.h"
#include "cd9660.h"
#include "cd9660_archimedes.h"
/*
* Convert a Unix time_t (non-leap seconds since 1970-01-01) to a RISC
* OS time (non-leap(?) centiseconds since 1900-01-01(?)).
*/
static u_int64_t
riscos_date(time_t unixtime)
{
u_int64_t base;
base = 31536000ULL * 70 + 86400 * 17;
return (((u_int64_t)unixtime) + base)*100;
}
/*
* Add "ARCHIMEDES" metadata to a node if that seems appropriate.
*
* We touch regular files with names matching /,[0-9a-f]{3}$/ and
* directories matching /^!/.
*/
static void
archimedes_convert_node(cd9660node *node)
{
struct ISO_ARCHIMEDES *arc;
size_t len;
int type = -1;
uint64_t stamp;
if (node->su_tail_data != NULL)
/* Something else already has the tail. */
return;
len = strlen(node->node->name);
if (len < 1) return;
if (len >= 4 && node->node->name[len-4] == ',')
/* XXX should support ,xxx and ,lxa */
type = strtoul(node->node->name + len - 3, NULL, 16);
if (type == -1 && node->node->name[0] != '!')
return;
if (type == -1) type = 0;
assert(sizeof(struct ISO_ARCHIMEDES) == 32);
if ((arc = calloc(1, sizeof(struct ISO_ARCHIMEDES))) == NULL) {
CD9660_MEM_ALLOC_ERROR("archimedes_convert_node");
exit(1);
}
stamp = riscos_date(node->node->inode->st.st_mtime);
memcpy(arc->magic, "ARCHIMEDES", 10);
cd9660_731(0xfff00000 | (type << 8) | (stamp >> 32), arc->loadaddr);
cd9660_731(stamp & 0x00ffffffffULL, arc->execaddr);
arc->ro_attr = RO_ACCESS_UR | RO_ACCESS_OR;
arc->cdfs_attr = node->node->name[0] == '!' ? CDFS_PLING : 0;
node->su_tail_data = (void *)arc;
node->su_tail_size = sizeof(*arc);
}
/*
* Add "ARCHIMEDES" metadata to an entire tree recursively.
*/
void
archimedes_convert_tree(cd9660node *node)
{
cd9660node *cn;
assert(node != NULL);
archimedes_convert_node(node);
/* Recurse on children. */
TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
archimedes_convert_tree(cn);
}

View File

@ -0,0 +1,48 @@
/* $NetBSD: cd9660_archimedes.h,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
/*-
* Copyright (c) 1998, 2009 Ben Harris
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* cd9660_archimedes.c - support for RISC OS "ARCHIMEDES" extension
*/
struct ISO_ARCHIMEDES {
char magic[10]; /* "ARCHIMEDES" */
unsigned char loadaddr[4]; /* Load address, little-endian */
unsigned char execaddr[4]; /* Exec address, little-endian */
unsigned char ro_attr; /* RISC OS attributes */
#define RO_ACCESS_UR 0x01 /* Owner read */
#define RO_ACCESS_UW 0x02 /* Owner write */
#define RO_ACCESS_L 0x04 /* Locked */
#define RO_ACCESS_OR 0x10 /* Public read */
#define RO_ACCESS_OW 0x20 /* Public write */
unsigned char cdfs_attr; /* Extra attributes for CDFS */
#define CDFS_PLING 0x01 /* Filename begins with '!' */
char reserved[12];
};
extern void archimedes_convert_tree(cd9660node *);

View File

@ -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.10 2009/01/10 22:06:29 bjh21 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.10 2009/01/10 22:06:29 bjh21 Exp $");
#endif /* !__lint */
static int cd9660_write_volume_descriptors(FILE *);
@ -48,7 +48,7 @@ static int cd9660_write_filedata(FILE *, int, const unsigned char *, int);
#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 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
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 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
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 @@ cd9660_copy_file(FILE *fd, int start_sector, const char *filename)
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);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: iso9660_rrip.c,v 1.7 2009/01/10 11:04:36 he Exp $ */
/* $NetBSD: iso9660_rrip.c,v 1.8 2009/01/10 22:06:29 bjh21 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.7 2009/01/10 11:04:36 he Exp $");
__RCSID("$NetBSD: iso9660_rrip.c,v 1.8 2009/01/10 22:06:29 bjh21 Exp $");
#endif /* !__lint */
static void cd9660_rrip_initialize_inode(cd9660node *);
@ -200,13 +200,17 @@ cd9660_rrip_finalize_node(cd9660node *node)
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_handle_continuation_common(cd9660node *node, int space)
* 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 @@ cd9660_susp_handle_continuation_common(cd9660node *node, int space)
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 @@ cd9660node_susp_create_node(int susp_type, int entry_type, const char *type_id,
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];

View File

@ -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.5 2009/01/10 22:06:29 bjh21 Exp $ */
/*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@ -203,6 +203,7 @@ struct ISO_SUSP_ATTRIBUTES {
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 */

View File

@ -1,4 +1,4 @@
.\" $NetBSD: makefs.8,v 1.30 2008/05/10 19:00:07 skrll Exp $
.\" $NetBSD: makefs.8,v 1.31 2009/01/10 22:06:29 bjh21 Exp $
.\"
.\" Copyright (c) 2001-2003 Wasabi Systems, Inc.
.\" All rights reserved.
@ -277,6 +277,12 @@ version id.
Allow multiple dots in a filename.
.It Sy applicationid
Application ID of the image.
.It Sy archimedes
Use the
.Ql ARCHIMEDES
extension to encode
.Tn RISC OS
metadata.
.It Sy boot-load-segment
Set load segment for the boot image.
.It Sy bootimage