Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival/cpio.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/archival/cpio.c
r3232 r3621 10 10 * Doesn't check CRC's 11 11 * Only supports new ASCII and CRC formats 12 *13 12 */ 14 13 #include "libbb.h" 14 #include "common_bufsiz.h" 15 15 #include "bb_archive.h" 16 16 17 //config:config CPIO 18 //config: bool "cpio" 19 //config: default y 20 //config: help 21 //config: cpio is an archival utility program used to create, modify, and 22 //config: extract contents from archives. 23 //config: cpio has 110 bytes of overheads for every stored file. 24 //config: 25 //config: This implementation of cpio can extract cpio archives created in the 26 //config: "newc" or "crc" format, it cannot create or modify them. 27 //config: 28 //config: Unless you have a specific application which requires cpio, you 29 //config: should probably say N here. 30 //config: 31 //config:config FEATURE_CPIO_O 32 //config: bool "Support for archive creation" 33 //config: default y 34 //config: depends on CPIO 35 //config: help 36 //config: This implementation of cpio can create cpio archives in the "newc" 37 //config: format only. 38 //config: 39 //config:config FEATURE_CPIO_P 40 //config: bool "Support for passthrough mode" 41 //config: default y 42 //config: depends on FEATURE_CPIO_O 43 //config: help 44 //config: Passthrough mode. Rarely used. 45 46 //applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) 47 //kbuild:lib-$(CONFIG_CPIO) += cpio.o 48 17 49 //usage:#define cpio_trivial_usage 18 //usage: "[-dmvu] [-F FILE] " IF_FEATURE_CPIO_O(" [-H newc]")50 //usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]") 19 51 //usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]") 20 52 //usage: " [EXTR_FILE]..." … … 35 67 //usage: "\n -p DIR Copy files to DIR" 36 68 //usage: ) 69 //usage: "\nOptions:" 37 70 //usage: "\n -d Make leading directories" 38 71 //usage: "\n -m Preserve mtime" … … 40 73 //usage: "\n -u Overwrite" 41 74 //usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file" 75 //usage: "\n -R USER[:GRP] Set owner of created files" 42 76 //usage: IF_FEATURE_CPIO_O( 43 77 //usage: "\n -H newc Archive format" … … 99 133 -L, --dereference Dereference symbolic links (copy the files 100 134 that they point to instead of copying the links) 101 -R, --owner=[USER][:.][GR OUP] Set owner of created files135 -R, --owner=[USER][:.][GRP] Set owner of created files 102 136 103 137 Options valid in --extract and --pass-through modes: … … 119 153 OPT_DEREF = (1 << 7), 120 154 OPT_FILE = (1 << 8), 121 OPTBIT_FILE = 8, 155 OPT_OWNER = (1 << 9), 156 OPTBIT_OWNER = 9, 122 157 IF_FEATURE_CPIO_O(OPTBIT_CREATE ,) 123 158 IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,) … … 132 167 }; 133 168 134 #define OPTION_STR "it0uvdmLF:" 169 #define OPTION_STR "it0uvdmLF:R:" 170 171 struct globals { 172 struct bb_uidgid_t owner_ugid; 173 } FIX_ALIASING; 174 #define G (*(struct globals*)bb_common_bufsiz1) 175 void BUG_cpio_globals_too_big(void); 176 #define INIT_G() do { \ 177 setup_common_bufsiz(); \ 178 G.owner_ugid.uid = -1L; \ 179 G.owner_ugid.gid = -1L; \ 180 } while (0) 135 181 136 182 #if ENABLE_FEATURE_CPIO_O … … 150 196 static NOINLINE int cpio_o(void) 151 197 { 152 static const char trailer[] ALIGN1 = "TRAILER!!!";153 198 struct name_s { 154 199 struct name_s *next; … … 191 236 bb_simple_perror_msg_and_die(name); 192 237 } 238 239 if (G.owner_ugid.uid != (uid_t)-1L) 240 st.st_uid = G.owner_ugid.uid; 241 if (G.owner_ugid.gid != (gid_t)-1L) 242 st.st_gid = G.owner_ugid.gid; 193 243 194 244 if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode))) … … 226 276 continue; 227 277 } 228 229 278 } else { /* line == NULL: EOF */ 230 279 next_link: … … 245 294 /* If no (more) hardlinks to output, 246 295 * output "trailer" entry */ 247 name = trailer;296 name = cpio_TRAILER; 248 297 /* st.st_size == 0 is a must, but for uniformity 249 298 * in the output, we zero out everything */ … … 293 342 294 343 if (!line) { 295 if (name != trailer)344 if (name != cpio_TRAILER) 296 345 goto next_link; 297 346 /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */ … … 309 358 archive_handle_t *archive_handle; 310 359 char *cpio_filename; 360 char *cpio_owner; 311 361 IF_FEATURE_CPIO_O(const char *cpio_fmt = "";) 312 362 unsigned opt; … … 323 373 #endif 324 374 #endif 375 "owner\0" Required_argument "R" 325 376 "verbose\0" No_argument "v" 326 377 "quiet\0" No_argument "\xff" … … 329 380 #endif 330 381 382 INIT_G(); 331 383 archive_handle = init_handle(); 332 384 /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */ … … 339 391 340 392 #if !ENABLE_FEATURE_CPIO_O 341 opt = getopt32(argv, OPTION_STR, &cpio_filename); 393 opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner); 394 #else 395 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), 396 &cpio_filename, &cpio_owner, &cpio_fmt); 397 #endif 342 398 argv += optind; 399 if (opt & OPT_OWNER) { /* -R */ 400 parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner); 401 archive_handle->cpio__owner = G.owner_ugid; 402 } 403 #if !ENABLE_FEATURE_CPIO_O 343 404 if (opt & OPT_FILE) { /* -F */ 344 405 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); 345 406 } 346 407 #else 347 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);348 argv += optind;349 408 if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */ 350 409 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
Note:
See TracChangeset
for help on using the changeset viewer.