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 */
28 #include <atalk/afp.h>
29 #include <atalk/adouble.h>
31 #include <atalk/acl.h>
32 #include <atalk/logger.h>
33 #include <atalk/util.h>
34 #include <atalk/volume.h>
35 #include <atalk/vfs.h>
36 #include <atalk/directory.h>
37 #include <atalk/unix.h>
44 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
46 /* ----------------------------- */
48 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
50 char buf[ MAXPATHLEN + 1];
57 if (NULL == ( dp = opendir( name)) ) {
59 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
64 strlcpy( buf, name, sizeof(buf));
65 strlcat( buf, "/", sizeof(buf) );
66 m = strchr( buf, '\0' );
68 while ((de = readdir(dp))) {
69 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
73 strlcat(buf, de->d_name, sizeof(buf));
74 if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
84 /*******************************************************************************
85 * classic adouble format
86 *******************************************************************************/
88 static int netatalk_name(const char *name)
90 return strcasecmp(name,".AppleDouble") &&
91 strcasecmp(name,".AppleDB") &&
92 strcasecmp(name,".AppleDesktop");
95 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
100 if (!(vol->v_flags & AFPVOL_USEDOTS))
103 return netatalk_name(name) && strcasecmp(name,".Parent");
106 /* ----------------- */
107 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
112 ad_p = vol->ad_path(path, ADFLAGS_HF );
114 if ( stat( ad_p, &st ) < 0 )
115 return 0; /* ignore */
117 return chown( ad_p, uid, gid );
120 /* ----------------- */
121 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
126 /* ----------------- */
127 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
132 /* bail if the file exists in the current directory.
133 * note: this will not fail with dangling symlinks */
135 if (stat(de->d_name, &st) == 0)
136 return AFPERR_DIRNEMPT;
138 if ((err = netatalk_unlink(name)))
144 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
148 /* delete stray .AppleDouble files. this happens to get .Parent files
150 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask)))
152 return netatalk_rmdir(-1, ".AppleDouble" );
155 /* ----------------- */
156 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
158 return setfilmode(name, ad_hf_mode(mode), st, v_umask);
161 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
163 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_HF ), mode, st, vol->v_umask);
166 /* ----------------- */
167 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
169 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
170 int dropbox = vol->v_flags;
172 if (dir_rx_set(mode)) {
173 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
177 if (adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0)
180 if (!dir_rx_set(mode)) {
181 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
187 /* ----------------- */
188 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
190 mode_t hf_mode = *(mode_t *)data;
193 if ( stat( name, &st ) < 0 ) {
196 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
198 else if (!S_ISDIR(st.st_mode)) {
199 if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
200 /* FIXME what do we do then? */
206 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
208 int dropbox = vol->v_flags;
209 mode_t hf_mode = ad_hf_mode(mode);
210 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
211 char *adouble_p = ad_dir(adouble);
213 if (dir_rx_set(mode)) {
214 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
218 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
221 if (!dir_rx_set(mode)) {
222 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
228 /* ----------------- */
229 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
231 struct perm *owner = data;
233 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
234 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
235 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
236 /* return ( -1 ); Sometimes this is okay */
241 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
243 int noadouble = vol_noadouble(vol);
251 adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
253 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask))
257 * We cheat: we know that chown doesn't do anything.
259 if ( stat( ".AppleDouble", &st ) < 0) {
260 if (errno == ENOENT && noadouble)
262 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
265 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
266 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
267 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
268 /* return ( -1 ); Sometimes this is okay */
273 /* ----------------- */
274 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
276 return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
279 /* ----------------- */
280 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
282 char adsrc[ MAXPATHLEN + 1];
285 strcpy( adsrc, vol->ad_path(src, 0 ));
286 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
290 if (errno == ENOENT) {
293 if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
296 /* We are here because :
297 * -there's no dest folder.
298 * -there's no .AppleDouble in the dest folder.
299 * if we use the struct adouble passed in parameter it will not
300 * create .AppleDouble if the file is already opened, so we
301 * use a diff one, it's not a pb,ie it's not the same file, yet.
303 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
304 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
305 ad_close(&ad, ADFLAGS_HF);
306 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) )
311 else { /* it's something else, bail out */
323 #ifdef HAVE_NFSv4_ACLS
324 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
326 static char buf[ MAXPATHLEN + 1];
330 if ((stat(path, &st)) != 0)
332 if (S_ISDIR(st.st_mode)) {
333 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
334 if (len < 0 || len >= MAXPATHLEN)
336 /* set acl on .AppleDouble dir first */
337 if ((acl(buf, cmd, count, aces)) != 0)
339 /* now set ACL on ressource fork */
340 if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
343 /* set ACL on ressource fork */
344 if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
350 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
353 static char buf[ MAXPATHLEN + 1];
357 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
358 if (len < 0 || len >= MAXPATHLEN)
360 /* remove ACL from .AppleDouble/.Parent first */
361 if ((ret = remove_acl(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
363 /* now remove from .AppleDouble dir */
364 if ((ret = remove_acl(buf)) != AFP_OK)
367 /* remove ACL from ressource fork */
368 if ((ret = remove_acl(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
375 /*********************************************************************************
377 *********************************************************************************/
378 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
380 struct perm *owner = data;
382 if (chown( name , owner->uid, owner->gid ) < 0) {
388 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
398 ad_p = ad_dir(vol->ad_path(path, ADFLAGS_HF ));
400 if ( stat( ad_p, &st ) < 0 ) {
405 if (chown( ad_p, uid, gid ) < 0) {
408 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
411 /* --------------------------------- */
412 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
414 return netatalk_unlink(name);
417 static int ads_delete_rf(char *name)
421 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
424 * it's a problem for a nfs mounted folder, there's .nfsxxx around
425 * for linux the following line solve it.
426 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
428 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
430 return netatalk_rmdir(-1, name);
433 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
437 /* bail if the file exists in the current directory.
438 * note: this will not fail with dangling symlinks */
440 if (stat(de->d_name, &st) == 0) {
441 return AFPERR_DIRNEMPT;
443 return ads_delete_rf(name);
446 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
450 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
451 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
454 return netatalk_rmdir(-1, ".AppleDouble" );
457 /* ------------------- */
463 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
465 struct set_mode *param = data;
467 return setfilmode(name, param->mode, param->st, v_umask);
470 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
472 mode_t file_mode = ad_hf_mode(mode);
473 mode_t dir_mode = file_mode;
474 struct set_mode param;
476 if ((dir_mode & (S_IRUSR | S_IWUSR )))
478 if ((dir_mode & (S_IRGRP | S_IWGRP )))
480 if ((dir_mode & (S_IROTH | S_IWOTH )))
485 if (dir_rx_set(dir_mode)) {
486 if (chmod( name, dir_mode ) < 0)
490 param.mode = file_mode;
491 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
494 if (!dir_rx_set(dir_mode)) {
495 if (chmod( name, dir_mode ) < 0)
502 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
504 return ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_HF )), mode, st, vol->v_umask);
507 /* ------------------- */
508 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
510 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
511 char ad_p[ MAXPATHLEN + 1];
512 int dropbox = vol->v_flags;
514 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
516 if (dir_rx_set(mode)) {
519 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
522 /* .AppleDouble/.Parent */
523 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
527 if (ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
530 if (!dir_rx_set(mode)) {
531 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
533 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
539 /* ------------------- */
545 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
548 struct dir_mode *param = data;
549 int ret = 0; /* 0 ignore error, -1 */
551 if (dir_rx_set(param->mode)) {
552 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
559 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
562 if (!dir_rx_set(param->mode)) {
563 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
573 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
575 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
576 char ad_p[ MAXPATHLEN + 1];
577 struct dir_mode param;
580 param.dropbox = vol->v_flags;
582 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
584 if (dir_rx_set(mode)) {
586 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
590 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
593 if (!dir_rx_set(mode)) {
594 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
600 /* ------------------- */
601 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
603 struct perm *owner = data;
605 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
606 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
607 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
608 /* return ( -1 ); Sometimes this is okay */
613 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
615 struct perm *owner = data;
617 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
620 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
621 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
622 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
623 /* return ( -1 ); Sometimes this is okay */
628 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
630 int noadouble = vol_noadouble(vol);
631 char adouble_p[ MAXPATHLEN + 1];
638 strlcpy(adouble_p, ad_dir(vol->ad_path(name, ADFLAGS_DIR )), sizeof(adouble_p));
640 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
644 * We cheat: we know that chown doesn't do anything.
646 if ( stat( ".AppleDouble", &st ) < 0) {
647 if (errno == ENOENT && noadouble)
649 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
652 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
653 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
654 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
655 /* return ( -1 ); Sometimes this is okay */
660 /* ------------------- */
661 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
667 ad_p = ad_dir(vol->ad_path(file, ADFLAGS_HF ));
670 if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
676 ret = ads_delete_rf(ad_p);
678 if (dirfd != -1 && fchdir(cwd) != 0) {
679 LOG(log_error, logtype_afpd, "RF_deletefile_ads: cant chdir back. exit!");
690 /* --------------------------- */
691 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
693 char adsrc[ MAXPATHLEN + 1];
696 strcpy( adsrc, ad_dir(vol->ad_path(src, 0 )));
697 if (unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) < 0) {
701 if (errno == ENOENT) {
704 if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
707 /* We are here because :
708 * -there's no dest folder.
709 * -there's no .AppleDouble in the dest folder.
710 * if we use the struct adouble passed in parameter it will not
711 * create .AppleDouble if the file is already opened, so we
712 * use a diff one, it's not a pb,ie it's not the same file, yet.
714 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
715 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
716 ad_close(&ad, ADFLAGS_HF);
718 /* We must delete it */
719 RF_deletefile_ads(vol, -1, dst );
720 if (!unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) )
725 else { /* it's something else, bail out */
737 /*************************************************************************
739 ************************************************************************/
740 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
742 return strncmp(name,"._", 2) && (
743 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
746 /* ---------------- */
747 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
749 /* We simply move the corresponding ad file as well */
750 char tempbuf[258]="._";
751 return unix_rename(dirfd, vol->ad_path(oldpath,0), -1, strcat(tempbuf,newpath));
754 /* ---------------- */
755 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
757 return netatalk_unlink( vol->ad_path(".",0) );
760 /* ---------------- */
761 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
763 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask);
766 /* ---------------- */
767 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
772 /* ---------------- */
773 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
778 /* ---------------- */
779 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
781 char adsrc[ MAXPATHLEN + 1];
784 strcpy( adsrc, vol->ad_path(src, 0 ));
786 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
790 if (errno == ENOENT && lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
798 /********************************************************************************************
800 ********************************************************************************************/
803 * Up until we really start stacking many VFS modules on top of one another or use
804 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
805 * via an fixed size array.
806 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
807 * this error code will be returned to the caller, BUT the chain in followed and all
808 * following funcs are called in order to give them a chance.
812 * Define most VFS funcs with macros as they all do the same.
813 * Only "ad_path" and "validupath" will NOT do stacking and only
814 * call the func from the first module.
817 #define VFS_MFUNC(name, args, vars) \
818 static int vfs_ ## name(args) \
820 int i = 0, ret = AFP_OK, err; \
821 while (vol->vfs_modules[i]) { \
822 if (vol->vfs_modules[i]->vfs_ ## name) { \
823 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
824 if ((ret == AFP_OK) && (err != AFP_OK)) \
832 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
833 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
834 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
835 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
836 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
837 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
838 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
839 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
840 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
841 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
842 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
843 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
844 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
845 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
846 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
847 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
848 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
850 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
852 return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
856 * These function pointers get called from the lib users via vol->vfs->func.
857 * These funcs are defined via the macros above.
859 static struct vfs_ops vfs_master_funcs = {
881 * Primary adouble modules: default, osx, sfm
884 static struct vfs_ops netatalk_adouble = {
885 /* vfs_validupath: */ validupath_adouble,
886 /* vfs_chown: */ RF_chown_adouble,
887 /* vfs_renamedir: */ RF_renamedir_adouble,
888 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
889 /* vfs_setfilmode: */ RF_setfilmode_adouble,
890 /* vfs_setdirmode: */ RF_setdirmode_adouble,
891 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
892 /* vfs_setdirowner: */ RF_setdirowner_adouble,
893 /* vfs_deletefile: */ RF_deletefile_adouble,
894 /* vfs_renamefile: */ RF_renamefile_adouble,
895 /* vfs_copyfile: */ NULL,
899 static struct vfs_ops netatalk_adouble_osx = {
900 /* vfs_validupath: */ validupath_osx,
901 /* vfs_chown: */ RF_chown_adouble,
902 /* vfs_renamedir: */ RF_renamedir_osx,
903 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
904 /* vfs_setfilmode: */ RF_setfilmode_adouble,
905 /* vfs_setdirmode: */ RF_setdirmode_osx,
906 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
907 /* vfs_setdirowner: */ RF_setdirowner_osx,
908 /* vfs_deletefile: */ RF_deletefile_adouble,
909 /* vfs_renamefile: */ RF_renamefile_osx,
910 /* vfs_copyfile: */ NULL,
914 /* samba sfm format. ad_path shouldn't be set her */
915 static struct vfs_ops netatalk_adouble_sfm = {
916 /* vfs_validupath: */ validupath_adouble,
917 /* vfs_chown: */ RF_chown_ads,
918 /* vfs_renamedir: */ RF_renamedir_adouble,
919 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
920 /* vfs_setfilmode: */ RF_setfilmode_ads,
921 /* vfs_setdirmode: */ RF_setdirmode_ads,
922 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
923 /* vfs_setdirowner: */ RF_setdirowner_ads,
924 /* vfs_deletefile: */ RF_deletefile_ads,
925 /* vfs_renamefile: */ RF_renamefile_ads,
926 /* vfs_copyfile: */ NULL,
931 * Secondary vfs modules for Extended Attributes
934 static struct vfs_ops netatalk_ea_adouble = {
935 /* vfs_validupath: */ NULL,
936 /* vfs_chown: */ ea_chown,
937 /* vfs_renamedir: */ NULL, /* ok */
938 /* vfs_deletecurdir: */ NULL, /* ok */
939 /* vfs_setfilmode: */ ea_chmod_file,
940 /* vfs_setdirmode: */ NULL, /* ok */
941 /* vfs_setdirunixmode:*/ ea_chmod_dir,
942 /* vfs_setdirowner: */ NULL, /* ok */
943 /* vfs_deletefile: */ ea_deletefile,
944 /* vfs_renamefile: */ ea_renamefile,
945 /* vfs_copyfile */ ea_copyfile,
947 /* vfs_remove_acl */ NULL,
948 /* vfs_getsize */ get_easize,
949 /* vfs_getcontent */ get_eacontent,
950 /* vfs_list */ list_eas,
951 /* vfs_set */ set_ea,
952 /* vfs_remove */ remove_ea
955 static struct vfs_ops netatalk_ea_sys = {
956 /* validupath: */ NULL,
957 /* rf_chown: */ NULL,
958 /* rf_renamedir: */ NULL,
959 /* rf_deletecurdir: */ NULL,
960 /* rf_setfilmode: */ NULL,
961 /* rf_setdirmode: */ NULL,
962 /* rf_setdirunixmode: */ NULL,
963 /* rf_setdirowner: */ NULL,
964 /* rf_deletefile: */ NULL,
965 /* rf_renamefile: */ NULL,
966 /* vfs_copyfile: */ sys_ea_copyfile,
968 /* rf_remove_acl */ NULL,
969 /* ea_getsize */ sys_get_easize,
970 /* ea_getcontent */ sys_get_eacontent,
971 /* ea_list */ sys_list_eas,
972 /* ea_set */ sys_set_ea,
973 /* ea_remove */ sys_remove_ea
977 * Tertiary VFS modules for ACLs
980 #ifdef HAVE_NFSv4_ACLS
981 static struct vfs_ops netatalk_solaris_acl_adouble = {
982 /* validupath: */ NULL,
983 /* rf_chown: */ NULL,
984 /* rf_renamedir: */ NULL,
985 /* rf_deletecurdir: */ NULL,
986 /* rf_setfilmode: */ NULL,
987 /* rf_setdirmode: */ NULL,
988 /* rf_setdirunixmode: */ NULL,
989 /* rf_setdirowner: */ NULL,
990 /* rf_deletefile: */ NULL,
991 /* rf_renamefile: */ NULL,
992 /* vfs_copyfile */ NULL,
993 /* rf_acl: */ RF_solaris_acl,
994 /* rf_remove_acl */ RF_solaris_remove_acl,
999 /* ---------------- */
1000 void initvol_vfs(struct vol *vol)
1002 vol->vfs = &vfs_master_funcs;
1004 /* Default adouble stuff */
1005 if (vol->v_adouble == AD_VERSION2_OSX) {
1006 vol->vfs_modules[0] = &netatalk_adouble_osx;
1007 vol->ad_path = ad_path_osx;
1009 else if (vol->v_adouble == AD_VERSION1_SFM) {
1010 vol->vfs_modules[0] = &netatalk_adouble_sfm;
1011 vol->ad_path = ad_path_sfm;
1014 vol->vfs_modules[0] = &netatalk_adouble;
1015 vol->ad_path = ad_path;
1018 /* Extended Attributes */
1019 if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
1020 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
1021 vol->vfs_modules[1] = &netatalk_ea_sys;
1022 } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
1023 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
1024 vol->vfs_modules[1] = &netatalk_ea_adouble;
1026 LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
1030 #ifdef HAVE_NFSv4_ACLS
1031 vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;