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