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>
46 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
48 /* ----------------------------- */
50 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
52 char buf[ MAXPATHLEN + 1];
59 if (NULL == ( dp = opendir( name)) ) {
61 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
66 strlcpy( buf, name, sizeof(buf));
67 strlcat( buf, "/", sizeof(buf) );
68 m = strchr( buf, '\0' );
70 while ((de = readdir(dp))) {
71 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
75 strlcat(buf, de->d_name, sizeof(buf));
76 if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
86 /*******************************************************************************
87 * classic adouble format
88 *******************************************************************************/
90 static int netatalk_name(const char *name)
92 return strcasecmp(name,".AppleDouble") &&
93 strcasecmp(name,".AppleDB") &&
94 strcasecmp(name,".AppleDesktop");
97 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
102 if (!(vol->v_flags & AFPVOL_USEDOTS))
105 return netatalk_name(name) && strcasecmp(name,".Parent");
108 /* ----------------- */
109 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
114 ad_p = vol->ad_path(path, ADFLAGS_HF );
116 if ( stat( ad_p, &st ) < 0 )
117 return 0; /* ignore */
119 return chown( ad_p, uid, gid );
122 /* ----------------- */
123 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
128 /* ----------------- */
129 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
134 /* bail if the file exists in the current directory.
135 * note: this will not fail with dangling symlinks */
137 if (stat(de->d_name, &st) == 0)
138 return AFPERR_DIRNEMPT;
140 if ((err = netatalk_unlink(name)))
146 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
150 /* delete stray .AppleDouble files. this happens to get .Parent files
152 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask)))
154 return netatalk_rmdir(-1, ".AppleDouble" );
157 /* ----------------- */
158 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
160 return setfilmode(name, ad_hf_mode(mode), st, v_umask);
163 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
165 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_HF ), mode, st, vol->v_umask);
168 /* ----------------- */
169 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
171 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
172 int dropbox = vol->v_flags;
174 if (dir_rx_set(mode)) {
175 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
179 if (adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0)
182 if (!dir_rx_set(mode)) {
183 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
189 /* ----------------- */
190 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
192 mode_t hf_mode = *(mode_t *)data;
195 if ( stat( name, &st ) < 0 ) {
198 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
200 else if (!S_ISDIR(st.st_mode)) {
201 if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
202 /* FIXME what do we do then? */
208 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
210 int dropbox = vol->v_flags;
211 mode_t hf_mode = ad_hf_mode(mode);
212 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
213 char *adouble_p = ad_dir(adouble);
215 if (dir_rx_set(mode)) {
216 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
220 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
223 if (!dir_rx_set(mode)) {
224 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
230 /* ----------------- */
231 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
233 struct perm *owner = data;
235 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
236 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
237 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
238 /* return ( -1 ); Sometimes this is okay */
243 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
245 int noadouble = vol_noadouble(vol);
253 adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
255 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask))
259 * We cheat: we know that chown doesn't do anything.
261 if ( stat( ".AppleDouble", &st ) < 0) {
262 if (errno == ENOENT && noadouble)
264 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
267 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
268 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
269 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
270 /* return ( -1 ); Sometimes this is okay */
275 /* ----------------- */
276 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
278 return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
281 /* ----------------- */
282 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
284 char adsrc[ MAXPATHLEN + 1];
287 strcpy( adsrc, vol->ad_path(src, 0 ));
288 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
292 if (errno == ENOENT) {
295 if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
298 /* We are here because :
299 * -there's no dest folder.
300 * -there's no .AppleDouble in the dest folder.
301 * if we use the struct adouble passed in parameter it will not
302 * create .AppleDouble if the file is already opened, so we
303 * use a diff one, it's not a pb,ie it's not the same file, yet.
305 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
306 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
307 ad_close(&ad, ADFLAGS_HF);
308 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) )
313 else { /* it's something else, bail out */
325 static int RF_copyfile_adouble(VFS_FUNC_ARGS_COPYFILE)
326 /* const struct vol *vol, int sfd, const char *src, const char *dst */
329 bstring s = NULL, d = NULL;
334 EC_NULL(name = strchr(src, '/'));
337 /* build src path to AppleDouble file*/
338 EC_NULL(dir = dirname(strdup(src)));
339 EC_NULL(s = bfromcstr(dir));
340 EC_ZERO(bcatcstr(s, "/.AppleDouble/"));
341 EC_ZERO(bcatcstr(s, name));
345 /* build dst path to AppleDouble file*/
346 EC_NULL(dir = dirname(strdup(dst)));
347 EC_NULL(d = bfromcstr(dir));
348 EC_ZERO(bcatcstr(d, "/.AppleDouble/"));
349 EC_ZERO(bcatcstr(d, name));
354 EC_ZERO(copy_file(sfd, src, dst, 0666));
363 #ifdef HAVE_SOLARIS_ACLS
364 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
366 static char buf[ MAXPATHLEN + 1];
370 if ((stat(path, &st)) != 0)
372 if (S_ISDIR(st.st_mode)) {
373 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
374 if (len < 0 || len >= MAXPATHLEN)
376 /* set acl on .AppleDouble dir first */
377 if ((acl(buf, cmd, count, aces)) != 0)
379 /* now set ACL on ressource fork */
380 if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
383 /* set ACL on ressource fork */
384 if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
390 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
393 static char buf[ MAXPATHLEN + 1];
397 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
398 if (len < 0 || len >= MAXPATHLEN)
400 /* remove ACL from .AppleDouble/.Parent first */
401 if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
403 /* now remove from .AppleDouble dir */
404 if ((ret = remove_acl_vfs(buf)) != AFP_OK)
407 /* remove ACL from ressource fork */
408 if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
415 #ifdef HAVE_POSIX_ACLS
416 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
419 static char buf[ MAXPATHLEN + 1];
423 if (S_ISDIR(st.st_mode)) {
424 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
425 if (len < 0 || len >= MAXPATHLEN)
427 /* set acl on .AppleDouble dir first */
428 EC_ZERO_LOG(acl_set_file(buf, type, acl));
430 if (type == ACL_TYPE_ACCESS)
431 /* set ACL on ressource fork (".Parent") too */
432 EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_DIR), type, acl));
434 /* set ACL on ressource fork */
435 EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl));
444 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
447 static char buf[ MAXPATHLEN + 1];
451 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
452 if (len < 0 || len >= MAXPATHLEN)
454 /* remove ACL from .AppleDouble/.Parent first */
455 EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR)), AFPERR_MISC);
457 /* now remove from .AppleDouble dir */
458 EC_ZERO_LOG_ERR(remove_acl_vfs(buf), AFPERR_MISC);
460 /* remove ACL from ressource fork */
461 EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC);
469 /*********************************************************************************
471 *********************************************************************************/
472 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
474 struct perm *owner = data;
476 if (chown( name , owner->uid, owner->gid ) < 0) {
482 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
492 ad_p = ad_dir(vol->ad_path(path, ADFLAGS_HF ));
494 if ( stat( ad_p, &st ) < 0 ) {
499 if (chown( ad_p, uid, gid ) < 0) {
502 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
505 /* --------------------------------- */
506 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
508 return netatalk_unlink(name);
511 static int ads_delete_rf(char *name)
515 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
518 * it's a problem for a nfs mounted folder, there's .nfsxxx around
519 * for linux the following line solve it.
520 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
522 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
524 return netatalk_rmdir(-1, name);
527 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
531 /* bail if the file exists in the current directory.
532 * note: this will not fail with dangling symlinks */
534 if (stat(de->d_name, &st) == 0) {
535 return AFPERR_DIRNEMPT;
537 return ads_delete_rf(name);
540 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
544 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
545 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
548 return netatalk_rmdir(-1, ".AppleDouble" );
551 /* ------------------- */
557 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
559 struct set_mode *param = data;
561 return setfilmode(name, param->mode, param->st, v_umask);
564 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
566 mode_t file_mode = ad_hf_mode(mode);
567 mode_t dir_mode = file_mode;
568 struct set_mode param;
570 if ((dir_mode & (S_IRUSR | S_IWUSR )))
572 if ((dir_mode & (S_IRGRP | S_IWGRP )))
574 if ((dir_mode & (S_IROTH | S_IWOTH )))
579 if (dir_rx_set(dir_mode)) {
580 if (chmod( name, dir_mode ) < 0)
584 param.mode = file_mode;
585 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
588 if (!dir_rx_set(dir_mode)) {
589 if (chmod( name, dir_mode ) < 0)
596 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
598 return ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_HF )), mode, st, vol->v_umask);
601 /* ------------------- */
602 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
604 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
605 char ad_p[ MAXPATHLEN + 1];
606 int dropbox = vol->v_flags;
608 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
610 if (dir_rx_set(mode)) {
613 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
616 /* .AppleDouble/.Parent */
617 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
621 if (ads_setfilmode(ad_dir(vol->ad_path(name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
624 if (!dir_rx_set(mode)) {
625 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
627 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
633 /* ------------------- */
639 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
642 struct dir_mode *param = data;
643 int ret = 0; /* 0 ignore error, -1 */
645 if (dir_rx_set(param->mode)) {
646 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
653 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
656 if (!dir_rx_set(param->mode)) {
657 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
667 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
669 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
670 char ad_p[ MAXPATHLEN + 1];
671 struct dir_mode param;
674 param.dropbox = vol->v_flags;
676 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
678 if (dir_rx_set(mode)) {
680 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
684 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
687 if (!dir_rx_set(mode)) {
688 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
694 /* ------------------- */
695 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
697 struct perm *owner = data;
699 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
700 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
701 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
702 /* return ( -1 ); Sometimes this is okay */
707 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
709 struct perm *owner = data;
711 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
714 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
715 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
716 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
717 /* return ( -1 ); Sometimes this is okay */
722 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
724 int noadouble = vol_noadouble(vol);
725 char adouble_p[ MAXPATHLEN + 1];
732 strlcpy(adouble_p, ad_dir(vol->ad_path(name, ADFLAGS_DIR )), sizeof(adouble_p));
734 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
738 * We cheat: we know that chown doesn't do anything.
740 if ( stat( ".AppleDouble", &st ) < 0) {
741 if (errno == ENOENT && noadouble)
743 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
746 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
747 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
748 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
749 /* return ( -1 ); Sometimes this is okay */
754 /* ------------------- */
755 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
761 ad_p = ad_dir(vol->ad_path(file, ADFLAGS_HF ));
764 if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
770 ret = ads_delete_rf(ad_p);
772 if (dirfd != -1 && fchdir(cwd) != 0) {
773 LOG(log_error, logtype_afpd, "RF_deletefile_ads: cant chdir back. exit!");
784 /* --------------------------- */
785 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
787 char adsrc[ MAXPATHLEN + 1];
790 strcpy( adsrc, ad_dir(vol->ad_path(src, 0 )));
791 if (unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) < 0) {
795 if (errno == ENOENT) {
798 if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
801 /* We are here because :
802 * -there's no dest folder.
803 * -there's no .AppleDouble in the dest folder.
804 * if we use the struct adouble passed in parameter it will not
805 * create .AppleDouble if the file is already opened, so we
806 * use a diff one, it's not a pb,ie it's not the same file, yet.
808 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
809 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
810 ad_close(&ad, ADFLAGS_HF);
812 /* We must delete it */
813 RF_deletefile_ads(vol, -1, dst );
814 if (!unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) )
819 else { /* it's something else, bail out */
831 /*************************************************************************
833 ************************************************************************/
834 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
836 return strncmp(name,"._", 2) && (
837 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
840 /* ---------------- */
841 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
843 /* We simply move the corresponding ad file as well */
844 char tempbuf[258]="._";
845 return unix_rename(dirfd, vol->ad_path(oldpath,0), -1, strcat(tempbuf,newpath));
848 /* ---------------- */
849 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
851 return netatalk_unlink( vol->ad_path(".",0) );
854 /* ---------------- */
855 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
857 return adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask);
860 /* ---------------- */
861 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
866 /* ---------------- */
867 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
872 /* ---------------- */
873 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
875 char adsrc[ MAXPATHLEN + 1];
878 strcpy( adsrc, vol->ad_path(src, 0 ));
880 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
884 if (errno == ENOENT && lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
892 /********************************************************************************************
894 ********************************************************************************************/
897 * Up until we really start stacking many VFS modules on top of one another or use
898 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
899 * via an fixed size array.
900 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
901 * this error code will be returned to the caller, BUT the chain in followed and all
902 * following funcs are called in order to give them a chance.
906 * Define most VFS funcs with macros as they all do the same.
907 * Only "ad_path" and "validupath" will NOT do stacking and only
908 * call the func from the first module.
911 #define VFS_MFUNC(name, args, vars) \
912 static int vfs_ ## name(args) \
914 int i = 0, ret = AFP_OK, err; \
915 while (vol->vfs_modules[i]) { \
916 if (vol->vfs_modules[i]->vfs_ ## name) { \
917 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
918 if ((ret == AFP_OK) && (err != AFP_OK)) \
926 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
927 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
928 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
929 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
930 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
931 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
932 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
933 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
934 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
935 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
936 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
937 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
938 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
939 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
940 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
941 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
942 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
944 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
946 return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
950 * These function pointers get called from the lib users via vol->vfs->func.
951 * These funcs are defined via the macros above.
953 static struct vfs_ops vfs_master_funcs = {
975 * Primary adouble modules: default, osx, sfm
978 static struct vfs_ops netatalk_adouble = {
979 /* vfs_validupath: */ validupath_adouble,
980 /* vfs_chown: */ RF_chown_adouble,
981 /* vfs_renamedir: */ RF_renamedir_adouble,
982 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
983 /* vfs_setfilmode: */ RF_setfilmode_adouble,
984 /* vfs_setdirmode: */ RF_setdirmode_adouble,
985 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
986 /* vfs_setdirowner: */ RF_setdirowner_adouble,
987 /* vfs_deletefile: */ RF_deletefile_adouble,
988 /* vfs_renamefile: */ RF_renamefile_adouble,
989 /* vfs_copyfile: */ RF_copyfile_adouble,
993 static struct vfs_ops netatalk_adouble_osx = {
994 /* vfs_validupath: */ validupath_osx,
995 /* vfs_chown: */ RF_chown_adouble,
996 /* vfs_renamedir: */ RF_renamedir_osx,
997 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
998 /* vfs_setfilmode: */ RF_setfilmode_adouble,
999 /* vfs_setdirmode: */ RF_setdirmode_osx,
1000 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
1001 /* vfs_setdirowner: */ RF_setdirowner_osx,
1002 /* vfs_deletefile: */ RF_deletefile_adouble,
1003 /* vfs_renamefile: */ RF_renamefile_osx,
1004 /* vfs_copyfile: */ NULL,
1008 /* samba sfm format. ad_path shouldn't be set her */
1009 static struct vfs_ops netatalk_adouble_sfm = {
1010 /* vfs_validupath: */ validupath_adouble,
1011 /* vfs_chown: */ RF_chown_ads,
1012 /* vfs_renamedir: */ RF_renamedir_adouble,
1013 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
1014 /* vfs_setfilmode: */ RF_setfilmode_ads,
1015 /* vfs_setdirmode: */ RF_setdirmode_ads,
1016 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
1017 /* vfs_setdirowner: */ RF_setdirowner_ads,
1018 /* vfs_deletefile: */ RF_deletefile_ads,
1019 /* vfs_renamefile: */ RF_renamefile_ads,
1020 /* vfs_copyfile: */ NULL,
1025 * Secondary vfs modules for Extended Attributes
1028 static struct vfs_ops netatalk_ea_adouble = {
1029 /* vfs_validupath: */ NULL,
1030 /* vfs_chown: */ ea_chown,
1031 /* vfs_renamedir: */ NULL, /* ok */
1032 /* vfs_deletecurdir: */ NULL, /* ok */
1033 /* vfs_setfilmode: */ ea_chmod_file,
1034 /* vfs_setdirmode: */ NULL, /* ok */
1035 /* vfs_setdirunixmode:*/ ea_chmod_dir,
1036 /* vfs_setdirowner: */ NULL, /* ok */
1037 /* vfs_deletefile: */ ea_deletefile,
1038 /* vfs_renamefile: */ ea_renamefile,
1039 /* vfs_copyfile */ ea_copyfile,
1040 /* vfs_acl: */ NULL,
1041 /* vfs_remove_acl */ NULL,
1042 /* vfs_getsize */ get_easize,
1043 /* vfs_getcontent */ get_eacontent,
1044 /* vfs_list */ list_eas,
1045 /* vfs_set */ set_ea,
1046 /* vfs_remove */ remove_ea
1049 static struct vfs_ops netatalk_ea_sys = {
1050 /* validupath: */ NULL,
1051 /* rf_chown: */ NULL,
1052 /* rf_renamedir: */ NULL,
1053 /* rf_deletecurdir: */ NULL,
1054 /* rf_setfilmode: */ NULL,
1055 /* rf_setdirmode: */ NULL,
1056 /* rf_setdirunixmode: */ NULL,
1057 /* rf_setdirowner: */ NULL,
1058 /* rf_deletefile: */ NULL,
1059 /* rf_renamefile: */ NULL,
1060 /* vfs_copyfile: */ sys_ea_copyfile,
1062 /* rf_remove_acl */ NULL,
1063 /* ea_getsize */ sys_get_easize,
1064 /* ea_getcontent */ sys_get_eacontent,
1065 /* ea_list */ sys_list_eas,
1066 /* ea_set */ sys_set_ea,
1067 /* ea_remove */ sys_remove_ea
1071 * Tertiary VFS modules for ACLs
1074 #ifdef HAVE_SOLARIS_ACLS
1075 static struct vfs_ops netatalk_solaris_acl_adouble = {
1076 /* validupath: */ NULL,
1077 /* rf_chown: */ NULL,
1078 /* rf_renamedir: */ NULL,
1079 /* rf_deletecurdir: */ NULL,
1080 /* rf_setfilmode: */ NULL,
1081 /* rf_setdirmode: */ NULL,
1082 /* rf_setdirunixmode: */ NULL,
1083 /* rf_setdirowner: */ NULL,
1084 /* rf_deletefile: */ NULL,
1085 /* rf_renamefile: */ NULL,
1086 /* vfs_copyfile */ NULL,
1087 /* rf_acl: */ RF_solaris_acl,
1088 /* rf_remove_acl */ RF_solaris_remove_acl,
1093 #ifdef HAVE_POSIX_ACLS
1094 static struct vfs_ops netatalk_posix_acl_adouble = {
1095 /* validupath: */ NULL,
1096 /* rf_chown: */ NULL,
1097 /* rf_renamedir: */ NULL,
1098 /* rf_deletecurdir: */ NULL,
1099 /* rf_setfilmode: */ NULL,
1100 /* rf_setdirmode: */ NULL,
1101 /* rf_setdirunixmode: */ NULL,
1102 /* rf_setdirowner: */ NULL,
1103 /* rf_deletefile: */ NULL,
1104 /* rf_renamefile: */ NULL,
1105 /* vfs_copyfile */ NULL,
1106 /* rf_acl: */ RF_posix_acl,
1107 /* rf_remove_acl */ RF_posix_remove_acl,
1112 /* ---------------- */
1113 void initvol_vfs(struct vol *vol)
1115 vol->vfs = &vfs_master_funcs;
1117 /* Default adouble stuff */
1118 if (vol->v_adouble == AD_VERSION2_OSX) {
1119 vol->vfs_modules[0] = &netatalk_adouble_osx;
1120 vol->ad_path = ad_path_osx;
1122 else if (vol->v_adouble == AD_VERSION1_SFM) {
1123 vol->vfs_modules[0] = &netatalk_adouble_sfm;
1124 vol->ad_path = ad_path_sfm;
1127 vol->vfs_modules[0] = &netatalk_adouble;
1128 vol->ad_path = ad_path;
1131 /* Extended Attributes */
1132 if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
1133 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
1134 vol->vfs_modules[1] = &netatalk_ea_sys;
1135 } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
1136 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
1137 vol->vfs_modules[1] = &netatalk_ea_adouble;
1139 LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
1143 #ifdef HAVE_SOLARIS_ACLS
1144 vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
1146 #ifdef HAVE_POSIX_ACLS
1147 vol->vfs_modules[2] = &netatalk_posix_acl_adouble;