Deleted Added
full compact
vfs_lookup.c (29041) vfs_lookup.c (29653)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vfs_lookup.c 8.4 (Berkeley) 2/16/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vfs_lookup.c 8.4 (Berkeley) 2/16/94
39 * $Id: vfs_lookup.c,v 1.18 1997/04/04 17:47:43 dfr Exp $
39 * $Id: vfs_lookup.c,v 1.19 1997/09/02 20:06:01 bde Exp $
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/namei.h>
47#include <sys/vnode.h>

--- 50 unchanged lines hidden (view full) ---

98#endif
99 fdp = cnp->cn_proc->p_fd;
100
101 /*
102 * Get a buffer for the name to be translated, and copy the
103 * name into the buffer.
104 */
105 if ((cnp->cn_flags & HASBUF) == 0)
40 */
41
42#include "opt_ktrace.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/namei.h>
47#include <sys/vnode.h>

--- 50 unchanged lines hidden (view full) ---

98#endif
99 fdp = cnp->cn_proc->p_fd;
100
101 /*
102 * Get a buffer for the name to be translated, and copy the
103 * name into the buffer.
104 */
105 if ((cnp->cn_flags & HASBUF) == 0)
106 MALLOC(cnp->cn_pnbuf, caddr_t, MAXPATHLEN, M_NAMEI, M_WAITOK);
106 cnp->cn_pnbuf = zalloc(namei_zone);
107 if (ndp->ni_segflg == UIO_SYSSPACE)
108 error = copystr(ndp->ni_dirp, cnp->cn_pnbuf,
109 MAXPATHLEN, (u_int *)&ndp->ni_pathlen);
110 else
111 error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf,
112 MAXPATHLEN, (u_int *)&ndp->ni_pathlen);
113
114 /*
115 * Don't allow empty pathnames.
116 */
117 if (!error && *cnp->cn_pnbuf == '\0')
118 error = ENOENT;
119
120 if (error) {
107 if (ndp->ni_segflg == UIO_SYSSPACE)
108 error = copystr(ndp->ni_dirp, cnp->cn_pnbuf,
109 MAXPATHLEN, (u_int *)&ndp->ni_pathlen);
110 else
111 error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf,
112 MAXPATHLEN, (u_int *)&ndp->ni_pathlen);
113
114 /*
115 * Don't allow empty pathnames.
116 */
117 if (!error && *cnp->cn_pnbuf == '\0')
118 error = ENOENT;
119
120 if (error) {
121 free(cnp->cn_pnbuf, M_NAMEI);
121 zfree(namei_zone, cnp->cn_pnbuf);
122 ndp->ni_vp = NULL;
123 return (error);
124 }
125 ndp->ni_loopcnt = 0;
126#ifdef KTRACE
127 if (KTRPOINT(cnp->cn_proc, KTR_NAMEI))
128 ktrnamei(cnp->cn_proc->p_tracep, cnp->cn_pnbuf);
129#endif

--- 18 unchanged lines hidden (view full) ---

148 ndp->ni_pathlen--;
149 }
150 dp = ndp->ni_rootdir;
151 VREF(dp);
152 }
153 ndp->ni_startdir = dp;
154 error = lookup(ndp);
155 if (error) {
122 ndp->ni_vp = NULL;
123 return (error);
124 }
125 ndp->ni_loopcnt = 0;
126#ifdef KTRACE
127 if (KTRPOINT(cnp->cn_proc, KTR_NAMEI))
128 ktrnamei(cnp->cn_proc->p_tracep, cnp->cn_pnbuf);
129#endif

--- 18 unchanged lines hidden (view full) ---

