Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c90da4

Browse files
committed
wip (but working) transfer of source mount
1 parent9a3de92 commit7c90da4

File tree

2 files changed

+74
-35
lines changed

2 files changed

+74
-35
lines changed

‎src/bindfs.c‎

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static struct Settings {
112112
gid_tcreate_for_gid;
113113
char*mntsrc;
114114
char*mntdest;
115+
char*back_dir;
115116
intmntdest_len;/* caches strlen(mntdest) */
116117
intmntsrc_fd;
117118

@@ -198,9 +199,9 @@ static struct Settings {
198199
* that the root for a mount that's no longer connected as an empty directory.
199200
*/
200201
staticintwrap_err(interr_no) {
201-
if (-err_no==ENOTCONN) {
202-
return-ENOENT;
203-
}
202+
//if (-err_no == ENOTCONN) {
203+
// return -ENOENT;
204+
//}
204205
returnerr_no;
205206
}
206207

@@ -628,30 +629,38 @@ static int bindfs_getattr(const char *path, struct stat *stbuf)
628629
}
629630

630631
if (lstat(real_path,stbuf)==-1) {
631-
632+
DPRINTF("lstat fail");
632633
res=wrap_err(-errno);
633634
if (strcmp(path,"/")==0) {
634-
// Dirty hack, confidence of this working hovers
635-
// between 23% and 56%.
636-
stbuf->st_dev=41;
637-
stbuf->st_ino=405659;
638-
stbuf->st_mode=16877;
639-
stbuf->st_nlink=2;
640-
stbuf->st_size=40;
641-
stbuf->st_blksize=4096;
642-
stbuf->st_atime=1517366021;
643-
stbuf->st_mtime=1517366021;
644-
stbuf->st_ctime=1517366021;
645-
646-
res=getattr_common(real_path,stbuf);
647-
}
635+
// DPRINTF("lstat fail, faking empty root");
636+
// // Dirty hack, confidence of this working hovers
637+
// // between 23% and 56%.
638+
// // stbuf->st_dev = 41;
639+
// // stbuf->st_ino = 405659;
640+
// // stbuf->st_mode = 16877;
641+
// // stbuf->st_nlink = 2;
642+
// // stbuf->st_size = 40;
643+
// // stbuf->st_blksize = 4096;
644+
// // stbuf->st_atime = 1517366021;
645+
// // stbuf->st_mtime = 1517366021;
646+
// // stbuf->st_ctime = 1517366021;
647+
648+
// free(real_path);
649+
real_path="/tmp/fuse/empty";
650+
if (lstat(real_path,stbuf)==-1) {
651+
DPRINTF("lstat really broke");
652+
returnres;
653+
}
648654

649-
free(real_path);
650-
returnres;
655+
// // res = getattr_common(real_path, stbuf);
656+
}else {
657+
// free(real_path);
658+
returnres;
659+
}
651660
}
652661

653662
res=getattr_common(real_path,stbuf);
654-
free(real_path);
663+
//free(real_path);
655664

656665
returnres;
657666
}
@@ -711,19 +720,20 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
711720
returnwrap_err(-errno);
712721
}
713722

714-
715-
716723
DIR*dp=opendir(real_path);
717724
if (dp==NULL) {
718-
free(real_path);
725+
DPRINTF("readdir real_path: %s",real_path);
719726
if (strcmp(path,"/")==0) {
720-
return0;
727+
real_path="/tmp/fuse/empty";
728+
dp=opendir(real_path);
729+
}else {
730+
// free(real_path);
731+
returnwrap_err(-errno);
721732
}
722-
returnwrap_err(-errno);
723733
}
724734

