1 /*
2 * Copyright (c) 1999, 2000, 2001 Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: releng/5.0/sys/fs/nwfs/nwfs_vnops.c 103936 2002-09-25 02:32:42Z jeff $
33 */
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/namei.h>
37 #include <sys/kernel.h>
38 #include <sys/bio.h>
39 #include <sys/buf.h>
40 #include <sys/fcntl.h>
41 #include <sys/mount.h>
42 #include <sys/unistd.h>
43 #include <sys/vnode.h>
44
45 #include <vm/vm.h>
46 #include <vm/vm_extern.h>
47
48 #include <machine/mutex.h>
49
50 #include <netncp/ncp.h>
51 #include <netncp/ncp_conn.h>
52 #include <netncp/ncp_subr.h>
53 #include <netncp/nwerror.h>
54 #include <netncp/ncp_nls.h>
55
56 #include <fs/nwfs/nwfs.h>
57 #include <fs/nwfs/nwfs_node.h>
58 #include <fs/nwfs/nwfs_subr.h>
59
60 /*
61 * Prototypes for NWFS vnode operations
62 */
63 static int nwfs_create(struct vop_create_args *);
64 static int nwfs_mknod(struct vop_mknod_args *);
65 static int nwfs_open(struct vop_open_args *);
66 static int nwfs_close(struct vop_close_args *);
67 static int nwfs_access(struct vop_access_args *);
68 static int nwfs_getattr(struct vop_getattr_args *);
69 static int nwfs_setattr(struct vop_setattr_args *);
70 static int nwfs_read(struct vop_read_args *);
71 static int nwfs_write(struct vop_write_args *);
72 static int nwfs_fsync(struct vop_fsync_args *);
73 static int nwfs_remove(struct vop_remove_args *);
74 static int nwfs_link(struct vop_link_args *);
75 static int nwfs_lookup(struct vop_lookup_args *);
76 static int nwfs_rename(struct vop_rename_args *);
77 static int nwfs_mkdir(struct vop_mkdir_args *);
78 static int nwfs_rmdir(struct vop_rmdir_args *);
79 static int nwfs_symlink(struct vop_symlink_args *);
80 static int nwfs_readdir(struct vop_readdir_args *);
81 static int nwfs_strategy(struct vop_strategy_args *);
82 static int nwfs_print(struct vop_print_args *);
83 static int nwfs_pathconf(struct vop_pathconf_args *ap);
84
85 /* Global vfs data structures for nwfs */
86 vop_t **nwfs_vnodeop_p;
87 static struct vnodeopv_entry_desc nwfs_vnodeop_entries[] = {
88 { &vop_default_desc, (vop_t *) vop_defaultop },
89 { &vop_access_desc, (vop_t *) nwfs_access },
90 { &vop_open_desc, (vop_t *) nwfs_open },
91 { &vop_close_desc, (vop_t *) nwfs_close },
92 { &vop_create_desc, (vop_t *) nwfs_create },
93 { &vop_fsync_desc, (vop_t *) nwfs_fsync },
94 { &vop_getattr_desc, (vop_t *) nwfs_getattr },
95 { &vop_getpages_desc, (vop_t *) nwfs_getpages },
96 { &vop_putpages_desc, (vop_t *) nwfs_putpages },
97 { &vop_ioctl_desc, (vop_t *) nwfs_ioctl },
98 { &vop_inactive_desc, (vop_t *) nwfs_inactive },
99 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
100 { &vop_link_desc, (vop_t *) nwfs_link },
101 { &vop_lock_desc, (vop_t *) vop_stdlock },
102 { &vop_lookup_desc, (vop_t *) nwfs_lookup },
103 { &vop_mkdir_desc, (vop_t *) nwfs_mkdir },
104 { &vop_mknod_desc, (vop_t *) nwfs_mknod },
105 { &vop_pathconf_desc, (vop_t *) nwfs_pathconf },
106 { &vop_print_desc, (vop_t *) nwfs_print },
107 { &vop_read_desc, (vop_t *) nwfs_read },
108 { &vop_readdir_desc, (vop_t *) nwfs_readdir },
109 { &vop_reclaim_desc, (vop_t *) nwfs_reclaim },
110 { &vop_remove_desc, (vop_t *) nwfs_remove },
111 { &vop_rename_desc, (vop_t *) nwfs_rename },
112 { &vop_rmdir_desc, (vop_t *) nwfs_rmdir },
113 { &vop_setattr_desc, (vop_t *) nwfs_setattr },
114 { &vop_strategy_desc, (vop_t *) nwfs_strategy },
115 { &vop_symlink_desc, (vop_t *) nwfs_symlink },
116 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
117 { &vop_write_desc, (vop_t *) nwfs_write },
118 { NULL, NULL }
119 };
120 static struct vnodeopv_desc nwfs_vnodeop_opv_desc =
121 { &nwfs_vnodeop_p, nwfs_vnodeop_entries };
122
123 VNODEOP_SET(nwfs_vnodeop_opv_desc);
124
125 /*
126 * nwfs_access vnode op
127 * for now just return ok
128 */
129 static int
130 nwfs_access(ap)
131 struct vop_access_args /* {
132 struct vnode *a_vp;
133 int a_mode;
134 struct ucred *a_cred;
135 struct thread *td;
136 } */ *ap;
137 {
138 struct vnode *vp = ap->a_vp;
139 struct ucred *cred = ap->a_cred;
140 u_int mode = ap->a_mode;
141 struct nwmount *nmp = VTONWFS(vp);
142 int error = 0;
143
144 NCPVNDEBUG("\n");
145 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
146 switch (vp->v_type) {
147 case VREG: case VDIR: case VLNK:
148 return (EROFS);
149 default:
150 break;
151 }
152 }
153 if (cred->cr_uid == 0)
154 return 0;
155 if (cred->cr_uid != nmp->m.uid) {
156 mode >>= 3;
157 if (!groupmember(nmp->m.gid, cred))
158 mode >>= 3;
159 }
160 error = (((vp->v_type == VREG) ? nmp->m.file_mode : nmp->m.dir_mode) & mode) == mode ? 0 : EACCES;
161 return error;
162 }
163 /*
164 * nwfs_open vnode op
165 */
166 /* ARGSUSED */
167 static int
168 nwfs_open(ap)
169 struct vop_open_args /* {
170 struct vnode *a_vp;
171 int a_mode;
172 struct ucred *a_cred;
173 struct thread *td;
174 } */ *ap;
175 {
176 struct vnode *vp = ap->a_vp;
177 int mode = ap->a_mode;
178 struct nwnode *np = VTONW(vp);
179 struct ncp_open_info no;
180 struct nwmount *nmp = VTONWFS(vp);
181 struct vattr vattr;
182 int error, nwm;
183
184 NCPVNDEBUG("%s,%d\n", np->n_name, np->opened);
185 if (vp->v_type != VREG && vp->v_type != VDIR) {
186 NCPFATAL("open vtype = %d\n", vp->v_type);
187 return (EACCES);
188 }
189 if (vp->v_type == VDIR) return 0; /* nothing to do now */
190 if (np->n_flag & NMODIFIED) {
191 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1)) == EINTR)
192 return (error);
193 np->n_atime = 0;
194 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
195 if (error) return (error);
196 np->n_mtime = vattr.va_mtime.tv_sec;
197 } else {
198 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
199 if (error) return (error);
200 if (np->n_mtime != vattr.va_mtime.tv_sec) {
201 if ((error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1)) == EINTR)
202 return (error);
203 np->n_mtime = vattr.va_mtime.tv_sec;
204 }
205 }
206 if (np->opened) {
207 np->opened++;
208 return 0;
209 }
210 nwm = AR_READ;
211 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
212 nwm |= AR_WRITE;
213 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
214 0, nwm, &no, ap->a_td, ap->a_cred);
215 if (error) {
216 if (mode & FWRITE)
217 return EACCES;
218 nwm = AR_READ;
219 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
220 nwm, &no, ap->a_td, ap->a_cred);
221 }
222 if (!error) {
223 np->opened++;
224 np->n_fh = no.fh;
225 np->n_origfh = no.origfh;
226 }
227 np->n_atime = 0;
228 return (error);
229 }
230
231 static int
232 nwfs_close(ap)
233 struct vop_close_args /* {
234 struct vnodeop_desc *a_desc;
235 struct vnode *a_vp;
236 int a_fflag;
237 struct ucred *a_cred;
238 struct thread *td;
239 } */ *ap;
240 {
241 struct vnode *vp = ap->a_vp;
242 struct nwnode *np = VTONW(vp);
243 int error;
244
245 NCPVNDEBUG("name=%s,pid=%d,c=%d\n", np->n_name, ap->a_td->td_proc->p_pid,
246 np->opened);
247
248 if (vp->v_type == VDIR) return 0; /* nothing to do now */
249 error = 0;
250 mtx_lock(&vp->v_interlock);
251 if (np->opened == 0) {
252 mtx_unlock(&vp->v_interlock);
253 return 0;
254 }
255 mtx_unlock(&vp->v_interlock);
256 error = nwfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1);
257 mtx_lock(&vp->v_interlock);
258 if (np->opened == 0) {
259 mtx_unlock(&vp->v_interlock);
260 return 0;
261 }
262 if (--np->opened == 0) {
263 mtx_unlock(&vp->v_interlock);
264 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
265 ap->a_td, ap->a_cred);
266 } else
267 mtx_unlock(&vp->v_interlock);
268 np->n_atime = 0;
269 return (error);
270 }
271
272 /*
273 * nwfs_getattr call from vfs.
274 */
275 static int
276 nwfs_getattr(ap)
277 struct vop_getattr_args /* {
278 struct vnode *a_vp;
279 struct vattr *a_vap;
280 struct ucred *a_cred;
281 struct thread *td;
282 } */ *ap;
283 {
284 struct vnode *vp = ap->a_vp;
285 struct nwnode *np = VTONW(vp);
286 struct vattr *va=ap->a_vap;
287 struct nwmount *nmp = VTONWFS(vp);
288 struct nw_entry_info fattr;
289 int error;
290 u_int32_t oldsize;
291
292 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
293 error = nwfs_attr_cachelookup(vp, va);
294 if (!error) return 0;
295 NCPVNDEBUG("not in cache\n");
296 oldsize = np->n_size;
297 if (np->n_flag & NVOLUME) {
298 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
299 ap->a_td, ap->a_cred);
300 } else {
301 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
302 np->n_name, &fattr, ap->a_td, ap->a_cred);
303 }
304 if (error) {
305 NCPVNDEBUG("error %d\n", error);
306 return error;
307 }
308 nwfs_attr_cacheenter(vp, &fattr);
309 *va = np->n_vattr;
310 if (np->opened)
311 np->n_size = oldsize;
312 return (0);
313 }
314 /*
315 * nwfs_setattr call from vfs.
316 */
317 static int
318 nwfs_setattr(ap)
319 struct vop_setattr_args /* {
320 struct vnode *a_vp;
321 struct vattr *a_vap;
322 struct ucred *a_cred;
323 struct thread *td;
324 } */ *ap;
325 {
326 struct vnode *vp = ap->a_vp;
327 struct nwnode *np = VTONW(vp);
328 struct vattr *vap = ap->a_vap;
329 u_quad_t tsize=0;
330 int error = 0;
331
332 NCPVNDEBUG("\n");
333 if (vap->va_flags != VNOVAL)
334 return (EOPNOTSUPP);
335 /*
336 * Disallow write attempts if the filesystem is mounted read-only.
337 */
338 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
339 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
340 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
341 return (EROFS);
342 if (vap->va_size != VNOVAL) {
343 switch (vp->v_type) {
344 case VDIR:
345 return (EISDIR);
346 case VREG:
347 /*
348 * Disallow write attempts if the filesystem is
349 * mounted read-only.
350 */
351 if (vp->v_mount->mnt_flag & MNT_RDONLY)
352 return (EROFS);
353 vnode_pager_setsize(vp, (u_long)vap->va_size);
354 tsize = np->n_size;
355 np->n_size = vap->va_size;
356 break;
357 default:
358 return EINVAL;
359 };
360 }
361 error = ncp_setattr(vp, vap, ap->a_cred, ap->a_td);
362 if (error && vap->va_size != VNOVAL) {
363 np->n_size = tsize;
364 vnode_pager_setsize(vp, (u_long)tsize);
365 }
366 np->n_atime = 0; /* invalidate cache */
367 VOP_GETATTR(vp, vap, ap->a_cred, ap->a_td);
368 np->n_mtime = vap->va_mtime.tv_sec;
369 return (0);
370 }
371 /*
372 * nwfs_read call.
373 */
374 static int
375 nwfs_read(ap)
376 struct vop_read_args /* {
377 struct vnode *a_vp;
378 struct uio *a_uio;
379 int a_ioflag;
380 struct ucred *a_cred;
381 } */ *ap;
382 {
383 struct vnode *vp = ap->a_vp;
384 struct uio *uio=ap->a_uio;
385 int error;
386 NCPVNDEBUG("nwfs_read:\n");
387
388 if (vp->v_type != VREG && vp->v_type != VDIR)
389 return (EPERM);
390 error = nwfs_readvnode(vp, uio, ap->a_cred);
391 return error;
392 }
393
394 static int
395 nwfs_write(ap)
396 struct vop_write_args /* {
397 struct vnode *a_vp;
398 struct uio *a_uio;
399 int a_ioflag;
400 struct ucred *a_cred;
401 } */ *ap;
402 {
403 struct vnode *vp = ap->a_vp;
404 struct uio *uio = ap->a_uio;
405 int error;
406
407 NCPVNDEBUG("%d,ofs=%d,sz=%d\n", vp->v_type, (int)uio->uio_offset, uio->uio_resid);
408
409 if (vp->v_type != VREG)
410 return (EPERM);
411 error = nwfs_writevnode(vp, uio, ap->a_cred, ap->a_ioflag);
412 return(error);
413 }
414 /*
415 * nwfs_create call
416 * Create a regular file. On entry the directory to contain the file being
417 * created is locked. We must release before we return. We must also free
418 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
419 * only if the SAVESTART bit in cn_flags is clear on success.
420 */
421 static int
422 nwfs_create(ap)
423 struct vop_create_args /* {
424 struct vnode *a_dvp;
425 struct vnode **a_vpp;
426 struct componentname *a_cnp;
427 struct vattr *a_vap;
428 } */ *ap;
429 {
430 struct vnode *dvp = ap->a_dvp;
431 struct vattr *vap = ap->a_vap;
432 struct vnode **vpp=ap->a_vpp;
433 struct componentname *cnp = ap->a_cnp;
434 struct vnode *vp = (struct vnode *)0;
435 int error = 0, fmode;
436 struct vattr vattr;
437 struct nwnode *np;
438 struct ncp_open_info no;
439 struct nwmount *nmp=VTONWFS(dvp);
440 ncpfid fid;
441
442
443 NCPVNDEBUG("\n");
444 *vpp = NULL;
445 if (vap->va_type == VSOCK)
446 return (EOPNOTSUPP);
447 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
448 return (error);
449 }
450 fmode = AR_READ | AR_WRITE;
451 /* if (vap->va_vaflags & VA_EXCLUSIVE)
452 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
453
454 error = ncp_open_create_file_or_subdir(nmp, dvp, cnp->cn_namelen, cnp->cn_nameptr,
455 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
456 0, fmode, &no, cnp->cn_thread, cnp->cn_cred);
457 if (!error) {
458 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_thread, cnp->cn_cred);
459 fid.f_parent = VTONW(dvp)->n_fid.f_id;
460 fid.f_id = no.fattr.dirEntNum;
461 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
462 if (!error) {
463 np = VTONW(vp);
464 np->opened = 0;
465 *vpp = vp;
466 }
467 if (cnp->cn_flags & MAKEENTRY)
468 cache_enter(dvp, vp, cnp);
469 }
470 return (error);
471 }
472
473 /*
474 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
475 * NetWare doesn't allow delete/rename operations on an opened file.
476 */
477 static int
478 nwfs_remove(ap)
479 struct vop_remove_args /* {
480 struct vnodeop_desc *a_desc;
481 struct vnode * a_dvp;
482 struct vnode * a_vp;
483 struct componentname * a_cnp;
484 } */ *ap;
485 {
486 struct vnode *vp = ap->a_vp;
487 struct vnode *dvp = ap->a_dvp;
488 struct componentname *cnp = ap->a_cnp;
489 struct nwnode *np = VTONW(vp);
490 struct nwmount *nmp = VTONWFS(vp);
491 int error;
492
493 if (vp->v_type == VDIR || np->opened || vrefcnt(vp) != 1)
494 return EPERM;
495 cache_purge(vp);
496 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
497 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
498 if (error == 0)
499 np->n_flag |= NSHOULDFREE;
500 else if (error == 0x899c)
501 error = EACCES;
502 return (error);
503 }
504
505 /*
506 * nwfs_file rename call
507 */
508 static int
509 nwfs_rename(ap)
510 struct vop_rename_args /* {
511 struct vnode *a_fdvp;
512 struct vnode *a_fvp;
513 struct componentname *a_fcnp;
514 struct vnode *a_tdvp;
515 struct vnode *a_tvp;
516 struct componentname *a_tcnp;
517 } */ *ap;
518 {
519 struct vnode *fvp = ap->a_fvp;
520 struct vnode *tvp = ap->a_tvp;
521 struct vnode *fdvp = ap->a_fdvp;
522 struct vnode *tdvp = ap->a_tdvp;
523 struct componentname *tcnp = ap->a_tcnp;
524 struct componentname *fcnp = ap->a_fcnp;
525 struct nwmount *nmp=VTONWFS(fvp);
526 u_int16_t oldtype = 6;
527 int error=0;
528
529 /* Check for cross-device rename */
530 if ((fvp->v_mount != tdvp->v_mount) ||
531 (tvp && (fvp->v_mount != tvp->v_mount))) {
532 error = EXDEV;
533 goto out;
534 }
535
536 if (tvp && vrefcnt(tvp) > 1) {
537 error = EBUSY;
538 goto out;
539 }
540 if (tvp && tvp != fvp) {
541 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
542 tcnp->cn_namelen, tcnp->cn_nameptr,
543 tcnp->cn_thread, tcnp->cn_cred);
544 if (error == 0x899c) error = EACCES;
545 if (error)
546 goto out;
547 }
548 if (fvp->v_type == VDIR) {
549 oldtype |= NW_TYPE_SUBDIR;
550 } else if (fvp->v_type == VREG) {
551 oldtype |= NW_TYPE_FILE;
552 } else
553 return EINVAL;
554 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
555 oldtype, &nmp->m.nls,
556 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
557 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
558 tcnp->cn_thread, tcnp->cn_cred);
559
560 if (error == 0x8992)
561 error = EEXIST;
562 if (fvp->v_type == VDIR) {
563 if (tvp != NULL && tvp->v_type == VDIR)
564 cache_purge(tdvp);
565 cache_purge(fdvp);
566 }
567 out:
568 if (tdvp == tvp)
569 vrele(tdvp);
570 else
571 vput(tdvp);
572 if (tvp)
573 vput(tvp);
574 vrele(fdvp);
575 vrele(fvp);
576 nwfs_attr_cacheremove(fdvp);
577 nwfs_attr_cacheremove(tdvp);
578 nwfs_attr_cacheremove(fvp);
579 if (tvp)
580 nwfs_attr_cacheremove(tvp);
581 /*
582 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
583 */
584 if (error == ENOENT)
585 error = 0;
586 return (error);
587 }
588
589 /*
590 * nwfs hard link create call
591 * Netware filesystems don't know what links are.
592 */
593 static int
594 nwfs_link(ap)
595 struct vop_link_args /* {
596 struct vnode *a_tdvp;
597 struct vnode *a_vp;
598 struct componentname *a_cnp;
599 } */ *ap;
600 {
601 return EOPNOTSUPP;
602 }
603
604 /*
605 * nwfs_symlink link create call
606 * Netware filesystems don't know what symlinks are.
607 */
608 static int
609 nwfs_symlink(ap)
610 struct vop_symlink_args /* {
611 struct vnode *a_dvp;
612 struct vnode **a_vpp;
613 struct componentname *a_cnp;
614 struct vattr *a_vap;
615 char *a_target;
616 } */ *ap;
617 {
618 return (EOPNOTSUPP);
619 }
620
621 static int nwfs_mknod(ap)
622 struct vop_mknod_args /* {
623 } */ *ap;
624 {
625 return (EOPNOTSUPP);
626 }
627
628 /*
629 * nwfs_mkdir call
630 */
631 static int
632 nwfs_mkdir(ap)
633 struct vop_mkdir_args /* {
634 struct vnode *a_dvp;
635 struct vnode **a_vpp;
636 struct componentname *a_cnp;
637 struct vattr *a_vap;
638 } */ *ap;
639 {
640 struct vnode *dvp = ap->a_dvp;
641 /* struct vattr *vap = ap->a_vap;*/
642 struct componentname *cnp = ap->a_cnp;
643 int len=cnp->cn_namelen;
644 struct ncp_open_info no;
645 struct nwnode *np;
646 struct vnode *newvp = (struct vnode *)0;
647 ncpfid fid;
648 int error = 0;
649 struct vattr vattr;
650 char *name=cnp->cn_nameptr;
651
652 if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
653 return (error);
654 }
655 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
656 return EEXIST;
657 }
658 if (ncp_open_create_file_or_subdir(VTONWFS(dvp), dvp, cnp->cn_namelen,
659 cnp->cn_nameptr, OC_MODE_CREATE, aDIR, 0xffff,
660 &no, cnp->cn_thread, cnp->cn_cred) != 0) {
661 error = EACCES;
662 } else {
663 error = 0;
664 }
665 if (!error) {
666 fid.f_parent = VTONW(dvp)->n_fid.f_id;
667 fid.f_id = no.fattr.dirEntNum;
668 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
669 if (!error) {
670 np = VTONW(newvp);
671 newvp->v_type = VDIR;
672 *ap->a_vpp = newvp;
673 }
674 }
675 return (error);
676 }
677
678 /*
679 * nwfs_remove directory call
680 */
681 static int
682 nwfs_rmdir(ap)
683 struct vop_rmdir_args /* {
684 struct vnode *a_dvp;
685 struct vnode *a_vp;
686 struct componentname *a_cnp;
687 } */ *ap;
688 {
689 struct vnode *vp = ap->a_vp;
690 struct vnode *dvp = ap->a_dvp;
691 struct componentname *cnp = ap->a_cnp;
692 struct nwnode *np = VTONW(vp);
693 struct nwmount *nmp = VTONWFS(vp);
694 struct nwnode *dnp = VTONW(dvp);
695 int error = EIO;
696
697 if (dvp == vp)
698 return EINVAL;
699
700 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
701 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
702 if (error == 0)
703 np->n_flag |= NSHOULDFREE;
704 else if (error == NWE_DIR_NOT_EMPTY)
705 error = ENOTEMPTY;
706 dnp->n_flag |= NMODIFIED;
707 nwfs_attr_cacheremove(dvp);
708 cache_purge(dvp);
709 cache_purge(vp);
710 return (error);
711 }
712
713 /*
714 * nwfs_readdir call
715 */
716 static int
717 nwfs_readdir(ap)
718 struct vop_readdir_args /* {
719 struct vnode *a_vp;
720 struct uio *a_uio;
721 struct ucred *a_cred;
722 int *a_eofflag;
723 u_long *a_cookies;
724 int a_ncookies;
725 } */ *ap;
726 {
727 struct vnode *vp = ap->a_vp;
728 struct uio *uio = ap->a_uio;
729 int error;
730
731 if (vp->v_type != VDIR)
732 return (EPERM);
733 if (ap->a_ncookies) {
734 printf("nwfs_readdir: no support for cookies now...");
735 return (EOPNOTSUPP);
736 }
737
738 error = nwfs_readvnode(vp, uio, ap->a_cred);
739 return error;
740 }
741 /* ARGSUSED */
742 static int
743 nwfs_fsync(ap)
744 struct vop_fsync_args /* {
745 struct vnodeop_desc *a_desc;
746 struct vnode * a_vp;
747 struct ucred * a_cred;
748 int a_waitfor;
749 struct thread *a_td;
750 } */ *ap;
751 {
752 /* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
753 return (0);
754 }
755
756 /* ARGSUSED */
757 static
758 int nwfs_print (ap)
759 struct vop_print_args /* {
760 struct vnode *a_vp;
761 } */ *ap;
762 {
763 struct vnode *vp = ap->a_vp;
764 struct nwnode *np = VTONW(vp);
765
766 printf("nwfs node: name = '%s', fid = %d, pfid = %d\n",
767 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
768 return (0);
769 }
770
771 static int nwfs_pathconf (ap)
772 struct vop_pathconf_args /* {
773 struct vnode *vp;
774 int name;
775 register_t *retval;
776 } */ *ap;
777 {
778 int name=ap->a_name, error=0;
779 register_t *retval=ap->a_retval;
780
781 switch(name){
782 case _PC_LINK_MAX:
783 *retval=0;
784 break;
785 case _PC_NAME_MAX:
786 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
787 break;
788 case _PC_PATH_MAX:
789 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
790 break;
791 default:
792 error=EINVAL;
793 }
794 return(error);
795 }
796
797 static int nwfs_strategy (ap)
798 struct vop_strategy_args /* {
799 struct buf *a_bp
800 } */ *ap;
801 {
802 struct buf *bp=ap->a_bp;
803 struct ucred *cr;
804 struct thread *td;
805 int error = 0;
806
807 NCPVNDEBUG("\n");
808 if (bp->b_flags & B_PHYS)
809 panic("nwfs physio");
810 if (bp->b_flags & B_ASYNC)
811 td = (struct thread *)0;
812 else
813 td = curthread; /* XXX */
814 if (bp->b_iocmd == BIO_READ)
815 cr = bp->b_rcred;
816 else
817 cr = bp->b_wcred;
818 /*
819 * If the op is asynchronous and an i/o daemon is waiting
820 * queue the request, wake it up and wait for completion
821 * otherwise just do it ourselves.
822 */
823 if ((bp->b_flags & B_ASYNC) == 0 )
824 error = nwfs_doio(bp, cr, td);
825 return (error);
826 }
827
828
829 /*
830 * How to keep the brain busy ...
831 * Currently lookup routine can make two lookup for vnode. This can be
832 * avoided by reorg the code.
833 */
834 int
835 nwfs_lookup(ap)
836 struct vop_lookup_args /* {
837 struct vnodeop_desc *a_desc;
838 struct vnode *a_dvp;
839 struct vnode **a_vpp;
840 struct componentname *a_cnp;
841 } */ *ap;
842 {
843 struct componentname *cnp = ap->a_cnp;
844 struct vnode *dvp = ap->a_dvp;
845 struct vnode **vpp = ap->a_vpp;
846 int flags = cnp->cn_flags;
847 struct vnode *vp;
848 struct nwmount *nmp;
849 struct mount *mp = dvp->v_mount;
850 struct nwnode *dnp, *npp;
851 struct nw_entry_info fattr, *fap;
852 ncpfid fid;
853 int nameiop=cnp->cn_nameiop, islastcn;
854 int lockparent, wantparent, error = 0, notfound;
855 struct thread *td = cnp->cn_thread;
856 char _name[cnp->cn_namelen+1];
857 bcopy(cnp->cn_nameptr, _name, cnp->cn_namelen);
858 _name[cnp->cn_namelen]=0;
859
860 if (dvp->v_type != VDIR)
861 return (ENOTDIR);
862 if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
863 printf("nwfs_lookup: invalid '..'\n");
864 return EIO;
865 }
866
867 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
868 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
869
870 islastcn = flags & ISLASTCN;
871 if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
872 return (EROFS);
873 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)))
874 return (error);
875 lockparent = flags & LOCKPARENT;
876 wantparent = flags & (LOCKPARENT|WANTPARENT);
877 nmp = VFSTONWFS(mp);
878 dnp = VTONW(dvp);
879 /*
880 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_vflag & VV_ROOT, (int)flags & ISDOTDOT);
881 */
882 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
883 (nameiop == CREATE || nameiop == RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
884 if (error)
885 return ENOENT;
886
887 error = cache_lookup(dvp, vpp, cnp);
888 NCPVNDEBUG("cache_lookup returned %d\n", error);
889 if (error > 0)
890 return error;
891 if (error) { /* name was found */
892 struct vattr vattr;
893 int vpid;
894
895 vp = *vpp;
896 vpid = vp->v_id;
897 if (dvp == vp) { /* lookup on current */
898 vref(vp);
899 error = 0;
900 NCPVNDEBUG("cached '.'");
901 } else if (flags & ISDOTDOT) {
902 VOP_UNLOCK(dvp, 0, td); /* unlock parent */
903 error = vget(vp, LK_EXCLUSIVE, td);
904 if (!error && lockparent && islastcn)
905 error = vn_lock(dvp, LK_EXCLUSIVE, td);
906 } else {
907 error = vget(vp, LK_EXCLUSIVE, td);
908 if (!lockparent || error || !islastcn)
909 VOP_UNLOCK(dvp, 0, td);
910 }
911 if (!error) {
912 if (vpid == vp->v_id) {
913 if (!VOP_GETATTR(vp, &vattr, cnp->cn_cred, td)
914 && vattr.va_ctime.tv_sec == VTONW(vp)->n_ctime) {
915 if (nameiop != LOOKUP && islastcn)
916 cnp->cn_flags |= SAVENAME;
917 NCPVNDEBUG("use cached vnode");
918 return (0);
919 }
920 cache_purge(vp);
921 }
922 vput(vp);
923 if (lockparent && dvp != vp && islastcn)
924 VOP_UNLOCK(dvp, 0, td);
925 }
926 error = vn_lock(dvp, LK_EXCLUSIVE, td);
927 *vpp = NULLVP;
928 if (error)
929 return (error);
930 }
931 /* not in cache, so ... */
932 error = 0;
933 *vpp = NULLVP;
934 fap = NULL;
935 if (flags & ISDOTDOT) {
936 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
937 fid = nmp->n_rootent;
938 fap = NULL;
939 notfound = 0;
940 } else {
941 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
942 if (error) {
943 return error;
944 }
945 fid = dnp->n_parent;
946 fap = &fattr;
947 /*np = *npp;*/
948 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
949 0, NULL, fap, td, cnp->cn_cred);
950 }
951 } else {
952 fap = &fattr;
953 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
954 fap, td, cnp->cn_cred);
955 fid.f_id = fap->dirEntNum;
956 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
957 fid.f_parent = dnp->n_fid.f_parent;
958 } else
959 fid.f_parent = dnp->n_fid.f_id;
960 NCPVNDEBUG("call to ncp_lookup returned=%d\n", notfound);
961 }
962 if (notfound && notfound < 0x80 )
963 return (notfound); /* hard error */
964 if (notfound) { /* entry not found */
965 /* Handle RENAME or CREATE case... */
966 if ((nameiop == CREATE || nameiop == RENAME) && wantparent && islastcn) {
967 cnp->cn_flags |= SAVENAME;
968 if (!lockparent)
969 VOP_UNLOCK(dvp, 0, td);
970 return (EJUSTRETURN);
971 }
972 return ENOENT;
973 }/* else {
974 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
975 }*/
976 /* handle DELETE case ... */
977 if (nameiop == DELETE && islastcn) { /* delete last component */
978 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
979 if (error) return (error);
980 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
981 VREF(dvp);
982 *vpp = dvp;
983 return 0;
984 }
985 error = nwfs_nget(mp, fid, fap, dvp, &vp);
986 if (error) return (error);
987 *vpp = vp;
988 cnp->cn_flags |= SAVENAME; /* I free it later */
989 if (!lockparent) VOP_UNLOCK(dvp, 0, td);
990 return (0);
991 }
992 if (nameiop == RENAME && islastcn && wantparent) {
993 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
994 if (error) return (error);
995 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
996 error = nwfs_nget(mp, fid, fap, dvp, &vp);
997 if (error) return (error);
998 *vpp = vp;
999 cnp->cn_flags |= SAVENAME;
1000 if (!lockparent)
1001 VOP_UNLOCK(dvp, 0, td);
1002 return (0);
1003 }
1004 if (flags & ISDOTDOT) {
1005 VOP_UNLOCK(dvp, 0, td); /* race to get the inode */
1006 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
1007 if (error) {
1008 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
1009 return (error);
1010 }
1011 if (lockparent && islastcn &&
1012 (error = vn_lock(dvp, LK_EXCLUSIVE, td))) {
1013 vput(vp);
1014 return (error);
1015 }
1016 *vpp = vp;
1017 } else if (NWCMPF(&dnp->n_fid, &fid)) {
1018 vref(dvp);
1019 *vpp = dvp;
1020 } else {
1021 error = nwfs_nget(mp, fid, fap, dvp, &vp);
1022 if (error) return (error);
1023 *vpp = vp;
1024 NCPVNDEBUG("lookup: getnewvp!\n");
1025 if (!lockparent || !islastcn)
1026 VOP_UNLOCK(dvp, 0, td);
1027 }
1028 if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
1029 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
1030 cache_enter(dvp, *vpp, cnp);
1031 }
1032 return (0);
1033 }
Cache object: 8bb88fcfede0528148f5a358a7a86ebe
|