2 Copyright (c) 2004 Didier Gautheron
3 Copyright (c) 2009 Frank Lahm
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.
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.
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.
22 #endif /* HAVE_CONFIG_H */
27 #include <atalk/afp.h>
28 #include <atalk/adouble.h>
30 #include <atalk/acl.h>
31 #include <atalk/logger.h>
32 #include <atalk/util.h>
33 #include <atalk/volume.h>
34 #include <atalk/vfs.h>
35 #include <atalk/directory.h>
36 #include <atalk/unix.h>
43 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
45 /* ----------------------------- */
47 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
49 char buf[ MAXPATHLEN + 1];
56 if (NULL == ( dp = opendir( name)) ) {
58 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
63 strlcpy( buf, name, sizeof(buf));
64 strlcat( buf, "/", sizeof(buf) );
65 m = strchr( buf, '\0' );
67 while ((de = readdir(dp))) {
68 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
72 strlcat(buf, de->d_name, sizeof(buf));
73 if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
83 /*******************************************************************************
84 * classic adouble format
85 *******************************************************************************/
87 static int netatalk_name(const char *name)
89 return strcasecmp(name,".AppleDouble") &&
90 strcasecmp(name,".AppleDB") &&
91 strcasecmp(name,".AppleDesktop");
94 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
99 if (!(vol->v_flags & AFPVOL_USEDOTS))
102 return netatalk_name(name) && strcasecmp(name,".Parent");
105 /* ----------------- */
106 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
111 ad_p = vol->ad_path(path, ADFLAGS_HF );
113 if ( stat( ad_p, &st ) < 0 )
114 return 0; /* ignore */
116 return chown( ad_p, uid, gid );
119 /* ----------------- */
120 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
125 /* ----------------- */
126 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
131 /* bail if the file exists in the current directory.
132 * note: this will not fail with dangling symlinks */
134 if (stat(de->d_name, &st) == 0)
135 return AFPERR_DIRNEMPT;
137 if ((err = netatalk_unlink(name)))
143 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
147 /* delete stray .AppleDouble files. this happens to get .Parent files
149 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask)))
151 return netatalk_rmdir( ".AppleDouble" );
154 /* ----------------- */
155 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
157 return setfilmode(name, ad_hf_mode(mode), st, v_umask);
160 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
162 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_HF ), mode, st, vol->v_umask);
165 /* ----------------- */
166 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
168 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
169 int dropbox = vol->v_flags;
171 if (dir_rx_set(mode)) {
172 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
176 if (adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0)
179 if (!dir_rx_set(mode)) {
180 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
186 /* ----------------- */
187 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
189 mode_t hf_mode = *(mode_t *)data;
192 if ( stat( name, &st ) < 0 ) {
195 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
197 else if (!S_ISDIR(st.st_mode)) {
198 if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
199 /* FIXME what do we do then? */
205 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
207 int dropbox = vol->v_flags;
208 mode_t hf_mode = ad_hf_mode(mode);
209 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
210 char *adouble_p = ad_dir(adouble);
212 if (dir_rx_set(mode)) {
213 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
217 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
220 if (!dir_rx_set(mode)) {
221 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
227 /* ----------------- */
228 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
230 struct perm *owner = data;
232 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
233 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
234 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
235 /* return ( -1 ); Sometimes this is okay */
240 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
242 int noadouble = vol_noadouble(vol);
250 adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
252 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask))
256 * We cheat: we know that chown doesn't do anything.
258 if ( stat( ".AppleDouble", &st ) < 0) {
259 if (errno == ENOENT && noadouble)
261 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
264 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
265 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
266 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
267 /* return ( -1 ); Sometimes this is okay */
272 /* ----------------- */
273 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
275 return netatalk_unlink(vol->ad_path(file, ADFLAGS_HF));
278 /* ----------------- */
279 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
281 char adsrc[ MAXPATHLEN + 1];
284 strcpy( adsrc, vol->ad_path(src, 0 ));
285 if (unix_rename( adsrc, vol->ad_path(dst, 0 )) < 0) {
289 if (errno == ENOENT) {
292 if (stat(adsrc, &st)) /* source has no ressource fork, */
295 /* We are here because :
296 * -there's no dest folder.
297 * -there's no .AppleDouble in the dest folder.
298 * if we use the struct adouble passed in parameter it will not
299 * create .AppleDouble if the file is already opened, so we
300 * use a diff one, it's not a pb,ie it's not the same file, yet.
302 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
303 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
304 ad_close(&ad, ADFLAGS_HF);
305 if (!unix_rename( adsrc, vol->ad_path(dst, 0 )) )
310 else { /* it's something else, bail out */
322 #ifdef HAVE_NFSv4_ACLS
323 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
325 static char buf[ MAXPATHLEN + 1];
329 if ((stat(path, &st)) != 0)
331 if (S_ISDIR(st.st_mode)) {
332 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
333 if (len < 0 || len >= MAXPATHLEN)
335 /* set acl on .AppleDouble dir first */
336 if ((acl(buf, cmd, count, aces)) != 0)
338 /* now set ACL on ressource fork */
339 if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
342 /* set ACL on ressource fork */
343 if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
349 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
352 static char buf[ MAXPATHLEN + 1];
356 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
357 if (len < 0 || len >= MAXPATHLEN)
359 /* remove ACL from .AppleDouble/.Parent first */
360 if ((ret = remove_acl(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
362 /* now remove from .AppleDouble dir */
363 if ((ret = remove_acl(buf)) != AFP_OK)
366 /* remove ACL from ressource fork */
367 if ((ret = remove_acl(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
374 /*********************************************************************************
376 *********************************************************************************/
377 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
379 struct perm *owner = data;
381 if (chown( name , owner->uid, owner->gid ) < 0) {
387 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
397 ad_p = ad_dir(vol->ad_path(path, ADFLAGS_HF ));
399 if ( stat( ad_p, &st ) < 0 ) {
404 if (chown( ad_p, uid, gid ) < 0) {
407 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
410 /* --------------------------------- */
411 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
413 return netatalk_unlink(name);
416 static int ads_delete_rf(char *name)
420 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
423 * it's a problem for a nfs mounted folder, there's .nfsxxx around
424 * for linux the following line solve it.
425 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
427 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
429 return netatalk_rmdir(name);
432 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
436 /* bail if the file exists in the current directory.
437 * note: this will not fail with dangling symlinks */
439 if (stat(de->d_name, &st) == 0) {
440 return AFPERR_DIRNEMPT;
442 return ads_delete_rf(name);
445 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
449 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
450 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
452 return netatalk_rmdir( ".AppleDouble" );
455 /* ------------------- */
461 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
463 struct set_mode *param = data;
465 return setfilmode(name, param->mode, param->st, v_umask);
468 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
470 mode_t file_mode = ad_hf_mode(mode);
471 mode_t dir_mode = file_mode;
472 struct set_mode param;
474 if ((dir_mode & (S_IRUSR | S_IWUSR )))
476 if ((dir_mode & (S_IRGRP | S_IWGRP )))
478 if ((dir_mode & (S_IROTH | S_IWOTH )))
483 if (dir_rx_set(dir_mode)) {
484 if (chmod( name, dir_mode ) < 0)
488 param.mode = file_mode;
489 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
492 if (!dir_rx_set(dir_mode)) {
493 if (chmod( name, dir_mode ) < 0)
500 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
502 return ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_HF )), mode, st, vol->v_umask);
505 /* ------------------- */
506 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
508 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
509 char ad_p[ MAXPATHLEN + 1];
510 int dropbox = vol->v_flags;
512 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
514 if (dir_rx_set(mode)) {
517 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
520 /* .AppleDouble/.Parent */
521 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
525 if (ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
528 if (!dir_rx_set(mode)) {
529 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
531 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
537 /* ------------------- */
543 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
546 struct dir_mode *param = data;
547 int ret = 0; /* 0 ignore error, -1 */
549 if (dir_rx_set(param->mode)) {
550 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
557 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
560 if (!dir_rx_set(param->mode)) {
561 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
571 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
573 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
574 char ad_p[ MAXPATHLEN + 1];
575 struct dir_mode param;
578 param.dropbox = vol->v_flags;
580 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
582 if (dir_rx_set(mode)) {
584 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
588 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
591 if (!dir_rx_set(mode)) {
592 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
598 /* ------------------- */
599 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
601 struct perm *owner = data;
603 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
604 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
605 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
606 /* return ( -1 ); Sometimes this is okay */
611 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
613 struct perm *owner = data;
615 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
618 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
619 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
620 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
621 /* return ( -1 ); Sometimes this is okay */
626 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
628 int noadouble = vol_noadouble(vol);
629 char adouble_p[ MAXPATHLEN + 1];
636 strlcpy(adouble_p, ad_dir(vol->ad_path(name, ADFLAGS_DIR )), sizeof(adouble_p));
638 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
642 * We cheat: we know that chown doesn't do anything.
644 if ( stat( ".AppleDouble", &st ) < 0) {
645 if (errno == ENOENT && noadouble)
647 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
650 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
651 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
652 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
653 /* return ( -1 ); Sometimes this is okay */
658 /* ------------------- */
659 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
661 char *ad_p = ad_dir(vol->ad_path(file, ADFLAGS_HF ));
663 return ads_delete_rf(ad_p);
666 /* --------------------------- */
667 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
669 char adsrc[ MAXPATHLEN + 1];
672 strcpy( adsrc, ad_dir(vol->ad_path(src, 0 )));
673 if (unix_rename( adsrc, ad_dir(vol->ad_path(dst, 0 ))) < 0) {
677 if (errno == ENOENT) {
680 if (stat(adsrc, &st)) /* source has no ressource fork, */
683 /* We are here because :
684 * -there's no dest folder.
685 * -there's no .AppleDouble in the dest folder.
686 * if we use the struct adouble passed in parameter it will not
687 * create .AppleDouble if the file is already opened, so we
688 * use a diff one, it's not a pb,ie it's not the same file, yet.
690 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
691 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
692 ad_close(&ad, ADFLAGS_HF);
694 /* We must delete it */
695 RF_deletefile_ads(vol, dst );
696 if (!unix_rename( adsrc, ad_dir(vol->ad_path(dst, 0 ))) )
701 else { /* it's something else, bail out */
713 /*************************************************************************
715 ************************************************************************/
716 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
718 return strncmp(name,"._", 2) && (
719 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
722 /* ---------------- */
723 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
725 /* We simply move the corresponding ad file as well */
726 char tempbuf[258]="._";
727 return rename(vol->ad_path(oldpath,0),strcat(tempbuf,newpath));
730 /* ---------------- */
731 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
733 return netatalk_unlink( vol->ad_path(".",0) );
736 /* ---------------- */
737 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
739 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask);
742 /* ---------------- */
743 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
748 /* ---------------- */
749 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
754 /* ---------------- */
755 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
757 char adsrc[ MAXPATHLEN + 1];
760 strcpy( adsrc, vol->ad_path(src, 0 ));
762 if (unix_rename( adsrc, vol->ad_path(dst, 0 )) < 0) {
766 if (errno == ENOENT && stat(adsrc, &st)) /* source has no ressource fork, */
774 /********************************************************************************************
776 ********************************************************************************************/
779 * Up until we really start stacking many VFS modules on top of one another or use
780 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
781 * via an fixed size array.
782 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
783 * this error code will be returned to the caller, BUT the chain in followed and all
784 * following funcs are called in order to give them a chance.
788 * Define most VFS funcs with macros as they all do the same.
789 * Only "ad_path" and "validupath" will NOT do stacking and only
790 * call the func from the first module.
793 #define VFS_MFUNC(name, args, vars) \
794 static int vfs_ ## name(args) \
796 int i = 0, ret = AFP_OK, err; \
797 while (vol->vfs_modules[i]) { \
798 if (vol->vfs_modules[i]->vfs_ ## name) { \
799 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
800 if ((ret == AFP_OK) && (err != AFP_OK)) \
808 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
809 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
810 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
811 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
812 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
813 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
814 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
815 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
816 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
817 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
818 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
819 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
820 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
821 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
822 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
823 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
824 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
826 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
828 return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
832 * These function pointers get called from the lib users via vol->vfs->func.
833 * These funcs are defined via the macros above.
835 static struct vfs_ops vfs_master_funcs = {
857 * Primary adouble modules: default, osx, sfm
860 static struct vfs_ops netatalk_adouble = {
861 /* vfs_validupath: */ validupath_adouble,
862 /* vfs_chown: */ RF_chown_adouble,
863 /* vfs_renamedir: */ RF_renamedir_adouble,
864 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
865 /* vfs_setfilmode: */ RF_setfilmode_adouble,
866 /* vfs_setdirmode: */ RF_setdirmode_adouble,
867 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
868 /* vfs_setdirowner: */ RF_setdirowner_adouble,
869 /* vfs_deletefile: */ RF_deletefile_adouble,
870 /* vfs_renamefile: */ RF_renamefile_adouble,
874 static struct vfs_ops netatalk_adouble_osx = {
875 /* vfs_validupath: */ validupath_osx,
876 /* vfs_chown: */ RF_chown_adouble,
877 /* vfs_renamedir: */ RF_renamedir_osx,
878 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
879 /* vfs_setfilmode: */ RF_setfilmode_adouble,
880 /* vfs_setdirmode: */ RF_setdirmode_osx,
881 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
882 /* vfs_setdirowner: */ RF_setdirowner_osx,
883 /* vfs_deletefile: */ RF_deletefile_adouble,
884 /* vfs_renamefile: */ RF_renamefile_osx,
888 /* samba sfm format. ad_path shouldn't be set her */
889 static struct vfs_ops netatalk_adouble_sfm = {
890 /* vfs_validupath: */ validupath_adouble,
891 /* vfs_chown: */ RF_chown_ads,
892 /* vfs_renamedir: */ RF_renamedir_adouble,
893 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
894 /* vfs_setfilmode: */ RF_setfilmode_ads,
895 /* vfs_setdirmode: */ RF_setdirmode_ads,
896 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
897 /* vfs_setdirowner: */ RF_setdirowner_ads,
898 /* vfs_deletefile: */ RF_deletefile_ads,
899 /* vfs_renamefile: */ RF_renamefile_ads,
904 * Secondary vfs modules for Extended Attributes
907 static struct vfs_ops netatalk_ea_adouble = {
908 /* vfs_validupath: */ NULL,
909 /* vfs_chown: */ ea_chown,
910 /* vfs_renamedir: */ NULL, /* ok */
911 /* vfs_deletecurdir: */ NULL, /* ok */
912 /* vfs_setfilmode: */ ea_chmod_file,
913 /* vfs_setdirmode: */ NULL, /* ok */
914 /* vfs_setdirunixmode:*/ ea_chmod_dir,
915 /* vfs_setdirowner: */ NULL, /* ok */
916 /* vfs_deletefile: */ ea_deletefile,
917 /* vfs_renamefile: */ ea_renamefile,
918 /* vfs_copyfile */ ea_copyfile,
920 /* vfs_remove_acl */ NULL,
921 /* vfs_getsize */ get_easize,
922 /* vfs_getcontent */ get_eacontent,
923 /* vfs_list */ list_eas,
924 /* vfs_set */ set_ea,
925 /* vfs_remove */ remove_ea
928 static struct vfs_ops netatalk_ea_sys = {
929 /* validupath: */ NULL,
930 /* rf_chown: */ NULL,
931 /* rf_renamedir: */ NULL,
932 /* rf_deletecurdir: */ NULL,
933 /* rf_setfilmode: */ NULL,
934 /* rf_setdirmode: */ NULL,
935 /* rf_setdirunixmode: */ NULL,
936 /* rf_setdirowner: */ NULL,
937 /* rf_deletefile: */ NULL,
938 /* rf_renamefile: */ NULL,
939 /* vfs_copyfile: */ sys_ea_copyfile,
941 /* rf_remove_acl */ NULL,
942 /* ea_getsize */ sys_get_easize,
943 /* ea_getcontent */ sys_get_eacontent,
944 /* ea_list */ sys_list_eas,
945 /* ea_set */ sys_set_ea,
946 /* ea_remove */ sys_remove_ea
950 * Tertiary VFS modules for ACLs
953 #ifdef HAVE_NFSv4_ACLS
954 static struct vfs_ops netatalk_solaris_acl_adouble = {
955 /* validupath: */ NULL,
956 /* rf_chown: */ NULL,
957 /* rf_renamedir: */ NULL,
958 /* rf_deletecurdir: */ NULL,
959 /* rf_setfilmode: */ NULL,
960 /* rf_setdirmode: */ NULL,
961 /* rf_setdirunixmode: */ NULL,
962 /* rf_setdirowner: */ NULL,
963 /* rf_deletefile: */ NULL,
964 /* rf_renamefile: */ NULL,
965 /* vfs_copyfile */ NULL,
966 /* rf_acl: */ RF_solaris_acl,
967 /* rf_remove_acl */ RF_solaris_remove_acl,
972 /* ---------------- */
973 void initvol_vfs(struct vol *vol)
975 vol->vfs = &vfs_master_funcs;
977 /* Default adouble stuff */
978 if (vol->v_adouble == AD_VERSION2_OSX) {
979 vol->vfs_modules[0] = &netatalk_adouble_osx;
980 vol->ad_path = ad_path_osx;
982 else if (vol->v_adouble == AD_VERSION1_SFM) {
983 vol->vfs_modules[0] = &netatalk_adouble_sfm;
984 vol->ad_path = ad_path_sfm;
987 vol->vfs_modules[0] = &netatalk_adouble;
988 vol->ad_path = ad_path;
991 /* Extended Attributes */
992 if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
993 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with native EAs.");
994 vol->vfs_modules[1] = &netatalk_ea_sys;
996 /* default: AFPVOL_EA_AD */
997 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with adouble files.");
998 vol->vfs_modules[1] = &netatalk_ea_adouble;
1002 #ifdef HAVE_NFSv4_ACLS
1003 vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;