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 */
24 #include <sys/types.h>
32 #include <atalk/afp.h>
33 #include <atalk/adouble.h>
35 #include <atalk/acl.h>
36 #include <atalk/logger.h>
37 #include <atalk/util.h>
38 #include <atalk/volume.h>
39 #include <atalk/vfs.h>
40 #include <atalk/directory.h>
41 #include <atalk/unix.h>
42 #include <atalk/errchk.h>
43 #include <atalk/bstrlib.h>
44 #include <atalk/bstradd.h>
51 typedef int (*rf_loop)(const struct vol *, struct dirent *, char *, void *, int);
53 /* ----------------------------- */
55 for_each_adouble(const char *from, const char *name, rf_loop fn, const struct vol *vol, void *data, int flag)
57 char buf[ MAXPATHLEN + 1];
64 if (NULL == ( dp = opendir( name)) ) {
66 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
71 strlcpy( buf, name, sizeof(buf));
72 strlcat( buf, "/", sizeof(buf) );
73 m = strchr( buf, '\0' );
75 while ((de = readdir(dp))) {
76 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
80 strlcat(buf, de->d_name, sizeof(buf));
81 if (fn && (ret = fn(vol, de, buf, data, flag))) {
91 /*******************************************************************************
92 * classic adouble format
93 *******************************************************************************/
95 static int netatalk_name(const char *name)
97 return strcasecmp(name,".AppleDouble") &&
98 strcasecmp(name,".AppleDB") &&
99 strcasecmp(name,".AppleDesktop");
102 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
107 if (!(vol->v_flags & AFPVOL_USEDOTS))
110 return netatalk_name(name) && strcasecmp(name,".Parent");
113 /* ----------------- */
114 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
119 ad_p = vol->ad_path(path, ADFLAGS_HF );
121 if ( stat( ad_p, &st ) < 0 )
122 return 0; /* ignore */
124 return chown( ad_p, uid, gid );
127 /* ----------------- */
128 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
133 /* ----------------- */
134 static int deletecurdir_adouble_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
139 /* bail if the file exists in the current directory.
140 * note: this will not fail with dangling symlinks */
142 if (stat(de->d_name, &st) == 0)
143 return AFPERR_DIRNEMPT;
145 if ((err = netatalk_unlink(name)))
151 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
155 /* delete stray .AppleDouble files. this happens to get .Parent files
157 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, vol, NULL, 1)))
159 return netatalk_rmdir(-1, ".AppleDouble" );
162 /* ----------------- */
163 static int adouble_setfilmode(const struct vol *vol, const char *name, mode_t mode, struct stat *st)
165 return setfilmode(vol, name, ad_hf_mode(mode), st);
168 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
170 return adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_HF ), mode, st);
173 /* ----------------- */
174 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
176 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
177 int dropbox = vol->v_flags;
179 if (dir_rx_set(mode)) {
180 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
184 if (adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_DIR ), mode, st) < 0)
187 if (!dir_rx_set(mode)) {
188 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
194 /* ----------------- */
195 static int setdirmode_adouble_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag)
197 mode_t hf_mode = *(mode_t *)data;
200 if (ostat(name, &st, vol_syml_opt(vol)) < 0 ) {
203 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
205 else if (!S_ISDIR(st.st_mode)) {
206 if (setfilmode(vol, name, hf_mode, &st) < 0) {
207 /* FIXME what do we do then? */
213 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
215 int dropbox = vol->v_flags;
216 mode_t hf_mode = ad_hf_mode(mode);
217 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
218 char *adouble_p = ad_dir(adouble);
220 if (dir_rx_set(mode)) {
221 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
225 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, vol, &hf_mode, vol_noadouble(vol)))
228 if (!dir_rx_set(mode)) {
229 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
235 /* ----------------- */
236 static int setdirowner_adouble_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag _U_)
238 struct perm *owner = data;
240 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
241 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
242 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
243 /* return ( -1 ); Sometimes this is okay */
248 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
250 int noadouble = vol_noadouble(vol);
258 adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
260 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, vol, &owner, noadouble))
264 * We cheat: we know that chown doesn't do anything.
266 if ( stat( ".AppleDouble", &st ) < 0) {
267 if (errno == ENOENT && noadouble)
269 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
272 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
273 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
274 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
275 /* return ( -1 ); Sometimes this is okay */
280 /* ----------------- */
281 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
283 return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
286 /* ----------------- */
287 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
289 char adsrc[ MAXPATHLEN + 1];
292 strcpy( adsrc, vol->ad_path(src, 0 ));
293 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
297 if (errno == ENOENT) {
300 if (ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
303 /* We are here because :
304 * -there's no dest folder.
305 * -there's no .AppleDouble in the dest folder.
306 * if we use the struct adouble passed in parameter it will not
307 * create .AppleDouble if the file is already opened, so we
308 * use a diff one, it's not a pb,ie it's not the same file, yet.
310 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
311 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
312 ad_close(&ad, ADFLAGS_HF);
313 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) )
318 else { /* it's something else, bail out */
330 static int RF_copyfile_adouble(VFS_FUNC_ARGS_COPYFILE)
331 /* const struct vol *vol, int sfd, const char *src, const char *dst */
334 bstring s = NULL, d = NULL;
339 const char *name = NULL;
340 const char *dir = NULL;
343 EC_ZERO(stat(dst, &st));
345 if (S_ISDIR(st.st_mode)) {
346 /* build src path to AppleDouble file*/
347 EC_NULL(s = bfromcstr(src));
348 EC_ZERO(bcatcstr(s, "/.AppleDouble/.Parent"));
350 /* build dst path to AppleDouble file*/
351 EC_NULL(d = bfromcstr(dst));
352 EC_ZERO(bcatcstr(d, "/.AppleDouble/.Parent"));
356 /* build src path to AppleDouble file*/
357 EC_NULL(dup1 = strdup(src));
358 EC_NULL(name = basename(strdup(dup1)));
360 EC_NULL(dup2 = strdup(src));
361 EC_NULL(dir = dirname(dup2));
362 EC_NULL(s = bfromcstr(dir));
363 EC_ZERO(bcatcstr(s, "/.AppleDouble/"));
364 EC_ZERO(bcatcstr(s, name));
366 /* build dst path to AppleDouble file*/
367 EC_NULL(dup4 = strdup(dst));
368 EC_NULL(name = basename(strdup(dup4)));
370 EC_NULL(dup3 = strdup(dst));
371 EC_NULL(dir = dirname(dup3));
372 EC_NULL(d = bfromcstr(dir));
373 EC_ZERO(bcatcstr(d, "/.AppleDouble/"));
374 EC_ZERO(bcatcstr(d, name));
377 EC_ZERO(copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666));
382 if (dup1) free(dup1);
383 if (dup2) free(dup2);
384 if (dup3) free(dup3);
385 if (dup4) free(dup4);
390 #ifdef HAVE_SOLARIS_ACLS
391 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
393 static char buf[ MAXPATHLEN + 1];
397 if ((stat(path, &st)) != 0)
399 if (S_ISDIR(st.st_mode)) {
400 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
401 if (len < 0 || len >= MAXPATHLEN)
403 /* set acl on .AppleDouble dir first */
404 if ((acl(buf, cmd, count, aces)) != 0)
406 /* now set ACL on ressource fork */
407 if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
410 /* set ACL on ressource fork */
411 if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
417 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
420 static char buf[ MAXPATHLEN + 1];
424 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
425 if (len < 0 || len >= MAXPATHLEN)
427 /* remove ACL from .AppleDouble/.Parent first */
428 if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
430 /* now remove from .AppleDouble dir */
431 if ((ret = remove_acl_vfs(buf)) != AFP_OK)
434 /* remove ACL from ressource fork */
435 if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
442 #ifdef HAVE_POSIX_ACLS
443 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
446 static char buf[ MAXPATHLEN + 1];
450 if (S_ISDIR(st.st_mode)) {
451 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
452 if (len < 0 || len >= MAXPATHLEN)
454 /* set acl on .AppleDouble dir first */
455 EC_ZERO_LOG(acl_set_file(buf, type, acl));
457 if (type == ACL_TYPE_ACCESS)
458 /* set ACL on ressource fork (".Parent") too */
459 EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_DIR), type, acl));
461 /* set ACL on ressource fork */
462 EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl));
471 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
474 static char buf[ MAXPATHLEN + 1];
478 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
479 if (len < 0 || len >= MAXPATHLEN)
481 /* remove ACL from .AppleDouble/.Parent first */
482 EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR)), AFPERR_MISC);
484 /* now remove from .AppleDouble dir */
485 EC_ZERO_LOG_ERR(remove_acl_vfs(buf), AFPERR_MISC);
487 /* remove ACL from ressource fork */
488 EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC);
496 /*********************************************************************************
498 *********************************************************************************/
499 static int ads_chown_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag _U_)
501 struct perm *owner = data;
503 if (chown( name , owner->uid, owner->gid ) < 0) {
509 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
519 ad_p = ad_dir(vol->ad_path(path, ADFLAGS_HF ));
521 if ( stat( ad_p, &st ) < 0 ) {
526 if (chown( ad_p, uid, gid ) < 0) {
529 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, vol, &owner, 1);
532 /* --------------------------------- */
533 static int deletecurdir_ads1_loop(const struct vol *vol _U_, struct dirent *de _U_, char *name, void *data _U_, int flag _U_)
535 return netatalk_unlink(name);
538 static int ads_delete_rf(char *name)
542 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, NULL, 1)))
545 * it's a problem for a nfs mounted folder, there's .nfsxxx around
546 * for linux the following line solve it.
547 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
549 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, NULL, 1)))
551 return netatalk_rmdir(-1, name);
554 static int deletecurdir_ads_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
558 /* bail if the file exists in the current directory.
559 * note: this will not fail with dangling symlinks */
561 if (stat(de->d_name, &st) == 0) {
562 return AFPERR_DIRNEMPT;
564 return ads_delete_rf(name);
567 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
571 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
572 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, vol, NULL, 1)))
575 return netatalk_rmdir(-1, ".AppleDouble" );
578 /* ------------------- */
584 static int ads_setfilmode_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag _U_)
586 struct set_mode *param = data;
588 return setfilmode(vol, name, param->mode, NULL);
591 static int ads_setfilmode(const struct vol *vol, const char * name, mode_t mode, struct stat *st)
593 mode_t file_mode = ad_hf_mode(mode);
594 mode_t dir_mode = file_mode;
595 struct set_mode param;
597 if ((dir_mode & (S_IRUSR | S_IWUSR )))
599 if ((dir_mode & (S_IRGRP | S_IWGRP )))
601 if ((dir_mode & (S_IROTH | S_IWOTH )))
606 if (dir_rx_set(dir_mode)) {
607 if (ochmod(name, dir_mode, st, vol_syml_opt(vol) | O_NETATALK_ACL) < 0)
611 param.mode = file_mode;
612 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, vol, ¶m, 0) < 0)
615 if (!dir_rx_set(dir_mode)) {
616 if (ochmod(name, dir_mode, st, vol_syml_opt(vol) | O_NETATALK_ACL) < 0)
623 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
625 return ads_setfilmode(vol, ad_dir(vol->ad_path(name, ADFLAGS_HF )), mode, st);
628 /* ------------------- */
629 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
631 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
632 char ad_p[ MAXPATHLEN + 1];
633 int dropbox = vol->v_flags;
635 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
637 if (dir_rx_set(mode)) {
640 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
643 /* .AppleDouble/.Parent */
644 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
648 if (ads_setfilmode(vol, ad_dir(vol->ad_path(name, ADFLAGS_DIR)), mode, st) < 0)
651 if (!dir_rx_set(mode)) {
652 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
654 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
660 /* ------------------- */
666 static int setdirmode_ads_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag)
669 struct dir_mode *param = data;
670 int ret = 0; /* 0 ignore error, -1 */
672 if (dir_rx_set(param->mode)) {
673 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, vol->v_umask) < 0) {
680 if (ads_setfilmode(vol, name, param->mode, NULL) < 0)
683 if (!dir_rx_set(param->mode)) {
684 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, vol->v_umask) < 0) {
694 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
696 char *adouble = vol->ad_path(name, ADFLAGS_DIR );
697 char ad_p[ MAXPATHLEN + 1];
698 struct dir_mode param;
701 param.dropbox = vol->v_flags;
703 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
705 if (dir_rx_set(mode)) {
707 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
711 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, vol, ¶m, vol_noadouble(vol)))
714 if (!dir_rx_set(mode)) {
715 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
721 /* ------------------- */
722 static int setdirowner_ads1_loop(const struct vol *vol _U_, struct dirent *de _U_, char *name, void *data, int flag _U_)
724 struct perm *owner = data;
726 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
727 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
728 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
729 /* return ( -1 ); Sometimes this is okay */
734 static int setdirowner_ads_loop(const struct vol *vol, struct dirent *de _U_, char *name, void *data, int flag)
736 struct perm *owner = data;
738 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, vol, data, flag) < 0)
741 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
742 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
743 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
744 /* return ( -1 ); Sometimes this is okay */
749 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
751 int noadouble = vol_noadouble(vol);
752 char adouble_p[ MAXPATHLEN + 1];
759 strlcpy(adouble_p, ad_dir(vol->ad_path(name, ADFLAGS_DIR )), sizeof(adouble_p));
761 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, vol, &owner, noadouble))
765 * We cheat: we know that chown doesn't do anything.
767 if ( stat( ".AppleDouble", &st ) < 0) {
768 if (errno == ENOENT && noadouble)
770 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
773 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
774 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
775 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
776 /* return ( -1 ); Sometimes this is okay */
781 /* ------------------- */
782 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
788 ad_p = ad_dir(vol->ad_path(file, ADFLAGS_HF ));
791 if (((cwd = open(".", O_RDONLY)) == -1) || (fchdir(dirfd) != 0)) {
797 ret = ads_delete_rf(ad_p);
799 if (dirfd != -1 && fchdir(cwd) != 0) {
800 LOG(log_error, logtype_afpd, "RF_deletefile_ads: cant chdir back. exit!");
811 /* --------------------------- */
812 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
814 char adsrc[ MAXPATHLEN + 1];
817 strcpy( adsrc, ad_dir(vol->ad_path(src, 0 )));
818 if (unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) < 0) {
822 if (errno == ENOENT) {
825 if (ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
828 /* We are here because :
829 * -there's no dest folder.
830 * -there's no .AppleDouble in the dest folder.
831 * if we use the struct adouble passed in parameter it will not
832 * create .AppleDouble if the file is already opened, so we
833 * use a diff one, it's not a pb,ie it's not the same file, yet.
835 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
836 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
837 ad_close(&ad, ADFLAGS_HF);
839 /* We must delete it */
840 RF_deletefile_ads(vol, -1, dst );
841 if (!unix_rename(dirfd, adsrc, -1, ad_dir(vol->ad_path(dst, 0 ))) )
846 else { /* it's something else, bail out */
858 /*************************************************************************
860 ************************************************************************/
861 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
863 return strncmp(name,"._", 2) && (
864 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
867 /* ---------------- */
868 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
870 /* We simply move the corresponding ad file as well */
871 char tempbuf[258]="._";
872 return unix_rename(dirfd, vol->ad_path(oldpath,0), -1, strcat(tempbuf,newpath));
875 /* ---------------- */
876 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
878 return netatalk_unlink( vol->ad_path(".",0) );
881 /* ---------------- */
882 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
884 return adouble_setfilmode(vol, vol->ad_path(name, ADFLAGS_DIR), mode, st);
887 /* ---------------- */
888 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
893 /* ---------------- */
894 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
899 /* ---------------- */
900 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
902 char adsrc[ MAXPATHLEN + 1];
905 strcpy( adsrc, vol->ad_path(src, 0 ));
907 if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
911 if (errno == ENOENT && ostatat(dirfd, adsrc, &st, vol_syml_opt(vol))) /* source has no ressource fork, */
919 /********************************************************************************************
921 ********************************************************************************************/
924 * Up until we really start stacking many VFS modules on top of one another or use
925 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
926 * via an fixed size array.
927 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
928 * this error code will be returned to the caller, BUT the chain in followed and all
929 * following funcs are called in order to give them a chance.
933 * Define most VFS funcs with macros as they all do the same.
934 * Only "ad_path" and "validupath" will NOT do stacking and only
935 * call the func from the first module.
938 #define VFS_MFUNC(name, args, vars) \
939 static int vfs_ ## name(args) \
941 int i = 0, ret = AFP_OK, err; \
942 while (vol->vfs_modules[i]) { \
943 if (vol->vfs_modules[i]->vfs_ ## name) { \
944 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
945 if ((ret == AFP_OK) && (err != AFP_OK)) \
953 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
954 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
955 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
956 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
957 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
958 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
959 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
960 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
961 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
962 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
964 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
965 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
967 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
968 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
969 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
970 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
971 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
973 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
975 return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
979 * These function pointers get called from the lib users via vol->vfs->func.
980 * These funcs are defined via the macros above.
982 static struct vfs_ops vfs_master_funcs = {
1006 * Primary adouble modules: default, osx, sfm
1009 static struct vfs_ops netatalk_adouble = {
1010 /* vfs_validupath: */ validupath_adouble,
1011 /* vfs_chown: */ RF_chown_adouble,
1012 /* vfs_renamedir: */ RF_renamedir_adouble,
1013 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
1014 /* vfs_setfilmode: */ RF_setfilmode_adouble,
1015 /* vfs_setdirmode: */ RF_setdirmode_adouble,
1016 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
1017 /* vfs_setdirowner: */ RF_setdirowner_adouble,
1018 /* vfs_deletefile: */ RF_deletefile_adouble,
1019 /* vfs_renamefile: */ RF_renamefile_adouble,
1020 /* vfs_copyfile: */ RF_copyfile_adouble,
1024 static struct vfs_ops netatalk_adouble_osx = {
1025 /* vfs_validupath: */ validupath_osx,
1026 /* vfs_chown: */ RF_chown_adouble,
1027 /* vfs_renamedir: */ RF_renamedir_osx,
1028 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
1029 /* vfs_setfilmode: */ RF_setfilmode_adouble,
1030 /* vfs_setdirmode: */ RF_setdirmode_osx,
1031 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
1032 /* vfs_setdirowner: */ RF_setdirowner_osx,
1033 /* vfs_deletefile: */ RF_deletefile_adouble,
1034 /* vfs_renamefile: */ RF_renamefile_osx,
1035 /* vfs_copyfile: */ NULL,
1039 /* samba sfm format. ad_path shouldn't be set her */
1040 static struct vfs_ops netatalk_adouble_sfm = {
1041 /* vfs_validupath: */ validupath_adouble,
1042 /* vfs_chown: */ RF_chown_ads,
1043 /* vfs_renamedir: */ RF_renamedir_adouble,
1044 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
1045 /* vfs_setfilmode: */ RF_setfilmode_ads,
1046 /* vfs_setdirmode: */ RF_setdirmode_ads,
1047 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
1048 /* vfs_setdirowner: */ RF_setdirowner_ads,
1049 /* vfs_deletefile: */ RF_deletefile_ads,
1050 /* vfs_renamefile: */ RF_renamefile_ads,
1051 /* vfs_copyfile: */ NULL,
1056 * Secondary vfs modules for Extended Attributes
1059 static struct vfs_ops netatalk_ea_adouble = {
1060 /* vfs_validupath: */ NULL,
1061 /* vfs_chown: */ ea_chown,
1062 /* vfs_renamedir: */ NULL, /* ok */
1063 /* vfs_deletecurdir: */ NULL, /* ok */
1064 /* vfs_setfilmode: */ ea_chmod_file,
1065 /* vfs_setdirmode: */ NULL, /* ok */
1066 /* vfs_setdirunixmode:*/ ea_chmod_dir,
1067 /* vfs_setdirowner: */ NULL, /* ok */
1068 /* vfs_deletefile: */ ea_deletefile,
1069 /* vfs_renamefile: */ ea_renamefile,
1070 /* vfs_copyfile */ ea_copyfile,
1072 /* vfs_acl: */ NULL,
1073 /* vfs_remove_acl */ NULL,
1075 /* vfs_getsize */ get_easize,
1076 /* vfs_getcontent */ get_eacontent,
1077 /* vfs_list */ list_eas,
1078 /* vfs_set */ set_ea,
1079 /* vfs_remove */ remove_ea
1082 static struct vfs_ops netatalk_ea_sys = {
1083 /* validupath: */ NULL,
1084 /* rf_chown: */ NULL,
1085 /* rf_renamedir: */ NULL,
1086 /* rf_deletecurdir: */ NULL,
1087 /* rf_setfilmode: */ NULL,
1088 /* rf_setdirmode: */ NULL,
1089 /* rf_setdirunixmode: */ NULL,
1090 /* rf_setdirowner: */ NULL,
1091 /* rf_deletefile: */ NULL,
1092 /* rf_renamefile: */ NULL,
1093 /* vfs_copyfile: */ sys_ea_copyfile,
1096 /* rf_remove_acl */ NULL,
1098 /* ea_getsize */ sys_get_easize,
1099 /* ea_getcontent */ sys_get_eacontent,
1100 /* ea_list */ sys_list_eas,
1101 /* ea_set */ sys_set_ea,
1102 /* ea_remove */ sys_remove_ea
1106 * Tertiary VFS modules for ACLs
1109 #ifdef HAVE_SOLARIS_ACLS
1110 static struct vfs_ops netatalk_solaris_acl_adouble = {
1111 /* validupath: */ NULL,
1112 /* rf_chown: */ NULL,
1113 /* rf_renamedir: */ NULL,
1114 /* rf_deletecurdir: */ NULL,
1115 /* rf_setfilmode: */ NULL,
1116 /* rf_setdirmode: */ NULL,
1117 /* rf_setdirunixmode: */ NULL,
1118 /* rf_setdirowner: */ NULL,
1119 /* rf_deletefile: */ NULL,
1120 /* rf_renamefile: */ NULL,
1121 /* vfs_copyfile */ NULL,
1122 /* rf_acl: */ RF_solaris_acl,
1123 /* rf_remove_acl */ RF_solaris_remove_acl,
1128 #ifdef HAVE_POSIX_ACLS
1129 static struct vfs_ops netatalk_posix_acl_adouble = {
1130 /* validupath: */ NULL,
1131 /* rf_chown: */ NULL,
1132 /* rf_renamedir: */ NULL,
1133 /* rf_deletecurdir: */ NULL,
1134 /* rf_setfilmode: */ NULL,
1135 /* rf_setdirmode: */ NULL,
1136 /* rf_setdirunixmode: */ NULL,
1137 /* rf_setdirowner: */ NULL,
1138 /* rf_deletefile: */ NULL,
1139 /* rf_renamefile: */ NULL,
1140 /* vfs_copyfile */ NULL,
1141 /* rf_acl: */ RF_posix_acl,
1142 /* rf_remove_acl */ RF_posix_remove_acl,
1147 /* ---------------- */
1148 void initvol_vfs(struct vol *vol)
1150 vol->vfs = &vfs_master_funcs;
1152 /* Default adouble stuff */
1153 if (vol->v_adouble == AD_VERSION2_OSX) {
1154 vol->vfs_modules[0] = &netatalk_adouble_osx;
1155 vol->ad_path = ad_path_osx;
1157 else if (vol->v_adouble == AD_VERSION1_SFM) {
1158 vol->vfs_modules[0] = &netatalk_adouble_sfm;
1159 vol->ad_path = ad_path_sfm;
1162 vol->vfs_modules[0] = &netatalk_adouble;
1163 vol->ad_path = ad_path;
1166 /* Extended Attributes */
1167 if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
1168 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
1169 vol->vfs_modules[1] = &netatalk_ea_sys;
1170 } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
1171 LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
1172 vol->vfs_modules[1] = &netatalk_ea_adouble;
1174 LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
1178 #ifdef HAVE_SOLARIS_ACLS
1179 vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
1181 #ifdef HAVE_POSIX_ACLS
1182 vol->vfs_modules[2] = &netatalk_posix_acl_adouble;