9de1ea684197998df62885988f516fbd5b62b9e7
2 Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 /* Example program using the lowlevel raw interface.
19 * This allow accurate control of the exact commands that are being used.
22 #define SERVER "10.1.1.27"
23 #define EXPORT "/VIRTUAL"
29 #include "libnfs-raw.h"
30 #include "libnfs-raw-mount.h"
39 void mount_mnt_cb(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
)
41 struct client
*client
= private_data
;
43 if (status
== RPC_STATUS_ERROR
) {
44 printf("mount/mnt call failed with \"%s\"\n", (char *)data
);
47 if (status
!= RPC_STATUS_SUCCESS
) {
48 printf("mount/mnt call to server %s failed, status:%d\n", client
->server
, status
);
52 printf("Got reply from server for MOUNT/MNT procedure.\n");
53 client
->is_finished
= 1;
57 void mount_null_cb(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
)
59 struct client
*client
= private_data
;
61 if (status
== RPC_STATUS_ERROR
) {
62 printf("mount null call failed with \"%s\"\n", (char *)data
);
65 if (status
!= RPC_STATUS_SUCCESS
) {
66 printf("mount null call to server %s failed, status:%d\n", client
->server
, status
);
70 printf("Got reply from server for MOUNT/NULL procedure.\n");
71 printf("Send MOUNT/MNT command for %s\n", client
->export
);
72 if (rpc_mount_mnt_async(rpc
, mount_mnt_cb
, client
->export
, client
) != 0) {
73 printf("Failed to send mnt request\n");
79 void mount_connect_cb(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
)
81 struct client
*client
= private_data
;
83 if (status
!= RPC_STATUS_SUCCESS
) {
84 printf("connection to RPC.MOUNTD on server %s failed\n", client
->server
);
88 printf("Connected to RPC.MOUNTD on %s:%d\n", client
->server
, client
->mount_port
);
89 printf("Send NULL request to check if RPC.MOUNTD is actually running\n");
90 if (rpc_mount_null_async(rpc
, mount_null_cb
, client
) != 0) {
91 printf("Failed to send null request\n");
97 void pmap_getport_cb(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
)
99 struct client
*client
= private_data
;
102 if (status
== RPC_STATUS_ERROR
) {
103 printf("portmapper getport call failed with \"%s\"\n", (char *)data
);
106 if (status
!= RPC_STATUS_SUCCESS
) {
107 printf("portmapper getport call to server %s failed, status:%d\n", client
->server
, status
);
111 client
->mount_port
= *(uint32_t *)data
;
112 printf("GETPORT returned Port:%d\n", client
->mount_port
);
113 if (client
->mount_port
== 0) {
114 printf("RPC.MOUNTD is not available on server : %s\n", client
->server
, client
->mount_port
);
118 printf("Disconnect socket from portmap server\n");
119 if (rpc_disconnect(rpc
, "normal disconnect") != 0) {
120 printf("Failed to disconnect socket to portmapper\n");
124 printf("Connect to RPC.MOUNTD on %s:%d\n", client
->server
, client
->mount_port
);
125 if (rpc_connect_async(rpc
, client
->server
, client
->mount_port
, mount_connect_cb
, client
) != 0) {
126 printf("Failed to start connection\n");
132 void pmap_null_cb(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
)
134 struct client
*client
= private_data
;
136 if (status
== RPC_STATUS_ERROR
) {
137 printf("portmapper null call failed with \"%s\"\n", (char *)data
);
140 if (status
!= RPC_STATUS_SUCCESS
) {
141 printf("portmapper null call to server %s failed, status:%d\n", client
->server
, status
);
145 printf("Got reply from server for PORTMAP/NULL procedure.\n");
146 printf("Send getport request asking for MOUNT port\n");
147 if (rpc_pmap_getport_async(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, pmap_getport_cb
, client
) != 0) {
148 printf("Failed to send getport request\n");
153 void pmap_connect_cb(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
)
155 struct client
*client
= private_data
;
157 printf("pmap_connect_cb status:%d.\n", status
);
158 if (status
!= RPC_STATUS_SUCCESS
) {
159 printf("connection to portmapper on server %s failed\n", client
->server
);
163 printf("Send NULL request to check if portmapper is actually running\n");
164 if (rpc_pmap_null_async(rpc
, pmap_null_cb
, client
) != 0) {
165 printf("Failed to send null request\n");
171 int main(int argc
, char *argv
[])
173 struct rpc_context
*rpc
;
176 struct client client
;
178 rpc
= rpc_init_context();
180 printf("failed to init context\n");
184 client
.server
= SERVER
;
185 client
.export
= EXPORT
;
186 client
.is_finished
= 0;
187 if (rpc_connect_async(rpc
, client
.server
, 111, pmap_connect_cb
, &client
) != 0) {
188 printf("Failed to start connection\n");
193 pfd
.fd
= rpc_get_fd(rpc
);
194 pfd
.events
= rpc_which_events(rpc
);
196 if (poll(&pfd
, 1, -1) < 0) {
197 printf("Poll failed");
200 if (rpc_service(rpc
, pfd
.revents
) < 0) {
201 printf("rpc_service failed\n");
204 if (client
.is_finished
) {
209 rpc_destroy_context(rpc
);
211 printf("nfsclient finished\n");