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 #include <util.h> 49 50 static void cd9660_rrip_initialize_inode(cd9660node *); 51 static int cd9660_susp_handle_continuation(iso9660_disk *, cd9660node *); 52 static int cd9660_susp_handle_continuation_common(iso9660_disk *, cd9660node *, 53 int); 54 55 int 56 cd9660_susp_initialize(iso9660_disk *diskStructure, cd9660node *node, 57 cd9660node *parent, cd9660node *grandparent) 58 { 59 cd9660node *cn; 60 int r; 61 62 /* Make sure the node is not NULL. If it is, there are major problems */ 63 assert(node != NULL); 64 65 if (!(node->type & CD9660_TYPE_DOT) && 66 !(node->type & CD9660_TYPE_DOTDOT)) 67 TAILQ_INIT(&(node->head)); 68 if (node->dot_record != 0) 69 TAILQ_INIT(&(node->dot_record->head)); 70 if (node->dot_dot_record != 0) 71 TAILQ_INIT(&(node->dot_dot_record->head)); 72 73 /* SUSP specific entries here */ 74 if ((r = cd9660_susp_initialize_node(diskStructure, node)) < 0) 75 return r; 76 77 /* currently called cd9660node_rrip_init_links */ 78 r = cd9660_rrip_initialize_node(diskStructure, node, parent, grandparent); 79 if (r < 0) 80 return r; 81 82 /* 83 * See if we need a CE record, and set all of the 84 * associated counters. 85 * 86 * This should be called after all extensions. After 87 * this is called, no new records should be added. 88 */ 89 if ((r = cd9660_susp_handle_continuation(diskStructure, node)) < 0) 90 return r; 91 92 /* Recurse on children. */ 93 TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) { 94 if ((r = cd9660_susp_initialize(diskStructure, cn, node, parent)) < 0) 95 return 0; 96 } 97 return 1; 98 } 99 100 int 101 cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node) 102 { 103 cd9660node *temp; 104 int r; 105 106 assert(node != NULL); 107 108 if (node == diskStructure->rootNode) 109 diskStructure->susp_continuation_area_current_free = 0; 110 111 if ((r = cd9660_susp_finalize_node(diskStructure, node)) < 0) 112 return r; 113 if ((r = cd9660_rrip_finalize_node(node)) < 0) 114 return r; 115 116 TAILQ_FOREACH(temp, &node->cn_children, cn_next_child) { 117 if ((r = cd9660_susp_finalize(diskStructure, temp)) < 0) 118 return r; 119 } 120 return 1; 121 } 122 123 /* 124 * If we really wanted to speed things up, we could have some sort of 125 * lookup table on the SUSP entry type that calls a functor. Or, we could 126 * combine the functions. These functions are kept separate to allow 127 * easier addition of other extensions. 128 129 * For the sake of simplicity and clarity, we won't be doing that for now. 130 */ 131 132 /* 133 * SUSP needs to update the following types: 134 * CE (continuation area) 135 */ 136 int 137 cd9660_susp_finalize_node(iso9660_disk *diskStructure, cd9660node *node) 138 { 139 struct ISO_SUSP_ATTRIBUTES *t; 140 141 /* Handle CE counters */ 142 if (node->susp_entry_ce_length > 0) { 143 node->susp_entry_ce_start = 144 diskStructure->susp_continuation_area_current_free; 145 diskStructure->susp_continuation_area_current_free += 146 node->susp_entry_ce_length; 147 } 148 149 TAILQ_FOREACH(t, &node->head, rr_ll) { 150 if (t->susp_type != SUSP_TYPE_SUSP || 151 t->entry_type != SUSP_ENTRY_SUSP_CE) 152 continue; 153 cd9660_bothendian_dword( 154 diskStructure-> 155 susp_continuation_area_start_sector, 156 t->attr.su_entry.CE.ca_sector); 157 158 cd9660_bothendian_dword( 159 diskStructure-> 160 susp_continuation_area_start_sector, 161 t->attr.su_entry.CE.ca_sector); 162 cd9660_bothendian_dword(node->susp_entry_ce_start, 163 t->attr.su_entry.CE.offset); 164 cd9660_bothendian_dword(node->susp_entry_ce_length, 165 t->attr.su_entry.CE.length); 166 } 167 return 0; 168 } 169 170 int 171 cd9660_rrip_finalize_node(cd9660node *node) 172 { 173 struct ISO_SUSP_ATTRIBUTES *t; 174 175 TAILQ_FOREACH(t, &node->head, rr_ll) { 176 if (t->susp_type != SUSP_TYPE_RRIP) 177 continue; 178 switch (t->entry_type) { 179 case SUSP_ENTRY_RRIP_CL: 180 /* Look at rr_relocated*/ 181 if (node->rr_relocated == NULL) 182 return -1; 183 cd9660_bothendian_dword( 184 node->rr_relocated->fileDataSector, 185 (unsigned char *) 186 t->attr.rr_entry.CL.dir_loc); 187 break; 188 case SUSP_ENTRY_RRIP_PL: 189 /* Look at rr_real_parent */ 190 if (node->parent == NULL || 191 node->parent->rr_real_parent == NULL) 192 return -1; 193 cd9660_bothendian_dword( 194 node->parent->rr_real_parent->fileDataSector, 195 (unsigned char *) 196 t->attr.rr_entry.PL.dir_loc); 197 break; 198 } 199 } 200 return 0; 201 } 202 203 static int 204 cd9660_susp_handle_continuation_common(iso9660_disk *diskStructure, 205 cd9660node *node, int space) 206 { 207 int ca_used, susp_used, susp_used_pre_ce, working; 208 struct ISO_SUSP_ATTRIBUTES *temp, *pre_ce, *last, *CE, *ST; 209 210 pre_ce = last = NULL; 211 working = 254 - space; 212 if (node->su_tail_size > 0) 213 /* Allow 4 bytes for "ST" record. */ 214 working -= node->su_tail_size + 4; 215 /* printf("There are %i bytes to work with\n",working); */ 216 217 susp_used_pre_ce = susp_used = 0; 218 ca_used = 0; 219 TAILQ_FOREACH(temp, &node->head, rr_ll) { 220 if (working < 0) 221 break; 222 /* 223 * printf("SUSP Entry found, length is %i\n", 224 * CD9660_SUSP_ENTRY_SIZE(temp)); 225 */ 226 working -= CD9660_SUSP_ENTRY_SIZE(temp); 227 if (working >= 0) { 228 last = temp; 229 susp_used += CD9660_SUSP_ENTRY_SIZE(temp); 230 } 231 if (working >= 28) { 232 /* 233 * Remember the last entry after which we 234 * could insert a "CE" entry. 235 */ 236 pre_ce = last; 237 susp_used_pre_ce = susp_used; 238 } 239 } 240 241 /* A CE entry is needed */ 242 if (working <= 0) { 243 CE = cd9660node_susp_create_node(SUSP_TYPE_SUSP, 244 SUSP_ENTRY_SUSP_CE, "CE", SUSP_LOC_ENTRY); 245 cd9660_susp_ce(CE, node); 246 /* This will automatically insert at the appropriate location */ 247 if (pre_ce != NULL) 248 TAILQ_INSERT_AFTER(&node->head, pre_ce, CE, rr_ll); 249 else 250 TAILQ_INSERT_HEAD(&node->head, CE, rr_ll); 251 last = CE; 252 susp_used = susp_used_pre_ce + 28; 253 /* Count how much CA data is necessary */ 254 for (temp = TAILQ_NEXT(last, rr_ll); temp != NULL; 255 temp = TAILQ_NEXT(temp, rr_ll)) { 256 ca_used += CD9660_SUSP_ENTRY_SIZE(temp); 257 } 258 } 259 260 /* An ST entry is needed */ 261 if (node->su_tail_size > 0) { 262 ST = cd9660node_susp_create_node(SUSP_TYPE_SUSP, 263 SUSP_ENTRY_SUSP_ST, "ST", SUSP_LOC_ENTRY); 264 cd9660_susp_st(ST, node); 265 if (last != NULL) 266 TAILQ_INSERT_AFTER(&node->head, last, ST, rr_ll); 267 else 268 TAILQ_INSERT_HEAD(&node->head, ST, rr_ll); 269 last = ST; 270 susp_used += 4; 271 } 272 if (last != NULL) 273 last->last_in_suf = 1; 274 275 node->susp_entry_size = susp_used; 276 node->susp_entry_ce_length = ca_used; 277 278 diskStructure->susp_continuation_area_size += ca_used; 279 return 1; 280 } 281 282 /* See if a continuation entry is needed for each of the different types */ 283 static int 284 cd9660_susp_handle_continuation(iso9660_disk *diskStructure, cd9660node *node) 285 { 286 assert (node != NULL); 287 288 /* Entry */ 289 if (cd9660_susp_handle_continuation_common(diskStructure, 290 node,(int)(node->isoDirRecord->length[0])) < 0) 291 return 0; 292 293 return 1; 294 } 295 296 int 297 cd9660_susp_initialize_node(iso9660_disk *diskStructure, cd9660node *node) 298 { 299 struct ISO_SUSP_ATTRIBUTES *temp; 300 301 /* 302 * Requirements/notes: 303 * CE: is added for us where needed 304 * ST: not sure if it is even required, but if so, should be 305 * handled by the CE code 306 * PD: isn't needed (though might be added for testing) 307 * SP: is stored ONLY on the . record of the root directory 308 * ES: not sure 309 */ 310 311 /* Check for root directory, add SP and ER if needed. */ 312 if (node->type & CD9660_TYPE_DOT) { 313 if (node->parent == diskStructure->rootNode) { 314 temp = cd9660node_susp_create_node(SUSP_TYPE_SUSP, 315 SUSP_ENTRY_SUSP_SP, "SP", SUSP_LOC_DOT); 316 cd9660_susp_sp(temp, node); 317 318 /* Should be first entry. */ 319 TAILQ_INSERT_HEAD(&node->head, temp, rr_ll); 320 } 321 } 322 return 1; 323 } 324 325 static void 326 cd9660_rrip_initialize_inode(cd9660node *node) 327 { 328 struct ISO_SUSP_ATTRIBUTES *attr; 329 330 /* 331 * Inode dependent values - this may change, 332 * but for now virtual files and directories do 333 * not have an inode structure 334 */ 335 336 if ((node->node != NULL) && (node->node->inode != NULL)) { 337 /* PX - POSIX attributes */ 338 attr = cd9660node_susp_create_node(SUSP_TYPE_RRIP, 339 SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY); 340 cd9660node_rrip_px(attr, node->node); 341 342 TAILQ_INSERT_TAIL(&node->head, attr, rr_ll); 343 344 /* TF - timestamp */ 345 attr = cd9660node_susp_create_node(SUSP_TYPE_RRIP, 346 SUSP_ENTRY_RRIP_TF, "TF", SUSP_LOC_ENTRY); 347 cd9660node_rrip_tf(attr, node->node); 348 TAILQ_INSERT_TAIL(&node->head, attr, rr_ll); 349 350 /* SL - Symbolic link */ 351 /* ?????????? Dan - why is this here? */ 352 if (TAILQ_EMPTY(&node->cn_children) && 353 node->node->inode != NULL && 354 S_ISLNK(node->node->inode->st.st_mode)) 355 cd9660_createSL(node); 356 357 /* PN - device number */ 358 if (node->node->inode != NULL && 359 ((S_ISCHR(node->node->inode->st.st_mode) || 360 S_ISBLK(node->node->inode->st.st_mode)))) { 361 attr = 362 cd9660node_susp_create_node(SUSP_TYPE_RRIP, 363 SUSP_ENTRY_RRIP_PN, "PN", 364 SUSP_LOC_ENTRY); 365 cd9660node_rrip_pn(attr, node->node); 366 TAILQ_INSERT_TAIL(&node->head, attr, rr_ll); 367 } 368 } 369 } 370 371 int 372 cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node, 373 cd9660node *parent, cd9660node *grandparent) 374 { 375 struct ISO_SUSP_ATTRIBUTES *current = NULL; 376 377 assert(node != NULL); 378 379 if (node->type & CD9660_TYPE_DOT) { 380 /* 381 * Handle ER - should be the only entry to appear on 382 * a "." record 383 */ 384 if (node->parent == diskStructure->rootNode) { 385 cd9660_susp_ER(node, 1, SUSP_RRIP_ER_EXT_ID, 386 SUSP_RRIP_ER_EXT_DES, SUSP_RRIP_ER_EXT_SRC); 387 } 388 if (parent != NULL && parent->node != NULL && 389 parent->node->inode != NULL) { 390 /* PX - POSIX attributes */ 391 current = cd9660node_susp_create_node(SUSP_TYPE_RRIP, 392 SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY); 393 cd9660node_rrip_px(current, parent->node); 394 TAILQ_INSERT_TAIL(&node->head, current, rr_ll); 395 } 396 } else if (node->type & CD9660_TYPE_DOTDOT) { 397 if (grandparent != NULL && grandparent->node != NULL && 398 grandparent->node->inode != NULL) { 399 /* PX - POSIX attributes */ 400 current = cd9660node_susp_create_node(SUSP_TYPE_RRIP, 401 SUSP_ENTRY_RRIP_PX, "PX", SUSP_LOC_ENTRY); 402 cd9660node_rrip_px(current, grandparent->node); 403 TAILQ_INSERT_TAIL(&node->head, current, rr_ll); 404 } 405 /* Handle PL */ 406 if (parent != NULL && parent->rr_real_parent != NULL) { 407 current = cd9660node_susp_create_node(SUSP_TYPE_RRIP, 408 SUSP_ENTRY_RRIP_PL, "PL", SUSP_LOC_DOTDOT); 409 cd9660_rrip_PL(current,node); 410 TAILQ_INSERT_TAIL(&node->head, current, rr_ll); 411 } 412 } else { 413 cd9660_rrip_initialize_inode(node); 414 415 /* 416 * Not every node needs a NM set - only if the name is 417 * actually different. IE: If a file is TEST -> TEST, 418 * no NM. test -> TEST, need a NM 419 * 420 * The rr_moved_dir needs to be assigned a NM record as well. 421 */ 422 if (node == diskStructure->rr_moved_dir) { 423 cd9660_rrip_add_NM(node, RRIP_DEFAULT_MOVE_DIR_NAME); 424 } 425 else if ((node->node != NULL) && 426 ((strlen(node->node->name) != 427 (uint8_t)node->isoDirRecord->name_len[0]) || 428 (memcmp(node->node->name,node->isoDirRecord->name, 429 (uint8_t)node->isoDirRecord->name_len[0]) != 0))) { 430 cd9660_rrip_NM(node); 431 } 432 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_atime); 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_mtime); 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 byes 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