xref: /netbsd-src/external/bsd/am-utils/dist/amd/ops_TEMPLATE.c (revision 8bae5d409deb915cf7c8f0539fae22ff2cb8a313)
1*8bae5d40Schristos /*	$NetBSD: ops_TEMPLATE.c,v 1.1.1.3 2015/01/17 16:34:15 christos Exp $	*/
2a53f50b9Schristos 
3a53f50b9Schristos /*
4*8bae5d40Schristos  * Copyright (c) 1997-2014 Erez Zadok
5a53f50b9Schristos  * Copyright (c) 1990 Jan-Simon Pendry
6a53f50b9Schristos  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7a53f50b9Schristos  * Copyright (c) 1990 The Regents of the University of California.
8a53f50b9Schristos  * All rights reserved.
9a53f50b9Schristos  *
10a53f50b9Schristos  * This code is derived from software contributed to Berkeley by
11a53f50b9Schristos  * Jan-Simon Pendry at Imperial College, London.
12a53f50b9Schristos  *
13a53f50b9Schristos  * Redistribution and use in source and binary forms, with or without
14a53f50b9Schristos  * modification, are permitted provided that the following conditions
15a53f50b9Schristos  * are met:
16a53f50b9Schristos  * 1. Redistributions of source code must retain the above copyright
17a53f50b9Schristos  *    notice, this list of conditions and the following disclaimer.
18a53f50b9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
19a53f50b9Schristos  *    notice, this list of conditions and the following disclaimer in the
20a53f50b9Schristos  *    documentation and/or other materials provided with the distribution.
21*8bae5d40Schristos  * 3. Neither the name of the University nor the names of its contributors
22a53f50b9Schristos  *    may be used to endorse or promote products derived from this software
23a53f50b9Schristos  *    without specific prior written permission.
24a53f50b9Schristos  *
25a53f50b9Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26a53f50b9Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27a53f50b9Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28a53f50b9Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29a53f50b9Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30a53f50b9Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31a53f50b9Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32a53f50b9Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33a53f50b9Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34a53f50b9Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35a53f50b9Schristos  * SUCH DAMAGE.
36a53f50b9Schristos  *
37a53f50b9Schristos  *
38a53f50b9Schristos  * File: am-utils/amd/ops_TEMPLATE.c
39a53f50b9Schristos  *
40a53f50b9Schristos  */
41a53f50b9Schristos 
42a53f50b9Schristos /*
43a53f50b9Schristos  * An empty template for an amd pseudo filesystem "foofs".
44a53f50b9Schristos  */
45a53f50b9Schristos 
46a53f50b9Schristos /*
47a53f50b9Schristos  * NOTE: if this is an Amd file system, prepend "amfs_" to all foofs symbols
48a53f50b9Schristos  * and renamed the file name to amfs_foofs.c.  If it is a native file system
49a53f50b9Schristos  * (such as pcfs, isofs, or ffs), then you can keep the names as is, and
50a53f50b9Schristos  * just rename the file to ops_foofs.c.
51a53f50b9Schristos  */
52a53f50b9Schristos 
53a53f50b9Schristos #ifdef HAVE_CONFIG_H
54a53f50b9Schristos # include <config.h>
55a53f50b9Schristos #endif /* HAVE_CONFIG_H */
56a53f50b9Schristos #include <am_defs.h>
57a53f50b9Schristos #include <amd.h>
58a53f50b9Schristos 
59a53f50b9Schristos /* forward declarations */
60a53f50b9Schristos static char *foofs_match(am_opts *fo);
61a53f50b9Schristos static int foofs_init(mntfs *mf);
62a53f50b9Schristos static int foofs_mount(am_node *mp, mntfs *mf);
63a53f50b9Schristos static int foofs_umount(am_node *mp, mntfs *mf);
64a53f50b9Schristos static am_node *foofs_lookuppn(am_node *mp, char *fname, int *error_return, int op);
65*8bae5d40Schristos static int foofs_readdir(am_node *mp, void cookie, voidp dp, voidp ep, u_int count);
66a53f50b9Schristos static am_node *foofs_readlink(am_node *mp, int *error_return);
67a53f50b9Schristos static void foofs_mounted(am_node *am, mntfs *mf);
68a53f50b9Schristos static void foofs_umounted(am_node *mp, mntfs *mf);
69a53f50b9Schristos static fserver *foofs_ffserver(mntfs *mf);
70a53f50b9Schristos 
71a53f50b9Schristos 
72a53f50b9Schristos /*
73a53f50b9Schristos  * Foofs operations.
74a53f50b9Schristos  * Define only those you need, others set to 0 (NULL)
75a53f50b9Schristos  */
76a53f50b9Schristos am_ops foofs_ops =
77a53f50b9Schristos {
78a53f50b9Schristos   "foofs",			/* name of file system */
79a53f50b9Schristos   foofs_match,			/* match */
80a53f50b9Schristos   foofs_init,			/* initialize */
81a53f50b9Schristos   foofs_mount,			/* mount vnode */
82a53f50b9Schristos   foofs_umount,			/* unmount vnode */
83a53f50b9Schristos   foofs_lookup_child,		/* lookup path-name */
84a53f50b9Schristos   foofs_mount_child,		/* mount path-name */
85a53f50b9Schristos   foofs_readdir,		/* read directory */
86a53f50b9Schristos   foofs_readlink,		/* read link */
87a53f50b9Schristos   foofs_mounted,		/* after-mount extra actions */
88a53f50b9Schristos   foofs_umounted,		/* after-umount extra actions */
89a53f50b9Schristos   foofs_ffserver,		/* find a file server */
90a53f50b9Schristos   foofs_get_wchan,		/* return the waiting channel */
91a53f50b9Schristos   FS_MKMNT | FS_BACKGROUND | FS_AMQINFO,	/* nfs_fs_flags */
92a53f50b9Schristos #ifdef HAVE_FS_AUTOFS
93a53f50b9Schristos   AUTOFS_TEMPLATE_FS_FLAGS,
94a53f50b9Schristos #endif /* HAVE_FS_AUTOFS */
95a53f50b9Schristos };
96a53f50b9Schristos 
97a53f50b9Schristos 
98a53f50b9Schristos /*
99a53f50b9Schristos  * Check that f/s has all needed fields.
100a53f50b9Schristos  * Returns: matched string if found, NULL otherwise.
101a53f50b9Schristos  */
102a53f50b9Schristos static char *
foofs_match(am_opts * fo)103a53f50b9Schristos foofs_match(am_opts *fo)
104a53f50b9Schristos {
105a53f50b9Schristos   char *cp = "fill this with a way to find the match";
106a53f50b9Schristos 
107a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_match...");
108a53f50b9Schristos 
109a53f50b9Schristos   if (cp)
110a53f50b9Schristos     return cp;			/* OK */
111a53f50b9Schristos 
112a53f50b9Schristos   return NULL;			/* not OK */
113a53f50b9Schristos }
114a53f50b9Schristos 
115a53f50b9Schristos 
116a53f50b9Schristos /*
117a53f50b9Schristos  * Initialize.
118a53f50b9Schristos  * Returns: 0 if OK, non-zero (errno) if failed.
119a53f50b9Schristos  */
120a53f50b9Schristos static int
foofs_init(mntfs * mf)121a53f50b9Schristos foofs_init(mntfs *mf)
122a53f50b9Schristos {
123a53f50b9Schristos   int error = 0;
124a53f50b9Schristos 
125a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_init...");
126a53f50b9Schristos 
127a53f50b9Schristos   error = EPERM;		/* XXX: fixme */
128a53f50b9Schristos   return error;
129a53f50b9Schristos }
130a53f50b9Schristos 
131a53f50b9Schristos 
132a53f50b9Schristos /*
133a53f50b9Schristos  * Mount vnode.
134a53f50b9Schristos  * Returns: 0 if OK, non-zero (errno) if failed.
135a53f50b9Schristos  */
136a53f50b9Schristos static int
foofs_mount(am_node * mp)137a53f50b9Schristos foofs_mount(am_node *mp)
138a53f50b9Schristos {
139a53f50b9Schristos   int error = 0;
140a53f50b9Schristos 
141a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_mount...");
142a53f50b9Schristos 
143a53f50b9Schristos   error = EPERM;		/* XXX: fixme */
144a53f50b9Schristos   return error;
145a53f50b9Schristos }
146a53f50b9Schristos 
147a53f50b9Schristos 
148a53f50b9Schristos /*
149a53f50b9Schristos  * Mount vfs.
150a53f50b9Schristos  * Returns: 0 if OK, non-zero (errno) if failed.
151a53f50b9Schristos  */
152a53f50b9Schristos static int
foofs_fmount(mntfs * mf)153a53f50b9Schristos foofs_fmount(mntfs *mf)
154a53f50b9Schristos {
155a53f50b9Schristos   int error = 0;
156a53f50b9Schristos 
157a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_fmount...");
158a53f50b9Schristos 
159a53f50b9Schristos   error = EPERM;		/* XXX: fixme */
160a53f50b9Schristos   return error;
161a53f50b9Schristos }
162a53f50b9Schristos 
163a53f50b9Schristos 
164a53f50b9Schristos /*
165a53f50b9Schristos  * Unmount vnode.
166a53f50b9Schristos  * Returns: 0 if OK, non-zero (errno) if failed.
167a53f50b9Schristos  */
168a53f50b9Schristos static int
foofs_umount(am_node * mp)169a53f50b9Schristos foofs_umount(am_node *mp)
170a53f50b9Schristos {
171a53f50b9Schristos   int error = 0;
172a53f50b9Schristos 
173a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_umount...");
174a53f50b9Schristos 
175a53f50b9Schristos   error = EPERM;		/* XXX: fixme */
176a53f50b9Schristos   return error;
177a53f50b9Schristos }
178a53f50b9Schristos 
179a53f50b9Schristos 
180a53f50b9Schristos /*
181a53f50b9Schristos  * Unmount VFS.
182a53f50b9Schristos  * Returns: 0 if OK, non-zero (errno) if failed.
183a53f50b9Schristos  */
184a53f50b9Schristos static int
foofs_fumount(mntfs * mf)185a53f50b9Schristos foofs_fumount(mntfs *mf)
186a53f50b9Schristos {
187a53f50b9Schristos   int error = 0;
188a53f50b9Schristos 
189a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_fumount...");
190a53f50b9Schristos 
191a53f50b9Schristos   error = EPERM;		/* XXX: fixme */
192a53f50b9Schristos   return error;
193a53f50b9Schristos }
194a53f50b9Schristos 
195a53f50b9Schristos 
196a53f50b9Schristos /*
197a53f50b9Schristos  * Lookup path-name.
198a53f50b9Schristos  * Returns: the am_node that was found, or NULL if failed.
199a53f50b9Schristos  * If failed, also fills in errno in error_return.
200a53f50b9Schristos  */
201a53f50b9Schristos static am_node *
foofs_lookuppn(am_node * mp,char * fname,int * error_return,int op)202a53f50b9Schristos foofs_lookuppn(am_node *mp, char *fname, int *error_return, int op)
203a53f50b9Schristos {
204a53f50b9Schristos   int error = 0;
205a53f50b9Schristos 
206a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_lookuppn...");
207a53f50b9Schristos 
208a53f50b9Schristos   error = EPERM;			/* XXX: fixme */
209a53f50b9Schristos 
210a53f50b9Schristos   *error_return = error;
211a53f50b9Schristos   return NULL;
212a53f50b9Schristos }
213a53f50b9Schristos 
214a53f50b9Schristos 
215a53f50b9Schristos /*
216a53f50b9Schristos  * Read directory.
217a53f50b9Schristos  * Returns: 0 if OK, non-zero (errno) if failed.
218a53f50b9Schristos  * If OK, fills in ep with chain of directory entries.
219a53f50b9Schristos  */
220a53f50b9Schristos static int
foofs_readdir(am_node * mp,void cookie,voidp dp,voidp ep,u_int count)221*8bae5d40Schristos foofs_readdir(am_node *mp, void cookie, voidp dp, voidp ep, u_int count)
222a53f50b9Schristos {
223a53f50b9Schristos   int error = 0;
224a53f50b9Schristos 
225a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_readdir...");
226a53f50b9Schristos 
227a53f50b9Schristos   error = EPERM;		/* XXX: fixme */
228a53f50b9Schristos   return error;
229a53f50b9Schristos }
230a53f50b9Schristos 
231a53f50b9Schristos 
232a53f50b9Schristos /*
233a53f50b9Schristos  * Read link.
234a53f50b9Schristos  * Returns: am_node found, or NULL if not found.
235a53f50b9Schristos  * If failed, fills in errno in error_return.
236a53f50b9Schristos  */
237a53f50b9Schristos static am_node *
foofs_readlink(am_node * mp,int * error_return)238a53f50b9Schristos foofs_readlink(am_node *mp, int *error_return)
239a53f50b9Schristos {
240a53f50b9Schristos   int error = 0;
241a53f50b9Schristos 
242a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_readlink...");
243a53f50b9Schristos 
244a53f50b9Schristos   error = EPERM;			/* XXX: fixme */
245a53f50b9Schristos 
246a53f50b9Schristos   *error_return = error;
247a53f50b9Schristos   return NULL;
248a53f50b9Schristos }
249a53f50b9Schristos 
250a53f50b9Schristos 
251a53f50b9Schristos /*
252a53f50b9Schristos  * Async mount callback function.
253a53f50b9Schristos  * After the base mount went OK, sometimes
254a53f50b9Schristos  * there are additional actions that are needed.  See union_mounted() and
255a53f50b9Schristos  * toplvl_mounted().
256a53f50b9Schristos  */
257a53f50b9Schristos static void
foofs_mounted(mntfs * mf)258a53f50b9Schristos foofs_mounted(mntfs *mf)
259a53f50b9Schristos {
260a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_mounted...");
261a53f50b9Schristos 
262a53f50b9Schristos   return;
263a53f50b9Schristos }
264a53f50b9Schristos 
265a53f50b9Schristos 
266a53f50b9Schristos /*
267a53f50b9Schristos  * Async unmount callback function.
268a53f50b9Schristos  * After the base umount() succeeds, we may want to take extra actions,
269a53f50b9Schristos  * such as informing remote mount daemons that we've unmounted them.
270a53f50b9Schristos  * See amfs_auto_umounted(), host_umounted(), nfs_umounted().
271a53f50b9Schristos  */
272a53f50b9Schristos static void
foofs_umounted(am_node * mp)273a53f50b9Schristos foofs_umounted(am_node *mp)
274a53f50b9Schristos {
275a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_umounted...");
276a53f50b9Schristos 
277a53f50b9Schristos   return;
278a53f50b9Schristos }
279a53f50b9Schristos 
280a53f50b9Schristos 
281a53f50b9Schristos /*
282a53f50b9Schristos  * Find a file server.
283a53f50b9Schristos  * Returns: fserver of found server, or NULL if not found.
284a53f50b9Schristos  */
285a53f50b9Schristos static fserver *
foofs_ffserver(mntfs * mf)286a53f50b9Schristos foofs_ffserver(mntfs *mf)
287a53f50b9Schristos {
288a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_ffserver...");
289a53f50b9Schristos 
290a53f50b9Schristos   return NULL;
291a53f50b9Schristos }
292a53f50b9Schristos 
293a53f50b9Schristos 
294a53f50b9Schristos /*
295a53f50b9Schristos  * Normally just return mf. Only inherit needs to do special tricks.
296a53f50b9Schristos  */
297a53f50b9Schristos static wchan_t *
foofs_get_wchan(mntfs * mf)298a53f50b9Schristos foofs_get_wchan(mntfs *mf)
299a53f50b9Schristos {
300a53f50b9Schristos   plog(XLOG_INFO, "entering foofs_get_wchan...");
301a53f50b9Schristos 
302a53f50b9Schristos   return mf;
303a53f50b9Schristos }
304