Lines Matching +full:attr +full:- +full:cnt +full:- +full:name
17 * information: Portions Copyright [yyyy] [name of copyright owner]
69 #include <attr.h>
96 #define FILE_PASS_ERR -1
122 * with character-format headers (odc, tar, ustar) we use
123 * CHAR_OFFSET_MAX. For archives with SVR4 ASCII headers (-c, -H crc)
124 * we store filesize in an 8-char hexadecimal string and use
172 static void swap(char *buf_p, int cnt);
203 static int open_dir(char *name);
215 struct passwd *Curpw_p, /* Current password entry for -t option */
216 *Rpw_p, /* Password entry for -R option */
220 struct group *Curgr_p, /* Current group entry for -t option */
262 *g_attrfnam_p, /* Real file name attr belongs to */
268 int g_rw_sysattr; /* read-write system attribute */
274 /* Data structure for handling multiply-linked files */
295 * -------------------------------------------------------------------------
296 * Stuff needed to pre-view the name stream
300 * when -L is specified.
317 ino_t sl_ino2; /* alternate inode for -Hodc */
345 #define DEV_HASHKEY(x) ((x) & (NDEVHENTRY -1))
348 * For remapping dev,inode for -Hodc archives.
370 #define sl_compare(lino, lftype, rino, rftype) (lino < rino ? -1 : \
371 (lino > rino ? 1 : (lftype < rftype ? -1 : \
376 static sl_remap_t *sl_remap_head = NULL; /* head of the inode-remap list */
380 * -------------------------------------------------------------------------
420 char *myname, /* program name */
427 T_lname[MAXPATHLEN], /* Array to hold links name for tar */
430 *Efil_p, /* -E pattern file string */
434 *Hdr_p, /* -H header type string */
435 *IOfil_p, /* -I/-O input/output archive string */
437 *Lnknam_p, /* Buffer for linking files with -p option */
442 *Renam_attr_p, /* Buffer for renaming attr with sys attrs */
444 *Symlnk_p, /* Buffer for holding symbolic link name */
448 bar_linkname[MAXPATHLEN]; /* store the name of the link */
463 Use_old_stat = 0, /* Create an old style -Hodc hdr (small dev's) */
476 attr_baseparent_fd = -1; /* attribute's base file descriptor */
480 gid_t Lastgid = (gid_t)-1; /* Used with -t & -v to record current gid */
483 uid_t Lastuid = (uid_t)-1; /* Used with -t & -v to record current uid */
505 *Out_p = stdout, /* File pointer for non-archive output */
517 } *attr;
559 * fd = openat(dfd, <name>,....);
568 * unlinkat(dfd, <component name>,...)
569 * fchownat(dfd, <component name>,..)
588 * /dev/null/attr.hdr
590 * The name of the attribute looks like:
591 * /dev/null/attr.
595 * rename them via cpio -r or pax -i
609 * --------------------------------
613 * --------------------------------
614 * --------------------------------
618 * --------------------------------
619 * --------------------------------
623 * --------------------------------
624 * --------------------------------
632 * --------------------------------
667 * except when the -R option is specified. When the -R is specified,
678 * with -DWAITAROUND defined, and then add the "-z" command line option to the
695 * and then select either copy in (-i), copy out (-o), or pass (-p) action.
705 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
731 Gen.g_dirfd = -1;
748 /* Do not count "extra" "read-ahead" buffered data */
750 Blocks -= (u_longlong_t)(Buffr.b_cnt / Bufsize);
757 Gen.g_dirfd = -1;
765 if (Gen.g_dirfd != -1) {
768 Gen.g_dirfd = -1;
783 Gen.g_dirfd = -1;
784 Gen.g_passdirfd = -1;
792 * name for attribute traversal.
803 if (Gen.g_passdirfd != -1)
805 Gen.g_passdirfd = -1;
807 if (Gen.g_dirfd != -1) {
810 Gen.g_dirfd = -1;
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.
845 * of the sub-list in which that entry is located through the argument.
855 sublist = sublist->L_nxt_p) {
856 if (sublist->L_gen.g_ino == G_p->g_ino &&
857 sublist->L_gen.g_dev == G_p->g_dev) {
865 new_entry->L_lnk_p = NULL;
866 new_entry->L_gen = *G_p; /* structure copy */
868 new_entry->L_gen.g_nam_p = e_zalloc(E_EXIT, (size_t)G_p->g_namesz);
870 (void) strcpy(new_entry->L_gen.g_nam_p, G_p->g_nam_p);
873 /* start new sub-list */
874 new_entry->L_nxt_p = &Lnk_hd;
875 new_entry->L_bck_p = Lnk_hd.L_bck_p;
876 Lnk_hd.L_bck_p = new_entry->L_bck_p->L_nxt_p = new_entry;
877 new_entry->L_lnk_p = NULL;
878 new_entry->L_cnt = 1;
879 new_entry->L_data = Onecopy ? 0 : 1;
882 /* add to existing sub-list */
885 sublist->L_cnt++;
888 ptr->L_lnk_p != NULL;
889 ptr = ptr->L_lnk_p) {
890 ptr->L_gen.g_filesz = G_p->g_filesz;
893 ptr->L_gen.g_filesz = G_p->g_filesz;
894 ptr->L_lnk_p = new_entry;
905 * distance to lseek if an I/O error is encountered with the -k option set
916 while ((Buffr.b_end_p - Buffr.b_in_p) >= Bufsize) {
919 if (((Buffr.b_end_p - Buffr.b_in_p) >= Bufsize) &&
971 } /* (Buffr.b_end_p - Buffr.b_in_p) <= Bufsize */
976 return (-1);
988 return (-1);
1017 Buffr.b_cnt -= (long)rv;
1027 * chgreel: Determine if end-of-medium has been reached. If it has,
1083 "To continue, type device/file name when "
1088 lastchar = strlen(str) - 1;
1102 msg(EXT, "Cannot change media types in mid-stream.");
1122 * and/or ask the user for new name when -r is used.
1132 /* Re-visit tar size issues later */
1133 if (G_p->g_namesz - 1 > Max_namesz) {
1134 msg(ERR, "Name exceeds maximum length - skipped.");
1143 if ((Args & OCr) && !Adir && !G_p->g_rw_sysattr) {
1145 (G_p->g_attrnam_p == NULL) ? G_p->g_nam_p : Renam_p,
1146 (G_p->g_attrnam_p == NULL) ? "" : gettext(" Attribute "),
1147 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p);
1153 lastchar = strlen(Renametmp_p) - 1;
1160 (G_p->g_attrnam_p == NULL) ? G_p->g_nam_p :
1161 G_p->g_attrfnam_p,
1162 (G_p->g_attrnam_p == NULL) ? "" :
1164 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p);
1165 if (G_p->g_attrparent_p == NULL) {
1166 *G_p->g_nam_p = '\0';
1173 if (G_p->g_attrnam_p == NULL) {
1175 G_p->g_nam_p)) {
1176 if ((G_p->g_nam_p != &nambuf[0]) &&
1177 (G_p->g_nam_p != &fullnam[0])) {
1178 free(G_p->g_nam_p);
1179 G_p->g_nam_p = e_zalloc(E_EXIT,
1188 (strlcpy(G_p->g_nam_p, Renametmp_p,
1193 if (G_p->g_attrnam_p != NULL) {
1194 free(G_p->g_attrnam_p);
1195 G_p->g_attrnam_p = e_strdup(E_EXIT,
1197 (void) strcpy(G_p->g_nam_p, Renam_p);
1209 if (G_p->g_attrnam_p == NULL) {
1218 VERBOSE((Args & OCt), G_p->g_nam_p);
1248 msg(ERR, "One of -i, -o or -p must be specified.");
1253 /* if non-zero, invalid options were specified */
1259 msg(ERR, "-a and -m are mutually exclusive.");
1264 msg(ERR, "-c and -H are mutually exclusive.");
1268 msg(ERR, "-v and -V are mutually exclusive.");
1272 msg(ERR, "-t and -V are mutually exclusive.");
1276 msg(ERR, "-B and -C are mutually exclusive.");
1280 msg(ERR, "-H and -6 are mutually exclusive.");
1284 msg(ERR, "-M not meaningful without -O or -I.");
1288 msg(ERR, "-A requires the -O option.");
1292 msg(ERR, "Illegal size given for -C option.");
1300 *t_p = 'a' + (*t_p - 'A');
1329 Max_namesz = HNAMLEN - 1;
1332 Max_namesz = TNAMLEN - 1;
1337 Max_namesz = HNAMLEN - 1;
1342 "Header type bar can only be used with -i");
1351 Max_namesz = TNAMLEN - 1;
1418 } else if ((Euid != Rpw_p->pw_uid) && !privileged) {
1419 msg(ERR, "R option only valid for super-user or "
1440 * (TARTYP (TAR and USTAR)). For -o and the CRC header, the file is opened and
1441 * the checksum is calculated. For -i and the CRC header, the checksum
1452 int cnt;
1466 /* OCo - do checksum of file */
1467 lcnt = G_p->g_filesz;
1481 lcnt -= have;
1487 crc_p = Thdr_p->tbuf.t_cksum;
1488 for (cnt = 0; cnt < TCRCLEN; cnt++) {
1493 for (cnt = 0; cnt < TARSZ; cnt++) {
1542 * If the length of the full name is greater than 256,
1547 "%s: file name too long", Gen.g_nam_p);
1551 * The length of the full name is greater than
1568 presize = fullnamesize - namesize - 1;
1624 /* make name null string */
1628 dpasswd->pw_name, 32);
1643 /* make name null string */
1647 dgroup->gr_name, 32);
1663 * -Hodc format. We should always use the original
1684 /* -Hodc */
1687 Gen.g_ino = p ? p->sl_ino2 : -1;
1689 if (Gen.g_ino == (ulong_t)-1) {
1690 msg(ERR, "%s%s%s: cannot be archived - inode too big "
1691 "for -Hodc format",
1724 int cnt = 0;
1734 cnt = 0;
1736 } else if ((errno == EEXIST) && (cnt == 0)) {
1766 if (!(Args & OCu) && G_p->g_mtime <= DesSt.st_mtime)
1773 cnt++;
1774 } while ((cnt < 2) && missdir(name2_p) == 0);
1775 if (!cnt) {
1801 } else if (cnt == 1)
1804 else if (cnt == 2)
1807 return (cnt);
1824 int cnt, result, rv = 0;
1833 nam_p = G_p->g_nam_p;
1845 if (G_p->g_attrparent_p == NULL) {
1847 if (fchownat(dirfd, ".", Rpw_p->pw_uid,
1848 Rpw_p->pw_gid, 0) != 0) {
1852 G_p->g_attrfnam_p);
1854 } else if ((fchownat(dirfd, ".", G_p->g_uid,
1855 G_p->g_gid, 0) != 0) && privileged) {
1858 "file %s\"", G_p->g_attrfnam_p);
1861 if (fchmod(dirfd, G_p->g_mode) != 0) {
1864 "file %s\"", G_p->g_attrfnam_p);
1873 G_p->g_attrfnam_p);
1911 /* A file by the same name exists. */
1946 * A file by the same name exists. Move it to a
1967 cnt = 0;
1973 result = mkdir(nam_p, G_p->g_mode);
1982 result = mknod(nam_p, (int)G_p->g_mode,
1983 (int)G_p->g_rdev);
2005 cnt = 0;
2009 cnt++;
2010 } while (cnt < 2 && missdir(nam_p) == 0);
2012 switch (cnt) {
2058 if ((Args & OCp) && G_p->g_ino == DesSt.st_ino &&
2059 G_p->g_dev == DesSt.st_dev) {
2061 return (-1);
2064 if (G_p->g_mtime <= DesSt.st_mtime && !(Args & OCu)) {
2066 return (-1);
2069 /* Make the temporary file name. */
2075 if (*(t_p - 1) == '/')
2077 t_p--;
2082 if (G_p->g_attrnam_p != NULL) {
2090 (void) fchdir(G_p->g_dirfd);
2095 if (G_p->g_attrnam_p != NULL) {
2104 msg(ERR, "Cannot get temporary file name.");
2105 return (-1);
2113 * defaults to 0 in the cpio-format-regular file case, so this test
2117 if (G_p->g_typeflag == 0 &&
2119 (G_p->g_mode & (ulong_t)Ftype) == S_IFREG) {
2126 if (G_p->g_attrnam_p == NULL) {
2132 G_p->g_nam_p = Over_p;
2133 if (G_p->g_attrnam_p != NULL) {
2138 if (G_p->g_attrnam_p == NULL) {
2141 Over_p = G_p->g_attrnam_p;
2175 return (-1);
2201 return (-1);
2210 return (-1);
2222 * ifd - Input file descriptor.
2223 * buffer - Buffer (allocated by caller) to copy data to.
2224 * datasize - The amount of data to read from the input file
2226 * error - When reading from an Archive file, indicates unreadable
2228 * data_in_info - Information needed when called from data_in().
2237 if (data_in_info->data_in_proc_mode != P_SKIP) {
2239 data_in_info->data_in_cksumval += cksum(CRC,
2241 if (data_in_info->data_in_swapfile)
2247 * do the de-compression while reading in the file
2250 if (data_in_info->data_in_compress_flag == 0 &&
2253 &(data_in_info->data_in_pipef));
2254 data_in_info->data_in_compress_flag++;
2260 Buffr.b_cnt -= datasize;
2268 * ifd - input file descriptor.
2269 * buf - Buffer (allocated by caller) to copy data to.
2270 * bytes - The amount of data to read from the input file
2272 * rdblocksz - The size of the chunk of data to read.
2275 * Return -1 when buffer is empty and read failed.
2291 min(bytes - bytesread, rdblocksz),
2297 * If buffer is empty, return -1.
2301 data_in_info->data_in_rd_eof = 1;
2302 return (-1);
2304 return (bytes - bytesread);
2313 * ofd - output file descriptor.
2314 * buf - Source buffer to output data from.
2315 * maxwrite - The amount of data to write to the output.
2322 ssize_t cnt;
2325 if ((cnt = write(ofd, buf, maxwrite)) < (ssize_t)maxwrite) {
2326 data_in_info->data_in_errno = errno;
2333 if (cnt != -1)
2334 data_in_info->data_in_wr_part = 1;
2337 Blocks += (u_longlong_t)((cnt + (Bufsize - 1)) / Bufsize);
2346 * ifd/ofd - i/o file descriptor
2347 * buf - buffer to be used for i/o
2348 * bytes - Amount to read/write
2349 * wrblocksz - Output block size.
2350 * rdblocksz - Read block size.
2353 * Return positive non-zero if write failed.
2361 int write_it = (data_in_info->data_in_proc_mode != P_SKIP);
2380 wrblocksz - sz, data_in_info);
2388 data_in_info->data_in_wr_part) {
2396 bytes -= (wrblocksz - sz);
2404 * ofd - output file descriptor
2405 * buf - buffer to fill with zeros
2406 * bytes - Amount to write
2407 * wrblocksz - Write block size
2424 bytes -= wrblocksz;
2436 * 3) If the file is a read-write system attribute file.
2438 * read-write system attribute file, which must be written in one operation,
2463 * file to output file descriptor. If ifd is -1, then the input file is
2467 * ifd - Input file descriptor to read from.
2468 * ofd - Output file descriptor of extracted file.
2469 * rw_sysattr - Flag indicating if a file is an extended
2471 * bytes - Amount of data (file size) of copy/write.
2472 * blocksize - Amount of data to read at a time from either
2474 * data_in_info - information needed while reading data when
2476 * holes - Information of holes in the input file.
2525 for (hl = holes->holes_list; hl != NULL; hl = hl->hl_next) {
2526 if (curpos != hl->hl_data) {
2528 noff = lseek(ofd, hl->hl_data, SEEK_SET);
2529 if (noff != hl->hl_data) {
2534 datasize = hl->hl_data - curpos;
2547 (void) lseek(ifd, hl->hl_data, SEEK_SET);
2549 curpos = hl->hl_data;
2551 datasize = hl->hl_hole - hl->hl_data;
2562 (void) ftruncate(ofd, hl->hl_data);
2575 data_in_info->data_in_wr_part) {
2580 hl = hl->hl_next;
2588 * header when non-fatal error occured.
2591 data_in_info->data_in_proc_mode = P_SKIP;
2593 datasize = hl->hl_hole - hl->hl_data;
2598 hl = hl->hl_next;
2625 holesdata_sz = holes->holesdata_sz - MIN_HOLES_HDRSIZE;
2637 (void) read_bytes(-1, holesdata, holesdata_sz, CPIOBSZ, data_in_info);
2638 *fileszp -= holesdata_sz;
2641 if (holesdata[holesdata_sz - 1] != '\0') {
2651 if (*fileszp != holes->data_size)
2679 if (G_p->g_attrnam_p != NULL) {
2680 nam_p = G_p->g_attrnam_p;
2682 nam_p = G_p->g_nam_p;
2685 if (((G_p->g_mode & Ftype) == S_IFLNK && proc_mode != P_SKIP) ||
2692 if (Args & (OCs | OCb) && G_p->g_filesz % 2) {
2698 if (Args & (OCS | OCb) && G_p->g_filesz % 4) {
2707 data_in_info->data_in_swapfile = swapfile;
2708 data_in_info->data_in_proc_mode = proc_mode;
2710 filesz = G_p->g_filesz;
2712 if (S_ISSPARSE(G_p->g_mode) && G_p->g_holes != NULL) {
2714 filesz -= MIN_HOLES_HDRSIZE;
2723 free_holes_info(G_p->g_holes);
2724 G_p->g_holes = NULL;
2726 rv = read_holesdata(G_p->g_holes, &filesz,
2733 free_holes_info(G_p->g_holes);
2734 G_p->g_holes = NULL;
2736 data_in_info->data_in_proc_mode = P_SKIP;
2742 if (G_p->g_holes != NULL) {
2743 rv = data_copy_with_holes(-1, Ofile,
2744 (G_p->g_attrnam_p == NULL) ? 0 : G_p->g_rw_sysattr,
2745 G_p->g_holes->orig_size,
2746 CPIOBSZ, data_in_info, G_p->g_holes);
2748 free_holes_info(G_p->g_holes);
2749 G_p->g_holes = NULL;
2751 rv = data_copy(-1, Ofile,
2752 (G_p->g_attrnam_p == NULL) ? 0 : G_p->g_rw_sysattr,
2758 errno = data_in_info->data_in_errno;
2761 msg(data_in_info->data_in_wr_part ? EXTN : ERRN,
2763 (G_p->g_attrnam_p == NULL) ? "" :
2764 G_p->g_attrfnam_p,
2765 (G_p->g_attrnam_p == NULL) ? "" :
2766 G_p->g_rw_sysattr ?
2776 rstfiles(U_KEEP, G_p->g_dirfd);
2785 pad = (Pad_val + 1 - (G_p->g_filesz & Pad_val)) & Pad_val;
2789 Buffr.b_cnt -= pad;
2793 Gen.g_cksum != data_in_info->data_in_cksumval) {
2794 msg(ERR, "\"%s\" - checksum error", nam_p);
2795 rstfiles(U_KEEP, G_p->g_dirfd);
2797 rstfiles(U_OVER, G_p->g_dirfd);
2798 if (Hdr_type == BAR && data_in_info->data_in_compress_flag) {
2799 (void) pclose(data_in_info->data_in_pipef);
2811 (G_p->g_attrparent_p == NULL) ? G_p->g_nam_p : G_p->g_attrpath_p);
2855 *real_filesz = file_size - amt_to_read;
2860 (amount_read - amt_to_read);
2870 amt_to_read -= (off_t)amount_read;
2900 holes_list_t *hl = holes->holes_list;
2903 for (hl = holes->holes_list; hl != NULL; hl = hl->hl_next) {
2904 datasize = hl->hl_hole - hl->hl_data;
2907 if (npos == -1 && errno == ENXIO) {
2910 * - we have a hole toward the end of file.
2911 * - file has been shrunk, and we've reached EOF.
2914 if (hl->hl_data == file_size)
2922 left += (hl->hl_hole - hl->hl_data);
2923 hl = hl->hl_next;
2930 if (curpos != hl->hl_data) {
2937 (void) lseek(Ifile, hl->hl_data, SEEK_SET);
2938 curpos = hl->hl_data;
2943 *real_filesz = curpos + datasize - left;
2944 left = file_size - *real_filesz;
2970 int cnt, pad;
2978 nam_p = G_p->g_nam_p;
2985 if (append_secattr(&secinfo, &len, aclp) == -1) {
2998 rstfiles(U_KEEP, G_p->g_dirfd);
3002 if ((G_p->g_mode & Ftype) == S_IFLNK && (Hdr_type !=
3007 FLUSH(G_p->g_filesz);
3010 /* Note that "size" and G_p->g_filesz are the same number */
3012 if ((size = readlink(nam_p, Buffr.b_in_p, G_p->g_filesz)) <
3019 * Note that it is OK not to add the NUL after the name read by
3025 pad = (Pad_val + 1 - (size & Pad_val)) & Pad_val;
3034 } else if ((G_p->g_mode & Ftype) == S_IFLNK &&
3039 * G_p->g_filesz is the length of the right-hand side of
3040 * the symlink "x -> y".
3044 if (G_p->g_filesz > NAMSIZ) {
3049 if ((size = readlink(nam_p, T_lname, G_p->g_filesz)) < 0) {
3055 G_p->g_filesz = (off_t)0;
3072 orig_filesz = G_p->g_filesz;
3079 if (Compress_sparse && S_ISREG(G_p->g_mode)) {
3083 * G_p->g_filesz will need to be changed to be the size of
3088 holes = get_holes_info(Ifile, G_p->g_filesz, B_FALSE);
3090 G_p->g_filesz = holes->holesdata_sz + holes->data_size;
3092 if (G_p->g_filesz > Max_offset) {
3095 G_p->g_nam_p,
3096 (G_p->g_attrnam_p == NULL) ? "" :
3097 G_p->g_rw_sysattr ?
3100 (G_p->g_attrnam_p == NULL) ? "" :
3101 ((G_p->g_attrparent_p == NULL) ?
3102 G_p->g_attrnam_p:
3103 G_p->g_attrpath_p));
3123 G_p->g_cksum = (ulong_t)-1;
3136 G_p->g_cksum = csum;
3138 G_p->g_cksum = 0;
3149 if ((append_secattr(&secinfo, &len, aclp)) == -1)
3170 write_ancillary(holes->holesdata,
3171 holes->holesdata_sz, B_FALSE);
3179 amt_to_read = read_compress_holes(nam_p, G_p->g_filesz,
3182 amt_to_read = read_file(nam_p, G_p->g_filesz,
3187 cnt = (amt_to_read > CPIOBSZ) ? CPIOBSZ : (int)amt_to_read;
3188 FLUSH(cnt);
3189 (void) memset(Buffr.b_in_p, 0, cnt);
3190 Buffr.b_in_p += cnt;
3191 Buffr.b_cnt += cnt;
3192 amt_to_read -= cnt;
3195 pad = (Pad_val + 1 - (G_p->g_filesz & Pad_val)) & Pad_val;
3207 G_p->g_nam_p : Gen.g_attrfnam_p,
3210 (Gen.g_attrnam_p == NULL) ? "" : G_p->g_nam_p);
3215 G_p->g_nam_p : Gen.g_attrfnam_p,
3218 (Gen.g_attrnam_p == NULL) ? "" : G_p->g_nam_p,
3219 (real_filesz - orig_filesz));
3224 G_p->g_nam_p : Gen.g_attrfnam_p,
3227 (Gen.g_attrnam_p == NULL) ? "" : G_p->g_nam_p,
3228 (orig_filesz - real_filesz));
3235 rstfiles(U_KEEP, G_p->g_dirfd);
3236 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
3253 if (G_p->g_attrnam_p != NULL) {
3254 namep = G_p->g_attrnam_p;
3257 rstfiles(U_KEEP, G_p->g_passdirfd);
3266 if ((Ifile = openat(G_p->g_dirfd, get_component(namep), 0)) < 0) {
3268 (G_p->g_attrnam_p == NULL) ? Nam_p : G_p->g_attrfnam_p,
3269 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_rw_sysattr ?
3271 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p);
3272 rstfiles(U_KEEP, G_p->g_passdirfd);
3282 data_in_info->data_in_proc_mode = P_PROC;
3284 if (S_ISREG(G_p->g_mode))
3285 holes = get_holes_info(Ifile, G_p->g_filesz, B_TRUE);
3289 (G_p->g_attrnam_p == NULL) ? 0 : G_p->g_rw_sysattr,
3290 G_p->g_filesz, Bufsize, data_in_info, holes);
3295 (G_p->g_attrnam_p == NULL) ? 0 : G_p->g_rw_sysattr,
3296 G_p->g_filesz, Bufsize, data_in_info);
3301 if (data_in_info->data_in_rd_eof) {
3307 (G_p->g_attrnam_p == NULL) ?
3308 Nam_p : G_p->g_attrfnam_p,
3309 (G_p->g_attrnam_p == NULL) ? "" :
3310 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
3312 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p);
3319 (G_p->g_attrnam_p == NULL) ?
3320 Nam_p : G_p->g_attrfnam_p,
3321 (G_p->g_attrnam_p == NULL) ? "" :
3322 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
3324 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p);
3330 (G_p->g_attrnam_p == NULL) ? "" :
3331 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
3333 (G_p->g_attrnam_p == NULL) ? "" : Over_p);
3337 (G_p->g_attrnam_p == NULL) ? "" :
3338 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
3340 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p);
3347 rstfiles(U_OVER, G_p->g_passdirfd);
3349 rstfiles(U_KEEP, G_p->g_passdirfd);
3364 * archive and g_nlink == 1, link this file to the file name in t_linkname
3366 * is an old style (binary or -c) archive, create and extract the data for the
3393 * 1. neither -@ or -/ was specified.
3394 * 2. -@ was specified, -/ wasn't specified, and we're
3396 * or we're processing a read-write system attribute file.
3397 * 3. -@ wasn't specified, -/ was specified, and the file
3398 * we're processing it not a read-write system attribute file,
3403 * generating a table of contents, or if both -@ and -/ were
3406 if (G_p->g_attrnam_p != NULL) {
3409 (Atflag && !SysAtflag && ((G_p->g_attrparent_p != NULL) ||
3410 G_p->g_rw_sysattr)) ||
3411 (!Atflag && SysAtflag && ((G_p->g_attrparent_p != NULL) ||
3412 !G_p->g_rw_sysattr)))) {
3428 if (proc_file == F_SKIP && G_p->g_nlink == 1) {
3433 * Zero. Due to this we need to force the name
3437 VERBOSE((Args & OCt), G_p->g_nam_p);
3459 typeflag = Thdr_p->tbuf.t_typeflag;
3460 if (G_p->g_nlink == 1) { /* hard link */
3466 (void) strncpy(lname, Thdr_p->tbuf.t_linkname,
3472 (void) creat_lnk(G_p->g_dirfd,
3473 &lname[0], G_p->g_nam_p);
3481 creat_spec(G_p->g_dirfd) > 0) {
3483 (G_p->g_attrparent_p == NULL) ?
3484 G_p->g_nam_p : G_p->g_attrpath_p);
3490 (Ofile = openout(G_p->g_dirfd)) < 0) {
3501 if (proc_file != F_SKIP && creat_spec(G_p->g_dirfd) > 0) {
3502 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
3506 VERBOSE((Args & OCt), G_p->g_nam_p);
3510 if (G_p->g_nlink == 1 || (Hdr_type == TAR ||
3513 if (proc_file != F_SKIP && creat_spec(G_p->g_dirfd) > 0)
3514 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
3517 (Ofile = openout(G_p->g_dirfd)) < 0) {
3530 if (l_p->L_cnt == l_p->L_gen.g_nlink)
3532 if (!Onecopy || G_p->g_attrnam_p != NULL) {
3534 G_p = &tl_p->L_gen;
3542 if (creat_spec(G_p->g_dirfd) > 0)
3544 G_p->g_nam_p);
3546 openout(G_p->g_dirfd)) < 0) {
3558 cwd = -1;
3559 if (l_p->L_gen.g_attrnam_p != NULL) {
3561 l_p->L_gen.g_attrnam_p);
3563 tl_p->L_gen.g_attrnam_p);
3565 (void) fchdir(G_p->g_dirfd);
3568 l_p->L_gen.g_nam_p);
3570 tl_p->L_gen.g_nam_p);
3572 (void) creat_lnk(G_p->g_dirfd,
3576 l_p->L_lnk_p = NULL;
3577 free(tl_p->L_gen.g_nam_p);
3579 if (cwd != -1)
3584 if (tl_p->L_gen.g_filesz)
3597 G_p = &tl_p->L_gen;
3603 if (l_p->L_data) {
3604 (void) creat_lnk(G_p->g_dirfd,
3605 l_p->L_gen.g_nam_p,
3606 G_p->g_nam_p);
3608 (void) creat_spec(G_p->g_dirfd);
3609 l_p->L_data = 1;
3611 G_p->g_nam_p);
3613 openout(G_p->g_dirfd)) < 0) {
3617 l_p->L_data = 1;
3621 tl_p = tl_p->L_lnk_p;
3626 tl_p->L_nxt_p = l_p->L_nxt_p;
3627 tl_p->L_bck_p = l_p->L_bck_p;
3628 l_p->L_bck_p->L_nxt_p = tl_p;
3629 l_p->L_nxt_p->L_bck_p = tl_p;
3630 free(l_p->L_gen.g_nam_p);
3633 } /* tl_p->L_lnk_p != NULL */
3634 if (l_p->L_data == 0) {
3648 * Subsequent links to this file put this file name in their t_linkname field.
3650 * (i.e. binary and -c), linked files are written out as they are encountered.
3652 * to each file are found. For a file with n links, write n - 1 headers with
3671 if (Compress_sparse == 0 && G_p->g_filesz > Max_offset) {
3673 G_p->g_nam_p,
3674 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_rw_sysattr ?
3676 (G_p->g_attrnam_p == NULL) ? "" :
3677 ((G_p->g_attrparent_p == NULL) ? G_p->g_attrnam_p:
3678 G_p->g_attrpath_p));
3689 if (G_p->g_nlink == 1) {
3699 (void) strncpy(T_lname, l_p->L_gen.g_nam_p,
3700 l_p->L_gen.g_namesz);
3707 G_p->g_nam_p, T_lname, NAMSIZ);
3712 VERBOSE((Args & (OCv | OCV)), tl_p->L_gen.g_nam_p);
3715 for (; ttl_p->L_lnk_p != NULL;
3716 ttl_p = ttl_p->L_lnk_p) {
3717 if (ttl_p->L_lnk_p == tl_p) {
3718 ttl_p->L_lnk_p = tl_p->L_lnk_p;
3719 free(tl_p->L_gen.g_nam_p);
3736 if ((append_secattr(&secinfo, &len, aclp)) == -1)
3752 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
3755 if (G_p->g_nlink == 1) {
3762 if (l_p->L_cnt == l_p->L_gen.g_nlink)
3764 else if (Onecopy && G_p->g_attrnam_p == NULL) {
3768 if (Onecopy && G_p->g_attrnam_p == NULL) {
3770 while (tl_p->L_lnk_p != NULL) {
3771 G_p = &tl_p->L_gen;
3772 G_p->g_filesz = (off_t)0;
3775 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
3776 tl_p = tl_p->L_lnk_p;
3778 G_p = &tl_p->L_gen;
3791 * Only archive extended attribute files when '-@' was specified.
3792 * Only archive system extended attribute files if '-/' was specified.
3844 * Never restore read-only system attribute files. Only restore read-write
3845 * system attributes files when -/ was specified, and only traverse into
3847 * -@ was specified. This keeps us from archiving
3848 * <attribute name>/<read-write system attribute file>
3849 * when -/ was specified without -@.
3851 * attrname - attribute file name
3852 * attrparent - attribute's parent name within the base file's
3854 * arc_rwsysattr - flag that indicates that read-write system attribute
3857 * rw_sysattr - on return, flag will indicate if attrname is a
3858 * read-write system attribute file.
3867 /* Never restore read-only system attribute files */
3876 * Don't archive a read-write system attribute file if
3884 /* Never restore read-only system attribute files */
3891 * Only restore read-write system attribute files
3892 * when -/ was specified. Only restore extended
3893 * attributes when -@ was specified.
3912 * Only archive/restore read-write extended system attribute
3928 retry_open_attr(int pdirfd, int cwd, char *fullname, char *pattr, char *name,
3932 int ofilefd = -1;
3942 * for example: a mode such as r-xr--r--
3951 * If file has a non-trivial ACL, then save it
3956 O_RDONLY)) == -1) {
3957 return (-1);
3959 if (fstat(dirfd, &parentstat) == -1) {
3961 (pdirfd == -1) ? "" : gettext("parent of "),
3962 (pdirfd == -1) ? fullname : name);
3964 return (-1);
3968 (pdirfd == -1) ? "" : gettext("parent of "),
3969 (pdirfd == -1) ? fullname : name);
3971 return (-1);
3975 if (fchmod(dirfd, newmode) == -1) {
3977 (pdirfd == -1) ? "" : gettext("parent of "),
3978 (pdirfd == -1) ? fullname : name, newmode);
3982 return (-1);
3986 if (pdirfd == -1) {
3997 ofilefd = openat(pdirfd, name, oflag, mode);
4003 if (fchmod(dirfd, parentstat.st_mode) == -1) {
4005 (pdirfd == -1) ? "" : gettext("parent of "),
4006 (pdirfd == -1) ? fullname : name, newmode);
4013 (pdirfd == -1) ? "" : gettext("parent of "),
4014 (pdirfd == -1) ? fullname : name);
4050 * attrname = <attr> | <sys_attr>
4054 * attr_parent = <attr>
4059 * attr_parent = <attr>
4060 * attrname = <attr> | <sys_attr>
4068 * opened attribute directory. In addition, if the attribute is a read-write
4091 int firsttime = (*attr_parentfd == -1);
4102 *attr_parentfd = -1;
4115 if ((*attr_parentfd = attropen(dirp, ".", O_RDONLY)) == -1) {
4121 if ((*attr_parentfd = retry_open_attr(-1, cwd, dirp,
4122 NULL, ".", O_RDONLY, 0)) == -1) {
4124 *attr_parentfd = -1;
4138 *attr_parentfd = -1;
4149 *attr_parentfd = -1;
4156 * (i.e., <attr>/<sys_attr>), then recursively call open_attr_dir() to
4169 * file_pass: If the -l option is set (link files when possible), and the
4171 * (G_p->g_nam_p) to the destination file (Fullnam) and return. If not a
4189 msg(ERR, "Use -d option to copy \"%s\"", G_p->g_nam_p);
4193 save_name = G_p->g_nam_p;
4195 while (*(G_p->g_nam_p) == '/') {
4196 G_p->g_nam_p++;
4199 (void) strcpy(Full_p, (G_p->g_attrfnam_p == NULL) ?
4200 G_p->g_nam_p : G_p->g_attrfnam_p);
4202 if (G_p->g_attrnam_p == NULL) {
4203 G_p->g_passdirfd = open_dir(Fullnam_p);
4205 if (G_p->g_passdirfd == -1) {
4217 * the base file (if G_p->g_attrparent_p is NULL) or the
4218 * attribute (if G_p->g_attrparent_p is set) of the base file.
4221 G_p->g_passdirfd = -1;
4222 (void) fchdir(G_p->g_baseparent_fd);
4223 (void) open_attr_dir(G_p->g_attrnam_p, Fullnam_p,
4224 G_p->g_baseparent_fd, (G_p->g_attrparent_p == NULL) ? NULL :
4225 G_p->g_attrparent_p, &G_p->g_passdirfd, &rw_sysattr);
4226 if (G_p->g_passdirfd == -1) {
4230 (G_p->g_attrparent_p == NULL) ? "" :
4232 (G_p->g_attrparent_p == NULL) ? "" :
4233 G_p->g_attrparent_p,
4234 (G_p->g_attrparent_p == NULL) ? "" :
4261 if (G_p->g_attrnam_p == NULL) {
4262 if (creat_lnk(G_p->g_passdirfd,
4270 if ((G_p->g_mode & Ftype) == S_IFLNK && !(Args & OCL)) {
4287 if (openout(G_p->g_passdirfd) < 0) {
4301 if (lchown(Fullnam_p, (int)Rpw_p->pw_uid,
4302 (int)Rpw_p->pw_gid) < 0) {
4307 } else if ((lchown(Fullnam_p, (int)G_p->g_uid,
4308 (int)G_p->g_gid) < 0) && privileged) {
4319 if (!Adir && G_p->g_nlink > 1) {
4328 G_p = &tl_p->L_gen;
4332 cwd = -1;
4334 if (l_p->L_gen.g_attrnam_p != NULL) {
4337 (void) strcpy(Lnkend_p, l_p->L_gen.g_attrnam_p);
4339 (void) fchdir(G_p->g_passdirfd);
4341 lto = tl_p->L_gen.g_attrnam_p;
4345 (void) strcpy(Lnkend_p, l_p->L_gen.g_nam_p);
4346 (void) strcpy(Full_p, tl_p->L_gen.g_nam_p);
4351 (void) creat_lnk(G_p->g_passdirfd, lfrom, lto);
4357 l_p->L_lnk_p = NULL;
4358 free(tl_p->L_gen.g_nam_p);
4361 if (l_p->L_cnt == G_p->g_nlink) {
4375 if (creat_spec(G_p->g_passdirfd) > 0) {
4378 } else if ((Ofile = openout(G_p->g_passdirfd)) > 0) {
4391 * first n - 1 have g_filesz set to 0)) followed by the data for the file.
4402 (void) strcpy(Gen.g_nam_p, l_p->L_gen.g_nam_p);
4406 Gen.g_nlink = l_p->L_cnt; /* "actual" link count */
4411 Gen.g_nam_p = tl_p->L_gen.g_nam_p;
4412 Gen.g_namesz = tl_p->L_gen.g_namesz;
4413 if (tl_p->L_lnk_p == NULL) {
4424 tl_p = tl_p->L_lnk_p;
4438 l_p = l_p->L_nxt_p;
4445 is_sysattr(char *name)
4447 return ((strcmp(name, VIEW_READONLY) == 0) ||
4448 (strcmp(name, VIEW_READWRITE) == 0));
4455 * set appropriately after a valid header is found. Unless the -k option is
4466 int hit = NONE, cnt = 0;
4578 if (Gen.g_namesz - 1 > Max_namesz)
4587 if (G_p->g_cksum !=
4591 "Bad header - checksum "
4595 } else if (hit != BAR) { /* binary, -c, ASC and CRC */
4598 if (*(Buffr.b_out_p + hsize - 1) != '\0')
4613 Buffr.b_cnt--;
4616 if (!cnt++)
4625 } else if (cnt > 0) {
4626 msg(EPOST, "Re-synchronized on magic number/header.");
4654 Max_namesz = HNAMLEN - 1;
4661 Max_namesz = TNAMLEN - 1;
4723 Buffr.b_cnt -= (off_t)offset;
4730 Thdr_p->tbuf.t_typeflag == _XATTR_HDRTYPE)) {
4750 * be a simple attribute or extended attribute name,
4751 * or it can be something like <attr>/<sys attr> if
4753 * Determine the attribute name and attribute parent
4755 * attribute or extended attribute name, the attribute
4757 * something like <attr>/<sys attr>, the attribute
4758 * parent will be contain <attr>, and the attribute
4759 * name will contain <sys attr>.
4761 tapath = xattrp->h_names +
4762 strlen(xattrp->h_names) + 1;
4795 xattrp->h_names);
4834 E_EXIT, xattr_linkp->h_names);
4842 Gen.g_mode |= attrmode(xattrp->h_typeflag);
4844 Thdr_p->tbuf.t_typeflag = xattrp->h_typeflag;
4854 xattrp->h_typeflag == DIRTYPE) {
4876 Hdr_type == TAR) && Thdr_p->tbuf.t_typeflag == 'A')) {
4881 int cnt;
4891 cnt = (int)(bytes > CPIOBSZ) ? CPIOBSZ : bytes;
4892 FILL(cnt);
4893 (void) memcpy(tp, Buffr.b_out_p, cnt);
4894 tp += cnt;
4895 Buffr.b_out_p += cnt;
4896 Buffr.b_cnt -= (off_t)cnt;
4897 bytes -= (off_t)cnt;
4900 pad = (Pad_val + 1 - (Gen.g_filesz & Pad_val)) &
4905 Buffr.b_cnt -= (off_t)pad;
4911 attr = (struct sec_attr *)tp;
4912 switch (attr->attr_type) {
4915 (void) sscanf(attr->attr_len, "%7lo",
4919 strlen(&attr->attr_info[0])
4923 acl_fromtext(&attr->attr_info[0],
4930 bytes -= attrsize;
4936 bytes -= attrsize;
4939 bytes -= attrsize;
4945 msg(EXT, "unrecognized attr type");
4987 Buffr.b_cnt -= MIN_HOLES_HDRSIZE;
5024 lastchar = strlen(s) - 1;
5028 if (lastchar == APATH - 1) {
5031 "%s name too long.",
5046 if (Gen.g_dirfd != -1) {
5048 Gen.g_dirfd = -1;
5072 if (Gen.g_dirfd != -1) {
5076 if (Gen.g_dirfd == -1) {
5089 if (Gen.g_dirfd != -1) {
5093 if (Gen.g_dirfd == -1) {
5109 Gen.g_dirfd == -1) {
5132 if (Gen.g_dirfd != -1) {
5137 if (Gen.g_dirfd == -1) {
5146 Gen.g_dirfd = -1;
5155 msg(ERR, "%s%s%s name too long.",
5182 G_p->g_nam_p,
5266 if (numpat == maxpat - 1) {
5273 *(Nam_p + len - 1) = '\0'; /* remove the \n */
5299 msg(EXTN, "I/O error - cannot continue");
5301 msg(EXT, "Unexpected end-of-file encountered.");
5308 * pattern is matched (the second return), return 0 if -f was specified, else
5310 * returns), return 0 if -f was not specified, else return != 0.
5316 char *str_p = G_p->g_nam_p;
5323 if (G_p->g_attrfnam_p != NULL)
5324 str_p = G_p->g_attrfnam_p;
5357 int cnt = 2;
5363 lastp = c_p + strlen(nam_p) - 1;
5372 cnt = mkdir(nam_p, Def_mode);
5373 if (cnt != 0) {
5375 return (cnt);
5378 msg(ERR, "Missing -d option.");
5380 return (-1);
5386 if (cnt == 2) /* the file already exists */
5387 cnt = 0;
5388 return (cnt);
5426 swp_p->s_half[0] = swp_b.s_half[1];
5427 swp_p->s_half[1] = swp_b.s_half[0];
5430 swp_p->s_half[0] = swp_b.s_half[0];
5431 swp_p->s_half[1] = swp_b.s_half[1];
5469 if (G_p && (G_p->g_attrnam_p != NULL) && G_p->g_rw_sysattr) {
5498 * and the current file exists, get a temporary file name from mktemp(3C),
5508 int cnt, result;
5512 if (G_p->g_attrnam_p != NULL) {
5513 nam_p = G_p->g_attrnam_p;
5518 nam_p = G_p->g_nam_p;
5524 (Max_filesz < (G_p->g_filesz >> 9))) {
5527 (G_p->g_attrnam_p == NULL) ? nam_p : G_p->g_attrfnam_p,
5528 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_rw_sysattr ?
5530 (G_p->g_attrnam_p == NULL) ? "" : nam_p,
5531 (off_t)(G_p->g_filesz - (Max_filesz << 9)));
5532 return (-1);
5537 * A file by the same name exists. Move it to a temporary
5554 if (G_p->g_rw_sysattr == 0)
5562 return (-1);
5570 if (G_p->g_attrnam_p != NULL) {
5576 nam_p = G_p->g_nam_p;
5587 * on non-XATTR system, symlink/open may fail with ENOENT. In such
5591 cnt = 0;
5596 if (Hdr_type == TAR && Thdr_p->tbuf.t_typeflag == SYMTYPE) {
5599 symlink(Thdr_p->tbuf.t_linkname, nam_p)) >= 0) {
5600 cnt = 0;
5610 "Cannot create symbolic link \"%s\" -> "
5612 Thdr_p->tbuf.t_linkname, nam_p);
5617 return (-1);
5621 cnt = 0;
5631 "Cannot create symbolic link \"%s\" -> "
5637 return (-1);
5639 } else if ((G_p->g_mode & Ftype) == S_IFLNK) {
5641 FILL(G_p->g_filesz);
5643 Buffr.b_out_p, G_p->g_filesz);
5644 *(Symlnk_p + G_p->g_filesz) = '\0';
5648 &Thdr_p->tbuf.t_linkname[0], NAMSIZ);
5651 cnt = 0;
5661 "Cannot create symbolic link \"%s\" -> "
5668 return (-1);
5674 O_CREAT|O_RDWR|O_TRUNC, (int)G_p->g_mode)) < 0) {
5676 if (G_p->g_attrnam_p != NULL) {
5679 (G_p->g_attrparent_p == NULL) ?
5680 NULL : G_p->g_attrparent_p, nam_p,
5682 (int)G_p->g_mode);
5694 return (-1);
5710 cnt = 0;
5714 cnt++;
5715 } while (cnt < 2 && missdir(nam_p) == 0);
5717 switch (cnt) {
5722 if ((G_p->g_mode & Ftype) == S_IFLNK ||
5727 (int)Rpw_p->pw_uid,
5728 (int)Rpw_p->pw_gid,
5733 (G_p->g_attrnam_p == NULL) ?
5734 nam_p : G_p->g_attrfnam_p,
5735 (G_p->g_attrnam_p == NULL) ?
5736 "" : G_p->g_rw_sysattr ?
5739 (G_p->g_attrnam_p == NULL) ?
5743 (int)G_p->g_uid, (int)G_p->g_gid,
5747 (G_p->g_attrnam_p == NULL) ?
5748 nam_p : G_p->g_attrfnam_p,
5749 (G_p->g_attrnam_p == NULL) ? "" :
5750 G_p->g_rw_sysattr ?
5753 (G_p->g_attrnam_p == NULL) ? "" : nam_p);
5761 (G_p->g_attrnam_p == NULL) ? Over_p :
5762 G_p->g_attrfnam_p,
5763 (G_p->g_attrnam_p == NULL) ? "" :
5764 G_p->g_rw_sysattr ?
5767 (G_p->g_attrnam_p == NULL) ? "" : Over_p);
5770 (G_p->g_attrnam_p == NULL) ? nam_p :
5771 G_p->g_attrfnam_p,
5772 (G_p->g_attrnam_p == NULL) ? "" :
5773 G_p->g_rw_sysattr ?
5776 (G_p->g_attrnam_p == NULL) ? "" : nam_p);
5783 (G_p->g_attrnam_p == NULL) ? Over_p :
5784 G_p->g_attrfnam_p,
5785 (G_p->g_attrnam_p == NULL) ? "" :
5786 G_p->g_rw_sysattr ?
5789 (G_p->g_attrnam_p == NULL) ? "" :
5793 (G_p->g_attrnam_p == NULL) ? nam_p :
5794 G_p->g_attrfnam_p,
5795 (G_p->g_attrnam_p == NULL) ? "" :
5796 G_p->g_rw_sysattr ?
5799 (G_p->g_attrnam_p == NULL) ? "" : nam_p);
5899 Thdr_p->tbuf.t_name, NAMSIZ);
5900 (void) sscanf(Thdr_p->tbuf.t_mode, "%8lo",
5902 (void) sscanf(Thdr_p->tbuf.t_uid, "%8lo", &Gen.g_uid);
5903 (void) sscanf(Thdr_p->tbuf.t_gid, "%8lo", &Gen.g_gid);
5904 (void) sscanf(Thdr_p->tbuf.t_size, "%11llo",
5906 (void) sscanf(Thdr_p->tbuf.t_mtime, "%12lo",
5908 (void) sscanf(Thdr_p->tbuf.t_cksum, "%8lo",
5910 if (Thdr_p->tbuf.t_linkname[0] != '\0')
5915 switch (Thdr_p->tbuf.t_typeflag) {
5934 (void) sscanf(Thdr_p->tbuf.t_magic, "%8lo",
5937 (void) sscanf(Thdr_p->tbuf.t_version, "%8lo",
5940 (void) sscanf(Thdr_p->tbuf.t_uname, "%32s",
5942 (void) sscanf(Thdr_p->tbuf.t_gname, "%32s",
5944 (void) sscanf(Thdr_p->tbuf.t_devmajor, "%8lo",
5946 (void) sscanf(Thdr_p->tbuf.t_devminor, "%8lo",
5949 Thdr_p->tbuf.t_prefix, PRESIZ);
5962 (void) sscanf(Thdr_p->tbuf.t_mode, "%lo", &Gen.g_mode);
5963 (void) sscanf(Thdr_p->tbuf.t_uid, "%lo", &Gen.g_uid);
5964 (void) sscanf(Thdr_p->tbuf.t_gid, "%lo", &Gen.g_gid);
5965 (void) sscanf(Thdr_p->tbuf.t_size, "%llo",
5967 (void) sscanf(Thdr_p->tbuf.t_mtime, "%lo",
5969 (void) sscanf(Thdr_p->tbuf.t_cksum, "%lo",
5971 if (Thdr_p->tbuf.t_typeflag == '1') /* hardlink */
5976 Thdr_p->tbuf.t_name, NAMSIZ);
6010 p->L_bck_p->L_nxt_p = p->L_nxt_p;
6011 p->L_nxt_p->L_bck_p = p->L_bck_p;
6014 struct Lnk *new_p = p->L_lnk_p;
6016 free(p->L_gen.g_nam_p);
6026 * 3B2, reads must begin on a word boundary, therefore, with the -i option,
6041 pad -= Buffr.b_cnt;
6047 msg(EXT, "Unexpected end-of-archive encountered.");
6064 Gen.g_uid = dpasswd->pw_uid;
6072 Gen.g_gid = dgroup->gr_gid;
6077 * rstfiles: Perform final changes to the file. If the -u option is set,
6101 if (G_p->g_attrnam_p == NULL) {
6104 nam_p = G_p->g_attrnam_p;
6108 nam_p = G_p->g_nam_p;
6123 (G_p->g_attrnam_p == NULL) ? Over_p : Fullnam_p,
6124 (G_p->g_attrnam_p == NULL) ? "" :
6125 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
6127 (G_p->g_attrnam_p == NULL) ? "" : Over_p);
6130 (G_p->g_attrnam_p == NULL) ? nam_p : Fullnam_p,
6131 (G_p->g_attrnam_p == NULL) ? "" :
6132 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
6134 (G_p->g_attrnam_p == NULL) ? "" : nam_p);
6148 tmp_ptr = G_p->g_nam_p;
6149 G_p->g_nam_p = Over_p;
6160 (G_p->g_attrnam_p == NULL) ?
6162 (G_p->g_attrnam_p == NULL) ? "" :
6163 G_p->g_rw_sysattr ?
6166 (G_p->g_attrnam_p == NULL) ?
6173 (G_p->g_attrnam_p == NULL) ?
6175 (G_p->g_attrnam_p == NULL) ? "" :
6176 G_p->g_rw_sysattr ?
6179 (G_p->g_attrnam_p == NULL) ?
6193 if (G_p->g_attrnam_p == NULL) {
6204 * the name.
6209 tmp_ptr = G_p->g_nam_p;
6210 G_p->g_nam_p = Over_p;
6218 (G_p->g_attrnam_p == NULL) ?
6220 (G_p->g_attrnam_p == NULL) ? "" :
6221 G_p->g_rw_sysattr ?
6224 (G_p->g_attrnam_p == NULL) ? "" : Over_p);
6230 if (G_p->g_attrnam_p != NULL) {
6231 inam_p = G_p->g_attrfnam_p;
6232 onam_p = G_p->g_attrnam_p;
6238 if (G_p->g_attrnam_p != NULL) {
6239 inam_p = onam_p = G_p->g_attrnam_p;
6241 inam_p = onam_p = G_p->g_nam_p;
6254 Rpw_p->pw_uid, Rpw_p->pw_gid,
6258 (G_p->g_attrnam_p == NULL) ? "" :
6259 G_p->g_rw_sysattr ?
6262 (G_p->g_attrnam_p == NULL) ? "" : onam_p);
6266 G_p->g_uid, G_p->g_gid,
6270 (G_p->g_attrnam_p == NULL) ? "" :
6271 G_p->g_rw_sysattr ?
6274 (G_p->g_attrnam_p == NULL) ? "" : onam_p);
6280 G_p->g_mtime, G_p->g_mtime);
6297 new_mask = G_p->g_mode;
6300 new_mask = G_p->g_mode & ~orig_mask;
6303 if (G_p->g_attrnam_p != NULL) {
6311 (G_p->g_attrnam_p == NULL) ?
6312 onam_p : G_p->g_attrfnam_p,
6313 (G_p->g_attrnam_p == NULL) ? "" :
6314 G_p->g_rw_sysattr ?
6317 (G_p->g_attrnam_p == NULL) ? "" : onam_p);
6330 set_tym(G_p->g_dirfd, get_component(inam_p),
6355 off2 = Bufsize - (Buffr.b_cnt % Bufsize);
6358 if (lseek(Archive, -(off1 + off2), SEEK_REL) < 0)
6362 if (lseek(Archive, (off_t)-rv, SEEK_REL) < 0)
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.
6407 char *dupl_p = "Only one occurrence of -%c allowed";
6416 if (PageSize == -1) {
6490 case 'v': /* verbose - print file names */
6538 case 'M': /* specify new end-of-media message */
6572 case '6': /* for old, sixth-edition files */
6602 largc -= optind;
6625 if (largc > 0) /* save patterns for -i option, if any */
6630 if (largc != 0) /* error if arguments left with -o */
6698 for (blk_cnt = blk_cnt_max; blk_cnt > 1; blk_cnt--) {
6726 Full_p = Fullnam_p + strlen(Fullnam_p) - 1;
6759 (G_p->g_attrnam_p == NULL) ? nam_p : Fullnam_p,
6760 (G_p->g_attrnam_p == NULL) ? "" :
6761 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
6763 (G_p->g_attrnam_p == NULL) ? "" : nam_p);
6767 (G_p->g_attrnam_p == NULL) ? nam_p : Fullnam_p,
6768 (G_p->g_attrnam_p == NULL) ? "" :
6769 G_p->g_rw_sysattr ? gettext(" System Attribute ") :
6771 (G_p->g_attrnam_p == NULL) ? "" : nam_p);
6778 * of a file from the archive with the -u option set, and the filename did
6791 nam_p = G_p->g_nam_p;
6820 * swap: Swap bytes (-s), halfwords (-S) or or both halfwords and bytes (-b).
6824 swap(char *buf_p, int cnt)
6831 rcnt = cnt % 4;
6832 cnt /= 4;
6834 tcnt = cnt;
6837 while (tcnt-- > 0) {
6838 tbyte = Swp_p->s_byte[0];
6839 Swp_p->s_byte[0] = Swp_p->s_byte[1];
6840 Swp_p->s_byte[1] = tbyte;
6841 tbyte = Swp_p->s_byte[2];
6842 Swp_p->s_byte[2] = Swp_p->s_byte[3];
6843 Swp_p->s_byte[3] = tbyte;
6847 tbyte = Swp_p->s_byte[0];
6848 Swp_p->s_byte[0] = Swp_p->s_byte[1];
6849 Swp_p->s_byte[1] = tbyte;
6850 tbyte = Swp_p->s_byte[2];
6854 tcnt = cnt;
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;
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"));
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"));
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.
6916 const char *name = nam_p;
6934 name = (Args & OCp) ? nam_p : Gen.g_attrfnam_p;
6943 Hdr_type == TAR) && Thdr_p->tbuf.t_typeflag == 'A')) {
6949 modestr[i] = '-';
6951 modestr[i-1] = aclchar;
6957 temp = (mode >> (6 - (i * 3)));
6985 case (S_IFREG): /* was initialized to '-' */
7019 if ((S_ISGID & G_p->g_mode) == S_ISGID && modestr[6] == 'x')
7028 if (Lastuid == (uid_t)-1)
7029 (void) printf("-1 ");
7031 (void) printf("%-9s", Curpw_p->pw_name);
7034 (void) printf("%-9s", Curpw_p->pw_name);
7037 (void) printf("%-9d", (int)Gen.g_uid);
7038 Lastuid = (uid_t)-1;
7042 if (Lastgid == (gid_t)-1)
7043 (void) printf("-1 ");
7045 (void) printf("%-9s", Curgr_p->gr_name);
7048 (void) printf("%-9s", Curgr_p->gr_name);
7051 (void) printf("%-9d", (int)Gen.g_gid);
7052 Lastgid = (gid_t)-1;
7063 filesz = Gen.g_holes->orig_size;
7076 str_fprintf(stdout, name_fmt, name, attribute);
7080 Thdr_p->tbuf.t_linkname);
7087 (void) printf(" -> %s", Symlnk_p);
7098 Thdr_p->tbuf.t_typeflag == '1') {
7101 Thdr_p->tbuf.t_linkname : Gen.g_attrfnam_p,
7109 str_fprintf(Out_p, name_fmt, name, attribute);
7131 int cnt, pad;
7154 if (G_p->g_attrnam_p != NULL && Hdr_type != USTAR &&
7156 mode = (G_p->g_mode & POSIXMODES) | _XATTR_CPIO_MODE;
7158 mode = G_p->g_mode;
7161 len = G_p->g_filesz;
7166 mode = G_p->g_mode | C_ISSPARSE;
7167 len = G_p->g_filesz;
7171 uid = G_p->g_uid;
7172 gid = G_p->g_gid;
7178 case BIN: /* 16-bits of u_short */
7205 * Since cpio formats -don't- encode the symbolic names, print
7212 if (uid != G_p->g_uid && Hdr_type != USTAR) {
7214 (G_p->g_attrnam_p == NULL) ?
7215 G_p->g_nam_p : G_p->g_attrfnam_p,
7216 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_rw_sysattr ?
7218 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p,
7223 if (gid != G_p->g_gid && Hdr_type != USTAR) {
7225 (G_p->g_attrnam_p == NULL) ?
7226 G_p->g_nam_p : G_p->g_attrfnam_p,
7227 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_rw_sysattr ?
7229 (G_p->g_attrnam_p == NULL) ? "" : G_p->g_attrnam_p,
7240 cnt = Hdrsz + G_p->g_namesz;
7245 cnt = TARSZ;
7250 FLUSH(cnt);
7254 Hdr.h_magic = (short)G_p->g_magic;
7255 Hdr.h_dev = G_p->g_dev;
7256 Hdr.h_ino = G_p->g_ino;
7260 Hdr.h_nlink = G_p->g_nlink;
7261 Hdr.h_rdev = G_p->g_rdev;
7262 mkshort(Hdr.h_mtime, (long)G_p->g_mtime);
7263 Hdr.h_namesize = (short)G_p->g_namesz;
7265 (void) strcpy(Hdr.h_name, G_p->g_nam_p);
7266 (void) memcpy(Buffr.b_in_p, &Hdr, cnt);
7272 "11llo%s", G_p->g_magic, G_p->g_dev, G_p->g_ino, mode,
7273 (long)uid, (long)gid, G_p->g_nlink, MK_USHORT(G_p->g_rdev),
7274 G_p->g_mtime, (long)G_p->g_namesz, (offset_t)len,
7275 G_p->g_nam_p);
7283 G_p->g_magic, G_p->g_ino, mode, G_p->g_uid,
7284 G_p->g_gid, G_p->g_nlink, G_p->g_mtime, (ulong_t)len,
7285 major(G_p->g_dev), minor(G_p->g_dev),
7286 major(G_p->g_rdev), minor(G_p->g_rdev),
7287 G_p->g_namesz, G_p->g_cksum, G_p->g_nam_p);
7292 (void) strncpy(Thdr_p->tbuf.t_name, G_p->g_tname,
7293 (int)strlen(G_p->g_tname));
7294 (void) sprintf(Thdr_p->tbuf.t_mode, "%07o", (int)mode);
7295 (void) sprintf(Thdr_p->tbuf.t_uid, "%07o", (int)uid);
7296 (void) sprintf(Thdr_p->tbuf.t_gid, "%07o", (int)gid);
7297 (void) sprintf(Thdr_p->tbuf.t_size, "%011llo",
7299 (void) sprintf(Thdr_p->tbuf.t_mtime, "%011lo", G_p->g_mtime);
7301 Thdr_p->tbuf.t_typeflag = 'A'; /* ACL file type */
7303 (G_p->g_attrnam_p != NULL)) {
7304 Thdr_p->tbuf.t_typeflag = _XATTR_HDRTYPE;
7306 Thdr_p->tbuf.t_typeflag = G_p->g_typeflag;
7312 if (((G_p->g_mode & Ftype) != S_IFLNK) &&
7313 (G_p->g_attrnam_p == NULL)) {
7314 Thdr_p->tbuf.t_typeflag = LNKTYPE;
7315 (void) sprintf(Thdr_p->tbuf.t_size,
7318 (void) strncpy(Thdr_p->tbuf.t_linkname, T_lname,
7321 (void) strcpy(Thdr_p->tbuf.t_magic, TMAGIC);
7322 (void) strcpy(Thdr_p->tbuf.t_version, TVERSION);
7323 (void) strcpy(Thdr_p->tbuf.t_uname, G_p->g_uname);
7324 (void) strcpy(Thdr_p->tbuf.t_gname, G_p->g_gname);
7325 (void) sprintf(Thdr_p->tbuf.t_devmajor, "%07o",
7326 (int)major(G_p->g_rdev));
7327 (void) sprintf(Thdr_p->tbuf.t_devminor, "%07o",
7328 (int)minor(G_p->g_rdev));
7330 (void) strcpy(Thdr_p->tbuf.t_prefix, Gen.g_prefix);
7334 Thdr_p->tbuf.t_prefix[0] = '\0';
7336 (void) sprintf(Thdr_p->tbuf.t_cksum, "%07o",
7342 (void) strncpy(Thdr_p->tbuf.t_name, G_p->g_nam_p,
7343 G_p->g_namesz);
7344 (void) sprintf(Thdr_p->tbuf.t_mode, "%07o ", (int)mode);
7345 (void) sprintf(Thdr_p->tbuf.t_uid, "%07o ", (int)uid);
7346 (void) sprintf(Thdr_p->tbuf.t_gid, "%07o ", (int)gid);
7347 (void) sprintf(Thdr_p->tbuf.t_size, "%011llo ",
7349 (void) sprintf(Thdr_p->tbuf.t_mtime, "%011o ",
7350 (int)G_p->g_mtime);
7352 Thdr_p->tbuf.t_typeflag = '1';
7354 Thdr_p->tbuf.t_typeflag = '\0';
7356 (void) strncpy(Thdr_p->tbuf.t_linkname, T_lname,
7363 Buffr.b_in_p += cnt;
7364 Buffr.b_cnt += cnt;
7365 pad = ((cnt + Pad_val) & ~Pad_val) - cnt;
7380 * so re-pad the buffer with nulls and try again.
7386 int cnt, need;
7421 for (cnt = 0; cnt < 3; cnt++) {
7431 need = Bufsize - (Buffr.b_cnt % Bufsize);
7437 cnt = (need < TARSZ) ? need : TARSZ;
7438 need -= cnt;
7439 FLUSH(cnt);
7440 (void) memset(Buffr.b_in_p, 0, cnt);
7441 Buffr.b_in_p += cnt;
7442 Buffr.b_cnt += cnt;
7455 if (Thdr_p->tbuf.t_typeflag == '5')
7471 typeflag = Thdr_p->tbuf.t_typeflag;
7480 * FromStat if the file is representable in -Hodc format, and NULL otherwise.
7501 msg(ERR, "Error -Hodc format can't support expanded"
7522 "device number - linked "
7542 /* -actual- not truncated uid */
7546 /* -actual- not truncated gid */
7567 * +------------------+
7569 * |------------------|
7571 * |------------------|
7573 * |------------------|
7575 * |------------------|
7577 * |------------------|
7581 * +------------------+
7594 if (tmp_hdr->dbuf.bar_magic[0] == BAR_VOLUME_MAGIC) {
7599 (void) memcpy(&(bar_Vhdr->dbuf), &(tmp_hdr->dbuf), TBLOCK);
7606 (void) sscanf(bar_Vhdr->dbuf.mode, "%8lo", &Gen_bar_vol.g_mode);
7607 (void) sscanf(bar_Vhdr->dbuf.uid, "%8d", (int *)&Gen_bar_vol.g_uid);
7608 (void) sscanf(bar_Vhdr->dbuf.gid, "%8d", (int *)&Gen_bar_vol.g_gid);
7609 (void) sscanf(bar_Vhdr->dbuf.size, "%12llo",
7611 (void) sscanf(bar_Vhdr->dbuf.mtime, "%12lo", &Gen_bar_vol.g_mtime);
7612 (void) sscanf(bar_Vhdr->dbuf.chksum, "%8lo", &Gen_bar_vol.g_cksum);
7615 if (bar_Vhdr->dbuf.compressed == '1')
7621 Buffr.b_cnt -= 512;
7626 if (strcmp(bar_Vhdr->dbuf.volume_num, "1") != 0) {
7630 bar_Vhdr->dbuf.volume_num);
7655 tmp = &tmp_hdr->dbuf.mode[1];
7657 (void) sscanf(tmp_hdr->dbuf.uid, "%8lo", &Gen.g_uid);
7658 (void) sscanf(tmp_hdr->dbuf.gid, "%8lo", &Gen.g_gid);
7659 (void) sscanf(tmp_hdr->dbuf.size, "%12llo",
7661 (void) sscanf(tmp_hdr->dbuf.mtime, "%12lo", &Gen.g_mtime);
7662 (void) sscanf(tmp_hdr->dbuf.chksum, "%8lo", &Gen.g_cksum);
7663 (void) sscanf(tmp_hdr->dbuf.rdev, "%8lo", &Gen.g_rdev);
7668 bar_linkflag = tmp_hdr->dbuf.linkflag;
7669 start_of_name = &tmp_hdr->dbuf.start_of_name;
7684 * if the bar archive is compressed, set up a pipe and do the de-compression
7697 "chmod +w '%s'; uncompress -c > '%s'; "
7699 Gen.g_nam_p, Gen.g_nam_p, (int)G_p->g_mode, Gen.g_nam_p);
7702 "uncompress -c > '%s'", Gen.g_nam_p);
7736 if (tmp_hdr->dbuf.bar_magic[0] == BAR_VOLUME_MAGIC) {
7741 (void) memcpy(&(bar_Vhdr->dbuf),
7742 &(tmp_hdr->dbuf), TBLOCK);
7750 (void) sscanf(bar_Vhdr->dbuf.mode, "%8lo",
7752 (void) sscanf(bar_Vhdr->dbuf.uid, "%8lo",
7754 (void) sscanf(bar_Vhdr->dbuf.gid, "%8lo",
7756 (void) sscanf(bar_Vhdr->dbuf.size, "%12llo",
7758 (void) sscanf(bar_Vhdr->dbuf.mtime, "%12lo",
7760 (void) sscanf(bar_Vhdr->dbuf.chksum, "%8lo",
7762 if (bar_Vhdr->dbuf.compressed == '1')
7771 (void) memcpy(Buffr.b_in_p, &buff[512], (Bufsize - 512));
7772 Buffr.b_in_p += (Bufsize - 512);
7773 Buffr.b_cnt += (long)(Bufsize - 512);
7789 if (ckname(1) != F_SKIP && creat_spec(G_p->g_dirfd) > 0) {
7790 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
7799 (Ofile = openout(G_p->g_dirfd)) < 0) {
7810 (void) creat_lnk(G_p->g_dirfd, bar_linkname, G_p->g_nam_p);
7815 (Ofile = openout(G_p->g_dirfd)) < 0) {
7823 if (ckname(1) != F_SKIP && creat_spec(G_p->g_dirfd) > 0) {
7824 VERBOSE((Args & (OCv | OCV)), G_p->g_nam_p);
7849 #define G_NS 12 /* noswap pseudo-dev */
7850 #define G_RAM 13 /* ram pseudo-dev */
7875 bufsize = -1;
7876 if (fstat(*fdes, &st_buf) == -1)
7877 return (-1);
7885 bufsize = -1;
7923 * the generic EOM indication of rv = -1, errno = ENOSPC.
7933 return (-1);
7940 (rv == -1 && errno == EIO)) {
7956 * the generic EOM indication of rv = -1, errno = ENOSPC.
7966 return (-1);
7972 if ((rv == 0 && errno == 0) || (rv == -1 && errno == EIO)) {
7974 rv = -1;
7993 if (ioctl(fd, MTIOCGET, &stuff) != -1) {
8013 if (ioctl(fd, FDIOGCHAR, &stuff) != -1) {
8052 return (-1);
8056 attr = e_zalloc(E_NORMAL, newattrsize);
8057 if (attr == NULL) {
8059 return (-1);
8061 attr->attr_type = (acl_type(aclp) == ACLENT_T) ?
8064 (void) sprintf(attr->attr_len, "%06o", acl_cnt(aclp));
8065 (void) strcpy((char *)&attr->attr_info[0], attrtext);
8073 return (-1);
8076 /* old security info + new attr header(8) + new attr */
8082 *secinfo_len -= newattrsize;
8083 return (-1);
8087 (void) memcpy(new_secinfo + oldsize, attr, newattrsize);
8100 int pad, cnt;
8106 cnt = (unsigned)(len > CPIOBSZ) ? CPIOBSZ : len;
8107 FLUSH(cnt);
8109 (void) memcpy(Buffr.b_in_p, buf, (unsigned)cnt);
8110 Buffr.b_in_p += cnt;
8111 Buffr.b_cnt += cnt;
8112 len -= cnt;
8113 buf += cnt;
8116 pad = (Pad_val + 1 - (cnt & Pad_val)) & Pad_val;
8129 DIR *name;
8141 if ((name = opendir(path)) == NULL) {
8143 return (-1);
8146 if (chdir(path) == -1) {
8148 return (-1);
8154 while ((direct = readdir(name)) != NULL) {
8158 if (strcmp(direct->d_name, ".") == 0 ||
8159 strcmp(direct->d_name, "..") == 0)
8162 if (lstat(direct->d_name, &sbuf) == -1) {
8163 msg(ERRN, MSG1, direct->d_name);
8164 (void) closedir(name);
8165 return (-1);
8169 if (remove_dir(direct->d_name) == -1) {
8170 msg(ERRN, MSG2, direct->d_name);
8171 (void) closedir(name);
8172 return (-1);
8175 if (unlink(direct->d_name) == -1) {
8176 msg(ERRN, MSG3, direct->d_name);
8177 (void) closedir(name);
8178 return (-1);
8187 (void) closedir(name);
8192 if (chdir("..") == -1) {
8194 return (-1);
8204 return (-1);
8207 if (rmdir(basename(path_copy)) == -1) {
8210 return (-1);
8257 * archive the extended attributes if -@ was specified,
8258 * and the extended system attributes if -/ was
8272 * Determine if there are non-transient system
8276 if ((filefd = open(filename, O_RDONLY)) == -1) {
8284 (attrparent == NULL) ? G_p->g_nam_p :
8285 G_p->g_attrfnam_p);
8325 if (Gen.g_dirfd == -1) {
8335 savenamep = G_p->g_nam_p;
8337 savenamep = G_p->g_attrfnam_p;
8340 if ((dirpfd = dup(Gen.g_dirfd)) == -1) {
8355 if (strcmp(dp->d_name, "..") == 0) {
8358 if (verify_attr(dp->d_name, attrparent,
8363 if (strcmp(dp->d_name, ".") == 0) {
8370 Gen.g_attrnam_p = dp->d_name;
8372 if (STAT(Gen.g_dirfd, Gen.g_nam_p, &SrcSt) == -1) {
8375 " file \"%s\"", dp->d_name, (attrparent == NULL) ?
8395 * Set up dummy header name
8399 * then the name is updated to drop the .hdr off
8405 msg(ERRN, "Could not calloc memory for attribute name");
8417 msg(ERRN, "Could not calloc memory for attribute name");
8434 filefd = openat(Gen.g_dirfd, dp->d_name, O_RDONLY);
8435 if (filefd == -1) {
8438 " file \"%s\"", dp->d_name, savenamep);
8456 * hidden attribute directory and read-write system attributes.
8462 Gen.g_attrparent_p = dp->d_name;
8469 if (Gen.g_passdirfd != -1) {
8471 Gen.g_passdirfd = -1;
8495 Gen.g_dirfd = -1;
8543 #define ROUNDTOTBLOCK(a) ((a + (TBLOCK -1)) & ~(TBLOCK -1))
8560 int stringlen; /* length of filename + attr */
8562 * length of filename + attr
8600 linkstringlen = strlen(linkinfo->L_gen.g_attrfnam_p) +
8601 strlen(linkinfo->L_gen.g_attrnam_p) + 2;
8625 (void) strcpy(hptr->h_version, XATTR_ARCH_VERS);
8626 (void) sprintf(hptr->h_component_len, "%0*d",
8627 sizeof (hptr->h_component_len) - 1, complen);
8628 (void) sprintf(hptr->h_link_component_len, "%0*d",
8629 sizeof (hptr->h_link_component_len) - 1, linklen);
8630 (void) sprintf(hptr->h_size, "%0*d", sizeof (hptr->h_size) - 1, len);
8637 * the normal name space. The remaining segments describes a path
8639 * the previous segment, making it possible to name attributes on
8641 * the second segment will contain the attribute name. If we are
8643 * second segment will contain the attribute name, and a third segment
8644 * will contain the system attribute name. The attribute pathing
8649 (void) sprintf(tptr->h_namesz, "%0*d", sizeof (tptr->h_namesz) - 1,
8651 (void) strcpy(tptr->h_names, filename);
8653 (void) strcpy(&tptr->h_names[attrnames_index], attrpath);
8654 tptr->h_typeflag = typeflag;
8662 if ((aptr = strpbrk(&tptr->h_names[attrnames_index], "/")) != NULL) {
8674 (void) sprintf(tptr->h_namesz, "%0*d",
8675 sizeof (tptr->h_namesz) - 1, linkstringlen);
8676 (void) strcpy(tptr->h_names, linkinfo->L_gen.g_attrfnam_p);
8678 &tptr->h_names[strlen(linkinfo->L_gen.g_attrfnam_p) + 1],
8679 linkinfo->L_gen.g_attrnam_p);
8680 tptr->h_typeflag = typeflag;
8719 if (G_p->g_attrnam_p != NULL) {
8720 return (openat(G_p->g_dirfd, G_p->g_attrnam_p, omode));
8722 return (openat(G_p->g_dirfd,
8723 get_component(G_p->g_nam_p), omode));
8730 return (openat(G_p->g_dirfd, get_component(G_p->g_nam_p), omode));
8742 int cnt;
8763 cnt = (int)(bytes > CPIOBSZ) ? CPIOBSZ : bytes;
8764 FILL(cnt);
8765 (void) memcpy(tp, Buffr.b_out_p, cnt);
8766 tp += cnt;
8767 Buffr.b_out_p += cnt;
8768 Buffr.b_cnt -= (off_t)cnt;
8769 bytes -= (off_t)cnt;
8772 pad = (Pad_val + 1 - (Gen.g_filesz & Pad_val)) &
8777 Buffr.b_cnt -= (off_t)pad;
8784 if (strcmp(xattrhead->h_version, XATTR_ARCH_VERS) != 0) {
8792 (void) sscanf(xattrhead->h_component_len, "%10d", &comp_len);
8793 (void) sscanf(xattrhead->h_link_component_len, "%10d", &link_len);
8796 (void) sscanf(xattrp->h_namesz, "%7d", &namelen);
8808 * the normal name space. The remaining segments describes a path
8810 * the previous segment, making it possible to name attributes on
8813 parentfilelen = strlen(xattrp->h_names);
8814 xattrapath = xattrp->h_names + parentfilelen + 1;
8819 * attribute. Save the name of the attribute for use later,
8820 * and replace the null separating the attribute name from
8821 * the system attribute name with a '/' so that xattrapath can
8822 * be used to display messages with the full attribute path name
8824 * in normal name space.
8897 open_dir(char *name)
8899 int fd = -1;
8900 int cnt = 0;
8903 dir = e_zalloc(E_EXIT, strlen(name) + 1);
8908 get_parent(name, dir);
8911 if (fd != -1) {
8915 cnt++;
8916 } while (cnt <= 1 && missdir(name) == 0);
8919 return (-1);
8928 if (G_p->g_attrnam_p != NULL) {
8935 * of either the base file (if G_p->g_attrparent_p is
8936 * NULL) or the attribute (if G_p->g_attrparent_p is
8939 (void) fchdir(G_p->g_baseparent_fd);
8940 (void) open_attr_dir(G_p->g_attrnam_p,
8941 G_p->g_attrfnam_p, G_p->g_baseparent_fd,
8942 (G_p->g_attrparent_p == NULL) ? NULL :
8943 G_p->g_attrparent_p, &G_p->g_dirfd, &rw_sysattr);
8947 (void) fchdir(G_p->g_baseparent_fd);
8950 if ((G_p->g_dirfd == -1) && (Args & (OCi | OCp))) {
8954 (G_p->g_attrparent_p == NULL) ? "" :
8956 (G_p->g_attrparent_p == NULL) ? "" :
8957 G_p->g_attrparent_p,
8958 (G_p->g_attrparent_p == NULL) ? "" :
8960 G_p->g_attrfnam_p);
8964 G_p->g_dirfd = open_dir(G_p->g_nam_p);
8965 if (G_p->g_dirfd == -1) {
8967 "Cannot open/create %s", G_p->g_nam_p);
8972 G_p->g_dirfd = -1;
8975 G_p->g_dirfd = -1;
8983 if (G_p->g_dirfd != -1) {
8984 (void) close(G_p->g_dirfd);
8985 G_p->g_dirfd = -1;
8999 * either the name + .hdr on the end or just the attr name
9010 if (tl_p->L_gen.g_ino == G_p->g_ino &&
9011 tl_p->L_gen.g_dev == G_p->g_dev) {
9015 tl_p = tl_p->L_nxt_p;
9046 while ((string > start) && *(string - 1) == '/') {
9047 string--;
9060 return (&slipool[--num_left]);
9064 return (&slipool[--num_left]);
9093 head->llink = NULL;
9094 head->bal = 0;
9096 p = head->rlink = sl_info_alloc();
9097 p->sl_ino = inode;
9098 p->sl_ftype = ftype;
9099 p->sl_count = 0;
9100 p->bal = 0;
9101 p->llink = NULL;
9102 p->rlink = NULL;
9108 s = p = head->rlink;
9113 switch (sl_compare(inode, ftype, p->sl_ino, p->sl_ftype)) {
9114 case -1:
9117 q = p->llink;
9121 p->llink = q;
9135 q = p->rlink;
9139 p->rlink = q;
9147 if (q->bal != 0) {
9157 q->sl_ino = inode;
9158 q->sl_ftype = ftype;
9159 q->sl_count = 0;
9160 q->llink = q->rlink = NULL;
9161 q->bal = 0;
9165 if ((cmpflg = sl_compare(inode, ftype, s->sl_ino, s->sl_ftype)) < 0) {
9166 r = p = s->llink;
9168 r = p = s->rlink;
9172 switch (sl_compare(inode, ftype, p->sl_ino, p->sl_ftype)) {
9173 case -1:
9174 p->bal = -1;
9175 p = p->llink;
9182 p->bal = 1;
9183 p = p->rlink;
9191 a = -1;
9196 if (s->bal == 0) {
9197 s->bal = a;
9198 head->llink = (sl_info_t *)((int)head->llink + 1);
9200 } else if (s->bal == -a) {
9201 s->bal = 0;
9206 * (s->bal == a)
9209 if (r->bal == a) {
9214 if (a == -1) {
9215 s->llink = r->rlink;
9216 r->rlink = s;
9218 s->rlink = r->llink;
9219 r->llink = s;
9222 s->bal = r->bal = 0;
9224 } else if (r->bal == -a) {
9227 if (a == -1) {
9228 p = r->rlink;
9229 r->rlink = p->llink;
9230 p->llink = r;
9231 s->llink = p->rlink;
9232 p->rlink = s;
9234 p = r->llink;
9235 r->llink = p->rlink;
9236 p->rlink = r;
9237 s->rlink = p->llink;
9238 p->llink = s;
9241 if (p->bal == 0) {
9242 s->bal = 0;
9243 r->bal = 0;
9244 } else if (p->bal == -a) {
9245 s->bal = 0;
9246 r->bal = a;
9247 } else if (p->bal == a) {
9248 s->bal = -a;
9249 r->bal = 0;
9252 p->bal = 0;
9257 if (s == t->rlink) {
9258 t->rlink = p;
9260 t->llink = p;
9276 return (p->sl_count);
9305 * archive the extended attributes if -@ was specified,
9306 * and the extended system attributes if -/ was
9319 /* Determine if there are non-transient system attributes. */
9347 if (dirfd == -1)
9351 if (tmpfd == -1) {
9363 if (dp->d_name[0] == '.') {
9364 if (dp->d_name[1] == '\0') {
9366 } else if ((dp->d_name[1] == '.') &&
9367 (dp->d_name[2] == '\0')) {
9376 if (fstatat(dirfd, dp->d_name, &sb,
9381 if (verify_attr(dp->d_name, attrparent,
9390 if (fstatat(dirfd, dp->d_name,
9406 rc = preview_attrs(s, dp->d_name);
9439 /* /var/tmp is read-only in the mini-root environment */
9441 if (statvfs(tmpdir, &tdsb) == -1 || tdsb.f_flag & ST_RDONLY) {
9451 if ((tmpfd = mkstemp(tmpfname)) == -1) {
9455 if (unlink(tmpfname) == -1) {
9471 /* pre-process the name */
9473 lastchar = strlen(s) - 1;
9475 if (s[lastchar] != '\n' && lastchar == APATH - 1) {
9513 if (fseek(tmpfile, 0L, SEEK_SET) == -1) {
9538 device = sbp->st_dev;
9539 inode = sbp->st_ino;
9540 ftype = sbp->st_mode & Ftype;
9546 if (p->sl_count > 0) {
9552 * (e.g., read-write system attribute files will always have
9565 p->sl_count++;
9570 p->sl_count = 1;
9573 /* -Hodc: remap inode (-1 on overflow) */
9577 for (q = sl_remap_head; q && (q->dev != device);
9578 q = q->next) {
9584 q->dev = device;
9585 p->sl_ino2 = q->inode_count = 1;
9587 q->next = (sl_remap_head) ?
9588 sl_remap_head->next : NULL;
9591 if ((size_t)q->inode_count <=
9592 ((1 << (sizeof (o_ino_t) * 8)) - 1)) {
9594 p->sl_ino2 = ++(q->inode_count);
9596 p->sl_ino2 = (ino_t)-1;
9619 for (p = head->rlink; p; ) {
9620 if ((c = sl_compare(inode, ftype, p->sl_ino,
9621 p->sl_ftype)) == 0) {
9625 p = p->llink;
9627 p = p->rlink;
9642 if (devcache != NULL && devcache->dev == device) {
9643 return (devcache->head);
9647 for (lp = sl_devhash[key]; lp; lp = lp->next) {
9648 if (lp->dev == device) {
9650 return (lp->head);
9663 lp->dev = device;
9664 lp->head = head;
9665 lp->next = sl_devhash[key];
9674 end = &path[strlen(path) -1];
9685 openat64(int fd, char *name, int oflag, mode_t cmode)
9687 return (open64(name, oflag, cmode));
9691 openat(int fd, char *name, int oflag, mode_t cmode)
9693 return (open(name, oflag, cmode));
9697 fchownat(int fd, char *name, uid_t owner, gid_t group, int flag)
9700 return (lchown(name, owner, group));
9702 return (chown(name, owner, group));
9737 attropen(char *file, char *attr, int omode, mode_t cmode)
9740 return (-1);