Fix the file position handling of the read and write calls
[deb_libnfs.git] / include / nfsc / libnfs.h
CommitLineData
84004dbf
RS
1/*
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16*/
17/*
18 * This is the highlevel interface to access NFS resources using a posix-like interface
19 */
52014ebf
AR
20
21#ifndef _LIBNFS_H_
22#define _LIBNFS_H_
23
84004dbf 24#include <stdint.h>
252aa90d
CF
25#if defined(ANDROID)
26#include <sys/time.h>
27#endif
d7c6e9aa
RS
28#if defined(AROS)
29#include <sys/time.h>
30#endif
84004dbf 31
d48be00c
AR
32#ifdef __cplusplus
33extern "C" {
34#endif
35
84004dbf 36struct nfs_context;
7f0242ca 37struct rpc_context;
84004dbf 38
d2ec73c7
PL
39struct nfs_url {
40 char *server;
41 char *path;
42 char *file;
43};
44
66ad6d84
RS
45#if defined(WIN32)
46#define EXTERN __declspec( dllexport )
47#else
52014ebf 48#define EXTERN
66ad6d84
RS
49#endif
50
eecdc4f3
RS
51#if defined(WIN32)
52struct statvfs {
53 uint32_t f_bsize;
54 uint32_t f_frsize;
55 uint64_t f_blocks;
56 uint64_t f_bfree;
57 uint64_t f_bavail;
58 uint32_t f_files;
59 uint32_t f_ffree;
60 uint32_t f_favail;
52014ebf 61 uint32_t f_fsid;
eecdc4f3
RS
62 uint32_t f_flag;
63 uint32_t f_namemax;
64};
65struct utimbuf {
66 time_t actime;
67 time_t modtime;
68};
69#define R_OK 4
70#define W_OK 2
71#define X_OK 1
72#endif
73
84004dbf
RS
74/*
75 * Used for interfacing the async version of the api into an external eventsystem
76 */
66ad6d84
RS
77EXTERN int nfs_get_fd(struct nfs_context *nfs);
78EXTERN int nfs_which_events(struct nfs_context *nfs);
79EXTERN int nfs_service(struct nfs_context *nfs, int revents);
83aa785d 80EXTERN int nfs_queue_length(struct nfs_context *nfs);
84004dbf
RS
81
82/*
83 * Used if you need different credentials than the default for the current user.
84 */
67ba2239
RS
85struct AUTH;
86EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
84004dbf 87
84004dbf
RS
88/*
89 * When an operation failed, this function can extract a detailed error string.
90 */
66ad6d84 91EXTERN char *nfs_get_error(struct nfs_context *nfs);
84004dbf
RS
92
93
94/*
95 * Callback for all ASYNC nfs functions
96 */
97typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
98
7f0242ca
RS
99/*
100 * Callback for all ASYNC rpc functions
101 */
102typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
84004dbf
RS
103
104
105
106/*
107 * NFS CONTEXT.
108 */
109/*
110 * Create an NFS c, the context.
111 * Function returns
112 * NULL : Failed to create a context.
113 * *nfs : A pointer to an nfs context.
114 */
66ad6d84 115EXTERN struct nfs_context *nfs_init_context(void);
84004dbf
RS
116/*
117 * Destroy an nfs context.
118 */
66ad6d84 119EXTERN void nfs_destroy_context(struct nfs_context *nfs);
84004dbf
RS
120
121
0961765a
RS
122/*
123 * URL parsing functions.
52014ebf 124 * These functions all parse a URL of the form
0961765a
RS
125 * nfs://server/path/file?argv=val[&arg=val]*
126 * and returns a nfs_url.
127 *
128 * Apart from parsing the URL the functions will also update
129 * the nfs context to reflect settings controlled via url arguments.
130 *
131 * Current URL arguments are :
132 * tcp-syncnt=<int> : Number of SYNs to send during the seccion establish
133 * before failing settin up the tcp connection to the
134 * server.
135 * uid=<int> : UID value to use when talking to the server.
136 * default it 65534 on Windows and getuid() on unixen.
137 * gid=<int> : GID value to use when talking to the server.
138 * default it 65534 on Windows and getgid() on unixen.
139 */
d2ec73c7
PL
140/*
141 * Parse a complete NFS URL including, server, path and
142 * filename. Fail if any component is missing.
143 */
144EXTERN struct nfs_url *nfs_parse_url_full(struct nfs_context *nfs, const char *url);
145
146/*
147 * Parse an NFS URL, but do not split path and file. File
148 * in the resulting struct remains NULL.
149 */
150EXTERN struct nfs_url *nfs_parse_url_dir(struct nfs_context *nfs, const char *url);
151
152/*
153 * Parse an NFS URL, but do not fail if file, path or even server is missing.
154 * Check elements of the resulting struct for NULL.
155 */
156EXTERN struct nfs_url *nfs_parse_url_incomplete(struct nfs_context *nfs, const char *url);
157
158
159/*
160 * Free the URL struct returned by the nfs_parse_url_* functions.
161 */
162EXTERN void nfs_destroy_url(struct nfs_url *url);
163
164
84004dbf
RS
165struct nfsfh;
166
17ef62fa
RS
167/*
168 * Get the maximum supported READ3 size by the server
169 */
183451cf 170EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
17ef62fa
RS
171
172/*
173 * Get the maximum supported WRITE3 size by the server
174 */
183451cf 175EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
17ef62fa 176
d43a8953 177/*
52014ebf 178 * MODIFY CONNECT PARAMTERS
d43a8953
PL
179 */
180
181EXTERN void nfs_set_tcp_syncnt(struct nfs_context *nfs, int v);
182EXTERN void nfs_set_uid(struct nfs_context *nfs, int uid);
183EXTERN void nfs_set_gid(struct nfs_context *nfs, int gid);
84004dbf
RS
184
185/*
186 * MOUNT THE EXPORT
187 */
188/*
189 * Async nfs mount.
190 * Function returns
191 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
192 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
193 *
194 * When the callback is invoked, status indicates the result:
195 * 0 : Success.
196 * data is NULL
197 * -errno : An error occured.
198 * data is the error string.
199 */
66ad6d84 200EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data);
84004dbf
RS
201/*
202 * Sync nfs mount.
203 * Function returns
204 * 0 : The operation was successfull.
205 * -errno : The command failed.
206 */
66ad6d84 207EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname);
84004dbf
RS
208
209
210
211
212/*
213 * STAT()
214 */
215/*
216 * Async stat(<filename>)
217 * Function returns
218 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
219 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
220 *
221 * When the callback is invoked, status indicates the result:
222 * 0 : Success.
223 * data is struct stat *
224 * -errno : An error occured.
225 * data is the error string.
226 */
479302f7 227/* This function is deprecated. Use nfs_stat64_async() instead */
84004dbf 228struct stat;
66ad6d84 229EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
230/*
231 * Sync stat(<filename>)
232 * Function returns
233 * 0 : The operation was successfull.
234 * -errno : The command failed.
235 */
479302f7 236/* This function is deprecated. Use nfs_stat64() instead */
be184101
M
237#ifdef WIN32
238EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
239#else
66ad6d84 240EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
be184101 241#endif
84004dbf 242
479302f7
RS
243
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);
288
84004dbf
RS
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 */
66ad6d84 304EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
305/*
306 * Sync fstat(nfsfh *)
307 * Function returns
308 * 0 : The operation was successfull.
309 * -errno : The command failed.
310 */
be184101
M
311#ifdef WIN32
312EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
313#else
66ad6d84 314EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
be184101 315#endif
84004dbf
RS
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 *
3cea44dc
RS
331 * Supported flags are
332 * O_RDONLY
333 * O_WRONLY
334 * O_RDWR
22a0f15b 335 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
3cea44dc 336 *
84004dbf
RS
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 */
3cea44dc 344EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
84004dbf 345/*
f893b680 346 * Sync open(<filename>)
84004dbf
RS
347 * Function returns
348 * 0 : The operation was successfull. *nfsfh is filled in.
349 * -errno : The command failed.
350 */
3cea44dc 351EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
84004dbf
RS
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 */
66ad6d84 372EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
373/*
374 * Sync close(nfsfh)
375 * Function returns
376 * 0 : The operation was successfull.
377 * -errno : The command failed.
378 */
66ad6d84 379EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
84004dbf
RS
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 */
183451cf 399EXTERN 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
400/*
401 * Sync pread()
402 * Function returns
403 * >=0 : numer of bytes read.
404 * -errno : An error occured.
405 */
183451cf 406EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
84004dbf
RS
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 */
183451cf 427EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
84004dbf
RS
428/*
429 * Sync read()
430 * Function returns
431 * >=0 : numer of bytes read.
432 * -errno : An error occured.
433 */
183451cf 434EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
84004dbf
RS
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 */
183451cf 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);
84004dbf
RS
456/*
457 * Sync pwrite()
458 * Function returns
459 * >=0 : numer of bytes written.
460 * -errno : An error occured.
461 */
183451cf 462EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
84004dbf
RS
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 */
183451cf 481EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
84004dbf
RS
482/*
483 * Sync write()
484 * Function returns
485 * >=0 : numer of bytes written.
486 * -errno : An error occured.
487 */
183451cf 488EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
84004dbf
RS
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.
183451cf 503 * data is uint64_t * for the current position.
84004dbf
RS
504 * -errno : An error occured.
505 * data is the error string.
506 */
1f1b6cb0 507EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, nfs_cb cb, void *private_data);
84004dbf
RS
508/*
509 * Sync lseek()
510 * Function returns
511 * >=0 : numer of bytes read.
512 * -errno : An error occured.
513 */
1f1b6cb0 514EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, uint64_t *current_offset);
84004dbf
RS
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 */
66ad6d84 532EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
533/*
534 * Sync fsync()
535 * Function returns
536 * 0 : Success
537 * -errno : An error occured.
538 */
66ad6d84 539EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
84004dbf
RS
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 */
183451cf 558EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
84004dbf
RS
559/*
560 * Sync truncate()
561 * Function returns
562 * 0 : Success
563 * -errno : An error occured.
564 */
183451cf 565EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
84004dbf
RS
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 */
183451cf 584EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
84004dbf
RS
585/*
586 * Sync ftruncate()
587 * Function returns
588 * 0 : Success
589 * -errno : An error occured.
590 */
183451cf 591EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
84004dbf
RS
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 */
66ad6d84 613EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
614/*
615 * Sync mkdir()
616 * Function returns
617 * 0 : Success
618 * -errno : An error occured.
619 */
66ad6d84 620EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
84004dbf
RS
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 */
66ad6d84 639EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
640/*
641 * Sync rmdir()
642 * Function returns
643 * 0 : Success
644 * -errno : An error occured.
645 */
66ad6d84 646EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
84004dbf
RS
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 */
66ad6d84 667EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
668/*
669 * Sync creat()
670 * Function returns
671 * 0 : Success
672 * -errno : An error occured.
673 */
66ad6d84 674EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
84004dbf
RS
675
676
1ec6b50a
RS
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);
84004dbf
RS
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 */
66ad6d84 719EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
720/*
721 * Sync unlink()
722 * Function returns
723 * 0 : Success
724 * -errno : An error occured.
725 */
66ad6d84 726EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
84004dbf
RS
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 */
66ad6d84 750EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
751/*
752 * Sync opendir()
753 * Function returns
754 * 0 : Success
755 * -errno : An error occured.
756 */
66ad6d84 757EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
84004dbf
RS
758
759
760
761/*
762 * READDIR()
763 */
764struct nfsdirent {
765 struct nfsdirent *next;
766 char *name;
767 uint64_t inode;
0804e67d 768
7bda8bad
RS
769 /* Some extra fields we get for free through the READDIRPLUS3 call.
770 You need libnfs-raw-nfs.h for type/mode constants */
0804e67d
RS
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;
7bda8bad
RS
777 uint32_t uid;
778 uint32_t gid;
84004dbf
RS
779};
780/*
781 * nfs_readdir() never blocks, so no special sync/async versions are available
782 */
66ad6d84 783EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
84004dbf
RS
784
785
786
787/*
f893b680 788 * CLOSEDIR()
84004dbf
RS
789 */
790/*
791 * nfs_closedir() never blocks, so no special sync/async versions are available
792 */
66ad6d84 793EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
84004dbf
RS
794
795
f893b680
RS
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
84004dbf
RS
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;
66ad6d84 856EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
857/*
858 * Sync statvfs(<dirname>)
859 * Function returns
860 * 0 : The operation was successfull.
861 * -errno : The command failed.
862 */
66ad6d84 863EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
84004dbf
RS
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;
66ad6d84 883EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
884/*
885 * Sync readlink(<name>)
886 * Function returns
887 * 0 : The operation was successfull.
888 * -errno : The command failed.
889 */
66ad6d84 890EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
84004dbf
RS
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 */
66ad6d84 909EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
910/*
911 * Sync chmod(<name>)
912 * Function returns
913 * 0 : The operation was successfull.
914 * -errno : The command failed.
915 */
66ad6d84 916EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
84004dbf
RS
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 */
66ad6d84 935EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
936/*
937 * Sync fchmod(<handle>)
938 * Function returns
939 * 0 : The operation was successfull.
940 * -errno : The command failed.
941 */
66ad6d84 942EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
84004dbf
RS
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 */
66ad6d84 961EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
84004dbf
RS
962/*
963 * Sync chown(<name>)
964 * Function returns
965 * 0 : The operation was successfull.
966 * -errno : The command failed.
967 */
66ad6d84 968EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
84004dbf
RS
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 */
66ad6d84 987EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
84004dbf
RS
988/*
989 * Sync fchown(<handle>)
990 * Function returns
991 * 0 : The operation was successfull.
992 * -errno : The command failed.
993 */
66ad6d84 994EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
84004dbf
RS
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 */
66ad6d84 1014EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
84004dbf
RS
1015/*
1016 * Sync utimes(<path>)
1017 * Function returns
1018 * 0 : The operation was successfull.
1019 * -errno : The command failed.
1020 */
66ad6d84 1021EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
84004dbf
RS
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;
66ad6d84 1040EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
84004dbf
RS
1041/*
1042 * Sync utime(<path>)
1043 * Function returns
1044 * 0 : The operation was successfull.
1045 * -errno : The command failed.
1046 */
66ad6d84 1047EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
84004dbf
RS
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 */
66ad6d84 1067EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
1068/*
1069 * Sync access(<path>)
1070 * Function returns
1071 * 0 : The operation was successfull.
1072 * -errno : The command failed.
1073 */
66ad6d84 1074EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
84004dbf
RS
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 */
66ad6d84 1094EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1095/*
1096 * Sync symlink(<path>)
1097 * Function returns
1098 * 0 : The operation was successfull.
1099 * -errno : The command failed.
1100 */
66ad6d84 1101EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
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 */
66ad6d84 1119EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1120/*
1121 * Sync rename(<oldpath>, <newpath>)
1122 * Function returns
1123 * 0 : The operation was successfull.
1124 * -errno : The command failed.
1125 */
66ad6d84 1126EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
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 */
66ad6d84 1145EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1146/*
1147 * Sync link(<oldpath>, <newpath>)
1148 * Function returns
1149 * 0 : The operation was successfull.
1150 * -errno : The command failed.
1151 */
66ad6d84 1152EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1153
1154
7f0242ca
RS
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 */
66ad6d84 1176EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
df5af25f
RS
1177/*
1178 * Sync getexports(<server>)
1179 * Function returns
1180 * NULL : something failed
1181 * exports export : a linked list of exported directories
52014ebf 1182 *
df5af25f
RS
1183 * returned data must be freed by calling mount_free_export_list(exportnode);
1184 */
66ad6d84 1185EXTERN struct exportnode *mount_getexports(const char *server);
7f0242ca 1186
66ad6d84 1187EXTERN void mount_free_export_list(struct exportnode *exports);
7f0242ca 1188
84004dbf
RS
1189
1190//qqq replace later with lseek(cur, 0)
183451cf 1191uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
552c7665
RS
1192
1193
1194
9c4212bf
RS
1195
1196
552c7665
RS
1197struct nfs_server_list {
1198 struct nfs_server_list *next;
1199 char *addr;
1200};
1201
9c4212bf
RS
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
52014ebf 1211 *
9c4212bf
RS
1212 * returned data must be freed by nfs_free_srvr_list(srv);
1213 */
552c7665
RS
1214struct nfs_server_list *nfs_find_local_servers(void);
1215void free_nfs_srvr_list(struct nfs_server_list *srv);
52014ebf 1216
d48be00c
AR
1217#ifdef __cplusplus
1218}
1219#endif
1220
52014ebf 1221#endif /* !_LIBNFS_H_ */