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