The branch main has been updated by dchagin:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=07c0b6e535c5c5bdbbb562a04e21a1a4d039b942

commit 07c0b6e535c5c5bdbbb562a04e21a1a4d039b942
Author:     Dmitry Chagin <[email protected]>
AuthorDate: 2023-05-29 08:19:41 +0000
Commit:     Dmitry Chagin <[email protected]>
CommitDate: 2023-05-29 08:19:41 +0000

    vfs: Retire kern_alternate_path() as unused anymore
    
    From now a non-native ABI should use pwd_altroot() ability to tell
    to the namei() its root directory to dynamically reroots lookups.
    
    Differential Revision:  https://reviews.freebsd.org/D40093
    MFC after:              2 month
---
 sys/kern/vfs_lookup.c | 114 --------------------------------------------------
 sys/sys/syscallsubr.h |   2 -
 2 files changed, 116 deletions(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index 593e1e487c6f..c813296b4931 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -1597,117 +1597,3 @@ NDVALIDATE_impl(struct nameidata *ndp, int line)
 }
 
 #endif
-
-/*
- * Determine if there is a suitable alternate filename under the specified
- * prefix for the specified path.  If the create flag is set, then the
- * alternate prefix will be used so long as the parent directory exists.
- * This is used by the various compatibility ABIs so that Linux binaries prefer
- * files under /compat/linux for example.  The chosen path (whether under
- * the prefix or under /) is returned in a kernel malloc'd buffer pointed
- * to by pathbuf.  The caller is responsible for free'ing the buffer from
- * the M_TEMP bucket if one is returned.
- */
-int
-kern_alternate_path(const char *prefix, const char *path, enum uio_seg pathseg,
-    char **pathbuf, int create, int dirfd)
-{
-       struct nameidata nd, ndroot;
-       char *ptr, *buf, *cp;
-       size_t len, sz;
-       int error;
-
-       buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
-       *pathbuf = buf;
-
-       /* Copy the prefix into the new pathname as a starting point. */
-       len = strlcpy(buf, prefix, MAXPATHLEN);
-       if (len >= MAXPATHLEN) {
-               *pathbuf = NULL;
-               free(buf, M_TEMP);
-               return (EINVAL);
-       }
-       sz = MAXPATHLEN - len;
-       ptr = buf + len;
-
-       /* Append the filename to the prefix. */
-       if (pathseg == UIO_SYSSPACE)
-               error = copystr(path, ptr, sz, &len);
-       else
-               error = copyinstr(path, ptr, sz, &len);
-
-       if (error) {
-               *pathbuf = NULL;
-               free(buf, M_TEMP);
-               return (error);
-       }
-
-       /* Only use a prefix with absolute pathnames. */
-       if (*ptr != '/') {
-               error = EINVAL;
-               goto keeporig;
-       }
-
-       if (dirfd != AT_FDCWD) {
-               /*
-                * We want the original because the "prefix" is
-                * included in the already opened dirfd.
-                */
-               bcopy(ptr, buf, len);
-               return (0);
-       }
-
-       /*
-        * We know that there is a / somewhere in this pathname.
-        * Search backwards for it, to find the file's parent dir
-        * to see if it exists in the alternate tree. If it does,
-        * and we want to create a file (cflag is set). We don't
-        * need to worry about the root comparison in this case.
-        */
-
-       if (create) {
-               for (cp = &ptr[len] - 1; *cp != '/'; cp--);
-               *cp = '\0';
-
-               NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, buf);
-               error = namei(&nd);
-               *cp = '/';
-               if (error != 0)
-                       goto keeporig;
-       } else {
-               NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, buf);
-
-               error = namei(&nd);
-               if (error != 0)
-                       goto keeporig;
-
-               /*
-                * We now compare the vnode of the prefix to the one
-                * vnode asked. If they resolve to be the same, then we
-                * ignore the match so that the real root gets used.
-                * This avoids the problem of traversing "../.." to find the
-                * root directory and never finding it, because "/" resolves
-                * to the emulation root directory. This is expensive :-(
-                */
-               NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, prefix);
-
-               /* We shouldn't ever get an error from this namei(). */
-               error = namei(&ndroot);
-               if (error == 0) {
-                       if (nd.ni_vp == ndroot.ni_vp)
-                               error = ENOENT;
-
-                       NDFREE_PNBUF(&ndroot);
-                       vrele(ndroot.ni_vp);
-               }
-       }
-
-       NDFREE_PNBUF(&nd);
-       vrele(nd.ni_vp);
-
-keeporig:
-       /* If there was an error, use the original path name. */
-       if (error)
-               bcopy(ptr, buf, len);
-       return (error);
-}
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 9486135b9ce2..64f1b16f92b9 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -94,8 +94,6 @@ int   kern_accessat(struct thread *td, int fd, const char 
*path,
            enum uio_seg pathseg, int flags, int mode);
 int    kern_adjtime(struct thread *td, struct timeval *delta,
            struct timeval *olddelta);
-int    kern_alternate_path(const char *prefix, const char *path,
-           enum uio_seg pathseg, char **pathbuf, int create, int dirfd);
 int    kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa);
 int    kern_break(struct thread *td, uintptr_t *addr);
 int    kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds,

Reply via email to