Commit | Line | Data |
---|---|---|
84004dbf RS |
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 | #include <stdio.h> | |
19 | #include <errno.h> | |
20 | #include <rpc/xdr.h> | |
21 | #include "libnfs.h" | |
22 | #include "libnfs-raw.h" | |
23 | #include "libnfs-private.h" | |
24 | #include "libnfs-raw-mount.h" | |
25 | ||
26 | ||
27 | int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
28 | { | |
29 | struct rpc_pdu *pdu; | |
30 | ||
31 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
32 | if (pdu == NULL) { | |
33 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call"); | |
34 | return -1; | |
35 | } | |
36 | ||
37 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
38 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call"); | |
39 | rpc_free_pdu(rpc, pdu); | |
40 | return -2; | |
41 | } | |
42 | ||
43 | return 0; | |
44 | } | |
45 | ||
46 | int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data) | |
47 | { | |
48 | struct rpc_pdu *pdu; | |
49 | ||
50 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (xdrproc_t)xdr_mountres3, sizeof(mountres3)); | |
51 | if (pdu == NULL) { | |
52 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/mnt call"); | |
53 | return -1; | |
54 | } | |
55 | ||
56 | if (xdr_dirpath(&pdu->xdr, &export) == 0) { | |
57 | rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call"); | |
58 | rpc_free_pdu(rpc, pdu); | |
59 | return -2; | |
60 | } | |
61 | ||
62 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
63 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call"); | |
64 | rpc_free_pdu(rpc, pdu); | |
65 | return -2; | |
66 | } | |
67 | ||
68 | return 0; | |
69 | } | |
70 | ||
71 | int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
72 | { | |
73 | struct rpc_pdu *pdu; | |
74 | ||
75 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist)); | |
76 | if (pdu == NULL) { | |
77 | printf("Failed to allocate pdu for mount/dump\n"); | |
78 | return -1; | |
79 | } | |
80 | ||
81 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
82 | printf("Failed to queue mount/dump pdu\n"); | |
83 | rpc_free_pdu(rpc, pdu); | |
84 | return -2; | |
85 | } | |
86 | ||
87 | return 0; | |
88 | } | |
89 | ||
90 | int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data) | |
91 | { | |
92 | struct rpc_pdu *pdu; | |
93 | ||
94 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0); | |
95 | if (pdu == NULL) { | |
96 | printf("Failed to allocate pdu for mount/umnt\n"); | |
97 | return -1; | |
98 | } | |
99 | ||
100 | if (xdr_dirpath(&pdu->xdr, &export) == 0) { | |
101 | printf("failed to encode dirpath for mount/umnt\n"); | |
102 | rpc_free_pdu(rpc, pdu); | |
103 | return -2; | |
104 | } | |
105 | ||
106 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
107 | printf("Failed to queue mount/umnt pdu\n"); | |
108 | rpc_free_pdu(rpc, pdu); | |
109 | return -2; | |
110 | } | |
111 | ||
112 | return 0; | |
113 | } | |
114 | ||
115 | int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
116 | { | |
117 | struct rpc_pdu *pdu; | |
118 | ||
119 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
120 | if (pdu == NULL) { | |
121 | printf("Failed to allocate pdu for mount/umntall\n"); | |
122 | return -1; | |
123 | } | |
124 | ||
125 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
126 | printf("Failed to queue mount/umntall pdu\n"); | |
127 | rpc_free_pdu(rpc, pdu); | |
128 | return -2; | |
129 | } | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
135 | { | |
136 | struct rpc_pdu *pdu; | |
137 | ||
138 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports)); | |
139 | if (pdu == NULL) { | |
140 | printf("Failed to allocate pdu for mount/export\n"); | |
141 | return -1; | |
142 | } | |
143 | ||
144 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
145 | printf("Failed to queue mount/export pdu\n"); | |
146 | rpc_free_pdu(rpc, pdu); | |
147 | return -2; | |
148 | } | |
149 | ||
150 | return 0; | |
151 | } | |
152 | ||
153 | char *mountstat3_to_str(int st) | |
154 | { | |
155 | enum mountstat3 stat = st; | |
156 | ||
157 | char *str = "unknown mount stat"; | |
158 | switch (stat) { | |
159 | case MNT3_OK: str="MNT3_OK"; break; | |
160 | case MNT3ERR_PERM: str="MNT3ERR_PERM"; break; | |
161 | case MNT3ERR_NOENT: str="MNT3ERR_NOENT"; break; | |
162 | case MNT3ERR_IO: str="MNT3ERR_IO"; break; | |
163 | case MNT3ERR_ACCES: str="MNT3ERR_ACCES"; break; | |
164 | case MNT3ERR_NOTDIR: str="MNT3ERR_NOTDIR"; break; | |
165 | case MNT3ERR_INVAL: str="MNT3ERR_INVAL"; break; | |
166 | case MNT3ERR_NAMETOOLONG: str="MNT3ERR_NAMETOOLONG"; break; | |
167 | case MNT3ERR_NOTSUPP: str="MNT3ERR_NOTSUPP"; break; | |
168 | case MNT3ERR_SERVERFAULT: str="MNT3ERR_SERVERFAULT"; break; | |
169 | } | |
170 | return str; | |
171 | } | |
172 | ||
173 | ||
174 | int mountstat3_to_errno(int st) | |
175 | { | |
176 | enum mountstat3 stat = st; | |
177 | ||
178 | switch (stat) { | |
179 | case MNT3_OK: return 0; break; | |
180 | case MNT3ERR_PERM: return -EPERM; break; | |
181 | case MNT3ERR_NOENT: return -EPERM; break; | |
182 | case MNT3ERR_IO: return -EIO; break; | |
183 | case MNT3ERR_ACCES: return -EACCES; break; | |
184 | case MNT3ERR_NOTDIR: return -ENOTDIR; break; | |
185 | case MNT3ERR_INVAL: return -EINVAL; break; | |
186 | case MNT3ERR_NAMETOOLONG: return -E2BIG; break; | |
187 | case MNT3ERR_NOTSUPP: return -EINVAL; break; | |
188 | case MNT3ERR_SERVERFAULT: return -EIO; break; | |
189 | } | |
190 | return -ERANGE; | |
191 | } |