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