Skip to content

Commit e641e12

Browse files
committed
Re-order function definitions (slightly more logical placement)
1 parent 77a2588 commit e641e12

1 file changed

Lines changed: 104 additions & 103 deletions

File tree

src/bindfs.c

Lines changed: 104 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ static int unapply_gid_offset(gid_t *gid);
247247
static size_t round_up_buffer_size_for_direct_io(size_t size);
248248
#endif
249249

250+
/* Access checking helper functions */
250251
static unsigned int permset_to_bits(acl_permset_t permset);
251252
static bool access_check(const char *real_path, int wants);
252253
static bool path_access_check(const char *path, int wants);
@@ -686,99 +687,6 @@ static size_t round_up_buffer_size_for_direct_io(size_t size)
686687
}
687688
#endif
688689

689-
#ifdef HAVE_FUSE_3
690-
static void *bindfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
691-
#else
692-
static void *bindfs_init()
693-
#endif
694-
{
695-
#ifdef HAVE_FUSE_3
696-
(void) conn;
697-
cfg->use_ino = 1;
698-
699-
// Disable caches so changes in base FS are visible immediately.
700-
// Especially the attribute cache must be disabled when different users
701-
// might see different file attributes, such as when mirroring users.
702-
cfg->entry_timeout = 0;
703-
cfg->attr_timeout = 0;
704-
cfg->negative_timeout = 0;
705-
#ifdef __linux__
706-
cfg->direct_io = settings.direct_io;
707-
#endif
708-
#endif
709-
710-
assert(settings.permchain != NULL);
711-
assert(settings.mntsrc_fd > 0);
712-
713-
maybe_stdout_stderr_to_file();
714-
715-
if (fchdir(settings.mntsrc_fd) != 0) {
716-
fprintf(
717-
stderr,
718-
"Could not change working directory to '%s': %s\n",
719-
settings.mntsrc,
720-
strerror(errno)
721-
);
722-
bindfs_init_failed = true;
723-
#ifdef __OpenBSD__
724-
exit(1);
725-
#else
726-
fuse_exit(fuse_get_context()->fuse);
727-
#endif
728-
}
729-
730-
return NULL;
731-
}
732-
733-
static void bindfs_destroy(void *private_data)
734-
{
735-
}
736-
737-
#ifdef HAVE_FUSE_3
738-
static int bindfs_getattr(const char *path, struct stat *stbuf,
739-
struct fuse_file_info *fi)
740-
#else
741-
static int bindfs_getattr(const char *path, struct stat *stbuf)
742-
#endif
743-
{
744-
int res;
745-
char *real_path;
746-
747-
real_path = process_path(path, true);
748-
if (real_path == NULL)
749-
return -errno;
750-
751-
if (lstat(real_path, stbuf) == -1) {
752-
free(real_path);
753-
return -errno;
754-
}
755-
756-
res = getattr_common(real_path, stbuf);
757-
free(real_path);
758-
return res;
759-
}
760-
761-
#ifndef HAVE_FUSE_3
762-
static int bindfs_fgetattr(const char *path, struct stat *stbuf,
763-
struct fuse_file_info *fi)
764-
{
765-
int res;
766-
char *real_path;
767-
768-
real_path = process_path(path, true);
769-
if (real_path == NULL)
770-
return -errno;
771-
772-
if (fstat(fi->fh, stbuf) == -1) {
773-
free(real_path);
774-
return -errno;
775-
}
776-
res = getattr_common(real_path, stbuf);
777-
free(real_path);
778-
return res;
779-
}
780-
#endif
781-
782690
/**
783691
* Convert an ACL permset to a bitmask.
784692
*
@@ -1000,16 +908,6 @@ static bool access_check(const char *real_path, int wants)
1000908
return (other_perms & wants) == wants;
1001909
}
1002910

1003-
static int bindfs_access(const char *path, int wants)
1004-
{
1005-
char *real_path = process_path(path, true);
1006-
1007-
if (!access_check(real_path, wants))
1008-
return -errno;
1009-
else
1010-
return 0;
1011-
}
1012-
1013911
/**
1014912
* Check the full path has search permissions and the immediate parent
1015913
* directory has `wants` permission.
@@ -1064,6 +962,109 @@ static bool path_has_search_perms(const char *path) {
1064962
return true;
1065963
}
1066964

965+
#ifdef HAVE_FUSE_3
966+
static void *bindfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
967+
#else
968+
static void *bindfs_init()
969+
#endif
970+
{
971+
#ifdef HAVE_FUSE_3
972+
(void) conn;
973+
cfg->use_ino = 1;
974+
975+
// Disable caches so changes in base FS are visible immediately.
976+
// Especially the attribute cache must be disabled when different users
977+
// might see different file attributes, such as when mirroring users.
978+
cfg->entry_timeout = 0;
979+
cfg->attr_timeout = 0;
980+
cfg->negative_timeout = 0;
981+
#ifdef __linux__
982+
cfg->direct_io = settings.direct_io;
983+
#endif
984+
#endif
985+
986+
assert(settings.permchain != NULL);
987+
assert(settings.mntsrc_fd > 0);
988+
989+
maybe_stdout_stderr_to_file();
990+
991+
if (fchdir(settings.mntsrc_fd) != 0) {
992+
fprintf(
993+
stderr,
994+
"Could not change working directory to '%s': %s\n",
995+
settings.mntsrc,
996+
strerror(errno)
997+
);
998+
bindfs_init_failed = true;
999+
#ifdef __OpenBSD__
1000+
exit(1);
1001+
#else
1002+
fuse_exit(fuse_get_context()->fuse);
1003+
#endif
1004+
}
1005+
1006+
return NULL;
1007+
}
1008+
1009+
static void bindfs_destroy(void *private_data)
1010+
{
1011+
}
1012+
1013+
#ifdef HAVE_FUSE_3
1014+
static int bindfs_getattr(const char *path, struct stat *stbuf,
1015+
struct fuse_file_info *fi)
1016+
#else
1017+
static int bindfs_getattr(const char *path, struct stat *stbuf)
1018+
#endif
1019+
{
1020+
int res;
1021+
char *real_path;
1022+
1023+
real_path = process_path(path, true);
1024+
if (real_path == NULL)
1025+
return -errno;
1026+
1027+
if (lstat(real_path, stbuf) == -1) {
1028+
free(real_path);
1029+
return -errno;
1030+
}
1031+
1032+
res = getattr_common(real_path, stbuf);
1033+
free(real_path);
1034+
return res;
1035+
}
1036+
1037+
#ifndef HAVE_FUSE_3
1038+
static int bindfs_fgetattr(const char *path, struct stat *stbuf,
1039+
struct fuse_file_info *fi)
1040+
{
1041+
int res;
1042+
char *real_path;
1043+
1044+
real_path = process_path(path, true);
1045+
if (real_path == NULL)
1046+
return -errno;
1047+
1048+
if (fstat(fi->fh, stbuf) == -1) {
1049+
free(real_path);
1050+
return -errno;
1051+
}
1052+
res = getattr_common(real_path, stbuf);
1053+
free(real_path);
1054+
return res;
1055+
}
1056+
#endif
1057+
1058+
static int bindfs_access(const char *path, int wants)
1059+
{
1060+
char *real_path = process_path(path, true);
1061+
1062+
if (!access_check(real_path, wants))
1063+
return -errno;
1064+
else
1065+
return 0;
1066+
}
1067+
10671068
static int bindfs_readlink(const char *path, char *buf, size_t size)
10681069
{
10691070
int res;

0 commit comments

Comments
 (0)