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