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