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