libnfs: Add lchown
[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;
fc08ac45
RL
273 uint64_t nfs_atime_nsec;
274 uint64_t nfs_mtime_nsec;
275 uint64_t nfs_ctime_nsec;
276 uint64_t nfs_used;
479302f7
RS
277};
278
279/*
280 * Async stat(<filename>)
281 * Function returns
282 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
283 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
284 *
285 * When the callback is invoked, status indicates the result:
286 * 0 : Success.
287 * data is struct nfs_stat_64 *
288 * -errno : An error occured.
289 * data is the error string.
290 */
291EXTERN int nfs_stat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
292/*
293 * Sync stat(<filename>)
294 * Function returns
295 * 0 : The operation was successfull.
296 * -errno : The command failed.
297 */
298EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
299
84004dbf
RS
300/*
301 * FSTAT()
302 */
303/*
304 * Async fstat(nfsfh *)
305 * Function returns
306 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
307 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
308 *
309 * When the callback is invoked, status indicates the result:
310 * 0 : Success.
311 * data is struct stat *
312 * -errno : An error occured.
313 * data is the error string.
314 */
3e020c15 315/* This function is deprecated. Use nfs_fstat64_async() instead */
66ad6d84 316EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
317/*
318 * Sync fstat(nfsfh *)
319 * Function returns
320 * 0 : The operation was successfull.
321 * -errno : The command failed.
322 */
be184101
M
323#ifdef WIN32
324EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
325#else
66ad6d84 326EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
be184101 327#endif
84004dbf 328
3e020c15
RL
329/* nfs_fstat64
330 * 64 bit version of fstat. All fields are always 64bit.
331 * Use these functions instead of nfs_fstat[_async](), especially if you
332 * have weird stat structures.
333 */
334/*
335 * FSTAT()
336 */
337/*
338 * Async fstat(nfsfh *)
339 * Function returns
340 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
341 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
342 *
343 * When the callback is invoked, status indicates the result:
344 * 0 : Success.
345 * data is struct stat *
346 * -errno : An error occured.
347 * data is the error string.
348 */
349EXTERN int nfs_fstat64_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
350/*
351 * Sync fstat(nfsfh *)
352 * Function returns
353 * 0 : The operation was successfull.
354 * -errno : The command failed.
355 */
356EXTERN int nfs_fstat64(struct nfs_context *nfs, struct nfsfh *nfsfh, struct nfs_stat_64 *st);
357
84004dbf
RS
358
359
360/*
361 * OPEN()
362 */
363/*
364 * Async open(<filename>)
365 *
548e2bea 366 * mode is a combination of the flags :
00b29d10 367 * O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND, O_TRUNC
84004dbf
RS
368 *
369 * Function returns
370 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
371 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
372 *
3cea44dc 373 * Supported flags are
548e2bea 374 * O_APPEND
3cea44dc
RS
375 * O_RDONLY
376 * O_WRONLY
377 * O_RDWR
00b29d10 378 * O_SYNC
22a0f15b 379 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
3cea44dc 380 *
84004dbf
RS
381 * When the callback is invoked, status indicates the result:
382 * 0 : Success.
383 * data is a struct *nfsfh;
384 * The nfsfh is close using nfs_close().
385 * -errno : An error occured.
386 * data is the error string.
387 */
3cea44dc 388EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
84004dbf 389/*
f893b680 390 * Sync open(<filename>)
84004dbf
RS
391 * Function returns
392 * 0 : The operation was successfull. *nfsfh is filled in.
393 * -errno : The command failed.
394 */
3cea44dc 395EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
84004dbf
RS
396
397
398
399
400/*
401 * CLOSE
402 */
403/*
404 * Async close(nfsfh)
405 *
406 * Function returns
407 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
408 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
409 *
410 * When the callback is invoked, status indicates the result:
411 * 0 : Success.
412 * data is NULL.
413 * -errno : An error occured.
414 * data is the error string.
415 */
66ad6d84 416EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
417/*
418 * Sync close(nfsfh)
419 * Function returns
420 * 0 : The operation was successfull.
421 * -errno : The command failed.
422 */
66ad6d84 423EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
84004dbf
RS
424
425
426/*
427 * PREAD()
428 */
429/*
430 * Async pread()
431 *
432 * Function returns
433 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
434 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
435 *
436 * When the callback is invoked, status indicates the result:
437 * >=0 : Success.
438 * status is numer of bytes read.
439 * data is a pointer to the returned data.
440 * -errno : An error occured.
441 * data is the error string.
442 */
183451cf 443EXTERN 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
444/*
445 * Sync pread()
446 * Function returns
447 * >=0 : numer of bytes read.
448 * -errno : An error occured.
449 */
183451cf 450EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
84004dbf
RS
451
452
453
454/*
455 * READ()
456 */
457/*
458 * Async read()
459 *
460 * Function returns
461 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
462 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
463 *
464 * When the callback is invoked, status indicates the result:
465 * >=0 : Success.
466 * status is numer of bytes read.
467 * data is a pointer to the returned data.
468 * -errno : An error occured.
469 * data is the error string.
470 */
183451cf 471EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
84004dbf
RS
472/*
473 * Sync read()
474 * Function returns
475 * >=0 : numer of bytes read.
476 * -errno : An error occured.
477 */
183451cf 478EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
84004dbf
RS
479
480
481
482
483/*
484 * PWRITE()
485 */
486/*
487 * Async pwrite()
488 *
489 * Function returns
490 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
491 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
492 *
493 * When the callback is invoked, status indicates the result:
494 * >=0 : Success.
495 * status is numer of bytes written.
496 * -errno : An error occured.
497 * data is the error string.
498 */
183451cf 499EXTERN 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
500/*
501 * Sync pwrite()
502 * Function returns
503 * >=0 : numer of bytes written.
504 * -errno : An error occured.
505 */
183451cf 506EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
84004dbf
RS
507
508
509/*
510 * WRITE()
511 */
512/*
513 * Async write()
514 *
515 * Function returns
516 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
517 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
518 *
519 * When the callback is invoked, status indicates the result:
520 * >=0 : Success.
521 * status is numer of bytes written.
522 * -errno : An error occured.
523 * data is the error string.
524 */
183451cf 525EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
84004dbf
RS
526/*
527 * Sync write()
528 * Function returns
529 * >=0 : numer of bytes written.
530 * -errno : An error occured.
531 */
183451cf 532EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
84004dbf
RS
533
534
535/*
536 * LSEEK()
537 */
538/*
539 * Async lseek()
540 *
541 * Function returns
542 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
543 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
544 *
545 * When the callback is invoked, status indicates the result:
546 * >=0 : Success.
183451cf 547 * data is uint64_t * for the current position.
84004dbf
RS
548 * -errno : An error occured.
549 * data is the error string.
550 */
1f1b6cb0 551EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, nfs_cb cb, void *private_data);
84004dbf
RS
552/*
553 * Sync lseek()
554 * Function returns
555 * >=0 : numer of bytes read.
556 * -errno : An error occured.
557 */
1f1b6cb0 558EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, uint64_t *current_offset);
84004dbf
RS
559
560
561/*
562 * FSYNC()
563 */
564/*
565 * Async fsync()
566 *
567 * Function returns
568 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
569 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
570 *
571 * When the callback is invoked, status indicates the result:
572 * 0 : Success.
573 * -errno : An error occured.
574 * data is the error string.
575 */
66ad6d84 576EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
84004dbf
RS
577/*
578 * Sync fsync()
579 * Function returns
580 * 0 : Success
581 * -errno : An error occured.
582 */
66ad6d84 583EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
84004dbf
RS
584
585
586
587/*
588 * TRUNCATE()
589 */
590/*
591 * Async truncate()
592 *
593 * Function returns
594 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
595 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
596 *
597 * When the callback is invoked, status indicates the result:
598 * 0 : Success.
599 * -errno : An error occured.
600 * data is the error string.
601 */
183451cf 602EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
84004dbf
RS
603/*
604 * Sync truncate()
605 * Function returns
606 * 0 : Success
607 * -errno : An error occured.
608 */
183451cf 609EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
84004dbf
RS
610
611
612
613/*
614 * FTRUNCATE()
615 */
616/*
617 * Async ftruncate()
618 *
619 * Function returns
620 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
621 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
622 *
623 * When the callback is invoked, status indicates the result:
624 * 0 : Success.
625 * -errno : An error occured.
626 * data is the error string.
627 */
183451cf 628EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
84004dbf
RS
629/*
630 * Sync ftruncate()
631 * Function returns
632 * 0 : Success
633 * -errno : An error occured.
634 */
183451cf 635EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
84004dbf
RS
636
637
638
639
640
641
642/*
643 * MKDIR()
644 */
645/*
646 * Async mkdir()
647 *
648 * Function returns
649 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
650 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
651 *
652 * When the callback is invoked, status indicates the result:
653 * 0 : Success.
654 * -errno : An error occured.
655 * data is the error string.
656 */
66ad6d84 657EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
658/*
659 * Sync mkdir()
660 * Function returns
661 * 0 : Success
662 * -errno : An error occured.
663 */
66ad6d84 664EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
84004dbf
RS
665
666
667
668/*
669 * RMDIR()
670 */
671/*
672 * Async rmdir()
673 *
674 * Function returns
675 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
676 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
677 *
678 * When the callback is invoked, status indicates the result:
679 * 0 : Success.
680 * -errno : An error occured.
681 * data is the error string.
682 */
66ad6d84 683EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
684/*
685 * Sync rmdir()
686 * Function returns
687 * 0 : Success
688 * -errno : An error occured.
689 */
66ad6d84 690EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
84004dbf
RS
691
692
693
694
695/*
696 * CREAT()
697 */
698/*
699 * Async creat()
700 *
701 * Function returns
702 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
703 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
704 *
705 * When the callback is invoked, status indicates the result:
706 * 0 : Success.
707 * data is a struct *nfsfh;
708 * -errno : An error occured.
709 * data is the error string.
710 */
66ad6d84 711EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
712/*
713 * Sync creat()
714 * Function returns
715 * 0 : Success
716 * -errno : An error occured.
717 */
66ad6d84 718EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
84004dbf 719
037a1061
RL
720/*
721 * Async create()
722 *
723 * Same as nfs_creat_async but allows passing flags:
724 * O_APPEND
725 * O_SYNC
726 * O_EXCL
370c59e3 727 * O_TRUNC
037a1061
RL
728 *
729 * Function returns
730 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
731 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
732 *
733 * When the callback is invoked, status indicates the result:
734 * 0 : Success.
735 * data is a struct *nfsfh;
736 * -errno : An error occured.
737 * data is the error string.
738 */
739EXTERN int nfs_create_async(struct nfs_context *nfs, const char *path, int flags, int mode, nfs_cb cb, void *private_data);
740/*
741 * Sync create()
742 * Function returns
743 * 0 : Success
744 * -errno : An error occured.
745 */
746EXTERN int nfs_create(struct nfs_context *nfs, const char *path, int flags, int mode, struct nfsfh **nfsfh);
747
84004dbf 748
1ec6b50a
RS
749/*
750 * MKNOD()
751 */
752/*
753 * Async mknod()
754 *
755 * Function returns
756 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
757 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
758 *
759 * When the callback is invoked, status indicates the result:
760 * 0 : Success.
761 * -errno : An error occured.
762 * data is the error string.
763 */
764EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
765/*
766 * Sync mknod()
767 * Function returns
768 * 0 : Success
769 * -errno : An error occured.
770 */
771EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
84004dbf
RS
772
773
774
775/*
776 * UNLINK()
777 */
778/*
779 * Async unlink()
780 *
781 * Function returns
782 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
783 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
784 *
785 * When the callback is invoked, status indicates the result:
786 * 0 : Success.
787 * data is NULL
788 * -errno : An error occured.
789 * data is the error string.
790 */
66ad6d84 791EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
792/*
793 * Sync unlink()
794 * Function returns
795 * 0 : Success
796 * -errno : An error occured.
797 */
66ad6d84 798EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
84004dbf
RS
799
800
801
802
803/*
804 * OPENDIR()
805 */
806struct nfsdir;
807/*
808 * Async opendir()
809 *
810 * Function returns
811 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
812 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
813 *
814 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
815 *
816 * When the callback is invoked, status indicates the result:
817 * 0 : Success.
818 * data is struct nfsdir *
819 * -errno : An error occured.
820 * data is the error string.
821 */
66ad6d84 822EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
823/*
824 * Sync opendir()
825 * Function returns
826 * 0 : Success
827 * -errno : An error occured.
828 */
66ad6d84 829EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
84004dbf
RS
830
831
832
833/*
834 * READDIR()
835 */
836struct nfsdirent {
837 struct nfsdirent *next;
838 char *name;
839 uint64_t inode;
0804e67d 840
7bda8bad
RS
841 /* Some extra fields we get for free through the READDIRPLUS3 call.
842 You need libnfs-raw-nfs.h for type/mode constants */
0804e67d
RS
843 uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
844 uint32_t mode;
845 uint64_t size;
846 struct timeval atime;
847 struct timeval mtime;
848 struct timeval ctime;
7bda8bad
RS
849 uint32_t uid;
850 uint32_t gid;
390ff38a 851 uint32_t nlink;
fc08ac45
RL
852 uint64_t dev;
853 uint64_t rdev;
854 uint64_t blksize;
855 uint64_t blocks;
856 uint64_t used;
857 uint32_t atime_nsec;
858 uint32_t mtime_nsec;
859 uint32_t ctime_nsec;
84004dbf
RS
860};
861/*
862 * nfs_readdir() never blocks, so no special sync/async versions are available
863 */
66ad6d84 864EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
84004dbf
RS
865
866
867
868/*
f893b680 869 * CLOSEDIR()
84004dbf
RS
870 */
871/*
872 * nfs_closedir() never blocks, so no special sync/async versions are available
873 */
66ad6d84 874EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
84004dbf
RS
875
876
f893b680
RS
877/*
878 * CHDIR()
879 */
880/*
881 * Async chdir(<path>)
882 *
883 * Function returns
884 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
885 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
886 *
887 * When the callback is invoked, status indicates the result:
888 * 0 : Success.
889 * data is NULL;
890 * -errno : An error occured.
891 * data is the error string.
892 */
893EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
894/*
895 * Sync chdir(<path>)
896 * Function returns
897 * 0 : The operation was successfull.
898 * -errno : The command failed.
899 */
900EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
901
902/*
903 * GETCWD()
904 */
905/*
906 * nfs_getcwd() never blocks, so no special sync/async versions are available
907 */
908/*
909 * Sync getcwd()
910 * This function returns a pointer to the current working directory.
911 * This pointer is only stable until the next [f]chdir or when the
912 * context is destroyed.
913 *
914 * Function returns
915 * 0 : The operation was successfull and *cwd is filled in.
916 * -errno : The command failed.
917 */
918EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
919
84004dbf
RS
920
921/*
922 * STATVFS()
923 */
924/*
925 * Async statvfs(<dirname>)
926 * Function returns
927 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
928 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
929 *
930 * When the callback is invoked, status indicates the result:
931 * 0 : Success.
932 * data is struct statvfs *
933 * -errno : An error occured.
934 * data is the error string.
935 */
936struct statvfs;
66ad6d84 937EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
938/*
939 * Sync statvfs(<dirname>)
940 * Function returns
941 * 0 : The operation was successfull.
942 * -errno : The command failed.
943 */
66ad6d84 944EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
84004dbf
RS
945
946
947/*
948 * READLINK()
949 */
950/*
951 * Async readlink(<name>)
952 * Function returns
953 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
954 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
955 *
956 * When the callback is invoked, status indicates the result:
957 * 0 : Success.
958 * data is a char *
959 * data is only valid during the callback and is automatically freed when the callback returns.
960 * -errno : An error occured.
961 * data is the error string.
962 */
963struct statvfs;
66ad6d84 964EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
84004dbf
RS
965/*
966 * Sync readlink(<name>)
967 * Function returns
968 * 0 : The operation was successfull.
969 * -errno : The command failed.
970 */
66ad6d84 971EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
84004dbf
RS
972
973
974
975/*
976 * CHMOD()
977 */
978/*
979 * Async chmod(<name>)
980 * Function returns
981 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
982 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
983 *
984 * When the callback is invoked, status indicates the result:
985 * 0 : Success.
986 * data is NULL
987 * -errno : An error occured.
988 * data is the error string.
989 */
66ad6d84 990EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
991/*
992 * Sync chmod(<name>)
993 * Function returns
994 * 0 : The operation was successfull.
995 * -errno : The command failed.
996 */
66ad6d84 997EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
84004dbf
RS
998
999
1000
1001/*
1002 * FCHMOD()
1003 */
1004/*
1005 * Async fchmod(<handle>)
1006 * Function returns
1007 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1008 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1009 *
1010 * When the callback is invoked, status indicates the result:
1011 * 0 : Success.
1012 * data is NULL
1013 * -errno : An error occured.
1014 * data is the error string.
1015 */
66ad6d84 1016EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
1017/*
1018 * Sync fchmod(<handle>)
1019 * Function returns
1020 * 0 : The operation was successfull.
1021 * -errno : The command failed.
1022 */
66ad6d84 1023EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
84004dbf
RS
1024
1025
1026
1027/*
1028 * CHOWN()
1029 */
1030/*
1031 * Async chown(<name>)
1032 * Function returns
1033 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1034 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1035 *
1036 * When the callback is invoked, status indicates the result:
1037 * 0 : Success.
1038 * data is NULL
1039 * -errno : An error occured.
1040 * data is the error string.
1041 */
66ad6d84 1042EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
84004dbf
RS
1043/*
1044 * Sync chown(<name>)
1045 * Function returns
1046 * 0 : The operation was successfull.
1047 * -errno : The command failed.
1048 */
66ad6d84 1049EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
5935a28a
RL
1050/*
1051 * Async chown(<name>)
1052 *
1053 * Like chown except if the destination is a symbolic link, it acts on the
1054 * symbolic link itself.
1055 *
1056 * Function returns
1057 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1058 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1059 *
1060 * When the callback is invoked, status indicates the result:
1061 * 0 : Success.
1062 * data is NULL
1063 * -errno : An error occured.
1064 * data is the error string.
1065 */
1066EXTERN int nfs_lchown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
1067/*
1068 * Sync chown(<name>)
1069 *
1070 * Like chown except if the destination is a symbolic link, it acts on the
1071 * symbolic link itself.
1072 *
1073 * Function returns
1074 * 0 : The operation was successfull.
1075 * -errno : The command failed.
1076 */
1077EXTERN int nfs_lchown(struct nfs_context *nfs, const char *path, int uid, int gid);
84004dbf
RS
1078
1079
1080
1081/*
1082 * FCHOWN()
1083 */
1084/*
1085 * Async fchown(<handle>)
1086 * Function returns
1087 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1088 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1089 *
1090 * When the callback is invoked, status indicates the result:
1091 * 0 : Success.
1092 * data is NULL
1093 * -errno : An error occured.
1094 * data is the error string.
1095 */
66ad6d84 1096EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
84004dbf
RS
1097/*
1098 * Sync fchown(<handle>)
1099 * Function returns
1100 * 0 : The operation was successfull.
1101 * -errno : The command failed.
1102 */
66ad6d84 1103EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
84004dbf
RS
1104
1105
1106
1107
1108/*
1109 * UTIMES()
1110 */
1111/*
1112 * Async utimes(<path>)
1113 * Function returns
1114 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1115 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1116 *
1117 * When the callback is invoked, status indicates the result:
1118 * 0 : Success.
1119 * data is NULL
1120 * -errno : An error occured.
1121 * data is the error string.
1122 */
66ad6d84 1123EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
84004dbf
RS
1124/*
1125 * Sync utimes(<path>)
1126 * Function returns
1127 * 0 : The operation was successfull.
1128 * -errno : The command failed.
1129 */
66ad6d84 1130EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
84004dbf
RS
1131
1132
1133/*
1134 * UTIME()
1135 */
1136/*
1137 * Async utime(<path>)
1138 * Function returns
1139 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1140 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1141 *
1142 * When the callback is invoked, status indicates the result:
1143 * 0 : Success.
1144 * data is NULL
1145 * -errno : An error occured.
1146 * data is the error string.
1147 */
1148struct utimbuf;
66ad6d84 1149EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
84004dbf
RS
1150/*
1151 * Sync utime(<path>)
1152 * Function returns
1153 * 0 : The operation was successfull.
1154 * -errno : The command failed.
1155 */
66ad6d84 1156EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
84004dbf
RS
1157
1158
1159
1160
1161/*
1162 * ACCESS()
1163 */
1164/*
1165 * Async access(<path>)
1166 * Function returns
1167 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1168 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1169 *
1170 * When the callback is invoked, status indicates the result:
1171 * 0 : Success.
1172 * data is NULL
1173 * -errno : An error occured.
1174 * data is the error string.
1175 */
66ad6d84 1176EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
84004dbf
RS
1177/*
1178 * Sync access(<path>)
1179 * Function returns
1180 * 0 : The operation was successfull.
1181 * -errno : The command failed.
1182 */
66ad6d84 1183EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
84004dbf
RS
1184
1185
1186
1187
1188/*
1189 * SYMLINK()
1190 */
1191/*
1192 * Async symlink(<path>)
1193 * Function returns
1194 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1195 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1196 *
1197 * When the callback is invoked, status indicates the result:
1198 * 0 : Success.
1199 * data is NULL
1200 * -errno : An error occured.
1201 * data is the error string.
1202 */
66ad6d84 1203EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1204/*
1205 * Sync symlink(<path>)
1206 * Function returns
1207 * 0 : The operation was successfull.
1208 * -errno : The command failed.
1209 */
66ad6d84 1210EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1211
1212
1213/*
1214 * RENAME()
1215 */
1216/*
1217 * Async rename(<oldpath>, <newpath>)
1218 * Function returns
1219 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1220 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1221 *
1222 * When the callback is invoked, status indicates the result:
1223 * 0 : Success.
1224 * data is NULL
1225 * -errno : An error occured.
1226 * data is the error string.
1227 */
66ad6d84 1228EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1229/*
1230 * Sync rename(<oldpath>, <newpath>)
1231 * Function returns
1232 * 0 : The operation was successfull.
1233 * -errno : The command failed.
1234 */
66ad6d84 1235EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1236
1237
1238
1239/*
1240 * LINK()
1241 */
1242/*
1243 * Async link(<oldpath>, <newpath>)
1244 * Function returns
1245 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1246 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1247 *
1248 * When the callback is invoked, status indicates the result:
1249 * 0 : Success.
1250 * data is NULL
1251 * -errno : An error occured.
1252 * data is the error string.
1253 */
66ad6d84 1254EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
84004dbf
RS
1255/*
1256 * Sync link(<oldpath>, <newpath>)
1257 * Function returns
1258 * 0 : The operation was successfull.
1259 * -errno : The command failed.
1260 */
66ad6d84 1261EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
84004dbf
RS
1262
1263
7f0242ca
RS
1264/*
1265 * GETEXPORTS()
1266 */
1267/*
1268 * Async getexports()
1269 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1270 * returned structures.
1271 *
1272 * This function will return the list of exports from an NFS server.
1273 *
1274 * Function returns
1275 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1276 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1277 *
1278 * When the callback is invoked, status indicates the result:
1279 * 0 : Success.
1280 * data is a pointer to an exports pointer:
1281 * exports export = *(exports *)data;
1282 * -errno : An error occured.
1283 * data is the error string.
1284 */
66ad6d84 1285EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
df5af25f
RS
1286/*
1287 * Sync getexports(<server>)
1288 * Function returns
1289 * NULL : something failed
1290 * exports export : a linked list of exported directories
52014ebf 1291 *
df5af25f
RS
1292 * returned data must be freed by calling mount_free_export_list(exportnode);
1293 */
66ad6d84 1294EXTERN struct exportnode *mount_getexports(const char *server);
7f0242ca 1295
66ad6d84 1296EXTERN void mount_free_export_list(struct exportnode *exports);
7f0242ca 1297
84004dbf
RS
1298
1299//qqq replace later with lseek(cur, 0)
183451cf 1300uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
552c7665
RS
1301
1302
1303
9c4212bf
RS
1304
1305
552c7665
RS
1306struct nfs_server_list {
1307 struct nfs_server_list *next;
1308 char *addr;
1309};
1310
9c4212bf
RS
1311/*
1312 * Sync find_local_servers(<server>)
1313 * This function will probe all local networks for NFS server. This function will
1314 * block for one second while awaiting for all nfs servers to respond.
1315 *
1316 * Function returns
1317 * NULL : something failed
1318 *
1319 * struct nfs_server_list : a linked list of all discovered servers
52014ebf 1320 *
9c4212bf
RS
1321 * returned data must be freed by nfs_free_srvr_list(srv);
1322 */
552c7665
RS
1323struct nfs_server_list *nfs_find_local_servers(void);
1324void free_nfs_srvr_list(struct nfs_server_list *srv);
52014ebf 1325
d48be00c
AR
1326#ifdef __cplusplus
1327}
1328#endif
1329
52014ebf 1330#endif /* !_LIBNFS_H_ */