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