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