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