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