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