4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Milan Jurik. All rights reserved.
24 */
25
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /*
30 * Portions of this source code were derived from Berkeley 4.3 BSD
31 * under license from the Regents of the University of California.
32 */
33
34 #include <stdio.h>
35 #include <sys/types.h>
36 #include <errno.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <fcntl.h>
40 #include <memory.h>
41 #include <string.h>
42 #include <stdarg.h>
43 #include <sys/stat.h>
808 }
809 Gen.g_dirfd = -1;
810 if (passret != FILE_LINKED) {
811 Gen.g_nam_p = Savenam_p;
812 xattrs_out(file_pass);
813 }
814 }
815 }
816 break;
817 default:
818 msg(EXT, "Impossible action.");
819 }
820 if (Ofile > 0) {
821 if (close(Ofile) != 0)
822 msg(EXTN, "close error");
823 }
824 if (Archive > 0) {
825 if (close(Archive) != 0)
826 msg(EXTN, "close error");
827 }
828 Blocks = (u_longlong_t)(Blocks * Bufsize + SBlocks + 0x1FF) >> 9;
829 msg(EPOST, "%lld blocks", Blocks);
830 if (Error_cnt)
831 msg(EPOST, "%d error(s)", Error_cnt);
832 return (EXIT_CODE);
833 }
834
835 /*
836 * add_lnk: Add a linked file's header to the linked file data structure, by
837 * either adding it to the end of an existing sub-list or starting
838 * a new sub-list. Each sub-list saves the links to a given file.
839 *
840 * Directly returns a pointer to the new entry; returns a pointer to the head
841 * of the sub-list in which that entry is located through the argument.
842 */
843
844 static struct Lnk *
845 add_lnk(struct Lnk **sublist_return)
846 {
847 struct Lnk *new_entry, *sublist;
848
849 for (sublist = Lnk_hd.L_nxt_p;
6362 Append = 0;
6363 }
6364
6365 /*
6366 * setup: Perform setup and initialization functions. Parse the options
6367 * using getopt(3C), call ckopts to check the options and initialize various
6368 * structures and pointers. Specifically, for the -i option, save any
6369 * patterns, for the -o option, check (via stat(2)) the archive, and for
6370 * the -p option, validate the destination directory.
6371 */
6372
6373 static void
6374 setup(int largc, char **largv)
6375 {
6376 extern int optind;
6377 extern char *optarg;
6378
6379 #if defined(O_XATTR)
6380 #if defined(_PC_SATTR_ENABLED)
6381 #ifdef WAITAROUND
6382 char *opts_p = "zabcdfiklmoprstuvABC:DE:H:I:LM:O:PR:SV6@/";
6383 #else
6384 char *opts_p = "abcdfiklmoprstuvABC:DE:H:I:LM:O:PR:SV6@/";
6385 #endif /* WAITAROUND */
6386
6387 #else /* _PC_SATTR_ENABLED */
6388 #ifdef WAITAROUND
6389 char *opts_p = "zabcdfiklmoprstuvABC:DE:H:I:LM:O:PR:SV6@";
6390 #else
6391 char *opts_p = "abcdfiklmoprstuvABC:DE:H:I:LM:O:PR:SV6@";
6392 #endif /* WAITAROUND */
6393 #endif /* _PC_SATTR_ENABLED */
6394
6395 #else /* O_XATTR */
6396 #ifdef WAITAROUND
6397 char *opts_p = "zabcdfiklmoprstuvABC:DE:H:I:LM:O:PR:SV6";
6398 #else
6399 char *opts_p = "abcdfiklmoprstuvABC:DE:H:I:LM:O:PR:SV6";
6400 #endif /* WAITAROUND */
6401 #endif /* O_XATTR */
6402
6403 char *dupl_p = "Only one occurrence of -%c allowed";
6404 int option;
6405 int blk_cnt, blk_cnt_max;
6406 struct rlimit rlim;
6407
6408 /* Remember the native page size. */
6409
6410 PageSize = sysconf(_SC_PAGESIZE);
6411
6412 if (PageSize == -1) {
6413 /*
6414 * This sysconf call will almost certainly never fail. The
6415 * symbol PAGESIZE itself resolves to the above sysconf call,
6416 * so we should go ahead and define our own constant.
6417 */
6418 PageSize = 8192;
6419 }
6451 Args |= OCi;
6452 Archive = 0;
6453 break;
6454 case 'k': /* retry after I/O errors */
6455 Args |= OCk;
6456 break;
6457 case 'l': /* link files when possible */
6458 Args |= OCl;
6459 break;
6460 case 'm': /* retain modification time */
6461 Args |= OCm;
6462 break;
6463 case 'o': /* "copy out" */
6464 Args |= OCo;
6465 Archive = 1;
6466 break;
6467 case 'p': /* "pass" */
6468 Max_namesz = APATH;
6469 Args |= OCp;
6470 break;
6471 case 'r': /* rename files interactively */
6472 Args |= OCr;
6473 break;
6474 case 's': /* swap bytes */
6475 Args |= OCs;
6476 break;
6477 case 't': /* table of contents */
6478 Args |= OCt;
6479 break;
6480 case 'u': /* copy unconditionally */
6481 Args |= OCu;
6482 break;
6483 case 'v': /* verbose - print file names */
6484 Args |= OCv;
6485 break;
6486 case 'A': /* append to existing archive */
6487 Args |= OCA;
6488 break;
6489 case 'B': /* set block size to 5120 bytes */
6490 Args |= OCB;
6850 while (tcnt-- > 0) {
6851 thalf = Swp_p->s_half[0];
6852 Swp_p->s_half[0] = Swp_p->s_half[1];
6853 Swp_p->s_half[1] = thalf;
6854 Swp_p++;
6855 }
6856 }
6857 }
6858
6859 /*
6860 * usage: Print the usage message on stderr and exit.
6861 */
6862
6863 static void
6864 usage(void)
6865 {
6866
6867 (void) fflush(stdout);
6868 #if defined(O_XATTR)
6869 (void) fprintf(stderr, gettext("USAGE:\n"
6870 "\tcpio -i[bcdfkmrstuv@BSV6] [-C size] "
6871 "[-E file] [-H hdr] [-I file [-M msg]] "
6872 "[-R id] [patterns]\n"
6873 "\tcpio -o[acv@ABLV] [-C size] "
6874 "[-H hdr] [-O file [-M msg]]\n"
6875 "\tcpio -p[adlmuv@LV] [-R id] directory\n"));
6876 #else
6877 (void) fprintf(stderr, gettext("USAGE:\n"
6878 "\tcpio -i[bcdfkmrstuvBSV6] [-C size] "
6879 "[-E file] [-H hdr] [-I file [-M msg]] "
6880 "[-R id] [patterns]\n"
6881 "\tcpio -o[acvABLV] [-C size] "
6882 "[-H hdr] [-O file [-M msg]]\n"
6883 "\tcpio -p[adlmuvLV] [-R id] directory\n"));
6884 #endif
6885 (void) fflush(stderr);
6886 exit(EXIT_CODE);
6887 }
6888
6889 /*
6890 * verbose: For each file, print either the filename (-v) or a dot (-V).
6891 * If the -t option (table of contents) is set, print either the filename,
6892 * or if the -v option is also set, print an "ls -l"-like listing.
6893 */
6894
6895 static void
6896 verbose(char *nam_p)
6897 {
6898 int i, j, temp;
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Milan Jurik. All rights reserved.
24 * Copyright (c) 2012 Gary Mills
25 */
26
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
33 */
34
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <errno.h>
38 #include <unistd.h>
39 #include <stdlib.h>
40 #include <fcntl.h>
41 #include <memory.h>
42 #include <string.h>
43 #include <stdarg.h>
44 #include <sys/stat.h>
809 }
810 Gen.g_dirfd = -1;
811 if (passret != FILE_LINKED) {
812 Gen.g_nam_p = Savenam_p;
813 xattrs_out(file_pass);
814 }
815 }
816 }
817 break;
818 default:
819 msg(EXT, "Impossible action.");
820 }
821 if (Ofile > 0) {
822 if (close(Ofile) != 0)
823 msg(EXTN, "close error");
824 }
825 if (Archive > 0) {
826 if (close(Archive) != 0)
827 msg(EXTN, "close error");
828 }
829 if ((Args & OCq) == 0) {
830 Blocks = (u_longlong_t)(Blocks * Bufsize + SBlocks +
831 0x1FF) >> 9;
832 msg(EPOST, "%lld blocks", Blocks);
833 }
834 if (Error_cnt)
835 msg(EPOST, "%d error(s)", Error_cnt);
836 return (EXIT_CODE);
837 }
838
839 /*
840 * add_lnk: Add a linked file's header to the linked file data structure, by
841 * either adding it to the end of an existing sub-list or starting
842 * a new sub-list. Each sub-list saves the links to a given file.
843 *
844 * Directly returns a pointer to the new entry; returns a pointer to the head
845 * of the sub-list in which that entry is located through the argument.
846 */
847
848 static struct Lnk *
849 add_lnk(struct Lnk **sublist_return)
850 {
851 struct Lnk *new_entry, *sublist;
852
853 for (sublist = Lnk_hd.L_nxt_p;
6366 Append = 0;
6367 }
6368
6369 /*
6370 * setup: Perform setup and initialization functions. Parse the options
6371 * using getopt(3C), call ckopts to check the options and initialize various
6372 * structures and pointers. Specifically, for the -i option, save any
6373 * patterns, for the -o option, check (via stat(2)) the archive, and for
6374 * the -p option, validate the destination directory.
6375 */
6376
6377 static void
6378 setup(int largc, char **largv)
6379 {
6380 extern int optind;
6381 extern char *optarg;
6382
6383 #if defined(O_XATTR)
6384 #if defined(_PC_SATTR_ENABLED)
6385 #ifdef WAITAROUND
6386 char *opts_p = "zabcdfiklmopqrstuvABC:DE:H:I:LM:O:PR:SV6@/";
6387 #else
6388 char *opts_p = "abcdfiklmopqrstuvABC:DE:H:I:LM:O:PR:SV6@/";
6389 #endif /* WAITAROUND */
6390
6391 #else /* _PC_SATTR_ENABLED */
6392 #ifdef WAITAROUND
6393 char *opts_p = "zabcdfiklmopqrstuvABC:DE:H:I:LM:O:PR:SV6@";
6394 #else
6395 char *opts_p = "abcdfiklmopqrstuvABC:DE:H:I:LM:O:PR:SV6@";
6396 #endif /* WAITAROUND */
6397 #endif /* _PC_SATTR_ENABLED */
6398
6399 #else /* O_XATTR */
6400 #ifdef WAITAROUND
6401 char *opts_p = "zabcdfiklmopqrstuvABC:DE:H:I:LM:O:PR:SV6";
6402 #else
6403 char *opts_p = "abcdfiklmopqrstuvABC:DE:H:I:LM:O:PR:SV6";
6404 #endif /* WAITAROUND */
6405 #endif /* O_XATTR */
6406
6407 char *dupl_p = "Only one occurrence of -%c allowed";
6408 int option;
6409 int blk_cnt, blk_cnt_max;
6410 struct rlimit rlim;
6411
6412 /* Remember the native page size. */
6413
6414 PageSize = sysconf(_SC_PAGESIZE);
6415
6416 if (PageSize == -1) {
6417 /*
6418 * This sysconf call will almost certainly never fail. The
6419 * symbol PAGESIZE itself resolves to the above sysconf call,
6420 * so we should go ahead and define our own constant.
6421 */
6422 PageSize = 8192;
6423 }
6455 Args |= OCi;
6456 Archive = 0;
6457 break;
6458 case 'k': /* retry after I/O errors */
6459 Args |= OCk;
6460 break;
6461 case 'l': /* link files when possible */
6462 Args |= OCl;
6463 break;
6464 case 'm': /* retain modification time */
6465 Args |= OCm;
6466 break;
6467 case 'o': /* "copy out" */
6468 Args |= OCo;
6469 Archive = 1;
6470 break;
6471 case 'p': /* "pass" */
6472 Max_namesz = APATH;
6473 Args |= OCp;
6474 break;
6475 case 'q': /* "quiet" */
6476 Args |= OCq;
6477 break;
6478 case 'r': /* rename files interactively */
6479 Args |= OCr;
6480 break;
6481 case 's': /* swap bytes */
6482 Args |= OCs;
6483 break;
6484 case 't': /* table of contents */
6485 Args |= OCt;
6486 break;
6487 case 'u': /* copy unconditionally */
6488 Args |= OCu;
6489 break;
6490 case 'v': /* verbose - print file names */
6491 Args |= OCv;
6492 break;
6493 case 'A': /* append to existing archive */
6494 Args |= OCA;
6495 break;
6496 case 'B': /* set block size to 5120 bytes */
6497 Args |= OCB;
6857 while (tcnt-- > 0) {
6858 thalf = Swp_p->s_half[0];
6859 Swp_p->s_half[0] = Swp_p->s_half[1];
6860 Swp_p->s_half[1] = thalf;
6861 Swp_p++;
6862 }
6863 }
6864 }
6865
6866 /*
6867 * usage: Print the usage message on stderr and exit.
6868 */
6869
6870 static void
6871 usage(void)
6872 {
6873
6874 (void) fflush(stdout);
6875 #if defined(O_XATTR)
6876 (void) fprintf(stderr, gettext("USAGE:\n"
6877 "\tcpio -i[bcdfkmqrstuv@BSV6] [-C size] "
6878 "[-E file] [-H hdr] [-I file [-M msg]] "
6879 "[-R id] [patterns]\n"
6880 "\tcpio -o[acv@ABLV] [-C size] "
6881 "[-H hdr] [-O file [-M msg]]\n"
6882 "\tcpio -p[adlmuv@LV] [-R id] directory\n"));
6883 #else
6884 (void) fprintf(stderr, gettext("USAGE:\n"
6885 "\tcpio -i[bcdfkmqrstuvBSV6] [-C size] "
6886 "[-E file] [-H hdr] [-I file [-M msg]] "
6887 "[-R id] [patterns]\n"
6888 "\tcpio -o[acvABLV] [-C size] "
6889 "[-H hdr] [-O file [-M msg]]\n"
6890 "\tcpio -p[adlmuvLV] [-R id] directory\n"));
6891 #endif
6892 (void) fflush(stderr);
6893 exit(EXIT_CODE);
6894 }
6895
6896 /*
6897 * verbose: For each file, print either the filename (-v) or a dot (-V).
6898 * If the -t option (table of contents) is set, print either the filename,
6899 * or if the -v option is also set, print an "ls -l"-like listing.
6900 */
6901
6902 static void
6903 verbose(char *nam_p)
6904 {
6905 int i, j, temp;
|