1*94e054a1Sad /* $NetBSD: genfs_node.h,v 1.24 2020/03/14 21:47:41 ad Exp $ */ 2099a6b52Schs 3099a6b52Schs /* 4099a6b52Schs * Copyright (c) 2001 Chuck Silvers. 5099a6b52Schs * All rights reserved. 6099a6b52Schs * 7099a6b52Schs * Redistribution and use in source and binary forms, with or without 8099a6b52Schs * modification, are permitted provided that the following conditions 9099a6b52Schs * are met: 10099a6b52Schs * 1. Redistributions of source code must retain the above copyright 11099a6b52Schs * notice, this list of conditions and the following disclaimer. 12099a6b52Schs * 2. Redistributions in binary form must reproduce the above copyright 13099a6b52Schs * notice, this list of conditions and the following disclaimer in the 14099a6b52Schs * documentation and/or other materials provided with the distribution. 15099a6b52Schs * 3. All advertising materials mentioning features or use of this software 16099a6b52Schs * must display the following acknowledgement: 17099a6b52Schs * This product includes software developed by Chuck Silvers. 18099a6b52Schs * 4. The name of the author may not be used to endorse or promote products 19099a6b52Schs * derived from this software without specific prior written permission. 20099a6b52Schs * 21099a6b52Schs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22099a6b52Schs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23099a6b52Schs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24099a6b52Schs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25099a6b52Schs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26099a6b52Schs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27099a6b52Schs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28099a6b52Schs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29099a6b52Schs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30099a6b52Schs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31099a6b52Schs */ 32099a6b52Schs 33099a6b52Schs #ifndef _MISCFS_GENFS_GENFS_NODE_H_ 34099a6b52Schs #define _MISCFS_GENFS_GENFS_NODE_H_ 35099a6b52Schs 369abeea58Sad #include <sys/rwlock.h> 379abeea58Sad 385f5ac77eSchs struct vm_page; 39fc9422c9Selad struct kauth_cred; 4062ce183fSdogcow struct uio; 414622d2aaSdholland struct vnode; 425f5ac77eSchs 43099a6b52Schs struct genfs_ops { 44b397c875Sperseant void (*gop_size)(struct vnode *, off_t, off_t *, int); 45fc9422c9Selad int (*gop_alloc)(struct vnode *, off_t, off_t, int, 46fc9422c9Selad struct kauth_cred *); 47099a6b52Schs int (*gop_write)(struct vnode *, struct vm_page **, int, int); 48b7bfe828Syamt void (*gop_markupdate)(struct vnode *, int); 49e406c140Schs void (*gop_putrange)(struct vnode *, off_t, off_t *, off_t *); 50099a6b52Schs }; 51099a6b52Schs 52b397c875Sperseant #define GOP_SIZE(vp, size, eobp, flags) \ 53b397c875Sperseant (*VTOG(vp)->g_op->gop_size)((vp), (size), (eobp), (flags)) 54099a6b52Schs #define GOP_ALLOC(vp, off, len, flags, cred) \ 55099a6b52Schs (*VTOG(vp)->g_op->gop_alloc)((vp), (off), (len), (flags), (cred)) 56099a6b52Schs #define GOP_WRITE(vp, pgs, npages, flags) \ 57099a6b52Schs (*VTOG(vp)->g_op->gop_write)((vp), (pgs), (npages), (flags)) 58e406c140Schs #define GOP_PUTRANGE(vp, off, lop, hip) \ 59e406c140Schs (*VTOG(vp)->g_op->gop_putrange)((vp), (off), (lop), (hip)) 60099a6b52Schs 61b7bfe828Syamt /* 62b7bfe828Syamt * GOP_MARKUPDATE: mark vnode's timestamps for update. 63b7bfe828Syamt * 64*94e054a1Sad * => called with vmobjlock (and possibly other locks) held. 65b7bfe828Syamt * => used for accesses via mmap. 66b7bfe828Syamt */ 67b7bfe828Syamt 68b7bfe828Syamt #define GOP_MARKUPDATE(vp, flags) \ 69b7bfe828Syamt (VTOG(vp)->g_op->gop_markupdate) ? \ 70b7bfe828Syamt (*VTOG(vp)->g_op->gop_markupdate)((vp), (flags)) : \ 71b7bfe828Syamt (void)0; 72b7bfe828Syamt 73b397c875Sperseant /* Flags to GOP_SIZE */ 7461d5d436Syamt #define GOP_SIZE_MEM 0x4 /* in-memory size */ 75b397c875Sperseant 76b7bfe828Syamt /* Flags to GOP_MARKUPDATE */ 77b7bfe828Syamt #define GOP_UPDATE_ACCESSED 1 78b7bfe828Syamt #define GOP_UPDATE_MODIFIED 2 79b7bfe828Syamt 80099a6b52Schs struct genfs_node { 8144d128faSyamt const struct genfs_ops *g_op; /* ops vector */ 829abeea58Sad krwlock_t g_glock; /* getpages lock */ 83099a6b52Schs }; 84099a6b52Schs 85099a6b52Schs #define VTOG(vp) ((struct genfs_node *)(vp)->v_data) 86099a6b52Schs 87b397c875Sperseant void genfs_size(struct vnode *, off_t, off_t *, int); 8844d128faSyamt void genfs_node_init(struct vnode *, const struct genfs_ops *); 894abc9f50Sad void genfs_node_destroy(struct vnode *); 90e406c140Schs void genfs_gop_putrange(struct vnode *, off_t, off_t *, off_t *); 91099a6b52Schs int genfs_gop_write(struct vnode *, struct vm_page **, int, int); 92e979c658Sreinoud int genfs_gop_write_rwmap(struct vnode *, struct vm_page **, int, int); 9340bf5f0eSchs int genfs_compat_gop_write(struct vnode *, struct vm_page **, int, int); 9433c1fd19Schs void genfs_directio(struct vnode *, struct uio *, int); 95099a6b52Schs 9637c68a65Syamt void genfs_node_wrlock(struct vnode *); 9737c68a65Syamt void genfs_node_rdlock(struct vnode *); 98e0f79090Suebayasi int genfs_node_rdtrylock(struct vnode *); 9937c68a65Syamt void genfs_node_unlock(struct vnode *); 100fca58884Schs int genfs_node_wrlocked(struct vnode *); 10137c68a65Syamt 102099a6b52Schs #endif /* _MISCFS_GENFS_GENFS_NODE_H_ */ 103