1 /* $NetBSD: mount_svr4.c,v 1.1.1.2 2009/03/20 20:26:50 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/conf/mount/mount_svr4.c 43 * 44 */ 45 46 /* 47 * SVR4: 48 * Solaris 2.x (SunOS 5.x) and HPUX-11 Mount helper. 49 * -Erez Zadok <ezk@cs.columbia.edu> 50 */ 51 52 #ifdef HAVE_CONFIG_H 53 # include <config.h> 54 #endif /* HAVE_CONFIG_H */ 55 #include <am_defs.h> 56 #include <amu.h> 57 58 59 /* 60 * On Solaris 8 with in-kernel mount table, pass mount options to kernel to 61 * have them evaluated. They will also show up in /etc/mnttab. 62 */ 63 #if defined(MNT2_GEN_OPT_OPTIONSTR) && defined(MAX_MNTOPT_STR) 64 # define sys_mount(fsname, dir, flags, type, data, datasize) \ 65 mount((fsname), (dir), (MNT2_GEN_OPT_OPTIONSTR | flags), (type), \ 66 (data), (datasize), mountopts, sizeof(mountopts)) 67 #else /* not defined(MNT2_GEN_OPT_OPTIONSTR) && defined(MAX_MNTOPT_STR) */ 68 # define sys_mount(fsname, dir, flags, type, data, datasize) \ 69 mount((fsname), (dir), (flags), (type), (data), (datasize)) 70 #endif /* not defined(MNT2_GEN_OPT_OPTIONSTR) && defined(MAX_MNTOPT_STR) */ 71 72 73 /* 74 * Map from conventional mount arguments 75 * to Solaris 2.x (SunOS 5.x) style arguments. 76 */ 77 int 78 mount_svr4(char *fsname, char *dir, int flags, MTYPE_TYPE type, caddr_t data, const char *optstr) 79 { 80 #if defined(MNT2_GEN_OPT_OPTIONSTR) && defined(MAX_MNTOPT_STR) 81 char mountopts[MAX_MNTOPT_STR]; 82 83 /* 84 * Save a copy of the mount options. The kernel will overwrite them with 85 * those it recognizes. 86 */ 87 xstrlcpy(mountopts, optstr, MAX_MNTOPT_STR); 88 #endif /* defined(MNT2_GEN_OPT_OPTIONSTR) && defined(MAX_MNTOPT_STR) */ 89 90 #if defined(MOUNT_TYPE_NFS3) && defined(MNTTAB_TYPE_NFS3) 91 if (STREQ(type, MOUNT_TYPE_NFS3)) { 92 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 93 type, (char *) data, sizeof(nfs_args_t)); 94 } 95 #endif /* defined(MOUNT_TYPE_NFS3) && defined(MNTTAB_TYPE_NFS3) */ 96 97 #if defined(MOUNT_TYPE_NFS) && defined(MNTTAB_TYPE_NFS) 98 if (STREQ(type, MOUNT_TYPE_NFS)) { 99 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 100 type, (char *) data, sizeof(nfs_args_t)); 101 } 102 #endif /* defined(MOUNT_TYPE_NFS) && defined(MNTTAB_TYPE_NFS) */ 103 104 #if defined(MOUNT_TYPE_AUTOFS) && defined(MNTTAB_TYPE_AUTOFS) 105 if (STREQ(type, MOUNT_TYPE_AUTOFS)) { 106 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 107 type, (char *) data, sizeof(autofs_args_t)); 108 } 109 #endif /* defined(MOUNT_TYPE_AUTOFS) && defined(MNTTAB_TYPE_AUTOFS) */ 110 111 #if defined(MOUNT_TYPE_UFS) && defined(MNTTAB_TYPE_UFS) 112 if (STREQ(type, MOUNT_TYPE_UFS)) 113 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 114 type, (char *) data, sizeof(ufs_args_t)); 115 #endif /* defined(MOUNT_TYPE_UFS) && defined(MNTTAB_TYPE_UFS) */ 116 117 #if defined(MOUNT_TYPE_PCFS) && defined(MNTTAB_TYPE_PCFS) 118 if (STREQ(type, MOUNT_TYPE_PCFS)) 119 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 120 type, (char *) data, sizeof(pcfs_args_t)); 121 #endif /* defined(MOUNT_TYPE_PCFS) && defined(MNTTAB_TYPE_PCFS) */ 122 123 #if defined(MOUNT_TYPE_CDFS) && defined(MNTTAB_TYPE_CDFS) 124 /* 125 * HSFS on Solaris allows for 3 HSFSMNT_* flags to be passed 126 * as arguments to the mount(). These flags are bit fields in an 127 * integer, and that integer is passed as the "data" of this system 128 * call. The flags are described in <sys/fs/hsfs_rrip.h>. However, 129 * Solaris does not have an interface to these. It does not define 130 * a structure hsfs_args or anything that one can figure out what 131 * arguments to pass to mount(2) for this type of filesystem. 132 * Therefore, until Sun does, no arguments are passed to this mount 133 * below. 134 * -Erez Zadok <ezk@cs.columbia.edu>. 135 */ 136 if (STREQ(type, MOUNT_TYPE_CDFS)) 137 return sys_mount(fsname, dir, (MNT2_GEN_OPT_FSS | flags), 138 type, (char *) NULL, 0); 139 #endif /* defined(MOUNT_TYPE_CDFS) && defined(MNTTAB_TYPE_CDFS) */ 140 141 #if defined(MOUNT_TYPE_LOFS) && defined(MNTTAB_TYPE_LOFS) 142 if (STREQ(type, MOUNT_TYPE_LOFS)) 143 return sys_mount(fsname, dir, (MNT2_GEN_OPT_FSS | flags), 144 type, (char *) NULL, 0); 145 #endif /* defined(MOUNT_TYPE_LOFS) && defined(MNTTAB_TYPE_LOFS) */ 146 147 #ifdef HAVE_FS_CACHEFS 148 # if defined(MOUNT_TYPE_CACHEFS) && defined(MNTTAB_TYPE_CACHEFS) 149 if (STREQ(type, MOUNT_TYPE_CACHEFS)) 150 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 151 type, (char *) data, sizeof(cachefs_args_t)); 152 # endif /* defined(MOUNT_TYPE_CACHEFS) && defined(MNTTAB_TYPE_CACHEFS) */ 153 #endif /*HAVE_FS_CACHEFS */ 154 155 #ifdef HAVE_FS_AUTOFS 156 # if defined(MOUNT_TYPE_AUTOFS) && defined(MNTTAB_TYPE_AUTOFS) 157 if (STREQ(type, MOUNT_TYPE_AUTOFS)) 158 return sys_mount(fsname, dir, (MNT2_GEN_OPT_DATA | flags), 159 type, (char *) data, sizeof(autofs_args_t)); 160 # endif /* defined(MOUNT_TYPE_AUTOFS) && defined(MNTTAB_TYPE_AUTOFS) */ 161 #endif /* HAVE_FS_AUTOFS */ 162 163 return EINVAL; 164 } 165