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