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