Changeset 2988 in kBuild
- Timestamp:
- Nov 1, 2016 9:26:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt/fts-nt.c
r2985 r2988 78 78 #endif 79 79 80 //#include <sys/cdefs.h>81 //__FBSDID("$FreeBSD$");82 83 //#include "namespace.h"84 //#include <sys/param.h>85 //#include <sys/mount.h>86 //#include <sys/stat.h>87 88 //#include <dirent.h>89 80 #include <errno.h> 90 //#include <fcntl.h>91 81 #include "fts-nt.h" 92 82 #include <stdlib.h> 93 83 #include <string.h> 94 //#include <unistd.h>95 //#include "un-namespace.h"96 //97 //#include "gen-private.h"98 84 #include <assert.h> 99 85 #include "nthlp.h" … … 110 96 static int fts_stat(FTS *, FTSENT *, int, HANDLE); 111 97 static int fts_process_stats(FTSENT *, BirdStat_T const *); 112 static int fts_safe_changedir(FTS *, FTSENT *, int, char *);113 static int fts_ufslinks(FTS *, const FTSENT *);114 98 115 99 #define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) … … 118 102 #define ISSET(opt) (sp->fts_options & (opt)) 119 103 #define SET(opt) (sp->fts_options |= (opt)) 120 121 #define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))122 104 123 105 /* fts_build flags */ … … 131 113 132 114 #define AT_SYMLINK_NOFOLLOW 1 133 #define fstatat(hDir, pszPath, pStat, fFlags) birdStatAt((hDir), (pszPath), (pStat), (fFlags) != 0)115 #define fstatat(hDir, pszPath, pStat, fFlags) birdStatAt((hDir), (pszPath), (pStat), (fFlags) != AT_SYMLINK_NOFOLLOW) 134 116 #define FTS_NT_DUMMY_SYMFD_VALUE ((HANDLE)~(intptr_t)(2)) /* current process */ 135 #define fchdir(fd) todo_fchdir(fd)136 extern int todo_fchdir(fts_fd_t fd);137 117 138 118 /* … … 143 123 struct _fts_private { 144 124 FTS ftsp_fts; 145 #if 0 /* Not needed on NT, see comment on fts_ufslinks */146 struct statfs ftsp_statfs;147 dev_t ftsp_dev;148 int ftsp_linksreliable;149 #endif150 125 }; 151 126 152 #if 0 /* Not needed on NT, see comment on fts_ufslinks */153 /*154 * The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it155 * knows that a directory could not possibly have subdirectories. This156 * is decided by looking at the link count: a subdirectory would157 * increment its parent's link count by virtue of its own ".." entry.158 * This assumption only holds for UFS-like filesystems that implement159 * links and directories this way, so we must punt for others.160 */161 162 static const char *ufslike_filesystems[] = {163 "ufs",164 "zfs",165 "nfs",166 "ext2fs",167 0168 };169 #endif170 127 171 128 FTS * FTSCALL … … 197 154 sp->fts_compar = compar; 198 155 sp->fts_options = options; 156 SET(FTS_NOCHDIR); /* NT: FTS_NOCHDIR is always on (for external consumes) */ 199 157 200 158 /* Shush, GCC. */ 201 159 tmp = NULL; 202 203 /* Logical walks turn on NOCHDIR; symbolic links are too hard. */204 if (ISSET(FTS_LOGICAL))205 SET(FTS_NOCHDIR);206 160 207 161 /* … … 449 403 */ 450 404 if (sp->fts_child != NULL) { 451 if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { 452 p->fts_errno = errno; 453 p->fts_flags |= FTS_DONTCHDIR; 454 for (p = sp->fts_child; p != NULL; 455 p = p->fts_link) 456 p->fts_accpath = 457 p->fts_parent->fts_accpath; 458 } 405 /* nothing to do */ 459 406 } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { 460 407 if (ISSET(FTS_STOP)) … … 475 422 */ 476 423 if (p->fts_level == FTS_ROOTLEVEL) { 477 /*NT: No fchdir: if (FCHDIR(sp, sp->fts_rfd)) {478 SET(FTS_STOP);479 return (NULL);480 } */481 424 fts_free_entry(tmp); 482 425 fts_load(sp, p); … … 794 737 if (oldaddr != sp->fts_path) { 795 738 doadjust = 1; 796 if ( ISSET(FTS_NOCHDIR))739 if (1 /*ISSET(FTS_NOCHDIR)*/) 797 740 cp = sp->fts_path + len; 798 741 } … … 1092 1035 } 1093 1036 1094 /*1095 * Change to dir specified by fd or p->fts_accpath without getting1096 * tricked by someone changing the world out from underneath us.1097 * Assumes p->fts_dev and p->fts_ino are filled in.1098 */1099 static int1100 fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)1101 {1102 #if 01103 int ret, oerrno, newfd;1104 struct stat sb;1105 1106 newfd = fd;1107 #endif1108 if (ISSET(FTS_NOCHDIR))1109 return (0);1110 assert(0);1111 return -1;1112 #if 01113 if (fd < 0 && (newfd = _open(path, O_RDONLY | O_DIRECTORY |1114 O_CLOEXEC, 0)) < 0)1115 return (-1);1116 if (_fstat(newfd, &sb)) {1117 ret = -1;1118 goto bail;1119 }1120 if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {1121 errno = ENOENT; /* disinformation */1122 ret = -1;1123 goto bail;1124 }1125 ret = fchdir(newfd);1126 bail:1127 oerrno = errno;1128 if (fd < 0)1129 (void)_close(newfd);1130 errno = oerrno;1131 return (ret);1132 #endif1133 }1134 1135 /*1136 * Check if the filesystem for "ent" has UFS-style links.1137 *1138 * bird: NT does not, which is why they need this check.1139 * See comment on r129052 (2004-05-08 15:09:02Z).1140 */1141 static int1142 fts_ufslinks(FTS *sp, const FTSENT *ent)1143 {1144 #if 01145 struct _fts_private *priv;1146 const char **cpp;1147 1148 priv = (struct _fts_private *)sp;1149 /*1150 * If this node's device is different from the previous, grab1151 * the filesystem information, and decide on the reliability1152 * of the link information from this filesystem for stat(2)1153 * avoidance.1154 */1155 if (priv->ftsp_dev != ent->fts_dev) {1156 if (statfs(ent->fts_path, &priv->ftsp_statfs) != -1) {1157 priv->ftsp_dev = ent->fts_dev;1158 priv->ftsp_linksreliable = 0;1159 for (cpp = ufslike_filesystems; *cpp; cpp++) {1160 if (strcmp(priv->ftsp_statfs.f_fstypename,1161 *cpp) == 0) {1162 priv->ftsp_linksreliable = 1;1163 break;1164 }1165 }1166 } else {1167 priv->ftsp_linksreliable = 0;1168 }1169 }1170 return (priv->ftsp_linksreliable);1171 #else1172 (void)sp; (void)ent;1173 return 0;1174 #endif1175 }1176
Note:
See TracChangeset
for help on using the changeset viewer.