Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
4.8 KiB

  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. void do_cpio(int argc, char **argv) /* Xn */
  71. #else
  72. void do_cpio(argc, argv) /* Xn */
  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. #ifdef _POSIX2_SOURCE /* Xn */
  89. #ifdef DF_TRACE_DEBUG
  90. printf("DF_TRACE_DEBUG: void do_cpio() in cpio.c\n");
  91. #endif
  92. while ((c = getopt(argc, (const char * const *) argv, "D:Bacdfilmoprtuv")) != EOF) { /* Xn */
  93. #else /* Xn */
  94. while ((c = getopt(argc, argv, "D:Bacdfilmoprtuv")) != EOF) {
  95. #endif /* Xn */
  96. switch (c) {
  97. case 'i':
  98. f_extract = 1;
  99. break;
  100. case 'o':
  101. f_create = 1;
  102. break;
  103. case 'p':
  104. f_pass = 1;
  105. dirname = argv[--argc];
  106. /* check to make sure that the argument is a directory */
  107. if (LSTAT(dirname, &st) < 0) {
  108. fatal(strerror(errno)); /* Xn */
  109. }
  110. if ((st.sb_mode & S_IFMT) != S_IFDIR) {
  111. fatal("Not a directory");
  112. }
  113. break;
  114. case 'B':
  115. blocksize = BLOCK;
  116. break;
  117. case 'a':
  118. f_access_time = 1;
  119. break;
  120. case 'c':
  121. break;
  122. case 'D':
  123. ar_file = optarg;
  124. break;
  125. case 'd':
  126. f_dir_create = 1;
  127. break;
  128. case 'f':
  129. f_reverse_match = 1;
  130. break;
  131. case 'l':
  132. f_link = 1;
  133. break;
  134. case 'm':
  135. f_mtime = 1;
  136. break;
  137. case 'r':
  138. f_interactive = 1;
  139. break;
  140. case 't':
  141. f_list = 1;
  142. break;
  143. case 'u':
  144. f_unconditional = 1;
  145. break;
  146. case 'v':
  147. f_verbose = 1;
  148. break;
  149. default:
  150. usage();
  151. }
  152. }
  153. if (f_create + f_pass + f_extract != 1) {
  154. usage();
  155. }
  156. if (!f_pass) {
  157. buf_allocate((OFFSET) blocksize);
  158. }
  159. if (f_extract) {
  160. open_archive(AR_READ); /* Open for reading */
  161. read_archive();
  162. } else if (f_create) {
  163. open_archive(AR_WRITE);
  164. create_archive();
  165. } else if (f_pass) {
  166. pass(dirname);
  167. }
  168. /* print out the total block count transfered */
  169. fprintf(stderr, "%ld Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
  170. exit(0);
  171. /* NOTREACHED */
  172. }
  173. /* usage - print a helpful message and exit
  174. *
  175. * DESCRIPTION
  176. *
  177. * Usage prints out the usage message for the CPIO interface and then
  178. * exits with a non-zero termination status. This is used when a user
  179. * has provided non-existant or incompatible command line arguments.
  180. *
  181. * RETURNS
  182. *
  183. * Returns an exit status of 1 to the parent process.
  184. *
  185. */
  186. #ifdef __STDC__
  187. static void usage(void)
  188. #else
  189. static void usage()
  190. #endif
  191. {
  192. #ifdef DF_TRACE_DEBUG
  193. printf("DF_TRACE_DEBUG: static void usage() in cpio.c\n");
  194. #endif
  195. fprintf(stderr, "Usage: %s -o[Bacv]\n", myname);
  196. fprintf(stderr, " %s -i[Bcdmrtuvf] [pattern...]\n", myname);
  197. fprintf(stderr, " %s -p[adlmruv] directory\n", myname);
  198. exit(1);
  199. }