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