nfs_pread_async: plug potential memleaks
[deb_libnfs.git] / include / nfsc / libnfs.h
CommitLineData
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 * This is the highlevel interface to access NFS resources using a posix-like interface
19 */
52014ebf
AR
20
21#ifndef _LIBNFS_H_
22#define _LIBNFS_H_
23
84004dbf 24#include <stdint.h>
252aa90d
CF
25#if defined(ANDROID)
26#include <sys/time.h>
27#endif
d7c6e9aa
RS
28#if defined(AROS)
29#include <sys/time.h>
30#endif
84004dbf 31
d48be00c
AR
32#ifdef __cplusplus
33extern "C" {
34#endif
35
84004dbf 36struct nfs_context;
7f0242ca 37struct rpc_context;
84004dbf 38
d2ec73c7
PL
39struct nfs_url {
40 char *server;
41 char *path;
42 char *file;
43};
44
66ad6d84
RS
45#if defined(WIN32)
46#define EXTERN __declspec( dllexport )
47#else
52014ebf 48#define EXTERN
66ad6d84
RS
49#endif
50
eecdc4f3
RS
51#if defined(WIN32)
52struct statvfs {
53 uint32_t f_bsize;
54 uint32_t f_frsize;
55 uint64_t f_blocks;
56 uint64_t f_bfree;
57 uint64_t f_bavail;
58 uint32_t f_files;
59 uint32_t f_ffree;
60 uint32_t f_favail;
52014ebf 61 uint32_t f_fsid;
eecdc4f3
RS
62 uint32_t f_flag;
63 uint32_t f_namemax;
64};
65struct utimbuf {
66 time_t actime;
67 time_t modtime;
68};
69#define R_OK 4
70#define W_OK 2
71#define X_OK 1
72#endif
73
84004dbf
RS
74/*
75 * Used for interfacing the async version of the api into an external eventsystem
76 */
66ad6d84
RS
77EXTERN int nfs_get_fd(struct nfs_context *nfs);
78EXTERN int nfs_which_events(struct nfs_context *nfs);
79EXTERN int nfs_service(struct nfs_context *nfs, int revents);
83aa785d 80EXTERN int nfs_queue_length(struct nfs_context *nfs);
84004dbf
RS
81
82/*
83 * Used if you need different credentials than the default for the current user.
84 */
67ba2239
RS
85struct AUTH;
86EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
84004dbf 87
84004dbf
RS
88/*
89 * When an operation failed, this function can extract a detailed error string.
90 */
66ad6d84 91EXTERN char *nfs_get_error(struct nfs_context *nfs);
84004dbf
RS
92
93
94/*
95 * Callback for all ASYNC nfs functions
96 */
97typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
98
7f0242ca
RS
99/*
100 * Callback for all ASYNC rpc functions
101 */
102typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
84004dbf
RS
103
104
105
106/*
107 * NFS CONTEXT.
108 */
109/*
110 * Create an NFS c, the context.
111 * Function returns
112 * NULL : Failed to create a context.
113 * *nfs : A pointer to an nfs context.
114 */
66ad6d84 115EXTERN struct nfs_context *nfs_init_context(void);
84004dbf
RS
116/*
117 * Destroy an nfs context.
118 */
66ad6d84 119EXTERN void nfs_destroy_context(struct nfs_context *nfs);
84004dbf
RS
120
121
0961765a
RS
122/*
123 * URL parsing functions.
52014ebf 124 * These functions all parse a URL of the form
0961765a
RS
125 * nfs://server/path/file?argv=val[&arg=val]*
126 * and returns a nfs_url.
127 *
128 * Apart from parsing the URL the functions will also update
129 * the nfs context to reflect settings controlled via url arguments.
130 *
131 * Current URL arguments are :
132 * tcp-syncnt=<int> : Number of SYNs to send during the seccion establish
133 * before failing settin up the tcp connection to the
134 * server.
135 * uid=<int> : UID value to use when talking to the server.
136 * default it 65534 on Windows and getuid() on unixen.
137 * gid=<int> : GID value to use when talking to the server.
138 * default it 65534 on Windows and getgid() on unixen.
139 */
d2ec73c7
PL
140/*
141 * Parse a complete NFS URL including, server, path and
142 * filename. Fail if any component is missing.
143 */
144EXTERN struct nfs_url *nfs_parse_url_full(struct nfs_context *nfs, const char *url);
145
146/*
147 * Parse an NFS URL, but do not split path and file. File
148 * in the resulting struct remains NULL.
149 */
150EXTERN struct nfs_url *nfs_parse_url_dir(struct nfs_context *nfs, const char *url);
151
152/*
153 * Parse an NFS URL, but do not fail if file, path or even server is missing.
154 * Check elements of the resulting struct for NULL.
155 */
156EXTERN struct nfs_url *nfs_parse_url_incomplete(struct nfs_context *nfs, const char *url);
157
158
159/*
160 * Free the URL struct returned by the nfs_parse_url_* functions.
161 */
162EXTERN void nfs_destroy_url(struct nfs_url *url);
163
164
84004dbf
RS
165struct nfsfh;
166
17ef62fa
RS
167/*
168 * Get the maximum supported READ3 size by the server
169 */
183451cf 170EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
17ef62fa
RS
171
172/*
173 * Get the maximum supported WRITE3 size by the server
174 */
183451cf 175EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
17ef62fa 176
d43a8953 177/*
52014ebf 178 * MODIFY CONNECT PARAMTERS
d43a8953
PL
179 */
180
181EXTERN void nfs_set_tcp_syncnt(struct nfs_context *nfs, int v);
182EXTERN void nfs_set_uid(struct nfs_context *nfs, int uid);
183EXTERN void nfs_set_gid(struct nfs_context *nfs, int gid);
84004dbf
RS
184
185/*
186 * MOUNT THE EXPORT
187 */
188/*
189 * Async nfs mount.
190 * Function returns
191 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
192 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
193 *
194 * When the callback is invoked, status indicates the result:
195 * 0 : Success.
196 * data is NULL
197 * -errno : An error occured.
198 * data is the error string.
199 */
66ad6d84 200EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data);
84004dbf
RS
201/*
202 * Sync nfs mount.
203 * Function returns
204 * 0 : The operation was successfull.
205 * -errno : The command failed.
206 */
66ad6d84 207EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname);
84004dbf
RS
208
209
210
211
212/*
213 * STAT()
214 */
215/*
216 * Async stat(<filename>)
217 * Function returns
218 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
219 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
220 *
221 * When the callback is invoked, status indicates the result:
222 * 0 : Success.
223 * data is struct stat *
224 * -errno : An error occured.
225 * data is the error string.
226 */
227struct stat;
66ad6d84 228EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
229/*
230 * Sync stat(<filename>)
231 * Function returns
232 * 0 : The operation was successfull.
233 * -errno : The command failed.
234 */
be184101
M
235#ifdef WIN32
236EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
237#else
66ad6d84 238EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
be184101 239#endif
84004dbf
RS
240
241/*
242 * FSTAT()
243 */
244/*
245 * Async fstat(nfsfh *)
246 * Function returns
247 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
248 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
249 *
250 * When the callback is invoked, status indicates the result:
251 * 0 : Success.
252 * data is struct stat *
253 * -errno : An error occured.
254 * data is the error string.
255 */
66ad6d84 256EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
257/*
258 * Sync fstat(nfsfh *)
259 * Function returns
260 * 0 : The operation was successfull.
261 * -errno : The command failed.
262 */
be184101
M
263#ifdef WIN32
264EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
265#else
66ad6d84 266EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
be184101 267#endif
84004dbf
RS
268
269
270
271/*
272 * OPEN()
273 */
274/*
275 * Async open(<filename>)
276 *
277 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
278 *
279 * Function returns
280 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
281 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
282 *
3cea44dc
RS
283 * Supported flags are
284 * O_RDONLY
285 * O_WRONLY
286 * O_RDWR
22a0f15b 287 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
3cea44dc 288 *
84004dbf
RS
289 * When the callback is invoked, status indicates the result:
290 * 0 : Success.
291 * data is a struct *nfsfh;
292 * The nfsfh is close using nfs_close().
293 * -errno : An error occured.
294 * data is the error string.
295 */
3cea44dc 296EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
84004dbf 297/*
f893b680 298 * Sync open(<filename>)
84004dbf
RS
299 * Function returns
300 * 0 : The operation was successfull. *nfsfh is filled in.
301 * -errno : The command failed.
302 */
3cea44dc 303EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
84004dbf
RS
304
305
306
307
308/*
309 * CLOSE
310 */
311/*
312 * Async close(nfsfh)
313 *
314 * Function returns
315 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
316 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
317 *
318 * When the callback is invoked, status indicates the result:
319 * 0 : Success.
320 * data is NULL.
321 * -errno : An error occured.
322 * data is the error string.
323 */
66ad6d84 324EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
325/*
326 * Sync close(nfsfh)
327 * Function returns
328 * 0 : The operation was successfull.
329 * -errno : The command failed.
330 */
66ad6d84 331EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
84004dbf
RS
332
333
334/*
335 * PREAD()
336 */
337/*
338 * Async pread()
339 *
340 * Function returns
341 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
342 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
343 *
344 * When the callback is invoked, status indicates the result:
345 * >=0 : Success.
346 * status is numer of bytes read.
347 * data is a pointer to the returned data.
348 * -errno : An error occured.
349 * data is the error string.
350 */
183451cf 351EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, nfs_cb cb, void *private_data);
84004dbf
RS
352/*
353 * Sync pread()
354 * Function returns
355 * >=0 : numer of bytes read.
356 * -errno : An error occured.
357 */
183451cf 358EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
84004dbf
RS
359
360
361
362/*
363 * READ()
364 */
365/*
366 * Async read()
367 *
368 * Function returns
369 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
370 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
371 *
372 * When the callback is invoked, status indicates the result:
373 * >=0 : Success.
374 * status is numer of bytes read.
375 * data is a pointer to the returned data.
376 * -errno : An error occured.
377 * data is the error string.
378 */
183451cf 379EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
84004dbf
RS
380/*
381 * Sync read()
382 * Function returns
383 * >=0 : numer of bytes read.
384 * -errno : An error occured.
385 */
183451cf 386EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
84004dbf
RS
387
388
389
390
391/*
392 * PWRITE()
393 */
394/*
395 * Async pwrite()
396 *
397 * Function returns
398 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
399 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
400 *
401 * When the callback is invoked, status indicates the result:
402 * >=0 : Success.
403 * status is numer of bytes written.
404 * -errno : An error occured.
405 * data is the error string.
406 */
183451cf 407EXTERN int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf, nfs_cb cb, void *private_data);
84004dbf
RS
408/*
409 * Sync pwrite()
410 * Function returns
411 * >=0 : numer of bytes written.
412 * -errno : An error occured.
413 */
183451cf 414EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
84004dbf
RS
415
416
417/*
418 * WRITE()
419 */
420/*
421 * Async write()
422 *
423 * Function returns
424 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
425 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
426 *
427 * When the callback is invoked, status indicates the result:
428 * >=0 : Success.
429 * status is numer of bytes written.
430 * -errno : An error occured.
431 * data is the error string.
432 */
183451cf 433EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
84004dbf
RS
434/*
435 * Sync write()
436 * Function returns
437 * >=0 : numer of bytes written.
438 * -errno : An error occured.
439 */
183451cf 440EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
84004dbf
RS
441
442
443/*
444 * LSEEK()
445 */
446/*
447 * Async lseek()
448 *
449 * Function returns
450 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
451 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
452 *
453 * When the callback is invoked, status indicates the result:
454 * >=0 : Success.
183451cf 455 * data is uint64_t * for the current position.
84004dbf
RS
456 * -errno : An error occured.
457 * data is the error string.
458 */
183451cf 459EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, nfs_cb cb, void *private_data);
84004dbf
RS
460/*
461 * Sync lseek()
462 * Function returns
463 * >=0 : numer of bytes read.
464 * -errno : An error occured.
465 */
183451cf 466EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, uint64_t *current_offset);
84004dbf
RS
467
468
469/*
470 * FSYNC()
471 */
472/*
473 * Async fsync()
474 *
475 * Function returns
476 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
477 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
478 *
479 * When the callback is invoked, status indicates the result:
480 * 0 : Success.
481 * -errno : An error occured.
482 * data is the error string.
483 */
66ad6d84 484EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
485/*
486 * Sync fsync()
487 * Function returns
488 * 0 : Success
489 * -errno : An error occured.
490 */
66ad6d84 491EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
84004dbf
RS
492
493
494
495/*
496 * TRUNCATE()
497 */
498/*
499 * Async truncate()
500 *
501 * Function returns
502 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
503 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
504 *
505 * When the callback is invoked, status indicates the result:
506 * 0 : Success.
507 * -errno : An error occured.
508 * data is the error string.
509 */
183451cf 510EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
84004dbf
RS
511/*
512 * Sync truncate()
513 * Function returns
514 * 0 : Success
515 * -errno : An error occured.
516 */
183451cf 517EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
84004dbf
RS
518
519
520
521/*
522 * FTRUNCATE()
523 */
524/*
525 * Async ftruncate()
526 *
527 * Function returns
528 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
529 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
530 *
531 * When the callback is invoked, status indicates the result:
532 * 0 : Success.
533 * -errno : An error occured.
534 * data is the error string.
535 */
183451cf 536EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
84004dbf
RS
537/*
538 * Sync ftruncate()
539 * Function returns
540 * 0 : Success
541 * -errno : An error occured.
542 */
183451cf 543EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
84004dbf
RS
544
545
546
547
548
549
550/*
551 * MKDIR()
552 */
553/*
554 * Async mkdir()
555 *
556 * Function returns
557 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
558 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
559 *
560 * When the callback is invoked, status indicates the result:
561 * 0 : Success.
562 * -errno : An error occured.
563 * data is the error string.
564 */
66ad6d84 565EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
566/*
567 * Sync mkdir()
568 * Function returns
569 * 0 : Success
570 * -errno : An error occured.
571 */
66ad6d84 572EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
84004dbf
RS
573
574
575
576/*
577 * RMDIR()
578 */
579/*
580 * Async rmdir()
581 *
582 * Function returns
583 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
584 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
585 *
586 * When the callback is invoked, status indicates the result:
587 * 0 : Success.
588 * -errno : An error occured.
589 * data is the error string.
590 */
66ad6d84 591EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
592/*
593 * Sync rmdir()
594 * Function returns
595 * 0 : Success
596 * -errno : An error occured.
597 */
66ad6d84 598EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
84004dbf
RS
599
600
601
602
603/*
604 * CREAT()
605 */
606/*
607 * Async creat()
608 *
609 * Function returns
610 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
611 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
612 *
613 * When the callback is invoked, status indicates the result:
614 * 0 : Success.
615 * data is a struct *nfsfh;
616 * -errno : An error occured.
617 * data is the error string.
618 */
66ad6d84 619EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
620/*
621 * Sync creat()
622 * Function returns
623 * 0 : Success
624 * -errno : An error occured.
625 */
66ad6d84 626EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
84004dbf
RS
627
628
1ec6b50a
RS
629/*
630 * MKNOD()
631 */
632/*
633 * Async mknod()
634 *
635 * Function returns
636 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
637 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
638 *
639 * When the callback is invoked, status indicates the result:
640 * 0 : Success.
641 * -errno : An error occured.
642 * data is the error string.
643 */
644EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
645/*
646 * Sync mknod()
647 * Function returns
648 * 0 : Success
649 * -errno : An error occured.
650 */
651EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
84004dbf
RS
652
653
654
655/*
656 * UNLINK()
657 */
658/*
659 * Async unlink()
660 *
661 * Function returns
662 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
663 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
664 *
665 * When the callback is invoked, status indicates the result:
666 * 0 : Success.
667 * data is NULL
668 * -errno : An error occured.
669 * data is the error string.
670 */
66ad6d84 671EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
672/*
673 * Sync unlink()
674 * Function returns
675 * 0 : Success
676 * -errno : An error occured.
677 */
66ad6d84 678EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
84004dbf
RS
679
680
681
682
683/*
684 * OPENDIR()
685 */
686struct nfsdir;
687/*
688 * Async opendir()
689 *
690 * Function returns
691 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
692 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
693 *
694 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
695 *
696 * When the callback is invoked, status indicates the result:
697 * 0 : Success.
698 * data is struct nfsdir *
699 * -errno : An error occured.
700 * data is the error string.
701 */
66ad6d84 702EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
703/*
704 * Sync opendir()
705 * Function returns
706 * 0 : Success
707 * -errno : An error occured.
708 */
66ad6d84 709EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
84004dbf
RS
710
711
712
713/*
714 * READDIR()
715 */
716struct nfsdirent {
717 struct nfsdirent *next;
718 char *name;
719 uint64_t inode;
0804e67d 720
7bda8bad
RS
721 /* Some extra fields we get for free through the READDIRPLUS3 call.
722 You need libnfs-raw-nfs.h for type/mode constants */
0804e67d
RS
723 uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
724 uint32_t mode;
725 uint64_t size;
726 struct timeval atime;
727 struct timeval mtime;
728 struct timeval ctime;
7bda8bad
RS
729 uint32_t uid;
730 uint32_t gid;
84004dbf
RS
731};
732/*
733 * nfs_readdir() never blocks, so no special sync/async versions are available
734 */
66ad6d84 735EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
84004dbf
RS
736
737
738
739/*
f893b680 740 * CLOSEDIR()
84004dbf
RS
741 */
742/*
743 * nfs_closedir() never blocks, so no special sync/async versions are available
744 */
66ad6d84 745EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
84004dbf
RS
746
747
f893b680
RS
748/*
749 * CHDIR()
750 */
751/*
752 * Async chdir(<path>)
753 *
754 * Function returns
755 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
756 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
757 *
758 * When the callback is invoked, status indicates the result:
759 * 0 : Success.
760 * data is NULL;
761 * -errno : An error occured.
762 * data is the error string.
763 */
764EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
765/*
766 * Sync chdir(<path>)
767 * Function returns
768 * 0 : The operation was successfull.
769 * -errno : The command failed.
770 */
771EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
772
773/*
774 * GETCWD()
775 */
776/*
777 * nfs_getcwd() never blocks, so no special sync/async versions are available
778 */
779/*
780 * Sync getcwd()
781 * This function returns a pointer to the current working directory.
782 * This pointer is only stable until the next [f]chdir or when the
783 * context is destroyed.
784 *
785 * Function returns
786 * 0 : The operation was successfull and *cwd is filled in.
787 * -errno : The command failed.
788 */
789EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
790
84004dbf
RS
791
792/*
793 * STATVFS()
794 */
795/*
796 * Async statvfs(<dirname>)
797 * Function returns
798 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
799 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
800 *
801 * When the callback is invoked, status indicates the result:
802 * 0 : Success.
803 * data is struct statvfs *
804 * -errno : An error occured.
805 * data is the error string.
806 */
807struct statvfs;
66ad6d84 808EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
809/*
810 * Sync statvfs(<dirname>)
811 * Function returns
812 * 0 : The operation was successfull.
813 * -errno : The command failed.
814 */
66ad6d84 815EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
84004dbf
RS
816
817
818/*
819 * READLINK()
820 */
821/*
822 * Async readlink(<name>)
823 * Function returns
824 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
825 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
826 *
827 * When the callback is invoked, status indicates the result:
828 * 0 : Success.
829 * data is a char *
830 * data is only valid during the callback and is automatically freed when the callback returns.
831 * -errno : An error occured.
832 * data is the error string.
833 */
834struct statvfs;
66ad6d84 835EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
836/*
837 * Sync readlink(<name>)
838 * Function returns
839 * 0 : The operation was successfull.
840 * -errno : The command failed.
841 */
66ad6d84 842EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
84004dbf
RS
843
844
845
846/*
847 * CHMOD()
848 */
849/*
850 * Async chmod(<name>)
851 * Function returns
852 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
853 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
854 *
855 * When the callback is invoked, status indicates the result:
856 * 0 : Success.
857 * data is NULL
858 * -errno : An error occured.
859 * data is the error string.
860 */
66ad6d84 861EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
862/*
863 * Sync chmod(<name>)
864 * Function returns
865 * 0 : The operation was successfull.
866 * -errno : The command failed.
867 */
66ad6d84 868EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
84004dbf
RS
869
870
871
872/*
873 * FCHMOD()
874 */
875/*
876 * Async fchmod(<handle>)
877 * Function returns
878 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
879 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
880 *
881 * When the callback is invoked, status indicates the result:
882 * 0 : Success.
883 * data is NULL
884 * -errno : An error occured.
885 * data is the error string.
886 */
66ad6d84 887EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
888/*
889 * Sync fchmod(<handle>)
890 * Function returns
891 * 0 : The operation was successfull.
892 * -errno : The command failed.
893 */
66ad6d84 894EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
84004dbf
RS
895
896
897
898/*
899 * CHOWN()
900 */
901/*
902 * Async chown(<name>)
903 * Function returns
904 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
905 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
906 *
907 * When the callback is invoked, status indicates the result:
908 * 0 : Success.
909 * data is NULL
910 * -errno : An error occured.
911 * data is the error string.
912 */
66ad6d84 913EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
84004dbf
RS
914/*
915 * Sync chown(<name>)
916 * Function returns
917 * 0 : The operation was successfull.
918 * -errno : The command failed.
919 */
66ad6d84 920EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
84004dbf
RS
921
922
923
924/*
925 * FCHOWN()
926 */
927/*
928 * Async fchown(<handle>)
929 * Function returns
930 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
931 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
932 *
933 * When the callback is invoked, status indicates the result:
934 * 0 : Success.
935 * data is NULL
936 * -errno : An error occured.
937 * data is the error string.
938 */
66ad6d84 939EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
84004dbf
RS
940/*
941 * Sync fchown(<handle>)
942 * Function returns
943 * 0 : The operation was successfull.
944 * -errno : The command failed.
945 */
66ad6d84 946EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
84004dbf
RS
947
948
949
950
951/*
952 * UTIMES()
953 */
954/*
955 * Async utimes(<path>)
956 * Function returns
957 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
958 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
959 *
960 * When the callback is invoked, status indicates the result:
961 * 0 : Success.
962 * data is NULL
963 * -errno : An error occured.
964 * data is the error string.
965 */
66ad6d84 966EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
84004dbf
RS
967/*
968 * Sync utimes(<path>)
969 * Function returns
970 * 0 : The operation was successfull.
971 * -errno : The command failed.
972 */
66ad6d84 973EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
84004dbf
RS
974
975
976/*
977 * UTIME()
978 */
979/*
980 * Async utime(<path>)
981 * Function returns
982 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
983 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
984 *
985 * When the callback is invoked, status indicates the result:
986 * 0 : Success.
987 * data is NULL
988 * -errno : An error occured.
989 * data is the error string.
990 */
991struct utimbuf;
66ad6d84 992EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
84004dbf
RS
993/*
994 * Sync utime(<path>)
995 * Function returns
996 * 0 : The operation was successfull.
997 * -errno : The command failed.
998 */
66ad6d84 999EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
84004dbf
RS
1000
1001
1002
1003
1004/*
1005 * ACCESS()
1006 */
1007/*
1008 * Async access(<path>)
1009 * Function returns
1010 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1011 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1012 *
1013 * When the callback is invoked, status indicates the result:
1014 * 0 : Success.
1015 * data is NULL
1016 * -errno : An error occured.
1017 * data is the error string.
1018 */
66ad6d84 1019EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
1020/*
1021 * Sync access(<path>)
1022 * Function returns
1023 * 0 : The operation was successfull.
1024 * -errno : The command failed.
1025 */
66ad6d84 1026EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
84004dbf
RS
1027
1028
1029
1030
1031/*
1032 * SYMLINK()
1033 */
1034/*
1035 * Async symlink(<path>)
1036 * Function returns
1037 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1038 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1039 *
1040 * When the callback is invoked, status indicates the result:
1041 * 0 : Success.
1042 * data is NULL
1043 * -errno : An error occured.
1044 * data is the error string.
1045 */
66ad6d84 1046EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1047/*
1048 * Sync symlink(<path>)
1049 * Function returns
1050 * 0 : The operation was successfull.
1051 * -errno : The command failed.
1052 */
66ad6d84 1053EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1054
1055
1056/*
1057 * RENAME()
1058 */
1059/*
1060 * Async rename(<oldpath>, <newpath>)
1061 * Function returns
1062 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1063 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1064 *
1065 * When the callback is invoked, status indicates the result:
1066 * 0 : Success.
1067 * data is NULL
1068 * -errno : An error occured.
1069 * data is the error string.
1070 */
66ad6d84 1071EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1072/*
1073 * Sync rename(<oldpath>, <newpath>)
1074 * Function returns
1075 * 0 : The operation was successfull.
1076 * -errno : The command failed.
1077 */
66ad6d84 1078EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1079
1080
1081
1082/*
1083 * LINK()
1084 */
1085/*
1086 * Async link(<oldpath>, <newpath>)
1087 * Function returns
1088 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1089 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1090 *
1091 * When the callback is invoked, status indicates the result:
1092 * 0 : Success.
1093 * data is NULL
1094 * -errno : An error occured.
1095 * data is the error string.
1096 */
66ad6d84 1097EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1098/*
1099 * Sync link(<oldpath>, <newpath>)
1100 * Function returns
1101 * 0 : The operation was successfull.
1102 * -errno : The command failed.
1103 */
66ad6d84 1104EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1105
1106
7f0242ca
RS
1107/*
1108 * GETEXPORTS()
1109 */
1110/*
1111 * Async getexports()
1112 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1113 * returned structures.
1114 *
1115 * This function will return the list of exports from an NFS server.
1116 *
1117 * Function returns
1118 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1119 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1120 *
1121 * When the callback is invoked, status indicates the result:
1122 * 0 : Success.
1123 * data is a pointer to an exports pointer:
1124 * exports export = *(exports *)data;
1125 * -errno : An error occured.
1126 * data is the error string.
1127 */
66ad6d84 1128EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
df5af25f
RS
1129/*
1130 * Sync getexports(<server>)
1131 * Function returns
1132 * NULL : something failed
1133 * exports export : a linked list of exported directories
52014ebf 1134 *
df5af25f
RS
1135 * returned data must be freed by calling mount_free_export_list(exportnode);
1136 */
66ad6d84 1137EXTERN struct exportnode *mount_getexports(const char *server);
7f0242ca 1138
66ad6d84 1139EXTERN void mount_free_export_list(struct exportnode *exports);
7f0242ca 1140
84004dbf
RS
1141
1142//qqq replace later with lseek(cur, 0)
183451cf 1143uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
552c7665
RS
1144
1145
1146
9c4212bf
RS
1147
1148
552c7665
RS
1149struct nfs_server_list {
1150 struct nfs_server_list *next;
1151 char *addr;
1152};
1153
9c4212bf
RS
1154/*
1155 * Sync find_local_servers(<server>)
1156 * This function will probe all local networks for NFS server. This function will
1157 * block for one second while awaiting for all nfs servers to respond.
1158 *
1159 * Function returns
1160 * NULL : something failed
1161 *
1162 * struct nfs_server_list : a linked list of all discovered servers
52014ebf 1163 *
9c4212bf
RS
1164 * returned data must be freed by nfs_free_srvr_list(srv);
1165 */
552c7665
RS
1166struct nfs_server_list *nfs_find_local_servers(void);
1167void free_nfs_srvr_list(struct nfs_server_list *srv);
52014ebf 1168
d48be00c
AR
1169#ifdef __cplusplus
1170}
1171#endif
1172
52014ebf 1173#endif /* !_LIBNFS_H_ */