2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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.
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.
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/>.
18 * This is the lowlevel interface to access NFS resources.
19 * Through this interface you have access to the full gamut of nfs and nfs related
20 * protocol as well as the XDR encoded/decoded structures.
30 struct rpc_context
*rpc_init_context(void);
31 void rpc_destroy_context(struct rpc_context
*rpc
);
34 void rpc_set_auth(struct rpc_context
*rpc
, struct AUTH
*auth
);
36 int rpc_get_fd(struct rpc_context
*rpc
);
37 int rpc_which_events(struct rpc_context
*rpc
);
38 int rpc_service(struct rpc_context
*rpc
, int revents
);
39 char *rpc_get_error(struct rpc_context
*rpc
);
42 #define RPC_STATUS_SUCCESS 0
43 #define RPC_STATUS_ERROR 1
44 #define RPC_STATUS_CANCEL 2
46 typedef void (*rpc_cb
)(struct rpc_context
*rpc
, int status
, void *data
, void *private_data
);
49 * Async connection to the tcp port at server:port.
51 * 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
52 * <0 : An error occured when trying to set up the connection. The callback will not be invoked.
54 * When the callback is invoked, status indicates the result:
55 * RPC_STATUS_SUCCESS : The tcp connection was successfully established.
57 * RPC_STATUS_ERROR : The connection failed to establish.
58 * data is the erro string.
59 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
62 int rpc_connect_async(struct rpc_context
*rpc
, const char *server
, int port
, rpc_cb cb
, void *private_data
);
64 * When disconnecting a connection in flight. All commands in flight will be called with the callback
65 * and status RPC_STATUS_ERROR. Data will be the error string for the disconnection.
67 int rpc_disconnect(struct rpc_context
*rpc
, char *error
);
69 void rpc_set_error(struct rpc_context
*rpc
, char *error_string
, ...);
77 * Call PORTMAPPER/NULL
79 * 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
80 * <0 : An error occured when trying to set up the connection. The callback will not be invoked.
82 * When the callback is invoked, status indicates the result:
83 * RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
85 * RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
86 * data is the error string.
87 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
90 int rpc_pmap_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
94 * Call PORTMAPPER/GETPORT.
96 * 0 : The connection was initiated. Once the connection establish finishes, the callback will be invoked.
97 * <0 : An error occured when trying to set up the connection. The callback will not be invoked.
99 * When the callback is invoked, status indicates the result:
100 * RPC_STATUS_SUCCESS : We got a successful response from the portmapper daemon.
101 * data is a (uint32_t *), containing the port returned.
102 * RPC_STATUS_ERROR : An error occured when trying to contact the portmapper.
103 * data is the error string.
104 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
107 int rpc_pmap_getport_async(struct rpc_context
*rpc
, int program
, int version
, rpc_cb cb
, void *private_data
);
114 char *mountstat3_to_str(int stat
);
115 int mountstat3_to_errno(int error
);
120 * 0 : The call was initiated. The callback will be invoked when the call completes.
121 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
123 * When the callback is invoked, status indicates the result:
124 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
126 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
127 * data is the error string.
128 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
131 int rpc_mount_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
136 * 0 : The call was initiated. The callback will be invoked when the call completes.
137 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
139 * When the callback is invoked, status indicates the result:
140 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
141 * data is union mountres3.
142 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
143 * data is the error string.
144 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
147 int rpc_mount_mnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
);
152 * 0 : The call was initiated. The callback will be invoked when the call completes.
153 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
155 * When the callback is invoked, status indicates the result:
156 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
157 * data is a mountlist.
158 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
159 * data is the error string.
160 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
163 int rpc_mount_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
168 * 0 : The call was initiated. The callback will be invoked when the call completes.
169 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
171 * When the callback is invoked, status indicates the result:
172 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
174 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
175 * data is the error string.
176 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
179 int rpc_mount_umnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
);
184 * 0 : The call was initiated. The callback will be invoked when the call completes.
185 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
187 * When the callback is invoked, status indicates the result:
188 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
190 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
191 * data is the error string.
192 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
195 int rpc_mount_umntall_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
200 * 0 : The call was initiated. The callback will be invoked when the call completes.
201 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
203 * When the callback is invoked, status indicates the result:
204 * RPC_STATUS_SUCCESS : We got a successful response from the mount daemon.
205 * data is an exports.
206 * RPC_STATUS_ERROR : An error occured when trying to contact the mount daemon.
207 * data is the error string.
208 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
211 int rpc_mount_export_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
220 char *nfsstat3_to_str(int error
);
221 int nfsstat3_to_errno(int error
);
226 * 0 : The call was initiated. The callback will be invoked when the call completes.
227 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
229 * When the callback is invoked, status indicates the result:
230 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
232 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
233 * data is the error string.
234 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
237 int rpc_nfs_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
242 * 0 : The call was initiated. The callback will be invoked when the call completes.
243 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
245 * When the callback is invoked, status indicates the result:
246 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
247 * data is GETATTR3res
248 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
249 * data is the error string.
250 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
253 int rpc_nfs_getattr_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
);
258 * 0 : The call was initiated. The callback will be invoked when the call completes.
259 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
261 * When the callback is invoked, status indicates the result:
262 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
264 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
265 * data is the error string.
266 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
269 int rpc_nfs_lookup_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *name
, void *private_data
);
274 * 0 : The call was initiated. The callback will be invoked when the call completes.
275 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
277 * When the callback is invoked, status indicates the result:
278 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
280 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
281 * data is the error string.
282 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
285 int rpc_nfs_access_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, int access
, void *private_data
);
290 * 0 : The call was initiated. The callback will be invoked when the call completes.
291 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
293 * When the callback is invoked, status indicates the result:
294 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
296 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
297 * data is the error string.
298 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
301 int rpc_nfs_read_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, off_t offset
, size_t count
, void *private_data
);
306 * 0 : The call was initiated. The callback will be invoked when the call completes.
307 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
309 * When the callback is invoked, status indicates the result:
310 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
311 * data is WRITE3res *
312 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
313 * data is the error string.
314 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
317 int rpc_nfs_write_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *buf
, off_t offset
, size_t count
, int stable_how
, void *private_data
);
322 * 0 : The call was initiated. The callback will be invoked when the call completes.
323 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
325 * When the callback is invoked, status indicates the result:
326 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
327 * data is COMMIT3res *
328 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
329 * data is the error string.
330 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
333 int rpc_nfs_commit_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
);
339 * 0 : The call was initiated. The callback will be invoked when the call completes.
340 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
342 * When the callback is invoked, status indicates the result:
343 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
344 * data is SETATTR3res *
345 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
346 * data is the error string.
347 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
351 int rpc_nfs_setattr_async(struct rpc_context
*rpc
, rpc_cb cb
, struct SETATTR3args
*args
, void *private_data
);
358 * 0 : The call was initiated. The callback will be invoked when the call completes.
359 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
361 * When the callback is invoked, status indicates the result:
362 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
363 * data is MKDIR3res *
364 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
365 * data is the error string.
366 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
369 int rpc_nfs_mkdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
);
378 * 0 : The call was initiated. The callback will be invoked when the call completes.
379 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
381 * When the callback is invoked, status indicates the result:
382 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
383 * data is RMDIR3res *
384 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
385 * data is the error string.
386 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
389 int rpc_nfs_rmdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
);
397 * 0 : The call was initiated. The callback will be invoked when the call completes.
398 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
400 * When the callback is invoked, status indicates the result:
401 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
402 * data is CREATE3res *
403 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
404 * data is the error string.
405 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
408 int rpc_nfs_create_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *name
, int mode
, void *private_data
);
416 * 0 : The call was initiated. The callback will be invoked when the call completes.
417 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
419 * When the callback is invoked, status indicates the result:
420 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
421 * data is REMOVE3res *
422 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
423 * data is the error string.
424 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
427 int rpc_nfs_remove_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *name
, void *private_data
);
434 * 0 : The call was initiated. The callback will be invoked when the call completes.
435 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
437 * When the callback is invoked, status indicates the result:
438 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
439 * data is READDIR3res *
440 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
441 * data is the error string.
442 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
445 int rpc_nfs_readdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, uint64_t cookie
, char *cookieverf
, int count
, void *private_data
);
450 * 0 : The call was initiated. The callback will be invoked when the call completes.
451 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
453 * When the callback is invoked, status indicates the result:
454 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
456 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
457 * data is the error string.
458 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
461 int rpc_nfs_fsstat_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
);
468 * 0 : The call was initiated. The callback will be invoked when the call completes.
469 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
471 * When the callback is invoked, status indicates the result:
472 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
474 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
475 * data is the error string.
476 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
479 int rpc_nfs_fsinfo_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
);
486 * 0 : The call was initiated. The callback will be invoked when the call completes.
487 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
489 * When the callback is invoked, status indicates the result:
490 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
491 * data is READLINK3res *
492 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
493 * data is the error string.
494 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
497 int rpc_nfs_readlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
);
504 * 0 : The call was initiated. The callback will be invoked when the call completes.
505 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
507 * When the callback is invoked, status indicates the result:
508 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
509 * data is SYMLINK3res *
510 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
511 * data is the error string.
512 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
515 int rpc_nfs_symlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *newname
, char *oldpath
, void *private_data
);
521 * 0 : The call was initiated. The callback will be invoked when the call completes.
522 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
524 * When the callback is invoked, status indicates the result:
525 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
526 * data is RENAME3res *
527 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
528 * data is the error string.
529 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
532 int rpc_nfs_rename_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*olddir
, char *oldname
, struct nfs_fh3
*newdir
, char *newname
, void *private_data
);
539 * 0 : The call was initiated. The callback will be invoked when the call completes.
540 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
542 * When the callback is invoked, status indicates the result:
543 * RPC_STATUS_SUCCESS : We got a successful response from the nfs daemon.
545 * RPC_STATUS_ERROR : An error occured when trying to contact the nfs daemon.
546 * data is the error string.
547 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
550 int rpc_nfs_link_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*file
, struct nfs_fh3
*newdir
, char *newname
, void *private_data
);
558 char *rquotastat_to_str(int error
);
559 int rquotastat_to_errno(int error
);
564 * 0 : The call was initiated. The callback will be invoked when the call completes.
565 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
567 * When the callback is invoked, status indicates the result:
568 * RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
570 * RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
571 * data is the error string.
572 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
575 int rpc_rquota1_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
);
578 * Call RQUOTA1/GETQUOTA
580 * 0 : The call was initiated. The callback will be invoked when the call completes.
581 * <0 : An error occured when trying to set up the call. The callback will not be invoked.
583 * When the callback is invoked, status indicates the result:
584 * RPC_STATUS_SUCCESS : We got a successful response from the rquota daemon.
585 * data is a RQUOTA1res structure.
586 * RPC_STATUS_ERROR : An error occured when trying to contact the rquota daemon.
587 * data is the error string.
588 * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
591 int rpc_rquota1_getquota_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, int uid
, void *private_data
);