]> arthur.barton.de Git - netatalk.git/blob - libatalk/vfs/vfs.c
Spotlight: use async Tracker SPARQL API
[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
174     if (dir_rx_set(mode)) {
175         if (ochmod(ad_dir(adouble),
176                    (DIRBITS | mode) & ~vol->v_umask,
177                    st,
178                    vol_syml_opt(vol) | vol_chmod_opt(vol)
179                 ) < 0)
180             return -1;
181     }
182
183     if (adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_DIR ), mode, st) < 0) 
184         return -1;
185
186     if (!dir_rx_set(mode)) {
187         if (ochmod(ad_dir(adouble),
188                    (DIRBITS | mode) & ~vol->v_umask,
189                    st,
190                    vol_syml_opt(vol) | vol_chmod_opt(vol)
191                 ) < 0)
192             return  -1 ;
193     }
194     return 0;
195 }
196
197 /* ----------------- */
198 static int setdirmode_adouble_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag)
199 {
200     mode_t hf_mode = *(mode_t *)data;
201     struct stat st;
202
203     if (ostat(name, &st, vol_syml_opt(vol)) < 0 ) {
204         if (flag)
205             return 0;
206         LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
207     }
208     else if (!S_ISDIR(st.st_mode)) {
209         if (setfilmode(vol, name, hf_mode, &st) < 0) {
210                /* FIXME what do we do then? */
211         }
212     }
213     return 0;
214 }
215
216 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
217 {
218     mode_t hf_mode = ad_hf_mode(mode);
219     const char  *adouble = vol->ad_path(name, ADFLAGS_DIR );
220     const char  *adouble_p = ad_dir(adouble);
221
222     if (dir_rx_set(mode)) {
223         if (ochmod(ad_dir(adouble),
224                    (DIRBITS | mode) & ~vol->v_umask,
225                    st,
226                    vol_syml_opt(vol) | vol_chmod_opt(vol)
227                 ) < 0)
228             return -1;
229     }
230
231     if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, vol, &hf_mode, 0))
232         return -1;
233
234     if (!dir_rx_set(mode)) {
235         if (ochmod(ad_dir(adouble),
236                    (DIRBITS | mode) & ~vol->v_umask,
237                    st,
238                    vol_syml_opt(vol) | vol_chmod_opt(vol)
239                 ) < 0)
240             return  -1 ;
241     }
242     return 0;
243 }
244
245 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
246 {
247     if (lchown(".AppleDouble", uid, gid) < 0 && errno != EPERM ) {
248         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
249             uid, gid,fullpathname(".AppleDouble"), strerror(errno));
250     }
251     return 0;
252 }
253
254 /* ----------------- */
255 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
256 {
257         return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
258 }
259
260 /* ----------------- */
261 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
262 {
263     char  adsrc[ MAXPATHLEN + 1];
264     int   err = 0;
265
266     strcpy( adsrc, vol->ad_path(src, 0 ));
267     if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
268         struct stat st;
269
270         err = errno;
271         if (errno == ENOENT) {
272                 struct adouble    ad;
273
274             if (ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
275                 return 0;
276
277             /* We are here  because :
278              * -there's no dest folder. 
279              * -there's no .AppleDouble in the dest folder.
280              * if we use the struct adouble passed in parameter it will not
281              * create .AppleDouble if the file is already opened, so we
282              * use a diff one, it's not a pb,ie it's not the same file, yet.
283              */
284             ad_init(&ad, vol); 
285             if (ad_open(&ad, dst, ADFLAGS_HF | ADFLAGS_RDWR | ADFLAGS_CREATE, 0666) == 0) {
286                 ad_close(&ad, ADFLAGS_HF);
287                 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) ) 
288                    err = 0;
289                 else 
290                    err = errno;
291             }
292             else { /* it's something else, bail out */
293                     err = errno;
294                 }
295             }
296         }
297         if (err) {
298                 errno = err;
299                 return -1;
300         }
301         return 0;
302 }
303
304 static int RF_copyfile_adouble(VFS_FUNC_ARGS_COPYFILE)
305 /* const struct vol *vol, int sfd, const char *src, const char *dst */
306 {
307     EC_INIT;
308     bstring s = NULL, d = NULL;
309     char *dup1 = NULL;
310     char *dup2 = NULL;
311     char *dup3 = NULL;
312     char *dup4 = NULL;
313     const char *name = NULL;
314     const char *dir = NULL;
315
316     struct stat st;
317     EC_ZERO(stat(dst, &st));
318
319     if (S_ISDIR(st.st_mode)) {
320         /* build src path to AppleDouble file*/
321         EC_NULL(s = bfromcstr(src));
322         EC_ZERO(bcatcstr(s, "/.AppleDouble/.Parent"));
323
324         /* build dst path to AppleDouble file*/
325         EC_NULL(d = bfromcstr(dst));
326         EC_ZERO(bcatcstr(d, "/.AppleDouble/.Parent"));
327     } else {
328         /* get basename */
329
330         /* build src path to AppleDouble file*/
331         EC_NULL(dup1 = strdup(src));
332         EC_NULL(name = basename(strdup(dup1)));
333
334         EC_NULL(dup2 = strdup(src));
335         EC_NULL(dir = dirname(dup2));
336         EC_NULL(s = bfromcstr(dir));
337         EC_ZERO(bcatcstr(s, "/.AppleDouble/"));
338         EC_ZERO(bcatcstr(s, name));
339
340         /* build dst path to AppleDouble file*/
341         EC_NULL(dup4 = strdup(dst));
342         EC_NULL(name = basename(strdup(dup4)));
343
344         EC_NULL(dup3 = strdup(dst));
345         EC_NULL(dir = dirname(dup3));
346         EC_NULL(d = bfromcstr(dir));
347         EC_ZERO(bcatcstr(d, "/.AppleDouble/"));
348         EC_ZERO(bcatcstr(d, name));
349     }
350
351     /* ignore errors */
352     if (copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666) != 0)
353         if (errno != ENOENT)
354             EC_FAIL;
355
356 EC_CLEANUP:
357     bdestroy(s);
358     bdestroy(d);
359     if (dup1) free(dup1);
360     if (dup2) free(dup2);
361     if (dup3) free(dup3);
362     if (dup4) free(dup4);
363
364     EC_EXIT;
365 }
366
367 #ifdef HAVE_NFSV4_ACLS
368 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
369 {
370     static char buf[ MAXPATHLEN + 1];
371     struct stat st;
372     int len;
373
374     if ((stat(path, &st)) != 0) {
375         if (errno == ENOENT)
376             return AFP_OK;
377         return AFPERR_MISC;
378     }
379     if (!S_ISDIR(st.st_mode)) {
380         /* set ACL on ressource fork */
381         if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
382             return AFPERR_MISC;
383     }
384     return AFP_OK;
385 }
386
387 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
388 {
389     int ret;
390     static char buf[ MAXPATHLEN + 1];
391     int len;
392
393     if (dir)
394         return AFP_OK;
395
396     /* remove ACL from ressource fork */
397     if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK) {
398         if (errno == ENOENT)
399             return AFP_OK;
400         return ret;
401     }
402
403     return AFP_OK;
404 }
405 #endif
406
407 #ifdef HAVE_POSIX_ACLS
408 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
409 {
410     EC_INIT;
411     struct stat st;
412
413     if (stat(path, &st) == -1)
414         EC_FAIL;
415
416     if (!S_ISDIR(st.st_mode)) {
417         /* set ACL on ressource fork */
418         EC_ZERO_ERR( acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl), AFPERR_MISC );
419     }
420     
421 EC_CLEANUP:
422     if (errno == ENOENT)
423         EC_STATUS(AFP_OK);
424     EC_EXIT;
425 }
426
427 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
428 {
429     EC_INIT;
430
431     if (dir)
432         EC_EXIT_STATUS(AFP_OK);
433
434     /* remove ACL from ressource fork */
435     EC_ZERO_ERR( remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC );
436
437 EC_CLEANUP:
438     if (errno == ENOENT)
439         EC_STATUS(AFP_OK);
440     EC_EXIT;
441 }
442 #endif
443
444 /*************************************************************************
445  * EA adouble format 
446  ************************************************************************/
447 static int validupath_ea(VFS_FUNC_ARGS_VALIDUPATH)
448 {
449     if (name[0] != '.')
450         return 1;
451     
452 #ifndef HAVE_EAFD
453     if (name[1] == '_')
454         return ad_valid_header_osx(name);
455 #endif
456     return netatalk_name(name);
457 }
458
459 /* ----------------- */
460 static int RF_chown_ea(VFS_FUNC_ARGS_CHOWN)
461 {
462 #ifndef HAVE_EAFD
463     return chown(vol->ad_path(path, ADFLAGS_HF ), uid, gid);
464 #endif
465     return 0;
466 }
467
468 /* ---------------- */
469 static int RF_renamedir_ea(VFS_FUNC_ARGS_RENAMEDIR)
470 {
471     return 0;
472 }
473
474 /* Returns 1 if the entry is NOT an ._ file */
475 static int deletecurdir_ea_osx_chkifempty_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
476 {
477     if (de->d_name[0] != '.' || de->d_name[0] == '_')
478         return 1;
479
480     return 0;
481 }
482
483 static int deletecurdir_ea_osx_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
484 {
485     int ret;
486     struct stat sb;
487
488     if (strncmp(name, "._", strlen("._")) == 0) {
489         if (lstat(name, &sb) != 0)
490             return -1;
491         if (S_ISREG(sb.st_mode))
492             if ((ret = netatalk_unlink(name)) != 0)
493                 return ret;
494     }
495
496     return 0;
497 }
498
499 /* ---------------- */
500 static int RF_deletecurdir_ea(VFS_FUNC_ARGS_DELETECURDIR)
501 {
502 #ifndef HAVE_EAFD
503     int err;
504     /* delete stray ._AppleDouble files */
505     if ((err = for_each_adouble("deletecurdir_ea_osx", ".",
506                                 deletecurdir_ea_osx_loop,
507                                 vol, NULL, 0)) != 0)
508         return err;
509
510 #endif
511     return 0;
512 }
513
514 /* ---------------- */
515 static int RF_setdirunixmode_ea(VFS_FUNC_ARGS_SETDIRUNIXMODE)
516 {
517 #ifndef HAVE_EAFD
518 #endif
519     return 0;
520 }
521
522 static int RF_setfilmode_ea(VFS_FUNC_ARGS_SETFILEMODE)
523 {
524 #ifndef HAVE_EAFD
525     return adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_HF ), mode, st);
526 #endif
527     return 0;
528 }
529
530 /* ---------------- */
531 static int RF_setdirmode_ea(VFS_FUNC_ARGS_SETDIRMODE)
532 {
533 #ifndef HAVE_EAFD
534 #endif
535     return 0;
536 }
537
538 /* ---------------- */
539 static int RF_setdirowner_ea(VFS_FUNC_ARGS_SETDIROWNER)
540 {
541 #ifndef HAVE_EAFD
542 #endif
543         return 0;
544 }
545
546 static int RF_deletefile_ea(VFS_FUNC_ARGS_DELETEFILE)
547 {
548 #ifndef HAVE_EAFD
549         return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
550 #endif
551     return 0;
552 }
553 static int RF_copyfile_ea(VFS_FUNC_ARGS_COPYFILE)
554 {
555 #ifdef HAVE_EAFD
556     /* the EA VFS module does this all for us */
557     return 0;
558 #endif
559
560     EC_INIT;
561     bstring s = NULL, d = NULL;
562     char *dup1 = NULL;
563     char *dup2 = NULL;
564     char *dup3 = NULL;
565     char *dup4 = NULL;
566     const char *name = NULL;
567     const char *dir = NULL;
568
569     /* get basename */
570
571     /* build src path to ._ file*/
572     EC_NULL(dup1 = strdup(src));
573     EC_NULL(name = basename(strdup(dup1)));
574
575     EC_NULL(dup2 = strdup(src));
576     EC_NULL(dir = dirname(dup2));
577     EC_NULL(s = bfromcstr(dir));
578     EC_ZERO(bcatcstr(s, "/._"));
579     EC_ZERO(bcatcstr(s, name));
580
581     /* build dst path to ._file*/
582     EC_NULL(dup4 = strdup(dst));
583     EC_NULL(name = basename(strdup(dup4)));
584
585     EC_NULL(dup3 = strdup(dst));
586     EC_NULL(dir = dirname(dup3));
587     EC_NULL(d = bfromcstr(dir));
588     EC_ZERO(bcatcstr(d, "/._"));
589     EC_ZERO(bcatcstr(d, name));
590
591     if (copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666) != 0) {
592         switch (errno) {
593         case ENOENT:
594             break;
595         default:
596             LOG(log_error, logtype_afpd, "[VFS] copyfile(\"%s\" -> \"%s\"): %s",
597                 cfrombstr(s), cfrombstr(d), strerror(errno));
598             EC_FAIL;
599                     
600         }
601     }
602
603 EC_CLEANUP:
604     bdestroy(s);
605     bdestroy(d);
606     free(dup1);
607     free(dup2);
608     free(dup3);
609     free(dup4);
610     EC_EXIT;
611 }
612
613 /* ---------------- */
614 static int RF_renamefile_ea(VFS_FUNC_ARGS_RENAMEFILE)
615 {
616 #ifndef HAVE_EAFD
617     char  adsrc[ MAXPATHLEN + 1];
618     int   err = 0;
619
620     strcpy( adsrc, vol->ad_path(src, 0 ));
621
622     if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
623         struct stat st;
624
625         err = errno;
626         if (errno == ENOENT && ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
627             return 0;
628         errno = err;
629         return -1;
630     }
631     return 0;
632 #endif
633     return 0;
634 }
635
636 /********************************************************************************************
637  * VFS chaining
638  ********************************************************************************************/
639
640 /* 
641  * Up until we really start stacking many VFS modules on top of one another or use
642  * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
643  * via an fixed size array.
644  * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
645  * this error code will be returned to the caller, BUT the chain in followed and all
646  * following funcs are called in order to give them a chance.
647  */
648
649 /* 
650  * Define most VFS funcs with macros as they all do the same.
651  * Only "ad_path" and "validupath" will NOT do stacking and only
652  * call the func from the first module.
653  */
654
655 #define VFS_MFUNC(name, args, vars) \
656     static int vfs_ ## name(args) \
657     { \
658         int i = 0, ret = AFP_OK, err; \
659         while (vol->vfs_modules[i]) { \
660             if (vol->vfs_modules[i]->vfs_ ## name) { \
661                 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
662                 if ((ret == AFP_OK) && (err != AFP_OK)) \
663                     ret = err; \
664             } \
665             i ++; \
666         } \
667         return ret; \
668     }
669
670 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
671 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR) 
672 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
673 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
674 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
675 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
676 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
677 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
678 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
679 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
680 #ifdef HAVE_ACLS
681 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
682 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
683 #endif
684 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
685 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
686 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
687 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
688 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
689
690 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
691 {
692     return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
693 }
694
695 /*
696  * These function pointers get called from the lib users via vol->vfs->func.
697  * These funcs are defined via the macros above.
698  */
699 static struct vfs_ops vfs_master_funcs = {
700     vfs_validupath,
701     vfs_chown,
702     vfs_renamedir,
703     vfs_deletecurdir,
704     vfs_setfilmode,
705     vfs_setdirmode,
706     vfs_setdirunixmode,
707     vfs_setdirowner,
708     vfs_deletefile,
709     vfs_renamefile,
710     vfs_copyfile,
711 #ifdef HAVE_ACLS
712     vfs_acl,
713     vfs_remove_acl,
714 #endif
715     vfs_ea_getsize,
716     vfs_ea_getcontent,
717     vfs_ea_list,
718     vfs_ea_set,
719     vfs_ea_remove
720 };
721
722 /* 
723  * Primary adouble modules: v2, ea
724  */
725
726 static struct vfs_ops netatalk_adouble_v2 = {
727     /* vfs_validupath:    */ validupath_adouble,
728     /* vfs_chown:         */ RF_chown_adouble,
729     /* vfs_renamedir:     */ RF_renamedir_adouble,
730     /* vfs_deletecurdir:  */ RF_deletecurdir_adouble,
731     /* vfs_setfilmode:    */ RF_setfilmode_adouble,
732     /* vfs_setdirmode:    */ RF_setdirmode_adouble,
733     /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
734     /* vfs_setdirowner:   */ RF_setdirowner_adouble,
735     /* vfs_deletefile:    */ RF_deletefile_adouble,
736     /* vfs_renamefile:    */ RF_renamefile_adouble,
737     /* vfs_copyfile:      */ RF_copyfile_adouble,
738     NULL
739 };
740
741 static struct vfs_ops netatalk_adouble_ea = {
742     /* vfs_validupath:    */ validupath_ea,
743     /* vfs_chown:         */ RF_chown_ea,
744     /* vfs_renamedir:     */ RF_renamedir_ea,
745     /* vfs_deletecurdir:  */ RF_deletecurdir_ea,
746     /* vfs_setfilmode:    */ RF_setfilmode_ea,
747     /* vfs_setdirmode:    */ RF_setdirmode_ea,
748     /* vfs_setdirunixmode:*/ RF_setdirunixmode_ea,
749     /* vfs_setdirowner:   */ RF_setdirowner_ea,
750     /* vfs_deletefile:    */ RF_deletefile_ea,
751     /* vfs_renamefile:    */ RF_renamefile_ea,
752     /* vfs_copyfile:      */ RF_copyfile_ea,
753     NULL
754 };
755
756 /* 
757  * Secondary vfs modules for Extended Attributes
758  */
759
760 static struct vfs_ops netatalk_ea_adouble = {
761     /* vfs_validupath:    */ NULL,
762     /* vfs_chown:         */ ea_chown,
763     /* vfs_renamedir:     */ NULL, /* ok */
764     /* vfs_deletecurdir:  */ NULL, /* ok */
765     /* vfs_setfilmode:    */ ea_chmod_file,
766     /* vfs_setdirmode:    */ NULL, /* ok */
767     /* vfs_setdirunixmode:*/ ea_chmod_dir,
768     /* vfs_setdirowner:   */ NULL, /* ok */
769     /* vfs_deletefile:    */ ea_deletefile,
770     /* vfs_renamefile:    */ ea_renamefile,
771     /* vfs_copyfile       */ ea_copyfile,
772 #ifdef HAVE_ACLS
773     /* vfs_acl:           */ NULL,
774     /* vfs_remove_acl     */ NULL,
775 #endif
776     /* vfs_getsize        */ get_easize,
777     /* vfs_getcontent     */ get_eacontent,
778     /* vfs_list           */ list_eas,
779     /* vfs_set            */ set_ea,
780     /* vfs_remove         */ remove_ea
781 };
782
783 static struct vfs_ops netatalk_ea_sys = {
784     /* validupath:        */ NULL,
785     /* rf_chown:          */ NULL,
786     /* rf_renamedir:      */ NULL,
787     /* rf_deletecurdir:   */ NULL,
788     /* rf_setfilmode:     */ NULL,
789     /* rf_setdirmode:     */ NULL,
790     /* rf_setdirunixmode: */ NULL,
791     /* rf_setdirowner:    */ NULL,
792     /* rf_deletefile:     */ NULL,
793     /* rf_renamefile:     */ NULL,
794     /* vfs_copyfile:      */ sys_ea_copyfile,
795 #ifdef HAVE_ACLS
796     /* rf_acl:            */ NULL,
797     /* rf_remove_acl      */ NULL,
798 #endif
799     /* ea_getsize         */ sys_get_easize,
800     /* ea_getcontent      */ sys_get_eacontent,
801     /* ea_list            */ sys_list_eas,
802     /* ea_set             */ sys_set_ea,
803     /* ea_remove          */ sys_remove_ea
804 };
805
806 /* 
807  * Tertiary VFS modules for ACLs
808  */
809
810 #ifdef HAVE_NFSV4_ACLS
811 static struct vfs_ops netatalk_solaris_acl_adouble = {
812     /* validupath:        */ NULL,
813     /* rf_chown:          */ NULL,
814     /* rf_renamedir:      */ NULL,
815     /* rf_deletecurdir:   */ NULL,
816     /* rf_setfilmode:     */ NULL,
817     /* rf_setdirmode:     */ NULL,
818     /* rf_setdirunixmode: */ NULL,
819     /* rf_setdirowner:    */ NULL,
820     /* rf_deletefile:     */ NULL,
821     /* rf_renamefile:     */ NULL,
822     /* vfs_copyfile       */ NULL,
823     /* rf_acl:            */ RF_solaris_acl,
824     /* rf_remove_acl      */ RF_solaris_remove_acl,
825     NULL
826 };
827 #endif
828
829 #ifdef HAVE_POSIX_ACLS
830 static struct vfs_ops netatalk_posix_acl_adouble = {
831     /* validupath:        */ NULL,
832     /* rf_chown:          */ NULL,
833     /* rf_renamedir:      */ NULL,
834     /* rf_deletecurdir:   */ NULL,
835     /* rf_setfilmode:     */ NULL,
836     /* rf_setdirmode:     */ NULL,
837     /* rf_setdirunixmode: */ NULL,
838     /* rf_setdirowner:    */ NULL,
839     /* rf_deletefile:     */ NULL,
840     /* rf_renamefile:     */ NULL,
841     /* vfs_copyfile       */ NULL,
842     /* rf_acl:            */ RF_posix_acl,
843     /* rf_remove_acl      */ RF_posix_remove_acl,
844     NULL
845 };
846 #endif
847
848 /* ---------------- */
849 void initvol_vfs(struct vol *vol)
850 {
851     vol->vfs = &vfs_master_funcs;
852
853     /* Default adouble stuff */
854     if (vol->v_adouble == AD_VERSION2) {
855         vol->vfs_modules[0] = &netatalk_adouble_v2;
856         vol->ad_path = ad_path;
857     } else {
858         vol->vfs_modules[0] = &netatalk_adouble_ea;
859 #ifdef HAVE_EAFD
860         vol->ad_path = ad_path_ea;
861 #else
862         vol->ad_path = ad_path_osx;
863 #endif
864     }
865
866     /* Extended Attributes */
867     if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
868         LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
869         vol->vfs_modules[1] = &netatalk_ea_sys;
870     } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
871         LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
872         vol->vfs_modules[1] = &netatalk_ea_adouble;
873     } else {
874         LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
875     }
876
877     /* ACLs */
878 #ifdef HAVE_NFSV4_ACLS
879     vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
880 #endif
881 #ifdef HAVE_POSIX_ACLS
882     vol->vfs_modules[2] = &netatalk_posix_acl_adouble;
883 #endif
884
885 }