1 /* extern.h - External declarations for cpio. Requires system.h. 2 Copyright (C) 1990-1992, 2001, 2006-2007, 2009-2010, 2014-2017 Free 3 Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3, or (at your option) 8 any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with this program; if not, write to the Free 17 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301 USA. */ 19 20 #include "paxlib.h" 21 #include "quotearg.h" 22 #include "quote.h" 23 24 enum archive_format 25 { 26 arf_unknown, arf_binary, arf_oldascii, arf_newascii, arf_crcascii, 27 arf_tar, arf_ustar, arf_hpoldascii, arf_hpbinary 28 }; 29 30 extern enum archive_format archive_format; 31 extern int reset_time_flag; 32 extern int io_block_size; 33 extern int create_dir_flag; 34 extern int rename_flag; 35 extern char *rename_batch_file; 36 extern int table_flag; 37 extern int unconditional_flag; 38 extern int verbose_flag; 39 extern int dot_flag; 40 extern int link_flag; 41 extern int retain_time_flag; 42 extern int crc_i_flag; 43 extern int append_flag; 44 extern int swap_bytes_flag; 45 extern int swap_halfwords_flag; 46 extern int swapping_bytes; 47 extern int swapping_halfwords; 48 extern int set_owner_flag; 49 extern uid_t set_owner; 50 extern int set_group_flag; 51 extern gid_t set_group; 52 extern int no_chown_flag; 53 extern int sparse_flag; 54 extern int quiet_flag; 55 extern int only_verify_crc_flag; 56 extern int no_abs_paths_flag; 57 extern unsigned int warn_option; 58 extern mode_t newdir_umask; 59 extern int renumber_inodes_option; 60 extern int ignore_devno_option; 61 62 /* Values for warn_option */ 63 #define CPIO_WARN_NONE 0 64 #define CPIO_WARN_TRUNCATE 0x01 65 #define CPIO_WARN_INTERDIR 0x02 66 #define CPIO_WARN_ALL (unsigned int)-1 67 68 extern bool to_stdout_option; 69 70 extern int last_header_start; 71 extern int copy_matching_files; 72 extern int numeric_uid; 73 extern char *pattern_file_name; 74 extern char *new_media_message; 75 extern char *new_media_message_with_number; 76 extern char *new_media_message_after_number; 77 extern int archive_des; 78 extern char *archive_name; 79 extern char *rsh_command_option; 80 extern uint32_t crc; 81 #ifdef DEBUG_CPIO 82 extern int debug_flag; 83 #endif 84 85 extern char *input_buffer, *output_buffer; 86 extern char *in_buff, *out_buff; 87 extern size_t input_buffer_size; 88 extern size_t input_size, output_size; 89 extern off_t input_bytes, output_bytes; 90 91 extern char *directory_name; 92 extern char **save_patterns; 93 extern int num_patterns; 94 extern char name_end; 95 extern char input_is_special; 96 extern char output_is_special; 97 extern char input_is_seekable; 98 extern char output_is_seekable; 99 extern int (*xstat) (); 100 extern void (*copy_function) (); 101 extern char *change_directory_option; 102 103 104 /* copyin.c */ 105 void warn_junk_bytes (long bytes_skipped); 106 /* FIXME: make read_* static in copyin.c */ 107 void read_in_header (struct cpio_file_stat *file_hdr, int in_des); 108 void read_in_old_ascii (struct cpio_file_stat *file_hdr, int in_des); 109 void read_in_new_ascii (struct cpio_file_stat *file_hdr, int in_des); 110 void read_in_binary (struct cpio_file_stat *file_hdr, 111 struct old_cpio_header *short_hdr, int in_des); 112 void swab_array (char *arg, int count); 113 void process_copy_in (void); 114 void long_format (struct cpio_file_stat *file_hdr, char const *link_name); 115 116 /* copyout.c */ 117 int write_out_header (struct cpio_file_stat *file_hdr, int out_des); 118 void process_copy_out (void); 119 int to_ascii (char *where, uintmax_t v, size_t digits, unsigned logbase, 120 bool nul); 121 void field_width_error (const char *filename, const char *fieldname, 122 uintmax_t value, size_t width, bool nul); 123 124 /* copypass.c */ 125 void process_copy_pass (void); 126 int link_to_maj_min_ino (char *file_name, int st_dev_maj, 127 int st_dev_min, ino_t st_ino); 128 int link_to_name (char const *link_name, char const *link_target); 129 130 /* dirname.c */ 131 char *dirname (char *path); 132 133 /* filemode.c */ 134 void mode_string (unsigned int mode, char *str); 135 136 /* idcache.c */ 137 char *getgroup (gid_t gid); 138 char *getuser (uid_t uid); 139 uid_t *getuidbyname (char *user); 140 gid_t *getgidbyname (char *group); 141 142 /* main.c */ 143 void process_args (int argc, char *argv[]); 144 void initialize_buffers (void); 145 146 /* makepath.c */ 147 int make_path (char const *argpath, uid_t owner, gid_t group, 148 const char *verbose_fmt_string); 149 150 /* tar.c */ 151 int write_out_tar_header (struct cpio_file_stat *file_hdr, int out_des); 152 int null_block (long *block, int size); 153 void read_in_tar_header (struct cpio_file_stat *file_hdr, int in_des); 154 int otoa (char *s, unsigned long *n); 155 int is_tar_header (char *buf); 156 int is_tar_filename_too_long (char *name); 157 158 /* userspec.c */ 159 char *parse_user_spec (char *name, uid_t *uid, gid_t *gid, 160 char **username, char **groupname); 161 162 /* util.c */ 163 void tape_empty_output_buffer (int out_des); 164 void disk_empty_output_buffer (int out_des, bool flush); 165 void swahw_array (char *ptr, int count); 166 void tape_buffered_write (char *in_buf, int out_des, off_t num_bytes); 167 void tape_buffered_read (char *in_buf, int in_des, off_t num_bytes); 168 int tape_buffered_peek (char *peek_buf, int in_des, int num_bytes); 169 void tape_toss_input (int in_des, off_t num_bytes); 170 void copy_files_tape_to_disk (int in_des, int out_des, off_t num_bytes); 171 void copy_files_disk_to_tape (int in_des, int out_des, off_t num_bytes, char *filename); 172 void copy_files_disk_to_disk (int in_des, int out_des, off_t num_bytes, char *filename); 173 void warn_if_file_changed (char *file_name, off_t old_file_size, 174 time_t old_file_mtime); 175 void create_all_directories (char const *name); 176 void prepare_append (int out_file_des); 177 char *find_inode_file (ino_t node_num, 178 unsigned long major_num, unsigned long minor_num); 179 struct inode_val *add_inode (ino_t node_num, char *file_name, 180 unsigned long major_num, unsigned long minor_num); 181 int open_archive (char *file); 182 void tape_offline (int tape_des); 183 void get_next_reel (int tape_des); 184 void set_new_media_message (char *message); 185 #ifdef HPUX_CDF 186 char *add_cdf_double_slashes (char *filename); 187 #endif 188 void write_nuls_to_file (off_t num_bytes, int out_des, 189 void (*writer) (char *in_buf, 190 int out_des, off_t num_bytes)); 191 #define DISK_IO_BLOCK_SIZE 512 192 193 /* FIXME: Move to system.h? */ 194 #ifndef SYMLINK_USES_UMASK 195 # define UMASKED_SYMLINK(name1,name2,mode) symlink(name1,name2) 196 #else 197 # define UMASKED_SYMLINK(name1,name2,mode) umasked_symlink(name1,name2,mode) 198 #endif /* SYMLINK_USES_UMASK */ 199 200 void set_perms (int fd, struct cpio_file_stat *header); 201 void set_file_times (int fd, const char *name, unsigned long atime, 202 unsigned long mtime); 203 void stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st); 204 void cpio_to_stat (struct stat *st, struct cpio_file_stat *hdr); 205 void cpio_safer_name_suffix (char *name, bool link_target, 206 bool absolute_names, bool strip_leading_dots); 207 int cpio_create_dir (struct cpio_file_stat *file_hdr, int existing_dir); 208 void change_dir (void); 209 210 /* FIXME: The following three should be defined in paxutils */ 211 #define LG_8 3 212 #define LG_16 4 213 /* The maximum uintmax_t value that can be represented with DIGITS digits, 214 assuming that each digit is BITS_PER_DIGIT wide. */ 215 #define MAX_VAL_WITH_DIGITS(digits, bits_per_digit) \ 216 ((digits) * (bits_per_digit) < sizeof (uintmax_t) * CHAR_BIT \ 217 ? ((uintmax_t) 1 << ((digits) * (bits_per_digit))) - 1 \ 218 : (uintmax_t) -1) 219 220 221 uintmax_t from_ascii (char const *where, size_t digs, unsigned logbase); 222 223 #define FROM_OCTAL(f) from_ascii (f, sizeof f, LG_8) 224 #define FROM_HEX(f) from_ascii (f, sizeof f, LG_16) 225 226 void delay_cpio_set_stat (struct cpio_file_stat *file_stat, 227 mode_t invert_permissions); 228 void delay_set_stat (char const *file_name, struct stat *st, 229 mode_t invert_permissions); 230 int repair_delayed_set_stat (struct cpio_file_stat *file_hdr); 231 void apply_delayed_set_stat (void); 232 233 int arf_stores_inode_p (enum archive_format arf); 234 235