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