1 | /* global.c - global variables and initial values for cpio.
|
---|
2 | Copyright (C) 1990, 1991, 1992, 2001, 2006 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This program 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 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public
|
---|
15 | License along with this program; if not, write to the Free
|
---|
16 | Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
17 | Boston, MA 02110-1301 USA. */
|
---|
18 |
|
---|
19 | #include <system.h>
|
---|
20 |
|
---|
21 | #include <sys/types.h>
|
---|
22 | #include "cpiohdr.h"
|
---|
23 | #include "dstring.h"
|
---|
24 | #include "extern.h"
|
---|
25 |
|
---|
26 | /* If true, reset access times after reading files (-a). */
|
---|
27 | int reset_time_flag = false;
|
---|
28 |
|
---|
29 | /* Block size value, initially 512. -B sets to 5120. */
|
---|
30 | int io_block_size = 512;
|
---|
31 |
|
---|
32 | /* The header format to recognize and produce. */
|
---|
33 | enum archive_format archive_format = arf_unknown;
|
---|
34 |
|
---|
35 | /* If true, create directories as needed. (-d with -i or -p) */
|
---|
36 | int create_dir_flag = false;
|
---|
37 |
|
---|
38 | /* If true, interactively rename files. (-r) */
|
---|
39 | int rename_flag = false;
|
---|
40 |
|
---|
41 | /* If non-NULL, the name of a file that will be read to
|
---|
42 | rename all of the files in the archive. --rename-batch-file. */
|
---|
43 | char *rename_batch_file = NULL;
|
---|
44 |
|
---|
45 | /* If true, print a table of contents of input. (-t) */
|
---|
46 | int table_flag = false;
|
---|
47 |
|
---|
48 | /* If true, copy unconditionally (older replaces newer). (-u) */
|
---|
49 | int unconditional_flag = false;
|
---|
50 |
|
---|
51 | /* If true, list the files processed, or ls -l style output with -t. (-v) */
|
---|
52 | int verbose_flag = false;
|
---|
53 |
|
---|
54 | /* If true, print a . for each file processed. (-V) */
|
---|
55 | int dot_flag = false;
|
---|
56 |
|
---|
57 | /* If true, link files whenever possible. Used with -p option. (-l) */
|
---|
58 | int link_flag = false;
|
---|
59 |
|
---|
60 | /* If true, retain previous file modification time. (-m) */
|
---|
61 | int retain_time_flag = false;
|
---|
62 |
|
---|
63 | /* Set true if crc_flag is true and we are doing a cpio -i. Used
|
---|
64 | by copy_files so it knows whether to compute the crc. */
|
---|
65 | int crc_i_flag = false;
|
---|
66 |
|
---|
67 | /* If true, append to end of archive. (-A) */
|
---|
68 | int append_flag = false;
|
---|
69 |
|
---|
70 | /* If true, swap bytes of each file during cpio -i. */
|
---|
71 | int swap_bytes_flag = false;
|
---|
72 |
|
---|
73 | /* If true, swap halfwords of each file during cpio -i. */
|
---|
74 | int swap_halfwords_flag = false;
|
---|
75 |
|
---|
76 | /* If true, we are swapping halfwords on the current file. */
|
---|
77 | int swapping_halfwords = false;
|
---|
78 |
|
---|
79 | /* If true, we are swapping bytes on the current file. */
|
---|
80 | int swapping_bytes = false;
|
---|
81 |
|
---|
82 | /* If true, set ownership of all files to UID `set_owner'. */
|
---|
83 | int set_owner_flag = false;
|
---|
84 | uid_t set_owner;
|
---|
85 |
|
---|
86 | /* If true, set group ownership of all files to GID `set_group'. */
|
---|
87 | int set_group_flag = false;
|
---|
88 | gid_t set_group;
|
---|
89 |
|
---|
90 | /* If true, do not chown the files. */
|
---|
91 | int no_chown_flag = false;
|
---|
92 |
|
---|
93 | /* If true, try to write sparse ("holey") files. */
|
---|
94 | int sparse_flag = false;
|
---|
95 |
|
---|
96 | /* If true, don't report number of blocks copied. */
|
---|
97 | int quiet_flag = false;
|
---|
98 |
|
---|
99 | /* If true, only read the archive and verify the files' CRC's, don't
|
---|
100 | actually extract the files. */
|
---|
101 | int only_verify_crc_flag = false;
|
---|
102 |
|
---|
103 | /* If true, don't use any absolute paths, prefix them by `./'. */
|
---|
104 | int no_abs_paths_flag = false;
|
---|
105 |
|
---|
106 | #ifdef DEBUG_CPIO
|
---|
107 | /* If true, print debugging information. */
|
---|
108 | int debug_flag = false;
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | /* File position of last header read. Only used during -A to determine
|
---|
112 | where the old TRAILER!!! record started. */
|
---|
113 | int last_header_start = 0;
|
---|
114 |
|
---|
115 | /* With -i; if true, copy only files that match any of the given patterns;
|
---|
116 | if false, copy only files that do not match any of the patterns. (-f) */
|
---|
117 | int copy_matching_files = true;
|
---|
118 |
|
---|
119 | /* With -itv; if true, list numeric uid and gid instead of translating them
|
---|
120 | into names. */
|
---|
121 | int numeric_uid = false;
|
---|
122 |
|
---|
123 | /* Name of file containing additional patterns (-E). */
|
---|
124 | char *pattern_file_name = NULL;
|
---|
125 |
|
---|
126 | /* Message to print when end of medium is reached (-M). */
|
---|
127 | char *new_media_message = NULL;
|
---|
128 |
|
---|
129 | /* With -M with %d, message to print when end of medium is reached. */
|
---|
130 | char *new_media_message_with_number = NULL;
|
---|
131 | char *new_media_message_after_number = NULL;
|
---|
132 |
|
---|
133 | /* File descriptor containing the archive. */
|
---|
134 | int archive_des;
|
---|
135 |
|
---|
136 | /* Name of file containing the archive, if known; NULL if stdin/out. */
|
---|
137 | char *archive_name = NULL;
|
---|
138 |
|
---|
139 | /* Name of the remote shell command, if known; NULL otherwise. */
|
---|
140 | char *rsh_command_option = NULL;
|
---|
141 |
|
---|
142 | /* CRC checksum. */
|
---|
143 | unsigned int crc;
|
---|
144 |
|
---|
145 | /* Input and output buffers. */
|
---|
146 | char *input_buffer, *output_buffer;
|
---|
147 |
|
---|
148 | /* The size of the input buffer. */
|
---|
149 | long input_buffer_size;
|
---|
150 |
|
---|
151 | /* Current locations in `input_buffer' and `output_buffer'. */
|
---|
152 | char *in_buff, *out_buff;
|
---|
153 |
|
---|
154 | /* Current number of bytes stored at `input_buff' and `output_buff'. */
|
---|
155 | long input_size, output_size;
|
---|
156 |
|
---|
157 | /* Total number of bytes read and written for all files.
|
---|
158 | Now that many tape drives hold more than 4Gb we need more than 32
|
---|
159 | bits to hold input_bytes and output_bytes. But it's not worth
|
---|
160 | the trouble of adding special multi-precision arithmetic if the
|
---|
161 | compiler doesn't support 64 bit ints since input_bytes and
|
---|
162 | output_bytes are only used to print the number of blocks copied. */
|
---|
163 | #ifdef __GNUC__
|
---|
164 | long long input_bytes, output_bytes;
|
---|
165 | #else
|
---|
166 | long input_bytes, output_bytes;
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | /* Saving of argument values for later reference. */
|
---|
170 | char *directory_name = NULL;
|
---|
171 | char **save_patterns;
|
---|
172 | int num_patterns;
|
---|
173 |
|
---|
174 | /* Character that terminates file names read from stdin. */
|
---|
175 | char name_end = '\n';
|
---|
176 |
|
---|
177 | /* true if input (cpio -i) or output (cpio -o) is a device node. */
|
---|
178 | char input_is_special = false;
|
---|
179 | char output_is_special = false;
|
---|
180 |
|
---|
181 | /* true if lseek works on the input. */
|
---|
182 | char input_is_seekable = false;
|
---|
183 |
|
---|
184 | /* true if lseek works on the output. */
|
---|
185 | char output_is_seekable = false;
|
---|
186 |
|
---|
187 | /* Print extra warning messages */
|
---|
188 | unsigned int warn_option = 0;
|
---|
189 |
|
---|
190 | /* Extract to standard output? */
|
---|
191 | bool to_stdout_option = false;
|
---|
192 |
|
---|
193 | /* The name this program was run with. */
|
---|
194 | char *program_name;
|
---|
195 |
|
---|
196 | /* A pointer to either lstat or stat, depending on whether
|
---|
197 | dereferencing of symlinks is done for input files. */
|
---|
198 | int (*xstat) ();
|
---|
199 |
|
---|
200 | /* Which copy operation to perform. (-i, -o, -p) */
|
---|
201 | void (*copy_function) () = 0;
|
---|