remove knfs support
[arla.git] / nnpfs / bsd / nnpfs_vfsops-bsd.c
blobc92aeac57f2152f5edef4a8bd60f5144b3dd4788
1 /*
2 * Copyright (c) 1995-2002, 2004-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include <nnpfs/nnpfs_locl.h>
36 RCSID("$Id$");
39 * NNPFS vfs operations.
42 #include <nnpfs/nnpfs_common.h>
43 #include <nnpfs/nnpfs_message.h>
44 #include <nnpfs/nnpfs_fs.h>
45 #include <nnpfs/nnpfs_dev.h>
46 #include <nnpfs/nnpfs_deb.h>
47 #include <nnpfs/nnpfs_vfsops.h>
48 #include <nnpfs/nnpfs_vfsops-bsd.h>
49 #include <nnpfs/nnpfs_vnodeops.h>
51 #ifndef __APPLE__
52 int
53 nnpfs_mount_caddr(struct mount *mp,
54 const char *user_path,
55 caddr_t user_data,
56 struct nameidata *ndp,
57 d_thread_t *p)
59 return nnpfs_mount_common(mp, user_path, user_data, ndp, p);
62 int
63 nnpfs_start(struct mount * mp, int flags, d_thread_t * p)
65 NNPFSDEB(XDEBVFOPS, ("nnpfs_start mp = %lx, flags = %d, proc = %lx\n",
66 (unsigned long)mp, flags, (unsigned long)p));
67 return 0;
70 int
71 nnpfs_unmount(struct mount * mp, int mntflags, d_thread_t *p)
73 NNPFSDEB(XDEBVFOPS, ("nnpfs_umount: mp = %lx, mntflags = %d, proc = %lx\n",
74 (unsigned long)mp, mntflags, (unsigned long)p));
75 return nnpfs_unmount_common(mp, mntflags);
78 int
79 nnpfs_root(struct mount *mp, struct vnode **vpp)
81 NNPFSDEB(XDEBVFOPS, ("nnpfs_root mp = %lx\n", (unsigned long)mp));
83 return nnpfs_root_common(mp, vpp, nnpfs_curproc());
86 int
87 nnpfs_quotactl(struct mount *mp, int cmd, uid_t uid, caddr_t arg, d_thread_t *p)
89 NNPFSDEB(XDEBVFOPS, ("nnpfs_quotactl: mp = %lx, cmd = %d, uid = %u, "
90 "arg = %lx, proc = %lx\n",
91 (unsigned long)mp, cmd, uid,
92 (unsigned long)arg, (unsigned long)p));
93 return EOPNOTSUPP;
96 int
97 nnpfs_statfs(struct mount *mp, nnpfs_statvfs *sbp, d_thread_t *p)
99 NNPFSDEB(XDEBVFOPS, ("nnpfs_statfs: mp = %lx, sbp = %lx, proc = %lx\n",
100 (unsigned long)mp,
101 (unsigned long)sbp,
102 (unsigned long)p));
103 bcopy(&mp->mnt_stat, sbp, sizeof(*sbp));
104 return 0;
107 #if defined(__DragonFly__) || (defined(__FreeBSD_version) && __FreeBSD_version > 600006)
109 nnpfs_sync(struct mount *mp, int waitfor, d_thread_t *p)
111 NNPFSDEB(XDEBVFOPS, ("nnpfs_sync: mp = %lx, waitfor = %d, "
112 "proc = %lx\n",
113 (unsigned long)mp,
114 waitfor,
115 (unsigned long)p));
116 return 0;
118 #else
120 nnpfs_sync(struct mount *mp, int waitfor, nnpfs_kernel_cred cred, d_thread_t *p)
122 NNPFSDEB(XDEBVFOPS, ("nnpfs_sync: mp = %lx, waitfor = %d, "
123 "cred = %lx, proc = %lx\n",
124 (unsigned long)mp,
125 waitfor,
126 (unsigned long)cred,
127 (unsigned long)p));
128 return 0;
130 #endif
133 nnpfs_snapshot(struct mount *mp, struct vnode *vp, struct timespec *ts)
135 NNPFSDEB(XDEBVFOPS, ("nnpfs_snapshot: mp = %lx\n",
136 (unsigned long)mp));
137 return EOPNOTSUPP;
141 nnpfs_vget(struct mount * mp, ino_t ino, struct vnode ** vpp)
143 NNPFSDEB(XDEBVFOPS, ("nnpfs_vget\n"));
144 return EOPNOTSUPP;
147 static int
148 common_fhtovp(struct mount * mp,
149 struct fid * fhp,
150 struct vnode ** vpp)
152 return EOPNOTSUPP;
155 /* new style fhtovp */
157 #ifdef HAVE_STRUCT_VFSOPS_VFS_CHECKEXP
159 nnpfs_fhtovp(struct mount * mp,
160 struct fid * fhp,
161 struct vnode ** vpp)
163 return common_fhtovp (mp, fhp, vpp);
166 #else /* !HAVE_STRUCT_VFSOPS_VFS_CHECKEXP */
168 /* old style fhtovp */
171 nnpfs_fhtovp(struct mount * mp,
172 struct fid * fhp,
173 struct mbuf * nam,
174 struct vnode ** vpp,
175 int *exflagsp,
176 struct ucred ** credanonp)
178 static struct ucred fhtovpcred;
179 int error;
181 /* XXX: Should see if we is exported to this client */
182 #if 0
183 np = vfs_export_lookup(mp, &ump->um_export, nam);
184 if (np == NULL)
185 return EACCES;
186 #endif
187 error = common_fhtovp(mp, fhp, vpp);
188 if (error == 0) {
189 fhtovpcred.cr_uid = 0;
190 fhtovpcred.cr_gid = 0;
191 fhtovpcred.cr_ngroups = 0;
193 #ifdef MNT_EXPUBLIC
194 *exflagsp = MNT_EXPUBLIC;
195 #else
196 *exflagsp = 0;
197 #endif
198 *credanonp = &fhtovpcred;
200 return error;
202 #endif /* !HAVE_STRUCT_VFSOPS_VFS_CHECKEXP */
205 nnpfs_checkexp (struct mount *mp,
206 #if defined(__FreeBSD__) || defined(__DragonFly__)
207 struct sockaddr *nam,
208 #else
209 struct mbuf *nam,
210 #endif
211 int *exflagsp,
212 struct ucred **credanonp)
214 #if 0
215 struct netcred *np;
216 #endif
218 NNPFSDEB(XDEBVFOPS, ("nnpfs_checkexp\n"));
220 #if 0
221 np = vfs_export_lookup(mp, &ump->um_export, nam);
222 if (np == NULL)
223 return EACCES;
224 #endif
225 return 0;
229 nnpfs_vptofh(struct vnode * vp,
230 struct fid * fhp
231 #if defined(__NetBSD__) && __NetBSD_Version__ >= 399002200 /* 3.99.22 */
232 ,size_t * fidsz
233 #endif
236 NNPFSDEB(XDEBVFOPS, ("nnpfs_vptofh\n"));
237 return EOPNOTSUPP;
240 #endif /* !__APPLE__ */
243 * nnpfs complete dead vnodes implementation.
245 * this is because the dead_vnodeops_p is _not_ filesystem, but rather
246 * a part of the vfs-layer.
249 #ifdef __APPLE__
251 nnpfs_dead_lookup(struct vnop_lookup_args * ap)
252 #else
254 nnpfs_dead_lookup(struct vop_lookup_args * ap)
255 /* struct vop_lookup_args {
256 struct vnodeop_desc *a_desc;
257 struct vnode *a_dvp;
258 struct vnode **a_vpp;
259 struct componentname *a_cnp;
260 }; */
261 #endif
263 *ap->a_vpp = NULL;
264 return ENOTDIR;
271 #ifdef HAVE_VOP_PUTPAGES
273 nnpfs_dead_putpages (struct vop_putpages_args *ap)
275 struct vnode *vp = ap->a_vp;
276 #ifdef __FreeBSD__
277 NNPFSDEB(XDEBVNOPS, ("nnpfs_dead_putpages %s\n", ap->a_gen.a_desc->vdesc_name));
278 #else
279 NNPFSDEB(XDEBVNOPS, ("nnpfs_dead_putpages %s\n", ap->a_desc->vdesc_name));
280 #endif
281 #ifndef __DragonFly__
282 nnpfs_interlock_unlock(&vp->v_interlock)
283 #endif
284 return 0;
286 #endif
289 * Given `fsid', `fileid', and `gen', return in `vpp' a locked and
290 * ref'ed vnode from that file system with that id and generation.
291 * All is done in the context of `proc'. Returns 0 if succesful, and
292 * error otherwise.
295 #ifdef __APPLE__
298 nnpfs_fhlookup (d_thread_t *proc,
299 struct nnpfs_fhandle_t *fhp,
300 struct vnode **vpp)
302 /* XXX write code here */
303 *vpp = NULL;
304 return ESTALE;
307 #else
310 nnpfs_fhlookup (d_thread_t *proc,
311 struct nnpfs_fhandle_t *fhp,
312 struct vnode **vpp)
314 int error;
315 struct mount *mp;
316 #if !(defined(HAVE_GETFH) && defined(HAVE_FHOPEN))
317 struct ucred *cred = proc->p_ucred;
318 struct vattr vattr;
319 fsid_t fsid;
320 struct nnpfs_fh_args *fh_args = (struct nnpfs_fh_args *)fhp->fhdata;
322 NNPFSDEB(XDEBVFOPS, ("nnpfs_fhlookup (nnpfs)\n"));
324 error = nnpfs_suser (proc);
325 if (error)
326 return EPERM;
328 if (fhp->len < sizeof(struct nnpfs_fh_args))
329 return EINVAL;
331 fsid = SCARG(fh_args, fsid);
333 mp = nnpfs_vfs_getvfs (&fsid);
334 if (mp == NULL)
335 return ENXIO;
337 #ifdef __APPLE__
339 uint32_t ino = SCARG(fh_args, fileid);
340 error = VFS_VGET(mp, &ino, vpp);
342 #else
343 error = VFS_VGET(mp, SCARG(fh_args, fileid), vpp);
344 #endif
346 if (error)
347 return error;
349 if (*vpp == NULL)
350 return ENOENT;
352 error = VOP_GETATTR(*vpp, &vattr, cred, proc);
353 if (error) {
354 vput(*vpp);
355 return error;
358 if (vattr.va_gen != SCARG(fh_args, gen)) {
359 vput(*vpp);
360 return ENOENT;
362 #else /* HAVE_GETFH && HAVE_FHOPEN */
364 fhandle_t *fh = (fhandle_t *) fhp;
366 NNPFSDEB(XDEBVFOPS, ("nnpfs_fhlookup (native)\n"));
368 mp = nnpfs_vfs_getvfs (&fh->fh_fsid);
369 if (mp == NULL)
370 return ESTALE;
372 #ifdef __APPLE__ /* XXX write code here */
373 *vpp = NULL;
374 return ESTALE;
375 #else
376 if ((error = VFS_FHTOVP(mp, &fh->fh_fid, vpp)) != 0) {
377 *vpp = NULL;
378 return error;
380 #endif
382 #endif /* HAVE_GETFH && HAVE_FHOPEN */
384 #ifdef __APPLE__
385 if ((*vpp)->v_type == VREG && (!UBCINFOEXISTS(*vpp)))
386 ubc_info_init(*vpp);
388 ubc_hold(*vpp);
389 #endif
391 return 0;
393 #endif
396 #ifndef __APPLE__
398 * Perform an open operation on the vnode identified by a `nnpfs_fhandle_t'
399 * (see nnpfs_fhlookup) with flags `user_flags'. Returns 0 or
400 * error. If successful, the file descriptor is returned in `retval'.
403 #ifndef __FreeBSD__
404 /* sometimes declared in <sys/file.h> */
405 extern KERNEL_VAR_VNOPS_CONST struct fileops vnops;
406 #endif
409 nnpfs_fhopen (d_thread_t *proc,
410 struct nnpfs_fhandle_t *fhp,
411 int user_flags,
412 register_t *retval)
414 int error;
415 struct vnode *vp;
416 nnpfs_kernel_cred cred = nnpfs_proc_to_cred(proc);
417 int flags = FFLAGS(user_flags);
418 int index;
419 struct file *fp;
420 int mode;
421 struct nnpfs_fhandle_t fh;
423 NNPFSDEB(XDEBVFOPS, ("nnpfs_fhopen: flags = %d\n", user_flags));
425 error = copyin (fhp, &fh, sizeof(fh));
426 if (error)
427 return error;
429 error = nnpfs_fhlookup (proc, &fh, &vp);
430 NNPFSDEB(XDEBVFOPS, ("nnpfs_fhlookup returned %d\n", error));
431 if (error)
432 return error;
434 #if defined(OpenBSD)
435 fdplock(proc->p_fd);
436 #endif
438 switch (vp->v_type) {
439 case VDIR :
440 case VREG :
441 break;
442 case VLNK :
443 error = EMLINK;
444 goto out;
445 default :
446 error = EOPNOTSUPP;
447 goto out;
450 mode = 0;
451 if (flags & FWRITE) {
452 switch (vp->v_type) {
453 case VREG :
454 break;
455 case VDIR :
456 error = EISDIR;
457 goto out;
458 default :
459 error = EOPNOTSUPP;
460 goto out;
463 error = vn_writechk (vp);
464 if (error)
465 goto out;
467 mode |= VWRITE;
469 if (flags & FREAD)
470 mode |= VREAD;
472 if (mode) {
473 error = VOP_ACCESS(vp, mode, cred, proc);
474 if (error)
475 goto out;
478 #if defined(__DragonFly__)
479 error = falloc(proc->td_proc, &fp, &index);
480 #else
481 error = falloc(proc, &fp, &index);
482 #endif
483 if (error)
484 goto out;
486 #if defined(__FreeBSD__) && __FreeBSD_version >= 502000
487 error = VOP_OPEN(vp, flags, cred, proc, index);
488 #else
489 error = VOP_OPEN(vp, flags, cred, proc);
490 #endif
491 if (error)
492 goto out2;
494 if (flags & FWRITE)
495 vp->v_writecount++;
497 fp->f_flag = flags & FMASK;
498 fp->f_type = DTYPE_VNODE;
499 fp->f_ops = &vnops;
500 fp->f_data = (caddr_t)vp;
501 nnpfs_vfs_unlock(vp, proc);
502 *retval = index;
503 #ifdef FILE_SET_MATURE
504 FILE_SET_MATURE(fp);
505 #endif
506 #ifdef FILE_UNUSE
507 FILE_UNUSE(fp, proc);
508 #endif
509 #ifdef __APPLE__
510 *fdflags(proc, index) &= ~UF_RESERVED;
511 #endif
512 #if defined(OpenBSD)
513 fdpunlock(proc->p_fd);
514 #endif
515 return 0;
516 out2:
517 #ifdef FILE_UNUSE
518 FILE_UNUSE(fp, proc);
519 #endif
520 #if defined(__FreeBSD__)
521 fdrop(fp, proc);
522 #elif defined(OpenBSD)
523 fdremove(proc->p_fd, index);
524 closef(fp, proc);
525 #else
526 ffree(fp);
527 #endif
529 out:
531 #if defined(OpenBSD)
532 fdpunlock(proc->p_fd);
533 #endif
535 NNPFSDEB(XDEBVFOPS, ("nnpfs_fhopen: error = %d\n", error));
536 vput(vp);
537 return error;
539 #endif