Get rid of the weird coda VOP function arguments and void casts and
[dragonfly.git] / sys / vfs / nwfs / nwfs_vnops.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1999, 2000 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: src/sys/nwfs/nwfs_vnops.c,v 1.6.2.3 2001/03/14 11:26:59 bp Exp $
66a1ddf5 33 * $DragonFly: src/sys/vfs/nwfs/nwfs_vnops.c,v 1.30 2006/07/18 22:22:16 dillon Exp $
984263bc
MD
34 */
35#include <sys/param.h>
36#include <sys/systm.h>
984263bc
MD
37#include <sys/kernel.h>
38#include <sys/buf.h>
39#include <sys/proc.h>
dadab5e9 40#include <sys/namei.h>
984263bc
MD
41#include <sys/fcntl.h>
42#include <sys/mount.h>
43#include <sys/unistd.h>
44#include <sys/vnode.h>
45
46#include <vm/vm.h>
47#include <vm/vm_extern.h>
48#include <vm/vm_zone.h>
49
d2438d69
MD
50#include <netproto/ncp/ncp.h>
51#include <netproto/ncp/ncp_conn.h>
52#include <netproto/ncp/ncp_subr.h>
53#include <netproto/ncp/nwerror.h>
54#include <netproto/ncp/ncp_nls.h>
984263bc 55
1f2de5d4
MD
56#include "nwfs.h"
57#include "nwfs_node.h"
58#include "nwfs_subr.h"
984263bc
MD
59
60/*
61 * Prototypes for NWFS vnode operations
62 */
e62afb5f
MD
63static int nwfs_create(struct vop_old_create_args *);
64static int nwfs_mknod(struct vop_old_mknod_args *);
984263bc
MD
65static int nwfs_open(struct vop_open_args *);
66static int nwfs_close(struct vop_close_args *);
67static int nwfs_access(struct vop_access_args *);
68static int nwfs_getattr(struct vop_getattr_args *);
69static int nwfs_setattr(struct vop_setattr_args *);
70static int nwfs_read(struct vop_read_args *);
71static int nwfs_write(struct vop_write_args *);
72static int nwfs_fsync(struct vop_fsync_args *);
e62afb5f
MD
73static int nwfs_remove(struct vop_old_remove_args *);
74static int nwfs_link(struct vop_old_link_args *);
75static int nwfs_lookup(struct vop_old_lookup_args *);
76static int nwfs_rename(struct vop_old_rename_args *);
77static int nwfs_mkdir(struct vop_old_mkdir_args *);
78static int nwfs_rmdir(struct vop_old_rmdir_args *);
79static int nwfs_symlink(struct vop_old_symlink_args *);
984263bc
MD
80static int nwfs_readdir(struct vop_readdir_args *);
81static int nwfs_bmap(struct vop_bmap_args *);
82static int nwfs_strategy(struct vop_strategy_args *);
83static int nwfs_print(struct vop_print_args *);
84static int nwfs_pathconf(struct vop_pathconf_args *ap);
85
86/* Global vfs data structures for nwfs */
66a1ddf5
MD
87struct vop_ops nwfs_vnode_vops = {
88 .vop_default = vop_defaultop,
89 .vop_access = nwfs_access,
90 .vop_bmap = nwfs_bmap,
91 .vop_open = nwfs_open,
92 .vop_close = nwfs_close,
93 .vop_old_create = nwfs_create,
94 .vop_fsync = nwfs_fsync,
95 .vop_getattr = nwfs_getattr,
96 .vop_getpages = nwfs_getpages,
97 .vop_putpages = nwfs_putpages,
98 .vop_ioctl = nwfs_ioctl,
99 .vop_inactive = nwfs_inactive,
100 .vop_islocked = vop_stdislocked,
101 .vop_old_link = nwfs_link,
102 .vop_lock = vop_stdlock,
103 .vop_old_lookup = nwfs_lookup,
104 .vop_old_mkdir = nwfs_mkdir,
105 .vop_old_mknod = nwfs_mknod,
106 .vop_pathconf = nwfs_pathconf,
107 .vop_print = nwfs_print,
108 .vop_read = nwfs_read,
109 .vop_readdir = nwfs_readdir,
110 .vop_reclaim = nwfs_reclaim,
111 .vop_old_remove = nwfs_remove,
112 .vop_old_rename = nwfs_rename,
113 .vop_old_rmdir = nwfs_rmdir,
114 .vop_setattr = nwfs_setattr,
115 .vop_strategy = nwfs_strategy,
116 .vop_old_symlink = nwfs_symlink,
117 .vop_unlock = vop_stdunlock,
118 .vop_write = nwfs_write
984263bc 119};
984263bc
MD
120
121/*
122 * nwfs_access vnode op
123 * for now just return ok
a9bb80e0
CP
124 *
125 * nwfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
126 * struct thread *a_td)
984263bc
MD
127 */
128static int
a9bb80e0 129nwfs_access(struct vop_access_args *ap)
984263bc
MD
130{
131 struct vnode *vp = ap->a_vp;
132 struct ucred *cred = ap->a_cred;
133 u_int mode = ap->a_mode;
134 struct nwmount *nmp = VTONWFS(vp);
135 int error = 0;
136
137 NCPVNDEBUG("\n");
138 if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
139 switch (vp->v_type) {
140 case VREG: case VDIR: case VLNK:
141 return (EROFS);
142 default:
143 break;
144 }
145 }
146 if (cred->cr_uid == 0)
147 return 0;
148 if (cred->cr_uid != nmp->m.uid) {
149 mode >>= 3;
150 if (!groupmember(nmp->m.gid, cred))
151 mode >>= 3;
152 }
153 error = (((vp->v_type == VREG) ? nmp->m.file_mode : nmp->m.dir_mode) & mode) == mode ? 0 : EACCES;
154 return error;
155}
156/*
157 * nwfs_open vnode op
a9bb80e0 158 *
87de5057 159 * nwfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
984263bc
MD
160 */
161/* ARGSUSED */
162static int
a9bb80e0 163nwfs_open(struct vop_open_args *ap)
984263bc 164{
87de5057 165 thread_t td = curthread; /* XXX */
984263bc
MD
166 struct vnode *vp = ap->a_vp;
167 int mode = ap->a_mode;
168 struct nwnode *np = VTONW(vp);
169 struct ncp_open_info no;
170 struct nwmount *nmp = VTONWFS(vp);
171 struct vattr vattr;
172 int error, nwm;
173
174 NCPVNDEBUG("%s,%d\n",np->n_name, np->opened);
175 if (vp->v_type != VREG && vp->v_type != VDIR) {
176 NCPFATAL("open vtype = %d\n", vp->v_type);
177 return (EACCES);
178 }
179 if (vp->v_type == VDIR) return 0; /* nothing to do now */
180 if (np->n_flag & NMODIFIED) {
87de5057 181 if ((error = nwfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
984263bc
MD
182 return (error);
183 np->n_atime = 0;
87de5057 184 error = VOP_GETATTR(vp, &vattr);
8ddc6004
MD
185 if (error)
186 return (error);
984263bc
MD
187 np->n_mtime = vattr.va_mtime.tv_sec;
188 } else {
87de5057 189 error = VOP_GETATTR(vp, &vattr);
8ddc6004
MD
190 if (error)
191 return (error);
984263bc 192 if (np->n_mtime != vattr.va_mtime.tv_sec) {
87de5057 193 if ((error = nwfs_vinvalbuf(vp, V_SAVE, 1)) == EINTR)
984263bc
MD
194 return (error);
195 np->n_mtime = vattr.va_mtime.tv_sec;
196 }
197 }
198 if (np->opened) {
199 np->opened++;
8ddc6004 200 return (vop_stdopen(ap));
984263bc
MD
201 }
202 nwm = AR_READ;
203 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
204 nwm |= AR_WRITE;
205 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
87de5057 206 0, nwm, &no, td, ap->a_cred);
984263bc
MD
207 if (error) {
208 if (mode & FWRITE)
209 return EACCES;
210 nwm = AR_READ;
211 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
87de5057 212 nwm, &no, td, ap->a_cred);
984263bc 213 }
8ddc6004
MD
214 np->n_atime = 0;
215 if (error == 0) {
984263bc
MD
216 np->opened++;
217 np->n_fh = no.fh;
218 np->n_origfh = no.origfh;
8ddc6004 219 error = vop_stdopen(ap);
984263bc 220 }
984263bc
MD
221 return (error);
222}
223
a9bb80e0
CP
224/*
225 * nwfs_close(struct vnodeop_desc *a_desc, struct vnode *a_vp, int a_fflag,
226 * struct ucred *a_cred, struct thread *a_td)
227 */
984263bc 228static int
a9bb80e0 229nwfs_close(struct vop_close_args *ap)
984263bc 230{
87de5057 231 thread_t td = curthread; /* XXX */
984263bc
MD
232 struct vnode *vp = ap->a_vp;
233 struct nwnode *np = VTONW(vp);
234 int error;
235
dadab5e9 236 NCPVNDEBUG("name=%s,td=%p,c=%d\n",np->n_name,ap->a_td,np->opened);
984263bc 237
984263bc 238 error = 0;
8ddc6004
MD
239 if (vp->v_type == VDIR)
240 goto done;
241 if (np->opened == 0)
242 goto done;
87de5057 243 error = nwfs_vinvalbuf(vp, V_SAVE, 1);
984263bc 244 if (np->opened == 0) {
8ddc6004
MD
245 error = 0; /* huh? */
246 goto done;
984263bc
MD
247 }
248 if (--np->opened == 0) {
984263bc 249 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh,
87de5057 250 td, proc0.p_ucred);
5fd012e0 251 }
984263bc 252 np->n_atime = 0;
8ddc6004
MD
253done:
254 vop_stdclose(ap);
984263bc
MD
255 return (error);
256}
257
258/*
259 * nwfs_getattr call from vfs.
a9bb80e0
CP
260 *
261 * nwfs_getattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred,
262 * struct thread *a_td)
984263bc
MD
263 */
264static int
a9bb80e0 265nwfs_getattr(struct vop_getattr_args *ap)
984263bc 266{
87de5057 267 thread_t td = curthread; /* XXX */
984263bc
MD
268 struct vnode *vp = ap->a_vp;
269 struct nwnode *np = VTONW(vp);
270 struct vattr *va=ap->a_vap;
271 struct nwmount *nmp = VTONWFS(vp);
272 struct nw_entry_info fattr;
273 int error;
274 u_int32_t oldsize;
275
276 NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_flag & VROOT) != 0);
277 error = nwfs_attr_cachelookup(vp,va);
278 if (!error) return 0;
279 NCPVNDEBUG("not in cache\n");
280 oldsize = np->n_size;
281 if (np->n_flag & NVOLUME) {
282 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
87de5057 283 td,proc0.p_ucred);
984263bc
MD
284 } else {
285 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen,
87de5057 286 np->n_name, &fattr, td, proc0.p_ucred);
984263bc
MD
287 }
288 if (error) {
289 NCPVNDEBUG("error %d\n", error);
290 return error;
291 }
292 nwfs_attr_cacheenter(vp, &fattr);
293 *va = np->n_vattr;
294 if (np->opened)
295 np->n_size = oldsize;
296 return (0);
297}
298/*
299 * nwfs_setattr call from vfs.
a9bb80e0 300 *
87de5057 301 * nwfs_setattr(struct vnode *a_vp, struct vattr *a_vap, struct ucred *a_cred)
984263bc
MD
302 */
303static int
a9bb80e0 304nwfs_setattr(struct vop_setattr_args *ap)
984263bc 305{
87de5057 306 thread_t td = curthread; /* XXX */
984263bc
MD
307 struct vnode *vp = ap->a_vp;
308 struct nwnode *np = VTONW(vp);
309 struct vattr *vap = ap->a_vap;
310 u_quad_t tsize=0;
311 int error = 0;
312
313 NCPVNDEBUG("\n");
314 if (vap->va_flags != VNOVAL)
315 return (EOPNOTSUPP);
316 /*
317 * Disallow write attempts if the filesystem is mounted read-only.
318 */
319 if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL ||
320 vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
321 vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
322 return (EROFS);
323 if (vap->va_size != VNOVAL) {
324 switch (vp->v_type) {
325 case VDIR:
326 return (EISDIR);
327 case VREG:
328 /*
329 * Disallow write attempts if the filesystem is
330 * mounted read-only.
331 */
332 if (vp->v_mount->mnt_flag & MNT_RDONLY)
333 return (EROFS);
334 vnode_pager_setsize(vp, (u_long)vap->va_size);
335 tsize = np->n_size;
336 np->n_size = vap->va_size;
337 break;
338 default:
339 return EINVAL;
340 };
341 }
87de5057 342 error = ncp_setattr(vp, vap, ap->a_cred, td);
984263bc
MD
343 if (error && vap->va_size != VNOVAL) {
344 np->n_size = tsize;
345 vnode_pager_setsize(vp, (u_long)tsize);
346 }
347 np->n_atime = 0; /* invalidate cache */
87de5057 348 VOP_GETATTR(vp, vap);
984263bc
MD
349 np->n_mtime = vap->va_mtime.tv_sec;
350 return (0);
351}
a9bb80e0 352
984263bc
MD
353/*
354 * nwfs_read call.
a9bb80e0
CP
355 *
356 * nwfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
357 * struct ucred *a_cred)
984263bc
MD
358 */
359static int
a9bb80e0 360nwfs_read(struct vop_read_args *ap)
984263bc
MD
361{
362 struct vnode *vp = ap->a_vp;
363 struct uio *uio=ap->a_uio;
364 int error;
365 NCPVNDEBUG("nwfs_read:\n");
366
367 if (vp->v_type != VREG && vp->v_type != VDIR)
368 return (EPERM);
369 error = nwfs_readvnode(vp, uio, ap->a_cred);
370 return error;
371}
372
a9bb80e0
CP
373/*
374 * nwfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
375 * struct ucred *a_cred)
376 */
984263bc 377static int
a9bb80e0 378nwfs_write(struct vop_write_args *ap)
984263bc
MD
379{
380 struct vnode *vp = ap->a_vp;
381 struct uio *uio = ap->a_uio;
382 int error;
383
384 NCPVNDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
385
386 if (vp->v_type != VREG)
387 return (EPERM);
388 error = nwfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
389 return(error);
390}
391/*
392 * nwfs_create call
393 * Create a regular file. On entry the directory to contain the file being
fad57d0e 394 * created is locked. We must release before we return.
a9bb80e0
CP
395 *
396 * nwfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
397 * struct componentname *a_cnpl, struct vattr *a_vap)
984263bc
MD
398 */
399static int
e62afb5f 400nwfs_create(struct vop_old_create_args *ap)
984263bc
MD
401{
402 struct vnode *dvp = ap->a_dvp;
403 struct vattr *vap = ap->a_vap;
404 struct vnode **vpp=ap->a_vpp;
405 struct componentname *cnp = ap->a_cnp;
406 struct vnode *vp = (struct vnode *)0;
407 int error = 0, fmode;
408 struct vattr vattr;
409 struct nwnode *np;
410 struct ncp_open_info no;
411 struct nwmount *nmp=VTONWFS(dvp);
412 ncpfid fid;
413
414
415 NCPVNDEBUG("\n");
416 *vpp = NULL;
417 if (vap->va_type == VSOCK)
418 return (EOPNOTSUPP);
87de5057 419 if ((error = VOP_GETATTR(dvp, &vattr))) {
984263bc
MD
420 return (error);
421 }
422 fmode = AR_READ | AR_WRITE;
423/* if (vap->va_vaflags & VA_EXCLUSIVE)
424 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
425
426 error = ncp_open_create_file_or_subdir(nmp,dvp,cnp->cn_namelen,cnp->cn_nameptr,
427 OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
dadab5e9 428 0, fmode, &no, cnp->cn_td, cnp->cn_cred);
984263bc 429 if (!error) {
dadab5e9 430 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_td,cnp->cn_cred);
984263bc
MD
431 fid.f_parent = VTONW(dvp)->n_fid.f_id;
432 fid.f_id = no.fattr.dirEntNum;
433 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
434 if (!error) {
435 np = VTONW(vp);
436 np->opened = 0;
437 *vpp = vp;
438 }
984263bc
MD
439 }
440 return (error);
441}
442
443/*
444 * nwfs_remove call. It isn't possible to emulate UFS behaivour because
445 * NetWare doesn't allow delete/rename operations on an opened file.
a9bb80e0
CP
446 *
447 * nwfs_remove(struct vnodeop_desc *a_desc, struct vnode *a_dvp,
448 * struct vnode *a_vp, struct componentname *a_cnp)
984263bc
MD
449 */
450static int
e62afb5f 451nwfs_remove(struct vop_old_remove_args *ap)
984263bc
MD
452{
453 struct vnode *vp = ap->a_vp;
454 struct vnode *dvp = ap->a_dvp;
455 struct componentname *cnp = ap->a_cnp;
456 struct nwnode *np = VTONW(vp);
457 struct nwmount *nmp = VTONWFS(vp);
458 int error;
459
460 if (vp->v_type == VDIR || np->opened || vp->v_usecount != 1) {
461 error = EPERM;
462 } else if (!ncp_conn_valid(NWFSTOCONN(nmp))) {
463 error = EIO;
464 } else {
984263bc 465 error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
dadab5e9 466 cnp->cn_namelen,cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
984263bc
MD
467 if (error == 0)
468 np->n_flag |= NSHOULDFREE;
469 else if (error == 0x899c)
470 error = EACCES;
471 }
472 return (error);
473}
474
475/*
476 * nwfs_file rename call
a9bb80e0
CP
477 *
478 * nwfs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
479 * struct componentname *a_fcnp, struct vnode *a_tdvp,
480 * struct vnode *a_tvp, struct componentname *a_tcnp)
984263bc
MD
481 */
482static int
e62afb5f 483nwfs_rename(struct vop_old_rename_args *ap)
984263bc
MD
484{
485 struct vnode *fvp = ap->a_fvp;
486 struct vnode *tvp = ap->a_tvp;
487 struct vnode *fdvp = ap->a_fdvp;
488 struct vnode *tdvp = ap->a_tdvp;
489 struct componentname *tcnp = ap->a_tcnp;
490 struct componentname *fcnp = ap->a_fcnp;
491 struct nwmount *nmp=VTONWFS(fvp);
492 u_int16_t oldtype = 6;
493 int error=0;
494
495 /* Check for cross-device rename */
496 if ((fvp->v_mount != tdvp->v_mount) ||
497 (tvp && (fvp->v_mount != tvp->v_mount))) {
498 error = EXDEV;
499 goto out;
500 }
501
502 if (tvp && tvp->v_usecount > 1) {
503 error = EBUSY;
504 goto out;
505 }
506 if (tvp && tvp != fvp) {
507 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
508 tcnp->cn_namelen, tcnp->cn_nameptr,
dadab5e9 509 tcnp->cn_td, tcnp->cn_cred);
984263bc
MD
510 if (error == 0x899c) error = EACCES;
511 if (error)
512 goto out;
513 }
514 if (fvp->v_type == VDIR) {
515 oldtype |= NW_TYPE_SUBDIR;
516 } else if (fvp->v_type == VREG) {
517 oldtype |= NW_TYPE_FILE;
518 } else
519 return EINVAL;
520 error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space,
521 oldtype, &nmp->m.nls,
522 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
523 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
dadab5e9 524 tcnp->cn_td,tcnp->cn_cred);
984263bc
MD
525
526 if (error == 0x8992)
527 error = EEXIST;
984263bc
MD
528out:
529 if (tdvp == tvp)
530 vrele(tdvp);
531 else
532 vput(tdvp);
533 if (tvp)
534 vput(tvp);
535 vrele(fdvp);
536 vrele(fvp);
537 nwfs_attr_cacheremove(fdvp);
538 nwfs_attr_cacheremove(tdvp);
539 /*
540 * Need to get rid of old vnodes, because netware will change
541 * file id on rename
542 */
543 vgone(fvp);
544 if (tvp)
545 vgone(tvp);
546 /*
547 * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
548 */
549 if (error == ENOENT)
550 error = 0;
551 return (error);
552}
553
554/*
555 * nwfs hard link create call
556 * Netware filesystems don't know what links are.
a9bb80e0
CP
557 *
558 * nwfs_link(struct vnode *a_tdvp, struct vnode *a_vp,
559 * struct componentname *a_cnp)
984263bc
MD
560 */
561static int
e62afb5f 562nwfs_link(struct vop_old_link_args *ap)
984263bc
MD
563{
564 return EOPNOTSUPP;
565}
566
567/*
568 * nwfs_symlink link create call
569 * Netware filesystems don't know what symlinks are.
a9bb80e0
CP
570 *
571 * nwfs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
572 * struct componentname *a_cnp, struct vattr *a_vap,
573 * char *a_target)
984263bc
MD
574 */
575static int
e62afb5f 576nwfs_symlink(struct vop_old_symlink_args *ap)
984263bc
MD
577{
578 return (EOPNOTSUPP);
579}
580
e62afb5f 581static int nwfs_mknod(struct vop_old_mknod_args *ap)
984263bc
MD
582{
583 return (EOPNOTSUPP);
584}
585
586/*
587 * nwfs_mkdir call
a9bb80e0
CP
588 *
589 * nwfs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
590 * struct componentname *a_cnp, struct vattr *a_vap)
984263bc
MD
591 */
592static int
e62afb5f 593nwfs_mkdir(struct vop_old_mkdir_args *ap)
984263bc
MD
594{
595 struct vnode *dvp = ap->a_dvp;
596/* struct vattr *vap = ap->a_vap;*/
597 struct componentname *cnp = ap->a_cnp;
598 int len=cnp->cn_namelen;
599 struct ncp_open_info no;
600 struct nwnode *np;
601 struct vnode *newvp = (struct vnode *)0;
602 ncpfid fid;
603 int error = 0;
604 struct vattr vattr;
605 char *name=cnp->cn_nameptr;
606
87de5057 607 if ((error = VOP_GETATTR(dvp, &vattr))) {
984263bc
MD
608 return (error);
609 }
610 if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
611 return EEXIST;
612 }
613 if (ncp_open_create_file_or_subdir(VTONWFS(dvp),dvp, cnp->cn_namelen,
614 cnp->cn_nameptr,OC_MODE_CREATE, aDIR, 0xffff,
dadab5e9 615 &no, cnp->cn_td, cnp->cn_cred) != 0) {
984263bc
MD
616 error = EACCES;
617 } else {
618 error = 0;
619 }
620 if (!error) {
621 fid.f_parent = VTONW(dvp)->n_fid.f_id;
622 fid.f_id = no.fattr.dirEntNum;
623 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
624 if (!error) {
625 np = VTONW(newvp);
626 newvp->v_type = VDIR;
627 *ap->a_vpp = newvp;
628 }
629 }
630 return (error);
631}
632
633/*
634 * nwfs_remove directory call
a9bb80e0
CP
635 *
636 * nwfs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
637 * struct componentname *a_cnp)
984263bc
MD
638 */
639static int
e62afb5f 640nwfs_rmdir(struct vop_old_rmdir_args *ap)
984263bc
MD
641{
642 struct vnode *vp = ap->a_vp;
643 struct vnode *dvp = ap->a_dvp;
644 struct componentname *cnp = ap->a_cnp;
645 struct nwnode *np = VTONW(vp);
646 struct nwmount *nmp = VTONWFS(vp);
647 struct nwnode *dnp = VTONW(dvp);
648 int error = EIO;
649
650 if (dvp == vp)
651 return EINVAL;
652
653 error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id,
dadab5e9 654 cnp->cn_namelen, cnp->cn_nameptr,cnp->cn_td,cnp->cn_cred);
984263bc
MD
655 if (error == 0)
656 np->n_flag |= NSHOULDFREE;
657 else if (error == NWE_DIR_NOT_EMPTY)
658 error = ENOTEMPTY;
659 dnp->n_flag |= NMODIFIED;
660 nwfs_attr_cacheremove(dvp);
984263bc
MD
661 return (error);
662}
663
664/*
665 * nwfs_readdir call
a9bb80e0
CP
666 *
667 * nwfs_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
668 * int *a_eofflag, u_long *a_cookies, int a_ncookies)
984263bc
MD
669 */
670static int
a9bb80e0 671nwfs_readdir(struct vop_readdir_args *ap)
984263bc
MD
672{
673 struct vnode *vp = ap->a_vp;
674 struct uio *uio = ap->a_uio;
675 int error;
676
677 if (vp->v_type != VDIR)
678 return (EPERM);
679 if (ap->a_ncookies) {
680 printf("nwfs_readdir: no support for cookies now...");
681 return (EOPNOTSUPP);
682 }
683
684 error = nwfs_readvnode(vp, uio, ap->a_cred);
685 return error;
686}
a9bb80e0
CP
687
688/*
689 * nwfs_fsync(struct vnodeop_desc *a_desc, struct vnode *a_vp,
690 * struct ucred *a_cred, int a_waitfor, struct thread *a_td)
691 */
984263bc
MD
692/* ARGSUSED */
693static int
a9bb80e0 694nwfs_fsync(struct vop_fsync_args *ap)
984263bc 695{
dadab5e9 696/* return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
984263bc
MD
697 return (0);
698}
699
a9bb80e0
CP
700/*
701 * nwfs_print(struct vnode *a_vp)
702 */
984263bc 703/* ARGSUSED */
a9bb80e0
CP
704static int
705nwfs_print(struct vop_print_args *ap)
984263bc
MD
706{
707 struct vnode *vp = ap->a_vp;
708 struct nwnode *np = VTONW(vp);
709
710 printf("nwfs node: name = '%s', fid = %d, pfid = %d\n",
711 np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
712 return (0);
713}
714
a9bb80e0
CP
715/*
716 * nwfs_pathconf(struct vnode *vp, int name, register_t *retval)
717 */
718static int
719nwfs_pathconf(struct vop_pathconf_args *ap)
984263bc
MD
720{
721 int name=ap->a_name, error=0;
722 register_t *retval=ap->a_retval;
723
724 switch(name){
725 case _PC_LINK_MAX:
726 *retval=0;
727 break;
728 case _PC_NAME_MAX:
729 *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
730 break;
731 case _PC_PATH_MAX:
732 *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
733 break;
734 default:
735 error=EINVAL;
736 }
737 return(error);
738}
739
a9bb80e0 740/*
81b5c339 741 * nwfs_strategy(struct vnode *a_vp, struct bio *a_bio)
a9bb80e0
CP
742 */
743static int
744nwfs_strategy(struct vop_strategy_args *ap)
984263bc 745{
81b5c339
MD
746 struct bio *bio = ap->a_bio;
747 struct buf *bp = bio->bio_buf;
984263bc 748 int error = 0;
dadab5e9 749 struct thread *td = NULL;
984263bc
MD
750
751 NCPVNDEBUG("\n");
dadab5e9
MD
752 if ((bp->b_flags & B_ASYNC) == 0)
753 td = curthread; /* YYY dunno if this is legal */
984263bc
MD
754 /*
755 * If the op is asynchronous and an i/o daemon is waiting
756 * queue the request, wake it up and wait for completion
757 * otherwise just do it ourselves.
758 */
759 if ((bp->b_flags & B_ASYNC) == 0 )
81b5c339 760 error = nwfs_doio(ap->a_vp, bio, proc0.p_ucred, td);
984263bc
MD
761 return (error);
762}
763
a9bb80e0 764/*
54078292
MD
765 * nwfs_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
766 * off_t *a_doffsetp, int *a_runp, int *a_runb)
a9bb80e0 767 */
984263bc 768static int
a9bb80e0 769nwfs_bmap(struct vop_bmap_args *ap)
984263bc
MD
770{
771 struct vnode *vp = ap->a_vp;
772
773 if (ap->a_vpp != NULL)
774 *ap->a_vpp = vp;
54078292
MD
775 if (ap->a_doffsetp != NULL)
776 *ap->a_doffsetp = ap->a_loffset;
984263bc
MD
777 if (ap->a_runp != NULL)
778 *ap->a_runp = 0;
779 if (ap->a_runb != NULL)
780 *ap->a_runb = 0;
781 return (0);
782}
783
784int
7648a732 785nwfs_nget(struct mount *mp, ncpfid fid, const struct nw_entry_info *fap,
984263bc
MD
786 struct vnode *dvp, struct vnode **vpp)
787{
788 int error;
789 struct nwnode *newnp;
790 struct vnode *vp;
791
792 *vpp = NULL;
793 error = nwfs_allocvp(mp, fid, &vp);
794 if (error)
795 return error;
796 newnp = VTONW(vp);
797 if (fap) {
798 newnp->n_attr = fap->attributes;
799 vp->v_type = newnp->n_attr & aDIR ? VDIR : VREG;
800 nwfs_attr_cacheenter(vp, fap);
801 }
802 if (dvp) {
803 newnp->n_parent = VTONW(dvp)->n_fid;
804 if ((newnp->n_flag & NNEW) && vp->v_type == VDIR) {
805 if ((dvp->v_flag & VROOT) == 0) {
806 newnp->n_refparent = 1;
807 vref(dvp); /* vhold */
808 }
809 }
810 } else {
811 if ((newnp->n_flag & NNEW) && vp->v_type == VREG)
812 printf("new vnode '%s' borned without parent ?\n",newnp->n_name);
813 }
814 newnp->n_flag &= ~NNEW;
815 *vpp = vp;
816 return 0;
817}
818
819/*
820 * How to keep the brain busy ...
821 * Currently lookup routine can make two lookup for vnode. This can be
822 * avoided by reorg the code.
a9bb80e0
CP
823 *
824 * nwfs_lookup(struct vnodeop_desc *a_desc, struct vnode *a_dvp,
825 * struct vnode **a_vpp, struct componentname *a_cnp)
984263bc
MD
826 */
827int
e62afb5f 828nwfs_lookup(struct vop_old_lookup_args *ap)
984263bc
MD
829{
830 struct componentname *cnp = ap->a_cnp;
831 struct vnode *dvp = ap->a_dvp;
832 struct vnode **vpp = ap->a_vpp;
833 int flags = cnp->cn_flags;
834 struct vnode *vp;
835 struct nwmount *nmp;
836 struct mount *mp = dvp->v_mount;
837 struct nwnode *dnp, *npp;
838 struct nw_entry_info fattr, *fap;
839 ncpfid fid;
fad57d0e 840 int nameiop=cnp->cn_nameiop;
984263bc 841 int lockparent, wantparent, error = 0, notfound;
dadab5e9 842 struct thread *td = cnp->cn_td;
984263bc
MD
843 char _name[cnp->cn_namelen+1];
844 bcopy(cnp->cn_nameptr,_name,cnp->cn_namelen);
845 _name[cnp->cn_namelen]=0;
846
847 if (dvp->v_type != VDIR)
848 return (ENOTDIR);
2b69e610 849 if ((flags & CNP_ISDOTDOT) && (dvp->v_flag & VROOT)) {
984263bc
MD
850 printf("nwfs_lookup: invalid '..'\n");
851 return EIO;
852 }
853
854 NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name,
855 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
856
fad57d0e 857 if ((mp->mnt_flag & MNT_RDONLY) && nameiop != NAMEI_LOOKUP)
984263bc 858 return (EROFS);
87de5057 859 if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred)))
984263bc 860 return (error);
2b69e610
MD
861 lockparent = flags & CNP_LOCKPARENT;
862 wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
984263bc
MD
863 nmp = VFSTONWFS(mp);
864 dnp = VTONW(dvp);
865/*
2b69e610 866printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_flag & VROOT, (int)flags & CNP_ISDOTDOT);
984263bc
MD
867*/
868 error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls,
2b69e610 869 (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
984263bc
MD
870 if (error)
871 return ENOENT;
872
984263bc
MD
873 error = 0;
874 *vpp = NULLVP;
875 fap = NULL;
2b69e610 876 if (flags & CNP_ISDOTDOT) {
984263bc
MD
877 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
878 fid = nmp->n_rootent;
879 fap = NULL;
880 notfound = 0;
881 } else {
dadab5e9 882 error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
984263bc
MD
883 if (error) {
884 return error;
885 }
886 fid = dnp->n_parent;
887 fap = &fattr;
888 /*np = *npp;*/
889 notfound = ncp_obtain_info(nmp, npp->n_dosfid,
dadab5e9 890 0, NULL, fap, td, cnp->cn_cred);
984263bc
MD
891 }
892 } else {
893 fap = &fattr;
894 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
dadab5e9 895 fap, td, cnp->cn_cred);
984263bc
MD
896 fid.f_id = fap->dirEntNum;
897 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
898 fid.f_parent = dnp->n_fid.f_parent;
899 } else
900 fid.f_parent = dnp->n_fid.f_id;
901 NCPVNDEBUG("call to ncp_lookup returned=%d\n",notfound);
902 }
903 if (notfound && notfound < 0x80 )
904 return (notfound); /* hard error */
905 if (notfound) { /* entry not found */
906 /* Handle RENAME or CREATE case... */
fad57d0e 907 if ((nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) && wantparent) {
984263bc 908 if (!lockparent)
ca466bae 909 VOP_UNLOCK(dvp, 0);
984263bc
MD
910 return (EJUSTRETURN);
911 }
912 return ENOENT;
913 }/* else {
914 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
915 }*/
916 /* handle DELETE case ... */
fad57d0e 917 if (nameiop == NAMEI_DELETE) { /* delete last component */
87de5057 918 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
984263bc
MD
919 if (error) return (error);
920 if (NWCMPF(&dnp->n_fid, &fid)) { /* we found ourselfs */
597aea93 921 vref(dvp);
984263bc
MD
922 *vpp = dvp;
923 return 0;
924 }
925 error = nwfs_nget(mp, fid, fap, dvp, &vp);
926 if (error) return (error);
927 *vpp = vp;
ca466bae 928 if (!lockparent) VOP_UNLOCK(dvp, 0);
984263bc
MD
929 return (0);
930 }
fad57d0e 931 if (nameiop == NAMEI_RENAME && wantparent) {
87de5057 932 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
984263bc
MD
933 if (error) return (error);
934 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
935 error = nwfs_nget(mp, fid, fap, dvp, &vp);
936 if (error) return (error);
937 *vpp = vp;
984263bc 938 if (!lockparent)
ca466bae 939 VOP_UNLOCK(dvp, 0);
984263bc
MD
940 return (0);
941 }
2b69e610 942 if (flags & CNP_ISDOTDOT) {
ca466bae 943 VOP_UNLOCK(dvp, 0); /* race to get the inode */
984263bc
MD
944 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
945 if (error) {
ca466bae 946 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
947 return (error);
948 }
ca466bae 949 if (lockparent && (error = vn_lock(dvp, LK_EXCLUSIVE))) {
984263bc
MD
950 vput(vp);
951 return (error);
952 }
953 *vpp = vp;
954 } else if (NWCMPF(&dnp->n_fid, &fid)) {
955 vref(dvp);
956 *vpp = dvp;
957 } else {
958 error = nwfs_nget(mp, fid, fap, dvp, &vp);
959 if (error) return (error);
960 *vpp = vp;
961 NCPVNDEBUG("lookup: getnewvp!\n");
fad57d0e 962 if (!lockparent)
ca466bae 963 VOP_UNLOCK(dvp, 0);
984263bc 964 }
fad57d0e
MD
965#if 0
966 /* XXX MOVE TO NREMOVE */
967 if ((cnp->cn_flags & CNP_MAKEENTRY)) {
984263bc 968 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
fad57d0e 969 /* XXX */
984263bc 970 }
fad57d0e 971#endif
984263bc
MD
972 return (0);
973}