Home | History | Annotate | Line # | Download | only in cpio
      1 /*-
      2  * SPDX-License-Identifier: BSD-2-Clause
      3  *
      4  * Copyright (c) 2003-2007 Tim Kientzle
      5  * All rights reserved.
      6  */
      7 
      8 #ifndef CPIO_H_INCLUDED
      9 #define CPIO_H_INCLUDED
     10 
     11 #include "cpio_platform.h"
     12 #include <stdio.h>
     13 
     14 /*
     15  * The internal state for the "cpio" program.
     16  *
     17  * Keeping all of the state in a structure like this simplifies memory
     18  * leak testing (at exit, anything left on the heap is suspect).  A
     19  * pointer to this structure is passed to most cpio internal
     20  * functions.
     21  */
     22 struct cpio {
     23 	/* Option parsing */
     24 	const char	 *argument;
     25 
     26 	/* Options */
     27 	int		  add_filter; /* --uuencode */
     28 	const char	 *filename;
     29 	int		  mode; /* -i -o -p */
     30 	int		  compress; /* -j, -y, or -z */
     31 	const char	 *format; /* -H format */
     32 	int		  bytes_per_block; /* -b block_size */
     33 	int		  verbose;   /* -v */
     34 	int		  dot;  /* -V */
     35 	int		  quiet;   /* --quiet */
     36 	int		  extract_flags; /* Flags for extract operation */
     37 	const char	 *compress_program;
     38 	int		  option_append; /* -A, only relevant for -o */
     39 	int		  option_atime_restore; /* -a */
     40 	int		  option_follow_links; /* -L */
     41 	int		  option_link; /* -l */
     42 	int		  option_list; /* -t */
     43 	char		  option_null; /* --null */
     44 	int		  option_numeric_uid_gid; /* -n */
     45 	int		  option_pwb; /* -6 */
     46 	int		  option_rename; /* -r */
     47 	char		 *destdir;
     48 	size_t		  destdir_len;
     49 	size_t		  pass_destpath_alloc;
     50 	char		 *pass_destpath;
     51 	int		  uid_override;
     52 	char		 *uname_override;
     53 	int		  gid_override;
     54 	char		 *gname_override;
     55 	int		  day_first; /* true if locale prefers day/mon */
     56 	const char	 *passphrase;
     57 
     58 	/* If >= 0, then close this when done. */
     59 	int		  fd;
     60 
     61 	/* Miscellaneous state information */
     62 	struct archive	 *archive;
     63 	struct archive	 *archive_read_disk;
     64 	int		  argc;
     65 	char		**argv;
     66 	int		  return_value; /* Value returned by main() */
     67 	struct archive_entry_linkresolver *linkresolver;
     68 
     69 	struct name_cache *uname_cache;
     70 	struct name_cache *gname_cache;
     71 
     72 	/* Work data. */
     73 	struct archive   *matching;
     74 	char		 *ppbuff;
     75 };
     76 
     77 struct cpio_owner {
     78         int uid;
     79         int gid;
     80         char *uname;
     81         char *gname;
     82 };
     83 
     84 int owner_parse(const char *, struct cpio_owner *, const char **);
     85 
     86 /* Fake short equivalents for long options that otherwise lack them. */
     87 enum {
     88 	OPTION_B64ENCODE = 1,
     89 	OPTION_GRZIP,
     90 	OPTION_INSECURE,
     91 	OPTION_LRZIP,
     92 	OPTION_LZ4,
     93 	OPTION_LZMA,
     94 	OPTION_LZOP,
     95 	OPTION_PASSPHRASE,
     96 	OPTION_NO_PRESERVE_OWNER,
     97 	OPTION_PRESERVE_OWNER,
     98 	OPTION_QUIET,
     99 	OPTION_UUENCODE,
    100 	OPTION_VERSION,
    101 	OPTION_ZSTD,
    102 };
    103 
    104 int	cpio_getopt(struct cpio *cpio);
    105 
    106 #endif
    107