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