Imported Upstream version 1.9.3
[deb_libnfs.git] / include / nfsc / libnfs.h
CommitLineData
dabf4152
AM
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 */
ee872606
RRS
20
21#ifndef _LIBNFS_H_
22#define _LIBNFS_H_
23
dabf4152 24#include <stdint.h>
ee872606
RRS
25#if defined(ANDROID)
26#include <sys/time.h>
27#endif
28#if defined(AROS)
29#include <sys/time.h>
30#endif
31
32#ifdef __cplusplus
33extern "C" {
34#endif
dabf4152
AM
35
36struct nfs_context;
37struct rpc_context;
38
ee872606
RRS
39struct nfs_url {
40 char *server;
41 char *path;
42 char *file;
43};
44
5670ec6e
AM
45#if defined(WIN32)
46#define EXTERN __declspec( dllexport )
47#else
ee872606 48#define EXTERN
5670ec6e
AM
49#endif
50
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;
ee872606 61 uint32_t f_fsid;
5670ec6e
AM
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
dabf4152
AM
74/*
75 * Used for interfacing the async version of the api into an external eventsystem
76 */
5670ec6e
AM
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);
80EXTERN int nfs_queue_length(struct nfs_context *nfs);
dabf4152
AM
81
82/*
83 * Used if you need different credentials than the default for the current user.
84 */
ee872606
RRS
85struct AUTH;
86EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
dabf4152
AM
87
88/*
89 * When an operation failed, this function can extract a detailed error string.
90 */
5670ec6e 91EXTERN char *nfs_get_error(struct nfs_context *nfs);
dabf4152
AM
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
99/*
100 * Callback for all ASYNC rpc functions
101 */
102typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
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 */
5670ec6e 115EXTERN struct nfs_context *nfs_init_context(void);
dabf4152
AM
116/*
117 * Destroy an nfs context.
118 */
5670ec6e 119EXTERN void nfs_destroy_context(struct nfs_context *nfs);
dabf4152
AM
120
121
ee872606
RRS
122/*
123 * URL parsing functions.
124 * These functions all parse a URL of the form
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 */
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
dabf4152
AM
165struct nfsfh;
166
167/*
168 * Get the maximum supported READ3 size by the server
169 */
5670ec6e 170EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
dabf4152
AM
171
172/*
173 * Get the maximum supported WRITE3 size by the server
174 */
5670ec6e 175EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
dabf4152 176
ee872606
RRS
177/*
178 * MODIFY CONNECT PARAMTERS
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);
dabf4152
AM
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 */
5670ec6e 200EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data);
dabf4152
AM
201/*
202 * Sync nfs mount.
203 * Function returns
204 * 0 : The operation was successfull.
205 * -errno : The command failed.
206 */
5670ec6e 207EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname);
dabf4152
AM
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 */
ee872606 227/* This function is deprecated. Use nfs_stat64_async() instead */
dabf4152 228struct stat;
5670ec6e 229EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
230/*
231 * Sync stat(<filename>)
232 * Function returns
233 * 0 : The operation was successfull.
234 * -errno : The command failed.
235 */
ee872606
RRS
236/* This function is deprecated. Use nfs_stat64() instead */
237#ifdef WIN32
238EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
239#else
5670ec6e 240EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
ee872606
RRS
241#endif
242
dabf4152 243
ee872606
RRS
244/* nfs_stat64
245 * 64 bit version if stat. All fields are always 64bit.
246 * Use these functions instead of nfs_stat[_async](), especially if you
247 * have weird stat structures.
248 */
249/*
250 * STAT()
251 */
252struct nfs_stat_64 {
253 uint64_t nfs_dev;
254 uint64_t nfs_ino;
255 uint64_t nfs_mode;
256 uint64_t nfs_nlink;
257 uint64_t nfs_uid;
258 uint64_t nfs_gid;
259 uint64_t nfs_rdev;
260 uint64_t nfs_size;
261 uint64_t nfs_blksize;
262 uint64_t nfs_blocks;
263 uint64_t nfs_atime;
264 uint64_t nfs_mtime;
265 uint64_t nfs_ctime;
266};
267
268/*
269 * Async stat(<filename>)
270 * Function returns
271 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
272 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
273 *
274 * When the callback is invoked, status indicates the result:
275 * 0 : Success.
276 * data is struct nfs_stat_64 *
277 * -errno : An error occured.
278 * data is the error string.
279 */
280EXTERN int nfs_stat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
281/*
282 * Sync stat(<filename>)
283 * Function returns
284 * 0 : The operation was successfull.
285 * -errno : The command failed.
286 */
287EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
dabf4152
AM
288
289/*
290 * FSTAT()
291 */
292/*
293 * Async fstat(nfsfh *)
294 * Function returns
295 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
296 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
297 *
298 * When the callback is invoked, status indicates the result:
299 * 0 : Success.
300 * data is struct stat *
301 * -errno : An error occured.
302 * data is the error string.
303 */
5670ec6e 304EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
dabf4152
AM
305/*
306 * Sync fstat(nfsfh *)
307 * Function returns
308 * 0 : The operation was successfull.
309 * -errno : The command failed.
310 */
ee872606
RRS
311#ifdef WIN32
312EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
313#else
5670ec6e 314EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
ee872606 315#endif
dabf4152
AM
316
317
318
319/*
320 * OPEN()
321 */
322/*
323 * Async open(<filename>)
324 *
325 * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
326 *
327 * Function returns
328 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
329 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
330 *
ee872606
RRS
331 * Supported flags are
332 * O_RDONLY
333 * O_WRONLY
334 * O_RDWR
335 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
336 *
dabf4152
AM
337 * When the callback is invoked, status indicates the result:
338 * 0 : Success.
339 * data is a struct *nfsfh;
340 * The nfsfh is close using nfs_close().
341 * -errno : An error occured.
342 * data is the error string.
343 */
ee872606 344EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
dabf4152 345/*
ee872606 346 * Sync open(<filename>)
dabf4152
AM
347 * Function returns
348 * 0 : The operation was successfull. *nfsfh is filled in.
349 * -errno : The command failed.
350 */
ee872606 351EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
dabf4152
AM
352
353
354
355
356/*
357 * CLOSE
358 */
359/*
360 * Async close(nfsfh)
361 *
362 * Function returns
363 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
364 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
365 *
366 * When the callback is invoked, status indicates the result:
367 * 0 : Success.
368 * data is NULL.
369 * -errno : An error occured.
370 * data is the error string.
371 */
5670ec6e 372EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
dabf4152
AM
373/*
374 * Sync close(nfsfh)
375 * Function returns
376 * 0 : The operation was successfull.
377 * -errno : The command failed.
378 */
5670ec6e 379EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
dabf4152
AM
380
381
382/*
383 * PREAD()
384 */
385/*
386 * Async pread()
387 *
388 * Function returns
389 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
390 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
391 *
392 * When the callback is invoked, status indicates the result:
393 * >=0 : Success.
394 * status is numer of bytes read.
395 * data is a pointer to the returned data.
396 * -errno : An error occured.
397 * data is the error string.
398 */
5670ec6e 399EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, nfs_cb cb, void *private_data);
dabf4152
AM
400/*
401 * Sync pread()
402 * Function returns
403 * >=0 : numer of bytes read.
404 * -errno : An error occured.
405 */
5670ec6e 406EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
dabf4152
AM
407
408
409
410/*
411 * READ()
412 */
413/*
414 * Async read()
415 *
416 * Function returns
417 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
418 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
419 *
420 * When the callback is invoked, status indicates the result:
421 * >=0 : Success.
422 * status is numer of bytes read.
423 * data is a pointer to the returned data.
424 * -errno : An error occured.
425 * data is the error string.
426 */
5670ec6e 427EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
dabf4152
AM
428/*
429 * Sync read()
430 * Function returns
431 * >=0 : numer of bytes read.
432 * -errno : An error occured.
433 */
5670ec6e 434EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
dabf4152
AM
435
436
437
438
439/*
440 * PWRITE()
441 */
442/*
443 * Async pwrite()
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.
451 * status is numer of bytes written.
452 * -errno : An error occured.
453 * data is the error string.
454 */
5670ec6e 455EXTERN 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);
dabf4152
AM
456/*
457 * Sync pwrite()
458 * Function returns
459 * >=0 : numer of bytes written.
460 * -errno : An error occured.
461 */
5670ec6e 462EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
dabf4152
AM
463
464
465/*
466 * WRITE()
467 */
468/*
469 * Async write()
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 * status is numer of bytes written.
478 * -errno : An error occured.
479 * data is the error string.
480 */
5670ec6e 481EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
dabf4152
AM
482/*
483 * Sync write()
484 * Function returns
485 * >=0 : numer of bytes written.
486 * -errno : An error occured.
487 */
5670ec6e 488EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
dabf4152
AM
489
490
491/*
492 * LSEEK()
493 */
494/*
495 * Async lseek()
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.
5670ec6e 503 * data is uint64_t * for the current position.
dabf4152
AM
504 * -errno : An error occured.
505 * data is the error string.
506 */
5670ec6e 507EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, nfs_cb cb, void *private_data);
dabf4152
AM
508/*
509 * Sync lseek()
510 * Function returns
511 * >=0 : numer of bytes read.
512 * -errno : An error occured.
513 */
5670ec6e 514EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, uint64_t *current_offset);
dabf4152
AM
515
516
517/*
518 * FSYNC()
519 */
520/*
521 * Async fsync()
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 */
5670ec6e 532EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
dabf4152
AM
533/*
534 * Sync fsync()
535 * Function returns
536 * 0 : Success
537 * -errno : An error occured.
538 */
5670ec6e 539EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
dabf4152
AM
540
541
542
543/*
544 * TRUNCATE()
545 */
546/*
547 * Async truncate()
548 *
549 * Function returns
550 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
551 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
552 *
553 * When the callback is invoked, status indicates the result:
554 * 0 : Success.
555 * -errno : An error occured.
556 * data is the error string.
557 */
5670ec6e 558EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
dabf4152
AM
559/*
560 * Sync truncate()
561 * Function returns
562 * 0 : Success
563 * -errno : An error occured.
564 */
5670ec6e 565EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
dabf4152
AM
566
567
568
569/*
570 * FTRUNCATE()
571 */
572/*
573 * Async ftruncate()
574 *
575 * Function returns
576 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
577 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
578 *
579 * When the callback is invoked, status indicates the result:
580 * 0 : Success.
581 * -errno : An error occured.
582 * data is the error string.
583 */
5670ec6e 584EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
dabf4152
AM
585/*
586 * Sync ftruncate()
587 * Function returns
588 * 0 : Success
589 * -errno : An error occured.
590 */
5670ec6e 591EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
dabf4152
AM
592
593
594
595
596
597
598/*
599 * MKDIR()
600 */
601/*
602 * Async mkdir()
603 *
604 * Function returns
605 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
606 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
607 *
608 * When the callback is invoked, status indicates the result:
609 * 0 : Success.
610 * -errno : An error occured.
611 * data is the error string.
612 */
5670ec6e 613EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
614/*
615 * Sync mkdir()
616 * Function returns
617 * 0 : Success
618 * -errno : An error occured.
619 */
5670ec6e 620EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
dabf4152
AM
621
622
623
624/*
625 * RMDIR()
626 */
627/*
628 * Async rmdir()
629 *
630 * Function returns
631 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
632 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
633 *
634 * When the callback is invoked, status indicates the result:
635 * 0 : Success.
636 * -errno : An error occured.
637 * data is the error string.
638 */
5670ec6e 639EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
640/*
641 * Sync rmdir()
642 * Function returns
643 * 0 : Success
644 * -errno : An error occured.
645 */
5670ec6e 646EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
dabf4152
AM
647
648
649
650
651/*
652 * CREAT()
653 */
654/*
655 * Async creat()
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 a struct *nfsfh;
664 * -errno : An error occured.
665 * data is the error string.
666 */
5670ec6e 667EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
dabf4152
AM
668/*
669 * Sync creat()
670 * Function returns
671 * 0 : Success
672 * -errno : An error occured.
673 */
5670ec6e 674EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
dabf4152
AM
675
676
5670ec6e
AM
677/*
678 * MKNOD()
679 */
680/*
681 * Async mknod()
682 *
683 * Function returns
684 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
685 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
686 *
687 * When the callback is invoked, status indicates the result:
688 * 0 : Success.
689 * -errno : An error occured.
690 * data is the error string.
691 */
692EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
693/*
694 * Sync mknod()
695 * Function returns
696 * 0 : Success
697 * -errno : An error occured.
698 */
699EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
dabf4152
AM
700
701
702
703/*
704 * UNLINK()
705 */
706/*
707 * Async unlink()
708 *
709 * Function returns
710 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
711 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
712 *
713 * When the callback is invoked, status indicates the result:
714 * 0 : Success.
715 * data is NULL
716 * -errno : An error occured.
717 * data is the error string.
718 */
5670ec6e 719EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
720/*
721 * Sync unlink()
722 * Function returns
723 * 0 : Success
724 * -errno : An error occured.
725 */
5670ec6e 726EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
dabf4152
AM
727
728
729
730
731/*
732 * OPENDIR()
733 */
734struct nfsdir;
735/*
736 * Async opendir()
737 *
738 * Function returns
739 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
740 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
741 *
742 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
743 *
744 * When the callback is invoked, status indicates the result:
745 * 0 : Success.
746 * data is struct nfsdir *
747 * -errno : An error occured.
748 * data is the error string.
749 */
5670ec6e 750EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
751/*
752 * Sync opendir()
753 * Function returns
754 * 0 : Success
755 * -errno : An error occured.
756 */
5670ec6e 757EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
dabf4152
AM
758
759
760
761/*
762 * READDIR()
763 */
764struct nfsdirent {
765 struct nfsdirent *next;
766 char *name;
767 uint64_t inode;
5670ec6e 768
ee872606
RRS
769 /* Some extra fields we get for free through the READDIRPLUS3 call.
770 You need libnfs-raw-nfs.h for type/mode constants */
5670ec6e
AM
771 uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
772 uint32_t mode;
773 uint64_t size;
774 struct timeval atime;
775 struct timeval mtime;
776 struct timeval ctime;
ee872606
RRS
777 uint32_t uid;
778 uint32_t gid;
dabf4152
AM
779};
780/*
781 * nfs_readdir() never blocks, so no special sync/async versions are available
782 */
5670ec6e 783EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
dabf4152
AM
784
785
786
787/*
ee872606 788 * CLOSEDIR()
dabf4152
AM
789 */
790/*
791 * nfs_closedir() never blocks, so no special sync/async versions are available
792 */
5670ec6e 793EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
dabf4152
AM
794
795
ee872606
RRS
796/*
797 * CHDIR()
798 */
799/*
800 * Async chdir(<path>)
801 *
802 * Function returns
803 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
804 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
805 *
806 * When the callback is invoked, status indicates the result:
807 * 0 : Success.
808 * data is NULL;
809 * -errno : An error occured.
810 * data is the error string.
811 */
812EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
813/*
814 * Sync chdir(<path>)
815 * Function returns
816 * 0 : The operation was successfull.
817 * -errno : The command failed.
818 */
819EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
820
821/*
822 * GETCWD()
823 */
824/*
825 * nfs_getcwd() never blocks, so no special sync/async versions are available
826 */
827/*
828 * Sync getcwd()
829 * This function returns a pointer to the current working directory.
830 * This pointer is only stable until the next [f]chdir or when the
831 * context is destroyed.
832 *
833 * Function returns
834 * 0 : The operation was successfull and *cwd is filled in.
835 * -errno : The command failed.
836 */
837EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
838
dabf4152
AM
839
840/*
841 * STATVFS()
842 */
843/*
844 * Async statvfs(<dirname>)
845 * Function returns
846 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
847 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
848 *
849 * When the callback is invoked, status indicates the result:
850 * 0 : Success.
851 * data is struct statvfs *
852 * -errno : An error occured.
853 * data is the error string.
854 */
855struct statvfs;
5670ec6e 856EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
857/*
858 * Sync statvfs(<dirname>)
859 * Function returns
860 * 0 : The operation was successfull.
861 * -errno : The command failed.
862 */
5670ec6e 863EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
dabf4152
AM
864
865
866/*
867 * READLINK()
868 */
869/*
870 * Async readlink(<name>)
871 * Function returns
872 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
873 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
874 *
875 * When the callback is invoked, status indicates the result:
876 * 0 : Success.
877 * data is a char *
878 * data is only valid during the callback and is automatically freed when the callback returns.
879 * -errno : An error occured.
880 * data is the error string.
881 */
882struct statvfs;
5670ec6e 883EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
dabf4152
AM
884/*
885 * Sync readlink(<name>)
886 * Function returns
887 * 0 : The operation was successfull.
888 * -errno : The command failed.
889 */
5670ec6e 890EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
dabf4152
AM
891
892
893
894/*
895 * CHMOD()
896 */
897/*
898 * Async chmod(<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 */
5670ec6e 909EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
dabf4152
AM
910/*
911 * Sync chmod(<name>)
912 * Function returns
913 * 0 : The operation was successfull.
914 * -errno : The command failed.
915 */
5670ec6e 916EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
dabf4152
AM
917
918
919
920/*
921 * FCHMOD()
922 */
923/*
924 * Async fchmod(<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 */
5670ec6e 935EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
dabf4152
AM
936/*
937 * Sync fchmod(<handle>)
938 * Function returns
939 * 0 : The operation was successfull.
940 * -errno : The command failed.
941 */
5670ec6e 942EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
dabf4152
AM
943
944
945
946/*
947 * CHOWN()
948 */
949/*
950 * Async chown(<name>)
951 * Function returns
952 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
953 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
954 *
955 * When the callback is invoked, status indicates the result:
956 * 0 : Success.
957 * data is NULL
958 * -errno : An error occured.
959 * data is the error string.
960 */
5670ec6e 961EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
dabf4152
AM
962/*
963 * Sync chown(<name>)
964 * Function returns
965 * 0 : The operation was successfull.
966 * -errno : The command failed.
967 */
5670ec6e 968EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
dabf4152
AM
969
970
971
972/*
973 * FCHOWN()
974 */
975/*
976 * Async fchown(<handle>)
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 */
5670ec6e 987EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
dabf4152
AM
988/*
989 * Sync fchown(<handle>)
990 * Function returns
991 * 0 : The operation was successfull.
992 * -errno : The command failed.
993 */
5670ec6e 994EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
dabf4152
AM
995
996
997
998
999/*
1000 * UTIMES()
1001 */
1002/*
1003 * Async utimes(<path>)
1004 * Function returns
1005 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1006 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1007 *
1008 * When the callback is invoked, status indicates the result:
1009 * 0 : Success.
1010 * data is NULL
1011 * -errno : An error occured.
1012 * data is the error string.
1013 */
5670ec6e 1014EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
dabf4152
AM
1015/*
1016 * Sync utimes(<path>)
1017 * Function returns
1018 * 0 : The operation was successfull.
1019 * -errno : The command failed.
1020 */
5670ec6e 1021EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
dabf4152
AM
1022
1023
1024/*
1025 * UTIME()
1026 */
1027/*
1028 * Async utime(<path>)
1029 * Function returns
1030 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1031 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1032 *
1033 * When the callback is invoked, status indicates the result:
1034 * 0 : Success.
1035 * data is NULL
1036 * -errno : An error occured.
1037 * data is the error string.
1038 */
1039struct utimbuf;
5670ec6e 1040EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
dabf4152
AM
1041/*
1042 * Sync utime(<path>)
1043 * Function returns
1044 * 0 : The operation was successfull.
1045 * -errno : The command failed.
1046 */
5670ec6e 1047EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
dabf4152
AM
1048
1049
1050
1051
1052/*
1053 * ACCESS()
1054 */
1055/*
1056 * Async access(<path>)
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 */
5670ec6e 1067EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
dabf4152
AM
1068/*
1069 * Sync access(<path>)
1070 * Function returns
1071 * 0 : The operation was successfull.
1072 * -errno : The command failed.
1073 */
5670ec6e 1074EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
dabf4152
AM
1075
1076
1077
1078
1079/*
1080 * SYMLINK()
1081 */
1082/*
1083 * Async symlink(<path>)
1084 * Function returns
1085 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1086 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1087 *
1088 * When the callback is invoked, status indicates the result:
1089 * 0 : Success.
1090 * data is NULL
1091 * -errno : An error occured.
1092 * data is the error string.
1093 */
5670ec6e 1094EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
dabf4152
AM
1095/*
1096 * Sync symlink(<path>)
1097 * Function returns
1098 * 0 : The operation was successfull.
1099 * -errno : The command failed.
1100 */
5670ec6e 1101EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
dabf4152
AM
1102
1103
1104/*
1105 * RENAME()
1106 */
1107/*
1108 * Async rename(<oldpath>, <newpath>)
1109 * Function returns
1110 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1111 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1112 *
1113 * When the callback is invoked, status indicates the result:
1114 * 0 : Success.
1115 * data is NULL
1116 * -errno : An error occured.
1117 * data is the error string.
1118 */
5670ec6e 1119EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
dabf4152
AM
1120/*
1121 * Sync rename(<oldpath>, <newpath>)
1122 * Function returns
1123 * 0 : The operation was successfull.
1124 * -errno : The command failed.
1125 */
5670ec6e 1126EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
dabf4152
AM
1127
1128
1129
1130/*
1131 * LINK()
1132 */
1133/*
1134 * Async link(<oldpath>, <newpath>)
1135 * Function returns
1136 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1137 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1138 *
1139 * When the callback is invoked, status indicates the result:
1140 * 0 : Success.
1141 * data is NULL
1142 * -errno : An error occured.
1143 * data is the error string.
1144 */
5670ec6e 1145EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
dabf4152
AM
1146/*
1147 * Sync link(<oldpath>, <newpath>)
1148 * Function returns
1149 * 0 : The operation was successfull.
1150 * -errno : The command failed.
1151 */
5670ec6e 1152EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
dabf4152
AM
1153
1154
1155/*
1156 * GETEXPORTS()
1157 */
1158/*
1159 * Async getexports()
1160 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1161 * returned structures.
1162 *
1163 * This function will return the list of exports from an NFS server.
1164 *
1165 * Function returns
1166 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1167 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1168 *
1169 * When the callback is invoked, status indicates the result:
1170 * 0 : Success.
1171 * data is a pointer to an exports pointer:
1172 * exports export = *(exports *)data;
1173 * -errno : An error occured.
1174 * data is the error string.
1175 */
5670ec6e 1176EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
dabf4152
AM
1177/*
1178 * Sync getexports(<server>)
1179 * Function returns
1180 * NULL : something failed
1181 * exports export : a linked list of exported directories
ee872606 1182 *
dabf4152
AM
1183 * returned data must be freed by calling mount_free_export_list(exportnode);
1184 */
5670ec6e 1185EXTERN struct exportnode *mount_getexports(const char *server);
dabf4152 1186
5670ec6e 1187EXTERN void mount_free_export_list(struct exportnode *exports);
dabf4152
AM
1188
1189
1190//qqq replace later with lseek(cur, 0)
5670ec6e 1191uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
dabf4152
AM
1192
1193
1194
1195
1196
1197struct nfs_server_list {
1198 struct nfs_server_list *next;
1199 char *addr;
1200};
1201
1202/*
1203 * Sync find_local_servers(<server>)
1204 * This function will probe all local networks for NFS server. This function will
1205 * block for one second while awaiting for all nfs servers to respond.
1206 *
1207 * Function returns
1208 * NULL : something failed
1209 *
1210 * struct nfs_server_list : a linked list of all discovered servers
ee872606 1211 *
dabf4152
AM
1212 * returned data must be freed by nfs_free_srvr_list(srv);
1213 */
1214struct nfs_server_list *nfs_find_local_servers(void);
1215void free_nfs_srvr_list(struct nfs_server_list *srv);
ee872606
RRS
1216
1217#ifdef __cplusplus
1218}
1219#endif
1220
1221#endif /* !_LIBNFS_H_ */