From owner-svn-soc-all@FreeBSD.ORG Fri Jun 17 22:30:45 2011 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id D0E88106566C for ; Fri, 17 Jun 2011 22:30:42 +0000 (UTC) (envelope-from gk@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 17 Jun 2011 22:30:42 +0000 Date: Fri, 17 Jun 2011 22:30:42 +0000 From: gk@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20110617223042.D0E88106566C@hub.freebsd.org> Cc: Subject: socsvn commit: r223373 - soc2011/gk/ino64-head/lib/libc/gen X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jun 2011 22:30:45 -0000 Author: gk Date: Fri Jun 17 22:30:42 2011 New Revision: 223373 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=223373 Log: libc: fts ftw nftw Added: soc2011/gk/ino64-head/lib/libc/gen/fts-compat8.c - copied, changed from r223372, soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c soc2011/gk/ino64-head/lib/libc/gen/fts-compat8.h - copied, changed from r223372, soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h soc2011/gk/ino64-head/lib/libc/gen/ftw-compat8.c (contents, props changed) soc2011/gk/ino64-head/lib/libc/gen/nftw-compat8.c (contents, props changed) Modified: soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc soc2011/gk/ino64-head/lib/libc/gen/Symbol.map soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h Modified: soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc ============================================================================== --- soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc Fri Jun 17 22:30:26 2011 (r223372) +++ soc2011/gk/ino64-head/lib/libc/gen/Makefile.inc Fri Jun 17 22:30:42 2011 (r223373) @@ -12,15 +12,15 @@ crypt.c ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c \ dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c errno.c \ exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \ - fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \ - getbootfile.c getbsize.c \ + fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c fts-compat8.c \ + ftw.c ftw-compat8.c getbootfile.c getbsize.c \ getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \ gethostname.c getloadavg.c getlogin.c getmntinfo.c getnetgrent.c \ getosreldate.c getpagesize.c getpagesizes.c \ getpeereid.c getprogname.c getpwent.c getttyent.c \ getusershell.c getutxent.c getvfsbyname.c glob.c glob-compat8.c \ initgroups.c isatty.c isinf.c isnan.c jrand48.c lcong48.c \ - lockf.c lrand48.c mrand48.c nftw.c nice.c \ + lockf.c lrand48.c mrand48.c nftw.c nftw-compat8.c nice.c \ nlist.c nrand48.c opendir.c \ pause.c pmadvise.c popen.c posix_spawn.c \ psignal.c pututxline.c pw_scan.c pwcache.c \ Modified: soc2011/gk/ino64-head/lib/libc/gen/Symbol.map ============================================================================== --- soc2011/gk/ino64-head/lib/libc/gen/Symbol.map Fri Jun 17 22:30:26 2011 (r223372) +++ soc2011/gk/ino64-head/lib/libc/gen/Symbol.map Fri Jun 17 22:30:42 2011 (r223373) @@ -134,7 +134,6 @@ setfsent; endfsent; ftok; - ftw; getbootfile; getbsize; cgetset; @@ -212,7 +211,6 @@ lockf; lrand48; mrand48; - nftw; nice; nlist; nrand48; @@ -314,14 +312,6 @@ fdevname_r; fdopendir; feature_present; - fts_children; - fts_close; - fts_get_clientptr; - fts_get_stream; - fts_open; - fts_read; - fts_set; - fts_set_clientptr; posix_spawn; posix_spawn_file_actions_addclose; posix_spawn_file_actions_adddup2; @@ -356,6 +346,15 @@ cfmakesane; dirfd; endutxent; + fts_children; + fts_close; + fts_get_clientptr; + fts_get_stream; + fts_open; + fts_read; + fts_set; + fts_set_clientptr; + ftw; getpagesizes; getutxent; getutxid; @@ -363,6 +362,7 @@ getutxuser; glob; globfree; + nftw; pututxline; readdir; readdir_r; Modified: soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c ============================================================================== --- soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c Fri Jun 17 22:30:26 2011 (r223372) +++ soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c Fri Jun 17 22:30:42 2011 (r223373) @@ -49,6 +49,7 @@ #include #include #include +#include "dirent-compat.h" #include "fts-compat.h" #include "un-namespace.h" @@ -637,7 +638,7 @@ FTS *sp; int type; { - struct dirent *dp; + struct freebsd8_dirent *dp; FTSENT *p, *head; int nitems; FTSENT *cur, *tail; @@ -749,7 +750,8 @@ /* Read the directory, attaching each entry to the `link' pointer. */ doadjust = 0; - for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { + for (head = tail = NULL, nitems = 0; + dirp && (dp = freebsd8_readdir(dirp));) { dnamlen = dp->d_namlen; if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) continue; @@ -906,8 +908,8 @@ { FTSENT *t; dev_t dev; - ino_t ino; - struct stat *sbp, sb; + uint32_t ino; + struct freebsd8_stat *sbp, sb; int saved_errno; /* If user needs stat info, stat buffer already allocated. */ @@ -930,16 +932,16 @@ * fail, set the errno from the stat call. */ if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { + if (freebsd8_stat(p->fts_accpath, sbp)) { saved_errno = errno; - if (!lstat(p->fts_accpath, sbp)) { + if (!freebsd8_lstat(p->fts_accpath, sbp)) { errno = 0; return (FTS_SLNONE); } p->fts_errno = saved_errno; goto err; } - } else if (lstat(p->fts_accpath, sbp)) { + } else if (freebsd8_lstat(p->fts_accpath, sbp)) { p->fts_errno = errno; err: memset(sbp, 0, sizeof(struct stat)); return (FTS_NS); @@ -1039,7 +1041,7 @@ struct ftsent_withstat { FTSENT ent; - struct stat statbuf; + struct freebsd8_stat statbuf; }; /* @@ -1175,14 +1177,14 @@ char *path; { int ret, oerrno, newfd; - struct stat sb; + struct freebsd8_stat sb; newfd = fd; if (ISSET(FTS_NOCHDIR)) return (0); if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) return (-1); - if (_fstat(newfd, &sb)) { + if (freebsd8_fstat(newfd, &sb)) { ret = -1; goto bail; } Modified: soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h ============================================================================== --- soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h Fri Jun 17 22:30:26 2011 (r223372) +++ soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h Fri Jun 17 22:30:42 2011 (r223373) @@ -86,9 +86,9 @@ u_short fts_pathlen; /* strlen(fts_path) */ u_short fts_namelen; /* strlen(fts_name) */ - ino_t fts_ino; /* inode */ + uint32_t fts_ino; /* inode */ dev_t fts_dev; /* device */ - nlink_t fts_nlink; /* link count */ + uint16_t fts_nlink; /* link count */ #define FTS_ROOTPARENTLEVEL -1 #define FTS_ROOTLEVEL 0 @@ -121,7 +121,7 @@ #define FTS_SKIP 4 /* discard node */ u_short fts_instr; /* fts_set() instructions */ - struct stat *fts_statp; /* stat(2) information */ + struct freebsd8_stat *fts_statp; /* stat(2) information */ char *fts_name; /* file name */ FTS *fts_fts; /* back pointer to main FTS */ } FTSENT; Copied and modified: soc2011/gk/ino64-head/lib/libc/gen/fts-compat8.c (from r223372, soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c) ============================================================================== --- soc2011/gk/ino64-head/lib/libc/gen/fts-compat.c Fri Jun 17 22:30:26 2011 (r223372, copy source) +++ soc2011/gk/ino64-head/lib/libc/gen/fts-compat8.c Fri Jun 17 22:30:42 2011 (r223373) @@ -49,30 +49,19 @@ #include #include #include -#include "fts-compat.h" +#include "dirent-compat.h" +#include "fts-compat8.h" #include "un-namespace.h" -#include "dirent-private.h" - -FTSENT *__fts_children_44bsd(FTS *, int); -int __fts_close_44bsd(FTS *); -void *__fts_get_clientptr_44bsd(FTS *); -FTS *__fts_get_stream_44bsd(FTSENT *); -FTS *__fts_open_44bsd(char * const *, int, - int (*)(const FTSENT * const *, const FTSENT * const *)); -FTSENT *__fts_read_44bsd(FTS *); -int __fts_set_44bsd(FTS *, FTSENT *, int); -void __fts_set_clientptr_44bsd(FTS *, void *); - -static FTSENT *fts_alloc(FTS *, char *, int); +static FTSENT *fts_alloc(FTS *, char *, size_t); static FTSENT *fts_build(FTS *, int); static void fts_lfree(FTSENT *); static void fts_load(FTS *, FTSENT *); static size_t fts_maxarglen(char * const *); static void fts_padjust(FTS *, FTSENT *); static int fts_palloc(FTS *, size_t); -static FTSENT *fts_sort(FTS *, FTSENT *, int); -static u_short fts_stat(FTS *, FTSENT *, int); +static FTSENT *fts_sort(FTS *, FTSENT *, size_t); +static int fts_stat(FTS *, FTSENT *, int); static int fts_safe_changedir(FTS *, FTSENT *, int, char *); static int fts_ufslinks(FTS *, const FTSENT *); @@ -112,7 +101,6 @@ static const char *ufslike_filesystems[] = { "ufs", - "zfs", "nfs", "nfs4", "ext2fs", @@ -120,7 +108,7 @@ }; FTS * -__fts_open_44bsd(argv, options, compar) +freebsd8_fts_open(argv, options, compar) char * const *argv; int options; int (*compar)(const FTSENT * const *, const FTSENT * const *); @@ -128,9 +116,8 @@ struct _fts_private *priv; FTS *sp; FTSENT *p, *root; - int nitems; FTSENT *parent, *tmp; - int len; + size_t len, nitems; /* Options check. */ if (options & ~FTS_OPTIONMASK) { @@ -138,6 +125,12 @@ return (NULL); } + /* fts_open() requires at least one path */ + if (*argv == NULL) { + errno = EINVAL; + return (NULL); + } + /* Allocate/initialize the stream. */ if ((priv = malloc(sizeof(*priv))) == NULL) return (NULL); @@ -237,7 +230,7 @@ FTS *sp; FTSENT *p; { - int len; + size_t len; char *cp; /* @@ -259,7 +252,7 @@ } int -__fts_close_44bsd(sp) +freebsd8_fts_close(sp) FTS *sp; { FTSENT *freep, *p; @@ -314,7 +307,7 @@ ? p->fts_pathlen - 1 : p->fts_pathlen) FTSENT * -__fts_read_44bsd(sp) +freebsd8_fts_read(sp) FTS *sp; { FTSENT *p, *tmp; @@ -508,7 +501,7 @@ */ /* ARGSUSED */ int -__fts_set_44bsd(sp, p, instr) +freebsd8_fts_set(sp, p, instr) FTS *sp; FTSENT *p; int instr; @@ -523,7 +516,7 @@ } FTSENT * -__fts_children_44bsd(sp, instr) +freebsd8_fts_children(sp, instr) FTS *sp; int instr; { @@ -584,35 +577,37 @@ if ((fd = _open(".", O_RDONLY, 0)) < 0) return (NULL); sp->fts_child = fts_build(sp, instr); - if (fchdir(fd)) + if (fchdir(fd)) { + (void)_close(fd); return (NULL); + } (void)_close(fd); return (sp->fts_child); } -#ifndef fts_get_clientptr -#error "fts_get_clientptr not defined" +#ifndef freebsd8_fts_get_clientptr +#error "freebsd8_fts_get_clientptr not defined" #endif void * -(__fts_get_clientptr_44bsd)(FTS *sp) +(freebsd8_fts_get_clientptr)(FTS *sp) { - return (fts_get_clientptr(sp)); + return (freebsd8_fts_get_clientptr(sp)); } -#ifndef fts_get_stream -#error "fts_get_stream not defined" +#ifndef freebsd8_fts_get_stream +#error "freebsd8_fts_get_stream not defined" #endif FTS * -(__fts_get_stream_44bsd)(FTSENT *p) +(freebsd8_fts_get_stream)(FTSENT *p) { - return (fts_get_stream(p)); + return (freebsd8_fts_get_stream(p)); } void -__fts_set_clientptr_44bsd(FTS *sp, void *clientptr) +freebsd8_fts_set_clientptr(FTS *sp, void *clientptr) { sp->fts_clientptr = clientptr; @@ -637,16 +632,16 @@ FTS *sp; int type; { - struct dirent *dp; + struct freebsd8_dirent *dp; FTSENT *p, *head; - int nitems; FTSENT *cur, *tail; DIR *dirp; void *oldaddr; - size_t dnamlen; - int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno, - nostat, doadjust; char *cp; + int cderrno, descend, oflag, saved_errno, nostat, doadjust; + long level; + long nlinks; /* has to be signed because -1 is a magic value */ + size_t dnamlen, len, maxlen, nitems; /* Set current node pointer. */ cur = sp->fts_cur; @@ -713,7 +708,7 @@ */ cderrno = 0; if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, _dirfd(dirp), NULL)) { + if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { if (nlinks && type == BREAD) cur->fts_errno = errno; cur->fts_flags |= FTS_DONTCHDIR; @@ -749,12 +744,13 @@ /* Read the directory, attaching each entry to the `link' pointer. */ doadjust = 0; - for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { + for (head = tail = NULL, nitems = 0; + dirp && (dp = freebsd8_readdir(dirp));) { dnamlen = dp->d_namlen; if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) continue; - if ((p = fts_alloc(sp, dp->d_name, (int)dnamlen)) == NULL) + if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL) goto mem1; if (dnamlen >= maxlen) { /* include space for NUL */ oldaddr = sp->fts_path; @@ -783,21 +779,6 @@ maxlen = sp->fts_pathlen - len; } - if (len + dnamlen >= USHRT_MAX) { - /* - * In an FTSENT, fts_pathlen is a u_short so it is - * possible to wraparound here. If we do, free up - * the current structure and the structures already - * allocated, then error out with ENAMETOOLONG. - */ - free(p); - fts_lfree(head); - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = ENAMETOOLONG; - return (NULL); - } p->fts_level = level; p->fts_parent = sp->fts_cur; p->fts_pathlen = len + dnamlen; @@ -863,11 +844,8 @@ * If not changing directories, reset the path back to original * state. */ - if (ISSET(FTS_NOCHDIR)) { - if (len == sp->fts_pathlen || nitems == 0) - --cp; - *cp = '\0'; - } + if (ISSET(FTS_NOCHDIR)) + sp->fts_path[cur->fts_pathlen] = '\0'; /* * If descended after called from fts_children or after called from @@ -898,7 +876,7 @@ return (head); } -static u_short +static int fts_stat(sp, p, follow) FTS *sp; FTSENT *p; @@ -906,8 +884,8 @@ { FTSENT *t; dev_t dev; - ino_t ino; - struct stat *sbp, sb; + uint32_t ino; + struct freebsd8_stat *sbp, sb; int saved_errno; /* If user needs stat info, stat buffer already allocated. */ @@ -930,16 +908,16 @@ * fail, set the errno from the stat call. */ if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { + if (freebsd8_stat(p->fts_accpath, sbp)) { saved_errno = errno; - if (!lstat(p->fts_accpath, sbp)) { + if (!freebsd8_lstat(p->fts_accpath, sbp)) { errno = 0; return (FTS_SLNONE); } p->fts_errno = saved_errno; goto err; } - } else if (lstat(p->fts_accpath, sbp)) { + } else if (freebsd8_lstat(p->fts_accpath, sbp)) { p->fts_errno = errno; err: memset(sbp, 0, sizeof(struct stat)); return (FTS_NS); @@ -1000,7 +978,7 @@ fts_sort(sp, head, nitems) FTS *sp; FTSENT *head; - int nitems; + size_t nitems; { FTSENT **ap, *p; @@ -1032,14 +1010,14 @@ fts_alloc(sp, name, namelen) FTS *sp; char *name; - int namelen; + size_t namelen; { FTSENT *p; size_t len; struct ftsent_withstat { FTSENT ent; - struct stat statbuf; + struct freebsd8_stat statbuf; }; /* @@ -1104,18 +1082,6 @@ { sp->fts_pathlen += more + 256; - /* - * Check for possible wraparound. In an FTS, fts_pathlen is - * a signed int but in an FTSENT it is an unsigned short. - * We limit fts_pathlen to USHRT_MAX to be safe in both cases. - */ - if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) { - if (sp->fts_path) - free(sp->fts_path); - sp->fts_path = NULL; - errno = ENAMETOOLONG; - return (1); - } sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen); return (sp->fts_path == NULL); } @@ -1175,14 +1141,14 @@ char *path; { int ret, oerrno, newfd; - struct stat sb; + struct freebsd8_stat sb; newfd = fd; if (ISSET(FTS_NOCHDIR)) return (0); if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) return (-1); - if (_fstat(newfd, &sb)) { + if (freebsd8_fstat(newfd, &sb)) { ret = -1; goto bail; } @@ -1234,11 +1200,11 @@ return (priv->ftsp_linksreliable); } -__sym_compat(fts_open, __fts_open_44bsd, FBSD_1.0); -__sym_compat(fts_close, __fts_close_44bsd, FBSD_1.0); -__sym_compat(fts_read, __fts_read_44bsd, FBSD_1.0); -__sym_compat(fts_set, __fts_set_44bsd, FBSD_1.0); -__sym_compat(fts_children, __fts_children_44bsd, FBSD_1.0); -__sym_compat(fts_get_clientptr, __fts_get_clientptr_44bsd, FBSD_1.0); -__sym_compat(fts_get_stream, __fts_get_stream_44bsd, FBSD_1.0); -__sym_compat(fts_set_clientptr, __fts_set_clientptr_44bsd, FBSD_1.0); +__sym_compat(fts_open, freebsd8_fts_open, FBSD_1.1); +__sym_compat(fts_close, freebsd8_fts_close, FBSD_1.1); +__sym_compat(fts_read, freebsd8_fts_read, FBSD_1.1); +__sym_compat(fts_set, freebsd8_fts_set, FBSD_1.1); +__sym_compat(fts_children, freebsd8_fts_children, FBSD_1.1); +__sym_compat(fts_get_clientptr, freebsd8_fts_get_clientptr, FBSD_1.1); +__sym_compat(fts_get_stream, freebsd8_fts_get_stream, FBSD_1.1); +__sym_compat(fts_set_clientptr, freebsd8_fts_set_clientptr, FBSD_1.1); Copied and modified: soc2011/gk/ino64-head/lib/libc/gen/fts-compat8.h (from r223372, soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h) ============================================================================== --- soc2011/gk/ino64-head/lib/libc/gen/fts-compat.h Fri Jun 17 22:30:26 2011 (r223372, copy source) +++ soc2011/gk/ino64-head/lib/libc/gen/fts-compat8.h Fri Jun 17 22:30:42 2011 (r223373) @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -44,8 +40,8 @@ dev_t fts_dev; /* starting device # */ char *fts_path; /* path for this descent */ int fts_rfd; /* fd for root */ - int fts_pathlen; /* sizeof(path) */ - int fts_nitems; /* elements in the sort array */ + size_t fts_pathlen; /* sizeof(path) */ + size_t fts_nitems; /* elements in the sort array */ int (*fts_compar) /* compare function */ (const struct _ftsent * const *, const struct _ftsent * const *); @@ -69,30 +65,23 @@ struct _ftsent *fts_cycle; /* cycle node */ struct _ftsent *fts_parent; /* parent directory */ struct _ftsent *fts_link; /* next file in directory */ - union { - struct { - long __fts_number; /* local numeric value */ - void *__fts_pointer; /* local address value */ - } __struct_ftsent; - int64_t __fts_bignum; - } __union_ftsent; -#define fts_number __union_ftsent.__struct_ftsent.__fts_number -#define fts_pointer __union_ftsent.__struct_ftsent.__fts_pointer -#define fts_bignum __union_ftsent.__fts_bignum + long long fts_number; /* local numeric value */ +#define fts_bignum fts_number /* XXX non-std, should go away */ + void *fts_pointer; /* local address value */ char *fts_accpath; /* access path */ char *fts_path; /* root path */ int fts_errno; /* errno for this node */ int fts_symfd; /* fd for symlink */ - u_short fts_pathlen; /* strlen(fts_path) */ - u_short fts_namelen; /* strlen(fts_name) */ + size_t fts_pathlen; /* strlen(fts_path) */ + size_t fts_namelen; /* strlen(fts_name) */ - ino_t fts_ino; /* inode */ + uint32_t fts_ino; /* inode */ dev_t fts_dev; /* device */ - nlink_t fts_nlink; /* link count */ + uint16_t fts_nlink; /* link count */ #define FTS_ROOTPARENTLEVEL -1 #define FTS_ROOTLEVEL 0 - short fts_level; /* depth (-1 to N) */ + long fts_level; /* depth (-1 to N) */ #define FTS_D 1 /* preorder directory */ #define FTS_DC 2 /* directory that causes cycles */ @@ -108,25 +97,34 @@ #define FTS_SL 12 /* symbolic link */ #define FTS_SLNONE 13 /* symbolic link without target */ #define FTS_W 14 /* whiteout object */ - u_short fts_info; /* user flags for FTSENT structure */ + int fts_info; /* user status for FTSENT structure */ #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ #define FTS_ISW 0x04 /* this is a whiteout object */ - u_short fts_flags; /* private flags for FTSENT structure */ + unsigned fts_flags; /* private flags for FTSENT structure */ #define FTS_AGAIN 1 /* read node again */ #define FTS_FOLLOW 2 /* follow symbolic link */ #define FTS_NOINSTR 3 /* no instructions */ #define FTS_SKIP 4 /* discard node */ - u_short fts_instr; /* fts_set() instructions */ + int fts_instr; /* fts_set() instructions */ - struct stat *fts_statp; /* stat(2) information */ + struct freebsd8_stat *fts_statp; /* stat(2) information */ char *fts_name; /* file name */ FTS *fts_fts; /* back pointer to main FTS */ } FTSENT; -#define fts_get_clientptr(fts) ((fts)->fts_clientptr) -#define fts_get_stream(ftsent) ((ftsent)->fts_fts) +FTSENT *freebsd8_fts_children(FTS *, int); +int freebsd8_fts_close(FTS *); +void *freebsd8_fts_get_clientptr(FTS *); +#define freebsd8_fts_get_clientptr(fts) ((fts)->fts_clientptr) +FTS *freebsd8_fts_get_stream(FTSENT *); +#define freebsd8_fts_get_stream(ftsent) ((ftsent)->fts_fts) +FTS *freebsd8_fts_open(char * const *, int, + int (*)(const FTSENT * const *, const FTSENT * const *)); +FTSENT *freebsd8_fts_read(FTS *); +int freebsd8_fts_set(FTS *, FTSENT *, int); +void freebsd8_fts_set_clientptr(FTS *, void *); #endif /* !_FTS_H_ */ Added: soc2011/gk/ino64-head/lib/libc/gen/ftw-compat8.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/gk/ino64-head/lib/libc/gen/ftw-compat8.c Fri Jun 17 22:30:42 2011 (r223373) @@ -0,0 +1,102 @@ +/* $OpenBSD: ftw.c,v 1.4 2004/07/07 16:05:23 millert Exp $ */ + +/* + * Copyright (c) 2003, 2004 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = "$OpenBSD: ftw.c,v 1.4 2004/07/07 16:05:23 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "fts-compat8.h" + +int +freebsd8_ftw(const char *path, + int (*fn)(const char *, const struct freebsd8_stat *, int), int nfds) +{ + char * const paths[2] = { (char *)path, NULL }; + FTSENT *cur; + FTS *ftsp; + int error = 0, fnflag, sverrno; + + /* XXX - nfds is currently unused */ + if (nfds < 1 || nfds > OPEN_MAX) { + errno = EINVAL; + return (-1); + } + + ftsp = freebsd8_fts_open(paths, + FTS_LOGICAL | FTS_COMFOLLOW | FTS_NOCHDIR, NULL); + if (ftsp == NULL) + return (-1); + while ((cur = freebsd8_fts_read(ftsp)) != NULL) { + switch (cur->fts_info) { + case FTS_D: + fnflag = FTW_D; + break; + case FTS_DNR: + fnflag = FTW_DNR; + break; + case FTS_DP: + /* we only visit in preorder */ + continue; + case FTS_F: + case FTS_DEFAULT: + fnflag = FTW_F; + break; + case FTS_NS: + case FTS_NSOK: + case FTS_SLNONE: + fnflag = FTW_NS; + break; + case FTS_SL: + fnflag = FTW_SL; + break; + case FTS_DC: + errno = ELOOP; + /* FALLTHROUGH */ + default: + error = -1; + goto done; + } + error = fn(cur->fts_path, cur->fts_statp, fnflag); + if (error != 0) + break; + } +done: + sverrno = errno; + if (freebsd8_fts_close(ftsp) != 0 && error == 0) + error = -1; + else + errno = sverrno; + return (error); +} + +__sym_compat(ftw, freebsd8_ftw, FBSD_1.0); Added: soc2011/gk/ino64-head/lib/libc/gen/nftw-compat8.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2011/gk/ino64-head/lib/libc/gen/nftw-compat8.c Fri Jun 17 22:30:42 2011 (r223373) @@ -0,0 +1,121 @@ +/* $OpenBSD: nftw.c,v 1.4 2004/07/07 16:05:23 millert Exp $ */ + +/* + * Copyright (c) 2003, 2004 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = "$OpenBSD: nftw.c,v 1.4 2004/07/07 16:05:23 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ +#endif + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include + +#include "fts-compat8.h" + +int +freebsd8_nftw(const char *path, + int (*fn)(const char *, const struct freebsd8_stat *, int, struct FTW *), + int nfds, int ftwflags) +{ + char * const paths[2] = { (char *)path, NULL }; + struct FTW ftw; + FTSENT *cur; + FTS *ftsp; + int error = 0, ftsflags, fnflag, postorder, sverrno; + + /* XXX - nfds is currently unused */ + if (nfds < 1 || nfds > OPEN_MAX) { + errno = EINVAL; + return (-1); + } + + ftsflags = FTS_COMFOLLOW; + if (!(ftwflags & FTW_CHDIR)) + ftsflags |= FTS_NOCHDIR; + if (ftwflags & FTW_MOUNT) + ftsflags |= FTS_XDEV; + if (ftwflags & FTW_PHYS) + ftsflags |= FTS_PHYSICAL; + else + ftsflags |= FTS_LOGICAL; + postorder = (ftwflags & FTW_DEPTH) != 0; + ftsp = freebsd8_fts_open(paths, ftsflags, NULL); + if (ftsp == NULL) + return (-1); + while ((cur = freebsd8_fts_read(ftsp)) != NULL) { + switch (cur->fts_info) { + case FTS_D: + if (postorder) + continue; + fnflag = FTW_D; + break; + case FTS_DNR: + fnflag = FTW_DNR; + break; + case FTS_DP: + if (!postorder) + continue; + fnflag = FTW_DP; + break; + case FTS_F: + case FTS_DEFAULT: + fnflag = FTW_F; + break; + case FTS_NS: + case FTS_NSOK: + fnflag = FTW_NS; + break; + case FTS_SL: + fnflag = FTW_SL; + break; + case FTS_SLNONE: + fnflag = FTW_SLN; + break; + case FTS_DC: + errno = ELOOP; + /* FALLTHROUGH */ + default: + error = -1; + goto done; + } + ftw.base = cur->fts_pathlen - cur->fts_namelen; + ftw.level = cur->fts_level; + error = fn(cur->fts_path, cur->fts_statp, fnflag, &ftw); + if (error != 0) + break; + } +done: + sverrno = errno; + if (freebsd8_fts_close(ftsp) != 0 && error == 0) + error = -1; + else + errno = sverrno; + return (error); +} + +__sym_compat(nftw, freebsd8_nftw, FBSD_1.0);