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