list.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. /* List a tar archive.
  2. Copyright (C) 1988, 1992, 1993 Free Software Foundation
  3. This file is part of GNU Tar.
  4. GNU Tar is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Tar is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Tar; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. /*
  16. * List a tar archive.
  17. *
  18. * Also includes support routines for reading a tar archive.
  19. *
  20. * this version written 26 Aug 1985 by John Gilmore (ihnp4!hoptoad!gnu).
  21. */
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include <sys/types.h>
  25. #include <errno.h>
  26. #ifndef STDC_HEADERS
  27. extern int errno;
  28. #endif
  29. #include <time.h>
  30. #ifdef BSD42
  31. #include <sys/file.h>
  32. #else
  33. #ifndef V7
  34. #include <fcntl.h>
  35. #endif
  36. #endif
  37. #define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
  38. #include "tar.h"
  39. #include "port.h"
  40. extern FILE *msg_file;
  41. long from_oct (); /* Decode octal number */
  42. void demode (); /* Print file mode */
  43. void restore_saved_dir_info ();
  44. PTR ck_malloc ();
  45. union record *head; /* Points to current archive header */
  46. struct stat hstat; /* Stat struct corresponding */
  47. int head_standard; /* Tape header is in ANSI format */
  48. int check_exclude ();
  49. void close_archive ();
  50. void decode_header ();
  51. int findgid ();
  52. int finduid ();
  53. void name_gather ();
  54. int name_match ();
  55. void names_notfound ();
  56. void open_archive ();
  57. void print_header ();
  58. int read_header ();
  59. void saverec ();
  60. void skip_file ();
  61. void skip_extended_headers ();
  62. extern char *quote_copy_string ();
  63. /*
  64. * Main loop for reading an archive.
  65. */
  66. void
  67. read_and (do_something)
  68. void (*do_something) ();
  69. {
  70. int status = 3; /* Initial status at start of archive */
  71. int prev_status;
  72. extern time_t new_time;
  73. char save_linkflag;
  74. name_gather (); /* Gather all the names */
  75. open_archive (1); /* Open for reading */
  76. for (;;)
  77. {
  78. prev_status = status;
  79. status = read_header ();
  80. switch (status)
  81. {
  82. case 1: /* Valid header */
  83. /* We should decode next field (mode) first... */
  84. /* Ensure incoming names are null terminated. */
  85. if (!name_match (current_file_name)
  86. || (f_new_files && hstat.st_mtime < new_time)
  87. || (f_exclude && check_exclude (current_file_name)))
  88. {
  89. int isextended = 0;
  90. if (head->header.linkflag == LF_VOLHDR
  91. || head->header.linkflag == LF_MULTIVOL
  92. || head->header.linkflag == LF_NAMES)
  93. {
  94. (*do_something) ();
  95. continue;
  96. }
  97. if (f_show_omitted_dirs
  98. && head->header.linkflag == LF_DIR)
  99. msg ("Omitting %s\n", current_file_name);
  100. /* Skip past it in the archive */
  101. if (head->header.isextended)
  102. isextended = 1;
  103. save_linkflag = head->header.linkflag;
  104. userec (head);
  105. if (isextended)
  106. {
  107. /* register union record *exhdr;
  108. for (;;) {
  109. exhdr = findrec();
  110. if (!exhdr->ext_hdr.isextended) {
  111. userec(exhdr);
  112. break;
  113. }
  114. }
  115. userec(exhdr);*/
  116. skip_extended_headers ();
  117. }
  118. /* Skip to the next header on the archive */
  119. if (save_linkflag != LF_DIR)
  120. skip_file ((long) hstat.st_size);
  121. continue;
  122. }
  123. (*do_something) ();
  124. continue;
  125. /*
  126. * If the previous header was good, tell them
  127. * that we are skipping bad ones.
  128. */
  129. case 0: /* Invalid header */
  130. userec (head);
  131. switch (prev_status)
  132. {
  133. case 3: /* Error on first record */
  134. msg ("Hmm, this doesn't look like a tar archive.");
  135. /* FALL THRU */
  136. case 2: /* Error after record of zeroes */
  137. case 1: /* Error after header rec */
  138. msg ("Skipping to next file header...");
  139. case 0: /* Error after error */
  140. break;
  141. }
  142. continue;
  143. case 2: /* Record of zeroes */
  144. userec (head);
  145. status = prev_status; /* If error after 0's */
  146. if (f_ignorez)
  147. continue;
  148. /* FALL THRU */
  149. case EOF: /* End of archive */
  150. break;
  151. }
  152. break;
  153. };
  154. restore_saved_dir_info ();
  155. close_archive ();
  156. names_notfound (); /* Print names not found */
  157. }
  158. /*
  159. * Print a header record, based on tar options.
  160. */
  161. void
  162. list_archive ()
  163. {
  164. extern char *save_name;
  165. int isextended = 0; /* Flag to remember if head is extended */
  166. /* Save the record */
  167. saverec (&head);
  168. /* Print the header record */
  169. if (f_verbose)
  170. {
  171. if (f_verbose > 1)
  172. decode_header (head, &hstat, &head_standard, 0);
  173. print_header ();
  174. }
  175. if (f_gnudump && head->header.linkflag == LF_DUMPDIR)
  176. {
  177. size_t size, written, check;
  178. char *data;
  179. extern long save_totsize;
  180. extern long save_sizeleft;
  181. userec (head);
  182. if (f_multivol)
  183. {
  184. save_name = current_file_name;
  185. save_totsize = hstat.st_size;
  186. }
  187. for (size = hstat.st_size; size > 0; size -= written)
  188. {
  189. if (f_multivol)
  190. save_sizeleft = size;
  191. data = findrec ()->charptr;
  192. if (data == NULL)
  193. {
  194. msg ("EOF in archive file?");
  195. break;
  196. }
  197. written = endofrecs ()->charptr - data;
  198. if (written > size)
  199. written = size;
  200. errno = 0;
  201. check = fwrite (data, sizeof (char), written, msg_file);
  202. userec ((union record *) (data + written - 1));
  203. if (check != written)
  204. {
  205. msg_perror ("only wrote %ld of %ld bytes to file %s", check, written, current_file_name);
  206. skip_file ((long) (size) - written);
  207. break;
  208. }
  209. }
  210. if (f_multivol)
  211. save_name = 0;
  212. saverec ((union record **) 0); /* Unsave it */
  213. fputc ('\n', msg_file);
  214. fflush (msg_file);
  215. return;
  216. }
  217. saverec ((union record **) 0);/* Unsave it */
  218. /* Check to see if we have an extended header to skip over also */
  219. if (head->header.isextended)
  220. isextended = 1;
  221. /* Skip past the header in the archive */
  222. userec (head);
  223. /*
  224. * If we needed to skip any extended headers, do so now, by
  225. * reading extended headers and skipping past them in the
  226. * archive.
  227. */
  228. if (isextended)
  229. {
  230. /* register union record *exhdr;
  231. for (;;) {
  232. exhdr = findrec();
  233. if (!exhdr->ext_hdr.isextended) {
  234. userec(exhdr);
  235. break;
  236. }
  237. userec(exhdr);
  238. }*/
  239. skip_extended_headers ();
  240. }
  241. if (f_multivol)
  242. save_name = current_file_name;
  243. /* Skip to the next header on the archive */
  244. skip_file ((long) hstat.st_size);
  245. if (f_multivol)
  246. save_name = 0;
  247. }
  248. /*
  249. * Read a record that's supposed to be a header record.
  250. * Return its address in "head", and if it is good, the file's
  251. * size in hstat.st_size.
  252. *
  253. * Return 1 for success, 0 if the checksum is bad, EOF on eof,
  254. * 2 for a record full of zeros (EOF marker).
  255. *
  256. * You must always userec(head) to skip past the header which this
  257. * routine reads.
  258. */
  259. int
  260. read_header ()
  261. {
  262. register int i;
  263. register long sum, signed_sum, recsum;
  264. register char *p;
  265. register union record *header;
  266. long from_oct ();
  267. char **longp;
  268. char *bp, *data;
  269. int size, written;
  270. static char *next_long_name, *next_long_link;
  271. char *name;
  272. recurse:
  273. header = findrec ();
  274. head = header; /* This is our current header */
  275. if (NULL == header)
  276. return EOF;
  277. recsum = from_oct (8, header->header.chksum);
  278. sum = 0;
  279. p = header->charptr;
  280. for (i = sizeof (*header); --i >= 0;)
  281. {
  282. /*
  283. * We can't use unsigned char here because of old compilers,
  284. * e.g. V7.
  285. */
  286. signed_sum += *p;
  287. sum += 0xFF & *p++;
  288. }
  289. /* Adjust checksum to count the "chksum" field as blanks. */
  290. for (i = sizeof (header->header.chksum); --i >= 0;)
  291. {
  292. sum -= 0xFF & header->header.chksum[i];
  293. signed_sum -= (char) header->header.chksum[i];
  294. }
  295. sum += ' ' * sizeof header->header.chksum;
  296. signed_sum += ' ' * sizeof header->header.chksum;
  297. if (sum == 8 * ' ')
  298. {
  299. /*
  300. * This is a zeroed record...whole record is 0's except
  301. * for the 8 blanks we faked for the checksum field.
  302. */
  303. return 2;
  304. }
  305. if (sum != recsum && signed_sum != recsum)
  306. return 0;
  307. /*
  308. * Good record. Decode file size and return.
  309. */
  310. if (header->header.linkflag == LF_LINK)
  311. hstat.st_size = 0; /* Links 0 size on tape */
  312. else
  313. hstat.st_size = from_oct (1 + 12, header->header.size);
  314. header->header.arch_name[NAMSIZ - 1] = '\0';
  315. if (header->header.linkflag == LF_LONGNAME
  316. || header->header.linkflag == LF_LONGLINK)
  317. {
  318. longp = ((header->header.linkflag == LF_LONGNAME)
  319. ? &next_long_name
  320. : &next_long_link);
  321. userec (header);
  322. if (*longp)
  323. free (*longp);
  324. bp = *longp = (char *) ck_malloc (hstat.st_size);
  325. for (size = hstat.st_size;
  326. size > 0;
  327. size -= written)
  328. {
  329. data = findrec ()->charptr;
  330. if (data == NULL)
  331. {
  332. msg ("Unexpected EOF on archive file");
  333. break;
  334. }
  335. written = endofrecs ()->charptr - data;
  336. if (written > size)
  337. written = size;
  338. bcopy (data, bp, written);
  339. bp += written;
  340. userec ((union record *) (data + written - 1));
  341. }
  342. goto recurse;
  343. }
  344. else
  345. {
  346. name = (next_long_name
  347. ? next_long_name
  348. : head->header.arch_name);
  349. if (current_file_name)
  350. free (current_file_name);
  351. current_file_name = ck_malloc (strlen (name) + 1);
  352. strcpy (current_file_name, name);
  353. name = (next_long_link
  354. ? next_long_link
  355. : head->header.arch_linkname);
  356. if (current_link_name)
  357. free (current_link_name);
  358. current_link_name = ck_malloc (strlen (name) + 1);
  359. strcpy (current_link_name, name);
  360. next_long_link = next_long_name = 0;
  361. return 1;
  362. }
  363. }
  364. /*
  365. * Decode things from a file header record into a "struct stat".
  366. * Also set "*stdp" to !=0 or ==0 depending whether header record is "Unix
  367. * Standard" tar format or regular old tar format.
  368. *
  369. * read_header() has already decoded the checksum and length, so we don't.
  370. *
  371. * If wantug != 0, we want the uid/group info decoded from Unix Standard
  372. * tapes (for extraction). If == 0, we are just printing anyway, so save time.
  373. *
  374. * decode_header should NOT be called twice for the same record, since the
  375. * two calls might use different "wantug" values and thus might end up with
  376. * different uid/gid for the two calls. If anybody wants the uid/gid they
  377. * should decode it first, and other callers should decode it without uid/gid
  378. * before calling a routine, e.g. print_header, that assumes decoded data.
  379. */
  380. void
  381. decode_header (header, st, stdp, wantug)
  382. register union record *header;
  383. register struct stat *st;
  384. int *stdp;
  385. int wantug;
  386. {
  387. long from_oct ();
  388. st->st_mode = from_oct (8, header->header.mode);
  389. st->st_mode &= 07777;
  390. st->st_mtime = from_oct (1 + 12, header->header.mtime);
  391. if (f_gnudump)
  392. {
  393. st->st_atime = from_oct (1 + 12, header->header.atime);
  394. st->st_ctime = from_oct (1 + 12, header->header.ctime);
  395. }
  396. if (0 == strcmp (header->header.magic, TMAGIC))
  397. {
  398. /* Unix Standard tar archive */
  399. *stdp = 1;
  400. if (wantug)
  401. {
  402. #ifdef NONAMES
  403. st->st_uid = from_oct (8, header->header.uid);
  404. st->st_gid = from_oct (8, header->header.gid);
  405. #else
  406. st->st_uid =
  407. (*header->header.uname
  408. ? finduid (header->header.uname)
  409. : from_oct (8, header->header.uid));
  410. st->st_gid =
  411. (*header->header.gname
  412. ? findgid (header->header.gname)
  413. : from_oct (8, header->header.gid));
  414. #endif
  415. }
  416. #if defined(S_IFBLK) || defined(S_IFCHR)
  417. switch (header->header.linkflag)
  418. {
  419. case LF_BLK:
  420. case LF_CHR:
  421. st->st_rdev = makedev (from_oct (8, header->header.devmajor),
  422. from_oct (8, header->header.devminor));
  423. }
  424. #endif
  425. }
  426. else
  427. {
  428. /* Old fashioned tar archive */
  429. *stdp = 0;
  430. st->st_uid = from_oct (8, header->header.uid);
  431. st->st_gid = from_oct (8, header->header.gid);
  432. st->st_rdev = 0;
  433. }
  434. }
  435. /*
  436. * Quick and dirty octal conversion.
  437. *
  438. * Result is -1 if the field is invalid (all blank, or nonoctal).
  439. */
  440. long
  441. from_oct (digs, where)
  442. register int digs;
  443. register char *where;
  444. {
  445. register long value;
  446. while (isspace (*where))
  447. { /* Skip spaces */
  448. where++;
  449. if (--digs <= 0)
  450. return -1; /* All blank field */
  451. }
  452. value = 0;
  453. while (digs > 0 && isodigit (*where))
  454. { /* Scan til nonoctal */
  455. value = (value << 3) | (*where++ - '0');
  456. --digs;
  457. }
  458. if (digs > 0 && *where && !isspace (*where))
  459. return -1; /* Ended on non-space/nul */
  460. return value;
  461. }
  462. /*
  463. * Actually print it.
  464. *
  465. * Plain and fancy file header block logging.
  466. * Non-verbose just prints the name, e.g. for "tar t" or "tar x".
  467. * This should just contain file names, so it can be fed back into tar
  468. * with xargs or the "-T" option. The verbose option can give a bunch
  469. * of info, one line per file. I doubt anybody tries to parse its
  470. * format, or if they do, they shouldn't. Unix tar is pretty random here
  471. * anyway.
  472. *
  473. * Note that print_header uses the globals <head>, <hstat>, and
  474. * <head_standard>, which must be set up in advance. This is not very clean
  475. * and should be cleaned up. FIXME.
  476. */
  477. #define UGSWIDTH 18 /* min width of User, group, size */
  478. /* UGSWIDTH of 18 means that with user and group names <= 8 chars the columns
  479. never shift during the listing. */
  480. #define DATEWIDTH 19 /* Last mod date */
  481. static int ugswidth = UGSWIDTH; /* Max width encountered so far */
  482. void
  483. print_header ()
  484. {
  485. char modes[11];
  486. char *timestamp;
  487. char uform[11], gform[11]; /* These hold formatted ints */
  488. char *user, *group;
  489. char size[24]; /* Holds a formatted long or maj, min */
  490. time_t longie; /* To make ctime() call portable */
  491. int pad;
  492. char *name;
  493. extern long baserec;
  494. if (f_sayblock)
  495. fprintf (msg_file, "rec %10d: ", baserec + (ar_record - ar_block));
  496. /* annofile(msg_file, (char *)NULL); */
  497. if (f_verbose <= 1)
  498. {
  499. /* Just the fax, mam. */
  500. char *name;
  501. name = quote_copy_string (current_file_name);
  502. if (name == 0)
  503. name = current_file_name;
  504. fprintf (msg_file, "%s\n", name);
  505. if (name != current_file_name)
  506. free (name);
  507. }
  508. else
  509. {
  510. /* File type and modes */
  511. modes[0] = '?';
  512. switch (head->header.linkflag)
  513. {
  514. case LF_VOLHDR:
  515. modes[0] = 'V';
  516. break;
  517. case LF_MULTIVOL:
  518. modes[0] = 'M';
  519. break;
  520. case LF_NAMES:
  521. modes[0] = 'N';
  522. break;
  523. case LF_LONGNAME:
  524. case LF_LONGLINK:
  525. msg ("Visible longname error\n");
  526. break;
  527. case LF_SPARSE:
  528. case LF_NORMAL:
  529. case LF_OLDNORMAL:
  530. case LF_LINK:
  531. modes[0] = '-';
  532. if ('/' == current_file_name[strlen (current_file_name) - 1])
  533. modes[0] = 'd';
  534. break;
  535. case LF_DUMPDIR:
  536. modes[0] = 'd';
  537. break;
  538. case LF_DIR:
  539. modes[0] = 'd';
  540. break;
  541. case LF_SYMLINK:
  542. modes[0] = 'l';
  543. break;
  544. case LF_BLK:
  545. modes[0] = 'b';
  546. break;
  547. case LF_CHR:
  548. modes[0] = 'c';
  549. break;
  550. case LF_FIFO:
  551. modes[0] = 'p';
  552. break;
  553. case LF_CONTIG:
  554. modes[0] = 'C';
  555. break;
  556. }
  557. demode ((unsigned) hstat.st_mode, modes + 1);
  558. /* Timestamp */
  559. longie = hstat.st_mtime;
  560. timestamp = ctime (&longie);
  561. timestamp[16] = '\0';
  562. timestamp[24] = '\0';
  563. /* User and group names */
  564. if (*head->header.uname && head_standard)
  565. {
  566. user = head->header.uname;
  567. }
  568. else
  569. {
  570. user = uform;
  571. (void) sprintf (uform, "%d",
  572. from_oct (8, head->header.uid));
  573. }
  574. if (*head->header.gname && head_standard)
  575. {
  576. group = head->header.gname;
  577. }
  578. else
  579. {
  580. group = gform;
  581. (void) sprintf (gform, "%d",
  582. from_oct (8, head->header.gid));
  583. }
  584. /* Format the file size or major/minor device numbers */
  585. switch (head->header.linkflag)
  586. {
  587. #if defined(S_IFBLK) || defined(S_IFCHR)
  588. case LF_CHR:
  589. case LF_BLK:
  590. (void) sprintf (size, "%d,%d",
  591. major (hstat.st_rdev),
  592. minor (hstat.st_rdev));
  593. break;
  594. #endif
  595. case LF_SPARSE:
  596. (void) sprintf (size, "%ld",
  597. from_oct (1 + 12, head->header.realsize));
  598. break;
  599. default:
  600. (void) sprintf (size, "%ld", (long) hstat.st_size);
  601. }
  602. /* Figure out padding and print the whole line. */
  603. pad = strlen (user) + strlen (group) + strlen (size) + 1;
  604. if (pad > ugswidth)
  605. ugswidth = pad;
  606. name = quote_copy_string (current_file_name);
  607. if (!name)
  608. name = current_file_name;
  609. fprintf (msg_file, "%s %s/%s %*s%s %s %s %s",
  610. modes,
  611. user,
  612. group,
  613. ugswidth - pad,
  614. "",
  615. size,
  616. timestamp + 4, timestamp + 20,
  617. name);
  618. if (name != current_file_name)
  619. free (name);
  620. switch (head->header.linkflag)
  621. {
  622. case LF_SYMLINK:
  623. name = quote_copy_string (current_link_name);
  624. if (!name)
  625. name = current_link_name;
  626. fprintf (msg_file, " -> %s\n", name);
  627. if (name != current_link_name)
  628. free (name);
  629. break;
  630. case LF_LINK:
  631. name = quote_copy_string (current_link_name);
  632. if (!name)
  633. name = current_link_name;
  634. fprintf (msg_file, " link to %s\n", current_link_name);
  635. if (name != current_link_name)
  636. free (name);
  637. break;
  638. default:
  639. fprintf (msg_file, " unknown file type '%c'\n",
  640. head->header.linkflag);
  641. break;
  642. case LF_OLDNORMAL:
  643. case LF_NORMAL:
  644. case LF_SPARSE:
  645. case LF_CHR:
  646. case LF_BLK:
  647. case LF_DIR:
  648. case LF_FIFO:
  649. case LF_CONTIG:
  650. case LF_DUMPDIR:
  651. putc ('\n', msg_file);
  652. break;
  653. case LF_VOLHDR:
  654. fprintf (msg_file, "--Volume Header--\n");
  655. break;
  656. case LF_MULTIVOL:
  657. fprintf (msg_file, "--Continued at byte %ld--\n", from_oct (1 + 12, head->header.offset));
  658. break;
  659. case LF_NAMES:
  660. fprintf (msg_file, "--Mangled file names--\n");
  661. break;
  662. }
  663. }
  664. fflush (msg_file);
  665. }
  666. /*
  667. * Print a similar line when we make a directory automatically.
  668. */
  669. void
  670. pr_mkdir (pathname, length, mode)
  671. char *pathname;
  672. int length;
  673. int mode;
  674. {
  675. char modes[11];
  676. char *name;
  677. extern long baserec;
  678. if (f_verbose > 1)
  679. {
  680. /* File type and modes */
  681. modes[0] = 'd';
  682. demode ((unsigned) mode, modes + 1);
  683. if (f_sayblock)
  684. fprintf (msg_file, "rec %10d: ", baserec + (ar_record - ar_block));
  685. /* annofile(msg_file, (char *)NULL); */
  686. name = quote_copy_string (pathname);
  687. if (!name)
  688. name = pathname;
  689. fprintf (msg_file, "%s %*s %.*s\n",
  690. modes,
  691. ugswidth + DATEWIDTH,
  692. "Creating directory:",
  693. length,
  694. pathname);
  695. if (name != pathname)
  696. free (name);
  697. }
  698. }
  699. /*
  700. * Skip over <size> bytes of data in records in the archive.
  701. */
  702. void
  703. skip_file (size)
  704. register long size;
  705. {
  706. union record *x;
  707. extern long save_totsize;
  708. extern long save_sizeleft;
  709. if (f_multivol)
  710. {
  711. save_totsize = size;
  712. save_sizeleft = size;
  713. }
  714. while (size > 0)
  715. {
  716. x = findrec ();
  717. if (x == NULL)
  718. { /* Check it... */
  719. msg ("Unexpected EOF on archive file");
  720. exit (EX_BADARCH);
  721. }
  722. userec (x);
  723. size -= RECORDSIZE;
  724. if (f_multivol)
  725. save_sizeleft -= RECORDSIZE;
  726. }
  727. }
  728. void
  729. skip_extended_headers ()
  730. {
  731. register union record *exhdr;
  732. for (;;)
  733. {
  734. exhdr = findrec ();
  735. if (!exhdr->ext_hdr.isextended)
  736. {
  737. userec (exhdr);
  738. break;
  739. }
  740. userec (exhdr);
  741. }
  742. }
  743. /*
  744. * Decode the mode string from a stat entry into a 9-char string and a null.
  745. */
  746. void
  747. demode (mode, string)
  748. register unsigned mode;
  749. register char *string;
  750. {
  751. register unsigned mask;
  752. register char *rwx = "rwxrwxrwx";
  753. for (mask = 0400; mask != 0; mask >>= 1)
  754. {
  755. if (mode & mask)
  756. *string++ = *rwx++;
  757. else
  758. {
  759. *string++ = '-';
  760. rwx++;
  761. }
  762. }
  763. if (mode & S_ISUID)
  764. if (string[-7] == 'x')
  765. string[-7] = 's';
  766. else
  767. string[-7] = 'S';
  768. if (mode & S_ISGID)
  769. if (string[-4] == 'x')
  770. string[-4] = 's';
  771. else
  772. string[-4] = 'S';
  773. if (mode & S_ISVTX)
  774. if (string[-1] == 'x')
  775. string[-1] = 't';
  776. else
  777. string[-1] = 'T';
  778. *string = '\0';
  779. }