11556Srgrimes/*-
21556Srgrimes * Copyright (c) 1992 Keith Muller.
31556Srgrimes * Copyright (c) 1992, 1993
41556Srgrimes *	The Regents of the University of California.  All rights reserved.
51556Srgrimes *
61556Srgrimes * This code is derived from software contributed to Berkeley by
71556Srgrimes * Keith Muller of the University of California, San Diego.
81556Srgrimes *
91556Srgrimes * Redistribution and use in source and binary forms, with or without
101556Srgrimes * modification, are permitted provided that the following conditions
111556Srgrimes * are met:
121556Srgrimes * 1. Redistributions of source code must retain the above copyright
131556Srgrimes *    notice, this list of conditions and the following disclaimer.
141556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151556Srgrimes *    notice, this list of conditions and the following disclaimer in the
161556Srgrimes *    documentation and/or other materials provided with the distribution.
171556Srgrimes * 4. Neither the name of the University nor the names of its contributors
181556Srgrimes *    may be used to endorse or promote products derived from this software
191556Srgrimes *    without specific prior written permission.
201556Srgrimes *
211556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311556Srgrimes * SUCH DAMAGE.
321556Srgrimes */
331556Srgrimes
341556Srgrimes#ifndef lint
3536049Scharnier#if 0
3636049Scharnierstatic char sccsid[] = "@(#)ftree.c	8.2 (Berkeley) 4/18/94";
3736049Scharnier#endif
381556Srgrimes#endif /* not lint */
3999110Sobrien#include <sys/cdefs.h>
4099110Sobrien__FBSDID("$FreeBSD$");
411556Srgrimes
421556Srgrimes#include <sys/types.h>
431556Srgrimes#include <sys/time.h>
441556Srgrimes#include <sys/stat.h>
451556Srgrimes#include <unistd.h>
461556Srgrimes#include <string.h>
471556Srgrimes#include <stdio.h>
481556Srgrimes#include <errno.h>
491556Srgrimes#include <stdlib.h>
501556Srgrimes#include <fts.h>
511556Srgrimes#include "pax.h"
521556Srgrimes#include "ftree.h"
531556Srgrimes#include "extern.h"
541556Srgrimes
551556Srgrimes/*
561556Srgrimes * routines to interface with the fts library function.
571556Srgrimes *
581556Srgrimes * file args supplied to pax are stored on a single linked list (of type FTREE)
591556Srgrimes * and given to fts to be processed one at a time. pax "selects" files from
601556Srgrimes * the expansion of each arg into the corresponding file tree (if the arg is a
611556Srgrimes * directory, otherwise the node itself is just passed to pax). The selection
621556Srgrimes * is modified by the -n and -u flags. The user is informed when a specific
631556Srgrimes * file arg does not generate any selected files. -n keeps expanding the file
641556Srgrimes * tree arg until one of its files is selected, then skips to the next file
651556Srgrimes * arg. when the user does not supply the file trees as command line args to
661556Srgrimes * pax, they are read from stdin
671556Srgrimes */
681556Srgrimes
6946684Skrisstatic FTS *ftsp = NULL;		/* current FTS handle */
701556Srgrimesstatic int ftsopts;			/* options to be used on fts_open */
711556Srgrimesstatic char *farray[2];			/* array for passing each arg to fts */
721556Srgrimesstatic FTREE *fthead = NULL;		/* head of linked list of file args */
731556Srgrimesstatic FTREE *fttail = NULL;		/* tail of linked list of file args */
741556Srgrimesstatic FTREE *ftcur = NULL;		/* current file arg being processed */
751556Srgrimesstatic FTSENT *ftent = NULL;		/* current file tree entry */
761556Srgrimesstatic int ftree_skip;			/* when set skip to next file arg */
771556Srgrimes
7890110Simpstatic int ftree_arg(void);
791556Srgrimes
801556Srgrimes/*
811556Srgrimes * ftree_start()
821556Srgrimes *	initialize the options passed to fts_open() during this run of pax
831556Srgrimes *	options are based on the selection of pax options by the user
841556Srgrimes *	fts_start() also calls fts_arg() to open the first valid file arg. We
851556Srgrimes *	also attempt to reset directory access times when -t (tflag) is set.
861556Srgrimes * Return:
871556Srgrimes *	0 if there is at least one valid file arg to process, -1 otherwise
881556Srgrimes */
891556Srgrimes
901556Srgrimesint
911556Srgrimesftree_start(void)
921556Srgrimes{
931556Srgrimes	/*
94100012Skeramida	 * Set up the operation mode of fts, open the first file arg. We must
951556Srgrimes	 * use FTS_NOCHDIR, as the user may have to open multiple archives and
961556Srgrimes	 * if fts did a chdir off into the boondocks, we may create an archive
97100012Skeramida	 * volume in a place where the user did not expect to.
981556Srgrimes	 */
991556Srgrimes	ftsopts = FTS_NOCHDIR;
1001556Srgrimes
1011556Srgrimes	/*
1021556Srgrimes	 * optional user flags that effect file traversal
1031556Srgrimes	 * -H command line symlink follow only (half follow)
104222177Suqs	 * -L follow symlinks (logical)
105222177Suqs	 * -P do not follow symlinks (physical). This is the default.
1061556Srgrimes	 * -X do not cross over mount points
1071556Srgrimes	 * -t preserve access times on files read.
1081556Srgrimes	 * -n select only the first member of a file tree when a match is found
1091556Srgrimes	 * -d do not extract subtrees rooted at a directory arg.
1101556Srgrimes	 */
1111556Srgrimes	if (Lflag)
1121556Srgrimes		ftsopts |= FTS_LOGICAL;
1131556Srgrimes	else
1141556Srgrimes		ftsopts |= FTS_PHYSICAL;
1151556Srgrimes	if (Hflag)
1161556Srgrimes#	ifdef NET2_FTS
11776017Skris		paxwarn(0, "The -H flag is not supported on this version");
1181556Srgrimes#	else
1191556Srgrimes		ftsopts |= FTS_COMFOLLOW;
1201556Srgrimes#	endif
1211556Srgrimes	if (Xflag)
1221556Srgrimes		ftsopts |= FTS_XDEV;
1231556Srgrimes
1241556Srgrimes	if ((fthead == NULL) && ((farray[0] = malloc(PAXPATHLEN+2)) == NULL)) {
12576017Skris		paxwarn(1, "Unable to allocate memory for file name buffer");
1261556Srgrimes		return(-1);
1271556Srgrimes	}
1281556Srgrimes
1291556Srgrimes	if (ftree_arg() < 0)
1301556Srgrimes		return(-1);
1311556Srgrimes	if (tflag && (atdir_start() < 0))
1321556Srgrimes		return(-1);
1331556Srgrimes	return(0);
1341556Srgrimes}
1351556Srgrimes
1361556Srgrimes/*
1371556Srgrimes * ftree_add()
1381556Srgrimes *	add the arg to the linked list of files to process. Each will be
1391556Srgrimes *	processed by fts one at a time
1401556Srgrimes * Return:
1411556Srgrimes *	0 if added to the linked list, -1 if failed
1421556Srgrimes */
1431556Srgrimes
1441556Srgrimesint
14590113Simpftree_add(char *str, int chflg)
1461556Srgrimes{
14790113Simp	FTREE *ft;
14890113Simp	int len;
1491556Srgrimes
1501556Srgrimes	/*
1511556Srgrimes	 * simple check for bad args
1521556Srgrimes	 */
1531556Srgrimes	if ((str == NULL) || (*str == '\0')) {
15476017Skris		paxwarn(0, "Invalid file name argument");
1551556Srgrimes		return(-1);
1561556Srgrimes	}
1571556Srgrimes
1581556Srgrimes	/*
1591556Srgrimes	 * allocate FTREE node and add to the end of the linked list (args are
1601556Srgrimes	 * processed in the same order they were passed to pax). Get rid of any
1611556Srgrimes	 * trailing / the user may pass us. (watch out for / by itself).
1621556Srgrimes	 */
1631556Srgrimes	if ((ft = (FTREE *)malloc(sizeof(FTREE))) == NULL) {
16476017Skris		paxwarn(0, "Unable to allocate memory for filename");
1651556Srgrimes		return(-1);
1661556Srgrimes	}
1671556Srgrimes
1681556Srgrimes	if (((len = strlen(str) - 1) > 0) && (str[len] == '/'))
1691556Srgrimes		str[len] = '\0';
1701556Srgrimes	ft->fname = str;
1711556Srgrimes	ft->refcnt = 0;
17276351Skris	ft->chflg = chflg;
1731556Srgrimes	ft->fow = NULL;
1741556Srgrimes	if (fthead == NULL) {
1751556Srgrimes		fttail = fthead = ft;
1761556Srgrimes		return(0);
1771556Srgrimes	}
1781556Srgrimes	fttail->fow = ft;
1791556Srgrimes	fttail = ft;
1801556Srgrimes	return(0);
1811556Srgrimes}
1821556Srgrimes
1831556Srgrimes/*
1841556Srgrimes * ftree_sel()
1851556Srgrimes *	this entry has been selected by pax. bump up reference count and handle
1861556Srgrimes *	-n and -d processing.
1871556Srgrimes */
1881556Srgrimes
1891556Srgrimesvoid
19090113Simpftree_sel(ARCHD *arcn)
1911556Srgrimes{
1921556Srgrimes	/*
1931556Srgrimes	 * set reference bit for this pattern. This linked list is only used
1941556Srgrimes	 * when file trees are supplied pax as args. The list is not used when
1951556Srgrimes	 * the trees are read from stdin.
1961556Srgrimes	 */
1978855Srgrimes	if (ftcur != NULL)
1981556Srgrimes		ftcur->refcnt = 1;
1991556Srgrimes
2001556Srgrimes	/*
2011556Srgrimes	 * if -n we are done with this arg, force a skip to the next arg when
2021556Srgrimes	 * pax asks for the next file in next_file().
2031556Srgrimes	 * if -d we tell fts only to match the directory (if the arg is a dir)
2041556Srgrimes	 * and not the entire file tree rooted at that point.
2051556Srgrimes	 */
2061556Srgrimes	if (nflag)
2071556Srgrimes		ftree_skip = 1;
2081556Srgrimes
2091556Srgrimes	if (!dflag || (arcn->type != PAX_DIR))
2101556Srgrimes		return;
2111556Srgrimes
2121556Srgrimes	if (ftent != NULL)
2131556Srgrimes		(void)fts_set(ftsp, ftent, FTS_SKIP);
2141556Srgrimes}
2151556Srgrimes
2161556Srgrimes/*
217140097Sbrian * ftree_notsel()
218140097Sbrian *	this entry has not been selected by pax.
219140097Sbrian */
220140097Sbrian
221140097Sbrianvoid
222201179Sedftree_notsel(void)
223140097Sbrian{
224140097Sbrian	if (ftent != NULL)
225140097Sbrian		(void)fts_set(ftsp, ftent, FTS_SKIP);
226140097Sbrian}
227140097Sbrian
228140097Sbrian/*
2291556Srgrimes * ftree_chk()
2301556Srgrimes *	called at end on pax execution. Prints all those file args that did not
2311556Srgrimes *	have a selected member (reference count still 0)
2321556Srgrimes */
2331556Srgrimes
2341556Srgrimesvoid
2351556Srgrimesftree_chk(void)
2361556Srgrimes{
23790113Simp	FTREE *ft;
23890113Simp	int wban = 0;
2391556Srgrimes
2401556Srgrimes	/*
2411556Srgrimes	 * make sure all dir access times were reset.
2421556Srgrimes	 */
2431556Srgrimes	if (tflag)
2441556Srgrimes		atdir_end();
2451556Srgrimes
2461556Srgrimes	/*
2471556Srgrimes	 * walk down list and check reference count. Print out those members
2481556Srgrimes	 * that never had a match
2491556Srgrimes	 */
2501556Srgrimes	for (ft = fthead; ft != NULL; ft = ft->fow) {
25176351Skris		if ((ft->refcnt > 0) || ft->chflg)
2521556Srgrimes			continue;
2531556Srgrimes		if (wban == 0) {
25476017Skris			paxwarn(1,"WARNING! These file names were not selected:");
2551556Srgrimes			++wban;
2561556Srgrimes		}
2571556Srgrimes		(void)fprintf(stderr, "%s\n", ft->fname);
2581556Srgrimes	}
2591556Srgrimes}
2601556Srgrimes
2611556Srgrimes/*
2621556Srgrimes * ftree_arg()
2631556Srgrimes *	Get the next file arg for fts to process. Can be from either the linked
2641556Srgrimes *	list or read from stdin when the user did not them as args to pax. Each
2651556Srgrimes *	arg is processed until the first successful fts_open().
2661556Srgrimes * Return:
2671556Srgrimes *	0 when the next arg is ready to go, -1 if out of file args (or EOF on
2681556Srgrimes *	stdin).
2691556Srgrimes */
2701556Srgrimes
2711556Srgrimesstatic int
2721556Srgrimesftree_arg(void)
2731556Srgrimes{
27490113Simp	char *pt;
2751556Srgrimes
2761556Srgrimes	/*
2771556Srgrimes	 * close off the current file tree
2781556Srgrimes	 */
2791556Srgrimes	if (ftsp != NULL) {
2801556Srgrimes		(void)fts_close(ftsp);
2811556Srgrimes		ftsp = NULL;
2821556Srgrimes	}
2831556Srgrimes
2841556Srgrimes	/*
2851556Srgrimes	 * keep looping until we get a valid file tree to process. Stop when we
2861556Srgrimes	 * reach the end of the list (or get an eof on stdin)
2871556Srgrimes	 */
2881556Srgrimes	for(;;) {
2891556Srgrimes		if (fthead == NULL) {
2901556Srgrimes			/*
2911556Srgrimes			 * the user didn't supply any args, get the file trees
2928855Srgrimes			 * to process from stdin;
2931556Srgrimes			 */
2941556Srgrimes			if (fgets(farray[0], PAXPATHLEN+1, stdin) == NULL)
2951556Srgrimes				return(-1);
2961556Srgrimes			if ((pt = strchr(farray[0], '\n')) != NULL)
2971556Srgrimes				*pt = '\0';
2981556Srgrimes		} else {
2991556Srgrimes			/*
30076017Skris			 * the user supplied the file args as arguments to pax
3011556Srgrimes			 */
3021556Srgrimes			if (ftcur == NULL)
3031556Srgrimes				ftcur = fthead;
3041556Srgrimes			else if ((ftcur = ftcur->fow) == NULL)
3051556Srgrimes				return(-1);
30676351Skris			if (ftcur->chflg) {
30776351Skris				/* First fchdir() back... */
30876351Skris				if (fchdir(cwdfd) < 0) {
30976351Skris					syswarn(1, errno,
31076351Skris					  "Can't fchdir to starting directory");
31176351Skris					return(-1);
31276351Skris				}
31376351Skris				if (chdir(ftcur->fname) < 0) {
31476351Skris					syswarn(1, errno, "Can't chdir to %s",
31576351Skris					    ftcur->fname);
31676351Skris					return(-1);
31776351Skris				}
31876351Skris				continue;
31976351Skris			} else
32076351Skris				farray[0] = ftcur->fname;
3211556Srgrimes		}
3221556Srgrimes
3231556Srgrimes		/*
324108533Sschweikh		 * Watch it, fts wants the file arg stored in an array of char
325108533Sschweikh		 * ptrs, with the last one a null. We use a two element array
3261556Srgrimes		 * and set farray[0] to point at the buffer with the file name
32746684Skris		 * in it. We cannot pass all the file args to fts at one shot
3281556Srgrimes		 * as we need to keep a handle on which file arg generates what
3291556Srgrimes		 * files (the -n and -d flags need this). If the open is
3301556Srgrimes		 * successful, return a 0.
3311556Srgrimes		 */
3321556Srgrimes		if ((ftsp = fts_open(farray, ftsopts, NULL)) != NULL)
3331556Srgrimes			break;
3341556Srgrimes	}
3351556Srgrimes	return(0);
3361556Srgrimes}
3371556Srgrimes
3381556Srgrimes/*
3391556Srgrimes * next_file()
3401556Srgrimes *	supplies the next file to process in the supplied archd structure.
3411556Srgrimes * Return:
3421556Srgrimes *	0 when contents of arcn have been set with the next file, -1 when done.
3431556Srgrimes */
3441556Srgrimes
3451556Srgrimesint
34690113Simpnext_file(ARCHD *arcn)
3471556Srgrimes{
34890113Simp	int cnt;
3491556Srgrimes	time_t atime;
3501556Srgrimes	time_t mtime;
3511556Srgrimes
3521556Srgrimes	/*
3531556Srgrimes	 * ftree_sel() might have set the ftree_skip flag if the user has the
3541556Srgrimes	 * -n option and a file was selected from this file arg tree. (-n says
3558855Srgrimes	 * only one member is matched for each pattern) ftree_skip being 1
3561556Srgrimes	 * forces us to go to the next arg now.
3571556Srgrimes	 */
3581556Srgrimes	if (ftree_skip) {
3591556Srgrimes		/*
3601556Srgrimes		 * clear and go to next arg
3611556Srgrimes		 */
3621556Srgrimes		ftree_skip = 0;
3631556Srgrimes		if (ftree_arg() < 0)
3641556Srgrimes			return(-1);
3651556Srgrimes	}
3661556Srgrimes
3671556Srgrimes	/*
3681556Srgrimes	 * loop until we get a valid file to process
3691556Srgrimes	 */
3701556Srgrimes	for(;;) {
3711556Srgrimes		if ((ftent = fts_read(ftsp)) == NULL) {
3721556Srgrimes			/*
3731556Srgrimes			 * out of files in this tree, go to next arg, if none
3741556Srgrimes			 * we are done
3751556Srgrimes			 */
3761556Srgrimes			if (ftree_arg() < 0)
3771556Srgrimes				return(-1);
3781556Srgrimes			continue;
3791556Srgrimes		}
3801556Srgrimes
3811556Srgrimes		/*
3821556Srgrimes		 * handle each type of fts_read() flag
3831556Srgrimes		 */
3841556Srgrimes		switch(ftent->fts_info) {
3851556Srgrimes		case FTS_D:
3861556Srgrimes		case FTS_DEFAULT:
3871556Srgrimes		case FTS_F:
3881556Srgrimes		case FTS_SL:
3891556Srgrimes		case FTS_SLNONE:
3901556Srgrimes			/*
3911556Srgrimes			 * these are all ok
3921556Srgrimes			 */
3931556Srgrimes			break;
3941556Srgrimes		case FTS_DP:
3951556Srgrimes			/*
3961556Srgrimes			 * already saw this directory. If the user wants file
3971556Srgrimes			 * access times reset, we use this to restore the
3981556Srgrimes			 * access time for this directory since this is the
3991556Srgrimes			 * last time we will see it in this file subtree
4001556Srgrimes			 * remember to force the time (this is -t on a read
4011556Srgrimes			 * directory, not a created directory).
4021556Srgrimes			 */
4031556Srgrimes#			ifdef NET2_FTS
4041556Srgrimes			if (!tflag || (get_atdir(ftent->fts_statb.st_dev,
4051556Srgrimes			    ftent->fts_statb.st_ino, &mtime, &atime) < 0))
4061556Srgrimes#			else
4071556Srgrimes			if (!tflag || (get_atdir(ftent->fts_statp->st_dev,
4081556Srgrimes			    ftent->fts_statp->st_ino, &mtime, &atime) < 0))
4091556Srgrimes#			endif
4101556Srgrimes				continue;
4111556Srgrimes			set_ftime(ftent->fts_path, mtime, atime, 1);
4121556Srgrimes			continue;
4131556Srgrimes		case FTS_DC:
4141556Srgrimes			/*
415102230Strhodes			 * fts claims a file system cycle
4161556Srgrimes			 */
41776017Skris			paxwarn(1,"File system cycle found at %s",ftent->fts_path);
4181556Srgrimes			continue;
4191556Srgrimes		case FTS_DNR:
4201556Srgrimes#			ifdef NET2_FTS
42176017Skris			syswarn(1, errno,
4221556Srgrimes#			else
42376017Skris			syswarn(1, ftent->fts_errno,
4241556Srgrimes#			endif
4251556Srgrimes			    "Unable to read directory %s", ftent->fts_path);
4261556Srgrimes			continue;
4271556Srgrimes		case FTS_ERR:
4281556Srgrimes#			ifdef NET2_FTS
42976017Skris			syswarn(1, errno,
4301556Srgrimes#			else
43176017Skris			syswarn(1, ftent->fts_errno,
4321556Srgrimes#			endif
4331556Srgrimes			    "File system traversal error");
4341556Srgrimes			continue;
4351556Srgrimes		case FTS_NS:
4361556Srgrimes		case FTS_NSOK:
4371556Srgrimes#			ifdef NET2_FTS
43876017Skris			syswarn(1, errno,
4391556Srgrimes#			else
44076017Skris			syswarn(1, ftent->fts_errno,
4411556Srgrimes#			endif
4421556Srgrimes			    "Unable to access %s", ftent->fts_path);
4431556Srgrimes			continue;
4441556Srgrimes		}
4451556Srgrimes
4461556Srgrimes		/*
4471556Srgrimes		 * ok got a file tree node to process. copy info into arcn
4481556Srgrimes		 * structure (initialize as required)
4491556Srgrimes		 */
4501556Srgrimes		arcn->skip = 0;
4511556Srgrimes		arcn->pad = 0;
4521556Srgrimes		arcn->ln_nlen = 0;
4531556Srgrimes		arcn->ln_name[0] = '\0';
4541556Srgrimes#		ifdef NET2_FTS
4551556Srgrimes		arcn->sb = ftent->fts_statb;
4561556Srgrimes#		else
4571556Srgrimes		arcn->sb = *(ftent->fts_statp);
4581556Srgrimes#		endif
4591556Srgrimes
4601556Srgrimes		/*
4611556Srgrimes		 * file type based set up and copy into the arcn struct
4621556Srgrimes		 * SIDE NOTE:
4631556Srgrimes		 * we try to reset the access time on all files and directories
4641556Srgrimes		 * we may read when the -t flag is specified. files are reset
4651556Srgrimes		 * when we close them after copying. we reset the directories
4661556Srgrimes		 * when we are done with their file tree (we also clean up at
4671556Srgrimes		 * end in case we cut short a file tree traversal). However
4681556Srgrimes		 * there is no way to reset access times on symlinks.
4691556Srgrimes		 */
4701556Srgrimes		switch(S_IFMT & arcn->sb.st_mode) {
4711556Srgrimes		case S_IFDIR:
4721556Srgrimes			arcn->type = PAX_DIR;
4731556Srgrimes			if (!tflag)
4741556Srgrimes				break;
4751556Srgrimes			add_atdir(ftent->fts_path, arcn->sb.st_dev,
4761556Srgrimes			    arcn->sb.st_ino, arcn->sb.st_mtime,
4771556Srgrimes			    arcn->sb.st_atime);
4781556Srgrimes			break;
4791556Srgrimes		case S_IFCHR:
4801556Srgrimes			arcn->type = PAX_CHR;
4811556Srgrimes			break;
4821556Srgrimes		case S_IFBLK:
4831556Srgrimes			arcn->type = PAX_BLK;
4841556Srgrimes			break;
4851556Srgrimes		case S_IFREG:
4861556Srgrimes			/*
4871556Srgrimes			 * only regular files with have data to store on the
4881556Srgrimes			 * archive. all others will store a zero length skip.
4891556Srgrimes			 * the skip field is used by pax for actual data it has
4901556Srgrimes			 * to read (or skip over).
4911556Srgrimes			 */
4921556Srgrimes			arcn->type = PAX_REG;
4931556Srgrimes			arcn->skip = arcn->sb.st_size;
4941556Srgrimes			break;
4951556Srgrimes		case S_IFLNK:
4961556Srgrimes			arcn->type = PAX_SLK;
4971556Srgrimes			/*
4981556Srgrimes			 * have to read the symlink path from the file
4991556Srgrimes			 */
5001556Srgrimes			if ((cnt = readlink(ftent->fts_path, arcn->ln_name,
50136784Simp			    PAXPATHLEN - 1)) < 0) {
50276017Skris				syswarn(1, errno, "Unable to read symlink %s",
5031556Srgrimes				    ftent->fts_path);
5041556Srgrimes				continue;
5051556Srgrimes			}
5061556Srgrimes			/*
5071556Srgrimes			 * set link name length, watch out readlink does not
50846684Skris			 * always NUL terminate the link path
5091556Srgrimes			 */
5101556Srgrimes			arcn->ln_name[cnt] = '\0';
5111556Srgrimes			arcn->ln_nlen = cnt;
5121556Srgrimes			break;
5131556Srgrimes		case S_IFSOCK:
5141556Srgrimes			/*
5151556Srgrimes			 * under BSD storing a socket is senseless but we will
5161556Srgrimes			 * let the format specific write function make the
5171556Srgrimes			 * decision of what to do with it.
5181556Srgrimes			 */
5191556Srgrimes			arcn->type = PAX_SCK;
5201556Srgrimes			break;
5211556Srgrimes		case S_IFIFO:
5221556Srgrimes			arcn->type = PAX_FIF;
5231556Srgrimes			break;
5241556Srgrimes		}
5251556Srgrimes		break;
5261556Srgrimes	}
5271556Srgrimes
5281556Srgrimes	/*
5291556Srgrimes	 * copy file name, set file name length
5301556Srgrimes	 */
53176351Skris	arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, sizeof(arcn->name) - 1);
5321556Srgrimes	arcn->name[arcn->nlen] = '\0';
5331556Srgrimes	arcn->org_name = ftent->fts_path;
5341556Srgrimes	return(0);
5351556Srgrimes}
536