Lines Matching +full:- +full:- +full:arg +full:- +full:file
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
52 * file args supplied to pax are stored on a single linked list (of type FTREE)
54 * the expansion of each arg into the corresponding file tree (if the arg is a
56 * is modified by the -n and -u flags. The user is informed when a specific
57 * file arg does not generate any selected files. -n keeps expanding the file
58 * tree arg until one of its files is selected, then skips to the next file
59 * arg. when the user does not supply the file trees as command line args to
65 static char *farray[2]; /* array for passing each arg to fts */
66 static FTREE *fthead = NULL; /* head of linked list of file args */
67 static FTREE *fttail = NULL; /* tail of linked list of file args */
68 static FTREE *ftcur = NULL; /* current file arg being processed */
69 static FTSENT *ftent = NULL; /* current file tree entry */
70 static int ftree_skip; /* when set skip to next file arg */
78 * fts_start() also calls fts_arg() to open the first valid file arg. We
79 * also attempt to reset directory access times when -t (tflag) is set.
81 * 0 if there is at least one valid file arg to process, -1 otherwise
88 * Set up the operation mode of fts, open the first file arg. We must in ftree_start()
96 * optional user flags that effect file traversal in ftree_start()
97 * -H command line symlink follow only (half follow) in ftree_start()
98 * -L follow symlinks (logical) in ftree_start()
99 * -P do not follow symlinks (physical). This is the default. in ftree_start()
100 * -X do not cross over mount points in ftree_start()
101 * -t preserve access times on files read. in ftree_start()
102 * -n select only the first member of a file tree when a match is found in ftree_start()
103 * -d do not extract subtrees rooted at a directory arg. in ftree_start()
115 paxwarn(1, "Unable to allocate memory for file name buffer"); in ftree_start()
116 return(-1); in ftree_start()
120 return(-1); in ftree_start()
122 return(-1); in ftree_start()
128 * add the arg to the linked list of files to process. Each will be
131 * 0 if added to the linked list, -1 if failed
144 paxwarn(0, "Invalid file name argument"); in ftree_add()
145 return(-1); in ftree_add()
155 return(-1); in ftree_add()
158 if (((len = strlen(str) - 1) > 0) && (str[len] == '/')) in ftree_add()
160 ft->fname = str; in ftree_add()
161 ft->refcnt = 0; in ftree_add()
162 ft->chflg = chflg; in ftree_add()
163 ft->fow = NULL; in ftree_add()
168 fttail->fow = ft; in ftree_add()
176 * -n and -d processing.
184 * when file trees are supplied pax as args. The list is not used when in ftree_sel()
188 ftcur->refcnt = 1; in ftree_sel()
191 * if -n we are done with this arg, force a skip to the next arg when in ftree_sel()
192 * pax asks for the next file in next_file(). in ftree_sel()
193 * if -d we tell fts only to match the directory (if the arg is a dir) in ftree_sel()
194 * and not the entire file tree rooted at that point. in ftree_sel()
199 if (!dflag || (arcn->type != PAX_DIR)) in ftree_sel()
220 * called at end on pax execution. Prints all those file args that did not
240 for (ft = fthead; ft != NULL; ft = ft->fow) { in ftree_chk()
241 if ((ft->refcnt > 0) || ft->chflg) in ftree_chk()
244 paxwarn(1,"WARNING! These file names were not selected:"); in ftree_chk()
247 (void)fprintf(stderr, "%s\n", ft->fname); in ftree_chk()
253 * Get the next file arg for fts to process. Can be from either the linked
255 * arg is processed until the first successful fts_open().
257 * 0 when the next arg is ready to go, -1 if out of file args (or EOF on
267 * close off the current file tree in ftree_arg()
275 * keep looping until we get a valid file tree to process. Stop when we in ftree_arg()
281 * the user didn't supply any args, get the file trees in ftree_arg()
285 return(-1); in ftree_arg()
290 * the user supplied the file args as arguments to pax in ftree_arg()
294 else if ((ftcur = ftcur->fow) == NULL) in ftree_arg()
295 return(-1); in ftree_arg()
296 if (ftcur->chflg) { in ftree_arg()
301 return(-1); in ftree_arg()
303 if (chdir(ftcur->fname) < 0) { in ftree_arg()
305 ftcur->fname); in ftree_arg()
306 return(-1); in ftree_arg()
310 farray[0] = ftcur->fname; in ftree_arg()
314 * Watch it, fts wants the file arg stored in an array of char in ftree_arg()
316 * and set farray[0] to point at the buffer with the file name in ftree_arg()
317 * in it. We cannot pass all the file args to fts at one shot in ftree_arg()
318 * as we need to keep a handle on which file arg generates what in ftree_arg()
319 * files (the -n and -d flags need this). If the open is in ftree_arg()
330 * supplies the next file to process in the supplied archd structure.
332 * 0 when contents of arcn have been set with the next file, -1 when done.
344 * -n option and a file was selected from this file arg tree. (-n says in next_file()
346 * forces us to go to the next arg now. in next_file()
350 * clear and go to next arg in next_file()
354 return(-1); in next_file()
358 * loop until we get a valid file to process in next_file()
363 * out of files in this tree, go to next arg, if none in next_file()
367 return(-1); in next_file()
374 switch(ftent->fts_info) { in next_file()
386 * already saw this directory. If the user wants file in next_file()
389 * last time we will see it in this file subtree in next_file()
390 * remember to force the time (this is -t on a read in next_file()
393 if (!tflag || (get_atdir(ftent->fts_statp->st_dev, in next_file()
394 ftent->fts_statp->st_ino, &mtime, &atime) < 0)) in next_file()
396 set_ftime(ftent->fts_path, mtime, atime, 1); in next_file()
400 * fts claims a file system cycle in next_file()
402 paxwarn(1,"File system cycle found at %s",ftent->fts_path); in next_file()
405 syswarn(1, ftent->fts_errno, in next_file()
406 "Unable to read directory %s", ftent->fts_path); in next_file()
409 syswarn(1, ftent->fts_errno, in next_file()
410 "File system traversal error"); in next_file()
414 syswarn(1, ftent->fts_errno, in next_file()
415 "Unable to access %s", ftent->fts_path); in next_file()
420 * ok got a file tree node to process. copy info into arcn in next_file()
423 arcn->skip = 0; in next_file()
424 arcn->pad = 0; in next_file()
425 arcn->ln_nlen = 0; in next_file()
426 arcn->ln_name[0] = '\0'; in next_file()
427 arcn->sb = *(ftent->fts_statp); in next_file()
430 * file type based set up and copy into the arcn struct in next_file()
433 * we may read when the -t flag is specified. files are reset in next_file()
435 * when we are done with their file tree (we also clean up at in next_file()
436 * end in case we cut short a file tree traversal). However in next_file()
439 switch(S_IFMT & arcn->sb.st_mode) { in next_file()
441 arcn->type = PAX_DIR; in next_file()
444 add_atdir(ftent->fts_path, arcn->sb.st_dev, in next_file()
445 arcn->sb.st_ino, arcn->sb.st_mtime, in next_file()
446 arcn->sb.st_atime); in next_file()
449 arcn->type = PAX_CHR; in next_file()
452 arcn->type = PAX_BLK; in next_file()
461 arcn->type = PAX_REG; in next_file()
462 arcn->skip = arcn->sb.st_size; in next_file()
465 arcn->type = PAX_SLK; in next_file()
467 * have to read the symlink path from the file in next_file()
469 if ((cnt = readlink(ftent->fts_path, arcn->ln_name, in next_file()
470 PAXPATHLEN - 1)) < 0) { in next_file()
472 ftent->fts_path); in next_file()
479 arcn->ln_name[cnt] = '\0'; in next_file()
480 arcn->ln_nlen = cnt; in next_file()
488 arcn->type = PAX_SCK; in next_file()
491 arcn->type = PAX_FIF; in next_file()
498 * copy file name, set file name length in next_file()
500 arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, sizeof(arcn->name) - 1); in next_file()
501 arcn->name[arcn->nlen] = '\0'; in next_file()
502 arcn->org_name = ftent->fts_path; in next_file()