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