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 */
29 #include <atalk/afp.h>
30 #include <atalk/adouble.h>
32 #include <atalk/acl.h>
33 #include <atalk/logger.h>
34 #include <atalk/util.h>
35 #include <atalk/volume.h>
36 #include <atalk/vfs.h>
37 #include <atalk/directory.h>
38 #include <atalk/unix.h>
39 #include <atalk/errchk.h>
40 #include <atalk/bstrlib.h>
41 #include <atalk/bstradd.h>
48 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
50 /* ----------------------------- */
52 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
54 char buf[ MAXPATHLEN + 1];
61 if (NULL == ( dp = opendir( name)) ) {
63 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
68 strlcpy( buf, name, sizeof(buf));
69 strlcat( buf, "/", sizeof(buf) );
70 m = strchr( buf, '\0' );
72 while ((de = readdir(dp))) {
73 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
77 strlcat(buf, de->d_name, sizeof(buf));
78 if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
88 /*******************************************************************************
89 * classic adouble format
90 *******************************************************************************/
92 static int netatalk_name(const char *name)
94 return strcasecmp(name,".AppleDouble") &&
95 strcasecmp(name,".AppleDB") &&
96 strcasecmp(name,".AppleDesktop");
99 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
104 if (!(vol->v_flags & AFPVOL_USEDOTS))
107 return netatalk_name(name) && strcasecmp(name,".Parent");
110 /* ----------------- */
111 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
116 ad_p = vol->ad_path(path, ADFLAGS_HF );
118 if ( stat( ad_p, &st ) < 0 )
119 return 0; /* ignore */
121 return chown( ad_p, uid, gid );
124 /* ----------------- */
125 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
130 /* ----------------- */
131 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
136 /* bail if the file exists in the current directory.
137 * note: this will not fail with dangling symlinks */
139 if (stat(de->d_name, &st) == 0)
140 return AFPERR_DIRNEMPT;
142 if ((err = netatalk_unlink(name)))
148 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
152 /* delete stray .AppleDouble files. this happens to get .Parent files
154 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask)))
156 return netatalk_rmdir(-1, ".AppleDouble" );
159 /* ----------------- */
160 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
162 return setfilmode(name, ad_hf_mode(mode), st, v_umask);
165 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
167 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_HF ), mode, st, vol->v_umask);
170 /* ----------------- */
171 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
173 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
174 int dropbox = vol->v_flags;
176 if (dir_rx_set(mode)) {
177 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
181 if (adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0)
184 if (!dir_rx_set(mode)) {
185 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
191 /* ----------------- */
192 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
194 mode_t hf_mode = *(mode_t *)data;
197 if ( stat( name, &st ) < 0 ) {
200 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
202 else if (!S_ISDIR(st.st_mode)) {
203 if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
204 /* FIXME what do we do then? */
210 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
212 int dropbox = vol->v_flags;
213 mode_t hf_mode = ad_hf_mode(mode);
214 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
215 char *adouble_p = ad_dir(adouble);
217 if (dir_rx_set(mode)) {
218 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
222 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
225 if (!dir_rx_set(mode)) {
226 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
232 /* ----------------- */
233 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
235 struct perm *owner = data;
237 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
238 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
239 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
240 /* return ( -1 ); Sometimes this is okay */
245 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
247 int noadouble = vol_noadouble(vol);
255 adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
257 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask))
261 * We cheat: we know that chown doesn't do anything.
263 if ( stat( ".AppleDouble", &st ) < 0) {
264 if (errno == ENOENT && noadouble)
266 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
269 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
270 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
271 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
272 /* return ( -1 ); Sometimes this is okay */
277 /* ----------------- */
278 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
280 return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
283 /* ----------------- */
284 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
286 char adsrc[ MAXPATHLEN + 1];
289 strcpy( adsrc, vol->ad_path(src, 0 ));
290 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
294 if (errno == ENOENT) {
297 if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
300 /* We are here because :
301 * -there's no dest folder.
302 * -there's no .AppleDouble in the dest folder.
303 * if we use the struct adouble passed in parameter it will not
304 * create .AppleDouble if the file is already opened, so we
305 * use a diff one, it's not a pb,ie it's not the same file, yet.
307 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
308 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
309 ad_close(&ad, ADFLAGS_HF);
310 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) )
315 else { /* it's something else, bail out */
327 static int RF_copyfile_adouble(VFS_FUNC_ARGS_COPYFILE)
328 /* const struct vol *vol, int sfd, const char *src, const char *dst */
331 bstring s = NULL, d = NULL;
336 EC_NULL(name = strrchr(src, '/'));
339 /* build src path to AppleDouble file*/
340 EC_NULL(dir = dirname(strdup(src)));
341 EC_NULL(s = bfromcstr(dir));
342 EC_ZERO(bcatcstr(s, "/.AppleDouble/"));
343 EC_ZERO(bcatcstr(s, name));
347 /* build dst path to AppleDouble file*/
348 EC_NULL(dir = dirname(strdup(dst)));
349 EC_NULL(d = bfromcstr(dir));
350 EC_ZERO(bcatcstr(d, "/.AppleDouble/"));
351 EC_ZERO(bcatcstr(d, name));
356 EC_ZERO(copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666));
365 #ifdef HAVE_SOLARIS_ACLS
366 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
368 static char buf[ MAXPATHLEN + 1];
372 if ((stat(path, &st)) != 0)
374 if (S_ISDIR(st.st_mode)) {
375 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
376 if (len < 0 || len >= MAXPATHLEN)
378 /* set acl on .AppleDouble dir first */
379 if ((acl(buf, cmd, count, aces)) != 0)
381 /* now set ACL on ressource fork */
382 if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
385 /* set ACL on ressource fork */
386 if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
392 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
395 static char buf[ MAXPATHLEN + 1];
399 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
400 if (len < 0 || len >= MAXPATHLEN)
402 /* remove ACL from .AppleDouble/.Parent first */
403 if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
405 /* now remove from .AppleDouble dir */
406 if ((ret = remove_acl_vfs(buf)) != AFP_OK)
409 /* remove ACL from ressource fork */
410 if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
417 #ifdef HAVE_POSIX_ACLS
418 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
421 static char buf[ MAXPATHLEN + 1];
425 if (S_ISDIR(st.st_mode)) {
426 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
427 if (len < 0 || len >= MAXPATHLEN)
429 /* set acl on .AppleDouble dir first */
430 EC_ZERO_LOG(acl_set_file(buf, type, acl));
432 if (type == ACL_TYPE_ACCESS)
433 /* set ACL on ressource fork (".Parent") too */
434 EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_DIR), type, acl));
436 /* set ACL on ressource fork */
437 EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl));
446 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
449 static char buf[ MAXPATHLEN + 1];
453 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
454 if (len < 0 || len >= MAXPATHLEN)
456 /* remove ACL from .AppleDouble/.Parent first */
457 EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR)), AFPERR_MISC);
459 /* now remove from .AppleDouble dir */
460 EC_ZERO_LOG_ERR(remove_acl_vfs(buf), AFPERR_MISC);
462 /* remove ACL from ressource fork */
463 EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC);
471 /*********************************************************************************
473 *********************************************************************************/
474 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
476 struct perm *owner = data;
478 if (chown( name , owner->uid, owner->gid ) < 0) {
484 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
494 ad_p = ad_dir(vol->ad_path(path, ADFLAGS_HF ));
496 if ( stat( ad_p, &st ) < 0 ) {
501 if (chown( ad_p, uid, gid ) < 0) {
504 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
507 /* --------------------------------- */
508 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
510 return netatalk_unlink(name);
513 static int ads_delete_rf(char *name)
517 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
520 * it's a problem for a nfs mounted folder, there's .nfsxxx around
521 * for linux the following line solve it.
522 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
524 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
526 return netatalk_rmdir(-1, name);
529 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
533 /* bail if the file exists in the current directory.
534 * note: this will not fail with dangling symlinks */
536 if (stat(de->d_name, &st) == 0) {
537 return AFPERR_DIRNEMPT;
539 return ads_delete_rf(name);
542 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
546 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
547 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
550 return netatalk_rmdir(-1, ".AppleDouble" );
553 /* ------------------- */
559 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
561 struct set_mode *param = data;
563 return setfilmode(name, param->mode, param->st, v_umask);
566 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
568 mode_t file_mode = ad_hf_mode(mode);
569 mode_t dir_mode = file_mode;
570 struct set_mode param;
572 if ((dir_mode & (S_IRUSR | S_IWUSR )))
574 if ((dir_mode & (S_IRGRP | S_IWGRP )))
576 if ((dir_mode & (S_IROTH | S_IWOTH )))
581 if (dir_rx_set(dir_mode)) {
582 if (chmod( name, dir_mode ) < 0)
586 param.mode = file_mode;
587 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
590 if (!dir_rx_set(dir_mode)) {
591 if (chmod( name, dir_mode ) < 0)
598 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
600 return ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_HF )), mode, st, vol->v_umask);
603 /* ------------------- */
604 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
606 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
607 char ad_p[ MAXPATHLEN + 1];
608 int dropbox = vol->v_flags;
610 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
612 if (dir_rx_set(mode)) {
615 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
618 /* .AppleDouble/.Parent */
619 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
623 if (ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
626 if (!dir_rx_set(mode)) {
627 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
629 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
635 /* ------------------- */
641 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
644 struct dir_mode *param = data;
645 int ret = 0; /* 0 ignore error, -1 */
647 if (dir_rx_set(param->mode)) {
648 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
655 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
658 if (!dir_rx_set(param->mode)) {
659 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
669 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
671 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
672 char ad_p[ MAXPATHLEN + 1];
673 struct dir_mode param;
676 param.dropbox = vol->v_flags;
678 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
680 if (dir_rx_set(mode)) {
682 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
686 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
689 if (!dir_rx_set(mode)) {
690 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
696 /* ------------------- */
697 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
699 struct perm *owner = data;
701 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
702 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
703 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
704 /* return ( -1 ); Sometimes this is okay */
709 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
711 struct perm *owner = data;
713 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
716 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
717 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
718 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
719 /* return ( -1 ); Sometimes this is okay */
724 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
726 int noadouble = vol_noadouble(vol);
727 char adouble_p[ MAXPATHLEN + 1];
734 strlcpy(adouble_p, ad_dir(vol->ad_path(name, ADFLAGS_DIR )), sizeof(adouble_p));
736 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
740 * We cheat: we know that chown doesn't do anything.
742 if ( stat( ".AppleDouble", &st ) < 0) {
743 if (errno == ENOENT && noadouble)
745 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
748 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
749 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
750 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
751 /* return ( -1 ); Sometimes this is okay */
756 /* ------------------- */
757 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
763 ad_p = ad_dir(vol->ad_path(file, ADFLAGS_HF ));
766 if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
772 ret = ads_delete_rf(ad_p);
774 if (dirfd != -1 && fchdir(cwd) != 0) {
775 LOG(log_error, logtype_afpd, "RF_deletefile_ads: cant chdir back. exit!");
786 /* --------------------------- */
787 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
789 char adsrc[ MAXPATHLEN + 1];
792 strcpy( adsrc, ad_dir(vol->ad_path(src, 0 )));
793 if (unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) < 0) {
797 if (errno == ENOENT) {
800 if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
803 /* We are here because :
804 * -there's no dest folder.
805 * -there's no .AppleDouble in the dest folder.
806 * if we use the struct adouble passed in parameter it will not
807 * create .AppleDouble if the file is already opened, so we
808 * use a diff one, it's not a pb,ie it's not the same file, yet.
810 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
811 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
812 ad_close(&ad, ADFLAGS_HF);
814 /* We must delete it */
815 RF_deletefile_ads(vol, -1, dst );
816 if (!unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) )
821 else { /* it's something else, bail out */
833 /*************************************************************************
835 ************************************************************************/
836 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
838 return strncmp(name,"._", 2) && (
839 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
842 /* ---------------- */
843 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
845 /* We simply move the corresponding ad file as well */
846 char tempbuf[258]="._";
847 return unix_rename(dirfd, vol->ad_path(oldpath,0), -1, strcat(tempbuf,newpath));
850 /* ---------------- */
851 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
853 return netatalk_unlink( vol->ad_path(".",0) );
856 /* ---------------- */
857 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
859 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask);
862 /* ---------------- */
863 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
868 /* ---------------- */
869 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
874 /* ---------------- */
875 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
877 char adsrc[ MAXPATHLEN + 1];
880 strcpy( adsrc, vol->ad_path(src, 0 ));
882 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
886 if (errno == ENOENT && lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
894 /********************************************************************************************
896 ********************************************************************************************/
899 * Up until we really start stacking many VFS modules on top of one another or use
900 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
901 * via an fixed size array.
902 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
903 * this error code will be returned to the caller, BUT the chain in followed and all
904 * following funcs are called in order to give them a chance.
908 * Define most VFS funcs with macros as they all do the same.
909 * Only "ad_path" and "validupath" will NOT do stacking and only
910 * call the func from the first module.
913 #define VFS_MFUNC(name, args, vars) \
914 static int vfs_ ## name(args) \
916 int i = 0, ret = AFP_OK, err; \
917 while (vol->vfs_modules[i]) { \
918 if (vol->vfs_modules[i]->vfs_ ## name) { \
919 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
920 if ((ret == AFP_OK) && (err != AFP_OK)) \
928 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
929 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
930 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
931 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
932 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
933 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
934 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
935 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
936 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
937 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
938 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
939 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
940 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
941 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
942 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
943 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
944 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
946 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
948 return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
952 * These function pointers get called from the lib users via vol->vfs->func.
953 * These funcs are defined via the macros above.
955 static struct vfs_ops vfs_master_funcs = {
977 * Primary adouble modules: default, osx, sfm
980 static struct vfs_ops netatalk_adouble = {
981 /* vfs_validupath: */ validupath_adouble,
982 /* vfs_chown: */ RF_chown_adouble,
983 /* vfs_renamedir: */ RF_renamedir_adouble,
984 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
985 /* vfs_setfilmode: */ RF_setfilmode_adouble,
986 /* vfs_setdirmode: */ RF_setdirmode_adouble,
987 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
988 /* vfs_setdirowner: */ RF_setdirowner_adouble,
989 /* vfs_deletefile: */ RF_deletefile_adouble,
990 /* vfs_renamefile: */ RF_renamefile_adouble,
991 /* vfs_copyfile: */ RF_copyfile_adouble,
995 static struct vfs_ops netatalk_adouble_osx = {
996 /* vfs_validupath: */ validupath_osx,
997 /* vfs_chown: */ RF_chown_adouble,
998 /* vfs_renamedir: */ RF_renamedir_osx,
999 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
1000 /* vfs_setfilmode: */ RF_setfilmode_adouble,
1001 /* vfs_setdirmode: */ RF_setdirmode_osx,
1002 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
1003 /* vfs_setdirowner: */ RF_setdirowner_osx,
1004 /* vfs_deletefile: */ RF_deletefile_adouble,
1005 /* vfs_renamefile: */ RF_renamefile_osx,
1006 /* vfs_copyfile: */ NULL,
1010 /* samba sfm format. ad_path shouldn't be set her */
1011 static struct vfs_ops netatalk_adouble_sfm = {
1012 /* vfs_validupath: */ validupath_adouble,
1013 /* vfs_chown: */ RF_chown_ads,
1014 /* vfs_renamedir: */ RF_renamedir_adouble,
1015 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
1016 /* vfs_setfilmode: */ RF_setfilmode_ads,
1017 /* vfs_setdirmode: */ RF_setdirmode_ads,
1018 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
1019 /* vfs_setdirowner: */ RF_setdirowner_ads,
1020 /* vfs_deletefile: */ RF_deletefile_ads,
1021 /* vfs_renamefile: */ RF_renamefile_ads,
1022 /* vfs_copyfile: */ NULL,
1027 * Secondary vfs modules for Extended Attributes
1030 static struct vfs_ops netatalk_ea_adouble = {
1031 /* vfs_validupath: */ NULL,
1032 /* vfs_chown: */ ea_chown,
1033 /* vfs_renamedir: */ NULL, /* ok */
1034 /* vfs_deletecurdir: */ NULL, /* ok */
1035 /* vfs_setfilmode: */ ea_chmod_file,
1036 /* vfs_setdirmode: */ NULL, /* ok */
1037 /* vfs_setdirunixmode:*/ ea_chmod_dir,
1038 /* vfs_setdirowner: */ NULL, /* ok */
1039 /* vfs_deletefile: */ ea_deletefile,
1040 /* vfs_renamefile: */ ea_renamefile,
1041 /* vfs_copyfile */ ea_copyfile,
1042 /* vfs_acl: */ NULL,
1043 /* vfs_remove_acl */ NULL,
1044 /* vfs_getsize */ get_easize,
1045 /* vfs_getcontent */ get_eacontent,
1046 /* vfs_list */ list_eas,
1047 /* vfs_set */ set_ea,
1048 /* vfs_remove */ remove_ea
1051 static struct vfs_ops netatalk_ea_sys = {
1052 /* validupath: */ NULL,
1053 /* rf_chown: */ NULL,
1054 /* rf_renamedir: */ NULL,
1055 /* rf_deletecurdir: */ NULL,
1056 /* rf_setfilmode: */ NULL,
1057 /* rf_setdirmode: */ NULL,
1058 /* rf_setdirunixmode: */ NULL,
1059 /* rf_setdirowner: */ NULL,
1060 /* rf_deletefile: */ NULL,
1061 /* rf_renamefile: */ NULL,
1062 /* vfs_copyfile: */ sys_ea_copyfile,
1064 /* rf_remove_acl */ NULL,
1065 /* ea_getsize */ sys_get_easize,
1066 /* ea_getcontent */ sys_get_eacontent,
1067 /* ea_list */ sys_list_eas,
1068 /* ea_set */ sys_set_ea,
1069 /* ea_remove */ sys_remove_ea
1073 * Tertiary VFS modules for ACLs
1076 #ifdef HAVE_SOLARIS_ACLS
1077 static struct vfs_ops netatalk_solaris_acl_adouble = {
1078 /* validupath: */ NULL,
1079 /* rf_chown: */ NULL,
1080 /* rf_renamedir: */ NULL,
1081 /* rf_deletecurdir: */ NULL,
1082 /* rf_setfilmode: */ NULL,
1083 /* rf_setdirmode: */ NULL,
1084 /* rf_setdirunixmode: */ NULL,
1085 /* rf_setdirowner: */ NULL,
1086 /* rf_deletefile: */ NULL,
1087 /* rf_renamefile: */ NULL,
1088 /* vfs_copyfile */ NULL,
1089 /* rf_acl: */ RF_solaris_acl,
1090 /* rf_remove_acl */ RF_solaris_remove_acl,
1095 #ifdef HAVE_POSIX_ACLS
1096 static struct vfs_ops netatalk_posix_acl_adouble = {
1097 /* validupath: */ NULL,
1098 /* rf_chown: */ NULL,
1099 /* rf_renamedir: */ NULL,
1100 /* rf_deletecurdir: */ NULL,
1101 /* rf_setfilmode: */ NULL,
1102 /* rf_setdirmode: */ NULL,
1103 /* rf_setdirunixmode: */ NULL,
1104 /* rf_setdirowner: */ NULL,
1105 /* rf_deletefile: */ NULL,
1106 /* rf_renamefile: */ NULL,
1107 /* vfs_copyfile */ NULL,
1108 /* rf_acl: */ RF_posix_acl,
1109 /* rf_remove_acl */ RF_posix_remove_acl,
1114 /* ---------------- */
1115 void initvol_vfs(struct vol *vol)
1117 vol->vfs = &vfs_master_funcs;
1119 /* Default adouble stuff */
1120 if (vol->v_adouble == AD_VERSION2_OSX) {
1121 vol->vfs_modules[0] = &netatalk_adouble_osx;
1122 vol->ad_path = ad_path_osx;
1124 else if (vol->v_adouble == AD_VERSION1_SFM) {
1125 vol->vfs_modules[0] = &netatalk_adouble_sfm;
1126 vol->ad_path = ad_path_sfm;
1129 vol->vfs_modules[0] = &netatalk_adouble;
1130 vol->ad_path = ad_path;
1133 /* Extended Attributes */
1134 if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
1135 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
1136 vol->vfs_modules[1] = &netatalk_ea_sys;
1137 } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
1138 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
1139 vol->vfs_modules[1] = &netatalk_ea_adouble;
1141 LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
1145 #ifdef HAVE_SOLARIS_ACLS
1146 vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
1148 #ifdef HAVE_POSIX_ACLS
1149 vol->vfs_modules[2] = &netatalk_posix_acl_adouble;