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