Home | History | Annotate | Line # | Download | only in cd9660
iso9660_rrip.c revision 1.1
      1  1.1  fvdl /*	$NetBSD: iso9660_rrip.c,v 1.1 2005/08/13 01:53:01 fvdl Exp $	*/
      2  1.1  fvdl 
      3  1.1  fvdl /*
      4  1.1  fvdl  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
      5  1.1  fvdl  * Perez-Rathke and Ram Vedam.  All rights reserved.
      6  1.1  fvdl  *
      7  1.1  fvdl  * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
      8  1.1  fvdl  * Alan Perez-Rathke and Ram Vedam.
      9  1.1  fvdl  *
     10  1.1  fvdl  * Redistribution and use in source and binary forms, with or
     11  1.1  fvdl  * without modification, are permitted provided that the following
     12  1.1  fvdl  * conditions are met:
     13  1.1  fvdl  * 1. Redistributions of source code must retain the above copyright
     14  1.1  fvdl  *    notice, this list of conditions and the following disclaimer.
     15  1.1  fvdl  * 2. Redistributions in binary form must reproduce the above
     16  1.1  fvdl  *    copyright notice, this list of conditions and the following
     17  1.1  fvdl  *    disclaimer in the documentation and/or other materials provided
     18  1.1  fvdl  *    with the distribution.
     19  1.1  fvdl  *
     20  1.1  fvdl  * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
     21  1.1  fvdl  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
     22  1.1  fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     24  1.1  fvdl  * DISCLAIMED.  IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
     25  1.1  fvdl  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     28  1.1  fvdl  * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     29  1.1  fvdl  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  1.1  fvdl  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     32  1.1  fvdl  * OF SUCH DAMAGE.
     33  1.1  fvdl  */
     34  1.1  fvdl /* This will hold all the function definitions
     35  1.1  fvdl  * defined in iso9660_rrip.h
     36  1.1  fvdl  */
     37  1.1  fvdl 
     38  1.1  fvdl #include "makefs.h"
     39  1.1  fvdl #include "cd9660.h"
     40  1.1  fvdl #include "iso9660_rrip.h"
     41  1.1  fvdl #include <sys/queue.h>
     42  1.1  fvdl #include <stdio.h>
     43  1.1  fvdl 
     44  1.1  fvdl #include <sys/cdefs.h>
     45  1.1  fvdl #if defined(__RCSID) && !defined(__lint)
     46  1.1  fvdl __RCSID("$NetBSD: iso9660_rrip.c,v 1.1 2005/08/13 01:53:01 fvdl Exp $");
     47  1.1  fvdl #endif  /* !__lint */
     48  1.1  fvdl 
     49  1.1  fvdl static int cd9660_susp_handle_continuation(cd9660node *);
     50  1.1  fvdl static int cd9660_susp_handle_continuation_common(cd9660node *, int);
     51  1.1  fvdl static struct ISO_SUSP_ATTRIBUTES *cd9660_get_last_attribute(cd9660node *);
     52  1.1  fvdl 
     53  1.1  fvdl int
     54  1.1  fvdl cd9660_susp_initialize(cd9660node *node)
     55  1.1  fvdl {
     56  1.1  fvdl 	cd9660node *temp;
     57  1.1  fvdl 	int r;
     58  1.1  fvdl 
     59  1.1  fvdl 	temp = node;
     60  1.1  fvdl 
     61  1.1  fvdl 	/* Make sure the node is not NULL. If it is, there are major problems */
     62  1.1  fvdl 	assert(node != NULL);
     63  1.1  fvdl 
     64  1.1  fvdl 	while (temp != NULL) {
     65  1.1  fvdl 		if (!(temp->type & CD9660_TYPE_DOT) &&
     66  1.1  fvdl 		    !(temp->type & CD9660_TYPE_DOTDOT))
     67  1.1  fvdl 			LIST_INIT(&(temp->head));
     68  1.1  fvdl 		if (temp->dot_record != 0)
     69  1.1  fvdl 			LIST_INIT(&(temp->dot_record->head));
     70  1.1  fvdl 		if (temp->dot_dot_record != 0)
     71  1.1  fvdl 			LIST_INIT(&(temp->dot_dot_record->head));
     72  1.1  fvdl 
     73  1.1  fvdl 		 /* SUSP specific entries here */
     74  1.1  fvdl 		if ((r = cd9660_susp_initialize_node(temp)) < 0)
     75  1.1  fvdl 			return r;
     76  1.1  fvdl 
     77  1.1  fvdl 		/* currently called cd9660node_rrip_init_links */
     78  1.1  fvdl 		if ((r = cd9660_rrip_initialize_node(temp)) < 0)
     79  1.1  fvdl 			return r;
     80  1.1  fvdl 
     81  1.1  fvdl 		/*
     82  1.1  fvdl 		 * See if we need a CE record, and set all of the
     83  1.1  fvdl 		 * associated counters.
     84  1.1  fvdl 		 *
     85  1.1  fvdl 		 * This should be called after all extensions. After
     86  1.1  fvdl 		 * this is called, no new records should be added.
     87  1.1  fvdl 		 */
     88  1.1  fvdl 		if ((r = cd9660_susp_handle_continuation(temp)) < 0)
     89  1.1  fvdl 			return r;
     90  1.1  fvdl 
     91  1.1  fvdl 		/* Recurse on child entries */
     92  1.1  fvdl 		if (temp->child != NULL) {
     93  1.1  fvdl 			if ((r = cd9660_susp_initialize(temp->child)) < 0)
     94  1.1  fvdl 				return 0;
     95  1.1  fvdl 		}
     96  1.1  fvdl 		temp = temp->next;
     97  1.1  fvdl 	}
     98  1.1  fvdl 	return 1;
     99  1.1  fvdl }
    100  1.1  fvdl 
    101  1.1  fvdl int
    102  1.1  fvdl cd9660_susp_finalize(cd9660node *node)
    103  1.1  fvdl {
    104  1.1  fvdl 	cd9660node *temp;
    105  1.1  fvdl 	int r;
    106  1.1  fvdl 
    107  1.1  fvdl 	assert(node != NULL);
    108  1.1  fvdl 
    109  1.1  fvdl 	if (node == diskStructure.rootNode)
    110  1.1  fvdl 		diskStructure.susp_continuation_area_current_free = 0;
    111  1.1  fvdl 
    112  1.1  fvdl 	temp = node;
    113  1.1  fvdl 	while (temp != NULL) {
    114  1.1  fvdl 
    115  1.1  fvdl 		if ((r = cd9660_susp_finalize_node(temp)) < 0)
    116  1.1  fvdl 			return r;
    117  1.1  fvdl 		if ((r = cd9660_rrip_finalize_node(temp)) < 0)
    118  1.1  fvdl 			return r;
    119  1.1  fvdl 
    120  1.1  fvdl 		if (temp->child != NULL) {
    121  1.1  fvdl 			if ((r = cd9660_susp_finalize(temp->child)) < 0)
    122  1.1  fvdl 				return r;
    123  1.1  fvdl 		}
    124  1.1  fvdl 		temp = temp->next;
    125  1.1  fvdl 	}
    126  1.1  fvdl 	return 1;
    127  1.1  fvdl }
    128  1.1  fvdl 
    129  1.1  fvdl /*
    130  1.1  fvdl  * If we really wanted to speed things up, we could have some sort of
    131  1.1  fvdl  * lookup table on the SUSP entry type that calls a functor. Or, we could
    132  1.1  fvdl  * combine the functions. These functions are kept separate to allow
    133  1.1  fvdl  * easier addition of other extensions.
    134  1.1  fvdl 
    135  1.1  fvdl  * For the sake of simplicity and clarity, we won't be doing that for now.
    136  1.1  fvdl  */
    137  1.1  fvdl 
    138  1.1  fvdl /*
    139  1.1  fvdl  * SUSP needs to update the following types:
    140  1.1  fvdl  * CE (continuation area)
    141  1.1  fvdl  */
    142  1.1  fvdl int
    143  1.1  fvdl cd9660_susp_finalize_node(cd9660node *node)
    144  1.1  fvdl {
    145  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *t;
    146  1.1  fvdl 
    147  1.1  fvdl 	/* Handle CE counters */
    148  1.1  fvdl 	if (node->susp_entry_ce_length > 0) {
    149  1.1  fvdl 		node->susp_entry_ce_start =
    150  1.1  fvdl 		    diskStructure.susp_continuation_area_current_free;
    151  1.1  fvdl 		diskStructure.susp_continuation_area_current_free +=
    152  1.1  fvdl 		    node->susp_entry_ce_length;
    153  1.1  fvdl 	}
    154  1.1  fvdl 
    155  1.1  fvdl 	for (t = node->head.lh_first; t != NULL; t = t->rr_ll.le_next) {
    156  1.1  fvdl 		if (t->susp_type == SUSP_TYPE_SUSP &&
    157  1.1  fvdl 		    t->entry_type == SUSP_ENTRY_SUSP_CE) {
    158  1.1  fvdl 			cd9660_bothendian_dword(
    159  1.1  fvdl 				diskStructure.
    160  1.1  fvdl 				  susp_continuation_area_start_sector,
    161  1.1  fvdl 				t->attr.su_entry.CE.ca_sector);
    162  1.1  fvdl 
    163  1.1  fvdl 			cd9660_bothendian_dword(
    164  1.1  fvdl 				diskStructure.
    165  1.1  fvdl 				  susp_continuation_area_start_sector,
    166  1.1  fvdl 				t->attr.su_entry.CE.ca_sector);
    167  1.1  fvdl 			cd9660_bothendian_dword(node->susp_entry_ce_start,
    168  1.1  fvdl 				t->attr.su_entry.CE.offset);
    169  1.1  fvdl 			cd9660_bothendian_dword(node->susp_entry_ce_length,
    170  1.1  fvdl 				t->attr.su_entry.CE.length);
    171  1.1  fvdl 		}
    172  1.1  fvdl 	}
    173  1.1  fvdl 
    174  1.1  fvdl 	return 0;
    175  1.1  fvdl }
    176  1.1  fvdl 
    177  1.1  fvdl int
    178  1.1  fvdl cd9660_rrip_finalize_node(cd9660node *node)
    179  1.1  fvdl {
    180  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *t;
    181  1.1  fvdl 
    182  1.1  fvdl 	for (t = node->head.lh_first; t != NULL; t = t->rr_ll.le_next) {
    183  1.1  fvdl 		if (t->susp_type == SUSP_TYPE_RRIP) {
    184  1.1  fvdl 			switch (t->entry_type) {
    185  1.1  fvdl 			case SUSP_ENTRY_RRIP_CL:
    186  1.1  fvdl 				/* Look at rr_relocated*/
    187  1.1  fvdl 				if (node->rr_relocated == NULL)
    188  1.1  fvdl 					return -1;
    189  1.1  fvdl 				cd9660_bothendian_dword(
    190  1.1  fvdl 					node->rr_relocated->fileDataSector,
    191  1.1  fvdl 					(unsigned char *)
    192  1.1  fvdl 					    t->attr.rr_entry.CL.dir_loc);
    193  1.1  fvdl 				break;
    194  1.1  fvdl 			case SUSP_ENTRY_RRIP_PL:
    195  1.1  fvdl 				/* Look at rr_real_parent */
    196  1.1  fvdl 				if (node->rr_real_parent == NULL)
    197  1.1  fvdl 					return -1;
    198  1.1  fvdl 				cd9660_bothendian_dword(
    199  1.1  fvdl 					node->rr_real_parent->fileDataSector,
    200  1.1  fvdl 					(unsigned char *)
    201  1.1  fvdl 					    t->attr.rr_entry.PL.dir_loc);
    202  1.1  fvdl 				break;
    203  1.1  fvdl 			}
    204  1.1  fvdl 		}
    205  1.1  fvdl 	}
    206  1.1  fvdl 	return 0;
    207  1.1  fvdl }
    208  1.1  fvdl 
    209  1.1  fvdl static int
    210  1.1  fvdl cd9660_susp_handle_continuation_common(cd9660node *node, int space)
    211  1.1  fvdl {
    212  1.1  fvdl 	int working;
    213  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *temp, *last = NULL, *CE;
    214  1.1  fvdl 	int susp_used, ca_used;
    215  1.1  fvdl 
    216  1.1  fvdl 	working = 254 - space;
    217  1.1  fvdl 	/* printf("There are %i bytes to work with\n",working); */
    218  1.1  fvdl 
    219  1.1  fvdl 	susp_used = 0;
    220  1.1  fvdl 	ca_used = 0;
    221  1.1  fvdl 	for (temp = node->head.lh_first; (temp != NULL) && (working >= 0);
    222  1.1  fvdl 		temp = temp->rr_ll.le_next) {
    223  1.1  fvdl 			/*
    224  1.1  fvdl 			 * printf("SUSP Entry found, length is %i\n",
    225  1.1  fvdl 			 * CD9660_SUSP_ENTRY_SIZE(temp));
    226  1.1  fvdl 			 */
    227  1.1  fvdl 			working -= CD9660_SUSP_ENTRY_SIZE(temp);
    228  1.1  fvdl 			if (working >= 28) {
    229  1.1  fvdl 				last = temp;
    230  1.1  fvdl 				susp_used += CD9660_SUSP_ENTRY_SIZE(temp);
    231  1.1  fvdl 			}
    232  1.1  fvdl 	}
    233  1.1  fvdl 
    234  1.1  fvdl 	/* A CE entry is needed */
    235  1.1  fvdl 	if (working <= 0) {
    236  1.1  fvdl 		CE = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
    237  1.1  fvdl 			SUSP_ENTRY_SUSP_CE, "CE", SUSP_LOC_ENTRY);
    238  1.1  fvdl 		cd9660_susp_ce(CE, node);
    239  1.1  fvdl 		/* This will automatically insert at the appropriate location */
    240  1.1  fvdl 		cd9660node_susp_add_entry(node, last, CE, 0);
    241  1.1  fvdl 		susp_used += 28;
    242  1.1  fvdl 
    243  1.1  fvdl 		/* Count how much CA data is necessary */
    244  1.1  fvdl 		for (temp = CE->rr_ll.le_next; temp != NULL;
    245  1.1  fvdl 		     temp = temp->rr_ll.le_next) {
    246  1.1  fvdl 			ca_used += CD9660_SUSP_ENTRY_SIZE(temp);
    247  1.1  fvdl 		}
    248  1.1  fvdl 	}
    249  1.1  fvdl 
    250  1.1  fvdl 	node->susp_entry_size = susp_used;
    251  1.1  fvdl 	node->susp_entry_ce_length = ca_used;
    252  1.1  fvdl 
    253  1.1  fvdl 	diskStructure.susp_continuation_area_size += ca_used;
    254  1.1  fvdl 	return 1;
    255  1.1  fvdl }
    256  1.1  fvdl 
    257  1.1  fvdl /* See if a continuation entry is needed for each of the different types */
    258  1.1  fvdl static int
    259  1.1  fvdl cd9660_susp_handle_continuation(cd9660node *node)
    260  1.1  fvdl {
    261  1.1  fvdl 	assert (node != NULL);
    262  1.1  fvdl 
    263  1.1  fvdl 	/* Entry */
    264  1.1  fvdl 	if (cd9660_susp_handle_continuation_common(
    265  1.1  fvdl 		node,(int)(node->isoDirRecord->length[0])) < 0)
    266  1.1  fvdl 		return 0;
    267  1.1  fvdl 
    268  1.1  fvdl 	return 1;
    269  1.1  fvdl }
    270  1.1  fvdl 
    271  1.1  fvdl struct ISO_SUSP_ATTRIBUTES*
    272  1.1  fvdl cd9660node_susp_add_entry(cd9660node *node, struct ISO_SUSP_ATTRIBUTES *prev,
    273  1.1  fvdl 			  struct ISO_SUSP_ATTRIBUTES *current, int at_head)
    274  1.1  fvdl {
    275  1.1  fvdl 	if (at_head || prev == NULL)
    276  1.1  fvdl 		LIST_INSERT_HEAD(&(node->head), current, rr_ll);
    277  1.1  fvdl 	else {
    278  1.1  fvdl 		LIST_INSERT_AFTER(prev, current, rr_ll);
    279  1.1  fvdl 		prev = current;
    280  1.1  fvdl 	}
    281  1.1  fvdl 
    282  1.1  fvdl 	return current;
    283  1.1  fvdl }
    284  1.1  fvdl 
    285  1.1  fvdl int
    286  1.1  fvdl cd9660_susp_initialize_node(cd9660node *node)
    287  1.1  fvdl {
    288  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *temp;
    289  1.1  fvdl 
    290  1.1  fvdl 	/*
    291  1.1  fvdl 	 * Requirements/notes:
    292  1.1  fvdl 	 * CE: is added for us where needed
    293  1.1  fvdl 	 * ST: not sure if it is even required, but if so, should be
    294  1.1  fvdl 	 *     handled by the CE code
    295  1.1  fvdl 	 * PD: isnt needed (though might be added for testing)
    296  1.1  fvdl 	 * SP: is stored ONLY on the . record of the root directory
    297  1.1  fvdl 	 * ES: not sure
    298  1.1  fvdl 	 */
    299  1.1  fvdl 
    300  1.1  fvdl 	/* Check for root directory, add SP and ER if needed. */
    301  1.1  fvdl 	if (node->type & CD9660_TYPE_DOT) {
    302  1.1  fvdl 		if (node->parent == diskStructure.rootNode) {
    303  1.1  fvdl 			temp = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
    304  1.1  fvdl 				SUSP_ENTRY_SUSP_SP, "SP", SUSP_LOC_DOT);
    305  1.1  fvdl 			cd9660_susp_sp(temp, node);
    306  1.1  fvdl 
    307  1.1  fvdl 			/* Should be first entry. */
    308  1.1  fvdl 			temp = cd9660node_susp_add_entry(node, NULL, temp, 1);
    309  1.1  fvdl 		}
    310  1.1  fvdl 	}
    311  1.1  fvdl 	return 1;
    312  1.1  fvdl }
    313  1.1  fvdl 
    314  1.1  fvdl /*
    315  1.1  fvdl  * XXXfvdl use a TAILQ.
    316  1.1  fvdl  */
    317  1.1  fvdl static struct ISO_SUSP_ATTRIBUTES *
    318  1.1  fvdl cd9660_get_last_attribute(cd9660node *node)
    319  1.1  fvdl {
    320  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *t;
    321  1.1  fvdl 
    322  1.1  fvdl 	assert(node != NULL);
    323  1.1  fvdl 
    324  1.1  fvdl 	t = node->head.lh_first;
    325  1.1  fvdl 	if (t == NULL)
    326  1.1  fvdl 		return NULL;
    327  1.1  fvdl 	if (t->rr_ll.le_next == NULL)
    328  1.1  fvdl 		return t;
    329  1.1  fvdl 	for (; t->rr_ll.le_next != NULL; t = t->rr_ll.le_next) ;
    330  1.1  fvdl 	return t;
    331  1.1  fvdl }
    332  1.1  fvdl 
    333  1.1  fvdl int
    334  1.1  fvdl cd9660_rrip_initialize_node(cd9660node *node)
    335  1.1  fvdl {
    336  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *current = NULL;
    337  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *prev = NULL;
    338  1.1  fvdl 
    339  1.1  fvdl 	assert(node != NULL);
    340  1.1  fvdl 
    341  1.1  fvdl 	if (node->type & CD9660_TYPE_DOT) {
    342  1.1  fvdl 		/*
    343  1.1  fvdl 		 * Handle ER - should be the only entry to appear on
    344  1.1  fvdl 		 * a "." record
    345  1.1  fvdl 		 */
    346  1.1  fvdl 		if (node->parent == diskStructure.rootNode) {
    347  1.1  fvdl 			cd9660_susp_ER (cd9660_get_last_attribute(node),
    348  1.1  fvdl 				node, 1, SUSP_RRIP_ER_EXT_ID,
    349  1.1  fvdl 				SUSP_RRIP_ER_EXT_DES, SUSP_RRIP_ER_EXT_SRC);
    350  1.1  fvdl 		}
    351  1.1  fvdl 	} else if (node->type & CD9660_TYPE_DOTDOT) {
    352  1.1  fvdl 
    353  1.1  fvdl 	} else {
    354  1.1  fvdl 		if (node != NULL)
    355  1.1  fvdl 			prev = cd9660_get_last_attribute(node);
    356  1.1  fvdl 			/*
    357  1.1  fvdl 			 * Inode dependent values - this may change,
    358  1.1  fvdl 			 * but for now virtual files and directories do
    359  1.1  fvdl 			 * not have an inode structure
    360  1.1  fvdl 			 */
    361  1.1  fvdl 
    362  1.1  fvdl 		if ((node->node != NULL) && (node->node->inode != NULL)) {
    363  1.1  fvdl 			/* PX - POSIX attributes */
    364  1.1  fvdl 			current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    365  1.1  fvdl 				SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY);
    366  1.1  fvdl 			cd9660node_rrip_px(current, node->node);
    367  1.1  fvdl 
    368  1.1  fvdl 			prev = cd9660node_susp_add_entry(node, prev,
    369  1.1  fvdl 			    current, 0);
    370  1.1  fvdl 
    371  1.1  fvdl 			/* TF - timestamp */
    372  1.1  fvdl 			current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    373  1.1  fvdl 				SUSP_ENTRY_RRIP_TF, "TF", SUSP_LOC_ENTRY);
    374  1.1  fvdl 			cd9660node_rrip_tf(current, node->node);
    375  1.1  fvdl 			prev = cd9660node_susp_add_entry(node, prev,
    376  1.1  fvdl 			    current, 0);
    377  1.1  fvdl 
    378  1.1  fvdl 			/* SL - Symbolic link */
    379  1.1  fvdl 			/* ?????????? Dan - why is this here? */
    380  1.1  fvdl 			if (((node->child) == NULL) &&
    381  1.1  fvdl 				(node->node->inode != NULL) &&
    382  1.1  fvdl 				(S_ISLNK(node->node->inode->st.st_mode))) {
    383  1.1  fvdl 				current =
    384  1.1  fvdl 				    cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    385  1.1  fvdl 					SUSP_ENTRY_RRIP_SL, "SL",
    386  1.1  fvdl 					SUSP_LOC_ENTRY);
    387  1.1  fvdl 				prev = cd9660_createSL(prev, node);
    388  1.1  fvdl 
    389  1.1  fvdl 			}
    390  1.1  fvdl 
    391  1.1  fvdl 			/* PN - device number */
    392  1.1  fvdl 			if ((node->node->inode != NULL) &&
    393  1.1  fvdl 				((S_ISCHR(node->node->inode->st.st_mode) ||
    394  1.1  fvdl 				(S_ISBLK(node->node->inode->st.st_mode))))) {
    395  1.1  fvdl 				current =
    396  1.1  fvdl 				    cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    397  1.1  fvdl 					SUSP_ENTRY_RRIP_PN, "PN",
    398  1.1  fvdl 				  	SUSP_LOC_ENTRY);
    399  1.1  fvdl 				cd9660node_rrip_pn(current, node->node);
    400  1.1  fvdl 				prev = cd9660node_susp_add_entry(node, prev,
    401  1.1  fvdl 				    current, 0);
    402  1.1  fvdl 			}
    403  1.1  fvdl 		}
    404  1.1  fvdl 		/*
    405  1.1  fvdl 		 * Not every node needs a NM set - only if the name is
    406  1.1  fvdl 		 * actually different. IE: If a file is TEST -> TEST,
    407  1.1  fvdl 		 * no NM. test -> TEST, need a NM
    408  1.1  fvdl 		 *
    409  1.1  fvdl 		 * The rr_moved_dir needs to be assigned a NM record as well.
    410  1.1  fvdl 		 */
    411  1.1  fvdl 		if (node == diskStructure.rr_moved_dir) {
    412  1.1  fvdl 			cd9660_rrip_add_NM(cd9660_get_last_attribute(node),node,
    413  1.1  fvdl 				RRIP_DEFAULT_MOVE_DIR_NAME);
    414  1.1  fvdl 		}
    415  1.1  fvdl 		else if ((node->node != NULL) &&
    416  1.1  fvdl 			((strlen(node->node->name) !=
    417  1.1  fvdl 			    (int)node->isoDirRecord->name_len[0]) ||
    418  1.1  fvdl 			(memcmp(node->node->name,node->isoDirRecord->name,
    419  1.1  fvdl 				(int) node->isoDirRecord->name_len[0]) != 0))) {
    420  1.1  fvdl 			cd9660_rrip_NM(cd9660_get_last_attribute(node), node);
    421  1.1  fvdl 		}
    422  1.1  fvdl 
    423  1.1  fvdl 
    424  1.1  fvdl 
    425  1.1  fvdl 		/* Rock ridge directory relocation code here. */
    426  1.1  fvdl 
    427  1.1  fvdl 		/* First handle the CL for the placeholder file. */
    428  1.1  fvdl 		if (node->rr_relocated != NULL) {
    429  1.1  fvdl 			current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    430  1.1  fvdl 				SUSP_ENTRY_RRIP_CL, "CL", SUSP_LOC_ENTRY);
    431  1.1  fvdl 			cd9660_rrip_CL(current, node);
    432  1.1  fvdl 			prev = cd9660node_susp_add_entry(node, prev,
    433  1.1  fvdl 			    current, 0);
    434  1.1  fvdl 		}
    435  1.1  fvdl 
    436  1.1  fvdl 		/* Handle RE*/
    437  1.1  fvdl 		if (node->rr_real_parent != NULL) {
    438  1.1  fvdl 			current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    439  1.1  fvdl 				SUSP_ENTRY_RRIP_RE, "RE", SUSP_LOC_ENTRY);
    440  1.1  fvdl 			cd9660_rrip_RE(current,node);
    441  1.1  fvdl 			prev = cd9660node_susp_add_entry(node, prev,
    442  1.1  fvdl 			    current, 0);
    443  1.1  fvdl 
    444  1.1  fvdl 			/* Handle PL */
    445  1.1  fvdl 			current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    446  1.1  fvdl 				SUSP_ENTRY_RRIP_PL, "PL", SUSP_LOC_DOTDOT);
    447  1.1  fvdl 			cd9660_rrip_PL(current,node->dot_dot_record);
    448  1.1  fvdl 			cd9660node_susp_add_entry(node->dot_dot_record,
    449  1.1  fvdl 				cd9660_get_last_attribute(node->dot_dot_record),
    450  1.1  fvdl 				    current,0);
    451  1.1  fvdl 		}
    452  1.1  fvdl 	}
    453  1.1  fvdl 	return 1;
    454  1.1  fvdl }
    455  1.1  fvdl 
    456  1.1  fvdl struct ISO_SUSP_ATTRIBUTES*
    457  1.1  fvdl cd9660node_susp_create_node(int susp_type, int entry_type, const char *type_id,
    458  1.1  fvdl 			    int write_loc)
    459  1.1  fvdl {
    460  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES* temp;
    461  1.1  fvdl 
    462  1.1  fvdl 	if ((temp = malloc(sizeof(struct ISO_SUSP_ATTRIBUTES))) == NULL) {
    463  1.1  fvdl 		CD9660_MEM_ALLOC_ERROR("cd9660node_susp_create_node");
    464  1.1  fvdl 		exit(1);
    465  1.1  fvdl 	}
    466  1.1  fvdl 
    467  1.1  fvdl 	temp->susp_type = susp_type;
    468  1.1  fvdl 	temp->entry_type = entry_type;
    469  1.1  fvdl 	/* Phase this out */
    470  1.1  fvdl 	temp->type_of[0] = type_id[0];
    471  1.1  fvdl 	temp->type_of[1] = type_id[1];
    472  1.1  fvdl 	temp->write_location = write_loc;
    473  1.1  fvdl 
    474  1.1  fvdl 	/*
    475  1.1  fvdl 	 * Since the first four bytes is common, lets go ahead and
    476  1.1  fvdl 	 * set the type identifier, since we are passing that to this
    477  1.1  fvdl 	 * function anyhow.
    478  1.1  fvdl 	 */
    479  1.1  fvdl 	temp->attr.su_entry.SP.h.type[0] = type_id[0];
    480  1.1  fvdl 	temp->attr.su_entry.SP.h.type[1] = type_id[1];
    481  1.1  fvdl 	return temp;
    482  1.1  fvdl }
    483  1.1  fvdl 
    484  1.1  fvdl int
    485  1.1  fvdl cd9660_rrip_PL(struct ISO_SUSP_ATTRIBUTES*p, cd9660node *node)
    486  1.1  fvdl {
    487  1.1  fvdl 	p->attr.rr_entry.PL.h.length[0] = 12;
    488  1.1  fvdl 	p->attr.rr_entry.PL.h.version[0] = 1;
    489  1.1  fvdl 	return 1;
    490  1.1  fvdl }
    491  1.1  fvdl 
    492  1.1  fvdl int
    493  1.1  fvdl cd9660_rrip_CL(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *node)
    494  1.1  fvdl {
    495  1.1  fvdl 	p->attr.rr_entry.CL.h.length[0] = 12;
    496  1.1  fvdl 	p->attr.rr_entry.CL.h.version[0] = 1;
    497  1.1  fvdl 	return 1;
    498  1.1  fvdl }
    499  1.1  fvdl 
    500  1.1  fvdl int
    501  1.1  fvdl cd9660_rrip_RE(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *node)
    502  1.1  fvdl {
    503  1.1  fvdl 	p->attr.rr_entry.RE.h.length[0] = 0;
    504  1.1  fvdl 	p->attr.rr_entry.RE.h.version[0] = 1;
    505  1.1  fvdl 	return 1;
    506  1.1  fvdl }
    507  1.1  fvdl 
    508  1.1  fvdl struct ISO_SUSP_ATTRIBUTES *
    509  1.1  fvdl cd9660_createSL(struct ISO_SUSP_ATTRIBUTES *prev, cd9660node *node)
    510  1.1  fvdl {
    511  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES* current;
    512  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES* temp;
    513  1.1  fvdl 	int path_count, dir_count, done, i, j, dir_copied;
    514  1.1  fvdl 	char temp_cr[255];
    515  1.1  fvdl 	char temp_sl[255]; /* used in copying continuation entry*/
    516  1.1  fvdl 	char* sl_ptr;
    517  1.1  fvdl 
    518  1.1  fvdl 	sl_ptr = node->node->symlink;
    519  1.1  fvdl 
    520  1.1  fvdl 	done = 0;
    521  1.1  fvdl 	path_count = 0;
    522  1.1  fvdl 	dir_count = 0;
    523  1.1  fvdl 	dir_copied = 0;
    524  1.1  fvdl 	temp = prev;
    525  1.1  fvdl 	current = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    526  1.1  fvdl 	    SUSP_ENTRY_RRIP_SL, "SL", SUSP_LOC_ENTRY);
    527  1.1  fvdl 
    528  1.1  fvdl 	current->attr.rr_entry.SL.h.version[0] = 1;
    529  1.1  fvdl 	current->attr.rr_entry.SL.flags[0] = SL_FLAGS_NONE;
    530  1.1  fvdl 
    531  1.1  fvdl 	if (*sl_ptr == '/') {
    532  1.1  fvdl 		temp_cr[0] = SL_FLAGS_ROOT;
    533  1.1  fvdl 		temp_cr[1] = 0;
    534  1.1  fvdl 		memcpy(current->attr.rr_entry.SL.component + path_count,
    535  1.1  fvdl 		    temp_cr, 2);
    536  1.1  fvdl 		path_count += 2;
    537  1.1  fvdl 		sl_ptr++;
    538  1.1  fvdl 	}
    539  1.1  fvdl 
    540  1.1  fvdl 	for (i = 0; i < (dir_count + 2); i++)
    541  1.1  fvdl 		temp_cr[i] = '\0';
    542  1.1  fvdl 
    543  1.1  fvdl 	while (!done) {
    544  1.1  fvdl 		while ((*sl_ptr != '/') && (*sl_ptr != '\0')) {
    545  1.1  fvdl 			dir_copied = 1;
    546  1.1  fvdl 			if (*sl_ptr == '.') {
    547  1.1  fvdl 				if ((*(sl_ptr + 1) == '/') || (*(sl_ptr + 1)
    548  1.1  fvdl 				     == '\0')) {
    549  1.1  fvdl 					temp_cr[0] = SL_FLAGS_CURRENT;
    550  1.1  fvdl 					sl_ptr++;
    551  1.1  fvdl 				} else if(*(sl_ptr + 1) == '.') {
    552  1.1  fvdl 					if ((*(sl_ptr + 2) == '/') ||
    553  1.1  fvdl 					    (*(sl_ptr + 2) == '\0')) {
    554  1.1  fvdl 						temp_cr[0] = SL_FLAGS_PARENT;
    555  1.1  fvdl 						sl_ptr += 2;
    556  1.1  fvdl 					}
    557  1.1  fvdl 				} else {
    558  1.1  fvdl 					temp_cr[dir_count+2] = *sl_ptr;
    559  1.1  fvdl 					sl_ptr++;
    560  1.1  fvdl 					dir_count++;
    561  1.1  fvdl 				}
    562  1.1  fvdl 			} else {
    563  1.1  fvdl 				temp_cr[dir_count + 2] = *sl_ptr;
    564  1.1  fvdl 				sl_ptr++;
    565  1.1  fvdl 				dir_count++;
    566  1.1  fvdl 			}
    567  1.1  fvdl 		}
    568  1.1  fvdl 
    569  1.1  fvdl 		if ((path_count + dir_count) >= 249) {
    570  1.1  fvdl 			current->attr.rr_entry.SL.flags[0] |= SL_FLAGS_CONTINUE;
    571  1.1  fvdl 
    572  1.1  fvdl 			j = 0;
    573  1.1  fvdl 
    574  1.1  fvdl 			if (path_count <= 249) {
    575  1.1  fvdl 				while(j != (249 - path_count)) {
    576  1.1  fvdl 					temp_sl[j] = temp_cr[j];
    577  1.1  fvdl 					j++;
    578  1.1  fvdl 				}
    579  1.1  fvdl 				temp_sl[0] = SL_FLAGS_CONTINUE;
    580  1.1  fvdl 				temp_sl[1] = j - 2;
    581  1.1  fvdl 				memcpy(
    582  1.1  fvdl 				    current->attr.rr_entry.SL.component +
    583  1.1  fvdl 					path_count,
    584  1.1  fvdl 				    temp_sl, j);
    585  1.1  fvdl 			}
    586  1.1  fvdl 
    587  1.1  fvdl 			path_count += j;
    588  1.1  fvdl 			current->attr.rr_entry.SL.h.length[0] = path_count + 5;
    589  1.1  fvdl 			temp = cd9660node_susp_add_entry(node, temp,
    590  1.1  fvdl 			    current, 0);
    591  1.1  fvdl 			current= cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    592  1.1  fvdl 			       SUSP_ENTRY_RRIP_SL, "SL", SUSP_LOC_ENTRY);
    593  1.1  fvdl 			current->attr.rr_entry.SL.h.version[0] = 1;
    594  1.1  fvdl 			current->attr.rr_entry.SL.flags[0] = SL_FLAGS_NONE;
    595  1.1  fvdl 
    596  1.1  fvdl 			path_count = 0;
    597  1.1  fvdl 
    598  1.1  fvdl 			if (dir_count > 2) {
    599  1.1  fvdl 				while (j != dir_count + 2) {
    600  1.1  fvdl 					current->attr.rr_entry.SL.component[
    601  1.1  fvdl 					    path_count + 2] = temp_cr[j];
    602  1.1  fvdl 					j++;
    603  1.1  fvdl 					path_count++;
    604  1.1  fvdl 				}
    605  1.1  fvdl 				current->attr.rr_entry.SL.component[1]
    606  1.1  fvdl 				    = path_count;
    607  1.1  fvdl 				path_count+= 2;
    608  1.1  fvdl 			} else {
    609  1.1  fvdl 				while(j != dir_count) {
    610  1.1  fvdl 					current->attr.rr_entry.SL.component[
    611  1.1  fvdl 					    path_count+2] = temp_cr[j];
    612  1.1  fvdl 					j++;
    613  1.1  fvdl 					path_count++;
    614  1.1  fvdl 				}
    615  1.1  fvdl 			}
    616  1.1  fvdl 		} else {
    617  1.1  fvdl 			if (dir_copied == 1) {
    618  1.1  fvdl 				temp_cr[1] = dir_count;
    619  1.1  fvdl 				memcpy(current->attr.rr_entry.SL.component +
    620  1.1  fvdl 					path_count,
    621  1.1  fvdl 				    temp_cr, dir_count + 2);
    622  1.1  fvdl 				path_count += dir_count + 2;
    623  1.1  fvdl 			}
    624  1.1  fvdl 		}
    625  1.1  fvdl 
    626  1.1  fvdl 		if (*sl_ptr == '\0') {
    627  1.1  fvdl 			done = 1;
    628  1.1  fvdl 			current->attr.rr_entry.SL.h.length[0] = path_count + 5;
    629  1.1  fvdl 			temp = cd9660node_susp_add_entry(node, temp,
    630  1.1  fvdl 			    current, 0);
    631  1.1  fvdl 		} else {
    632  1.1  fvdl 			sl_ptr++;
    633  1.1  fvdl 			dir_count = 0;
    634  1.1  fvdl 			dir_copied = 0;
    635  1.1  fvdl 			for(i = 0; i < 255; i++) {
    636  1.1  fvdl 				temp_cr[i] = '\0';
    637  1.1  fvdl 			}
    638  1.1  fvdl 		}
    639  1.1  fvdl 	}
    640  1.1  fvdl 
    641  1.1  fvdl 	return temp;
    642  1.1  fvdl }
    643  1.1  fvdl 
    644  1.1  fvdl int
    645  1.1  fvdl cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *v, fsnode *pxinfo)
    646  1.1  fvdl {
    647  1.1  fvdl 	v->attr.rr_entry.PX.h.length[0] = 36;
    648  1.1  fvdl 	v->attr.rr_entry.PX.h.version[0] = 1;
    649  1.1  fvdl 	cd9660_bothendian_dword(pxinfo->inode->st.st_mode,
    650  1.1  fvdl 	    v->attr.rr_entry.PX.mode);
    651  1.1  fvdl 	cd9660_bothendian_dword(pxinfo->inode->st.st_nlink,
    652  1.1  fvdl 	    v->attr.rr_entry.PX.links);
    653  1.1  fvdl 	cd9660_bothendian_dword(pxinfo->inode->st.st_uid,
    654  1.1  fvdl 	    v->attr.rr_entry.PX.uid);
    655  1.1  fvdl 	cd9660_bothendian_dword(pxinfo->inode->st.st_gid,
    656  1.1  fvdl 	    v->attr.rr_entry.PX.gid);
    657  1.1  fvdl 
    658  1.1  fvdl 	/* Ignoring the serial number for now */
    659  1.1  fvdl 	return 1;
    660  1.1  fvdl }
    661  1.1  fvdl 
    662  1.1  fvdl int
    663  1.1  fvdl cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *pn_field, fsnode *fnode)
    664  1.1  fvdl {
    665  1.1  fvdl 	pn_field->attr.rr_entry.PN.h.length[0] = 20;
    666  1.1  fvdl 	pn_field->attr.rr_entry.PN.h.version[0] = 1;
    667  1.1  fvdl 
    668  1.1  fvdl 	if (sizeof (fnode->inode->st.st_dev) > 32)
    669  1.1  fvdl 		cd9660_bothendian_dword((uint64_t)fnode->inode->st.st_dev >> 32,
    670  1.1  fvdl 		    pn_field->attr.rr_entry.PN.high);
    671  1.1  fvdl 	else
    672  1.1  fvdl 		cd9660_bothendian_dword(0, pn_field->attr.rr_entry.PN.high);
    673  1.1  fvdl 
    674  1.1  fvdl 	cd9660_bothendian_dword(fnode->inode->st.st_dev & 0xffffffff,
    675  1.1  fvdl 		pn_field->attr.rr_entry.PN.low);
    676  1.1  fvdl 	return 1;
    677  1.1  fvdl }
    678  1.1  fvdl 
    679  1.1  fvdl #if 0
    680  1.1  fvdl int
    681  1.1  fvdl cd9660node_rrip_nm(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *file_node)
    682  1.1  fvdl {
    683  1.1  fvdl 	int nm_length = strlen(file_node->isoDirRecord->name) + 5;
    684  1.1  fvdl         p->attr.rr_entry.NM.h.type[0] = 'N';
    685  1.1  fvdl 	p->attr.rr_entry.NM.h.type[1] = 'M';
    686  1.1  fvdl 	sprintf(p->attr.rr_entry.NM.altname, "%s", file_node->isoDirRecord->name);
    687  1.1  fvdl 	p->attr.rr_entry.NM.h.length[0] = (unsigned char)nm_length;
    688  1.1  fvdl 	p->attr.rr_entry.NM.h.version[0] = (unsigned char)1;
    689  1.1  fvdl 	p->attr.rr_entry.NM.flags[0] = (unsigned char) NM_PARENT;
    690  1.1  fvdl 	return 1;
    691  1.1  fvdl }
    692  1.1  fvdl #endif
    693  1.1  fvdl 
    694  1.1  fvdl int
    695  1.1  fvdl cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *p, fsnode *_node)
    696  1.1  fvdl {
    697  1.1  fvdl 	p->attr.rr_entry.TF.flags[0] = TF_MODIFY | TF_ACCESS | TF_ATTRIBUTES;
    698  1.1  fvdl 	p->attr.rr_entry.TF.h.length[0] = 4;
    699  1.1  fvdl 	p->attr.rr_entry.TF.h.version[0] = 1;
    700  1.1  fvdl 
    701  1.1  fvdl 	/*
    702  1.1  fvdl 	 * Need to add creation time, backup time,
    703  1.1  fvdl 	 * expiration time, and effective time.
    704  1.1  fvdl 	 */
    705  1.1  fvdl 
    706  1.1  fvdl 	cd9660_time_915(p->attr.rr_entry.TF.timestamp,
    707  1.1  fvdl 		_node->inode->st.st_atime);
    708  1.1  fvdl 	p->attr.rr_entry.TF.h.length[0] += 7;
    709  1.1  fvdl 
    710  1.1  fvdl 	cd9660_time_915(p->attr.rr_entry.TF.timestamp + 7,
    711  1.1  fvdl 		_node->inode->st.st_mtime);
    712  1.1  fvdl 	p->attr.rr_entry.TF.h.length[0] += 7;
    713  1.1  fvdl 
    714  1.1  fvdl 	cd9660_time_915(p->attr.rr_entry.TF.timestamp + 14,
    715  1.1  fvdl 		_node->inode->st.st_ctime);
    716  1.1  fvdl 	p->attr.rr_entry.TF.h.length[0] += 7;
    717  1.1  fvdl 	return 1;
    718  1.1  fvdl }
    719  1.1  fvdl 
    720  1.1  fvdl int
    721  1.1  fvdl cd9660_susp_sp(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *spinfo)
    722  1.1  fvdl {
    723  1.1  fvdl 	p->attr.su_entry.SP.h.length[0] = 7;
    724  1.1  fvdl 	p->attr.su_entry.SP.h.version[0] = 1;
    725  1.1  fvdl 	p->attr.su_entry.SP.check[0] = 0xBE;
    726  1.1  fvdl 	p->attr.su_entry.SP.check[1] = 0xEF;
    727  1.1  fvdl 	p->attr.su_entry.SP.len_skp[0] = 0;
    728  1.1  fvdl 	return 1;
    729  1.1  fvdl }
    730  1.1  fvdl 
    731  1.1  fvdl int
    732  1.1  fvdl cd9660_susp_st(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *stinfo)
    733  1.1  fvdl {
    734  1.1  fvdl 	p->attr.su_entry.ST.h.type[0] = 'S';
    735  1.1  fvdl 	p->attr.su_entry.ST.h.type[1] = 'T';
    736  1.1  fvdl 	p->attr.su_entry.ST.h.length[0] = 4;
    737  1.1  fvdl 	p->attr.su_entry.ST.h.version[0] = 1;
    738  1.1  fvdl 	return 1;
    739  1.1  fvdl }
    740  1.1  fvdl 
    741  1.1  fvdl int
    742  1.1  fvdl cd9660_susp_ce(struct ISO_SUSP_ATTRIBUTES *p, cd9660node *spinfo)
    743  1.1  fvdl {
    744  1.1  fvdl 	p->attr.su_entry.CE.h.length[0] = 28;
    745  1.1  fvdl 	p->attr.su_entry.CE.h.version[0] = 1;
    746  1.1  fvdl 	/* Other attributes dont matter right now, will be updated later */
    747  1.1  fvdl 	return 1;
    748  1.1  fvdl }
    749  1.1  fvdl 
    750  1.1  fvdl int
    751  1.1  fvdl cd9660_susp_pd(struct ISO_SUSP_ATTRIBUTES *p, int length)
    752  1.1  fvdl {
    753  1.1  fvdl 	return 1;
    754  1.1  fvdl }
    755  1.1  fvdl 
    756  1.1  fvdl struct ISO_SUSP_ATTRIBUTES*
    757  1.1  fvdl cd9660_rrip_add_NM(struct ISO_SUSP_ATTRIBUTES *add_after, cd9660node *node,
    758  1.1  fvdl 		   const char *name)
    759  1.1  fvdl {
    760  1.1  fvdl 	int working,len;
    761  1.1  fvdl 	const char *p;
    762  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *r,*temp;
    763  1.1  fvdl 
    764  1.1  fvdl 	/*
    765  1.1  fvdl 	 * Each NM record has 254 byes to work with. This means that
    766  1.1  fvdl 	 * the name data itself only has 249 bytes to work with. So, a
    767  1.1  fvdl 	 * name with 251 characters would require two nm records.
    768  1.1  fvdl 	 */
    769  1.1  fvdl 	p = name;
    770  1.1  fvdl 	temp = add_after;
    771  1.1  fvdl 	working = 1;
    772  1.1  fvdl 	while (working) {
    773  1.1  fvdl 		r = cd9660node_susp_create_node(SUSP_TYPE_RRIP,
    774  1.1  fvdl 		    SUSP_ENTRY_RRIP_NM, "NM", SUSP_LOC_ENTRY);
    775  1.1  fvdl 		r->attr.rr_entry.NM.h.version[0] = 1;
    776  1.1  fvdl 		r->attr.rr_entry.NM.flags[0] = RRIP_NM_FLAGS_NONE;
    777  1.1  fvdl 		len = strlen(p);
    778  1.1  fvdl 
    779  1.1  fvdl 		if (len > 249) {
    780  1.1  fvdl 			len = 249;
    781  1.1  fvdl 			r->attr.rr_entry.NM.flags[0] = RRIP_NM_FLAGS_CONTINUE;
    782  1.1  fvdl 		} else {
    783  1.1  fvdl 			working = 0;
    784  1.1  fvdl 		}
    785  1.1  fvdl 		memcpy(r->attr.rr_entry.NM.altname, p, len);
    786  1.1  fvdl 		r->attr.rr_entry.NM.h.length[0] = 5 + len;
    787  1.1  fvdl 
    788  1.1  fvdl 		temp = cd9660node_susp_add_entry(node, temp, r, 0);
    789  1.1  fvdl 
    790  1.1  fvdl 		p += len;
    791  1.1  fvdl 	}
    792  1.1  fvdl 
    793  1.1  fvdl 	return temp;
    794  1.1  fvdl }
    795  1.1  fvdl 
    796  1.1  fvdl struct ISO_SUSP_ATTRIBUTES*
    797  1.1  fvdl cd9660_rrip_NM(struct ISO_SUSP_ATTRIBUTES *add_after, cd9660node *node)
    798  1.1  fvdl {
    799  1.1  fvdl 	return cd9660_rrip_add_NM(add_after, node, node->node->name);
    800  1.1  fvdl }
    801  1.1  fvdl 
    802  1.1  fvdl struct ISO_SUSP_ATTRIBUTES*
    803  1.1  fvdl cd9660_susp_ER(struct ISO_SUSP_ATTRIBUTES *add_after, cd9660node *node,
    804  1.1  fvdl 	       u_char ext_version, const char* ext_id, const char* ext_des,
    805  1.1  fvdl 	       const char* ext_src)
    806  1.1  fvdl {
    807  1.1  fvdl 	int l;
    808  1.1  fvdl 	struct ISO_SUSP_ATTRIBUTES *r;
    809  1.1  fvdl 
    810  1.1  fvdl 	r = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
    811  1.1  fvdl 			SUSP_ENTRY_SUSP_ER, "ER", SUSP_LOC_DOT);
    812  1.1  fvdl 
    813  1.1  fvdl 	/* Fixed data is 8 bytes */
    814  1.1  fvdl 	r->attr.su_entry.ER.h.length[0] = 8;
    815  1.1  fvdl 	r->attr.su_entry.ER.h.version[0] = 1;
    816  1.1  fvdl 
    817  1.1  fvdl 	r->attr.su_entry.ER.len_id[0] = (u_char)strlen(ext_id);
    818  1.1  fvdl 	r->attr.su_entry.ER.len_des[0] = (u_char)strlen(ext_des);
    819  1.1  fvdl 	r->attr.su_entry.ER.len_src[0] = (u_char)strlen(ext_src);
    820  1.1  fvdl 
    821  1.1  fvdl 	l = r->attr.su_entry.ER.len_id[0] +
    822  1.1  fvdl 		r->attr.su_entry.ER.len_src[0] +
    823  1.1  fvdl 		r->attr.su_entry.ER.len_des[0];
    824  1.1  fvdl 
    825  1.1  fvdl 	/* Everything must fit. */
    826  1.1  fvdl 	assert(l + r->attr.su_entry.ER.h.length[0] <= 254);
    827  1.1  fvdl 
    828  1.1  fvdl 	r->attr.su_entry.ER.h.length[0] += (u_char)l;
    829  1.1  fvdl 
    830  1.1  fvdl 
    831  1.1  fvdl 	r->attr.su_entry.ER.ext_ver[0] = ext_version;
    832  1.1  fvdl 	memcpy(r->attr.su_entry.ER.ext_data, ext_id,
    833  1.1  fvdl 		(int)r->attr.su_entry.ER.len_id[0]);
    834  1.1  fvdl 	l = (int) r->attr.su_entry.ER.len_id[0];
    835  1.1  fvdl 	memcpy(r->attr.su_entry.ER.ext_data + l,ext_des,
    836  1.1  fvdl 		(int)r->attr.su_entry.ER.len_des[0]);
    837  1.1  fvdl 
    838  1.1  fvdl 	l += (int)r->attr.su_entry.ER.len_des[0];
    839  1.1  fvdl 	memcpy(r->attr.su_entry.ER.ext_data + l,ext_src,
    840  1.1  fvdl 		(int)r->attr.su_entry.ER.len_src[0]);
    841  1.1  fvdl 
    842  1.1  fvdl 	return cd9660node_susp_add_entry(node, add_after, r, 0);
    843  1.1  fvdl }
    844  1.1  fvdl 
    845  1.1  fvdl struct ISO_SUSP_ATTRIBUTES*
    846  1.1  fvdl cd9660_susp_ES(struct ISO_SUSP_ATTRIBUTES *last, cd9660node *node)
    847  1.1  fvdl {
    848  1.1  fvdl 	return NULL;
    849  1.1  fvdl }
    850