VirtualBox

Changeset 2988 in kBuild


Ignore:
Timestamp:
Nov 1, 2016 9:26:15 PM (8 years ago)
Author:
bird
Message:

fts-nt.c: cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/nt/fts-nt.c

    r2985 r2988  
    7878#endif
    7979
    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>
    8980#include <errno.h>
    90 //#include <fcntl.h>
    9181#include "fts-nt.h"
    9282#include <stdlib.h>
    9383#include <string.h>
    94 //#include <unistd.h>
    95 //#include "un-namespace.h"
    96 //
    97 //#include "gen-private.h"
    9884#include <assert.h>
    9985#include "nthlp.h"
     
    11096static int       fts_stat(FTS *, FTSENT *, int, HANDLE);
    11197static 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 *);
    11498
    11599#define ISDOT(a)        (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
     
    118102#define ISSET(opt)      (sp->fts_options & (opt))
    119103#define SET(opt)        (sp->fts_options |= (opt))
    120 
    121 #define FCHDIR(sp, fd)  (!ISSET(FTS_NOCHDIR) && fchdir(fd))
    122104
    123105/* fts_build flags */
     
    131113
    132114#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)
    134116#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);
    137117
    138118/*
     
    143123struct _fts_private {
    144124        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 #endif
    150125};
    151126
    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 it
    155  * knows that a directory could not possibly have subdirectories.  This
    156  * is decided by looking at the link count: a subdirectory would
    157  * increment its parent's link count by virtue of its own ".." entry.
    158  * This assumption only holds for UFS-like filesystems that implement
    159  * 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         0
    168 };
    169 #endif
    170127
    171128FTS * FTSCALL
     
    197154        sp->fts_compar = compar;
    198155        sp->fts_options = options;
     156        SET(FTS_NOCHDIR); /* NT: FTS_NOCHDIR is always on (for external consumes) */
    199157
    200158        /* Shush, GCC. */
    201159        tmp = NULL;
    202 
    203         /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
    204         if (ISSET(FTS_LOGICAL))
    205                 SET(FTS_NOCHDIR);
    206160
    207161        /*
     
    449403                 */
    450404                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 */
    459406                } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
    460407                        if (ISSET(FTS_STOP))
     
    475422                 */
    476423                if (p->fts_level == FTS_ROOTLEVEL) {
    477                         /*NT: No fchdir: if (FCHDIR(sp, sp->fts_rfd)) {
    478                                 SET(FTS_STOP);
    479                                 return (NULL);
    480                         } */
    481424                        fts_free_entry(tmp);
    482425                        fts_load(sp, p);
     
    794737                        if (oldaddr != sp->fts_path) {
    795738                                doadjust = 1;
    796                                 if (ISSET(FTS_NOCHDIR))
     739                                if (1 /*ISSET(FTS_NOCHDIR)*/)
    797740                                        cp = sp->fts_path + len;
    798741                        }
     
    10921035}
    10931036
    1094 /*
    1095  * Change to dir specified by fd or p->fts_accpath without getting
    1096  * 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 int
    1100 fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
    1101 {
    1102 #if 0
    1103         int ret, oerrno, newfd;
    1104         struct stat sb;
    1105 
    1106         newfd = fd;
    1107 #endif
    1108         if (ISSET(FTS_NOCHDIR))
    1109                 return (0);
    1110         assert(0);
    1111         return -1;
    1112 #if 0
    1113         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 #endif
    1133 }
    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 int
    1142 fts_ufslinks(FTS *sp, const FTSENT *ent)
    1143 {
    1144 #if 0
    1145         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, grab
    1151          * the filesystem information, and decide on the reliability
    1152          * 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 #else
    1172         (void)sp; (void)ent;
    1173         return 0;
    1174 #endif
    1175 }
    1176 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette