libnfs: Add lutimes
[deb_libnfs.git] / include / nfsc / libnfs.h
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 */
20
21 #ifndef _LIBNFS_H_
22 #define _LIBNFS_H_
23
24 #include <stdint.h>
25 #if defined(ANDROID)
26 #include <sys/time.h>
27 #endif
28 #if defined(AROS)
29 #include <sys/time.h>
30 #endif
31 #if defined(__APPLE__) && defined(__MACH__)
32 #include <sys/time.h>
33 #endif
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #define LIBNFS_FEATURE_READAHEAD
40 #define NFS_BLKSIZE 4096
41
42 struct nfs_context;
43 struct rpc_context;
44
45 struct nfs_url {
46 char *server;
47 char *path;
48 char *file;
49 };
50
51 #if defined(WIN32)
52 #define EXTERN __declspec( dllexport )
53 #else
54 #define EXTERN
55 #endif
56
57 #if defined(WIN32)
58 struct 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;
67 uint32_t f_fsid;
68 uint32_t f_flag;
69 uint32_t f_namemax;
70 };
71 struct 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
80 /*
81 * Used for interfacing the async version of the api into an external eventsystem
82 */
83 EXTERN int nfs_get_fd(struct nfs_context *nfs);
84 EXTERN int nfs_which_events(struct nfs_context *nfs);
85 EXTERN int nfs_service(struct nfs_context *nfs, int revents);
86 EXTERN int nfs_queue_length(struct nfs_context *nfs);
87
88 /*
89 * Used if you need different credentials than the default for the current user.
90 */
91 struct AUTH;
92 EXTERN void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
93
94 /*
95 * When an operation failed, this function can extract a detailed error string.
96 */
97 EXTERN char *nfs_get_error(struct nfs_context *nfs);
98
99
100 /*
101 * Callback for all ASYNC nfs functions
102 */
103 typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
104
105 /*
106 * Callback for all ASYNC rpc functions
107 */
108 typedef void (*rpc_cb)(struct rpc_context *rpc, int status, void *data, void *private_data);
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 */
121 EXTERN struct nfs_context *nfs_init_context(void);
122 /*
123 * Destroy an nfs context.
124 */
125 EXTERN void nfs_destroy_context(struct nfs_context *nfs);
126
127
128 /*
129 * URL parsing functions.
130 * These functions all parse a URL of the form
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 */
146 /*
147 * Parse a complete NFS URL including, server, path and
148 * filename. Fail if any component is missing.
149 */
150 EXTERN 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 */
156 EXTERN 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 */
162 EXTERN 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 */
168 EXTERN void nfs_destroy_url(struct nfs_url *url);
169
170
171 struct nfsfh;
172
173 /*
174 * Get the maximum supported READ3 size by the server
175 */
176 EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
177
178 /*
179 * Get the maximum supported WRITE3 size by the server
180 */
181 EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
182
183 /*
184 * MODIFY CONNECT PARAMTERS
185 */
186
187 EXTERN void nfs_set_tcp_syncnt(struct nfs_context *nfs, int v);
188 EXTERN void nfs_set_uid(struct nfs_context *nfs, int uid);
189 EXTERN void nfs_set_gid(struct nfs_context *nfs, int gid);
190 EXTERN void nfs_set_readahead(struct nfs_context *nfs, uint32_t v);
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 */
207 EXTERN int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *exportname, nfs_cb cb, void *private_data);
208 /*
209 * Sync nfs mount.
210 * Function returns
211 * 0 : The operation was successfull.
212 * -errno : The command failed.
213 */
214 EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *exportname);
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 */
234 /* This function is deprecated. Use nfs_stat64_async() instead */
235 struct stat;
236 EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
237 /*
238 * Sync stat(<filename>)
239 * Function returns
240 * 0 : The operation was successfull.
241 * -errno : The command failed.
242 */
243 /* This function is deprecated. Use nfs_stat64() instead */
244 #ifdef WIN32
245 EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
246 #else
247 EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
248 #endif
249
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 */
259 struct 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 uint64_t nfs_atime_nsec;
274 uint64_t nfs_mtime_nsec;
275 uint64_t nfs_ctime_nsec;
276 uint64_t nfs_used;
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 */
291 EXTERN 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 */
298 EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
299
300 /*
301 * Async stat(<filename>)
302 *
303 * Like stat except if the destination is a symbolic link, it acts on the
304 * symbolic link itself.
305 *
306 * Function returns
307 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
308 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
309 *
310 * When the callback is invoked, status indicates the result:
311 * 0 : Success.
312 * data is struct nfs_stat_64 *
313 * -errno : An error occured.
314 * data is the error string.
315 */
316 EXTERN int nfs_lstat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
317 /*
318 * Sync stat(<filename>)
319 *
320 * Like stat except if the destination is a symbolic link, it acts on the
321 * symbolic link itself.
322 *
323 * Function returns
324 * 0 : The operation was successfull.
325 * -errno : The command failed.
326 */
327 EXTERN int nfs_lstat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
328
329 /*
330 * FSTAT()
331 */
332 /*
333 * Async fstat(nfsfh *)
334 * Function returns
335 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
336 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
337 *
338 * When the callback is invoked, status indicates the result:
339 * 0 : Success.
340 * data is struct stat *
341 * -errno : An error occured.
342 * data is the error string.
343 */
344 /* This function is deprecated. Use nfs_fstat64_async() instead */
345 EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
346 /*
347 * Sync fstat(nfsfh *)
348 * Function returns
349 * 0 : The operation was successfull.
350 * -errno : The command failed.
351 */
352 #ifdef WIN32
353 EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat64 *st);
354 #else
355 EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
356 #endif
357
358 /* nfs_fstat64
359 * 64 bit version of fstat. All fields are always 64bit.
360 * Use these functions instead of nfs_fstat[_async](), especially if you
361 * have weird stat structures.
362 */
363 /*
364 * FSTAT()
365 */
366 /*
367 * Async fstat(nfsfh *)
368 * Function returns
369 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
370 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
371 *
372 * When the callback is invoked, status indicates the result:
373 * 0 : Success.
374 * data is struct stat *
375 * -errno : An error occured.
376 * data is the error string.
377 */
378 EXTERN int nfs_fstat64_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
379 /*
380 * Sync fstat(nfsfh *)
381 * Function returns
382 * 0 : The operation was successfull.
383 * -errno : The command failed.
384 */
385 EXTERN int nfs_fstat64(struct nfs_context *nfs, struct nfsfh *nfsfh, struct nfs_stat_64 *st);
386
387
388
389 /*
390 * OPEN()
391 */
392 /*
393 * Async open(<filename>)
394 *
395 * mode is a combination of the flags :
396 * O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND, O_TRUNC
397 *
398 * Function returns
399 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
400 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
401 *
402 * Supported flags are
403 * O_APPEND
404 * O_RDONLY
405 * O_WRONLY
406 * O_RDWR
407 * O_SYNC
408 * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
409 *
410 * When the callback is invoked, status indicates the result:
411 * 0 : Success.
412 * data is a struct *nfsfh;
413 * The nfsfh is close using nfs_close().
414 * -errno : An error occured.
415 * data is the error string.
416 */
417 EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
418 /*
419 * Sync open(<filename>)
420 * Function returns
421 * 0 : The operation was successfull. *nfsfh is filled in.
422 * -errno : The command failed.
423 */
424 EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
425
426
427
428
429 /*
430 * CLOSE
431 */
432 /*
433 * Async close(nfsfh)
434 *
435 * Function returns
436 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
437 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
438 *
439 * When the callback is invoked, status indicates the result:
440 * 0 : Success.
441 * data is NULL.
442 * -errno : An error occured.
443 * data is the error string.
444 */
445 EXTERN int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
446 /*
447 * Sync close(nfsfh)
448 * Function returns
449 * 0 : The operation was successfull.
450 * -errno : The command failed.
451 */
452 EXTERN int nfs_close(struct nfs_context *nfs, struct nfsfh *nfsfh);
453
454
455 /*
456 * PREAD()
457 */
458 /*
459 * Async pread()
460 *
461 * Function returns
462 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
463 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
464 *
465 * When the callback is invoked, status indicates the result:
466 * >=0 : Success.
467 * status is numer of bytes read.
468 * data is a pointer to the returned data.
469 * -errno : An error occured.
470 * data is the error string.
471 */
472 EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, nfs_cb cb, void *private_data);
473 /*
474 * Sync pread()
475 * Function returns
476 * >=0 : numer of bytes read.
477 * -errno : An error occured.
478 */
479 EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
480
481
482
483 /*
484 * READ()
485 */
486 /*
487 * Async read()
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 read.
496 * data is a pointer to the returned data.
497 * -errno : An error occured.
498 * data is the error string.
499 */
500 EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, nfs_cb cb, void *private_data);
501 /*
502 * Sync read()
503 * Function returns
504 * >=0 : numer of bytes read.
505 * -errno : An error occured.
506 */
507 EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
508
509
510
511
512 /*
513 * PWRITE()
514 */
515 /*
516 * Async pwrite()
517 *
518 * Function returns
519 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
520 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
521 *
522 * When the callback is invoked, status indicates the result:
523 * >=0 : Success.
524 * status is numer of bytes written.
525 * -errno : An error occured.
526 * data is the error string.
527 */
528 EXTERN 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);
529 /*
530 * Sync pwrite()
531 * Function returns
532 * >=0 : numer of bytes written.
533 * -errno : An error occured.
534 */
535 EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, uint64_t count, char *buf);
536
537
538 /*
539 * WRITE()
540 */
541 /*
542 * Async write()
543 *
544 * Function returns
545 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
546 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
547 *
548 * When the callback is invoked, status indicates the result:
549 * >=0 : Success.
550 * status is numer of bytes written.
551 * -errno : An error occured.
552 * data is the error string.
553 */
554 EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf, nfs_cb cb, void *private_data);
555 /*
556 * Sync write()
557 * Function returns
558 * >=0 : numer of bytes written.
559 * -errno : An error occured.
560 */
561 EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count, char *buf);
562
563
564 /*
565 * LSEEK()
566 */
567 /*
568 * Async lseek()
569 *
570 * Function returns
571 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
572 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
573 *
574 * When the callback is invoked, status indicates the result:
575 * >=0 : Success.
576 * data is uint64_t * for the current position.
577 * -errno : An error occured.
578 * data is the error string.
579 */
580 EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, nfs_cb cb, void *private_data);
581 /*
582 * Sync lseek()
583 * Function returns
584 * >=0 : numer of bytes read.
585 * -errno : An error occured.
586 */
587 EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, uint64_t *current_offset);
588
589
590 /*
591 * FSYNC()
592 */
593 /*
594 * Async fsync()
595 *
596 * Function returns
597 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
598 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
599 *
600 * When the callback is invoked, status indicates the result:
601 * 0 : Success.
602 * -errno : An error occured.
603 * data is the error string.
604 */
605 EXTERN int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
606 /*
607 * Sync fsync()
608 * Function returns
609 * 0 : Success
610 * -errno : An error occured.
611 */
612 EXTERN int nfs_fsync(struct nfs_context *nfs, struct nfsfh *nfsfh);
613
614
615
616 /*
617 * TRUNCATE()
618 */
619 /*
620 * Async truncate()
621 *
622 * Function returns
623 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
624 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
625 *
626 * When the callback is invoked, status indicates the result:
627 * 0 : Success.
628 * -errno : An error occured.
629 * data is the error string.
630 */
631 EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, uint64_t length, nfs_cb cb, void *private_data);
632 /*
633 * Sync truncate()
634 * Function returns
635 * 0 : Success
636 * -errno : An error occured.
637 */
638 EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, uint64_t length);
639
640
641
642 /*
643 * FTRUNCATE()
644 */
645 /*
646 * Async ftruncate()
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 */
657 EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length, nfs_cb cb, void *private_data);
658 /*
659 * Sync ftruncate()
660 * Function returns
661 * 0 : Success
662 * -errno : An error occured.
663 */
664 EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t length);
665
666
667
668
669
670
671 /*
672 * MKDIR()
673 */
674 /*
675 * Async mkdir()
676 *
677 * Function returns
678 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
679 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
680 *
681 * When the callback is invoked, status indicates the result:
682 * 0 : Success.
683 * -errno : An error occured.
684 * data is the error string.
685 */
686 EXTERN int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
687 /*
688 * Sync mkdir()
689 * Function returns
690 * 0 : Success
691 * -errno : An error occured.
692 */
693 EXTERN int nfs_mkdir(struct nfs_context *nfs, const char *path);
694
695
696
697 /*
698 * RMDIR()
699 */
700 /*
701 * Async rmdir()
702 *
703 * Function returns
704 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
705 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
706 *
707 * When the callback is invoked, status indicates the result:
708 * 0 : Success.
709 * -errno : An error occured.
710 * data is the error string.
711 */
712 EXTERN int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
713 /*
714 * Sync rmdir()
715 * Function returns
716 * 0 : Success
717 * -errno : An error occured.
718 */
719 EXTERN int nfs_rmdir(struct nfs_context *nfs, const char *path);
720
721
722
723
724 /*
725 * CREAT()
726 */
727 /*
728 * Async creat()
729 *
730 * Function returns
731 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
732 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
733 *
734 * When the callback is invoked, status indicates the result:
735 * 0 : Success.
736 * data is a struct *nfsfh;
737 * -errno : An error occured.
738 * data is the error string.
739 */
740 EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
741 /*
742 * Sync creat()
743 * Function returns
744 * 0 : Success
745 * -errno : An error occured.
746 */
747 EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
748
749 /*
750 * Async create()
751 *
752 * Same as nfs_creat_async but allows passing flags:
753 * O_APPEND
754 * O_SYNC
755 * O_EXCL
756 * O_TRUNC
757 *
758 * Function returns
759 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
760 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
761 *
762 * When the callback is invoked, status indicates the result:
763 * 0 : Success.
764 * data is a struct *nfsfh;
765 * -errno : An error occured.
766 * data is the error string.
767 */
768 EXTERN int nfs_create_async(struct nfs_context *nfs, const char *path, int flags, int mode, nfs_cb cb, void *private_data);
769 /*
770 * Sync create()
771 * Function returns
772 * 0 : Success
773 * -errno : An error occured.
774 */
775 EXTERN int nfs_create(struct nfs_context *nfs, const char *path, int flags, int mode, struct nfsfh **nfsfh);
776
777
778 /*
779 * MKNOD()
780 */
781 /*
782 * Async mknod()
783 *
784 * Function returns
785 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
786 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
787 *
788 * When the callback is invoked, status indicates the result:
789 * 0 : Success.
790 * -errno : An error occured.
791 * data is the error string.
792 */
793 EXTERN int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev, nfs_cb cb, void *private_data);
794 /*
795 * Sync mknod()
796 * Function returns
797 * 0 : Success
798 * -errno : An error occured.
799 */
800 EXTERN int nfs_mknod(struct nfs_context *nfs, const char *path, int mode, int dev);
801
802
803
804 /*
805 * UNLINK()
806 */
807 /*
808 * Async unlink()
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 the callback is invoked, status indicates the result:
815 * 0 : Success.
816 * data is NULL
817 * -errno : An error occured.
818 * data is the error string.
819 */
820 EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
821 /*
822 * Sync unlink()
823 * Function returns
824 * 0 : Success
825 * -errno : An error occured.
826 */
827 EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path);
828
829
830
831
832 /*
833 * OPENDIR()
834 */
835 struct nfsdir;
836 /*
837 * Async opendir()
838 *
839 * Function returns
840 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
841 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
842 *
843 * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
844 *
845 * When the callback is invoked, status indicates the result:
846 * 0 : Success.
847 * data is struct nfsdir *
848 * -errno : An error occured.
849 * data is the error string.
850 */
851 EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
852 /*
853 * Sync opendir()
854 * Function returns
855 * 0 : Success
856 * -errno : An error occured.
857 */
858 EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
859
860
861
862 /*
863 * READDIR()
864 */
865 struct nfsdirent {
866 struct nfsdirent *next;
867 char *name;
868 uint64_t inode;
869
870 /* Some extra fields we get for free through the READDIRPLUS3 call.
871 You need libnfs-raw-nfs.h for type/mode constants */
872 uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */
873 uint32_t mode;
874 uint64_t size;
875 struct timeval atime;
876 struct timeval mtime;
877 struct timeval ctime;
878 uint32_t uid;
879 uint32_t gid;
880 uint32_t nlink;
881 uint64_t dev;
882 uint64_t rdev;
883 uint64_t blksize;
884 uint64_t blocks;
885 uint64_t used;
886 uint32_t atime_nsec;
887 uint32_t mtime_nsec;
888 uint32_t ctime_nsec;
889 };
890 /*
891 * nfs_readdir() never blocks, so no special sync/async versions are available
892 */
893 EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
894
895
896
897 /*
898 * CLOSEDIR()
899 */
900 /*
901 * nfs_closedir() never blocks, so no special sync/async versions are available
902 */
903 EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
904
905
906 /*
907 * CHDIR()
908 */
909 /*
910 * Async chdir(<path>)
911 *
912 * Function returns
913 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
914 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
915 *
916 * When the callback is invoked, status indicates the result:
917 * 0 : Success.
918 * data is NULL;
919 * -errno : An error occured.
920 * data is the error string.
921 */
922 EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
923 /*
924 * Sync chdir(<path>)
925 * Function returns
926 * 0 : The operation was successfull.
927 * -errno : The command failed.
928 */
929 EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
930
931 /*
932 * GETCWD()
933 */
934 /*
935 * nfs_getcwd() never blocks, so no special sync/async versions are available
936 */
937 /*
938 * Sync getcwd()
939 * This function returns a pointer to the current working directory.
940 * This pointer is only stable until the next [f]chdir or when the
941 * context is destroyed.
942 *
943 * Function returns
944 * 0 : The operation was successfull and *cwd is filled in.
945 * -errno : The command failed.
946 */
947 EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
948
949
950 /*
951 * STATVFS()
952 */
953 /*
954 * Async statvfs(<dirname>)
955 * Function returns
956 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
957 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
958 *
959 * When the callback is invoked, status indicates the result:
960 * 0 : Success.
961 * data is struct statvfs *
962 * -errno : An error occured.
963 * data is the error string.
964 */
965 struct statvfs;
966 EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
967 /*
968 * Sync statvfs(<dirname>)
969 * Function returns
970 * 0 : The operation was successfull.
971 * -errno : The command failed.
972 */
973 EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
974
975
976 /*
977 * READLINK()
978 */
979 /*
980 * Async readlink(<name>)
981 * Function returns
982 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
983 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
984 *
985 * When the callback is invoked, status indicates the result:
986 * 0 : Success.
987 * data is a char *
988 * data is only valid during the callback and is automatically freed when the callback returns.
989 * -errno : An error occured.
990 * data is the error string.
991 */
992 struct statvfs;
993 EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
994 /*
995 * Sync readlink(<name>)
996 * Function returns
997 * 0 : The operation was successfull.
998 * -errno : The command failed.
999 */
1000 EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
1001
1002
1003
1004 /*
1005 * CHMOD()
1006 */
1007 /*
1008 * Async chmod(<name>)
1009 * Function returns
1010 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1011 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1012 *
1013 * When the callback is invoked, status indicates the result:
1014 * 0 : Success.
1015 * data is NULL
1016 * -errno : An error occured.
1017 * data is the error string.
1018 */
1019 EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
1020 /*
1021 * Sync chmod(<name>)
1022 * Function returns
1023 * 0 : The operation was successfull.
1024 * -errno : The command failed.
1025 */
1026 EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode);
1027
1028
1029
1030 /*
1031 * FCHMOD()
1032 */
1033 /*
1034 * Async fchmod(<handle>)
1035 * Function returns
1036 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1037 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1038 *
1039 * When the callback is invoked, status indicates the result:
1040 * 0 : Success.
1041 * data is NULL
1042 * -errno : An error occured.
1043 * data is the error string.
1044 */
1045 EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
1046 /*
1047 * Sync fchmod(<handle>)
1048 * Function returns
1049 * 0 : The operation was successfull.
1050 * -errno : The command failed.
1051 */
1052 EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
1053
1054
1055
1056 /*
1057 * CHOWN()
1058 */
1059 /*
1060 * Async chown(<name>)
1061 * Function returns
1062 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1063 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1064 *
1065 * When the callback is invoked, status indicates the result:
1066 * 0 : Success.
1067 * data is NULL
1068 * -errno : An error occured.
1069 * data is the error string.
1070 */
1071 EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
1072 /*
1073 * Sync chown(<name>)
1074 * Function returns
1075 * 0 : The operation was successfull.
1076 * -errno : The command failed.
1077 */
1078 EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid);
1079 /*
1080 * Async chown(<name>)
1081 *
1082 * Like chown except if the destination is a symbolic link, it acts on the
1083 * symbolic link itself.
1084 *
1085 * Function returns
1086 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1087 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1088 *
1089 * When the callback is invoked, status indicates the result:
1090 * 0 : Success.
1091 * data is NULL
1092 * -errno : An error occured.
1093 * data is the error string.
1094 */
1095 EXTERN int nfs_lchown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
1096 /*
1097 * Sync chown(<name>)
1098 *
1099 * Like chown except if the destination is a symbolic link, it acts on the
1100 * symbolic link itself.
1101 *
1102 * Function returns
1103 * 0 : The operation was successfull.
1104 * -errno : The command failed.
1105 */
1106 EXTERN int nfs_lchown(struct nfs_context *nfs, const char *path, int uid, int gid);
1107
1108
1109
1110 /*
1111 * FCHOWN()
1112 */
1113 /*
1114 * Async fchown(<handle>)
1115 * Function returns
1116 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1117 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1118 *
1119 * When the callback is invoked, status indicates the result:
1120 * 0 : Success.
1121 * data is NULL
1122 * -errno : An error occured.
1123 * data is the error string.
1124 */
1125 EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
1126 /*
1127 * Sync fchown(<handle>)
1128 * Function returns
1129 * 0 : The operation was successfull.
1130 * -errno : The command failed.
1131 */
1132 EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
1133
1134
1135
1136
1137 /*
1138 * UTIMES()
1139 */
1140 /*
1141 * Async utimes(<path>)
1142 * Function returns
1143 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1144 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1145 *
1146 * When the callback is invoked, status indicates the result:
1147 * 0 : Success.
1148 * data is NULL
1149 * -errno : An error occured.
1150 * data is the error string.
1151 */
1152 EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
1153 /*
1154 * Sync utimes(<path>)
1155 * Function returns
1156 * 0 : The operation was successfull.
1157 * -errno : The command failed.
1158 */
1159 EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times);
1160 /*
1161 * Async utimes(<path>)
1162 *
1163 * Like utimes except if the destination is a symbolic link, it acts on the
1164 * symbolic link itself.
1165 *
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 */
1176 EXTERN int nfs_lutimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
1177 /*
1178 * Sync utimes(<path>)
1179 *
1180 * Like utimes except if the destination is a symbolic link, it acts on the
1181 * symbolic link itself.
1182 *
1183 * Function returns
1184 * 0 : The operation was successfull.
1185 * -errno : The command failed.
1186 */
1187 EXTERN int nfs_lutimes(struct nfs_context *nfs, const char *path, struct timeval *times);
1188
1189
1190 /*
1191 * UTIME()
1192 */
1193 /*
1194 * Async utime(<path>)
1195 * Function returns
1196 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1197 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1198 *
1199 * When the callback is invoked, status indicates the result:
1200 * 0 : Success.
1201 * data is NULL
1202 * -errno : An error occured.
1203 * data is the error string.
1204 */
1205 struct utimbuf;
1206 EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
1207 /*
1208 * Sync utime(<path>)
1209 * Function returns
1210 * 0 : The operation was successfull.
1211 * -errno : The command failed.
1212 */
1213 EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times);
1214
1215
1216
1217
1218 /*
1219 * ACCESS()
1220 */
1221 /*
1222 * Async access(<path>)
1223 * Function returns
1224 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1225 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1226 *
1227 * When the callback is invoked, status indicates the result:
1228 * 0 : Success.
1229 * data is NULL
1230 * -errno : An error occured.
1231 * data is the error string.
1232 */
1233 EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
1234 /*
1235 * Sync access(<path>)
1236 * Function returns
1237 * 0 : The operation was successfull.
1238 * -errno : The command failed.
1239 */
1240 EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode);
1241
1242
1243
1244
1245 /*
1246 * SYMLINK()
1247 */
1248 /*
1249 * Async symlink(<path>)
1250 * Function returns
1251 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1252 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1253 *
1254 * When the callback is invoked, status indicates the result:
1255 * 0 : Success.
1256 * data is NULL
1257 * -errno : An error occured.
1258 * data is the error string.
1259 */
1260 EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1261 /*
1262 * Sync symlink(<path>)
1263 * Function returns
1264 * 0 : The operation was successfull.
1265 * -errno : The command failed.
1266 */
1267 EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1268
1269
1270 /*
1271 * RENAME()
1272 */
1273 /*
1274 * Async rename(<oldpath>, <newpath>)
1275 * Function returns
1276 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1277 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1278 *
1279 * When the callback is invoked, status indicates the result:
1280 * 0 : Success.
1281 * data is NULL
1282 * -errno : An error occured.
1283 * data is the error string.
1284 */
1285 EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1286 /*
1287 * Sync rename(<oldpath>, <newpath>)
1288 * Function returns
1289 * 0 : The operation was successfull.
1290 * -errno : The command failed.
1291 */
1292 EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1293
1294
1295
1296 /*
1297 * LINK()
1298 */
1299 /*
1300 * Async link(<oldpath>, <newpath>)
1301 * Function returns
1302 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1303 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1304 *
1305 * When the callback is invoked, status indicates the result:
1306 * 0 : Success.
1307 * data is NULL
1308 * -errno : An error occured.
1309 * data is the error string.
1310 */
1311 EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
1312 /*
1313 * Sync link(<oldpath>, <newpath>)
1314 * Function returns
1315 * 0 : The operation was successfull.
1316 * -errno : The command failed.
1317 */
1318 EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath);
1319
1320
1321 /*
1322 * GETEXPORTS()
1323 */
1324 /*
1325 * Async getexports()
1326 * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the
1327 * returned structures.
1328 *
1329 * This function will return the list of exports from an NFS server.
1330 *
1331 * Function returns
1332 * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
1333 * <0 : An error occured when trying to set up the operation. The callback will not be invoked.
1334 *
1335 * When the callback is invoked, status indicates the result:
1336 * 0 : Success.
1337 * data is a pointer to an exports pointer:
1338 * exports export = *(exports *)data;
1339 * -errno : An error occured.
1340 * data is the error string.
1341 */
1342 EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data);
1343 /*
1344 * Sync getexports(<server>)
1345 * Function returns
1346 * NULL : something failed
1347 * exports export : a linked list of exported directories
1348 *
1349 * returned data must be freed by calling mount_free_export_list(exportnode);
1350 */
1351 EXTERN struct exportnode *mount_getexports(const char *server);
1352
1353 EXTERN void mount_free_export_list(struct exportnode *exports);
1354
1355
1356 //qqq replace later with lseek(cur, 0)
1357 uint64_t nfs_get_current_offset(struct nfsfh *nfsfh);
1358
1359
1360
1361
1362
1363 struct nfs_server_list {
1364 struct nfs_server_list *next;
1365 char *addr;
1366 };
1367
1368 /*
1369 * Sync find_local_servers(<server>)
1370 * This function will probe all local networks for NFS server. This function will
1371 * block for one second while awaiting for all nfs servers to respond.
1372 *
1373 * Function returns
1374 * NULL : something failed
1375 *
1376 * struct nfs_server_list : a linked list of all discovered servers
1377 *
1378 * returned data must be freed by nfs_free_srvr_list(srv);
1379 */
1380 struct nfs_server_list *nfs_find_local_servers(void);
1381 void free_nfs_srvr_list(struct nfs_server_list *srv);
1382
1383 #ifdef __cplusplus
1384 }
1385 #endif
1386
1387 #endif /* !_LIBNFS_H_ */