1 /* $NetBSD: mount_aix.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_aix.c
39 *
40 */
41
42 /*
43 * AIX 5.x Mount helper
44 */
45
46 #ifdef HAVE_CONFIG_H
47 # include <config.h>
48 #endif /* HAVE_CONFIG_H */
49 #include <am_defs.h>
50 #include <amu.h>
51
52 #define VMT_ROUNDUP(len) (4 * ((len + 3) / 4))
53 #define VMT_ASSIGN(vp, idx, data, size) \
54 vp->vmt_data[idx].vmt_off = p - (char *) vp; \
55 vp->vmt_data[idx].vmt_size = size; \
56 memmove(p, data, size); \
57 p += VMT_ROUNDUP(size);
58
59 /* missing external definitions from AIX's headers */
60 extern int vmount(struct vmount *vmount, int size);
61
62
63 static int
aix5_mkvp(char * p,int gfstype,int flags,char * object,char * stub,char * host,char * info,int info_size,char * args)64 aix5_mkvp(char *p, int gfstype, int flags, char *object, char *stub, char *host, char *info, int info_size, char *args)
65 {
66 struct vmount *vp = (struct vmount *) p;
67
68 memset((voidp) vp, 0, sizeof(*vp));
69 /*
70 * Fill in standard fields
71 */
72 vp->vmt_revision = VMT_REVISION;
73 vp->vmt_flags = flags;
74 vp->vmt_gfstype = gfstype;
75
76 /*
77 * Fill in all variable length data
78 */
79 p += sizeof(*vp);
80
81 VMT_ASSIGN(vp, VMT_OBJECT, object, strlen(object) + 1);
82 VMT_ASSIGN(vp, VMT_STUB, stub, strlen(stub) + 1);
83 VMT_ASSIGN(vp, VMT_HOST, host, strlen(host) + 1);
84 VMT_ASSIGN(vp, VMT_HOSTNAME, host, strlen(host) + 1);
85 VMT_ASSIGN(vp, VMT_INFO, info, info_size);
86 VMT_ASSIGN(vp, VMT_ARGS, args, strlen(args) + 1);
87
88 /*
89 * Return length
90 */
91 return vp->vmt_length = p - (char *) vp;
92 }
93
94
95 /*
96 * Map from conventional mount arguments to AIX 3,x style arguments.
97 * But we avoid all the messy BIS stuff for AIX 5.x
98 */
99 int
mount_aix3(char * fsname,char * dir,int flags,int type,void * data,char * mnt_opts)100 mount_aix3(char *fsname, char *dir, int flags, int type, void *data, char *mnt_opts)
101 {
102 char buf[4096];
103 int size, ret;
104 int real_size = sizeof(nfs_args_t); /* size passed to aix5_mkvp() */
105 char *real_args = data; /* args passed to aix5_mkvp() */
106 char *host, *rfs, *idx;
107 int aix_type = type;
108 #ifdef HAVE_FS_NFS3
109 struct nfs_args v2args;
110 nfs_args_t *v3args = (nfs_args_t *) data;
111 #endif /* HAVE_FS_NFS3 */
112
113 #ifdef DEBUG
114 dlog("mount_aix3: fsname %s, dir %s, type %d", fsname, dir, type);
115 #endif /* DEBUG */
116
117 switch (aix_type) {
118
119 case MOUNT_TYPE_NFS:
120
121 #ifdef HAVE_FS_NFS3
122 /*
123 * This is tricky. If we have v3 support, but this nfs mount is v2,
124 * then I must copy the arguments from the v3 nfs_args to the v2 one.
125 */
126 memmove((voidp) &v2args.addr, (voidp) &v3args->addr, sizeof(struct sockaddr_in));
127 v2args.hostname = v3args->hostname;
128 v2args.netname = v3args->netname;
129 memmove((voidp) v2args.fh.x, v3args->fh, FHSIZE);
130 v2args.flags = v3args->flags;
131 v2args.wsize = v3args->wsize;
132 v2args.rsize = v3args->rsize;
133 v2args.timeo = v3args->timeo;
134 v2args.retrans = v3args->retrans;
135 v2args.acregmin = v3args->acregmin;
136 v2args.acregmax = v3args->acregmax;
137 v2args.acdirmin = v3args->acdirmin;
138 v2args.acdirmax = v3args->acdirmax;
139 v2args.pathconf = v3args->pathconf;
140
141 /* now set real_* stuff */
142 real_size = sizeof(v2args);
143 real_args = (char *) &v2args;
144
145 case MOUNT_TYPE_NFS3:
146 #endif /* HAVE_FS_NFS3 */
147
148 idx = strchr(fsname, ':');
149 if (idx) {
150 *idx = '\0';
151 rfs = xstrdup(idx + 1);
152 host = xstrdup(fsname);
153 *idx = ':';
154 } else {
155 rfs = xstrdup(fsname);
156 host = xstrdup(am_get_hostname());
157 }
158
159 size = aix5_mkvp(buf, type, flags, rfs, dir, host,
160 real_args, real_size, mnt_opts);
161 XFREE(rfs);
162 XFREE(host);
163 break;
164
165 case MOUNT_TYPE_UFS:
166 /* Need to open block device and extract log device info from sblk. */
167 return EINVAL;
168
169 default:
170 return EINVAL;
171 }
172
173 /*
174 * XXX: Warning, if vmount() hangs your amd in AIX 5.1, it
175 * is because of a kernel bug in the NFS code. Get a patch from IBM
176 * or upgrade to 5.2.
177 */
178 ret = vmount((struct vmount *)buf, size);
179 if (ret < 0) {
180 plog(XLOG_ERROR, "mount_aix3: vmount failed with errno %d", errno);
181 perror ("vmount");
182 }
183 return ret;
184 }
185