148 ndp->ni_pathlen--;
149 }
150 dp = ndp->ni_rootdir;
151 VREF(dp);
152 }
153 ndp->ni_startdir = dp;
154 error = lookup(ndp);
155 if (error) {
156 FREE(cnp->cn_pnbuf, M_NAMEI);
156 zfree(namei_zone, cnp->cn_pnbuf);
157 return (error);
158 }
159 /*
160 * Check for symbolic link
161 */
162 if ((cnp->cn_flags & ISSYMLINK) == 0) {
163 if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0)
157 return (error);
158 }
159 /*
160 * Check for symbolic link
161 */
162 if ((cnp->cn_flags & ISSYMLINK) == 0) {
163 if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0)
164 FREE(cnp->cn_pnbuf, M_NAMEI);
164 zfree(namei_zone, cnp->cn_pnbuf);
165 else
166 cnp->cn_flags |= HASBUF;
167 return (0);
168 }
169 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
170 VOP_UNLOCK(ndp->ni_dvp, 0, p);
171 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
172 error = ELOOP;
173 break;
174 }
175 if (ndp->ni_pathlen > 1)
165 else
166 cnp->cn_flags |= HASBUF;
167 return (0);
168 }
169 if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
170 VOP_UNLOCK(ndp->ni_dvp, 0, p);
171 if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
172 error = ELOOP;
173 break;
174 }
175 if (ndp->ni_pathlen > 1)
176 MALLOC(cp, char *, MAXPATHLEN, M_NAMEI, M_WAITOK);
176 cp = zalloc(namei_zone);
177 else
178 cp = cnp->cn_pnbuf;
179 aiov.iov_base = cp;
180 aiov.iov_len = MAXPATHLEN;
181 auio.uio_iov = &aiov;
182 auio.uio_iovcnt = 1;
183 auio.uio_offset = 0;
184 auio.uio_rw = UIO_READ;
185 auio.uio_segflg = UIO_SYSSPACE;
186 auio.uio_procp = (struct proc *)0;
187 auio.uio_resid = MAXPATHLEN;
188 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
189 if (error) {
190 if (ndp->ni_pathlen > 1)
177 else
178 cp = cnp->cn_pnbuf;
179 aiov.iov_base = cp;
180 aiov.iov_len = MAXPATHLEN;
181 auio.uio_iov = &aiov;
182 auio.uio_iovcnt = 1;
183 auio.uio_offset = 0;
184 auio.uio_rw = UIO_READ;
185 auio.uio_segflg = UIO_SYSSPACE;
186 auio.uio_procp = (struct proc *)0;
187 auio.uio_resid = MAXPATHLEN;
188 error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
189 if (error) {
190 if (ndp->ni_pathlen > 1)
191 free(cp, M_NAMEI);
191 zfree(namei_zone, cp);
192 break;
193 }
194 linklen = MAXPATHLEN - auio.uio_resid;
195 if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
196 if (ndp->ni_pathlen > 1)
192 break;
193 }
194 linklen = MAXPATHLEN - auio.uio_resid;
195 if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
196 if (ndp->ni_pathlen > 1)
197 free(cp, M_NAMEI);
197 zfree(namei_zone, cp);
198 error = ENAMETOOLONG;
199 break;
200 }
201 if (ndp->ni_pathlen > 1) {
202 bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
198 error = ENAMETOOLONG;
199 break;
200 }
201 if (ndp->ni_pathlen > 1) {
202 bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
203 FREE(cnp->cn_pnbuf, M_NAMEI);
203 zfree(namei_zone, cnp->cn_pnbuf);
204 cnp->cn_pnbuf = cp;
205 } else
206 cnp->cn_pnbuf[linklen] = '\0';
207 ndp->ni_pathlen += linklen;
208 vput(ndp->ni_vp);
209 dp = ndp->ni_dvp;
210 }
204 cnp->cn_pnbuf = cp;
205 } else
206 cnp->cn_pnbuf[linklen] = '\0';
207 ndp->ni_pathlen += linklen;
208 vput(ndp->ni_vp);
209 dp = ndp->ni_dvp;
210 }
211 FREE(cnp->cn_pnbuf, M_NAMEI);
211 zfree(namei_zone, cnp->cn_pnbuf);
212 vrele(ndp->ni_dvp);
213 vput(ndp->ni_vp);
214 ndp->ni_vp = NULL;
215 return (error);
216}
217
218/*
219 * Search a pathname.

--- 478 unchanged lines hidden ---
212 vrele(ndp->ni_dvp);
213 vput(ndp->ni_vp);
214 ndp->ni_vp = NULL;
215 return (error);
216}
217
218/*
219 * Search a pathname.

--- 478 unchanged lines hidden ---