aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/makefs/cd9660
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/makefs/cd9660')
-rw-r--r--usr.sbin/makefs/cd9660/Makefile.inc5
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_archimedes.c126
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_archimedes.h52
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_conversion.c4
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_debug.c4
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_eltorito.c43
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_eltorito.h8
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_strings.c8
-rw-r--r--usr.sbin/makefs/cd9660/cd9660_write.c10
-rw-r--r--usr.sbin/makefs/cd9660/iso9660_rrip.c111
-rw-r--r--usr.sbin/makefs/cd9660/iso9660_rrip.h30
11 files changed, 132 insertions, 269 deletions
diff --git a/usr.sbin/makefs/cd9660/Makefile.inc b/usr.sbin/makefs/cd9660/Makefile.inc
index b5012a323699..ec949f1413dc 100644
--- a/usr.sbin/makefs/cd9660/Makefile.inc
+++ b/usr.sbin/makefs/cd9660/Makefile.inc
@@ -1,9 +1,6 @@
-# $FreeBSD$
-#
-
.PATH: ${SRCDIR}/cd9660
CFLAGS+=-I${SRCTOP}/sys/fs/cd9660/
SRCS+= cd9660_strings.c cd9660_debug.c cd9660_eltorito.c \
- cd9660_write.c cd9660_conversion.c iso9660_rrip.c cd9660_archimedes.c
+ cd9660_write.c cd9660_conversion.c iso9660_rrip.c
diff --git a/usr.sbin/makefs/cd9660/cd9660_archimedes.c b/usr.sbin/makefs/cd9660/cd9660_archimedes.c
deleted file mode 100644
index cf53e0123d24..000000000000
--- a/usr.sbin/makefs/cd9660/cd9660_archimedes.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/* $NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
-
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * 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).
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <assert.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <util.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(*arc) == 32);
- arc = ecalloc(1, sizeof(*arc));
-
- 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);
-}
diff --git a/usr.sbin/makefs/cd9660/cd9660_archimedes.h b/usr.sbin/makefs/cd9660/cd9660_archimedes.h
deleted file mode 100644
index 96e30336310b..000000000000
--- a/usr.sbin/makefs/cd9660/cd9660_archimedes.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* $NetBSD: cd9660_archimedes.h,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
-
-/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * 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
- *
- * $FreeBSD$
- */
-
-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 *);
diff --git a/usr.sbin/makefs/cd9660/cd9660_conversion.c b/usr.sbin/makefs/cd9660/cd9660_conversion.c
index 57a1c62a25b7..4ccc87e22661 100644
--- a/usr.sbin/makefs/cd9660/cd9660_conversion.c
+++ b/usr.sbin/makefs/cd9660/cd9660_conversion.c
@@ -1,7 +1,7 @@
/* $NetBSD: cd9660_conversion.c,v 1.4 2007/03/14 14:11:17 christos Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -36,8 +36,6 @@
#include "cd9660.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
static char cd9660_compute_gm_offset(time_t);
#if 0
diff --git a/usr.sbin/makefs/cd9660/cd9660_debug.c b/usr.sbin/makefs/cd9660/cd9660_debug.c
index b1e07fb85f0f..f49c5108f4c2 100644
--- a/usr.sbin/makefs/cd9660/cd9660_debug.c
+++ b/usr.sbin/makefs/cd9660/cd9660_debug.c
@@ -1,7 +1,7 @@
/* $NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -34,8 +34,6 @@
* OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/mount.h>
diff --git a/usr.sbin/makefs/cd9660/cd9660_eltorito.c b/usr.sbin/makefs/cd9660/cd9660_eltorito.c
index 3628a798db4c..dd5bf67b2b09 100644
--- a/usr.sbin/makefs/cd9660/cd9660_eltorito.c
+++ b/usr.sbin/makefs/cd9660/cd9660_eltorito.c
@@ -1,7 +1,7 @@
/* $NetBSD: cd9660_eltorito.c,v 1.23 2018/03/28 06:48:55 nonaka Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -39,7 +39,13 @@
#include <util.h>
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+/*
+ * Partition Status Information from Apple Tech Note 1189
+ */
+#define APPLE_PS_VALID 0x00000001 /* Entry is valid */
+#define APPLE_PS_ALLOCATED 0x00000002 /* Entry is allocated */
+#define APPLE_PS_READABLE 0x00000010 /* Entry is readable */
+#define APPLE_PS_WRITABLE 0x00000020 /* Entry is writable */
#ifdef DEBUG
#define ELTORITO_DPRINTF(__x) printf __x
@@ -366,6 +372,7 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
struct boot_catalog_entry *x86_head, *mac_head, *ppc_head, *efi_head,
*valid_entry, *default_entry, *temp, *head, **headp, *next;
struct cd9660_boot_image *tmp_disk;
+ uint8_t system;
headp = NULL;
x86_head = mac_head = ppc_head = efi_head = NULL;
@@ -377,12 +384,19 @@ cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
/* Point to catalog: For now assume it consumes one sector */
ELTORITO_DPRINTF(("Boot catalog will go in sector %d\n", first_sector));
diskStructure->boot_catalog_sector = first_sector;
- cd9660_bothendian_dword(first_sector,
- diskStructure->boot_descriptor->boot_catalog_pointer);
+ cd9660_731(first_sector,
+ diskStructure->boot_descriptor->boot_catalog_pointer);
+
+ /*
+ * Use system type of default image for validation entry. Fallback to
+ * X86 system type if not found.
+ */
+ system = default_boot_image != NULL ? default_boot_image->system :
+ ET_SYS_X86;
/* Step 1: Generate boot catalog */
/* Step 1a: Validation entry */
- valid_entry = cd9660_boot_setup_validation_entry(ET_SYS_X86);
+ valid_entry = cd9660_boot_setup_validation_entry(system);
if (valid_entry == NULL)
return -1;
@@ -540,7 +554,7 @@ cd9660_write_mbr_partition_entry(FILE *fd, int idx, off_t sector_start,
if (fseeko(fd, (off_t)(idx) * 16 + 0x1be, SEEK_SET) == -1)
err(1, "fseeko");
-
+
val = 0x80; /* Bootable */
fwrite(&val, sizeof(val), 1, fd);
@@ -574,15 +588,8 @@ cd9660_write_apm_partition_entry(FILE *fd, int idx, int total_partitions,
uint32_t apm32, part_status;
uint16_t apm16;
- /* See Apple Tech Note 1189 for the details about the pmPartStatus
- * flags.
- * Below the flags which are default:
- * - IsValid 0x01
- * - IsAllocated 0x02
- * - IsReadable 0x10
- * - IsWritable 0x20
- */
- part_status = 0x01 | 0x02 | 0x10 | 0x20;
+ part_status = APPLE_PS_VALID | APPLE_PS_ALLOCATED | APPLE_PS_READABLE |
+ APPLE_PS_WRITABLE;
if (fseeko(fd, (off_t)(idx + 1) * sector_size, SEEK_SET) == -1)
err(1, "fseeko");
@@ -610,7 +617,7 @@ cd9660_write_apm_partition_entry(FILE *fd, int idx, int total_partitions,
apm32 = 0;
/* pmLgDataStart */
fwrite(&apm32, sizeof(apm32), 1, fd);
- /* pmDataCnt */
+ /* pmDataCnt */
apm32 = htobe32(nsectors);
fwrite(&apm32, sizeof(apm32), 1, fd);
/* pmPartStatus */
@@ -659,9 +666,9 @@ cd9660_write_boot(iso9660_disk *diskStructure, FILE *fd)
}
cd9660_copy_file(diskStructure, fd, t->sector, t->filename);
- if (t->system == ET_SYS_MAC)
+ if (t->system == ET_SYS_MAC)
apm_partitions++;
- if (t->system == ET_SYS_PPC)
+ if (t->system == ET_SYS_PPC)
mbr_partitions++;
}
diff --git a/usr.sbin/makefs/cd9660/cd9660_eltorito.h b/usr.sbin/makefs/cd9660/cd9660_eltorito.h
index cbc3f8419e31..a9ad0901e1a7 100644
--- a/usr.sbin/makefs/cd9660/cd9660_eltorito.h
+++ b/usr.sbin/makefs/cd9660/cd9660_eltorito.h
@@ -1,7 +1,7 @@
/* $NetBSD: cd9660_eltorito.h,v 1.6 2017/01/24 11:22:43 nonaka Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -32,8 +32,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _CD9660_ELTORITO_H_
@@ -131,7 +129,7 @@ struct boot_catalog_entry {
char entry_type;
union {
boot_catalog_validation_entry VE;
- boot_catalog_initial_entry IE;
+ boot_catalog_initial_entry IE;
boot_catalog_section_header SH;
boot_catalog_section_entry SE;
boot_catalog_section_entry_extension EX;
@@ -144,7 +142,7 @@ struct boot_catalog_entry {
struct cd9660_boot_image {
char *filename;
int size;
- int sector; /* copied to LoadRBA */
+ int sector; /* copied to LoadRBA */
int num_sectors;
unsigned int loadSegment;
u_char targetMode;
diff --git a/usr.sbin/makefs/cd9660/cd9660_strings.c b/usr.sbin/makefs/cd9660/cd9660_strings.c
index 12d7566e463d..b3111fca6cd1 100644
--- a/usr.sbin/makefs/cd9660/cd9660_strings.c
+++ b/usr.sbin/makefs/cd9660/cd9660_strings.c
@@ -1,7 +1,7 @@
/* $NetBSD: cd9660_strings.c,v 1.4 2007/01/16 17:32:05 hubertf Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -36,8 +36,6 @@
#include <sys/mount.h>
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <ctype.h>
@@ -46,9 +44,9 @@ __FBSDID("$FreeBSD$");
void
-cd9660_uppercase_characters(char *str, int len)
+cd9660_uppercase_characters(char *str, size_t len)
{
- int p;
+ size_t p;
for (p = 0; p < len; p++) {
if (islower((unsigned char)str[p]) )
diff --git a/usr.sbin/makefs/cd9660/cd9660_write.c b/usr.sbin/makefs/cd9660/cd9660_write.c
index 71e884f792d9..828af11669c1 100644
--- a/usr.sbin/makefs/cd9660/cd9660_write.c
+++ b/usr.sbin/makefs/cd9660/cd9660_write.c
@@ -1,7 +1,7 @@
/* $NetBSD: cd9660_write.c,v 1.14 2011/01/04 09:48:21 wiz Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -38,8 +38,6 @@
#include "iso9660_rrip.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <util.h>
static int cd9660_write_volume_descriptors(iso9660_disk *, FILE *);
@@ -273,7 +271,7 @@ cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode)
/* Todo : clean up variables */
- temp_file_name = ecalloc(CD9660MAXPATH + 1, 1);
+ temp_file_name = ecalloc(PATH_MAX, 1);
buf = emalloc(diskStructure->sectorSize);
if ((writenode->level != 0) &&
!(writenode->node->type & S_IFDIR)) {
@@ -316,7 +314,7 @@ cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode)
/*
* Now loop over children, writing out their directory
* records - beware of sector boundaries
- */
+ */
TAILQ_FOREACH(temp, &writenode->cn_children, cn_next_child) {
/*
* Copy the temporary record and adjust its size
@@ -429,7 +427,6 @@ cd9660_copy_file(iso9660_disk *diskStructure, FILE *fd, off_t start_sector,
{
FILE *rf;
int bytes_read;
- off_t sector = start_sector;
int buf_size = diskStructure->sectorSize;
char *buf;
@@ -462,7 +459,6 @@ cd9660_copy_file(iso9660_disk *diskStructure, FILE *fd, off_t start_sector,
(void)fclose(rf);
return 0;
}
- sector++;
}
fclose(rf);
diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.c b/usr.sbin/makefs/cd9660/iso9660_rrip.c
index c5ef88d59de6..31c6e38a96fe 100644
--- a/usr.sbin/makefs/cd9660/iso9660_rrip.c
+++ b/usr.sbin/makefs/cd9660/iso9660_rrip.c
@@ -1,7 +1,7 @@
/* $NetBSD: iso9660_rrip.c,v 1.14 2014/05/30 13:14:47 martin Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -38,8 +38,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/queue.h>
#include <sys/types.h>
#include <stdio.h>
@@ -49,7 +47,7 @@ __FBSDID("$FreeBSD$");
#include "iso9660_rrip.h"
#include <util.h>
-static void cd9660_rrip_initialize_inode(cd9660node *);
+static void cd9660_rrip_initialize_inode(iso9660_disk *, cd9660node *);
static int cd9660_susp_handle_continuation(iso9660_disk *, cd9660node *);
static int cd9660_susp_handle_continuation_common(iso9660_disk *, cd9660node *,
int);
@@ -72,6 +70,11 @@ cd9660_susp_initialize(iso9660_disk *diskStructure, cd9660node *node,
if (node->dot_dot_record != 0)
TAILQ_INIT(&(node->dot_dot_record->head));
+ if (diskStructure->rr_inode_next == 0) {
+ RB_INIT(&diskStructure->rr_inode_map);
+ diskStructure->rr_inode_next = 1;
+ }
+
/* SUSP specific entries here */
if ((r = cd9660_susp_initialize_node(diskStructure, node)) < 0)
return r;
@@ -103,6 +106,7 @@ int
cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node)
{
cd9660node *temp;
+ struct inode_map_node *mapnode, *mapnodetmp;
int r;
assert(node != NULL);
@@ -119,6 +123,16 @@ cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node)
if ((r = cd9660_susp_finalize(diskStructure, temp)) < 0)
return r;
}
+
+ if (diskStructure->rr_inode_next != 0) {
+ RB_FOREACH_SAFE(mapnode, inode_map_tree,
+ &(diskStructure->rr_inode_map), mapnodetmp) {
+ RB_REMOVE(inode_map_tree,
+ &(diskStructure->rr_inode_map), mapnode);
+ free(mapnode);
+ }
+ diskStructure->rr_inode_next = 0;
+ }
return 1;
}
@@ -325,7 +339,7 @@ cd9660_susp_initialize_node(iso9660_disk *diskStructure, cd9660node *node)
}
static void
-cd9660_rrip_initialize_inode(cd9660node *node)
+cd9660_rrip_initialize_inode(iso9660_disk *diskStructure, cd9660node *node)
{
struct ISO_SUSP_ATTRIBUTES *attr;
@@ -339,7 +353,7 @@ cd9660_rrip_initialize_inode(cd9660node *node)
/* PX - POSIX attributes */
attr = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
- cd9660node_rrip_px(attr, node->node);
+ cd9660node_rrip_px(diskStructure, attr, node->node);
TAILQ_INSERT_TAIL(&node->head, attr, rr_ll);
@@ -392,7 +406,14 @@ cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node,
/* PX - POSIX attributes */
current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
- cd9660node_rrip_px(current, parent->node);
+ cd9660node_rrip_px(diskStructure, current,
+ parent->node);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+
+ /* TF - timestamp */
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_TF, "TF", SUSP_LOC_ENTRY);
+ cd9660node_rrip_tf(current, parent->node);
TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
}
} else if (node->type & CD9660_TYPE_DOTDOT) {
@@ -401,7 +422,14 @@ cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node,
/* PX - POSIX attributes */
current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
- cd9660node_rrip_px(current, grandparent->node);
+ cd9660node_rrip_px(diskStructure, current,
+ grandparent->node);
+ TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
+
+ /* TF - timestamp */
+ current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
+ SUSP_ENTRY_RRIP_TF, "TF", SUSP_LOC_ENTRY);
+ cd9660node_rrip_tf(current, grandparent->node);
TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
}
/* Handle PL */
@@ -412,28 +440,14 @@ cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node,
TAILQ_INSERT_TAIL(&node->head, current, rr_ll);
}
} else {
- cd9660_rrip_initialize_inode(node);
+ cd9660_rrip_initialize_inode(diskStructure, node);
- /*
- * Not every node needs a NM set - only if the name is
- * actually different. IE: If a file is TEST -> TEST,
- * no NM. test -> TEST, need a NM
- *
- * The rr_moved_dir needs to be assigned a NM record as well.
- */
if (node == diskStructure->rr_moved_dir) {
cd9660_rrip_add_NM(node, RRIP_DEFAULT_MOVE_DIR_NAME);
- }
- else if ((node->node != NULL) &&
- ((strlen(node->node->name) !=
- (uint8_t)node->isoDirRecord->name_len[0]) ||
- (memcmp(node->node->name,node->isoDirRecord->name,
- (uint8_t)node->isoDirRecord->name_len[0]) != 0))) {
+ } else if (node->node != NULL) {
cd9660_rrip_NM(node);
}
-
-
/* Rock ridge directory relocation code here. */
/* First handle the CL for the placeholder file. */
@@ -634,8 +648,45 @@ cd9660_createSL(cd9660node *node)
}
}
+static int
+inode_map_node_cmp(struct inode_map_node *a, struct inode_map_node *b)
+{
+ if (a->key < b->key)
+ return (-1);
+ if (a->key > b->key)
+ return (1);
+ return (0);
+}
+
+RB_GENERATE(inode_map_tree, inode_map_node, entry, inode_map_node_cmp);
+
+static uint64_t
+inode_map(iso9660_disk *diskStructure, uint64_t in)
+{
+ struct inode_map_node lookup = { .key = in };
+ struct inode_map_node *node;
+
+ /*
+ * Always assign an inode number if src inode unset. mtree mode leaves
+ * src inode unset for files with st_nlink == 1.
+ */
+ if (in != 0) {
+ node = RB_FIND(inode_map_tree, &(diskStructure->rr_inode_map),
+ &lookup);
+ if (node != NULL)
+ return (node->value);
+ }
+
+ node = emalloc(sizeof(struct inode_map_node));
+ node->key = in;
+ node->value = diskStructure->rr_inode_next++;
+ RB_INSERT(inode_map_tree, &(diskStructure->rr_inode_map), node);
+ return (node->value);
+}
+
int
-cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo)
+cd9660node_rrip_px(iso9660_disk *diskStructure, struct ISO_SUSP_ATTRIBUTES *v,
+ fsnode *pxinfo)
{
v->attr.rr_entry.PX.h.length[0] = 44;
v->attr.rr_entry.PX.h.version[0] = 1;
@@ -647,8 +698,8 @@ cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo)
v->attr.rr_entry.PX.uid);
cd9660_bothendian_dword(pxinfo->inode->st.st_gid,
v->attr.rr_entry.PX.gid);
- cd9660_bothendian_dword(pxinfo->inode->st.st_ino,
- v->attr.rr_entry.PX.serial);
+ cd9660_bothendian_dword(inode_map(diskStructure,
+ pxinfo->inode->st.st_ino), v->attr.rr_entry.PX.serial);
return 1;
}
@@ -699,11 +750,11 @@ cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *p, fsnode *_node)
*/
cd9660_time_915(p->attr.rr_entry.TF.timestamp,
- _node->inode->st.st_atime);
+ _node->inode->st.st_mtime);
p->attr.rr_entry.TF.h.length[0] += 7;
cd9660_time_915(p->attr.rr_entry.TF.timestamp + 7,
- _node->inode->st.st_mtime);
+ _node->inode->st.st_atime);
p->attr.rr_entry.TF.h.length[0] += 7;
cd9660_time_915(p->attr.rr_entry.TF.timestamp + 14,
@@ -756,7 +807,7 @@ cd9660_rrip_add_NM(cd9660node *node, const char *name)
struct ISO_SUSP_ATTRIBUTES *r;
/*
- * Each NM record has 254 byes to work with. This means that
+ * Each NM record has 254 bytes to work with. This means that
* the name data itself only has 249 bytes to work with. So, a
* name with 251 characters would require two nm records.
*/
diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.h b/usr.sbin/makefs/cd9660/iso9660_rrip.h
index 0c7b89ec860b..4c738d27ba45 100644
--- a/usr.sbin/makefs/cd9660/iso9660_rrip.h
+++ b/usr.sbin/makefs/cd9660/iso9660_rrip.h
@@ -1,7 +1,7 @@
/* $NetBSD: iso9660_rrip.h,v 1.5 2009/01/10 22:06:29 bjh21 Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
* Perez-Rathke and Ram Vedam. All rights reserved.
@@ -32,8 +32,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef __ISO9660_RRIP_H__
#define __ISO9660_RRIP_H__
@@ -52,17 +50,17 @@
#define PX_LENGTH 0x2C
#define PN_LENGTH 0x14
-#define TF_CREATION 0x00
-#define TF_MODIFY 0x01
-#define TF_ACCESS 0x02
-#define TF_ATTRIBUTES 0x04
-#define TF_BACKUP 0x08
-#define TF_EXPIRATION 0x10
-#define TF_EFFECTIVE 0x20
-#define TF_LONGFORM 0x40
-#define NM_CONTINUE 0x80
-#define NM_CURRENT 0x100
-#define NM_PARENT 0x200
+#define TF_CREATION 0x01
+#define TF_MODIFY 0x02
+#define TF_ACCESS 0x04
+#define TF_ATTRIBUTES 0x08
+#define TF_BACKUP 0x10
+#define TF_EXPIRATION 0x20
+#define TF_EFFECTIVE 0x40
+#define TF_LONG_FORM 0x80
+#define NM_CONTINUE 0x01
+#define NM_CURRENT 0x02
+#define NM_PARENT 0x04
#define SUSP_LOC_ENTRY 0x01
@@ -209,7 +207,7 @@ struct ISO_SUSP_ATTRIBUTES {
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 susp_type; /* SUSP or RRIP */
char entry_type; /* Record type */
char write_location;
TAILQ_ENTRY(ISO_SUSP_ATTRIBUTES) rr_ll;
@@ -226,7 +224,7 @@ int cd9660_susp_finalize_node(iso9660_disk *, cd9660node *);
int cd9660_rrip_finalize_node(cd9660node *);
/* POSIX File attribute */
-int cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
+int cd9660node_rrip_px(iso9660_disk *, struct ISO_SUSP_ATTRIBUTES *, fsnode *);
/* Device number */
int cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *, fsnode *);