2 Copyright (c) 2004 Didier Gautheron
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #endif /* HAVE_CONFIG_H */
26 #include <atalk/afp.h>
27 #include <atalk/adouble.h>
28 #include <atalk/vfs.h>
30 #include <atalk/acl.h>
31 #include <atalk/logger.h>
32 #include <atalk/util.h>
33 #include <atalk/volume.h>
34 #include <atalk/directory.h>
35 #include <atalk/unix.h>
42 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
44 /* ----------------------------- */
46 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
48 char buf[ MAXPATHLEN + 1];
55 if (NULL == ( dp = opendir( name)) ) {
57 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
62 strlcpy( buf, name, sizeof(buf));
63 strlcat( buf, "/", sizeof(buf) );
64 m = strchr( buf, '\0' );
66 while ((de = readdir(dp))) {
67 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
71 strlcat(buf, de->d_name, sizeof(buf));
72 if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
82 /*******************************************************************************
83 * classic adouble format
84 *******************************************************************************/
86 static int netatalk_name(const char *name)
88 return strcasecmp(name,".AppleDB") &&
89 strcasecmp(name,".AppleDouble") &&
90 strcasecmp(name,".AppleDesktop");
93 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
95 return (vol->v_flags & AFPVOL_USEDOTS) ?
96 netatalk_name(name) && strcasecmp(name,".Parent"): name[0] != '.';
99 /* ----------------- */
100 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
105 ad_p = vol->vfs->ad_path(path, ADFLAGS_HF );
107 if ( stat( ad_p, &st ) < 0 )
108 return 0; /* ignore */
110 return chown( ad_p, uid, gid );
113 /* ----------------- */
114 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
119 /* ----------------- */
120 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
125 /* bail if the file exists in the current directory.
126 * note: this will not fail with dangling symlinks */
128 if (stat(de->d_name, &st) == 0)
129 return AFPERR_DIRNEMPT;
131 if ((err = netatalk_unlink(name)))
137 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
141 /* delete stray .AppleDouble files. this happens to get .Parent files
143 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask)))
145 return netatalk_rmdir( ".AppleDouble" );
148 /* ----------------- */
149 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
151 return setfilmode(name, ad_hf_mode(mode), st, v_umask);
154 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
156 return adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_HF ), mode, st, vol->v_umask);
159 /* ----------------- */
160 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
162 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
163 int dropbox = vol->v_flags;
165 if (dir_rx_set(mode)) {
166 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
170 if (adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0)
173 if (!dir_rx_set(mode)) {
174 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
180 /* ----------------- */
181 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
183 mode_t hf_mode = *(mode_t *)data;
186 if ( stat( name, &st ) < 0 ) {
189 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
191 else if (!S_ISDIR(st.st_mode)) {
192 if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
193 /* FIXME what do we do then? */
199 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
201 int dropbox = vol->v_flags;
202 mode_t hf_mode = ad_hf_mode(mode);
203 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
204 char *adouble_p = ad_dir(adouble);
206 if (dir_rx_set(mode)) {
207 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
211 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
214 if (!dir_rx_set(mode)) {
215 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
221 /* ----------------- */
222 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
224 struct perm *owner = data;
226 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
227 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
228 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
229 /* return ( -1 ); Sometimes this is okay */
234 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
236 int noadouble = vol_noadouble(vol);
244 adouble_p = ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR ));
246 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask))
250 * We cheat: we know that chown doesn't do anything.
252 if ( stat( ".AppleDouble", &st ) < 0) {
253 if (errno == ENOENT && noadouble)
255 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
258 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
259 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
260 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
261 /* return ( -1 ); Sometimes this is okay */
266 /* ----------------- */
267 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
269 return netatalk_unlink(vol->vfs->ad_path( file, ADFLAGS_HF));
272 /* ----------------- */
273 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
275 char adsrc[ MAXPATHLEN + 1];
278 strcpy( adsrc, vol->vfs->ad_path( src, 0 ));
279 if (unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) < 0) {
283 if (errno == ENOENT) {
286 if (stat(adsrc, &st)) /* source has no ressource fork, */
289 /* We are here because :
290 * -there's no dest folder.
291 * -there's no .AppleDouble in the dest folder.
292 * if we use the struct adouble passed in parameter it will not
293 * create .AppleDouble if the file is already opened, so we
294 * use a diff one, it's not a pb,ie it's not the same file, yet.
296 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
297 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
298 ad_close(&ad, ADFLAGS_HF);
299 if (!unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) )
304 else { /* it's something else, bail out */
316 #ifdef HAVE_NFSv4_ACLS
317 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
319 static char buf[ MAXPATHLEN + 1];
323 if ((stat(path, &st)) != 0)
325 if (S_ISDIR(st.st_mode)) {
326 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
327 if (len < 0 || len >= MAXPATHLEN)
329 /* set acl on .AppleDouble dir first */
330 if ((acl(buf, cmd, count, aces)) != 0)
332 /* now set ACL on ressource fork */
333 if ((acl(vol->vfs->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
336 /* set ACL on ressource fork */
337 if ((acl(vol->vfs->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
343 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
346 static char buf[ MAXPATHLEN + 1];
350 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
351 if (len < 0 || len >= MAXPATHLEN)
353 /* remove ACL from .AppleDouble/.Parent first */
354 if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
356 /* now remove from .AppleDouble dir */
357 if ((ret = remove_acl(buf)) != AFP_OK)
360 /* remove ACL from ressource fork */
361 if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_HF))) != AFP_OK)
368 /*********************************************************************************
370 *********************************************************************************/
371 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
373 struct perm *owner = data;
375 if (chown( name , owner->uid, owner->gid ) < 0) {
381 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
391 ad_p = ad_dir(vol->vfs->ad_path(path, ADFLAGS_HF ));
393 if ( stat( ad_p, &st ) < 0 ) {
398 if (chown( ad_p, uid, gid ) < 0) {
401 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
404 /* --------------------------------- */
405 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
407 return netatalk_unlink(name);
410 static int ads_delete_rf(char *name)
414 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
417 * it's a problem for a nfs mounted folder, there's .nfsxxx around
418 * for linux the following line solve it.
419 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
421 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
423 return netatalk_rmdir(name);
426 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
430 /* bail if the file exists in the current directory.
431 * note: this will not fail with dangling symlinks */
433 if (stat(de->d_name, &st) == 0) {
434 return AFPERR_DIRNEMPT;
436 return ads_delete_rf(name);
439 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
443 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
444 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
446 return netatalk_rmdir( ".AppleDouble" );
449 /* ------------------- */
455 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
457 struct set_mode *param = data;
459 return setfilmode(name, param->mode, param->st, v_umask);
462 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
464 mode_t file_mode = ad_hf_mode(mode);
465 mode_t dir_mode = file_mode;
466 struct set_mode param;
468 if ((dir_mode & (S_IRUSR | S_IWUSR )))
470 if ((dir_mode & (S_IRGRP | S_IWGRP )))
472 if ((dir_mode & (S_IROTH | S_IWOTH )))
477 if (dir_rx_set(dir_mode)) {
478 if (chmod( name, dir_mode ) < 0)
482 param.mode = file_mode;
483 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
486 if (!dir_rx_set(dir_mode)) {
487 if (chmod( name, dir_mode ) < 0)
494 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
496 return ads_setfilmode(ad_dir(vol->vfs->ad_path( name, ADFLAGS_HF )), mode, st, vol->v_umask);
499 /* ------------------- */
500 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
502 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
503 char ad_p[ MAXPATHLEN + 1];
504 int dropbox = vol->v_flags;
506 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
508 if (dir_rx_set(mode)) {
511 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
514 /* .AppleDouble/.Parent */
515 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
519 if (ads_setfilmode(ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
522 if (!dir_rx_set(mode)) {
523 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
525 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
531 /* ------------------- */
537 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
540 struct dir_mode *param = data;
541 int ret = 0; /* 0 ignore error, -1 */
543 if (dir_rx_set(param->mode)) {
544 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
551 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
554 if (!dir_rx_set(param->mode)) {
555 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
565 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
567 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
568 char ad_p[ MAXPATHLEN + 1];
569 struct dir_mode param;
572 param.dropbox = vol->v_flags;
574 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
576 if (dir_rx_set(mode)) {
578 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
582 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
585 if (!dir_rx_set(mode)) {
586 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
592 /* ------------------- */
593 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
595 struct perm *owner = data;
597 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
598 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
599 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
600 /* return ( -1 ); Sometimes this is okay */
605 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
607 struct perm *owner = data;
609 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
612 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
613 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
614 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
615 /* return ( -1 ); Sometimes this is okay */
620 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
622 int noadouble = vol_noadouble(vol);
623 char adouble_p[ MAXPATHLEN + 1];
630 strlcpy(adouble_p, ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR )), sizeof(adouble_p));
632 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
636 * We cheat: we know that chown doesn't do anything.
638 if ( stat( ".AppleDouble", &st ) < 0) {
639 if (errno == ENOENT && noadouble)
641 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
644 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
645 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
646 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
647 /* return ( -1 ); Sometimes this is okay */
652 /* ------------------- */
653 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
655 char *ad_p = ad_dir(vol->vfs->ad_path(file, ADFLAGS_HF ));
657 return ads_delete_rf(ad_p);
660 /* --------------------------- */
661 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
663 char adsrc[ MAXPATHLEN + 1];
666 strcpy( adsrc, ad_dir(vol->vfs->ad_path( src, 0 )));
667 if (unix_rename( adsrc, ad_dir(vol->vfs->ad_path( dst, 0 ))) < 0) {
671 if (errno == ENOENT) {
674 if (stat(adsrc, &st)) /* source has no ressource fork, */
677 /* We are here because :
678 * -there's no dest folder.
679 * -there's no .AppleDouble in the dest folder.
680 * if we use the struct adouble passed in parameter it will not
681 * create .AppleDouble if the file is already opened, so we
682 * use a diff one, it's not a pb,ie it's not the same file, yet.
684 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
685 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
686 ad_close(&ad, ADFLAGS_HF);
688 /* We must delete it */
689 RF_deletefile_ads(vol, dst );
690 if (!unix_rename( adsrc, ad_dir(vol->vfs->ad_path( dst, 0 ))) )
695 else { /* it's something else, bail out */
707 /*************************************************************************
709 ************************************************************************/
710 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
712 return strncmp(name,"._", 2) && (
713 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
716 /* ---------------- */
717 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
719 /* We simply move the corresponding ad file as well */
720 char tempbuf[258]="._";
721 return rename(vol->vfs->ad_path(oldpath,0),strcat(tempbuf,newpath));
724 /* ---------------- */
725 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
727 return netatalk_unlink( vol->vfs->ad_path(".",0) );
730 /* ---------------- */
731 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
733 return adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_DIR ), mode, st, vol->v_umask);
736 /* ---------------- */
737 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
742 /* ---------------- */
743 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
748 /* ---------------- */
749 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
751 char adsrc[ MAXPATHLEN + 1];
754 strcpy( adsrc, vol->vfs->ad_path( src, 0 ));
756 if (unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) < 0) {
760 if (errno == ENOENT && stat(adsrc, &st)) /* source has no ressource fork, */
768 /********************************************************************************************
770 ********************************************************************************************/
773 * Up until we really start stacking many VFS modules on top of one another or use
774 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
775 * via an fixed size array.
776 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
777 * this error code will be returned to the caller, BUT the chain in followed and all
778 * following funcs are called in order to give them a chance.
782 * Currently the maximum will be:
783 * main adouble module + EA module + ACL module + NULL = 4.
784 * NULL is an end of array marker.
786 static struct vfs_ops *vfs[4] = { NULL };
789 * Define most VFS funcs with macros as they all do the same.
790 * Only "ad_path" and "validupath" will NOT do stacking and only
791 * call the func from the first module.
793 #define VFS_MFUNC(name, args, vars) \
794 static int vfs_ ## name(args) \
796 int i = 0, ret = AFP_OK, err; \
798 if (vfs[i]->vfs_ ## name) { \
799 err = vfs[i]->vfs_ ## name (vars); \
800 if ((ret == AFP_OK) && (err != AFP_OK)) \
808 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
809 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
810 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
811 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
812 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
813 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
814 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
815 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
816 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
817 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
818 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
819 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
820 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
821 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
822 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
823 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
824 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
826 static char *vfs_path(const char *path, int flags)
828 return vfs[0]->ad_path(path, flags);
831 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
833 return vfs[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
837 * These function pointers get called from the lib users via vol->vfs->func.
838 * These funcs are defined via the macros above.
840 struct vfs_ops vfs_master_funcs = {
863 * Primary adouble modules: default, osx, sfm
866 static struct vfs_ops netatalk_adouble = {
867 /* vfs_path: */ ad_path,
868 /* vfs_validupath: */ validupath_adouble,
869 /* vfs_chown: */ RF_chown_adouble,
870 /* vfs_renamedir: */ RF_renamedir_adouble,
871 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
872 /* vfs_setfilmode: */ RF_setfilmode_adouble,
873 /* vfs_setdirmode: */ RF_setdirmode_adouble,
874 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
875 /* vfs_setdirowner: */ RF_setdirowner_adouble,
876 /* vfs_deletefile: */ RF_deletefile_adouble,
877 /* vfs_renamefile: */ RF_renamefile_adouble
881 static struct vfs_ops netatalk_adouble_osx = {
882 /* vfs_path: */ ad_path_osx,
883 /* vfs_validupath: */ validupath_osx,
884 /* vfs_chown: */ RF_chown_adouble,
885 /* vfs_renamedir: */ RF_renamedir_osx,
886 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
887 /* vfs_setfilmode: */ RF_setfilmode_adouble,
888 /* vfs_setdirmode: */ RF_setdirmode_osx,
889 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
890 /* vfs_setdirowner: */ RF_setdirowner_osx,
891 /* vfs_deletefile: */ RF_deletefile_adouble,
892 /* vfs_renamefile: */ RF_renamefile_osx
895 /* samba sfm format. ad_path shouldn't be set her */
896 static struct vfs_ops netatalk_adouble_sfm = {
897 /* vfs_path: */ ad_path_sfm,
898 /* vfs_validupath: */ validupath_adouble,
899 /* vfs_chown: */ RF_chown_ads,
900 /* vfs_renamedir: */ RF_renamedir_adouble,
901 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
902 /* vfs_setfilmode: */ RF_setfilmode_ads,
903 /* vfs_setdirmode: */ RF_setdirmode_ads,
904 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
905 /* vfs_setdirowner: */ RF_setdirowner_ads,
906 /* vfs_deletefile: */ RF_deletefile_ads,
907 /* vfs_renamefile: */ RF_renamefile_ads,
911 * Secondary vfs modules for Extended Attributes
914 struct vfs_ops netatalk_ea_adouble = {
915 /* vfs_path: */ NULL,
916 /* vfs_validupath: */ NULL,
917 /* vfs_chown: */ ea_chown,
918 /* vfs_renamedir: */ NULL, /* ok */
919 /* vfs_deletecurdir: */ NULL, /* ok */
920 /* vfs_setfilmode: */ ea_chmod_file,
921 /* vfs_setdirmode: */ NULL, /* ok */
922 /* vfs_setdirunixmode:*/ ea_chmod_dir,
923 /* vfs_setdirowner: */ NULL, /* ok */
924 /* vfs_deletefile: */ ea_deletefile,
925 /* vfs_renamefile: */ ea_renamefile,
926 /* vfs_copyfile */ ea_copyfile,
928 /* vfs_remove_acl */ NULL,
929 /* vfs_getsize */ get_easize,
930 /* vfs_getcontent */ get_eacontent,
931 /* vfs_list */ list_eas,
932 /* vfs_set */ set_ea,
933 /* vfs_remove */ remove_ea
936 #ifdef HAVE_SOLARIS_EAS
937 struct vfs_ops netatalk_ea_solaris = {
939 /* validupath: */ NULL,
940 /* rf_chown: */ NULL,
941 /* rf_renamedir: */ NULL,
942 /* rf_deletecurdir: */ NULL,
943 /* rf_setfilmode: */ NULL,
944 /* rf_setdirmode: */ NULL,
945 /* rf_setdirunixmode: */ NULL,
946 /* rf_setdirowner: */ NULL,
947 /* rf_deletefile: */ NULL,
948 /* rf_renamefile: */ NULL,
949 /* vfs_copyfile: */ NULL,
951 /* rf_remove_acl */ NULL,
952 /* ea_getsize */ sol_get_easize,
953 /* ea_getcontent */ sol_get_eacontent,
954 /* ea_list */ sol_list_eas,
955 /* ea_set */ sol_set_ea,
956 /* ea_remove */ sol_remove_ea
961 * Tertiary attributes for ACLs
964 #ifdef HAVE_NFSv4_ACLS
965 struct vfs_ops netatalk_solaris_acl_adouble = {
967 /* validupath: */ NULL,
968 /* rf_chown: */ NULL,
969 /* rf_renamedir: */ NULL,
970 /* rf_deletecurdir: */ NULL,
971 /* rf_setfilmode: */ NULL,
972 /* rf_setdirmode: */ NULL,
973 /* rf_setdirunixmode: */ NULL,
974 /* rf_setdirowner: */ NULL,
975 /* rf_deletefile: */ NULL,
976 /* rf_renamefile: */ NULL,
977 /* vfs_copyfile */ NULL,
978 /* rf_acl: */ RF_solaris_acl,
979 /* rf_remove_acl */ RF_remove_acl
983 /* ---------------- */
984 void initvol_vfs(struct vol *vol)
986 vol->vfs = &vfs_master_funcs;
988 /* Default adouble stuff */
989 if (vol->v_adouble == AD_VERSION2_OSX) {
990 vfs[0] = &netatalk_adouble_osx;
992 else if (vol->v_adouble == AD_VERSION1_SFM) {
993 vfs[0] = &netatalk_adouble_sfm;
996 vfs[0] = &netatalk_adouble;
999 /* Extended Attributes */
1000 if (vol->v_vfs_ea == AFPVOL_EA_SOLARIS) {
1002 #ifdef HAVE_SOLARIS_EAS
1003 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with Solaris native EAs.");
1004 vfs[1] = &netatalk_ea_solaris;
1006 LOG(log_error, logtype_afpd, "initvol_vfs: Can't enable Solaris EA support.");
1011 /* default: AFPVOL_EA_AD */
1012 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with adouble files.");
1013 vfs[1] = &netatalk_ea_adouble;
1017 #ifdef HAVE_NFSv4_ACLS
1018 vfs[2] = &netatalk_solaris_acl_adouble;