]> arthur.barton.de Git - netatalk.git/blob - libatalk/vfs/vfs.c
Fix several VFS inconsistencies
[netatalk.git] / libatalk / vfs / vfs.c
1 /*
2     Copyright (c) 2004 Didier Gautheron
3     Copyright (c) 2009 Frank Lahm
4  
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9  
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14  
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19 */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif /* HAVE_CONFIG_H */
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <libgen.h>
31
32 #include <atalk/afp.h>    
33 #include <atalk/adouble.h>
34 #include <atalk/ea.h>
35 #include <atalk/acl.h>
36 #include <atalk/logger.h>
37 #include <atalk/util.h>
38 #include <atalk/volume.h>
39 #include <atalk/vfs.h>
40 #include <atalk/directory.h>
41 #include <atalk/unix.h>
42 #include <atalk/errchk.h>
43 #include <atalk/bstrlib.h>
44 #include <atalk/bstradd.h>
45 #include <atalk/compat.h>
46
47 struct perm {
48     uid_t uid;
49     gid_t gid;
50 };
51
52 typedef int (*rf_loop)(const struct vol *, struct dirent *, char *, void *, int);
53
54 /* ----------------------------- */
55 static int 
56 for_each_adouble(const char *from, const char *name, rf_loop fn, const struct vol *vol, void *data, int flag)
57 {
58     char            buf[ MAXPATHLEN + 1];
59     char            *m;
60     DIR             *dp;
61     struct dirent   *de;
62     int             ret;
63     
64
65     if (NULL == ( dp = opendir( name)) ) {
66         if (!flag) {
67             LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
68             return -1;
69         }
70         return 0;
71     }
72     strlcpy( buf, name, sizeof(buf));
73     strlcat( buf, "/", sizeof(buf) );
74     m = strchr( buf, '\0' );
75     ret = 0;
76     while ((de = readdir(dp))) {
77         if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
78                 continue;
79         }
80         
81         strlcat(buf, de->d_name, sizeof(buf));
82         if (fn && (ret = fn(vol, de, buf, data, flag))) {
83            closedir(dp);
84            return ret;
85         }
86         *m = 0;
87     }
88     closedir(dp);
89     return ret;
90 }
91
92 static int netatalk_name(const char *name)
93 {
94     return strcmp(name,".AppleDB") && strcmp(name,".AppleDesktop");        
95 }
96
97 /*******************************************************************************
98  * classic adouble format 
99  *******************************************************************************/
100
101 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
102 {
103     if (name[0] != '.')
104         return 1;
105     
106     return netatalk_name(name) && strcmp(name,".AppleDouble") && strcasecmp(name,".Parent");
107 }                                           
108
109 /* ----------------- */
110 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
111 {
112     struct stat st;
113     const char *ad_p;
114
115     ad_p = vol->ad_path(path, ADFLAGS_HF );
116
117     if ( stat( ad_p, &st ) < 0 )
118         return 0; /* ignore */
119
120     return chown( ad_p, uid, gid );
121 }
122
123 /* ----------------- */
124 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
125 {
126     return 0;
127 }
128
129 /* ----------------- */
130 static int deletecurdir_adouble_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
131 {
132     struct stat st;
133     int         err;
134     
135     /* bail if the file exists in the current directory.
136      * note: this will not fail with dangling symlinks */
137     
138     if (lstat(de->d_name, &st) == 0)
139         return AFPERR_DIRNEMPT;
140
141     if ((err = netatalk_unlink(name)))
142         return err;
143
144     return 0;
145 }
146
147 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
148 {
149     int err;
150
151     /* delete stray .AppleDouble files. this happens to get .Parent files
152        as well. */
153     if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, vol, NULL, 1))) 
154         return err;
155     return netatalk_rmdir(-1, ".AppleDouble" );
156 }
157
158 /* ----------------- */
159 static int adouble_setfilmode(const struct vol *vol, const char *name, mode_t mode, struct stat *st)
160 {
161     return setfilmode(vol, name, ad_hf_mode(mode), st);
162 }
163
164 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
165 {
166     return adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_HF ), mode, st);
167 }
168
169 /* ----------------- */
170 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
171 {
172     const char *adouble = vol->ad_path(name, ADFLAGS_DIR );
173     int  dropbox = vol->v_flags;
174
175     if (dir_rx_set(mode)) {
176         if (chmod_acl(ad_dir(adouble), (DIRBITS | mode) & ~vol->v_umask) < 0 ) 
177             return -1;
178     }
179
180     if (adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_DIR ), mode, st) < 0) 
181         return -1;
182
183     if (!dir_rx_set(mode)) {
184         if (chmod_acl(ad_dir(adouble), (DIRBITS | mode) & ~vol->v_umask) < 0 ) 
185             return  -1 ;
186     }
187     return 0;
188 }
189
190 /* ----------------- */
191 static int setdirmode_adouble_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag)
192 {
193     mode_t hf_mode = *(mode_t *)data;
194     struct stat st;
195
196     if (ostat(name, &st, vol_syml_opt(vol)) < 0 ) {
197         if (flag)
198             return 0;
199         LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
200     }
201     else if (!S_ISDIR(st.st_mode)) {
202         if (setfilmode(vol, name, hf_mode, &st) < 0) {
203                /* FIXME what do we do then? */
204         }
205     }
206     return 0;
207 }
208
209 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
210 {
211     int   dropbox = vol->v_flags;
212     mode_t hf_mode = ad_hf_mode(mode);
213     const char  *adouble = vol->ad_path(name, ADFLAGS_DIR );
214     const char  *adouble_p = ad_dir(adouble);
215
216     if (dir_rx_set(mode)) {
217         if (chmod_acl(ad_dir(adouble), (DIRBITS | mode) & ~vol->v_umask) < 0) 
218             return -1;
219     }
220
221     if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, vol, &hf_mode, 0))
222         return -1;
223
224     if (!dir_rx_set(mode)) {
225         if (chmod_acl(ad_dir(adouble), (DIRBITS | mode) & ~vol->v_umask) < 0) 
226             return  -1 ;
227     }
228     return 0;
229 }
230
231 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
232 {
233     if (lchown(".AppleDouble", uid, gid) < 0 && errno != EPERM ) {
234         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
235             uid, gid,fullpathname(".AppleDouble"), strerror(errno));
236     }
237     return 0;
238 }
239
240 /* ----------------- */
241 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
242 {
243         return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
244 }
245
246 /* ----------------- */
247 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
248 {
249     char  adsrc[ MAXPATHLEN + 1];
250     int   err = 0;
251
252     strcpy( adsrc, vol->ad_path(src, 0 ));
253     if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
254         struct stat st;
255
256         err = errno;
257         if (errno == ENOENT) {
258                 struct adouble    ad;
259
260             if (ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
261                 return 0;
262
263             /* We are here  because :
264              * -there's no dest folder. 
265              * -there's no .AppleDouble in the dest folder.
266              * if we use the struct adouble passed in parameter it will not
267              * create .AppleDouble if the file is already opened, so we
268              * use a diff one, it's not a pb,ie it's not the same file, yet.
269              */
270             ad_init(&ad, vol); 
271             if (ad_open(&ad, dst, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) == 0) {
272                 ad_close(&ad, ADFLAGS_HF);
273                 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) ) 
274                    err = 0;
275                 else 
276                    err = errno;
277             }
278             else { /* it's something else, bail out */
279                     err = errno;
280                 }
281             }
282         }
283         if (err) {
284                 errno = err;
285                 return -1;
286         }
287         return 0;
288 }
289
290 static int RF_copyfile_adouble(VFS_FUNC_ARGS_COPYFILE)
291 /* const struct vol *vol, int sfd, const char *src, const char *dst */
292 {
293     EC_INIT;
294     bstring s = NULL, d = NULL;
295     char *dup1 = NULL;
296     char *dup2 = NULL;
297     char *dup3 = NULL;
298     char *dup4 = NULL;
299     const char *name = NULL;
300     const char *dir = NULL;
301
302     struct stat st;
303     EC_ZERO(stat(dst, &st));
304
305     if (S_ISDIR(st.st_mode)) {
306         /* build src path to AppleDouble file*/
307         EC_NULL(s = bfromcstr(src));
308         EC_ZERO(bcatcstr(s, "/.AppleDouble/.Parent"));
309
310         /* build dst path to AppleDouble file*/
311         EC_NULL(d = bfromcstr(dst));
312         EC_ZERO(bcatcstr(d, "/.AppleDouble/.Parent"));
313     } else {
314         /* get basename */
315
316         /* build src path to AppleDouble file*/
317         EC_NULL(dup1 = strdup(src));
318         EC_NULL(name = basename(strdup(dup1)));
319
320         EC_NULL(dup2 = strdup(src));
321         EC_NULL(dir = dirname(dup2));
322         EC_NULL(s = bfromcstr(dir));
323         EC_ZERO(bcatcstr(s, "/.AppleDouble/"));
324         EC_ZERO(bcatcstr(s, name));
325
326         /* build dst path to AppleDouble file*/
327         EC_NULL(dup4 = strdup(dst));
328         EC_NULL(name = basename(strdup(dup4)));
329
330         EC_NULL(dup3 = strdup(dst));
331         EC_NULL(dir = dirname(dup3));
332         EC_NULL(d = bfromcstr(dir));
333         EC_ZERO(bcatcstr(d, "/.AppleDouble/"));
334         EC_ZERO(bcatcstr(d, name));
335     }
336
337     /* ignore errors */
338     if (copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666) != 0)
339         if (errno != ENOENT)
340             EC_FAIL;
341
342 EC_CLEANUP:
343     bdestroy(s);
344     bdestroy(d);
345     if (dup1) free(dup1);
346     if (dup2) free(dup2);
347     if (dup3) free(dup3);
348     if (dup4) free(dup4);
349
350     EC_EXIT;
351 }
352
353 #ifdef HAVE_SOLARIS_ACLS
354 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
355 {
356     static char buf[ MAXPATHLEN + 1];
357     struct stat st;
358     int len;
359
360     if ((stat(path, &st)) != 0)
361         return -1;
362     if (S_ISDIR(st.st_mode)) {
363         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
364         if (len < 0 || len >=  MAXPATHLEN)
365             return -1;
366         /* set acl on .AppleDouble dir first */
367         if ((acl(buf, cmd, count, aces)) != 0)
368             return -1;
369         /* now set ACL on ressource fork */
370         if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
371             return -1;
372     } else
373         /* set ACL on ressource fork */
374         if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
375             return -1;
376
377     return 0;
378 }
379
380 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
381 {
382     int ret;
383     static char buf[ MAXPATHLEN + 1];
384     int len;
385
386     if (dir) {
387         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
388         if (len < 0 || len >=  MAXPATHLEN)
389             return AFPERR_MISC;
390         /* remove ACL from .AppleDouble/.Parent first */
391         if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
392             return ret;
393         /* now remove from .AppleDouble dir */
394         if ((ret = remove_acl_vfs(buf)) != AFP_OK)
395             return ret;
396     } else
397         /* remove ACL from ressource fork */
398         if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
399             return ret;
400
401     return AFP_OK;
402 }
403 #endif
404
405 #ifdef HAVE_POSIX_ACLS
406 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
407 {
408     EC_INIT;
409     static char buf[ MAXPATHLEN + 1];
410     struct stat st;
411     int len;
412
413     if (S_ISDIR(st.st_mode)) {
414         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
415         if (len < 0 || len >=  MAXPATHLEN)
416             EC_FAIL;
417         /* set acl on .AppleDouble dir first */
418         EC_ZERO_LOG(acl_set_file(buf, type, acl));
419
420         if (type == ACL_TYPE_ACCESS)
421             /* set ACL on ressource fork (".Parent") too */
422             EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_DIR), type, acl));
423     } else {
424         /* set ACL on ressource fork */
425         EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl));
426     }
427     
428 EC_CLEANUP:
429     if (ret != 0)
430         return AFPERR_MISC;
431     return AFP_OK;
432 }
433
434 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
435 {
436     EC_INIT;
437     static char buf[ MAXPATHLEN + 1];
438     int len;
439
440     if (dir) {
441         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
442         if (len < 0 || len >=  MAXPATHLEN)
443             return AFPERR_MISC;
444         /* remove ACL from .AppleDouble/.Parent first */
445         EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR)), AFPERR_MISC);
446
447         /* now remove from .AppleDouble dir */
448         EC_ZERO_LOG_ERR(remove_acl_vfs(buf), AFPERR_MISC);
449     } else {
450         /* remove ACL from ressource fork */
451         EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC);
452     }
453
454 EC_CLEANUP:
455     EC_EXIT;
456 }
457 #endif
458
459 /*************************************************************************
460  * EA adouble format 
461  ************************************************************************/
462 static int validupath_ea(VFS_FUNC_ARGS_VALIDUPATH)
463 {
464     if (name[0] != '.')
465         return 1;
466     
467 #ifndef HAVE_EAFD
468     if (name[1] == '_')
469         return ad_valid_header_osx(name);
470 #endif
471     return netatalk_name(name);
472 }
473
474 /* ----------------- */
475 static int RF_chown_ea(VFS_FUNC_ARGS_CHOWN)
476 {
477 #ifndef HAVE_EAFD
478     return chown(vol->ad_path(path, ADFLAGS_HF ), uid, gid);
479 #endif
480     return 0;
481 }
482
483 /* ---------------- */
484 static int RF_renamedir_ea(VFS_FUNC_ARGS_RENAMEDIR)
485 {
486     return 0;
487 }
488
489 /* Returns 1 if the entry is NOT an ._ file */
490 static int deletecurdir_ea_osx_chkifempty_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
491 {
492     if (de->d_name[0] != '.' || de->d_name[0] == '_')
493         return 1;
494
495     return 0;
496 }
497
498 static int deletecurdir_ea_osx_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
499 {
500     int ret;
501     
502     if ((ret = netatalk_unlink(name)) != 0)
503         return ret;
504
505     return 0;
506 }
507
508 /* ---------------- */
509 static int RF_deletecurdir_ea(VFS_FUNC_ARGS_DELETECURDIR)
510 {
511 #ifndef HAVE_EAFD
512     int err;
513     /* delete stray ._AppleDouble files */
514
515     /* first check if there's really no other file besides files starting with ._ */
516     if ((err = for_each_adouble("deletecurdir_ea_osx", ".",
517                                 deletecurdir_ea_osx_chkifempty_loop,
518                                 vol, NULL, 0)) != 0) {
519         if (err == 1)
520             return AFPERR_DIRNEMPT;
521         return AFPERR_MISC;
522     }
523
524     /* Now delete orphaned ._ files */
525     if ((err = for_each_adouble("deletecurdir_ea_osx", ".",
526                                 deletecurdir_ea_osx_loop,
527                                 vol, NULL, 0)) != 0)
528         return err;
529
530 #endif
531     return 0;
532 }
533
534 /* ---------------- */
535 static int RF_setdirunixmode_ea(VFS_FUNC_ARGS_SETDIRUNIXMODE)
536 {
537 #ifndef HAVE_EAFD
538 #endif
539     return 0;
540 }
541
542 static int RF_setfilmode_ea(VFS_FUNC_ARGS_SETFILEMODE)
543 {
544 #ifndef HAVE_EAFD
545     return adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_HF ), mode, st);
546 #endif
547     return 0;
548 }
549
550 /* ---------------- */
551 static int RF_setdirmode_ea(VFS_FUNC_ARGS_SETDIRMODE)
552 {
553 #ifndef HAVE_EAFD
554 #endif
555     return 0;
556 }
557
558 /* ---------------- */
559 static int RF_setdirowner_ea(VFS_FUNC_ARGS_SETDIROWNER)
560 {
561 #ifndef HAVE_EAFD
562 #endif
563         return 0;
564 }
565
566 static int RF_deletefile_ea(VFS_FUNC_ARGS_DELETEFILE)
567 {
568 #ifndef HAVE_EAFD
569         return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
570 #endif
571     return 0;
572 }
573 static int RF_copyfile_ea(VFS_FUNC_ARGS_COPYFILE)
574 {
575 #ifdef HAVE_EAFD
576     /* the EA VFS module does this all for us */
577     return 0;
578 #endif
579
580     EC_INIT;
581     bstring s = NULL, d = NULL;
582     char *dup1 = NULL;
583     char *dup2 = NULL;
584     char *dup3 = NULL;
585     char *dup4 = NULL;
586     const char *name = NULL;
587     const char *dir = NULL;
588
589     /* get basename */
590
591     /* build src path to ._ file*/
592     EC_NULL(dup1 = strdup(src));
593     EC_NULL(name = basename(strdup(dup1)));
594
595     EC_NULL(dup2 = strdup(src));
596     EC_NULL(dir = dirname(dup2));
597     EC_NULL(s = bfromcstr(dir));
598     EC_ZERO(bcatcstr(s, "/._"));
599     EC_ZERO(bcatcstr(s, name));
600
601     /* build dst path to ._file*/
602     EC_NULL(dup4 = strdup(dst));
603     EC_NULL(name = basename(strdup(dup4)));
604
605     EC_NULL(dup3 = strdup(dst));
606     EC_NULL(dir = dirname(dup3));
607     EC_NULL(d = bfromcstr(dir));
608     EC_ZERO(bcatcstr(d, "/._"));
609     EC_ZERO(bcatcstr(d, name));
610
611     if (copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666) != 0) {
612         switch (errno) {
613         case ENOENT:
614             break;
615         default:
616             LOG(log_error, logtype_afpd, "[VFS] copyfile(\"%s\" -> \"%s\"): %s",
617                 cfrombstr(s), cfrombstr(d), strerror(errno));
618             EC_FAIL;
619                     
620         }
621     }
622
623 EC_CLEANUP:
624     bdestroy(s);
625     bdestroy(d);
626     free(dup1);
627     free(dup2);
628     free(dup3);
629     free(dup4);
630     EC_EXIT;
631 }
632
633 /* ---------------- */
634 static int RF_renamefile_ea(VFS_FUNC_ARGS_RENAMEFILE)
635 {
636 #ifndef HAVE_EAFD
637     char  adsrc[ MAXPATHLEN + 1];
638     int   err = 0;
639
640     strcpy( adsrc, vol->ad_path(src, 0 ));
641
642     if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
643         struct stat st;
644
645         err = errno;
646         if (errno == ENOENT && ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
647             return 0;
648         errno = err;
649         return -1;
650     }
651     return 0;
652 #endif
653     return 0;
654 }
655
656 /********************************************************************************************
657  * VFS chaining
658  ********************************************************************************************/
659
660 /* 
661  * Up until we really start stacking many VFS modules on top of one another or use
662  * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
663  * via an fixed size array.
664  * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
665  * this error code will be returned to the caller, BUT the chain in followed and all
666  * following funcs are called in order to give them a chance.
667  */
668
669 /* 
670  * Define most VFS funcs with macros as they all do the same.
671  * Only "ad_path" and "validupath" will NOT do stacking and only
672  * call the func from the first module.
673  */
674
675 #define VFS_MFUNC(name, args, vars) \
676     static int vfs_ ## name(args) \
677     { \
678         int i = 0, ret = AFP_OK, err; \
679         while (vol->vfs_modules[i]) { \
680             if (vol->vfs_modules[i]->vfs_ ## name) { \
681                 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
682                 if ((ret == AFP_OK) && (err != AFP_OK)) \
683                     ret = err; \
684             } \
685             i ++; \
686         } \
687         return ret; \
688     }
689
690 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
691 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR) 
692 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
693 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
694 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
695 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
696 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
697 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
698 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
699 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
700 #ifdef HAVE_ACLS
701 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
702 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
703 #endif
704 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
705 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
706 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
707 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
708 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
709
710 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
711 {
712     return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
713 }
714
715 /*
716  * These function pointers get called from the lib users via vol->vfs->func.
717  * These funcs are defined via the macros above.
718  */
719 static struct vfs_ops vfs_master_funcs = {
720     vfs_validupath,
721     vfs_chown,
722     vfs_renamedir,
723     vfs_deletecurdir,
724     vfs_setfilmode,
725     vfs_setdirmode,
726     vfs_setdirunixmode,
727     vfs_setdirowner,
728     vfs_deletefile,
729     vfs_renamefile,
730     vfs_copyfile,
731 #ifdef HAVE_ACLS
732     vfs_acl,
733     vfs_remove_acl,
734 #endif
735     vfs_ea_getsize,
736     vfs_ea_getcontent,
737     vfs_ea_list,
738     vfs_ea_set,
739     vfs_ea_remove
740 };
741
742 /* 
743  * Primary adouble modules: v2, ea
744  */
745
746 static struct vfs_ops netatalk_adouble_v2 = {
747     /* vfs_validupath:    */ validupath_adouble,
748     /* vfs_chown:         */ RF_chown_adouble,
749     /* vfs_renamedir:     */ RF_renamedir_adouble,
750     /* vfs_deletecurdir:  */ RF_deletecurdir_adouble,
751     /* vfs_setfilmode:    */ RF_setfilmode_adouble,
752     /* vfs_setdirmode:    */ RF_setdirmode_adouble,
753     /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
754     /* vfs_setdirowner:   */ RF_setdirowner_adouble,
755     /* vfs_deletefile:    */ RF_deletefile_adouble,
756     /* vfs_renamefile:    */ RF_renamefile_adouble,
757     /* vfs_copyfile:      */ RF_copyfile_adouble,
758     NULL
759 };
760
761 static struct vfs_ops netatalk_adouble_ea = {
762     /* vfs_validupath:    */ validupath_ea,
763     /* vfs_chown:         */ RF_chown_ea,
764     /* vfs_renamedir:     */ RF_renamedir_ea,
765     /* vfs_deletecurdir:  */ RF_deletecurdir_ea,
766     /* vfs_setfilmode:    */ RF_setfilmode_ea,
767     /* vfs_setdirmode:    */ RF_setdirmode_ea,
768     /* vfs_setdirunixmode:*/ RF_setdirunixmode_ea,
769     /* vfs_setdirowner:   */ RF_setdirowner_ea,
770     /* vfs_deletefile:    */ RF_deletefile_ea,
771     /* vfs_renamefile:    */ RF_renamefile_ea,
772     /* vfs_copyfile:      */ RF_copyfile_ea,
773     NULL
774 };
775
776 /* 
777  * Secondary vfs modules for Extended Attributes
778  */
779
780 static struct vfs_ops netatalk_ea_adouble = {
781     /* vfs_validupath:    */ NULL,
782     /* vfs_chown:         */ ea_chown,
783     /* vfs_renamedir:     */ NULL, /* ok */
784     /* vfs_deletecurdir:  */ NULL, /* ok */
785     /* vfs_setfilmode:    */ ea_chmod_file,
786     /* vfs_setdirmode:    */ NULL, /* ok */
787     /* vfs_setdirunixmode:*/ ea_chmod_dir,
788     /* vfs_setdirowner:   */ NULL, /* ok */
789     /* vfs_deletefile:    */ ea_deletefile,
790     /* vfs_renamefile:    */ ea_renamefile,
791     /* vfs_copyfile       */ ea_copyfile,
792 #ifdef HAVE_ACLS
793     /* vfs_acl:           */ NULL,
794     /* vfs_remove_acl     */ NULL,
795 #endif
796     /* vfs_getsize        */ get_easize,
797     /* vfs_getcontent     */ get_eacontent,
798     /* vfs_list           */ list_eas,
799     /* vfs_set            */ set_ea,
800     /* vfs_remove         */ remove_ea
801 };
802
803 static struct vfs_ops netatalk_ea_sys = {
804     /* validupath:        */ NULL,
805     /* rf_chown:          */ NULL,
806     /* rf_renamedir:      */ NULL,
807     /* rf_deletecurdir:   */ NULL,
808     /* rf_setfilmode:     */ NULL,
809     /* rf_setdirmode:     */ NULL,
810     /* rf_setdirunixmode: */ NULL,
811     /* rf_setdirowner:    */ NULL,
812     /* rf_deletefile:     */ NULL,
813     /* rf_renamefile:     */ NULL,
814     /* vfs_copyfile:      */ sys_ea_copyfile,
815 #ifdef HAVE_ACLS
816     /* rf_acl:            */ NULL,
817     /* rf_remove_acl      */ NULL,
818 #endif
819     /* ea_getsize         */ sys_get_easize,
820     /* ea_getcontent      */ sys_get_eacontent,
821     /* ea_list            */ sys_list_eas,
822     /* ea_set             */ sys_set_ea,
823     /* ea_remove          */ sys_remove_ea
824 };
825
826 /* 
827  * Tertiary VFS modules for ACLs
828  */
829
830 #ifdef HAVE_SOLARIS_ACLS
831 static struct vfs_ops netatalk_solaris_acl_adouble = {
832     /* validupath:        */ NULL,
833     /* rf_chown:          */ NULL,
834     /* rf_renamedir:      */ NULL,
835     /* rf_deletecurdir:   */ NULL,
836     /* rf_setfilmode:     */ NULL,
837     /* rf_setdirmode:     */ NULL,
838     /* rf_setdirunixmode: */ NULL,
839     /* rf_setdirowner:    */ NULL,
840     /* rf_deletefile:     */ NULL,
841     /* rf_renamefile:     */ NULL,
842     /* vfs_copyfile       */ NULL,
843     /* rf_acl:            */ RF_solaris_acl,
844     /* rf_remove_acl      */ RF_solaris_remove_acl,
845     NULL
846 };
847 #endif
848
849 #ifdef HAVE_POSIX_ACLS
850 static struct vfs_ops netatalk_posix_acl_adouble = {
851     /* validupath:        */ NULL,
852     /* rf_chown:          */ NULL,
853     /* rf_renamedir:      */ NULL,
854     /* rf_deletecurdir:   */ NULL,
855     /* rf_setfilmode:     */ NULL,
856     /* rf_setdirmode:     */ NULL,
857     /* rf_setdirunixmode: */ NULL,
858     /* rf_setdirowner:    */ NULL,
859     /* rf_deletefile:     */ NULL,
860     /* rf_renamefile:     */ NULL,
861     /* vfs_copyfile       */ NULL,
862     /* rf_acl:            */ RF_posix_acl,
863     /* rf_remove_acl      */ RF_posix_remove_acl,
864     NULL
865 };
866 #endif
867
868 /* ---------------- */
869 void initvol_vfs(struct vol *vol)
870 {
871     vol->vfs = &vfs_master_funcs;
872
873     /* Default adouble stuff */
874     if (vol->v_adouble == AD_VERSION2) {
875         vol->vfs_modules[0] = &netatalk_adouble_v2;
876         vol->ad_path = ad_path;
877     } else {
878         vol->vfs_modules[0] = &netatalk_adouble_ea;
879 #ifdef HAVE_EAFD
880         vol->ad_path = ad_path_ea;
881 #else
882         vol->ad_path = ad_path_osx;
883 #endif
884     }
885
886     /* Extended Attributes */
887     if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
888         LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
889         vol->vfs_modules[1] = &netatalk_ea_sys;
890     } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
891         LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
892         vol->vfs_modules[1] = &netatalk_ea_adouble;
893     } else {
894         LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
895     }
896
897     /* ACLs */
898 #ifdef HAVE_SOLARIS_ACLS
899     vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
900 #endif
901 #ifdef HAVE_POSIX_ACLS
902     vol->vfs_modules[2] = &netatalk_posix_acl_adouble;
903 #endif
904
905 }