725735
longpc_ret=pathconf(real_path,_PC_NAME_MAX);
726-
free(real_path);
736+
//free(real_path);
727737
if (pc_ret<0) {
728738
DPRINTF("pathconf failed: %s (%d)",strerror(errno),errno);
729739
pc_ret=NAME_MAX;
@@ -740,10 +750,12 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
740750
structdirent*de;
741751
result=readdir_r(dp,de_buf,&de);
742752
if (result!=0) {
753+
DPRINTF("readdir_r fail");
743754
result=-result;
744755
break;
745756
}
746757
if (de==NULL) {
758+
DPRINTF("readdir_r dirent NULL");
747759
break;
748760
}
749761

@@ -1362,6 +1374,7 @@ static int bindfs_getxattr(const char *path, const char *name, char *value,
13621374
returnwrap_err(-errno);
13631375

13641376
#if defined(__APPLE__)
1377+
// lol apple
13651378
if (strcmp(name,A_KAUTH_FILESEC_XATTR)==0) {
13661379
charnew_name[MAXPATHLEN];
13671380
memcpy(new_name,A_KAUTH_FILESEC_XATTR,sizeof(A_KAUTH_FILESEC_XATTR));
@@ -1372,12 +1385,20 @@ static int bindfs_getxattr(const char *path, const char *name, char *value,
13721385
}
13731386
#elif defined(HAVE_LGETXATTR)
13741387
res=lgetxattr(real_path,name,value,size);
1388+
if (res==-1) {
1389+
res=lgetxattr("/tmp/fuse/empty",name,value,size);
1390+
}
13751391
#else
13761392
res=getxattr(real_path,name,value,size,0,XATTR_NOFOLLOW);
1393+
if (res==-1) {
1394+
res=getxattr("/tmp/fuse/empty",name,value,size,0,XATTR_NOFOLLOW);
1395+
}
13771396
#endif
13781397
free(real_path);
1379-
if (res==-1)
1398+
if (res==-1) {
1399+
DPRINTF("failed getxattr result");
13801400
returnwrap_err(-errno);
1401+
}
13811402
returnres;
13821403
}
13831404

@@ -1583,6 +1604,8 @@ static void print_usage(const char *progname)
15831604
" --block-devices-as-files Show block devices as regular files.\n"
15841605
" --multithreaded Enable multithreaded mode. See man page\n"
15851606
" for security issue with current implementation.\n"
1607+
" --backup-dir=... Backup directory used in case dir can no longer\n"
1608+
" be reached.\n"
15861609
"\n"
15871610
"FUSE options:\n"
15881611
" -o opt[,opt,...] Mount options.\n"
@@ -1898,7 +1921,7 @@ static int parse_user_map(UserMap *map, UserMap *reverse_map, char *spec)
18981921
staticvoidmaybe_stdout_stderr_to_file()
18991922
{
19001923
/* TODO: make this a command line option. */
1901-
#if0
1924+
#if1
19021925
intfd;
19031926

19041927
constchar*filename="bindfs.log";
@@ -1941,7 +1964,20 @@ static void setup_signal_handling()
19411964

19421965
staticvoidsignal_handler(intsig)
19431966
{
1967+
DPRINTF("signal handler");
19441968
invalidate_user_cache();
1969+
close(settings.mntsrc_fd);
1970+
1971+
settings.mntsrc="/tmp/fuse/empty";
1972+
settings.mntsrc_fd=open(settings.mntsrc,O_RDONLY);
1973+
if (settings.mntsrc_fd==-1) {
1974+
DPRINTF("shits broken");
1975+
}
1976+
1977+
if (fchdir(settings.mntsrc_fd)!=0) {
1978+
DPRINTF("fchdir fail");
1979+
fuse_exit(fuse_get_context()->fuse);
1980+
}
19451981
}
19461982

19471983
staticvoidatexit_func()
@@ -2001,6 +2037,7 @@ int main(int argc, char *argv[])
20012037
intmultithreaded;
20022038
char*uid_offset;
20032039
char*gid_offset;
2040+
char*back_dir;
20042041
}od;
20052042

20062043
#defineOPT2(one,two,key) \
@@ -2072,8 +2109,7 @@ int main(int argc, char *argv[])
20722109
OPT_OFFSET2("--multithreaded","multithreaded",multithreaded,-1),
20732110
OPT_OFFSET2("--uid-offset=%s","uid-offset=%s",uid_offset,0),
20742111
OPT_OFFSET2("--gid-offset=%s","gid-offset=%s",gid_offset,0),
2075-
2076-
2112+
OPT_OFFSET2("--backup-dir=%s","backup-dir=%s",back_dir,0),
20772113

20782114

20792115
FUSE_OPT_END
@@ -2096,6 +2132,7 @@ int main(int argc, char *argv[])
20962132
settings.create_for_gid=-1;
20972133
settings.mntsrc=NULL;
20982134
settings.mntdest=NULL;
2135+
settings.back_dir=NULL;
20992136
settings.mntdest_len=0;
21002137
settings.original_working_dir=get_working_dir();
21012138
settings.create_policy= (getuid()==0) ?CREATE_AS_USER :CREATE_AS_MOUNTER;
@@ -2152,6 +2189,11 @@ int main(int argc, char *argv[])
21522189
}
21532190
}
21542191

2192+
/* Parse backup directory */
2193+
if (od.back_dir) {
2194+
2195+
}
2196+
21552197
/* Parse new owner and group */
21562198
if (od.user) {
21572199
if (!user_uid(od.user,&settings.new_uid)) {

‎src/debug.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@
2828
/* Handier to lock and use strerror() than allocate buffer for strerror_r(). */
2929
externpthread_mutex_tstrerror_lock;
3030

31-
#ifBINDFS_DEBUG
3231
#include<stdio.h>
3332
#defineDPRINTF(fmt, ...) do { \
3433
pthread_mutex_lock(&strerror_lock); \
3534
fprintf(stderr, "DEBUG: " fmt "\n", ##__VA_ARGS__); \
3635
pthread_mutex_unlock(&strerror_lock); \
3736
} while (0)
38-
#else
39-
#defineDPRINTF(...)
40-
#endif
37+
4138

4239
#endif
4340

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp