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 */
27 #include <atalk/afp.h>
28 #include <atalk/adouble.h>
29 #include <atalk/vfs.h>
31 #include <atalk/acl.h>
32 #include <atalk/logger.h>
33 #include <atalk/util.h>
34 #include <atalk/volume.h>
35 #include <atalk/directory.h>
36 #include <atalk/unix.h>
43 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
45 /* ----------------------------- */
47 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
49 char buf[ MAXPATHLEN + 1];
56 if (NULL == ( dp = opendir( name)) ) {
58 LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
63 strlcpy( buf, name, sizeof(buf));
64 strlcat( buf, "/", sizeof(buf) );
65 m = strchr( buf, '\0' );
67 while ((de = readdir(dp))) {
68 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
72 strlcat(buf, de->d_name, sizeof(buf));
73 if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
83 /*******************************************************************************
84 * classic adouble format
85 *******************************************************************************/
87 static int netatalk_name(const char *name)
89 return strcasecmp(name,".AppleDB") &&
90 strcasecmp(name,".AppleDouble") &&
91 strcasecmp(name,".AppleDesktop");
94 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
96 return (vol->v_flags & AFPVOL_USEDOTS) ?
97 netatalk_name(name) && strcasecmp(name,".Parent"): name[0] != '.';
100 /* ----------------- */
101 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
106 ad_p = vol->vfs->ad_path(path, ADFLAGS_HF );
108 if ( stat( ad_p, &st ) < 0 )
109 return 0; /* ignore */
111 return chown( ad_p, uid, gid );
114 /* ----------------- */
115 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
120 /* ----------------- */
121 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
126 /* bail if the file exists in the current directory.
127 * note: this will not fail with dangling symlinks */
129 if (stat(de->d_name, &st) == 0)
130 return AFPERR_DIRNEMPT;
132 if ((err = netatalk_unlink(name)))
138 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
142 /* delete stray .AppleDouble files. this happens to get .Parent files
144 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask)))
146 return netatalk_rmdir( ".AppleDouble" );
149 /* ----------------- */
150 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
152 return setfilmode(name, ad_hf_mode(mode), st, v_umask);
155 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
157 return adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_HF ), mode, st, vol->v_umask);
160 /* ----------------- */
161 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
163 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
164 int dropbox = vol->v_flags;
166 if (dir_rx_set(mode)) {
167 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
171 if (adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0)
174 if (!dir_rx_set(mode)) {
175 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 )
181 /* ----------------- */
182 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
184 mode_t hf_mode = *(mode_t *)data;
187 if ( stat( name, &st ) < 0 ) {
190 LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
192 else if (!S_ISDIR(st.st_mode)) {
193 if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
194 /* FIXME what do we do then? */
200 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
202 int dropbox = vol->v_flags;
203 mode_t hf_mode = ad_hf_mode(mode);
204 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
205 char *adouble_p = ad_dir(adouble);
207 if (dir_rx_set(mode)) {
208 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
212 if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
215 if (!dir_rx_set(mode)) {
216 if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0)
222 /* ----------------- */
223 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
225 struct perm *owner = data;
227 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
228 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
229 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
230 /* return ( -1 ); Sometimes this is okay */
235 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
237 int noadouble = vol_noadouble(vol);
245 adouble_p = ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR ));
247 if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask))
251 * We cheat: we know that chown doesn't do anything.
253 if ( stat( ".AppleDouble", &st ) < 0) {
254 if (errno == ENOENT && noadouble)
256 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
259 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
260 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
261 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
262 /* return ( -1 ); Sometimes this is okay */
267 /* ----------------- */
268 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
270 return netatalk_unlink(vol->vfs->ad_path( file, ADFLAGS_HF));
273 /* ----------------- */
274 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
276 char adsrc[ MAXPATHLEN + 1];
279 strcpy( adsrc, vol->vfs->ad_path( src, 0 ));
280 if (unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) < 0) {
284 if (errno == ENOENT) {
287 if (stat(adsrc, &st)) /* source has no ressource fork, */
290 /* We are here because :
291 * -there's no dest folder.
292 * -there's no .AppleDouble in the dest folder.
293 * if we use the struct adouble passed in parameter it will not
294 * create .AppleDouble if the file is already opened, so we
295 * use a diff one, it's not a pb,ie it's not the same file, yet.
297 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
298 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
299 ad_close(&ad, ADFLAGS_HF);
300 if (!unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) )
305 else { /* it's something else, bail out */
317 #ifdef HAVE_NFSv4_ACLS
318 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
320 static char buf[ MAXPATHLEN + 1];
324 if ((stat(path, &st)) != 0)
326 if (S_ISDIR(st.st_mode)) {
327 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
328 if (len < 0 || len >= MAXPATHLEN)
330 /* set acl on .AppleDouble dir first */
331 if ((acl(buf, cmd, count, aces)) != 0)
333 /* now set ACL on ressource fork */
334 if ((acl(vol->vfs->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
337 /* set ACL on ressource fork */
338 if ((acl(vol->vfs->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
344 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
347 static char buf[ MAXPATHLEN + 1];
351 len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
352 if (len < 0 || len >= MAXPATHLEN)
354 /* remove ACL from .AppleDouble/.Parent first */
355 if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
357 /* now remove from .AppleDouble dir */
358 if ((ret = remove_acl(buf)) != AFP_OK)
361 /* remove ACL from ressource fork */
362 if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_HF))) != AFP_OK)
369 /*********************************************************************************
371 *********************************************************************************/
372 static int ads_chown_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
374 struct perm *owner = data;
376 if (chown( name , owner->uid, owner->gid ) < 0) {
382 static int RF_chown_ads(VFS_FUNC_ARGS_CHOWN)
392 ad_p = ad_dir(vol->vfs->ad_path(path, ADFLAGS_HF ));
394 if ( stat( ad_p, &st ) < 0 ) {
399 if (chown( ad_p, uid, gid ) < 0) {
402 return for_each_adouble("chown_ads", ad_p, ads_chown_loop, &owner, 1, vol->v_umask);
405 /* --------------------------------- */
406 static int deletecurdir_ads1_loop(struct dirent *de _U_, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
408 return netatalk_unlink(name);
411 static int ads_delete_rf(char *name)
415 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
418 * it's a problem for a nfs mounted folder, there's .nfsxxx around
419 * for linux the following line solve it.
420 * but it could fail if rm .nfsxxx create a new .nfsyyy :(
422 if ((err = for_each_adouble("deletecurdir", name, deletecurdir_ads1_loop, NULL, 1, 0)))
424 return netatalk_rmdir(name);
427 static int deletecurdir_ads_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask _U_)
431 /* bail if the file exists in the current directory.
432 * note: this will not fail with dangling symlinks */
434 if (stat(de->d_name, &st) == 0) {
435 return AFPERR_DIRNEMPT;
437 return ads_delete_rf(name);
440 static int RF_deletecurdir_ads(VFS_FUNC_ARGS_DELETECURDIR)
444 /* delete stray .AppleDouble files. this happens to get .Parent files as well. */
445 if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_ads_loop, NULL, 1, 0)))
447 return netatalk_rmdir( ".AppleDouble" );
450 /* ------------------- */
456 static int ads_setfilmode_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask)
458 struct set_mode *param = data;
460 return setfilmode(name, param->mode, param->st, v_umask);
463 static int ads_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
465 mode_t file_mode = ad_hf_mode(mode);
466 mode_t dir_mode = file_mode;
467 struct set_mode param;
469 if ((dir_mode & (S_IRUSR | S_IWUSR )))
471 if ((dir_mode & (S_IRGRP | S_IWGRP )))
473 if ((dir_mode & (S_IROTH | S_IWOTH )))
478 if (dir_rx_set(dir_mode)) {
479 if (chmod( name, dir_mode ) < 0)
483 param.mode = file_mode;
484 if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, ¶m, 0, v_umask) < 0)
487 if (!dir_rx_set(dir_mode)) {
488 if (chmod( name, dir_mode ) < 0)
495 static int RF_setfilmode_ads(VFS_FUNC_ARGS_SETFILEMODE)
497 return ads_setfilmode(ad_dir(vol->vfs->ad_path( name, ADFLAGS_HF )), mode, st, vol->v_umask);
500 /* ------------------- */
501 static int RF_setdirunixmode_ads(VFS_FUNC_ARGS_SETDIRUNIXMODE)
503 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
504 char ad_p[ MAXPATHLEN + 1];
505 int dropbox = vol->v_flags;
507 strlcpy(ad_p,ad_dir(adouble), MAXPATHLEN + 1);
509 if (dir_rx_set(mode)) {
512 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
515 /* .AppleDouble/.Parent */
516 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
520 if (ads_setfilmode(ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR)), mode, st, vol->v_umask) < 0)
523 if (!dir_rx_set(mode)) {
524 if (stickydirmode(ad_p, DIRBITS | mode, dropbox, vol->v_umask) < 0)
526 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, dropbox, vol->v_umask) < 0)
532 /* ------------------- */
538 static int setdirmode_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
541 struct dir_mode *param = data;
542 int ret = 0; /* 0 ignore error, -1 */
544 if (dir_rx_set(param->mode)) {
545 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
552 if (ads_setfilmode(name, param->mode, NULL, v_umask) < 0)
555 if (!dir_rx_set(param->mode)) {
556 if (stickydirmode(name, DIRBITS | param->mode, param->dropbox, v_umask) < 0) {
566 static int RF_setdirmode_ads(VFS_FUNC_ARGS_SETDIRMODE)
568 char *adouble = vol->vfs->ad_path( name, ADFLAGS_DIR );
569 char ad_p[ MAXPATHLEN + 1];
570 struct dir_mode param;
573 param.dropbox = vol->v_flags;
575 strlcpy(ad_p,ad_dir(adouble), sizeof(ad_p));
577 if (dir_rx_set(mode)) {
579 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0)
583 if (for_each_adouble("setdirmode_ads", ad_dir(ad_p), setdirmode_ads_loop, ¶m, vol_noadouble(vol), vol->v_umask))
586 if (!dir_rx_set(mode)) {
587 if (stickydirmode(ad_dir(ad_p), DIRBITS | mode, param.dropbox, vol->v_umask) < 0 )
593 /* ------------------- */
594 static int setdirowner_ads1_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
596 struct perm *owner = data;
598 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
599 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
600 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
601 /* return ( -1 ); Sometimes this is okay */
606 static int setdirowner_ads_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask _U_)
608 struct perm *owner = data;
610 if (for_each_adouble("setdirowner", name, setdirowner_ads1_loop, data, flag, 0) < 0)
613 if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
614 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
615 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
616 /* return ( -1 ); Sometimes this is okay */
621 static int RF_setdirowner_ads(VFS_FUNC_ARGS_SETDIROWNER)
623 int noadouble = vol_noadouble(vol);
624 char adouble_p[ MAXPATHLEN + 1];
631 strlcpy(adouble_p, ad_dir(vol->vfs->ad_path( name, ADFLAGS_DIR )), sizeof(adouble_p));
633 if (for_each_adouble("setdirowner", ad_dir(adouble_p), setdirowner_ads_loop, &owner, noadouble, 0))
637 * We cheat: we know that chown doesn't do anything.
639 if ( stat( ".AppleDouble", &st ) < 0) {
640 if (errno == ENOENT && noadouble)
642 LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
645 if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
646 LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
647 uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
648 /* return ( -1 ); Sometimes this is okay */
653 /* ------------------- */
654 static int RF_deletefile_ads(VFS_FUNC_ARGS_DELETEFILE)
656 char *ad_p = ad_dir(vol->vfs->ad_path(file, ADFLAGS_HF ));
658 return ads_delete_rf(ad_p);
661 /* --------------------------- */
662 static int RF_renamefile_ads(VFS_FUNC_ARGS_RENAMEFILE)
664 char adsrc[ MAXPATHLEN + 1];
667 strcpy( adsrc, ad_dir(vol->vfs->ad_path( src, 0 )));
668 if (unix_rename( adsrc, ad_dir(vol->vfs->ad_path( dst, 0 ))) < 0) {
672 if (errno == ENOENT) {
675 if (stat(adsrc, &st)) /* source has no ressource fork, */
678 /* We are here because :
679 * -there's no dest folder.
680 * -there's no .AppleDouble in the dest folder.
681 * if we use the struct adouble passed in parameter it will not
682 * create .AppleDouble if the file is already opened, so we
683 * use a diff one, it's not a pb,ie it's not the same file, yet.
685 ad_init(&ad, vol->v_adouble, vol->v_ad_options);
686 if (!ad_open(dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666, &ad)) {
687 ad_close(&ad, ADFLAGS_HF);
689 /* We must delete it */
690 RF_deletefile_ads(vol, dst );
691 if (!unix_rename( adsrc, ad_dir(vol->vfs->ad_path( dst, 0 ))) )
696 else { /* it's something else, bail out */
708 /*************************************************************************
710 ************************************************************************/
711 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
713 return strncmp(name,"._", 2) && (
714 (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
717 /* ---------------- */
718 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
720 /* We simply move the corresponding ad file as well */
721 char tempbuf[258]="._";
722 return rename(vol->vfs->ad_path(oldpath,0),strcat(tempbuf,newpath));
725 /* ---------------- */
726 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
728 return netatalk_unlink( vol->vfs->ad_path(".",0) );
731 /* ---------------- */
732 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
734 return adouble_setfilmode(vol->vfs->ad_path( name, ADFLAGS_DIR ), mode, st, vol->v_umask);
737 /* ---------------- */
738 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
743 /* ---------------- */
744 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
749 /* ---------------- */
750 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
752 char adsrc[ MAXPATHLEN + 1];
755 strcpy( adsrc, vol->vfs->ad_path( src, 0 ));
757 if (unix_rename( adsrc, vol->vfs->ad_path( dst, 0 )) < 0) {
761 if (errno == ENOENT && stat(adsrc, &st)) /* source has no ressource fork, */
769 /********************************************************************************************
771 ********************************************************************************************/
774 * Up until we really start stacking many VFS modules on top of one another or use
775 * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
776 * via an fixed size array.
777 * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
778 * this error code will be returned to the caller, BUT the chain in followed and all
779 * following funcs are called in order to give them a chance.
783 * Currently the maximum will be:
784 * main adouble module + EA module + ACL module + NULL = 4.
785 * NULL is an end of array marker.
787 static struct vfs_ops *vfs[4] = { NULL };
790 * Define most VFS funcs with macros as they all do the same.
791 * Only "ad_path" and "validupath" will NOT do stacking and only
792 * call the func from the first module.
794 #define VFS_MFUNC(name, args, vars) \
795 static int vfs_ ## name(args) \
797 int i = 0, ret = AFP_OK, err; \
799 if (vfs[i]->vfs_ ## name) { \
800 err = vfs[i]->vfs_ ## name (vars); \
801 if ((ret == AFP_OK) && (err != AFP_OK)) \
809 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
810 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR)
811 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
812 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
813 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
814 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
815 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
816 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
817 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
818 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
819 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
820 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
821 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
822 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
823 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
824 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
825 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
827 static char *vfs_path(const char *path, int flags)
829 return vfs[0]->ad_path(path, flags);
832 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
834 return vfs[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
838 * These function pointers get called from the lib users via vol->vfs->func.
839 * These funcs are defined via the macros above.
841 static struct vfs_ops vfs_master_funcs = {
864 * Primary adouble modules: default, osx, sfm
867 static struct vfs_ops netatalk_adouble = {
868 /* vfs_path: */ ad_path,
869 /* vfs_validupath: */ validupath_adouble,
870 /* vfs_chown: */ RF_chown_adouble,
871 /* vfs_renamedir: */ RF_renamedir_adouble,
872 /* vfs_deletecurdir: */ RF_deletecurdir_adouble,
873 /* vfs_setfilmode: */ RF_setfilmode_adouble,
874 /* vfs_setdirmode: */ RF_setdirmode_adouble,
875 /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
876 /* vfs_setdirowner: */ RF_setdirowner_adouble,
877 /* vfs_deletefile: */ RF_deletefile_adouble,
878 /* vfs_renamefile: */ RF_renamefile_adouble,
882 static struct vfs_ops netatalk_adouble_osx = {
883 /* vfs_path: */ ad_path_osx,
884 /* vfs_validupath: */ validupath_osx,
885 /* vfs_chown: */ RF_chown_adouble,
886 /* vfs_renamedir: */ RF_renamedir_osx,
887 /* vfs_deletecurdir: */ RF_deletecurdir_osx,
888 /* vfs_setfilmode: */ RF_setfilmode_adouble,
889 /* vfs_setdirmode: */ RF_setdirmode_osx,
890 /* vfs_setdirunixmode:*/ RF_setdirunixmode_osx,
891 /* vfs_setdirowner: */ RF_setdirowner_osx,
892 /* vfs_deletefile: */ RF_deletefile_adouble,
893 /* vfs_renamefile: */ RF_renamefile_osx,
897 /* samba sfm format. ad_path shouldn't be set her */
898 static struct vfs_ops netatalk_adouble_sfm = {
899 /* vfs_path: */ ad_path_sfm,
900 /* vfs_validupath: */ validupath_adouble,
901 /* vfs_chown: */ RF_chown_ads,
902 /* vfs_renamedir: */ RF_renamedir_adouble,
903 /* vfs_deletecurdir: */ RF_deletecurdir_ads,
904 /* vfs_setfilmode: */ RF_setfilmode_ads,
905 /* vfs_setdirmode: */ RF_setdirmode_ads,
906 /* vfs_setdirunixmode:*/ RF_setdirunixmode_ads,
907 /* vfs_setdirowner: */ RF_setdirowner_ads,
908 /* vfs_deletefile: */ RF_deletefile_ads,
909 /* vfs_renamefile: */ RF_renamefile_ads,
914 * Secondary vfs modules for Extended Attributes
917 static struct vfs_ops netatalk_ea_adouble = {
918 /* vfs_path: */ NULL,
919 /* vfs_validupath: */ NULL,
920 /* vfs_chown: */ ea_chown,
921 /* vfs_renamedir: */ NULL, /* ok */
922 /* vfs_deletecurdir: */ NULL, /* ok */
923 /* vfs_setfilmode: */ ea_chmod_file,
924 /* vfs_setdirmode: */ NULL, /* ok */
925 /* vfs_setdirunixmode:*/ ea_chmod_dir,
926 /* vfs_setdirowner: */ NULL, /* ok */
927 /* vfs_deletefile: */ ea_deletefile,
928 /* vfs_renamefile: */ ea_renamefile,
929 /* vfs_copyfile */ ea_copyfile,
931 /* vfs_remove_acl */ NULL,
932 /* vfs_getsize */ get_easize,
933 /* vfs_getcontent */ get_eacontent,
934 /* vfs_list */ list_eas,
935 /* vfs_set */ set_ea,
936 /* vfs_remove */ remove_ea
939 #ifdef HAVE_SOLARIS_EAS
940 static struct vfs_ops netatalk_ea_solaris = {
942 /* validupath: */ NULL,
943 /* rf_chown: */ NULL,
944 /* rf_renamedir: */ NULL,
945 /* rf_deletecurdir: */ NULL,
946 /* rf_setfilmode: */ NULL,
947 /* rf_setdirmode: */ NULL,
948 /* rf_setdirunixmode: */ NULL,
949 /* rf_setdirowner: */ NULL,
950 /* rf_deletefile: */ NULL,
951 /* rf_renamefile: */ NULL,
952 /* vfs_copyfile: */ NULL,
954 /* rf_remove_acl */ NULL,
955 /* ea_getsize */ sol_get_easize,
956 /* ea_getcontent */ sol_get_eacontent,
957 /* ea_list */ sol_list_eas,
958 /* ea_set */ sol_set_ea,
959 /* ea_remove */ sol_remove_ea
964 * Tertiary VFS modules for ACLs
967 #ifdef HAVE_NFSv4_ACLS
968 static struct vfs_ops netatalk_solaris_acl_adouble = {
970 /* validupath: */ NULL,
971 /* rf_chown: */ NULL,
972 /* rf_renamedir: */ NULL,
973 /* rf_deletecurdir: */ NULL,
974 /* rf_setfilmode: */ NULL,
975 /* rf_setdirmode: */ NULL,
976 /* rf_setdirunixmode: */ NULL,
977 /* rf_setdirowner: */ NULL,
978 /* rf_deletefile: */ NULL,
979 /* rf_renamefile: */ NULL,
980 /* vfs_copyfile */ NULL,
981 /* rf_acl: */ RF_solaris_acl,
982 /* rf_remove_acl */ RF_remove_acl,
987 /* ---------------- */
988 void initvol_vfs(struct vol *vol)
990 vol->vfs = &vfs_master_funcs;
992 /* Default adouble stuff */
993 if (vol->v_adouble == AD_VERSION2_OSX) {
994 vfs[0] = &netatalk_adouble_osx;
996 else if (vol->v_adouble == AD_VERSION1_SFM) {
997 vfs[0] = &netatalk_adouble_sfm;
1000 vfs[0] = &netatalk_adouble;
1003 /* Extended Attributes */
1004 if (vol->v_vfs_ea == AFPVOL_EA_SOLARIS) {
1006 #ifdef HAVE_SOLARIS_EAS
1007 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with Solaris native EAs.");
1008 vfs[1] = &netatalk_ea_solaris;
1010 LOG(log_error, logtype_afpd, "initvol_vfs: Can't enable Solaris EA support.");
1015 /* default: AFPVOL_EA_AD */
1016 LOG(log_debug, logtype_afpd, "initvol_vfs: Enabling EA support with adouble files.");
1017 vfs[1] = &netatalk_ea_adouble;
1021 #ifdef HAVE_NFSv4_ACLS
1022 vfs[2] = &netatalk_solaris_acl_adouble;