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