PORTMAPPER: Add set/unset functions
[deb_libnfs.git] / mount / mount.c
1 /*
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef WIN32
19 #include "win32_compat.h"
20 #endif/*WIN32*/
21
22 #include <stdio.h>
23 #include <errno.h>
24 #include <rpc/rpc.h>
25 #include <rpc/xdr.h>
26 #include "libnfs.h"
27 #include "libnfs-raw.h"
28 #include "libnfs-private.h"
29 #include "libnfs-raw-mount.h"
30
31 int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
32 {
33 struct rpc_pdu *pdu;
34
35 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
36 if (pdu == NULL) {
37 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call");
38 return -1;
39 }
40
41 if (rpc_queue_pdu(rpc, pdu) != 0) {
42 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
43 rpc_free_pdu(rpc, pdu);
44 return -1;
45 }
46
47 return 0;
48 }
49
50 int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
51 {
52 struct rpc_pdu *pdu;
53
54 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (xdrproc_t)xdr_mountres3, sizeof(mountres3));
55 if (pdu == NULL) {
56 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/mnt call");
57 return -1;
58 }
59
60 if (xdr_dirpath(&pdu->xdr, &export) == 0) {
61 rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call");
62 rpc_free_pdu(rpc, pdu);
63 return -1;
64 }
65
66 if (rpc_queue_pdu(rpc, pdu) != 0) {
67 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call");
68 rpc_free_pdu(rpc, pdu);
69 return -1;
70 }
71
72 return 0;
73 }
74
75 int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
76 {
77 struct rpc_pdu *pdu;
78
79 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist));
80 if (pdu == NULL) {
81 rpc_set_error(rpc, "Failed to allocate pdu for mount/dump");
82 return -1;
83 }
84
85 if (rpc_queue_pdu(rpc, pdu) != 0) {
86 rpc_set_error(rpc, "Failed to queue mount/dump pdu");
87 rpc_free_pdu(rpc, pdu);
88 return -1;
89 }
90
91 return 0;
92 }
93
94 int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
95 {
96 struct rpc_pdu *pdu;
97
98 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0);
99 if (pdu == NULL) {
100 rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt");
101 return -1;
102 }
103
104 if (xdr_dirpath(&pdu->xdr, &export) == 0) {
105 rpc_set_error(rpc, "failed to encode dirpath for mount/umnt");
106 rpc_free_pdu(rpc, pdu);
107 return -1;
108 }
109
110 if (rpc_queue_pdu(rpc, pdu) != 0) {
111 rpc_set_error(rpc, "Failed to queue mount/umnt pdu");
112 rpc_free_pdu(rpc, pdu);
113 return -1;
114 }
115
116 return 0;
117 }
118
119 int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
120 {
121 struct rpc_pdu *pdu;
122
123 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0);
124 if (pdu == NULL) {
125 rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall");
126 return -1;
127 }
128
129 if (rpc_queue_pdu(rpc, pdu) != 0) {
130 rpc_set_error(rpc, "Failed to queue mount/umntall pdu");
131 rpc_free_pdu(rpc, pdu);
132 return -1;
133 }
134
135 return 0;
136 }
137
138 int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
139 {
140 struct rpc_pdu *pdu;
141
142 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports));
143 if (pdu == NULL) {
144 rpc_set_error(rpc, "Failed to allocate pdu for mount/export");
145 return -1;
146 }
147
148 if (rpc_queue_pdu(rpc, pdu) != 0) {
149 rpc_set_error(rpc, "Failed to queue mount/export pdu");
150 rpc_free_pdu(rpc, pdu);
151 return -1;
152 }
153
154 return 0;
155 }
156
157 char *mountstat3_to_str(int st)
158 {
159 enum mountstat3 stat = st;
160
161 char *str = "unknown mount stat";
162 switch (stat) {
163 case MNT3_OK: str="MNT3_OK"; break;
164 case MNT3ERR_PERM: str="MNT3ERR_PERM"; break;
165 case MNT3ERR_NOENT: str="MNT3ERR_NOENT"; break;
166 case MNT3ERR_IO: str="MNT3ERR_IO"; break;
167 case MNT3ERR_ACCES: str="MNT3ERR_ACCES"; break;
168 case MNT3ERR_NOTDIR: str="MNT3ERR_NOTDIR"; break;
169 case MNT3ERR_INVAL: str="MNT3ERR_INVAL"; break;
170 case MNT3ERR_NAMETOOLONG: str="MNT3ERR_NAMETOOLONG"; break;
171 case MNT3ERR_NOTSUPP: str="MNT3ERR_NOTSUPP"; break;
172 case MNT3ERR_SERVERFAULT: str="MNT3ERR_SERVERFAULT"; break;
173 }
174 return str;
175 }
176
177
178 int mountstat3_to_errno(int st)
179 {
180 enum mountstat3 stat = st;
181
182 switch (stat) {
183 case MNT3_OK: return 0; break;
184 case MNT3ERR_PERM: return -EPERM; break;
185 case MNT3ERR_NOENT: return -EPERM; break;
186 case MNT3ERR_IO: return -EIO; break;
187 case MNT3ERR_ACCES: return -EACCES; break;
188 case MNT3ERR_NOTDIR: return -ENOTDIR; break;
189 case MNT3ERR_INVAL: return -EINVAL; break;
190 case MNT3ERR_NAMETOOLONG: return -E2BIG; break;
191 case MNT3ERR_NOTSUPP: return -EINVAL; break;
192 case MNT3ERR_SERVERFAULT: return -EIO; break;
193 }
194 return -ERANGE;
195 }
196
197
198