| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#include <sys/types.h> |
| 40 |
#include <sys/stat.h> |
| 41 |
#include <limits.h> |
| 42 |
#include <stdio.h> |
| 43 |
#include <stdlib.h> |
| 44 |
#include <string.h> |
| 45 |
#if HAVE_STRINGS_H |
| 46 |
#include <strings.h> |
| 47 |
#endif |
| 48 |
#include <unistd.h> |
| 49 |
|
| 50 |
#include "pax.h" |
| 51 |
#include "cpio.h" |
| 52 |
#include "extern.h" |
| 53 |
|
| 54 |
__RCSID("$MirOS: src/bin/pax/cpio.c,v 1.29 2024/08/17 23:33:51 tg Exp $"); |
| 55 |
|
| 56 |
static int rd_nm(ARCHD *, int); |
| 57 |
static int rd_ln_nm(ARCHD *); |
| 58 |
static int com_rd(ARCHD *); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#ifndef SMALL |
| 65 |
static int swp_head; |
| 66 |
#endif |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
int |
| 80 |
cpio_strd(void) |
| 81 |
{ |
| 82 |
return(lnk_start()); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
int |
| 96 |
cpio_trail(ARCHD *arcn, char *notused MKSH_A_UNUSED, |
| 97 |
int notused2 MKSH_A_UNUSED, int *notused3 MKSH_A_UNUSED) |
| 98 |
{ |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
if ((strcmp(arcn->name, TRAILER) == 0) && (arcn->sb.st_size == 0)) |
| 103 |
return(0); |
| 104 |
return(-1); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
static int |
| 115 |
com_rd(ARCHD *arcn) |
| 116 |
{ |
| 117 |
arcn->skip = 0; |
| 118 |
arcn->pat = NULL; |
| 119 |
arcn->org_name = arcn->name; |
| 120 |
switch (arcn->sb.st_mode & C_IFMT) { |
| 121 |
case C_ISFIFO: |
| 122 |
arcn->type = PAX_FIF; |
| 123 |
break; |
| 124 |
case C_ISDIR: |
| 125 |
arcn->type = PAX_DIR; |
| 126 |
break; |
| 127 |
case C_ISBLK: |
| 128 |
arcn->type = PAX_BLK; |
| 129 |
break; |
| 130 |
case C_ISCHR: |
| 131 |
arcn->type = PAX_CHR; |
| 132 |
break; |
| 133 |
case C_ISLNK: |
| 134 |
arcn->type = PAX_SLK; |
| 135 |
break; |
| 136 |
case C_ISOCK: |
| 137 |
arcn->type = PAX_SCK; |
| 138 |
break; |
| 139 |
case C_ISCTG: |
| 140 |
case C_ISREG: |
| 141 |
default: |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
arcn->sb.st_mode = (arcn->sb.st_mode & 0xfff) | C_ISREG; |
| 147 |
arcn->type = PAX_REG; |
| 148 |
arcn->skip = arcn->sb.st_size; |
| 149 |
break; |
| 150 |
} |
| 151 |
if (chk_lnk(arcn) < 0) |
| 152 |
return(-1); |
| 153 |
return(0); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
int |
| 164 |
cpio_endwr(void) |
| 165 |
{ |
| 166 |
ARCHD last; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
memset(&last, 0, sizeof(last)); |
| 172 |
last.nlen = sizeof(TRAILER) - 1; |
| 173 |
last.type = PAX_REG; |
| 174 |
last.sb.st_nlink = 1; |
| 175 |
(void)strlcpy(last.name, TRAILER, sizeof(last.name)); |
| 176 |
return((*frmt->wr)(&last)); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
static int |
| 187 |
rd_nm(ARCHD *arcn, int nsz) |
| 188 |
{ |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if ((nsz == 0) || ((size_t)nsz > sizeof(arcn->name))) { |
| 193 |
paxwarn(1, "cpio file name length %d is out of range", nsz); |
| 194 |
return(-1); |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
if ((rd_wrbuf(arcn->name,nsz) != nsz) || (arcn->name[nsz-1] != '\0') || |
| 201 |
(arcn->name[0] == '\0')) { |
| 202 |
paxwarn(1, "cpio file name in header is corrupted"); |
| 203 |
return(-1); |
| 204 |
} |
| 205 |
return(0); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
static int |
| 217 |
rd_ln_nm(ARCHD *arcn) |
| 218 |
{ |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
if (((off_t)arcn->sb.st_size <= 0) || |
| 223 |
((off_t)arcn->sb.st_size >= (off_t)sizeof(arcn->ln_name))) { |
| 224 |
paxwarn(1, "cpio link name length is invalid: %" OT_FMT, |
| 225 |
arcn->sb.st_size); |
| 226 |
return(-1); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
if (rd_wrbuf(arcn->ln_name, (int)arcn->sb.st_size) != |
| 233 |
(int)arcn->sb.st_size) { |
| 234 |
paxwarn(1, "cpio link name read error"); |
| 235 |
return(-1); |
| 236 |
} |
| 237 |
arcn->ln_nlen = arcn->sb.st_size; |
| 238 |
arcn->ln_name[arcn->ln_nlen] = '\0'; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
if (arcn->ln_name[0] == '\0') { |
| 244 |
paxwarn(1, "cpio link name is corrupt"); |
| 245 |
return(-1); |
| 246 |
} |
| 247 |
return(0); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
int |
| 263 |
cpio_id(char *blk, int size) |
| 264 |
{ |
| 265 |
if ((size < (int)sizeof(HD_CPIO)) || |
| 266 |
(strncmp(blk, AMAGIC, sizeof(AMAGIC) - 1) != 0)) |
| 267 |
return(-1); |
| 268 |
return(0); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
int |
| 280 |
cpio_rd(ARCHD *arcn, char *buf) |
| 281 |
{ |
| 282 |
int nsz; |
| 283 |
unsigned long long val; |
| 284 |
HD_CPIO *hd; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
if (cpio_id(buf, sizeof(HD_CPIO)) < 0) |
| 290 |
return(-1); |
| 291 |
hd = (HD_CPIO *)buf; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
arcn->pad = 0; |
| 298 |
arcn->sb.st_dev = (dev_t)asc_ul(hd->c_dev, sizeof(hd->c_dev), OCT); |
| 299 |
arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), OCT); |
| 300 |
arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), OCT); |
| 301 |
arcn->sb.st_uid = (uid_t)asc_ul(hd->c_uid, sizeof(hd->c_uid), OCT); |
| 302 |
arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), OCT); |
| 303 |
arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink), |
| 304 |
OCT); |
| 305 |
arcn->sb.st_rdev = (dev_t)asc_ul(hd->c_rdev, sizeof(hd->c_rdev), OCT); |
| 306 |
val = asc_ull(hd->c_mtime, sizeof(hd->c_mtime), OCT); |
| 307 |
if (val > MAX_TIME_T) |
| 308 |
arcn->sb.st_mtime = INT_MAX; |
| 309 |
else |
| 310 |
arcn->sb.st_mtime = val; |
| 311 |
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; |
| 312 |
#if HAVE_ST_MTIMENSEC |
| 313 |
arcn->sb.st_ctimensec = arcn->sb.st_atimensec = arcn->sb.st_mtimensec = 0; |
| 314 |
#endif |
| 315 |
arcn->sb.st_size = (off_t)asc_ull(hd->c_filesize,sizeof(hd->c_filesize), |
| 316 |
OCT); |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
if ((nsz = (int)asc_ul(hd->c_namesize,sizeof(hd->c_namesize),OCT)) < 2) |
| 323 |
return(-1); |
| 324 |
arcn->nlen = nsz - 1; |
| 325 |
if (rd_nm(arcn, nsz) < 0) |
| 326 |
return(-1); |
| 327 |
|
| 328 |
if (((arcn->sb.st_mode&C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)) { |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
arcn->ln_nlen = 0; |
| 333 |
arcn->ln_name[0] = '\0'; |
| 334 |
return(com_rd(arcn)); |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
if (rd_ln_nm(arcn) < 0) |
| 342 |
return(-1); |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
return(com_rd(arcn)); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
off_t |
| 358 |
cpio_endrd(void) |
| 359 |
{ |
| 360 |
return ((off_t)(sizeof(HD_CPIO) + sizeof(TRAILER))); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
int |
| 371 |
cpio_stwr(int is_app MKSH_A_UNUSED) |
| 372 |
{ |
| 373 |
if ((anonarch & ANON_INODES) && flnk_start()) |
| 374 |
return (-1); |
| 375 |
return (dev_start()); |
| 376 |
} |
| 377 |
|
| 378 |
#ifndef SMALL |
| 379 |
int |
| 380 |
dist_stwr(int is_app) |
| 381 |
{ |
| 382 |
mircpio_deprecated("'dist' format", |
| 383 |
"the cpio format with 512 bytes blocksize and -M dist"); |
| 384 |
anonarch &= ANON_DEBUG | ANON_VERBOSE; |
| 385 |
anonarch |= ANON_UIDGID | ANON_INODES | ANON_HARDLINKS; |
| 386 |
return (cpio_stwr(is_app)); |
| 387 |
} |
| 388 |
#endif |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
int |
| 400 |
cpio_wr(ARCHD *arcn) |
| 401 |
{ |
| 402 |
HD_CPIO *hd; |
| 403 |
int nsz; |
| 404 |
char hdblk[sizeof(HD_CPIO)]; |
| 405 |
u_long t_uid, t_gid, t_dev; |
| 406 |
ino_t t_ino; |
| 407 |
time_t t_mtime; |
| 408 |
|
| 409 |
anonarch_init(); |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
if (map_dev(arcn, CPIO_MASK, CPIO_MASK) < 0) |
| 415 |
return(-1); |
| 416 |
|
| 417 |
arcn->pad = 0; |
| 418 |
nsz = arcn->nlen + 1; |
| 419 |
hd = (HD_CPIO *)hdblk; |
| 420 |
if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR)) |
| 421 |
arcn->sb.st_rdev = 0; |
| 422 |
|
| 423 |
t_uid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_uid; |
| 424 |
t_gid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_gid; |
| 425 |
t_mtime = (anonarch & ANON_MTIME) ? 0 : arcn->sb.st_mtime; |
| 426 |
t_ino = (anonarch & ANON_INODES) ? (ino_t)chk_flnk(arcn) : |
| 427 |
arcn->sb.st_ino; |
| 428 |
t_dev = (anonarch & ANON_INODES) ? 0UL : (u_long)arcn->sb.st_dev; |
| 429 |
|
| 430 |
if (!cpio_trail(arcn, NULL, 0, NULL)) |
| 431 |
t_ino = 0UL; |
| 432 |
if (t_ino == (ino_t)-1) { |
| 433 |
paxwarn(1, "Invalid inode number for file %s", arcn->org_name); |
| 434 |
return (1); |
| 435 |
} |
| 436 |
if (!(anonarch & ANON_HARDLINKS)) |
| 437 |
arcn->type &= ~PAX_LINKOR; |
| 438 |
|
| 439 |
switch (arcn->type) { |
| 440 |
case PAX_CTG: |
| 441 |
case PAX_REG: |
| 442 |
case PAX_HRG: |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
if (ull_asc(arcn->sb.st_size, hd->c_filesize, |
| 447 |
sizeof(hd->c_filesize), OCT)) { |
| 448 |
paxwarn(1, "File is too large for %s format %s", |
| 449 |
"cpio", arcn->org_name); |
| 450 |
return (1); |
| 451 |
} |
| 452 |
break; |
| 453 |
case PAX_SLK: |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
if (ul_asc(arcn->ln_nlen, hd->c_filesize, |
| 458 |
sizeof(hd->c_filesize), OCT)) |
| 459 |
goto out; |
| 460 |
break; |
| 461 |
default: |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
if (ul_asc(0, hd->c_filesize, sizeof(hd->c_filesize), OCT)) |
| 466 |
goto out; |
| 467 |
break; |
| 468 |
} |
| 469 |
|
| 470 |
#ifndef SMALL |
| 471 |
if (anonarch & ANON_DEBUG) |
| 472 |
paxwarn(0, "writing dev %lX inode %10lX mode %8lo user %ld:%ld" |
| 473 |
"\n\tnlink %3ld mtime %08llX name '%s'", t_dev, |
| 474 |
(u_long)t_ino, (u_long)arcn->sb.st_mode, t_uid, t_gid, |
| 475 |
(u_long)arcn->sb.st_nlink, (unsigned long long)t_mtime, |
| 476 |
arcn->name); |
| 477 |
#endif |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
if (ul_asc(MAGIC, hd->c_magic, sizeof(hd->c_magic), OCT) || |
| 483 |
ul_asc(t_dev, hd->c_dev, sizeof(hd->c_dev), OCT) || |
| 484 |
ul_asc((u_long)t_ino, hd->c_ino, sizeof(hd->c_ino), OCT) || |
| 485 |
ul_asc(arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode), OCT) || |
| 486 |
ul_asc(t_uid, hd->c_uid, sizeof(hd->c_uid), OCT) || |
| 487 |
ul_asc(t_gid, hd->c_gid, sizeof(hd->c_gid), OCT) || |
| 488 |
ul_asc(arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink), OCT) || |
| 489 |
ul_asc(arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev), OCT) || |
| 490 |
ull_asc(t_mtime < 0 ? 0ULL : (unsigned long long)t_mtime, hd->c_mtime, sizeof(hd->c_mtime), OCT) || |
| 491 |
ul_asc(nsz, hd->c_namesize, sizeof(hd->c_namesize), OCT)) |
| 492 |
goto out; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
if ((wr_rdbuf(hdblk, (int)sizeof(HD_CPIO)) < 0) || |
| 498 |
(wr_rdbuf(arcn->name, nsz) < 0)) { |
| 499 |
paxwarn(1, "Unable to write %s %s for %s", |
| 500 |
"cpio", "header", arcn->org_name); |
| 501 |
return (-1); |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
if (PAX_IS_REG(arcn->type) || (arcn->type == PAX_HRG)) |
| 509 |
return (0); |
| 510 |
if (arcn->type & PAX_LINKOR) { |
| 511 |
arcn->type &= ~PAX_LINKOR; |
| 512 |
return (1); |
| 513 |
} |
| 514 |
if (arcn->type != PAX_SLK) |
| 515 |
return (1); |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
if (wr_rdbuf(arcn->ln_name, arcn->ln_nlen) < 0) { |
| 522 |
paxwarn(1, "Unable to write %s %s for %s", |
| 523 |
"cpio", "link name", arcn->org_name); |
| 524 |
return (-1); |
| 525 |
} |
| 526 |
return(1); |
| 527 |
|
| 528 |
out: |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
paxwarn(1, "%s header field is too small for file %s", |
| 533 |
"cpio", arcn->org_name); |
| 534 |
return (1); |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
int |
| 551 |
vcpio_id(char *blk, int size) |
| 552 |
{ |
| 553 |
if ((size < (int)sizeof(HD_VCPIO)) || |
| 554 |
(strncmp(blk, AVMAGIC, sizeof(AVMAGIC) - 1) != 0)) |
| 555 |
return(-1); |
| 556 |
return(0); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
int |
| 568 |
crc_id(char *blk, int size) |
| 569 |
{ |
| 570 |
if ((size < (int)sizeof(HD_VCPIO)) || |
| 571 |
(strncmp(blk, AVCMAGIC, sizeof(AVCMAGIC) - 1) != 0)) |
| 572 |
return(-1); |
| 573 |
return(0); |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
int |
| 584 |
crc_strd(void) |
| 585 |
{ |
| 586 |
docrc = 1; |
| 587 |
return(lnk_start()); |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
int |
| 599 |
vcpio_rd(ARCHD *arcn, char *buf) |
| 600 |
{ |
| 601 |
HD_VCPIO *hd; |
| 602 |
dev_t devminor; |
| 603 |
dev_t devmajor; |
| 604 |
int nsz; |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
if (docrc) { |
| 611 |
if (crc_id(buf, sizeof(HD_VCPIO)) < 0) |
| 612 |
return(-1); |
| 613 |
} else { |
| 614 |
if (vcpio_id(buf, sizeof(HD_VCPIO)) < 0) |
| 615 |
return(-1); |
| 616 |
} |
| 617 |
|
| 618 |
hd = (HD_VCPIO *)buf; |
| 619 |
arcn->pad = 0; |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), HEX); |
| 625 |
arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), HEX); |
| 626 |
arcn->sb.st_uid = (uid_t)asc_ul(hd->c_uid, sizeof(hd->c_uid), HEX); |
| 627 |
arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), HEX); |
| 628 |
arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime,sizeof(hd->c_mtime),HEX); |
| 629 |
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; |
| 630 |
#if HAVE_ST_MTIMENSEC |
| 631 |
arcn->sb.st_ctimensec = arcn->sb.st_atimensec = arcn->sb.st_mtimensec = 0; |
| 632 |
#endif |
| 633 |
arcn->sb.st_size = (off_t)asc_ull(hd->c_filesize, |
| 634 |
sizeof(hd->c_filesize), HEX); |
| 635 |
arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink), |
| 636 |
HEX); |
| 637 |
devmajor = (dev_t)asc_ul(hd->c_maj, sizeof(hd->c_maj), HEX); |
| 638 |
devminor = (dev_t)asc_ul(hd->c_min, sizeof(hd->c_min), HEX); |
| 639 |
arcn->sb.st_dev = TODEV(devmajor, devminor); |
| 640 |
devmajor = (dev_t)asc_ul(hd->c_rmaj, sizeof(hd->c_rmaj), HEX); |
| 641 |
devminor = (dev_t)asc_ul(hd->c_rmin, sizeof(hd->c_rmin), HEX); |
| 642 |
arcn->sb.st_rdev = TODEV(devmajor, devminor); |
| 643 |
arcn->crc = asc_ul(hd->c_chksum, sizeof(hd->c_chksum), HEX); |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
if ((nsz = (int)asc_ul(hd->c_namesize,sizeof(hd->c_namesize),HEX)) < 2) |
| 650 |
return(-1); |
| 651 |
arcn->nlen = nsz - 1; |
| 652 |
if (rd_nm(arcn, nsz) < 0) |
| 653 |
return(-1); |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
if (rd_skip(VCPIO_PAD(sizeof(HD_VCPIO) + nsz)) < 0) |
| 659 |
return(-1); |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
if (((arcn->sb.st_mode&C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)) { |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
arcn->ln_nlen = 0; |
| 670 |
arcn->ln_name[0] = '\0'; |
| 671 |
arcn->pad = VCPIO_PAD(arcn->sb.st_size); |
| 672 |
return(com_rd(arcn)); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
if ((rd_ln_nm(arcn) < 0) || |
| 679 |
(rd_skip(VCPIO_PAD(arcn->sb.st_size)) < 0)) |
| 680 |
return(-1); |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
return(com_rd(arcn)); |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
off_t |
| 696 |
vcpio_endrd(void) |
| 697 |
{ |
| 698 |
return sizeof(HD_VCPIO) + sizeof(TRAILER) + |
| 699 |
(VCPIO_PAD(sizeof(HD_VCPIO) + sizeof(TRAILER))); |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
int |
| 710 |
crc_stwr(int is_app MKSH_A_UNUSED) |
| 711 |
{ |
| 712 |
docrc = 1; |
| 713 |
if ((anonarch & ANON_INODES) && flnk_start()) |
| 714 |
return (-1); |
| 715 |
return(dev_start()); |
| 716 |
} |
| 717 |
|
| 718 |
#ifndef SMALL |
| 719 |
int |
| 720 |
v4root_stwr(int is_app) |
| 721 |
{ |
| 722 |
mircpio_deprecated("'v4norm' format", |
| 723 |
"the sv4crc format with 512 bytes blocksize and -M root"); |
| 724 |
anonarch &= ANON_DEBUG | ANON_VERBOSE; |
| 725 |
anonarch |= ANON_UIDGID | ANON_INODES; |
| 726 |
return (crc_stwr(is_app)); |
| 727 |
} |
| 728 |
|
| 729 |
int |
| 730 |
v4norm_stwr(int is_app) |
| 731 |
{ |
| 732 |
mircpio_deprecated("'v4norm' format", |
| 733 |
"the sv4crc format with 512 bytes blocksize and -M norm"); |
| 734 |
anonarch &= ANON_DEBUG | ANON_VERBOSE; |
| 735 |
anonarch |= ANON_UIDGID | ANON_INODES | ANON_MTIME | ANON_HARDLINKS; |
| 736 |
return (crc_stwr(is_app)); |
| 737 |
} |
| 738 |
#endif |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
int |
| 750 |
vcpio_wr(ARCHD *arcn) |
| 751 |
{ |
| 752 |
HD_VCPIO *hd; |
| 753 |
unsigned int nsz; |
| 754 |
char hdblk[sizeof(HD_VCPIO)]; |
| 755 |
u_long t_uid, t_gid, t_major, t_minor; |
| 756 |
ino_t t_ino; |
| 757 |
time_t t_mtime; |
| 758 |
|
| 759 |
anonarch_init(); |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
if (map_dev(arcn, VCPIO_MASK, VCPIO_MASK) < 0) |
| 766 |
return(-1); |
| 767 |
nsz = arcn->nlen + 1; |
| 768 |
hd = (HD_VCPIO *)hdblk; |
| 769 |
if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR)) |
| 770 |
arcn->sb.st_rdev = 0; |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
if (docrc) { |
| 777 |
if (ul_asc(VCMAGIC, hd->c_magic, sizeof(hd->c_magic), OCT) || |
| 778 |
ul_asc(arcn->crc,hd->c_chksum,sizeof(hd->c_chksum), HEX)) |
| 779 |
goto out; |
| 780 |
} else { |
| 781 |
if (ul_asc(VMAGIC, hd->c_magic, sizeof(hd->c_magic), OCT) || |
| 782 |
ul_asc(0, hd->c_chksum, sizeof(hd->c_chksum),HEX)) |
| 783 |
goto out; |
| 784 |
} |
| 785 |
|
| 786 |
t_uid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_uid; |
| 787 |
t_gid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_gid; |
| 788 |
t_mtime = (anonarch & ANON_MTIME) ? 0 : arcn->sb.st_mtime; |
| 789 |
t_ino = (anonarch & ANON_INODES) ? (ino_t)chk_flnk(arcn) : |
| 790 |
arcn->sb.st_ino; |
| 791 |
t_major = (anonarch & ANON_INODES) ? 0UL : (u_long)MAJOR(arcn->sb.st_dev); |
| 792 |
t_minor = (anonarch & ANON_INODES) ? 0UL : (u_long)MINOR(arcn->sb.st_dev); |
| 793 |
|
| 794 |
if (!cpio_trail(arcn, NULL, 0, NULL)) |
| 795 |
t_ino = 0UL; |
| 796 |
if (t_ino == (ino_t)-1) { |
| 797 |
paxwarn(1, "Invalid inode number for file %s", arcn->org_name); |
| 798 |
return (1); |
| 799 |
} |
| 800 |
if (!(anonarch & ANON_HARDLINKS)) |
| 801 |
arcn->type &= ~PAX_LINKOR; |
| 802 |
|
| 803 |
switch (arcn->type) { |
| 804 |
case PAX_CTG: |
| 805 |
case PAX_REG: |
| 806 |
case PAX_HRG: |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
arcn->pad = VCPIO_PAD(arcn->sb.st_size); |
| 812 |
if (ull_asc(arcn->sb.st_size, hd->c_filesize, |
| 813 |
sizeof(hd->c_filesize), HEX)) { |
| 814 |
paxwarn(1, "File is too large for %s format %s", |
| 815 |
"sv4cpio", arcn->org_name); |
| 816 |
return (1); |
| 817 |
} |
| 818 |
break; |
| 819 |
case PAX_SLK: |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
arcn->pad = 0; |
| 825 |
if (ul_asc(arcn->ln_nlen, hd->c_filesize, |
| 826 |
sizeof(hd->c_filesize), HEX)) |
| 827 |
goto out; |
| 828 |
break; |
| 829 |
default: |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
arcn->pad = 0; |
| 834 |
if (ul_asc(0, hd->c_filesize, sizeof(hd->c_filesize), HEX)) |
| 835 |
goto out; |
| 836 |
break; |
| 837 |
} |
| 838 |
|
| 839 |
#ifndef SMALL |
| 840 |
if (anonarch & ANON_DEBUG) |
| 841 |
paxwarn(0, "writing dev %lX:%lx inode %10lX mode %8lo user %ld:%ld" |
| 842 |
"\n\tnlink %3ld mtime %08llX name '%s'", t_major, t_minor, |
| 843 |
(u_long)t_ino, (u_long)arcn->sb.st_mode, t_uid, t_gid, |
| 844 |
(u_long)arcn->sb.st_nlink, (unsigned long long)t_mtime, |
| 845 |
arcn->name); |
| 846 |
#endif |
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
if (ul_asc(t_ino, hd->c_ino, sizeof(hd->c_ino), HEX) || |
| 852 |
ul_asc(arcn->sb.st_mode, hd->c_mode, sizeof(hd->c_mode), HEX) || |
| 853 |
ul_asc(t_uid, hd->c_uid, sizeof(hd->c_uid), HEX) || |
| 854 |
ul_asc(t_gid, hd->c_gid, sizeof(hd->c_gid), HEX) || |
| 855 |
ul_asc(t_mtime < 0 ? 0 : t_mtime, hd->c_mtime, |
| 856 |
sizeof(hd->c_mtime), HEX) || |
| 857 |
ul_asc(arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink), HEX) || |
| 858 |
|
| 859 |
ul_asc(t_major, hd->c_maj, sizeof(hd->c_maj), HEX) || |
| 860 |
ul_asc(t_minor, hd->c_min, sizeof(hd->c_min), HEX) || |
| 861 |
|
| 862 |
ul_asc(MAJOR(arcn->sb.st_rdev), hd->c_rmaj, sizeof(hd->c_rmaj), HEX) || |
| 863 |
ul_asc(MINOR(arcn->sb.st_rdev), hd->c_rmin, sizeof(hd->c_rmin), HEX) || |
| 864 |
ul_asc(nsz, hd->c_namesize, sizeof(hd->c_namesize), HEX)) |
| 865 |
goto out; |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
if ((wr_rdbuf(hdblk, (int)sizeof(HD_VCPIO)) < 0) || |
| 871 |
(wr_rdbuf(arcn->name, (int)nsz) < 0) || |
| 872 |
(wr_skip(VCPIO_PAD(sizeof(HD_VCPIO) + nsz)) < 0)) { |
| 873 |
paxwarn(1, "Unable to write %s %s for %s", |
| 874 |
"sv4cpio", "header", arcn->org_name); |
| 875 |
return (-1); |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
if (PAX_IS_REG(arcn->type) || (arcn->type == PAX_HRG)) |
| 882 |
return(0); |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
if (arcn->type & PAX_LINKOR) { |
| 888 |
arcn->type &= ~PAX_LINKOR; |
| 889 |
return (1); |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
if (arcn->type != PAX_SLK) |
| 896 |
return(1); |
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
if ((wr_rdbuf(arcn->ln_name, arcn->ln_nlen) < 0) || |
| 902 |
(wr_skip(VCPIO_PAD(arcn->ln_nlen)) < 0)) { |
| 903 |
paxwarn(1, "Unable to write %s %s for %s", |
| 904 |
"sv4cpio", "link name", arcn->org_name); |
| 905 |
return (-1); |
| 906 |
} |
| 907 |
return(1); |
| 908 |
|
| 909 |
out: |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
paxwarn(1, "%s header field is too small for file %s", |
| 914 |
"sv4cpio", arcn->org_name); |
| 915 |
return (1); |
| 916 |
} |
| 917 |
|
| 918 |
#ifndef SMALL |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
int |
| 932 |
bcpio_id(char *blk, int size) |
| 933 |
{ |
| 934 |
if (size < (int)sizeof(HD_BCPIO)) |
| 935 |
return(-1); |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
if (((unsigned short)SHRT_EXT(blk)) == MAGIC) |
| 941 |
return(0); |
| 942 |
if (((unsigned short)RSHRT_EXT(blk)) == MAGIC) { |
| 943 |
if (!swp_head) |
| 944 |
++swp_head; |
| 945 |
return(0); |
| 946 |
} |
| 947 |
return(-1); |
| 948 |
} |
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
int |
| 960 |
bcpio_rd(ARCHD *arcn, char *buf) |
| 961 |
{ |
| 962 |
HD_BCPIO *hd; |
| 963 |
int nsz; |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
if (bcpio_id(buf, sizeof(HD_BCPIO)) < 0) |
| 969 |
return(-1); |
| 970 |
|
| 971 |
arcn->pad = 0; |
| 972 |
hd = (HD_BCPIO *)buf; |
| 973 |
if (swp_head) { |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
arcn->sb.st_dev = (dev_t)(RSHRT_EXT(hd->h_dev)); |
| 978 |
arcn->sb.st_ino = (ino_t)(RSHRT_EXT(hd->h_ino)); |
| 979 |
arcn->sb.st_mode = (mode_t)(RSHRT_EXT(hd->h_mode)); |
| 980 |
arcn->sb.st_uid = (uid_t)(RSHRT_EXT(hd->h_uid)); |
| 981 |
arcn->sb.st_gid = (gid_t)(RSHRT_EXT(hd->h_gid)); |
| 982 |
arcn->sb.st_nlink = (nlink_t)(RSHRT_EXT(hd->h_nlink)); |
| 983 |
arcn->sb.st_rdev = (dev_t)(RSHRT_EXT(hd->h_rdev)); |
| 984 |
arcn->sb.st_mtime = (time_t)(RSHRT_EXT(hd->h_mtime_1)); |
| 985 |
arcn->sb.st_mtime = (arcn->sb.st_mtime << 16) | |
| 986 |
((time_t)(RSHRT_EXT(hd->h_mtime_2))); |
| 987 |
arcn->sb.st_size = (off_t)(RSHRT_EXT(hd->h_filesize_1)); |
| 988 |
arcn->sb.st_size = (arcn->sb.st_size << 16) | |
| 989 |
((off_t)(RSHRT_EXT(hd->h_filesize_2))); |
| 990 |
nsz = (int)(RSHRT_EXT(hd->h_namesize)); |
| 991 |
} else { |
| 992 |
arcn->sb.st_dev = (dev_t)(SHRT_EXT(hd->h_dev)); |
| 993 |
arcn->sb.st_ino = (ino_t)(SHRT_EXT(hd->h_ino)); |
| 994 |
arcn->sb.st_mode = (mode_t)(SHRT_EXT(hd->h_mode)); |
| 995 |
arcn->sb.st_uid = (uid_t)(SHRT_EXT(hd->h_uid)); |
| 996 |
arcn->sb.st_gid = (gid_t)(SHRT_EXT(hd->h_gid)); |
| 997 |
arcn->sb.st_nlink = (nlink_t)(SHRT_EXT(hd->h_nlink)); |
| 998 |
arcn->sb.st_rdev = (dev_t)(SHRT_EXT(hd->h_rdev)); |
| 999 |
arcn->sb.st_mtime = (time_t)(SHRT_EXT(hd->h_mtime_1)); |
| 1000 |
arcn->sb.st_mtime = (arcn->sb.st_mtime << 16) | |
| 1001 |
((time_t)(SHRT_EXT(hd->h_mtime_2))); |
| 1002 |
arcn->sb.st_size = (off_t)(SHRT_EXT(hd->h_filesize_1)); |
| 1003 |
arcn->sb.st_size = (arcn->sb.st_size << 16) | |
| 1004 |
((off_t)(SHRT_EXT(hd->h_filesize_2))); |
| 1005 |
nsz = (int)(SHRT_EXT(hd->h_namesize)); |
| 1006 |
} |
| 1007 |
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; |
| 1008 |
#if HAVE_ST_MTIMENSEC |
| 1009 |
arcn->sb.st_ctimensec = arcn->sb.st_atimensec = arcn->sb.st_mtimensec = 0; |
| 1010 |
#endif |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
if (nsz < 2) |
| 1017 |
return(-1); |
| 1018 |
arcn->nlen = nsz - 1; |
| 1019 |
if (rd_nm(arcn, nsz) < 0) |
| 1020 |
return(-1); |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
if (rd_skip(BCPIO_PAD(sizeof(HD_BCPIO) + nsz)) < 0) |
| 1026 |
return(-1); |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
if (((arcn->sb.st_mode & C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)){ |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
arcn->ln_nlen = 0; |
| 1037 |
arcn->ln_name[0] = '\0'; |
| 1038 |
arcn->pad = BCPIO_PAD(arcn->sb.st_size); |
| 1039 |
return(com_rd(arcn)); |
| 1040 |
} |
| 1041 |
|
| 1042 |
if ((rd_ln_nm(arcn) < 0) || |
| 1043 |
(rd_skip(BCPIO_PAD(arcn->sb.st_size)) < 0)) |
| 1044 |
return(-1); |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
return(com_rd(arcn)); |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
off_t |
| 1060 |
bcpio_endrd(void) |
| 1061 |
{ |
| 1062 |
return sizeof(HD_BCPIO) + sizeof(TRAILER) + |
| 1063 |
(BCPIO_PAD(sizeof(HD_BCPIO) + sizeof(TRAILER))); |
| 1064 |
} |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
int |
| 1078 |
bcpio_wr(ARCHD *arcn) |
| 1079 |
{ |
| 1080 |
HD_BCPIO *hd; |
| 1081 |
int nsz; |
| 1082 |
char hdblk[sizeof(HD_BCPIO)]; |
| 1083 |
off_t t_offt; |
| 1084 |
int t_int; |
| 1085 |
time_t t_timet; |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
if (map_dev(arcn, BCPIO_MASK, BCPIO_MASK) < 0) |
| 1092 |
return(-1); |
| 1093 |
|
| 1094 |
if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR)) |
| 1095 |
arcn->sb.st_rdev = 0; |
| 1096 |
hd = (HD_BCPIO *)hdblk; |
| 1097 |
|
| 1098 |
switch (arcn->type) { |
| 1099 |
case PAX_CTG: |
| 1100 |
case PAX_REG: |
| 1101 |
case PAX_HRG: |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
arcn->pad = BCPIO_PAD(arcn->sb.st_size); |
| 1107 |
hd->h_filesize_1[0] = CHR_WR_0(arcn->sb.st_size); |
| 1108 |
hd->h_filesize_1[1] = CHR_WR_1(arcn->sb.st_size); |
| 1109 |
hd->h_filesize_2[0] = CHR_WR_2(arcn->sb.st_size); |
| 1110 |
hd->h_filesize_2[1] = CHR_WR_3(arcn->sb.st_size); |
| 1111 |
t_offt = (off_t)(SHRT_EXT(hd->h_filesize_1)); |
| 1112 |
t_offt = (t_offt<<16) | ((off_t)(SHRT_EXT(hd->h_filesize_2))); |
| 1113 |
|
| 1114 |
if ((off_t)arcn->sb.st_size != t_offt) { |
| 1115 |
paxwarn(1, "File is too large for %s format %s", |
| 1116 |
"bcpio", arcn->org_name); |
| 1117 |
return (1); |
| 1118 |
} |
| 1119 |
break; |
| 1120 |
case PAX_SLK: |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
arcn->pad = 0; |
| 1126 |
hd->h_filesize_1[0] = CHR_WR_0(arcn->ln_nlen); |
| 1127 |
hd->h_filesize_1[1] = CHR_WR_1(arcn->ln_nlen); |
| 1128 |
hd->h_filesize_2[0] = CHR_WR_2(arcn->ln_nlen); |
| 1129 |
hd->h_filesize_2[1] = CHR_WR_3(arcn->ln_nlen); |
| 1130 |
t_int = (int)(SHRT_EXT(hd->h_filesize_1)); |
| 1131 |
t_int = (t_int << 16) | ((int)(SHRT_EXT(hd->h_filesize_2))); |
| 1132 |
if (arcn->ln_nlen != t_int) |
| 1133 |
goto out; |
| 1134 |
break; |
| 1135 |
default: |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
arcn->pad = 0; |
| 1140 |
hd->h_filesize_1[0] = (char)0; |
| 1141 |
hd->h_filesize_1[1] = (char)0; |
| 1142 |
hd->h_filesize_2[0] = (char)0; |
| 1143 |
hd->h_filesize_2[1] = (char)0; |
| 1144 |
break; |
| 1145 |
} |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
hd->h_magic[0] = CHR_WR_2(MAGIC); |
| 1151 |
hd->h_magic[1] = CHR_WR_3(MAGIC); |
| 1152 |
hd->h_dev[0] = CHR_WR_2(arcn->sb.st_dev); |
| 1153 |
hd->h_dev[1] = CHR_WR_3(arcn->sb.st_dev); |
| 1154 |
if (arcn->sb.st_dev != (dev_t)(SHRT_EXT(hd->h_dev))) |
| 1155 |
goto out; |
| 1156 |
hd->h_ino[0] = CHR_WR_2(arcn->sb.st_ino); |
| 1157 |
hd->h_ino[1] = CHR_WR_3(arcn->sb.st_ino); |
| 1158 |
if (arcn->sb.st_ino != (ino_t)(SHRT_EXT(hd->h_ino))) |
| 1159 |
goto out; |
| 1160 |
hd->h_mode[0] = CHR_WR_2(arcn->sb.st_mode); |
| 1161 |
hd->h_mode[1] = CHR_WR_3(arcn->sb.st_mode); |
| 1162 |
if (arcn->sb.st_mode != (mode_t)(SHRT_EXT(hd->h_mode))) |
| 1163 |
goto out; |
| 1164 |
hd->h_uid[0] = CHR_WR_2(arcn->sb.st_uid); |
| 1165 |
hd->h_uid[1] = CHR_WR_3(arcn->sb.st_uid); |
| 1166 |
if (arcn->sb.st_uid != (uid_t)(SHRT_EXT(hd->h_uid))) |
| 1167 |
goto out; |
| 1168 |
hd->h_gid[0] = CHR_WR_2(arcn->sb.st_gid); |
| 1169 |
hd->h_gid[1] = CHR_WR_3(arcn->sb.st_gid); |
| 1170 |
if (arcn->sb.st_gid != (gid_t)(SHRT_EXT(hd->h_gid))) |
| 1171 |
goto out; |
| 1172 |
hd->h_nlink[0] = CHR_WR_2(arcn->sb.st_nlink); |
| 1173 |
hd->h_nlink[1] = CHR_WR_3(arcn->sb.st_nlink); |
| 1174 |
if (arcn->sb.st_nlink != (nlink_t)(SHRT_EXT(hd->h_nlink))) |
| 1175 |
goto out; |
| 1176 |
hd->h_rdev[0] = CHR_WR_2(arcn->sb.st_rdev); |
| 1177 |
hd->h_rdev[1] = CHR_WR_3(arcn->sb.st_rdev); |
| 1178 |
if (arcn->sb.st_rdev != (dev_t)(SHRT_EXT(hd->h_rdev))) |
| 1179 |
goto out; |
| 1180 |
if (arcn->sb.st_mtime > 0) { |
| 1181 |
hd->h_mtime_1[0] = CHR_WR_0(arcn->sb.st_mtime); |
| 1182 |
hd->h_mtime_1[1] = CHR_WR_1(arcn->sb.st_mtime); |
| 1183 |
hd->h_mtime_2[0] = CHR_WR_2(arcn->sb.st_mtime); |
| 1184 |
hd->h_mtime_2[1] = CHR_WR_3(arcn->sb.st_mtime); |
| 1185 |
t_timet = (time_t)SHRT_EXT(hd->h_mtime_1); |
| 1186 |
t_timet = t_timet << 16 | (time_t)SHRT_EXT(hd->h_mtime_2); |
| 1187 |
if (arcn->sb.st_mtime != t_timet) |
| 1188 |
goto out; |
| 1189 |
} else { |
| 1190 |
hd->h_mtime_1[0] = hd->h_mtime_1[1] = 0; |
| 1191 |
hd->h_mtime_2[0] = hd->h_mtime_2[1] = 0; |
| 1192 |
} |
| 1193 |
nsz = arcn->nlen + 1; |
| 1194 |
hd->h_namesize[0] = CHR_WR_2(nsz); |
| 1195 |
hd->h_namesize[1] = CHR_WR_3(nsz); |
| 1196 |
if (nsz != (int)(SHRT_EXT(hd->h_namesize))) |
| 1197 |
goto out; |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
if ((wr_rdbuf(hdblk, (int)sizeof(HD_BCPIO)) < 0) || |
| 1203 |
(wr_rdbuf(arcn->name, nsz) < 0) || |
| 1204 |
(wr_skip(BCPIO_PAD(sizeof(HD_BCPIO) + nsz)) < 0)) { |
| 1205 |
paxwarn(1, "Unable to write %s %s for %s", |
| 1206 |
"bcpio", "header", arcn->org_name); |
| 1207 |
return (-1); |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
if (PAX_IS_REG(arcn->type) || (arcn->type == PAX_HRG)) |
| 1214 |
return(0); |
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
if (arcn->type != PAX_SLK) |
| 1220 |
return(1); |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
if ((wr_rdbuf(arcn->ln_name, arcn->ln_nlen) < 0) || |
| 1226 |
(wr_skip(BCPIO_PAD(arcn->ln_nlen)) < 0)) { |
| 1227 |
paxwarn(1, "Unable to write %s %s for %s", |
| 1228 |
"bcpio", "link name", arcn->org_name); |
| 1229 |
return (-1); |
| 1230 |
} |
| 1231 |
return(1); |
| 1232 |
|
| 1233 |
out: |
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
paxwarn(1, "%s header field is too small for file %s", |
| 1238 |
"bcpio", arcn->org_name); |
| 1239 |
return (1); |
| 1240 |
} |
| 1241 |
#endif |