1/* $NetBSD: tmpfs_specops.c,v 1.16 2021/07/19 01:30:25 dholland Exp $ */ 2 3/* 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code 9 * 2005 program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * tmpfs vnode interface for special devices. 35 */ 36 37#include <sys/cdefs.h> 38__KERNEL_RCSID(0, "$NetBSD: tmpfs_specops.c,v 1.16 2021/07/19 01:30:25 dholland Exp $"); 39 40#include <sys/param.h> 41#include <sys/vnode.h> 42 43#include <fs/tmpfs/tmpfs.h> 44#include <fs/tmpfs/tmpfs_specops.h> 45 46/* 47 * vnode operations vector used for special devices stored in a tmpfs 48 * file system. 49 */ 50 51int (**tmpfs_specop_p)(void *); 52 53const struct vnodeopv_entry_desc tmpfs_specop_entries[] = { 54 { &vop_default_desc, vn_default_error }, 55 GENFS_SPECOP_ENTRIES, 56 { &vop_close_desc, tmpfs_spec_close }, 57 { &vop_access_desc, tmpfs_access }, 58 { &vop_accessx_desc, genfs_accessx }, 59 { &vop_getattr_desc, tmpfs_getattr }, 60 { &vop_setattr_desc, tmpfs_setattr }, 61 { &vop_read_desc, tmpfs_spec_read }, 62 { &vop_write_desc, tmpfs_spec_write }, 63 { &vop_fcntl_desc, genfs_fcntl }, 64 { &vop_fsync_desc, spec_fsync }, 65 { &vop_inactive_desc, tmpfs_inactive }, 66 { &vop_reclaim_desc, tmpfs_reclaim }, 67 { &vop_lock_desc, genfs_lock }, 68 { &vop_unlock_desc, genfs_unlock }, 69 { &vop_print_desc, tmpfs_print }, 70 { &vop_islocked_desc, genfs_islocked }, 71 { &vop_bwrite_desc, vn_bwrite }, 72 { NULL, NULL } 73}; 74 75const struct vnodeopv_desc tmpfs_specop_opv_desc = { 76 &tmpfs_specop_p, tmpfs_specop_entries 77}; 78 79int 80tmpfs_spec_close(void *v) 81{ 82 struct vop_close_args /* { 83 struct vnode *a_vp; 84 int a_fflag; 85 kauth_cred_t a_cred; 86 } */ *ap __unused = v; 87 88 return VOCALL(spec_vnodeop_p, VOFFSET(vop_close), v); 89} 90 91int 92tmpfs_spec_read(void *v) 93{ 94 struct vop_read_args /* { 95 struct vnode *a_vp; 96 struct uio *a_uio; 97 int a_ioflag; 98 kauth_cred_t a_cred; 99 } */ *ap = v; 100 vnode_t *vp = ap->a_vp; 101 102 tmpfs_update(vp, TMPFS_UPDATE_ATIME); 103 return VOCALL(spec_vnodeop_p, VOFFSET(vop_read), v); 104} 105 106int 107tmpfs_spec_write(void *v) 108{ 109 struct vop_write_args /* { 110 struct vnode *a_vp; 111 struct uio *a_uio; 112 int a_ioflag; 113 kauth_cred_t a_cred; 114 } */ *ap = v; 115 vnode_t *vp = ap->a_vp; 116 117 tmpfs_update(vp, TMPFS_UPDATE_MTIME); 118 return VOCALL(spec_vnodeop_p, VOFFSET(vop_write), v); 119} 120