cpio.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* $Source: /u/mark/src/pax/RCS/cpio.c,v $
  2. *
  3. * $Revision: 1.2 $
  4. *
  5. * cpio.c - Cpio specific functions for archive handling
  6. *
  7. * DESCRIPTION
  8. *
  9. * These function provide a cpio conformant interface to the pax
  10. * program.
  11. *
  12. * AUTHOR
  13. *
  14. * Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
  15. *
  16. * Sponsored by The USENIX Association for public distribution.
  17. *
  18. * Copyright (c) 1989 Mark H. Colburn.
  19. * All rights reserved.
  20. *
  21. * Redistribution and use in source and binary forms are permitted
  22. * provided that the above copyright notice is duplicated in all such
  23. * forms and that any documentation, advertising materials, and other
  24. * materials related to such distribution and use acknowledge that the
  25. * software was developed * by Mark H. Colburn and sponsored by The
  26. * USENIX Association.
  27. *
  28. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  29. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  30. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  31. *
  32. * $Log: cpio.c,v $
  33. * Revision 1.2 89/02/12 10:04:13 mark
  34. * 1.2 release fixes
  35. *
  36. * Revision 1.1 88/12/23 18:02:05 mark
  37. * Initial revision
  38. *
  39. */
  40. #ifndef lint
  41. static char *ident = "$Id: cpio.c,v 1.2 89/02/12 10:04:13 mark Exp $";
  42. static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
  43. #endif /* ! lint */
  44. /* Headers */
  45. #include "pax.h"
  46. /* Function Prototypes */
  47. #ifdef __STDC__
  48. static void usage(void);
  49. #else /* !__STDC__ */
  50. static void usage();
  51. #endif /* __STDC__ */
  52. /* do_cpio - handle cpio format archives
  53. *
  54. * DESCRIPTION
  55. *
  56. * Do_cpio provides a standard CPIO interface to the PAX program. All
  57. * of the standard cpio flags are available, and the behavior of the
  58. * program mimics traditonal cpio.
  59. *
  60. * PARAMETERS
  61. *
  62. * int argc - command line argument count
  63. * char **argv - pointer to command line arguments
  64. *
  65. * RETURNS
  66. *
  67. * Nothing.
  68. */
  69. #ifdef __STDC__
  70. int do_cpio(int argc, char **argv)
  71. #else
  72. int do_cpio(argc, argv)
  73. int argc;
  74. char **argv;
  75. #endif
  76. {
  77. int c;
  78. char *dirname;
  79. Stat st;
  80. /* default input/output file for CPIO is STDIN/STDOUT */
  81. ar_file = "-";
  82. names_from_stdin = 1;
  83. /* set up the flags to reflect the default CPIO inteface. */
  84. blocksize = BLOCKSIZE;
  85. ar_interface = CPIO;
  86. ar_format = CPIO;
  87. msgfile=stderr;
  88. while ((c = getopt(argc, argv, "D:Bacdfilmoprtuv")) != EOF) {
  89. switch (c) {
  90. case 'i':
  91. f_extract = 1;
  92. break;
  93. case 'o':
  94. f_create = 1;
  95. break;
  96. case 'p':
  97. f_pass = 1;
  98. dirname = argv[--argc];
  99. /* check to make sure that the argument is a directory */
  100. if (LSTAT(dirname, &st) < 0) {
  101. fatal(strerror());
  102. }
  103. if ((st.sb_mode & S_IFMT) != S_IFDIR) {
  104. fatal("Not a directory");
  105. }
  106. break;
  107. case 'B':
  108. blocksize = BLOCK;
  109. break;
  110. case 'a':
  111. f_access_time = 1;
  112. break;
  113. case 'c':
  114. break;
  115. case 'D':
  116. ar_file = optarg;
  117. break;
  118. case 'd':
  119. f_dir_create = 1;
  120. break;
  121. case 'f':
  122. f_reverse_match = 1;
  123. break;
  124. case 'l':
  125. f_link = 1;
  126. break;
  127. case 'm':
  128. f_mtime = 1;
  129. break;
  130. case 'r':
  131. f_interactive = 1;
  132. break;
  133. case 't':
  134. f_list = 1;
  135. break;
  136. case 'u':
  137. f_unconditional = 1;
  138. break;
  139. case 'v':
  140. f_verbose = 1;
  141. break;
  142. default:
  143. usage();
  144. }
  145. }
  146. if (f_create + f_pass + f_extract != 1) {
  147. usage();
  148. }
  149. if (!f_pass) {
  150. buf_allocate((OFFSET) blocksize);
  151. }
  152. if (f_extract) {
  153. open_archive(AR_READ); /* Open for reading */
  154. read_archive();
  155. } else if (f_create) {
  156. open_archive(AR_WRITE);
  157. create_archive();
  158. } else if (f_pass) {
  159. pass(dirname);
  160. }
  161. /* print out the total block count transfered */
  162. fprintf(stderr, "%ld Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
  163. exit(0);
  164. /* NOTREACHED */
  165. }
  166. /* usage - print a helpful message and exit
  167. *
  168. * DESCRIPTION
  169. *
  170. * Usage prints out the usage message for the CPIO interface and then
  171. * exits with a non-zero termination status. This is used when a user
  172. * has provided non-existant or incompatible command line arguments.
  173. *
  174. * RETURNS
  175. *
  176. * Returns an exit status of 1 to the parent process.
  177. *
  178. */
  179. #ifdef __STDC__
  180. static void usage(void)
  181. #else
  182. static void usage()
  183. #endif
  184. {
  185. fprintf(stderr, "Usage: %s -o[Bacv]\n", myname);
  186. fprintf(stderr, " %s -i[Bcdmrtuvf] [pattern...]\n", myname);
  187. fprintf(stderr, " %s -p[adlmruv] directory\n", myname);
  188. exit(1);
  189. }