ftree.c revision 1.1 1 1.1 jtc /*-
2 1.1 jtc * Copyright (c) 1992 Keith Muller.
3 1.1 jtc * Copyright (c) 1992, 1993
4 1.1 jtc * The Regents of the University of California. All rights reserved.
5 1.1 jtc *
6 1.1 jtc * This code is derived from software contributed to Berkeley by
7 1.1 jtc * Keith Muller of the University of California, San Diego.
8 1.1 jtc *
9 1.1 jtc * Redistribution and use in source and binary forms, with or without
10 1.1 jtc * modification, are permitted provided that the following conditions
11 1.1 jtc * are met:
12 1.1 jtc * 1. Redistributions of source code must retain the above copyright
13 1.1 jtc * notice, this list of conditions and the following disclaimer.
14 1.1 jtc * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 jtc * notice, this list of conditions and the following disclaimer in the
16 1.1 jtc * documentation and/or other materials provided with the distribution.
17 1.1 jtc * 3. All advertising materials mentioning features or use of this software
18 1.1 jtc * must display the following acknowledgement:
19 1.1 jtc * This product includes software developed by the University of
20 1.1 jtc * California, Berkeley and its contributors.
21 1.1 jtc * 4. Neither the name of the University nor the names of its contributors
22 1.1 jtc * may be used to endorse or promote products derived from this software
23 1.1 jtc * without specific prior written permission.
24 1.1 jtc *
25 1.1 jtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 jtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 jtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 jtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 jtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 jtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 jtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 jtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 jtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 jtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 jtc * SUCH DAMAGE.
36 1.1 jtc */
37 1.1 jtc
38 1.1 jtc #ifndef lint
39 1.1 jtc static char sccsid[] = "@(#)ftree.c 8.2 (Berkeley) 4/18/94";
40 1.1 jtc #endif /* not lint */
41 1.1 jtc
42 1.1 jtc #include <sys/types.h>
43 1.1 jtc #include <sys/time.h>
44 1.1 jtc #include <sys/stat.h>
45 1.1 jtc #include <sys/param.h>
46 1.1 jtc #include <unistd.h>
47 1.1 jtc #include <string.h>
48 1.1 jtc #include <stdio.h>
49 1.1 jtc #include <ctype.h>
50 1.1 jtc #include <errno.h>
51 1.1 jtc #include <stdlib.h>
52 1.1 jtc #include <fts.h>
53 1.1 jtc #include "pax.h"
54 1.1 jtc #include "ftree.h"
55 1.1 jtc #include "extern.h"
56 1.1 jtc
57 1.1 jtc /*
58 1.1 jtc * routines to interface with the fts library function.
59 1.1 jtc *
60 1.1 jtc * file args supplied to pax are stored on a single linked list (of type FTREE)
61 1.1 jtc * and given to fts to be processed one at a time. pax "selects" files from
62 1.1 jtc * the expansion of each arg into the corresponding file tree (if the arg is a
63 1.1 jtc * directory, otherwise the node itself is just passed to pax). The selection
64 1.1 jtc * is modified by the -n and -u flags. The user is informed when a specific
65 1.1 jtc * file arg does not generate any selected files. -n keeps expanding the file
66 1.1 jtc * tree arg until one of its files is selected, then skips to the next file
67 1.1 jtc * arg. when the user does not supply the file trees as command line args to
68 1.1 jtc * pax, they are read from stdin
69 1.1 jtc */
70 1.1 jtc
71 1.1 jtc static FTS *ftsp = NULL; /* curent FTS handle */
72 1.1 jtc static int ftsopts; /* options to be used on fts_open */
73 1.1 jtc static char *farray[2]; /* array for passing each arg to fts */
74 1.1 jtc static FTREE *fthead = NULL; /* head of linked list of file args */
75 1.1 jtc static FTREE *fttail = NULL; /* tail of linked list of file args */
76 1.1 jtc static FTREE *ftcur = NULL; /* current file arg being processed */
77 1.1 jtc static FTSENT *ftent = NULL; /* current file tree entry */
78 1.1 jtc static int ftree_skip; /* when set skip to next file arg */
79 1.1 jtc
80 1.1 jtc static int ftree_arg __P((void));
81 1.1 jtc
82 1.1 jtc /*
83 1.1 jtc * ftree_start()
84 1.1 jtc * initialize the options passed to fts_open() during this run of pax
85 1.1 jtc * options are based on the selection of pax options by the user
86 1.1 jtc * fts_start() also calls fts_arg() to open the first valid file arg. We
87 1.1 jtc * also attempt to reset directory access times when -t (tflag) is set.
88 1.1 jtc * Return:
89 1.1 jtc * 0 if there is at least one valid file arg to process, -1 otherwise
90 1.1 jtc */
91 1.1 jtc
92 1.1 jtc #if __STDC__
93 1.1 jtc int
94 1.1 jtc ftree_start(void)
95 1.1 jtc #else
96 1.1 jtc int
97 1.1 jtc ftree_start()
98 1.1 jtc #endif
99 1.1 jtc {
100 1.1 jtc /*
101 1.1 jtc * set up the operation mode of fts, open the first file arg. We must
102 1.1 jtc * use FTS_NOCHDIR, as the user may have to open multiple archives and
103 1.1 jtc * if fts did a chdir off into the boondocks, we may create an archive
104 1.1 jtc * volume in an place where the user did not expect to.
105 1.1 jtc */
106 1.1 jtc ftsopts = FTS_NOCHDIR;
107 1.1 jtc
108 1.1 jtc /*
109 1.1 jtc * optional user flags that effect file traversal
110 1.1 jtc * -H command line symlink follow only (half follow)
111 1.1 jtc * -L follow sylinks (logical)
112 1.1 jtc * -P do not follow sylinks (physical). This is the default.
113 1.1 jtc * -X do not cross over mount points
114 1.1 jtc * -t preserve access times on files read.
115 1.1 jtc * -n select only the first member of a file tree when a match is found
116 1.1 jtc * -d do not extract subtrees rooted at a directory arg.
117 1.1 jtc */
118 1.1 jtc if (Lflag)
119 1.1 jtc ftsopts |= FTS_LOGICAL;
120 1.1 jtc else
121 1.1 jtc ftsopts |= FTS_PHYSICAL;
122 1.1 jtc if (Hflag)
123 1.1 jtc # ifdef NET2_FTS
124 1.1 jtc warn(0, "The -H flag is not supported on this version");
125 1.1 jtc # else
126 1.1 jtc ftsopts |= FTS_COMFOLLOW;
127 1.1 jtc # endif
128 1.1 jtc if (Xflag)
129 1.1 jtc ftsopts |= FTS_XDEV;
130 1.1 jtc
131 1.1 jtc if ((fthead == NULL) && ((farray[0] = malloc(PAXPATHLEN+2)) == NULL)) {
132 1.1 jtc warn(1, "Unable to allocate memory for file name buffer");
133 1.1 jtc return(-1);
134 1.1 jtc }
135 1.1 jtc
136 1.1 jtc if (ftree_arg() < 0)
137 1.1 jtc return(-1);
138 1.1 jtc if (tflag && (atdir_start() < 0))
139 1.1 jtc return(-1);
140 1.1 jtc return(0);
141 1.1 jtc }
142 1.1 jtc
143 1.1 jtc /*
144 1.1 jtc * ftree_add()
145 1.1 jtc * add the arg to the linked list of files to process. Each will be
146 1.1 jtc * processed by fts one at a time
147 1.1 jtc * Return:
148 1.1 jtc * 0 if added to the linked list, -1 if failed
149 1.1 jtc */
150 1.1 jtc
151 1.1 jtc #if __STDC__
152 1.1 jtc int
153 1.1 jtc ftree_add(register char *str)
154 1.1 jtc #else
155 1.1 jtc int
156 1.1 jtc ftree_add(str)
157 1.1 jtc register char *str;
158 1.1 jtc #endif
159 1.1 jtc {
160 1.1 jtc register FTREE *ft;
161 1.1 jtc register int len;
162 1.1 jtc
163 1.1 jtc /*
164 1.1 jtc * simple check for bad args
165 1.1 jtc */
166 1.1 jtc if ((str == NULL) || (*str == '\0')) {
167 1.1 jtc warn(0, "Invalid file name arguement");
168 1.1 jtc return(-1);
169 1.1 jtc }
170 1.1 jtc
171 1.1 jtc /*
172 1.1 jtc * allocate FTREE node and add to the end of the linked list (args are
173 1.1 jtc * processed in the same order they were passed to pax). Get rid of any
174 1.1 jtc * trailing / the user may pass us. (watch out for / by itself).
175 1.1 jtc */
176 1.1 jtc if ((ft = (FTREE *)malloc(sizeof(FTREE))) == NULL) {
177 1.1 jtc warn(0, "Unable to allocate memory for filename");
178 1.1 jtc return(-1);
179 1.1 jtc }
180 1.1 jtc
181 1.1 jtc if (((len = strlen(str) - 1) > 0) && (str[len] == '/'))
182 1.1 jtc str[len] = '\0';
183 1.1 jtc ft->fname = str;
184 1.1 jtc ft->refcnt = 0;
185 1.1 jtc ft->fow = NULL;
186 1.1 jtc if (fthead == NULL) {
187 1.1 jtc fttail = fthead = ft;
188 1.1 jtc return(0);
189 1.1 jtc }
190 1.1 jtc fttail->fow = ft;
191 1.1 jtc fttail = ft;
192 1.1 jtc return(0);
193 1.1 jtc }
194 1.1 jtc
195 1.1 jtc /*
196 1.1 jtc * ftree_sel()
197 1.1 jtc * this entry has been selected by pax. bump up reference count and handle
198 1.1 jtc * -n and -d processing.
199 1.1 jtc */
200 1.1 jtc
201 1.1 jtc #if __STDC__
202 1.1 jtc void
203 1.1 jtc ftree_sel(register ARCHD *arcn)
204 1.1 jtc #else
205 1.1 jtc void
206 1.1 jtc ftree_sel(arcn)
207 1.1 jtc register ARCHD *arcn;
208 1.1 jtc #endif
209 1.1 jtc {
210 1.1 jtc /*
211 1.1 jtc * set reference bit for this pattern. This linked list is only used
212 1.1 jtc * when file trees are supplied pax as args. The list is not used when
213 1.1 jtc * the trees are read from stdin.
214 1.1 jtc */
215 1.1 jtc if (ftcur != NULL)
216 1.1 jtc ftcur->refcnt = 1;
217 1.1 jtc
218 1.1 jtc /*
219 1.1 jtc * if -n we are done with this arg, force a skip to the next arg when
220 1.1 jtc * pax asks for the next file in next_file().
221 1.1 jtc * if -d we tell fts only to match the directory (if the arg is a dir)
222 1.1 jtc * and not the entire file tree rooted at that point.
223 1.1 jtc */
224 1.1 jtc if (nflag)
225 1.1 jtc ftree_skip = 1;
226 1.1 jtc
227 1.1 jtc if (!dflag || (arcn->type != PAX_DIR))
228 1.1 jtc return;
229 1.1 jtc
230 1.1 jtc if (ftent != NULL)
231 1.1 jtc (void)fts_set(ftsp, ftent, FTS_SKIP);
232 1.1 jtc }
233 1.1 jtc
234 1.1 jtc /*
235 1.1 jtc * ftree_chk()
236 1.1 jtc * called at end on pax execution. Prints all those file args that did not
237 1.1 jtc * have a selected member (reference count still 0)
238 1.1 jtc */
239 1.1 jtc
240 1.1 jtc #if __STDC__
241 1.1 jtc void
242 1.1 jtc ftree_chk(void)
243 1.1 jtc #else
244 1.1 jtc void
245 1.1 jtc ftree_chk()
246 1.1 jtc #endif
247 1.1 jtc {
248 1.1 jtc register FTREE *ft;
249 1.1 jtc register int wban = 0;
250 1.1 jtc
251 1.1 jtc /*
252 1.1 jtc * make sure all dir access times were reset.
253 1.1 jtc */
254 1.1 jtc if (tflag)
255 1.1 jtc atdir_end();
256 1.1 jtc
257 1.1 jtc /*
258 1.1 jtc * walk down list and check reference count. Print out those members
259 1.1 jtc * that never had a match
260 1.1 jtc */
261 1.1 jtc for (ft = fthead; ft != NULL; ft = ft->fow) {
262 1.1 jtc if (ft->refcnt > 0)
263 1.1 jtc continue;
264 1.1 jtc if (wban == 0) {
265 1.1 jtc warn(1,"WARNING! These file names were not selected:");
266 1.1 jtc ++wban;
267 1.1 jtc }
268 1.1 jtc (void)fprintf(stderr, "%s\n", ft->fname);
269 1.1 jtc }
270 1.1 jtc }
271 1.1 jtc
272 1.1 jtc /*
273 1.1 jtc * ftree_arg()
274 1.1 jtc * Get the next file arg for fts to process. Can be from either the linked
275 1.1 jtc * list or read from stdin when the user did not them as args to pax. Each
276 1.1 jtc * arg is processed until the first successful fts_open().
277 1.1 jtc * Return:
278 1.1 jtc * 0 when the next arg is ready to go, -1 if out of file args (or EOF on
279 1.1 jtc * stdin).
280 1.1 jtc */
281 1.1 jtc
282 1.1 jtc #if __STDC__
283 1.1 jtc static int
284 1.1 jtc ftree_arg(void)
285 1.1 jtc #else
286 1.1 jtc static int
287 1.1 jtc ftree_arg()
288 1.1 jtc #endif
289 1.1 jtc {
290 1.1 jtc register char *pt;
291 1.1 jtc
292 1.1 jtc /*
293 1.1 jtc * close off the current file tree
294 1.1 jtc */
295 1.1 jtc if (ftsp != NULL) {
296 1.1 jtc (void)fts_close(ftsp);
297 1.1 jtc ftsp = NULL;
298 1.1 jtc }
299 1.1 jtc
300 1.1 jtc /*
301 1.1 jtc * keep looping until we get a valid file tree to process. Stop when we
302 1.1 jtc * reach the end of the list (or get an eof on stdin)
303 1.1 jtc */
304 1.1 jtc for(;;) {
305 1.1 jtc if (fthead == NULL) {
306 1.1 jtc /*
307 1.1 jtc * the user didn't supply any args, get the file trees
308 1.1 jtc * to process from stdin;
309 1.1 jtc */
310 1.1 jtc if (fgets(farray[0], PAXPATHLEN+1, stdin) == NULL)
311 1.1 jtc return(-1);
312 1.1 jtc if ((pt = strchr(farray[0], '\n')) != NULL)
313 1.1 jtc *pt = '\0';
314 1.1 jtc } else {
315 1.1 jtc /*
316 1.1 jtc * the user supplied the file args as arguements to pax
317 1.1 jtc */
318 1.1 jtc if (ftcur == NULL)
319 1.1 jtc ftcur = fthead;
320 1.1 jtc else if ((ftcur = ftcur->fow) == NULL)
321 1.1 jtc return(-1);
322 1.1 jtc farray[0] = ftcur->fname;
323 1.1 jtc }
324 1.1 jtc
325 1.1 jtc /*
326 1.1 jtc * watch it, fts wants the file arg stored in a array of char
327 1.1 jtc * ptrs, with the last one a null. we use a two element array
328 1.1 jtc * and set farray[0] to point at the buffer with the file name
329 1.1 jtc * in it. We cannnot pass all the file args to fts at one shot
330 1.1 jtc * as we need to keep a handle on which file arg generates what
331 1.1 jtc * files (the -n and -d flags need this). If the open is
332 1.1 jtc * successful, return a 0.
333 1.1 jtc */
334 1.1 jtc if ((ftsp = fts_open(farray, ftsopts, NULL)) != NULL)
335 1.1 jtc break;
336 1.1 jtc }
337 1.1 jtc return(0);
338 1.1 jtc }
339 1.1 jtc
340 1.1 jtc /*
341 1.1 jtc * next_file()
342 1.1 jtc * supplies the next file to process in the supplied archd structure.
343 1.1 jtc * Return:
344 1.1 jtc * 0 when contents of arcn have been set with the next file, -1 when done.
345 1.1 jtc */
346 1.1 jtc
347 1.1 jtc #if __STDC__
348 1.1 jtc int
349 1.1 jtc next_file(register ARCHD *arcn)
350 1.1 jtc #else
351 1.1 jtc int
352 1.1 jtc next_file(arcn)
353 1.1 jtc register ARCHD *arcn;
354 1.1 jtc #endif
355 1.1 jtc {
356 1.1 jtc register int cnt;
357 1.1 jtc time_t atime;
358 1.1 jtc time_t mtime;
359 1.1 jtc
360 1.1 jtc /*
361 1.1 jtc * ftree_sel() might have set the ftree_skip flag if the user has the
362 1.1 jtc * -n option and a file was selected from this file arg tree. (-n says
363 1.1 jtc * only one member is matched for each pattern) ftree_skip being 1
364 1.1 jtc * forces us to go to the next arg now.
365 1.1 jtc */
366 1.1 jtc if (ftree_skip) {
367 1.1 jtc /*
368 1.1 jtc * clear and go to next arg
369 1.1 jtc */
370 1.1 jtc ftree_skip = 0;
371 1.1 jtc if (ftree_arg() < 0)
372 1.1 jtc return(-1);
373 1.1 jtc }
374 1.1 jtc
375 1.1 jtc /*
376 1.1 jtc * loop until we get a valid file to process
377 1.1 jtc */
378 1.1 jtc for(;;) {
379 1.1 jtc if ((ftent = fts_read(ftsp)) == NULL) {
380 1.1 jtc /*
381 1.1 jtc * out of files in this tree, go to next arg, if none
382 1.1 jtc * we are done
383 1.1 jtc */
384 1.1 jtc if (ftree_arg() < 0)
385 1.1 jtc return(-1);
386 1.1 jtc continue;
387 1.1 jtc }
388 1.1 jtc
389 1.1 jtc /*
390 1.1 jtc * handle each type of fts_read() flag
391 1.1 jtc */
392 1.1 jtc switch(ftent->fts_info) {
393 1.1 jtc case FTS_D:
394 1.1 jtc case FTS_DEFAULT:
395 1.1 jtc case FTS_F:
396 1.1 jtc case FTS_SL:
397 1.1 jtc case FTS_SLNONE:
398 1.1 jtc /*
399 1.1 jtc * these are all ok
400 1.1 jtc */
401 1.1 jtc break;
402 1.1 jtc case FTS_DP:
403 1.1 jtc /*
404 1.1 jtc * already saw this directory. If the user wants file
405 1.1 jtc * access times reset, we use this to restore the
406 1.1 jtc * access time for this directory since this is the
407 1.1 jtc * last time we will see it in this file subtree
408 1.1 jtc * remember to force the time (this is -t on a read
409 1.1 jtc * directory, not a created directory).
410 1.1 jtc */
411 1.1 jtc # ifdef NET2_FTS
412 1.1 jtc if (!tflag || (get_atdir(ftent->fts_statb.st_dev,
413 1.1 jtc ftent->fts_statb.st_ino, &mtime, &atime) < 0))
414 1.1 jtc # else
415 1.1 jtc if (!tflag || (get_atdir(ftent->fts_statp->st_dev,
416 1.1 jtc ftent->fts_statp->st_ino, &mtime, &atime) < 0))
417 1.1 jtc # endif
418 1.1 jtc continue;
419 1.1 jtc set_ftime(ftent->fts_path, mtime, atime, 1);
420 1.1 jtc continue;
421 1.1 jtc case FTS_DC:
422 1.1 jtc /*
423 1.1 jtc * fts claims a file system cycle
424 1.1 jtc */
425 1.1 jtc warn(1,"File system cycle found at %s",ftent->fts_path);
426 1.1 jtc continue;
427 1.1 jtc case FTS_DNR:
428 1.1 jtc # ifdef NET2_FTS
429 1.1 jtc syswarn(1, errno,
430 1.1 jtc # else
431 1.1 jtc syswarn(1, ftent->fts_errno,
432 1.1 jtc # endif
433 1.1 jtc "Unable to read directory %s", ftent->fts_path);
434 1.1 jtc continue;
435 1.1 jtc case FTS_ERR:
436 1.1 jtc # ifdef NET2_FTS
437 1.1 jtc syswarn(1, errno,
438 1.1 jtc # else
439 1.1 jtc syswarn(1, ftent->fts_errno,
440 1.1 jtc # endif
441 1.1 jtc "File system traversal error");
442 1.1 jtc continue;
443 1.1 jtc case FTS_NS:
444 1.1 jtc case FTS_NSOK:
445 1.1 jtc # ifdef NET2_FTS
446 1.1 jtc syswarn(1, errno,
447 1.1 jtc # else
448 1.1 jtc syswarn(1, ftent->fts_errno,
449 1.1 jtc # endif
450 1.1 jtc "Unable to access %s", ftent->fts_path);
451 1.1 jtc continue;
452 1.1 jtc }
453 1.1 jtc
454 1.1 jtc /*
455 1.1 jtc * ok got a file tree node to process. copy info into arcn
456 1.1 jtc * structure (initialize as required)
457 1.1 jtc */
458 1.1 jtc arcn->skip = 0;
459 1.1 jtc arcn->pad = 0;
460 1.1 jtc arcn->ln_nlen = 0;
461 1.1 jtc arcn->ln_name[0] = '\0';
462 1.1 jtc # ifdef NET2_FTS
463 1.1 jtc arcn->sb = ftent->fts_statb;
464 1.1 jtc # else
465 1.1 jtc arcn->sb = *(ftent->fts_statp);
466 1.1 jtc # endif
467 1.1 jtc
468 1.1 jtc /*
469 1.1 jtc * file type based set up and copy into the arcn struct
470 1.1 jtc * SIDE NOTE:
471 1.1 jtc * we try to reset the access time on all files and directories
472 1.1 jtc * we may read when the -t flag is specified. files are reset
473 1.1 jtc * when we close them after copying. we reset the directories
474 1.1 jtc * when we are done with their file tree (we also clean up at
475 1.1 jtc * end in case we cut short a file tree traversal). However
476 1.1 jtc * there is no way to reset access times on symlinks.
477 1.1 jtc */
478 1.1 jtc switch(S_IFMT & arcn->sb.st_mode) {
479 1.1 jtc case S_IFDIR:
480 1.1 jtc arcn->type = PAX_DIR;
481 1.1 jtc if (!tflag)
482 1.1 jtc break;
483 1.1 jtc add_atdir(ftent->fts_path, arcn->sb.st_dev,
484 1.1 jtc arcn->sb.st_ino, arcn->sb.st_mtime,
485 1.1 jtc arcn->sb.st_atime);
486 1.1 jtc break;
487 1.1 jtc case S_IFCHR:
488 1.1 jtc arcn->type = PAX_CHR;
489 1.1 jtc break;
490 1.1 jtc case S_IFBLK:
491 1.1 jtc arcn->type = PAX_BLK;
492 1.1 jtc break;
493 1.1 jtc case S_IFREG:
494 1.1 jtc /*
495 1.1 jtc * only regular files with have data to store on the
496 1.1 jtc * archive. all others will store a zero length skip.
497 1.1 jtc * the skip field is used by pax for actual data it has
498 1.1 jtc * to read (or skip over).
499 1.1 jtc */
500 1.1 jtc arcn->type = PAX_REG;
501 1.1 jtc arcn->skip = arcn->sb.st_size;
502 1.1 jtc break;
503 1.1 jtc case S_IFLNK:
504 1.1 jtc arcn->type = PAX_SLK;
505 1.1 jtc /*
506 1.1 jtc * have to read the symlink path from the file
507 1.1 jtc */
508 1.1 jtc if ((cnt = readlink(ftent->fts_path, arcn->ln_name,
509 1.1 jtc PAXPATHLEN)) < 0) {
510 1.1 jtc syswarn(1, errno, "Unable to read symlink %s",
511 1.1 jtc ftent->fts_path);
512 1.1 jtc continue;
513 1.1 jtc }
514 1.1 jtc /*
515 1.1 jtc * set link name length, watch out readlink does not
516 1.1 jtc * allways null terminate the link path
517 1.1 jtc */
518 1.1 jtc arcn->ln_name[cnt] = '\0';
519 1.1 jtc arcn->ln_nlen = cnt;
520 1.1 jtc break;
521 1.1 jtc case S_IFSOCK:
522 1.1 jtc /*
523 1.1 jtc * under BSD storing a socket is senseless but we will
524 1.1 jtc * let the format specific write function make the
525 1.1 jtc * decision of what to do with it.
526 1.1 jtc */
527 1.1 jtc arcn->type = PAX_SCK;
528 1.1 jtc break;
529 1.1 jtc case S_IFIFO:
530 1.1 jtc arcn->type = PAX_FIF;
531 1.1 jtc break;
532 1.1 jtc }
533 1.1 jtc break;
534 1.1 jtc }
535 1.1 jtc
536 1.1 jtc /*
537 1.1 jtc * copy file name, set file name length
538 1.1 jtc */
539 1.1 jtc arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, PAXPATHLEN+1);
540 1.1 jtc arcn->name[arcn->nlen] = '\0';
541 1.1 jtc arcn->org_name = ftent->fts_path;
542 1.1 jtc return(0);
543 1.1 jtc }
544