cpio.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * cpio - copy file archives in and out
  3. *
  4. * Gunnar Ritter, Freiburg i. Br., Germany, April 2003.
  5. */
  6. /*
  7. * Copyright (c) 2003 Gunnar Ritter
  8. *
  9. * This software is provided 'as-is', without any express or implied
  10. * warranty. In no event will the authors be held liable for any damages
  11. * arising from the use of this software.
  12. *
  13. * Permission is granted to anyone to use this software for any purpose,
  14. * including commercial applications, and to alter it and redistribute
  15. * it freely, subject to the following restrictions:
  16. *
  17. * 1. The origin of this software must not be misrepresented; you must not
  18. * claim that you wrote the original software. If you use this software
  19. * in a product, an acknowledgment in the product documentation would be
  20. * appreciated but is not required.
  21. *
  22. * 2. Altered source versions must be plainly marked as such, and must not be
  23. * misrepresented as being the original software.
  24. *
  25. * 3. This notice may not be removed or altered from any source distribution.
  26. */
  27. /* Sccsid @(#)cpio.h 1.29 (gritter) 3/26/07 */
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <inttypes.h>
  31. enum {
  32. FMT_NONE = 00000000, /* no format chosen yet */
  33. TYP_PAX = 00000010, /* uses pax-like extended headers */
  34. TYP_BE = 00000100, /* this binary archive is big-endian */
  35. TYP_SGI = 00000200, /* SGI cpio -K flag binary archive */
  36. TYP_SCO = 00000200, /* SCO UnixWare 7.1 extended archive */
  37. TYP_CRC = 00000400, /* this has a SVR4 'crc' checksum */
  38. TYP_BINARY = 00001000, /* this is a binary cpio type */
  39. TYP_OCPIO = 00002000, /* this is an old cpio type */
  40. TYP_NCPIO = 00004000, /* this is a SVR4 cpio type */
  41. TYP_CRAY = 00010000, /* this is a Cray cpio archive */
  42. TYP_CPIO = 00077000, /* this is a cpio type */
  43. TYP_OTAR = 00100000, /* this is an old tar type */
  44. TYP_USTAR = 00200000, /* this is a ustar type */
  45. TYP_BAR = 00400000, /* this is a bar type */
  46. TYP_TAR = 00700000, /* this is a tar type */
  47. FMT_ODC = 00002001, /* POSIX ASCII cpio format */
  48. FMT_DEC = 00002002, /* DEC extended cpio format */
  49. FMT_BINLE = 00003001, /* binary (default) cpio format LE */
  50. FMT_BINBE = 00003101, /* binary (default) cpio format BE */
  51. FMT_SGILE = 00003201, /* IRIX-style -K binary format LE */
  52. FMT_SGIBE = 00003301, /* IRIX-style -K binary format BE */
  53. FMT_ASC = 00004001, /* SVR4 ASCII cpio format */
  54. FMT_SCOASC = 00004201, /* UnixWare 7.1 ASCII cpio format */
  55. FMT_CRC = 00004401, /* SVR4 ASCII cpio format w/checksum */
  56. FMT_SCOCRC = 00004601, /* UnixWare 7.1 ASCII cpio w/checksum */
  57. FMT_CRAY = 00010001, /* Cray cpio, UNICOS 6 and later */
  58. FMT_CRAY5 = 00010002, /* Cray cpio, UNICOS 5 and earlier */
  59. FMT_OTAR = 00100001, /* obsolete tar format */
  60. FMT_TAR = 00200001, /* our tar format type */
  61. FMT_USTAR = 00200002, /* ustar format */
  62. FMT_GNUTAR = 00200003, /* GNU tar format type */
  63. FMT_PAX = 00200011, /* POSIX.1-2001 pax format type */
  64. FMT_SUN = 00200012, /* Sun extended tar format type */
  65. FMT_BAR = 00400001, /* bar format type */
  66. FMT_ZIP = 01000000 /* zip format */
  67. } fmttype;
  68. /*
  69. * Zip compression method.
  70. */
  71. enum cmethod {
  72. C_STORED = 0, /* no compression */
  73. C_SHRUNK = 1,
  74. C_REDUCED1 = 2,
  75. C_REDUCED2 = 3,
  76. C_REDUCED3 = 4,
  77. C_REDUCED4 = 5,
  78. C_IMPLODED = 6,
  79. C_TOKENIZED = 7,
  80. C_DEFLATED = 8,
  81. C_ENHDEFLD = 9,
  82. C_DCLIMPLODED = 10,
  83. C_PKRESERVED = 11,
  84. C_BZIP2 = 12,
  85. };
  86. /*
  87. * A collection of the interesting facts about a file in copy-in mode.
  88. */
  89. struct file {
  90. struct stat f_st; /* file stat */
  91. long long f_rmajor; /* st_rdev major */
  92. long long f_rminor; /* st_rdev minor */
  93. long long f_dsize; /* display size */
  94. long long f_csize; /* compressed size */
  95. long long f_Kbase; /* base size for -K */
  96. long long f_Krest; /* rest size for -K */
  97. long long f_Ksize; /* faked -K size field */
  98. char *f_name; /* file name */
  99. size_t f_nsiz; /* file name size */
  100. char *f_lnam; /* link name */
  101. size_t f_lsiz; /* link name size */
  102. uint32_t f_chksum; /* checksum */
  103. int f_pad; /* padding size */
  104. int f_fd; /* file descriptor (for pass mode) */
  105. enum cmethod f_cmethod; /* zip compression method */
  106. enum {
  107. FG_CRYPT = 0001, /* encrypted zip file */
  108. FG_BIT1 = 0002,
  109. FG_BIT2 = 0004,
  110. FG_DESC = 0010 /* zip file with data descriptor */
  111. } f_gflag; /* zip general flag */
  112. enum {
  113. OF_ZIP64 = 0001 /* is a zip64 archive entry */
  114. } f_oflag; /* other flags */
  115. };
  116. /*
  117. * Patterns for gmatch().
  118. */
  119. struct glist {
  120. struct glist *g_nxt;
  121. const char *g_pat;
  122. unsigned g_gotcha : 1;
  123. unsigned g_not : 1;
  124. unsigned g_art : 1;
  125. };
  126. extern int aflag;
  127. extern int Aflag;
  128. extern int bflag;
  129. extern int Bflag;
  130. extern int cflag;
  131. extern int Cflag;
  132. extern int dflag;
  133. extern int Dflag;
  134. extern int eflag;
  135. extern int cray_eflag;
  136. extern const char *Eflag;
  137. extern int fflag;
  138. extern int Hflag;
  139. extern const char *Iflag;
  140. extern int kflag;
  141. extern int Kflag;
  142. extern int lflag;
  143. extern int Lflag;
  144. extern int mflag;
  145. extern const char *Mflag;
  146. extern const char *Oflag;
  147. extern int Pflag;
  148. extern int rflag;
  149. extern const char *Rflag;
  150. extern int sflag;
  151. extern int Sflag;
  152. extern int tflag;
  153. extern int uflag;
  154. extern int hp_Uflag;
  155. extern int vflag;
  156. extern int Vflag;
  157. extern int sixflag;
  158. extern int action;
  159. extern long long errcnt;
  160. extern int blksiz;
  161. extern int sysv3;
  162. extern int printsev;
  163. extern char *progname;
  164. extern struct glist *patterns;
  165. enum { /* type of pax command this is */
  166. PAX_TYPE_CPIO = 0, /* not a pax command */
  167. PAX_TYPE_PAX1992 = 1, /* POSIX.2 pax command */
  168. PAX_TYPE_PAX2001 = 2 /* POSIX.1-2001 pax command */
  169. } pax;
  170. extern int pax_dflag;
  171. extern int pax_kflag;
  172. extern int pax_nflag;
  173. extern int pax_sflag;
  174. extern int pax_uflag;
  175. extern int pax_Xflag;
  176. enum {
  177. PAX_P_NONE = 0000,
  178. PAX_P_ATIME = 0001,
  179. PAX_P_MTIME = 0004,
  180. PAX_P_OWNER = 0010,
  181. PAX_P_MODE = 0020,
  182. PAX_P_EVERY = 0400
  183. } pax_preserve;
  184. extern size_t (*ofiles)(char **, size_t *);
  185. extern void (*prtime)(time_t);
  186. extern ssize_t bread(char *, size_t);
  187. extern void bunread(const char *, size_t);
  188. extern void swap(char *, size_t, int, int);
  189. extern void msg(int, int, const char *, ...);
  190. extern void emsg(int, const char *, ...);
  191. extern void unexeoa(void);
  192. extern int setfmt(char *);
  193. extern char *oneintfmt(const char *);
  194. extern int setreassign(const char *);
  195. extern void addg(const char *, int);
  196. extern void *srealloc(void *, size_t);
  197. extern void *smalloc(size_t);
  198. extern void *scalloc(size_t, size_t);
  199. extern void *svalloc(size_t, int);
  200. extern char *sstrdup(const char *);
  201. extern int pax_options(char *, int);
  202. extern int zipunshrink(struct file *, const char *, int, int, uint32_t *);
  203. extern int zipexplode(struct file *, const char *, int, int, uint32_t *);
  204. extern int zipexpand(struct file *, const char *, int, int, uint32_t *);
  205. extern int zipinflate(struct file *, const char *, int, int, uint32_t *);
  206. extern int zipunbz2(struct file *, const char *, int, int, uint32_t *);
  207. extern int zipblast(struct file *, const char *, int, int, uint32_t *);
  208. extern uint32_t zipcrc(uint32_t, const uint8_t *, size_t);
  209. extern void flags(int, char **);
  210. extern void usage(void);
  211. extern int pax_track(const char *, time_t);
  212. extern void pax_prlink(struct file *);
  213. extern int pax_sname(char **, size_t *);
  214. extern void pax_onexit(void);