ftree.c revision 1.16 1 /* $NetBSD: ftree.c,v 1.16 2002/01/29 10:20:29 tv Exp $ */
2
3 /*-
4 * Copyright (c) 1992 Keith Muller.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Keith Muller of the University of California, San Diego.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 */
39
40 /*-
41 * Copyright (c) 2001 The NetBSD Foundation, Inc.
42 * All rights reserved.
43 *
44 * This code is derived from software contributed to The NetBSD Foundation
45 * by Luke Mewburn of Wasabi Systems.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by the NetBSD
58 * Foundation, Inc. and its contributors.
59 * 4. Neither the name of The NetBSD Foundation nor the names of its
60 * contributors may be used to endorse or promote products derived
61 * from this software without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
64 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
65 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
66 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
67 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
68 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
69 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
70 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
71 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
72 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
73 * POSSIBILITY OF SUCH DAMAGE.
74 */
75
76 #include <sys/cdefs.h>
77 #ifndef lint
78 #if 0
79 static char sccsid[] = "@(#)ftree.c 8.2 (Berkeley) 4/18/94";
80 #else
81 __RCSID("$NetBSD: ftree.c,v 1.16 2002/01/29 10:20:29 tv Exp $");
82 #endif
83 #endif /* not lint */
84
85 #include <sys/types.h>
86 #include <sys/time.h>
87 #include <sys/stat.h>
88 #include <sys/param.h>
89 #include <unistd.h>
90 #include <string.h>
91 #include <stdio.h>
92 #include <ctype.h>
93 #include <errno.h>
94 #include <stdlib.h>
95 #include "pax.h"
96 #include "ftree.h"
97 #include "extern.h"
98 #include "mtree.h"
99
100 #if HAVE_FTS_H
101 #include <fts.h>
102 #endif
103
104 /*
105 * routines to interface with the fts library function.
106 *
107 * file args supplied to pax are stored on a single linked list (of type FTREE)
108 * and given to fts to be processed one at a time. pax "selects" files from
109 * the expansion of each arg into the corresponding file tree (if the arg is a
110 * directory, otherwise the node itself is just passed to pax). The selection
111 * is modified by the -n and -u flags. The user is informed when a specific
112 * file arg does not generate any selected files. -n keeps expanding the file
113 * tree arg until one of its files is selected, then skips to the next file
114 * arg. when the user does not supply the file trees as command line args to
115 * pax, they are read from stdin
116 */
117
118 static FTS *ftsp = NULL; /* current FTS handle */
119 static int ftsopts; /* options to be used on fts_open */
120 static char *farray[2]; /* array for passing each arg to fts */
121 static FTREE *fthead = NULL; /* head of linked list of file args */
122 static FTREE *fttail = NULL; /* tail of linked list of file args */
123 static FTREE *ftcur = NULL; /* current file arg being processed */
124 static FTSENT *ftent = NULL; /* current file tree entry */
125 static int ftree_skip; /* when set skip to next file arg */
126 static NODE *ftnode = NULL; /* mtree(8) specfile; used by -M */
127
128 static int ftree_arg(void);
129
130 #ifdef NET2_FTS
131 #define FTS_ERRNO(x) errno
132 #else
133 #define FTS_ERRNO(x) (x)->fts_errno
134 #endif
135
136 /*
137 * ftree_start()
138 * initialize the options passed to fts_open() during this run of pax
139 * options are based on the selection of pax options by the user
140 * fts_start() also calls fts_arg() to open the first valid file arg. We
141 * also attempt to reset directory access times when -t (tflag) is set.
142 * Return:
143 * 0 if there is at least one valid file arg to process, -1 otherwise
144 */
145
146 int
147 ftree_start(void)
148 {
149
150 /*
151 * if -M is given, the list of filenames on stdin is actually
152 * an mtree(8) specfile, so parse the specfile into a NODE *
153 * tree at ftnode, for use by next_file()
154 */
155 if (Mflag) {
156 if (fthead != NULL) {
157 tty_warn(1,
158 "The -M flag is only supported when reading file list from stdin");
159 return(-1);
160 }
161 ftnode = spec(stdin);
162 if (ftnode != NULL &&
163 (ftnode->type != F_DIR || strcmp(ftnode->name, ".") != 0)) {
164 tty_warn(1,
165 "First node of specfile is not `.' directory");
166 return(-1);
167 }
168 return(0);
169 }
170
171 /*
172 * set up the operation mode of fts, open the first file arg. We must
173 * use FTS_NOCHDIR, as the user may have to open multiple archives and
174 * if fts did a chdir off into the boondocks, we may create an archive
175 * volume in an place where the user did not expect to.
176 */
177 ftsopts = FTS_NOCHDIR;
178
179 /*
180 * optional user flags that effect file traversal
181 * -H command line symlink follow only (half follow)
182 * -L follow sylinks (logical)
183 * -P do not follow sylinks (physical). This is the default.
184 * -X do not cross over mount points
185 * -t preserve access times on files read.
186 * -n select only the first member of a file tree when a match is found
187 * -d do not extract subtrees rooted at a directory arg.
188 */
189 if (Lflag)
190 ftsopts |= FTS_LOGICAL;
191 else
192 ftsopts |= FTS_PHYSICAL;
193 if (Hflag)
194 #ifdef NET2_FTS
195 tty_warn(0, "The -H flag is not supported on this version");
196 #else
197 ftsopts |= FTS_COMFOLLOW;
198 #endif
199 if (Xflag)
200 ftsopts |= FTS_XDEV;
201
202 if ((fthead == NULL) && ((farray[0] = malloc(PAXPATHLEN+2)) == NULL)) {
203 tty_warn(1, "Unable to allocate memory for file name buffer");
204 return(-1);
205 }
206
207 if (ftree_arg() < 0)
208 return(-1);
209 if (tflag && (atdir_start() < 0))
210 return(-1);
211 return(0);
212 }
213
214 /*
215 * ftree_add()
216 * add the arg to the linked list of files to process. Each will be
217 * processed by fts one at a time
218 * Return:
219 * 0 if added to the linked list, -1 if failed
220 */
221
222 int
223 ftree_add(char *str, int isdir)
224 {
225 FTREE *ft;
226 int len;
227
228 /*
229 * simple check for bad args
230 */
231 if ((str == NULL) || (*str == '\0')) {
232 tty_warn(0, "Invalid file name arguement");
233 return(-1);
234 }
235
236 /*
237 * allocate FTREE node and add to the end of the linked list (args are
238 * processed in the same order they were passed to pax). Get rid of any
239 * trailing / the user may pass us. (watch out for / by itself).
240 */
241 if ((ft = (FTREE *)malloc(sizeof(FTREE))) == NULL) {
242 tty_warn(0, "Unable to allocate memory for filename");
243 return(-1);
244 }
245
246 if (((len = strlen(str) - 1) > 0) && (str[len] == '/'))
247 str[len] = '\0';
248 ft->fname = str;
249 ft->refcnt = -isdir;
250 ft->fow = NULL;
251 if (fthead == NULL) {
252 fttail = fthead = ft;
253 return(0);
254 }
255 fttail->fow = ft;
256 fttail = ft;
257 return(0);
258 }
259
260 /*
261 * ftree_sel()
262 * this entry has been selected by pax. bump up reference count and handle
263 * -n and -d processing.
264 */
265
266 void
267 ftree_sel(ARCHD *arcn)
268 {
269 /*
270 * set reference bit for this pattern. This linked list is only used
271 * when file trees are supplied pax as args. The list is not used when
272 * the trees are read from stdin.
273 */
274 if (ftcur != NULL)
275 ftcur->refcnt = 1;
276
277 /*
278 * if -n we are done with this arg, force a skip to the next arg when
279 * pax asks for the next file in next_file().
280 * if -M we don't use fts(3), so the rest of this function is moot.
281 * if -d we tell fts only to match the directory (if the arg is a dir)
282 * and not the entire file tree rooted at that point.
283 */
284 if (nflag)
285 ftree_skip = 1;
286
287 if (Mflag || !dflag || (arcn->type != PAX_DIR))
288 return;
289
290 if (ftent != NULL)
291 (void)fts_set(ftsp, ftent, FTS_SKIP);
292 }
293
294 /*
295 * ftree_chk()
296 * called at end on pax execution. Prints all those file args that did not
297 * have a selected member (reference count still 0)
298 */
299
300 void
301 ftree_chk(void)
302 {
303 FTREE *ft;
304 int wban = 0;
305
306 /*
307 * make sure all dir access times were reset.
308 */
309 if (tflag)
310 atdir_end();
311
312 /*
313 * walk down list and check reference count. Print out those members
314 * that never had a match
315 */
316 for (ft = fthead; ft != NULL; ft = ft->fow) {
317 if (ft->refcnt != 0)
318 continue;
319 if (wban == 0) {
320 tty_warn(1,
321 "WARNING! These file names were not selected:");
322 ++wban;
323 }
324 (void)fprintf(stderr, "%s\n", ft->fname);
325 }
326 }
327
328 /*
329 * ftree_arg()
330 * Get the next file arg for fts to process. Can be from either the linked
331 * list or read from stdin when the user did not them as args to pax. Each
332 * arg is processed until the first successful fts_open().
333 * Return:
334 * 0 when the next arg is ready to go, -1 if out of file args (or EOF on
335 * stdin).
336 */
337
338 static int
339 ftree_arg(void)
340 {
341 char *pt;
342
343 /*
344 * close off the current file tree
345 */
346 if (ftsp != NULL) {
347 (void)fts_close(ftsp);
348 ftsp = NULL;
349 }
350
351 /*
352 * keep looping until we get a valid file tree to process. Stop when we
353 * reach the end of the list (or get an eof on stdin)
354 */
355 for(;;) {
356 if (fthead == NULL) {
357 /*
358 * the user didn't supply any args, get the file trees
359 * to process from stdin;
360 */
361 if (fgets(farray[0], PAXPATHLEN+1, stdin) == NULL)
362 return(-1);
363 if ((pt = strchr(farray[0], '\n')) != NULL)
364 *pt = '\0';
365 } else {
366 /*
367 * the user supplied the file args as arguements to pax
368 */
369 if (ftcur == NULL)
370 ftcur = fthead;
371 else if ((ftcur = ftcur->fow) == NULL)
372 return(-1);
373
374 if (ftcur->refcnt < 0) {
375 /*
376 * chdir entry.
377 * Change directory and retry loop.
378 */
379 if (ar_dochdir(ftcur->fname))
380 return (-1);
381 continue;
382 }
383 farray[0] = ftcur->fname;
384 }
385
386 /*
387 * watch it, fts wants the file arg stored in a array of char
388 * ptrs, with the last one a null. we use a two element array
389 * and set farray[0] to point at the buffer with the file name
390 * in it. We cannot pass all the file args to fts at one shot
391 * as we need to keep a handle on which file arg generates what
392 * files (the -n and -d flags need this). If the open is
393 * successful, return a 0.
394 */
395 if ((ftsp = fts_open(farray, ftsopts, NULL)) != NULL)
396 break;
397 }
398 return(0);
399 }
400
401 /*
402 * next_file()
403 * supplies the next file to process in the supplied archd structure.
404 * Return:
405 * 0 when contents of arcn have been set with the next file, -1 when done.
406 */
407
408 int
409 next_file(ARCHD *arcn)
410 {
411 static char curdir[PAXPATHLEN+2], curpath[PAXPATHLEN+2];
412 static int curdirlen;
413
414 struct stat statbuf;
415 FTSENT Mftent;
416 int cnt;
417 time_t atime, mtime;
418 char *curlink;
419 #define MFTENT_DUMMY_DEV UINT_MAX
420
421 curlink = NULL;
422 /*
423 * if parsing an mtree(8) specfile, build up `dummy' ftsent
424 * from specfile info, and jump below to complete setup of arcn.
425 */
426 if (Mflag) {
427 if (ftnode == NULL) /* tree is empty */
428 return (-1);
429
430 /* get current name */
431 if (snprintf(curpath, sizeof(curpath), "%s%s%s",
432 curdir, curdirlen ? "/" : "", ftnode->name)
433 >= sizeof(curpath)) {
434 tty_warn(1, "line %lu: %s: %s", (u_long)ftnode->lineno,
435 curdir, strerror(ENAMETOOLONG));
436 return (-1);
437 }
438 ftnode->flags |= F_VISIT; /* mark node visited */
439
440 /* construct dummy FTSENT */
441 Mftent.fts_path = curpath;
442 Mftent.fts_statp = &statbuf;
443 Mftent.fts_pointer = ftnode;
444 ftent = &Mftent;
445 /* stat existing file */
446 if (lstat(Mftent.fts_path, &statbuf) == -1) {
447 /* fake up stat buffer */
448 memset(&statbuf, 0, sizeof(statbuf));
449 statbuf.st_dev = MFTENT_DUMMY_DEV;
450 statbuf.st_ino = ftnode->lineno;
451 statbuf.st_size = 0;
452 #define NODETEST(t, m) \
453 if (!(t)) { \
454 tty_warn(1, "line %lu: %s: %s not specified", \
455 (u_long)ftnode->lineno, \
456 ftent->fts_path, m); \
457 return(-1); \
458 }
459 statbuf.st_mode = nodetoino(ftnode->type);
460 NODETEST(ftnode->flags & F_TYPE, "type");
461 NODETEST(ftnode->flags & F_MODE, "mode");
462 if (!(ftnode->flags & F_TIME))
463 statbuf.st_mtime = starttime;
464 NODETEST(ftnode->flags & (F_GID | F_GNAME), "group");
465 NODETEST(ftnode->flags & (F_UID | F_UNAME), "user");
466 if (ftnode->type == F_BLOCK || ftnode->type == F_CHAR)
467 NODETEST(ftnode->flags & F_DEV,
468 "device number");
469 if (ftnode->type == F_LINK)
470 NODETEST(ftnode->flags & F_SLINK, "symlink");
471 /* don't require F_FLAGS or F_SIZE */
472 #undef NODETEST
473 } else if (ftnode->flags & F_TYPE &&
474 nodetoino(ftnode->type) != (statbuf.st_mode & S_IFMT)) {
475 tty_warn(1,
476 "line %lu: %s: type mismatch: specfile %s, tree %s",
477 (u_long)ftnode->lineno, ftent->fts_path,
478 inotype(nodetoino(ftnode->type)),
479 inotype(statbuf.st_mode));
480 return(-1);
481 }
482 /*
483 * override settings with those from specfile
484 */
485 if (ftnode->flags & F_MODE) {
486 statbuf.st_mode &= ~ALLPERMS;
487 statbuf.st_mode |= (ftnode->st_mode & ALLPERMS);
488 }
489 if (ftnode->flags & (F_GID | F_GNAME))
490 statbuf.st_gid = ftnode->st_gid;
491 if (ftnode->flags & (F_UID | F_UNAME))
492 statbuf.st_uid = ftnode->st_uid;
493 #if HAVE_STRUCT_STAT_ST_FLAGS
494 if (ftnode->flags & F_FLAGS)
495 statbuf.st_flags = ftnode->st_flags;
496 #endif
497 if (ftnode->flags & F_TIME)
498 #ifdef BSD4_4
499 statbuf.st_mtimespec = ftnode->st_mtimespec;
500 #else
501 statbuf.st_mtime = ftnode->st_mtimespec.tv_sec;
502 #endif
503 if (ftnode->flags & F_DEV)
504 statbuf.st_rdev = ftnode->st_rdev;
505 if (ftnode->flags & F_SLINK)
506 curlink = ftnode->slink;
507 /* ignore F_SIZE */
508
509 /*
510 * find next node
511 */
512 if (ftnode->type == F_DIR && ftnode->child != NULL) {
513 /* directory with unseen child */
514 ftnode = ftnode->child;
515 curdirlen = l_strncpy(curdir, curpath, sizeof(curdir));
516 } else do {
517 if (ftnode->next != NULL) {
518 /* next node at current level */
519 ftnode = ftnode->next;
520 } else { /* move back to parent */
521 /* reset time only on first cd.. */
522 if (Mftent.fts_pointer == ftnode && tflag &&
523 (get_atdir(MFTENT_DUMMY_DEV, ftnode->lineno,
524 &mtime, &atime) == 0)) {
525 set_ftime(ftent->fts_path,
526 mtime, atime, 1);
527 }
528 if (ftnode->parent == ftnode)
529 ftnode = NULL;
530 else
531 ftnode = ftnode->parent;
532 if (ftnode != NULL) {
533 curdirlen -= strlen(ftnode->name) + 1;
534 curdir[curdirlen] = '\0';
535 }
536 }
537 } while (ftnode != NULL && ftnode->flags & F_VISIT);
538 goto got_ftent;
539 }
540
541 /*
542 * ftree_sel() might have set the ftree_skip flag if the user has the
543 * -n option and a file was selected from this file arg tree. (-n says
544 * only one member is matched for each pattern) ftree_skip being 1
545 * forces us to go to the next arg now.
546 */
547 if (ftree_skip) {
548 /*
549 * clear and go to next arg
550 */
551 ftree_skip = 0;
552 if (ftree_arg() < 0)
553 return(-1);
554 }
555
556 /*
557 * loop until we get a valid file to process
558 */
559 for(;;) {
560 if ((ftent = fts_read(ftsp)) == NULL) {
561 /*
562 * out of files in this tree, go to next arg, if none
563 * we are done
564 */
565 if (ftree_arg() < 0)
566 return(-1);
567 continue;
568 }
569
570 /*
571 * handle each type of fts_read() flag
572 */
573 switch(ftent->fts_info) {
574 case FTS_D:
575 /*
576 * cpio does *not* decend directories listed in the
577 * arguments, unlike pax/tar, so needs special handling
578 * here. failure to do so results in massive amounts
579 * of duplicated files in the output.
580 */
581 if (cpio_mode)
582 continue;
583 /* FALLTHROUGH */
584 case FTS_DEFAULT:
585 case FTS_F:
586 case FTS_SL:
587 case FTS_SLNONE:
588 /*
589 * these are all ok
590 */
591 break;
592 case FTS_DP:
593 /*
594 * already saw this directory. If the user wants file
595 * access times reset, we use this to restore the
596 * access time for this directory since this is the
597 * last time we will see it in this file subtree
598 * remember to force the time (this is -t on a read
599 * directory, not a created directory).
600 */
601 if (!tflag || (get_atdir(
602 #ifdef NET2_FTS
603 ftent->fts_statb.st_dev, ftent->fts_statb.st_ino,
604 #else
605 ftent->fts_statp->st_dev, ftent->fts_statp->st_ino,
606 #endif
607 &mtime, &atime) < 0))
608 continue;
609 set_ftime(ftent->fts_path, mtime, atime, 1);
610 continue;
611 case FTS_DC:
612 /*
613 * fts claims a file system cycle
614 */
615 tty_warn(1,"File system cycle found at %s",
616 ftent->fts_path);
617 continue;
618 case FTS_DNR:
619 syswarn(1, FTS_ERRNO(ftent),
620 "Unable to read directory %s", ftent->fts_path);
621 continue;
622 case FTS_ERR:
623 syswarn(1, FTS_ERRNO(ftent),
624 "File system traversal error");
625 continue;
626 case FTS_NS:
627 case FTS_NSOK:
628 syswarn(1, FTS_ERRNO(ftent),
629 "Unable to access %s", ftent->fts_path);
630 continue;
631 }
632
633 got_ftent:
634 /*
635 * ok got a file tree node to process. copy info into arcn
636 * structure (initialize as required)
637 */
638 arcn->skip = 0;
639 arcn->pad = 0;
640 arcn->ln_nlen = 0;
641 arcn->ln_name[0] = '\0';
642 #ifdef NET2_FTS
643 arcn->sb = ftent->fts_statb;
644 #else
645 arcn->sb = *(ftent->fts_statp);
646 #endif
647
648 /*
649 * file type based set up and copy into the arcn struct
650 * SIDE NOTE:
651 * we try to reset the access time on all files and directories
652 * we may read when the -t flag is specified. files are reset
653 * when we close them after copying. we reset the directories
654 * when we are done with their file tree (we also clean up at
655 * end in case we cut short a file tree traversal). However
656 * there is no way to reset access times on symlinks.
657 */
658 switch(S_IFMT & arcn->sb.st_mode) {
659 case S_IFDIR:
660 arcn->type = PAX_DIR;
661 if (!tflag)
662 break;
663 add_atdir(ftent->fts_path, arcn->sb.st_dev,
664 arcn->sb.st_ino, arcn->sb.st_mtime,
665 arcn->sb.st_atime);
666 break;
667 case S_IFCHR:
668 arcn->type = PAX_CHR;
669 break;
670 case S_IFBLK:
671 arcn->type = PAX_BLK;
672 break;
673 case S_IFREG:
674 /*
675 * only regular files with have data to store on the
676 * archive. all others will store a zero length skip.
677 * the skip field is used by pax for actual data it has
678 * to read (or skip over).
679 */
680 arcn->type = PAX_REG;
681 arcn->skip = arcn->sb.st_size;
682 break;
683 case S_IFLNK:
684 arcn->type = PAX_SLK;
685 if (curlink != NULL) {
686 cnt = l_strncpy(arcn->ln_name, curlink,
687 sizeof(arcn->ln_name));
688 /*
689 * have to read the symlink path from the file
690 */
691 } else if ((cnt =
692 readlink(ftent->fts_path, arcn->ln_name,
693 PAXPATHLEN)) < 0) {
694 syswarn(1, errno, "Unable to read symlink %s",
695 ftent->fts_path);
696 continue;
697 }
698 /*
699 * set link name length, watch out readlink does not
700 * allways null terminate the link path
701 */
702 arcn->ln_name[cnt] = '\0';
703 arcn->ln_nlen = cnt;
704 break;
705 case S_IFSOCK:
706 /*
707 * under BSD storing a socket is senseless but we will
708 * let the format specific write function make the
709 * decision of what to do with it.
710 */
711 arcn->type = PAX_SCK;
712 break;
713 case S_IFIFO:
714 arcn->type = PAX_FIF;
715 break;
716 }
717 break;
718 }
719
720 /*
721 * copy file name, set file name length
722 */
723 arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, PAXPATHLEN+1);
724 arcn->name[arcn->nlen] = '\0';
725 arcn->org_name = ftent->fts_path;
726 return(0);
727 }
728