/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* This file contains the file lookup code for NFS.
*/
#include "brpc.h"
#include "clnt.h"
#include <st_pathname.h>
#include "nfs_inet.h"
#include "socket_inet.h"
#include <rpcsvc/nfs_prot.h>
#include <rpcsvc/nfs4_prot.h>
#include <sys/bootdebug.h>
#include "mac.h"
/*
* starting at current directory (root for us), lookup the pathname.
* return the file handle of said file.
*/
/*
* For NFSv4 we may be calling lookup in the context of evaluating the
* root path. In this case we set needroothandle to TRUE.
*/
int
{
int error;
if (error)
return (error);
return (error);
}
static int
{
int nlink = 0;
int error = 0;
/*
* Each time we begin a new name interpretation (e.g.
* when first called and after each symbolic link is
* substituted), we allow the search to start at the
* root directory if the name starts with a '/', otherwise
* continuing from the current directory.
*/
component[0] = '\0';
if (!needroothandle)
*cfile = roothandle;
}
next:
/*
* Make sure we have a directory.
*/
if (!cfile_is_dir(cfile)) {
goto bad;
}
/*
* Process the next component of the pathname.
*/
if (error)
goto bad;
/*
* Check for degenerate name (e.g. / or "")
* which is a way of talking about a directory,
* e.g. "/." or ".".
*/
if (component[0] == '\0')
return (0);
/*
* Handle "..": two special cases.
* 1. If at root directory (e.g. after chroot)
* then ignore it so can't get out.
* 2. If this vnode is the root of a mounted
* file system, then replace it with the
* vnode which was mounted on so we take the
* .. in the other file system.
*/
if (cfile == &roothandle)
goto skip;
}
/*
* Perform a lookup in the current directory.
* We create a simple negative lookup cache by storing
* inode -1 to indicate file not found.
*/
if (cino == -1)
return (ENOENT);
#ifdef DEBUG
#endif
if ((cino == 0) ||
/*
* If an RPC error occurs, error is not changed,
* else it is the NFS error if NULL is returned.
*/
error = -1;
case NFS_VERSION:
break;
case NFS_V3:
break;
case NFS_V4:
break;
default:
printf("lookup: NFS Version %d not supported\n",
break;
}
/*
* Check for RPC error
*/
if (error == -1) {
printf("lookup: lookup RPC error\n");
return (error);
}
/*
* Check for NFS error
*/
if ((error != NFSERR_NOENT) &&
(error != NFS3ERR_NOENT) &&
(error != NFS4ERR_NOENT)) {
#ifdef DEBUG
#endif
return (error);
}
#ifdef DEBUG
#endif
/*
* File not found so set cached inode to -1
*/
return (error);
}
bkmem_alloc(sizeof (struct nfs_file))) {
/*
* Save this entry in cache for next time ...
*/
if (!cino)
sizeof (struct nfs_file));
} else {
/*
* Out of memory, clear cache keys so we don't get
* confused later.
*/
cino = 0;
}
}
/*
* If we hit a symbolic link and there is more path to be
* translated or this operation does not wish to apply
* to a link, then place the contents of the link at the
* front of the remaining pathname.
*/
if (cfile_is_lnk(cdp)) {
char *pathp;
nlink++;
if (nlink > MAXSYMLINKS) {
goto bad;
}
case NFS_VERSION:
break;
case NFS_V3:
break;
case NFS_V4:
break;
default:
printf("getsymlink: NFS Version %d not supported\n",
break;
}
if (error)
goto bad;
if (stpn_pathleft(&linkpath) == 0)
if (error)
goto bad;
goto begin;
}
if (needroothandle) {
roothandle = *cdp;
}
skip:
/*
* Skip to next component of the pathname.
* If no more components, return last directory (if wanted) and
* last component (if wanted).
*/
if (stpn_pathleft(pnp) == 0) {
return (0);
}
/*
* skip over slashes from end of last component
*/
goto next;
bad:
/*
* Error.
*/
return (error);
}