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); | |
84004dbf RS |
60 | |
61 | /* | |
62 | * Used if you need different credentials than the default for the current user. | |
63 | */ | |
64 | struct AUTH; | |
66ad6d84 | 65 | EXTERN void nfs_set_auth(struct nfs_context *nfs, struct 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 | */ | |
66ad6d84 | 107 | EXTERN size_t nfs_get_readmax(struct nfs_context *nfs); |
17ef62fa RS |
108 | |
109 | /* | |
110 | * Get the maximum supported WRITE3 size by the server | |
111 | */ | |
66ad6d84 | 112 | EXTERN size_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 | */ | |
66ad6d84 | 268 | EXTERN int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_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 | */ | |
66ad6d84 | 275 | EXTERN int nfs_pread(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_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 | */ | |
66ad6d84 | 296 | EXTERN int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_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 | */ | |
66ad6d84 | 303 | EXTERN int nfs_read(struct nfs_context *nfs, struct nfsfh *nfsfh, size_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 | */ | |
66ad6d84 | 324 | EXTERN int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_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 | */ | |
66ad6d84 | 331 | EXTERN int nfs_pwrite(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_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 | */ | |
66ad6d84 | 350 | EXTERN int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_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 | */ | |
66ad6d84 | 357 | EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, size_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. | |
372 | * data is off_t * for the current position. | |
373 | * -errno : An error occured. | |
374 | * data is the error string. | |
375 | */ | |
66ad6d84 | 376 | EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_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 | */ | |
66ad6d84 | 383 | EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_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 | */ | |
66ad6d84 | 427 | EXTERN int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_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 | */ | |
66ad6d84 | 434 | EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path, off_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 | */ | |
66ad6d84 | 453 | EXTERN int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_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 | */ | |
66ad6d84 | 460 | EXTERN int nfs_ftruncate(struct nfs_context *nfs, struct nfsfh *nfsfh, off_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 | ||
546 | ||
547 | ||
548 | ||
549 | /* | |
550 | * UNLINK() | |
551 | */ | |
552 | /* | |
553 | * Async unlink() | |
554 | * | |
555 | * Function returns | |
556 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
557 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
558 | * | |
559 | * When the callback is invoked, status indicates the result: | |
560 | * 0 : Success. | |
561 | * data is NULL | |
562 | * -errno : An error occured. | |
563 | * data is the error string. | |
564 | */ | |
66ad6d84 | 565 | EXTERN int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); |
84004dbf RS |
566 | /* |
567 | * Sync unlink() | |
568 | * Function returns | |
569 | * 0 : Success | |
570 | * -errno : An error occured. | |
571 | */ | |
66ad6d84 | 572 | EXTERN int nfs_unlink(struct nfs_context *nfs, const char *path); |
84004dbf RS |
573 | |
574 | ||
575 | ||
576 | ||
577 | /* | |
578 | * OPENDIR() | |
579 | */ | |
580 | struct nfsdir; | |
581 | /* | |
582 | * Async opendir() | |
583 | * | |
584 | * Function returns | |
585 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
586 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
587 | * | |
588 | * When struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir() | |
589 | * | |
590 | * When the callback is invoked, status indicates the result: | |
591 | * 0 : Success. | |
592 | * data is struct nfsdir * | |
593 | * -errno : An error occured. | |
594 | * data is the error string. | |
595 | */ | |
66ad6d84 | 596 | EXTERN int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); |
84004dbf RS |
597 | /* |
598 | * Sync opendir() | |
599 | * Function returns | |
600 | * 0 : Success | |
601 | * -errno : An error occured. | |
602 | */ | |
66ad6d84 | 603 | EXTERN int nfs_opendir(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir); |
84004dbf RS |
604 | |
605 | ||
606 | ||
607 | /* | |
608 | * READDIR() | |
609 | */ | |
610 | struct nfsdirent { | |
611 | struct nfsdirent *next; | |
612 | char *name; | |
613 | uint64_t inode; | |
0804e67d RS |
614 | |
615 | /* some extra fields we get for free through the READDIRPLUS3 call. You need libnfs-raw-nfs.h for these */ | |
616 | uint32_t type; /* NF3REG, NF3DIR, NF3BLK, ... */ | |
617 | uint32_t mode; | |
618 | uint64_t size; | |
619 | struct timeval atime; | |
620 | struct timeval mtime; | |
621 | struct timeval ctime; | |
84004dbf RS |
622 | }; |
623 | /* | |
624 | * nfs_readdir() never blocks, so no special sync/async versions are available | |
625 | */ | |
66ad6d84 | 626 | EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir); |
84004dbf RS |
627 | |
628 | ||
629 | ||
630 | /* | |
631 | * READDIR() | |
632 | */ | |
633 | /* | |
634 | * nfs_closedir() never blocks, so no special sync/async versions are available | |
635 | */ | |
66ad6d84 | 636 | EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir); |
84004dbf RS |
637 | |
638 | ||
639 | ||
640 | /* | |
641 | * STATVFS() | |
642 | */ | |
643 | /* | |
644 | * Async statvfs(<dirname>) | |
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 the callback is invoked, status indicates the result: | |
650 | * 0 : Success. | |
651 | * data is struct statvfs * | |
652 | * -errno : An error occured. | |
653 | * data is the error string. | |
654 | */ | |
655 | struct statvfs; | |
66ad6d84 | 656 | EXTERN int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); |
84004dbf RS |
657 | /* |
658 | * Sync statvfs(<dirname>) | |
659 | * Function returns | |
660 | * 0 : The operation was successfull. | |
661 | * -errno : The command failed. | |
662 | */ | |
66ad6d84 | 663 | EXTERN int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs); |
84004dbf RS |
664 | |
665 | ||
666 | /* | |
667 | * READLINK() | |
668 | */ | |
669 | /* | |
670 | * Async readlink(<name>) | |
671 | * Function returns | |
672 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
673 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
674 | * | |
675 | * When the callback is invoked, status indicates the result: | |
676 | * 0 : Success. | |
677 | * data is a char * | |
678 | * data is only valid during the callback and is automatically freed when the callback returns. | |
679 | * -errno : An error occured. | |
680 | * data is the error string. | |
681 | */ | |
682 | struct statvfs; | |
66ad6d84 | 683 | EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data); |
84004dbf RS |
684 | /* |
685 | * Sync readlink(<name>) | |
686 | * Function returns | |
687 | * 0 : The operation was successfull. | |
688 | * -errno : The command failed. | |
689 | */ | |
66ad6d84 | 690 | EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize); |
84004dbf RS |
691 | |
692 | ||
693 | ||
694 | /* | |
695 | * CHMOD() | |
696 | */ | |
697 | /* | |
698 | * Async chmod(<name>) | |
699 | * Function returns | |
700 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
701 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
702 | * | |
703 | * When the callback is invoked, status indicates the result: | |
704 | * 0 : Success. | |
705 | * data is NULL | |
706 | * -errno : An error occured. | |
707 | * data is the error string. | |
708 | */ | |
66ad6d84 | 709 | EXTERN int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); |
84004dbf RS |
710 | /* |
711 | * Sync chmod(<name>) | |
712 | * Function returns | |
713 | * 0 : The operation was successfull. | |
714 | * -errno : The command failed. | |
715 | */ | |
66ad6d84 | 716 | EXTERN int nfs_chmod(struct nfs_context *nfs, const char *path, int mode); |
84004dbf RS |
717 | |
718 | ||
719 | ||
720 | /* | |
721 | * FCHMOD() | |
722 | */ | |
723 | /* | |
724 | * Async fchmod(<handle>) | |
725 | * Function returns | |
726 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
727 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
728 | * | |
729 | * When the callback is invoked, status indicates the result: | |
730 | * 0 : Success. | |
731 | * data is NULL | |
732 | * -errno : An error occured. | |
733 | * data is the error string. | |
734 | */ | |
66ad6d84 | 735 | EXTERN int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data); |
84004dbf RS |
736 | /* |
737 | * Sync fchmod(<handle>) | |
738 | * Function returns | |
739 | * 0 : The operation was successfull. | |
740 | * -errno : The command failed. | |
741 | */ | |
66ad6d84 | 742 | EXTERN int nfs_fchmod(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode); |
84004dbf RS |
743 | |
744 | ||
745 | ||
746 | /* | |
747 | * CHOWN() | |
748 | */ | |
749 | /* | |
750 | * Async chown(<name>) | |
751 | * Function returns | |
752 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
753 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
754 | * | |
755 | * When the callback is invoked, status indicates the result: | |
756 | * 0 : Success. | |
757 | * data is NULL | |
758 | * -errno : An error occured. | |
759 | * data is the error string. | |
760 | */ | |
66ad6d84 | 761 | EXTERN int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data); |
84004dbf RS |
762 | /* |
763 | * Sync chown(<name>) | |
764 | * Function returns | |
765 | * 0 : The operation was successfull. | |
766 | * -errno : The command failed. | |
767 | */ | |
66ad6d84 | 768 | EXTERN int nfs_chown(struct nfs_context *nfs, const char *path, int uid, int gid); |
84004dbf RS |
769 | |
770 | ||
771 | ||
772 | /* | |
773 | * FCHOWN() | |
774 | */ | |
775 | /* | |
776 | * Async fchown(<handle>) | |
777 | * Function returns | |
778 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
779 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
780 | * | |
781 | * When the callback is invoked, status indicates the result: | |
782 | * 0 : Success. | |
783 | * data is NULL | |
784 | * -errno : An error occured. | |
785 | * data is the error string. | |
786 | */ | |
66ad6d84 | 787 | EXTERN int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data); |
84004dbf RS |
788 | /* |
789 | * Sync fchown(<handle>) | |
790 | * Function returns | |
791 | * 0 : The operation was successfull. | |
792 | * -errno : The command failed. | |
793 | */ | |
66ad6d84 | 794 | EXTERN int nfs_fchown(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid); |
84004dbf RS |
795 | |
796 | ||
797 | ||
798 | ||
799 | /* | |
800 | * UTIMES() | |
801 | */ | |
802 | /* | |
803 | * Async utimes(<path>) | |
804 | * Function returns | |
805 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
806 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
807 | * | |
808 | * When the callback is invoked, status indicates the result: | |
809 | * 0 : Success. | |
810 | * data is NULL | |
811 | * -errno : An error occured. | |
812 | * data is the error string. | |
813 | */ | |
66ad6d84 | 814 | EXTERN int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data); |
84004dbf RS |
815 | /* |
816 | * Sync utimes(<path>) | |
817 | * Function returns | |
818 | * 0 : The operation was successfull. | |
819 | * -errno : The command failed. | |
820 | */ | |
66ad6d84 | 821 | EXTERN int nfs_utimes(struct nfs_context *nfs, const char *path, struct timeval *times); |
84004dbf RS |
822 | |
823 | ||
824 | /* | |
825 | * UTIME() | |
826 | */ | |
827 | /* | |
828 | * Async utime(<path>) | |
829 | * Function returns | |
830 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
831 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
832 | * | |
833 | * When the callback is invoked, status indicates the result: | |
834 | * 0 : Success. | |
835 | * data is NULL | |
836 | * -errno : An error occured. | |
837 | * data is the error string. | |
838 | */ | |
839 | struct utimbuf; | |
66ad6d84 | 840 | EXTERN int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data); |
84004dbf RS |
841 | /* |
842 | * Sync utime(<path>) | |
843 | * Function returns | |
844 | * 0 : The operation was successfull. | |
845 | * -errno : The command failed. | |
846 | */ | |
66ad6d84 | 847 | EXTERN int nfs_utime(struct nfs_context *nfs, const char *path, struct utimbuf *times); |
84004dbf RS |
848 | |
849 | ||
850 | ||
851 | ||
852 | /* | |
853 | * ACCESS() | |
854 | */ | |
855 | /* | |
856 | * Async access(<path>) | |
857 | * Function returns | |
858 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
859 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
860 | * | |
861 | * When the callback is invoked, status indicates the result: | |
862 | * 0 : Success. | |
863 | * data is NULL | |
864 | * -errno : An error occured. | |
865 | * data is the error string. | |
866 | */ | |
66ad6d84 | 867 | EXTERN int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data); |
84004dbf RS |
868 | /* |
869 | * Sync access(<path>) | |
870 | * Function returns | |
871 | * 0 : The operation was successfull. | |
872 | * -errno : The command failed. | |
873 | */ | |
66ad6d84 | 874 | EXTERN int nfs_access(struct nfs_context *nfs, const char *path, int mode); |
84004dbf RS |
875 | |
876 | ||
877 | ||
878 | ||
879 | /* | |
880 | * SYMLINK() | |
881 | */ | |
882 | /* | |
883 | * Async symlink(<path>) | |
884 | * Function returns | |
885 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
886 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
887 | * | |
888 | * When the callback is invoked, status indicates the result: | |
889 | * 0 : Success. | |
890 | * data is NULL | |
891 | * -errno : An error occured. | |
892 | * data is the error string. | |
893 | */ | |
66ad6d84 | 894 | EXTERN int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); |
84004dbf RS |
895 | /* |
896 | * Sync symlink(<path>) | |
897 | * Function returns | |
898 | * 0 : The operation was successfull. | |
899 | * -errno : The command failed. | |
900 | */ | |
66ad6d84 | 901 | EXTERN int nfs_symlink(struct nfs_context *nfs, const char *oldpath, const char *newpath); |
84004dbf RS |
902 | |
903 | ||
904 | /* | |
905 | * RENAME() | |
906 | */ | |
907 | /* | |
908 | * Async rename(<oldpath>, <newpath>) | |
909 | * Function returns | |
910 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
911 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
912 | * | |
913 | * When the callback is invoked, status indicates the result: | |
914 | * 0 : Success. | |
915 | * data is NULL | |
916 | * -errno : An error occured. | |
917 | * data is the error string. | |
918 | */ | |
66ad6d84 | 919 | EXTERN int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); |
84004dbf RS |
920 | /* |
921 | * Sync rename(<oldpath>, <newpath>) | |
922 | * Function returns | |
923 | * 0 : The operation was successfull. | |
924 | * -errno : The command failed. | |
925 | */ | |
66ad6d84 | 926 | EXTERN int nfs_rename(struct nfs_context *nfs, const char *oldpath, const char *newpath); |
84004dbf RS |
927 | |
928 | ||
929 | ||
930 | /* | |
931 | * LINK() | |
932 | */ | |
933 | /* | |
934 | * Async link(<oldpath>, <newpath>) | |
935 | * Function returns | |
936 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
937 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
938 | * | |
939 | * When the callback is invoked, status indicates the result: | |
940 | * 0 : Success. | |
941 | * data is NULL | |
942 | * -errno : An error occured. | |
943 | * data is the error string. | |
944 | */ | |
66ad6d84 | 945 | EXTERN int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data); |
84004dbf RS |
946 | /* |
947 | * Sync link(<oldpath>, <newpath>) | |
948 | * Function returns | |
949 | * 0 : The operation was successfull. | |
950 | * -errno : The command failed. | |
951 | */ | |
66ad6d84 | 952 | EXTERN int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath); |
84004dbf RS |
953 | |
954 | ||
7f0242ca RS |
955 | /* |
956 | * GETEXPORTS() | |
957 | */ | |
958 | /* | |
959 | * Async getexports() | |
960 | * NOTE: You must include 'libnfs-raw-mount.h' to get the definitions of the | |
961 | * returned structures. | |
962 | * | |
963 | * This function will return the list of exports from an NFS server. | |
964 | * | |
965 | * Function returns | |
966 | * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. | |
967 | * <0 : An error occured when trying to set up the operation. The callback will not be invoked. | |
968 | * | |
969 | * When the callback is invoked, status indicates the result: | |
970 | * 0 : Success. | |
971 | * data is a pointer to an exports pointer: | |
972 | * exports export = *(exports *)data; | |
973 | * -errno : An error occured. | |
974 | * data is the error string. | |
975 | */ | |
66ad6d84 | 976 | EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb cb, void *private_data); |
df5af25f RS |
977 | /* |
978 | * Sync getexports(<server>) | |
979 | * Function returns | |
980 | * NULL : something failed | |
981 | * exports export : a linked list of exported directories | |
982 | * | |
983 | * returned data must be freed by calling mount_free_export_list(exportnode); | |
984 | */ | |
66ad6d84 | 985 | EXTERN struct exportnode *mount_getexports(const char *server); |
7f0242ca | 986 | |
66ad6d84 | 987 | EXTERN void mount_free_export_list(struct exportnode *exports); |
7f0242ca | 988 | |
84004dbf RS |
989 | |
990 | //qqq replace later with lseek(cur, 0) | |
991 | off_t nfs_get_current_offset(struct nfsfh *nfsfh); | |
552c7665 RS |
992 | |
993 | ||
994 | ||
9c4212bf RS |
995 | |
996 | ||
552c7665 RS |
997 | struct nfs_server_list { |
998 | struct nfs_server_list *next; | |
999 | char *addr; | |
1000 | }; | |
1001 | ||
9c4212bf RS |
1002 | /* |
1003 | * Sync find_local_servers(<server>) | |
1004 | * This function will probe all local networks for NFS server. This function will | |
1005 | * block for one second while awaiting for all nfs servers to respond. | |
1006 | * | |
1007 | * Function returns | |
1008 | * NULL : something failed | |
1009 | * | |
1010 | * struct nfs_server_list : a linked list of all discovered servers | |
1011 | * | |
1012 | * returned data must be freed by nfs_free_srvr_list(srv); | |
1013 | */ | |
552c7665 RS |
1014 | struct nfs_server_list *nfs_find_local_servers(void); |
1015 | void free_nfs_srvr_list(struct nfs_server_list *srv); |