specdev.h revision 1.48 1 1.48 riastrad /* $NetBSD: specdev.h,v 1.48 2022/03/28 12:36:42 riastradh Exp $ */
2 1.34 ad
3 1.34 ad /*-
4 1.34 ad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.34 ad * All rights reserved.
6 1.34 ad *
7 1.34 ad * Redistribution and use in source and binary forms, with or without
8 1.34 ad * modification, are permitted provided that the following conditions
9 1.34 ad * are met:
10 1.34 ad * 1. Redistributions of source code must retain the above copyright
11 1.34 ad * notice, this list of conditions and the following disclaimer.
12 1.34 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.34 ad * notice, this list of conditions and the following disclaimer in the
14 1.34 ad * documentation and/or other materials provided with the distribution.
15 1.34 ad *
16 1.34 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.34 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.34 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.34 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.34 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.34 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.34 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.34 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.34 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.34 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.34 ad * POSSIBILITY OF SUCH DAMAGE.
27 1.34 ad */
28 1.8 cgd
29 1.1 cgd /*
30 1.7 mycroft * Copyright (c) 1990, 1993
31 1.7 mycroft * The Regents of the University of California. All rights reserved.
32 1.1 cgd *
33 1.1 cgd * Redistribution and use in source and binary forms, with or without
34 1.1 cgd * modification, are permitted provided that the following conditions
35 1.1 cgd * are met:
36 1.1 cgd * 1. Redistributions of source code must retain the above copyright
37 1.1 cgd * notice, this list of conditions and the following disclaimer.
38 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
39 1.1 cgd * notice, this list of conditions and the following disclaimer in the
40 1.1 cgd * documentation and/or other materials provided with the distribution.
41 1.24 agc * 3. Neither the name of the University nor the names of its contributors
42 1.1 cgd * may be used to endorse or promote products derived from this software
43 1.1 cgd * without specific prior written permission.
44 1.1 cgd *
45 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 1.1 cgd * SUCH DAMAGE.
56 1.1 cgd *
57 1.17 fvdl * @(#)specdev.h 8.6 (Berkeley) 5/21/95
58 1.1 cgd */
59 1.34 ad
60 1.23 matt #ifndef _MISCFS_SPECFS_SPECDEV_H_
61 1.23 matt #define _MISCFS_SPECFS_SPECDEV_H_
62 1.1 cgd
63 1.34 ad #include <sys/mutex.h>
64 1.34 ad #include <sys/vnode.h>
65 1.34 ad
66 1.34 ad typedef struct specnode {
67 1.34 ad vnode_t *sn_next;
68 1.34 ad struct specdev *sn_dev;
69 1.47 riastrad u_int sn_opencnt; /* # of opens, share of sd_opencnt */
70 1.34 ad dev_t sn_rdev;
71 1.34 ad bool sn_gone;
72 1.34 ad } specnode_t;
73 1.34 ad
74 1.34 ad typedef struct specdev {
75 1.34 ad struct mount *sd_mountpoint;
76 1.34 ad struct lockf *sd_lockf;
77 1.34 ad vnode_t *sd_bdevvp;
78 1.47 riastrad u_int sd_opencnt; /* # of opens; close when ->0 */
79 1.47 riastrad u_int sd_refcnt; /* # of specnodes referencing this */
80 1.34 ad dev_t sd_rdev;
81 1.48 riastrad bool sd_opened; /* true if successfully opened */
82 1.34 ad } specdev_t;
83 1.34 ad
84 1.1 cgd /*
85 1.1 cgd * Exported shorthand
86 1.1 cgd */
87 1.34 ad #define v_specnext v_specnode->sn_next
88 1.34 ad #define v_rdev v_specnode->sn_rdev
89 1.34 ad #define v_speclockf v_specnode->sn_dev->sd_lockf
90 1.1 cgd
91 1.1 cgd /*
92 1.1 cgd * Special device management
93 1.1 cgd */
94 1.34 ad void spec_node_init(vnode_t *, dev_t);
95 1.34 ad void spec_node_destroy(vnode_t *);
96 1.40 hannken int spec_node_lookup_by_dev(enum vtype, dev_t, vnode_t **);
97 1.40 hannken int spec_node_lookup_by_mount(struct mount *, vnode_t **);
98 1.42 hannken struct mount *spec_node_getmountedfs(vnode_t *);
99 1.42 hannken void spec_node_setmountedfs(vnode_t *, struct mount *);
100 1.34 ad void spec_node_revoke(vnode_t *);
101 1.1 cgd
102 1.1 cgd /*
103 1.1 cgd * Prototypes for special file operations on vnodes.
104 1.1 cgd */
105 1.27 xtraeme extern int (**spec_vnodeop_p)(void *);
106 1.1 cgd struct nameidata;
107 1.7 mycroft struct componentname;
108 1.1 cgd struct flock;
109 1.1 cgd struct buf;
110 1.1 cgd struct uio;
111 1.1 cgd
112 1.27 xtraeme int spec_lookup(void *);
113 1.27 xtraeme int spec_open(void *);
114 1.27 xtraeme int spec_close(void *);
115 1.27 xtraeme int spec_read(void *);
116 1.27 xtraeme int spec_write(void *);
117 1.43 dholland int spec_fdiscard(void *);
118 1.27 xtraeme int spec_ioctl(void *);
119 1.27 xtraeme int spec_poll(void *);
120 1.27 xtraeme int spec_kqfilter(void *);
121 1.31 pooka int spec_mmap(void *);
122 1.27 xtraeme int spec_fsync(void *);
123 1.16 kleink #define spec_seek genfs_nullop /* XXX should query device */
124 1.27 xtraeme int spec_inactive(void *);
125 1.44 hannken int spec_reclaim(void *);
126 1.27 xtraeme int spec_bmap(void *);
127 1.27 xtraeme int spec_strategy(void *);
128 1.27 xtraeme int spec_print(void *);
129 1.27 xtraeme int spec_pathconf(void *);
130 1.27 xtraeme int spec_advlock(void *);
131 1.23 matt
132 1.45 dholland /*
133 1.45 dholland * This macro provides an initializer list for the fs-independent part
134 1.45 dholland * of a filesystem's special file vnode ops descriptor table. We still
135 1.45 dholland * need such a table in every filesystem, but we can at least avoid
136 1.45 dholland * the cutpaste.
137 1.45 dholland *
138 1.45 dholland * This contains these ops:
139 1.45 dholland * parsepath lookup
140 1.45 dholland * create whiteout mknod open fallocate fdiscard ioctl poll kqfilter
141 1.45 dholland * revoke mmap seek remove link rename mkdir rmdir symlink readdir
142 1.45 dholland * readlink abortop bmap strategy pathconf advlock getpages putpages
143 1.45 dholland *
144 1.45 dholland * The filesystem should provide these ops that need to be its own:
145 1.45 dholland * access and accessx
146 1.45 dholland * getattr
147 1.45 dholland * setattr
148 1.45 dholland * fcntl
149 1.45 dholland * inactive
150 1.45 dholland * reclaim
151 1.45 dholland * lock
152 1.45 dholland * unlock
153 1.45 dholland * print (should probably also call spec_print)
154 1.45 dholland * islocked
155 1.45 dholland * bwrite (normally vn_bwrite)
156 1.45 dholland * openextattr
157 1.45 dholland * closeextattr
158 1.45 dholland * getextattr
159 1.45 dholland * setextattr
160 1.45 dholland * listextattr
161 1.45 dholland * deleteextattr
162 1.45 dholland * getacl
163 1.45 dholland * setacl
164 1.45 dholland * aclcheck
165 1.45 dholland *
166 1.45 dholland * The filesystem should also provide these ops that some filesystems
167 1.45 dholland * do their own things with:
168 1.45 dholland * close
169 1.45 dholland * read
170 1.45 dholland * write
171 1.45 dholland * fsync
172 1.45 dholland * In most cases "their own things" means adjust timestamps and call
173 1.45 dholland * spec_foo. For fsync it varies, but should always also call spec_fsync.
174 1.45 dholland *
175 1.45 dholland * Note that because the op descriptor tables are unordered it does not
176 1.45 dholland * matter where in the table this macro goes (except I think default
177 1.45 dholland * still needs to be first...)
178 1.45 dholland */
179 1.45 dholland #define GENFS_SPECOP_ENTRIES \
180 1.45 dholland { &vop_parsepath_desc, genfs_badop }, /* parsepath */ \
181 1.45 dholland { &vop_lookup_desc, spec_lookup }, /* lookup */ \
182 1.45 dholland { &vop_create_desc, genfs_badop }, /* create */ \
183 1.45 dholland { &vop_whiteout_desc, genfs_badop }, /* whiteout */ \
184 1.45 dholland { &vop_mknod_desc, genfs_badop }, /* mknod */ \
185 1.45 dholland { &vop_open_desc, spec_open }, /* open */ \
186 1.45 dholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ \
187 1.45 dholland { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */ \
188 1.45 dholland { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ \
189 1.45 dholland { &vop_poll_desc, spec_poll }, /* poll */ \
190 1.45 dholland { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ \
191 1.45 dholland { &vop_revoke_desc, genfs_revoke }, /* revoke */ \
192 1.45 dholland { &vop_mmap_desc, spec_mmap }, /* mmap */ \
193 1.45 dholland { &vop_seek_desc, spec_seek }, /* seek */ \
194 1.45 dholland { &vop_remove_desc, genfs_badop }, /* remove */ \
195 1.45 dholland { &vop_link_desc, genfs_badop }, /* link */ \
196 1.45 dholland { &vop_rename_desc, genfs_badop }, /* rename */ \
197 1.45 dholland { &vop_mkdir_desc, genfs_badop }, /* mkdir */ \
198 1.45 dholland { &vop_rmdir_desc, genfs_badop }, /* rmdir */ \
199 1.45 dholland { &vop_symlink_desc, genfs_badop }, /* symlink */ \
200 1.45 dholland { &vop_readdir_desc, genfs_badop }, /* readdir */ \
201 1.45 dholland { &vop_readlink_desc, genfs_badop }, /* readlink */ \
202 1.45 dholland { &vop_abortop_desc, genfs_badop }, /* abortop */ \
203 1.45 dholland { &vop_bmap_desc, spec_bmap }, /* bmap */ \
204 1.45 dholland { &vop_strategy_desc, spec_strategy }, /* strategy */ \
205 1.45 dholland { &vop_pathconf_desc, spec_pathconf }, /* pathconf */ \
206 1.45 dholland { &vop_advlock_desc, spec_advlock }, /* advlock */ \
207 1.45 dholland { &vop_getpages_desc, genfs_getpages }, /* getpages */ \
208 1.45 dholland { &vop_putpages_desc, genfs_putpages } /* putpages */
209 1.45 dholland
210 1.45 dholland
211 1.38 elad bool iskmemvp(struct vnode *);
212 1.39 elad void spec_init(void);
213 1.38 elad
214 1.23 matt #endif /* _MISCFS_SPECFS_SPECDEV_H_ */
215