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];
322 if ((stat(path, &st)) != 0)
324 if (S_ISDIR(st.st_mode)) {
325 if ((snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path)) < 0)
327 /* set acl on .AppleDouble dir first */
328 if ((acl(buf, cmd, count, aces)) != 0)
330 /* now set ACL on ressource fork */
331 if ((acl(vol->vfs->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
334 /* set ACL on ressource fork */
335 if ((acl(vol->vfs->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
341 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
344 static char buf[ MAXPATHLEN + 1];
347 if ((snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path)) < 0)
349 /* remove ACL from .AppleDouble/.Parent first */
350 if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
352 /* now remove from .AppleDouble dir */
353 if ((ret = remove_acl(buf)) != AFP_OK)
356 /* remove ACL from ressource fork */
357 if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_HF))) != AFP_OK)
364 /*********************************************************************************
366 *********************************************************************************/
367 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
369 struct perm *owner = data;
371 if (chown( name , owner->uid, owner->gid ) < 0) {
377 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
387 ad_p = ad_dir(vol->vfs->ad_path(path, ADFLAGS_HF ));
389 if ( stat( ad_p, &st ) < 0 ) {
394 if (chown( ad_p, uid, gid ) < 0) {
397 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
400 /* --------------------------------- */
401 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
403 return netatalk_unlink(name);
406 static int ads_delete_rf(char *name)
410 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
413 * it's a problem for a nfs mounted folder, there's .nfsxxx around
414 * for linux the following line solve it.
415 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
417 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
419 return netatalk_rmdir(name);
422 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
426 /* bail if the file exists in the current directory.
427 * note: this will not fail with dangling symlinks */
429 if (stat(de->d_name, &st) == 0) {
430 return AFPERR_DIRNEMPT;
432 return ads_delete_rf(name);
435 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
439 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
440 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
442 return netatalk_rmdir( ".AppleDouble" );
445 /* ------------------- */
451 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
453 struct set_mode *param = data;
455 return setfilmode(name, param->mode, param->st, v_umask);
458 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
460 mode_t file_mode = ad_hf_mode(mode);
461 mode_t dir_mode = file_mode;
462 struct set_mode param;
464 if ((dir_mode & (S_IRUSR | S_IWUSR )))
466 if ((dir_mode & (S_IRGRP | S_IWGRP )))
468 if ((dir_mode & (S_IROTH | S_IWOTH )))
473 if (dir_rx_set(dir_mode)) {
474 if (chmod( name, dir_mode ) < 0)
478 param.mode = file_mode;
479 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
482 if (!dir_rx_set(dir_mode)) {
483 if (chmod( name, dir_mode ) < 0)
490 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
492 return ads_setfilmode(ad_dir(vol->vfs->ad_path( name, ADFLAGS_HF )), mode, st, vol->v_umask);
495 /* ------------------- */
496 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
498 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
499 char ad_p[ MAXPATHLEN + 1];
500 int dropbox = vol->v_flags;
502 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
504 if (dir_rx_set(mode)) {
507 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
510 /* .AppleDouble/.Parent */
511 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
515 if (ads_setfilmode(ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
518 if (!dir_rx_set(mode)) {
519 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
521 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
527 /* ------------------- */
533 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
536 struct dir_mode *param = data;
537 int ret = 0; /* 0 ignore error, -1 */
539 if (dir_rx_set(param->mode)) {
540 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
547 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
550 if (!dir_rx_set(param->mode)) {
551 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
561 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
563 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
564 char ad_p[ MAXPATHLEN + 1];
565 struct dir_mode param;
568 param.dropbox = vol->v_flags;
570 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
572 if (dir_rx_set(mode)) {
574 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
578 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
581 if (!dir_rx_set(mode)) {
582 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
588 /* ------------------- */
589 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
591 struct perm *owner = data;
593 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
594 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
595 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
596 /* return ( -1 ); Sometimes this is okay */
601 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
603 struct perm *owner = data;
605 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
608 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
609 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
610 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
611 /* return ( -1 ); Sometimes this is okay */
616 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
618 int noadouble = vol_noadouble(vol);
619 char adouble_p[ MAXPATHLEN + 1];
626 strlcpy(adouble_p, ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR )), sizeof(adouble_p));
628 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
632 * We cheat: we know that chown doesn't do anything.
634 if ( stat( ".AppleDouble", &st ) < 0) {
635 if (errno == ENOENT && noadouble)
637 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
640 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
641 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
642 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
643 /* return ( -1 ); Sometimes this is okay */
648 /* ------------------- */
649 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
651 char *ad_p = ad_dir(vol->vfs->ad_path(file, ADFLAGS_HF ));
653 return ads_delete_rf(ad_p);
656 /* --------------------------- */
657 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
659 char adsrc[ MAXPATHLEN + 1];
662 strcpy( adsrc, ad_dir(vol->vfs->ad_path( src, 0 )));
663 if (unix_rename( adsrc, ad_dir(vol->vfs->ad_path( dst, 0 ))) < 0) {
667 if (errno == ENOENT) {
670 if (stat(adsrc, &st)) /* source has no ressource fork, */
673 /* We are here because :
674 * -there's no dest folder.
675 * -there's no .AppleDouble in the dest folder.
676 * if we use the struct adouble passed in parameter it will not
677 * create .AppleDouble if the file is already opened, so we
678 * use a diff one, it's not a pb,ie it's not the same file, yet.
680 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
681 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
682 ad_close(&ad, ADFLAGS_HF);
684 /* We must delete it */
685 RF_deletefile_ads(vol, dst );
686 if (!unix_rename( adsrc, ad_dir(vol->vfs->ad_path( dst, 0 ))) )
691 else { /* it's something else, bail out */
703 /*************************************************************************
705 ************************************************************************/
706 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
708 return strncmp(name,"._", 2) && (
709 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
712 /* ---------------- */
713 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
715 /* We simply move the corresponding ad file as well */
716 char tempbuf[258]="._";
717 return rename(vol->vfs->ad_path(oldpath,0),strcat(tempbuf,newpath));
720 /* ---------------- */
721 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
723 return netatalk_unlink( vol->vfs->ad_path(".",0) );
726 /* ---------------- */
727 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
729 return adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_DIR ), mode, st, vol->v_umask);
732 /* ---------------- */
733 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
738 /* ---------------- */
739 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
744 /* ---------------- */
745 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
747 char adsrc[ MAXPATHLEN + 1];
750 strcpy( adsrc, vol->vfs->ad_path( src, 0 ));
752 if (unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) < 0) {
756 if (errno == ENOENT && stat(adsrc, &st)) /* source has no ressource fork, */
764 /********************************************************************************************
766 ********************************************************************************************/
769 * Up until we really start stacking many VFS modules on top of one another or use
770 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
771 * via an fixed size array.
772 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
773 * this error code will be returned to the caller, BUT the chain in followed and all
774 * following funcs are called in order to give them a chance.
778 * Currently the maximum will be:
779 * main adouble module + EA module + ACL module + NULL = 4.
780 * NULL is an end of array marker.
782 static struct vfs_ops *vfs[4] = { NULL };
785 * Define most VFS funcs with macros as they all do the same.
786 * Only "ad_path" and "validupath" will NOT do stacking and only
787 * call the func from the first module.
789 #define VFS_MFUNC(name, args, vars) \
790 static int vfs_ ## name(args) \
792 int i = 0, ret = AFP_OK, err; \
794 if (vfs[i]->vfs_ ## name) { \
795 err = vfs[i]->vfs_ ## name (vars); \
796 if ((ret == AFP_OK) && (err != AFP_OK)) \
804 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
805 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
806 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
807 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
808 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
809 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
810 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
811 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
812 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
813 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
814 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
815 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
816 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
817 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
818 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
819 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
820 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
822 static char *vfs_path(const char *path, int flags)
824 return vfs[0]->ad_path(path, flags);
827 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
829 return vfs[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
833 * These function pointers get called from the lib users via vol->vfs->func.
834 * These funcs are defined via the macros above.
836 struct vfs_ops vfs_master_funcs = {
859 * Primary adouble modules: default, osx, sfm
862 static struct vfs_ops netatalk_adouble = {
863 /* vfs_path: */ ad_path,
864 /* vfs_validupath: */ validupath_adouble,
865 /* vfs_chown: */ RF_chown_adouble,
866 /* vfs_renamedir: */ RF_renamedir_adouble,
867 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
868 /* vfs_setfilmode: */ RF_setfilmode_adouble,
869 /* vfs_setdirmode: */ RF_setdirmode_adouble,
870 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
871 /* vfs_setdirowner: */ RF_setdirowner_adouble,
872 /* vfs_deletefile: */ RF_deletefile_adouble,
873 /* vfs_renamefile: */ RF_renamefile_adouble
877 static struct vfs_ops netatalk_adouble_osx = {
878 /* vfs_path: */ ad_path_osx,
879 /* vfs_validupath: */ validupath_osx,
880 /* vfs_chown: */ RF_chown_adouble,
881 /* vfs_renamedir: */ RF_renamedir_osx,
882 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
883 /* vfs_setfilmode: */ RF_setfilmode_adouble,
884 /* vfs_setdirmode: */ RF_setdirmode_osx,
885 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
886 /* vfs_setdirowner: */ RF_setdirowner_osx,
887 /* vfs_deletefile: */ RF_deletefile_adouble,
888 /* vfs_renamefile: */ RF_renamefile_osx
891 /* samba sfm format. ad_path shouldn't be set her */
892 static struct vfs_ops netatalk_adouble_sfm = {
893 /* vfs_path: */ ad_path_sfm,
894 /* vfs_validupath: */ validupath_adouble,
895 /* vfs_chown: */ RF_chown_ads,
896 /* vfs_renamedir: */ RF_renamedir_adouble,
897 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
898 /* vfs_setfilmode: */ RF_setfilmode_ads,
899 /* vfs_setdirmode: */ RF_setdirmode_ads,
900 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
901 /* vfs_setdirowner: */ RF_setdirowner_ads,
902 /* vfs_deletefile: */ RF_deletefile_ads,
903 /* vfs_renamefile: */ RF_renamefile_ads,
907 * Secondary vfs modules for Extended Attributes
910 struct vfs_ops netatalk_ea_adouble = {
911 /* vfs_path: */ NULL,
912 /* vfs_validupath: */ NULL,
913 /* vfs_chown: */ ea_chown,
914 /* vfs_renamedir: */ NULL, /* ok */
915 /* vfs_deletecurdir: */ NULL, /* ok */
916 /* vfs_setfilmode: */ NULL,
917 /* vfs_setdirmode: */ NULL,
918 /* vfs_setdirunixmode:*/ NULL,
919 /* vfs_setdirowner: */ NULL,
920 /* vfs_deletefile: */ ea_deletefile,
921 /* vfs_renamefile: */ ea_renamefile,
922 /* vfs_copyfile */ ea_copyfile,
924 /* vfs_remove_acl */ NULL,
925 /* vfs_getsize */ get_easize,
926 /* vfs_getcontent */ get_eacontent,
927 /* vfs_list */ list_eas,
928 /* vfs_set */ set_ea,
929 /* vfs_remove */ remove_ea
932 #ifdef HAVE_SOLARIS_EAS
933 struct vfs_ops netatalk_ea_solaris = {
935 /* validupath: */ NULL,
936 /* rf_chown: */ NULL,
937 /* rf_renamedir: */ NULL,
938 /* rf_deletecurdir: */ NULL,
939 /* rf_setfilmode: */ NULL,
940 /* rf_setdirmode: */ NULL,
941 /* rf_setdirunixmode: */ NULL,
942 /* rf_setdirowner: */ NULL,
943 /* rf_deletefile: */ NULL,
944 /* rf_renamefile: */ NULL,
945 /* vfs_copyfile: */ NULL,
947 /* rf_remove_acl */ NULL,
948 /* ea_getsize */ sol_get_easize,
949 /* ea_getcontent */ sol_get_eacontent,
950 /* ea_list */ sol_list_eas,
951 /* ea_set */ sol_set_ea,
952 /* ea_remove */ sol_remove_ea
957 * Tertiary attributes for ACLs
960 #ifdef HAVE_NFSv4_ACLS
961 struct vfs_ops netatalk_solaris_acl_adouble = {
963 /* validupath: */ NULL,
964 /* rf_chown: */ NULL,
965 /* rf_renamedir: */ NULL,
966 /* rf_deletecurdir: */ NULL,
967 /* rf_setfilmode: */ NULL,
968 /* rf_setdirmode: */ NULL,
969 /* rf_setdirunixmode: */ NULL,
970 /* rf_setdirowner: */ NULL,
971 /* rf_deletefile: */ NULL,
972 /* rf_renamefile: */ NULL,
973 /* vfs_copyfile */ NULL,
974 /* rf_acl: */ RF_solaris_acl,
975 /* rf_remove_acl */ RF_remove_acl
979 /* ---------------- */
980 void initvol_vfs(struct vol *vol)
982 vol->vfs = &vfs_master_funcs;
984 /* Default adouble stuff */
985 if (vol->v_adouble == AD_VERSION2_OSX) {
986 vfs[0] = &netatalk_adouble_osx;
988 else if (vol->v_adouble == AD_VERSION1_SFM) {
989 vfs[0] = &netatalk_adouble_sfm;
992 vfs[0] = &netatalk_adouble;
995 /* Extended Attributes */
996 if (vol->v_vfs_ea == AFPVOL_EA_SOLARIS) {
998 #ifdef HAVE_SOLARIS_EAS
999 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with Solaris native EAs.");
1000 vfs[1] = &netatalk_ea_solaris;
1002 LOG(log_error, logtype_afpd, "initvol_vfs: Can't enable Solaris EA support.");
1007 /* default: AFPVOL_EA_AD */
1008 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with adouble files.");
1009 vfs[1] = &netatalk_ea_adouble;
1013 #ifdef HAVE_NFSv4_ACLS
1014 vfs[2] = &netatalk_solaris_acl_adouble;