Implemented the passthrough.
Passthrough is usable now. There have been issues with the `access` operation: it's unclear what it must return, since the answer isn't known at the time when it is called. If it always returns "denied", many applications would finish without trying to open a file, thinking the access would not be granted after `access` call. Although always returning "permitted" seems like a better choice, it still might cause unexpected behaviour. Perhaps one way to solve this, is actually asking user whether to allow access. In any case, this issue needs to be looked into.
This commit is contained in:
parent
1ddbef6a65
commit
bfc22c79e0
@ -217,6 +217,7 @@ static int xmp_releasedir(const char *path, struct fuse_file_info *fi) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// TODO: make this work
|
// TODO: make this work
|
||||||
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) {
|
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) {
|
||||||
int res;
|
int res;
|
||||||
@ -230,6 +231,7 @@ static int xmp_mknod(const char *path, mode_t mode, dev_t rdev) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static int xmp_mkdir(const char *path, mode_t mode) {
|
static int xmp_mkdir(const char *path, mode_t mode) {
|
||||||
int res;
|
int res;
|
||||||
@ -288,7 +290,7 @@ static int xmp_rename(const char *from, const char *to, unsigned int flags) {
|
|||||||
static int xmp_link(const char *from, const char *to) {
|
static int xmp_link(const char *from, const char *to) {
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = link(from, to);
|
res = source_link(from, to);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
@ -301,7 +303,7 @@ static int xmp_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) {
|
|||||||
if (fi)
|
if (fi)
|
||||||
res = fchmod(fi->fh, mode);
|
res = fchmod(fi->fh, mode);
|
||||||
else
|
else
|
||||||
res = chmod(path, mode);
|
res = source_chmod(path, mode);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
@ -315,7 +317,7 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid,
|
|||||||
if (fi)
|
if (fi)
|
||||||
res = fchown(fi->fh, uid, gid);
|
res = fchown(fi->fh, uid, gid);
|
||||||
else
|
else
|
||||||
res = lchown(path, uid, gid);
|
res = source_chown(path, uid, gid);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
@ -329,7 +331,7 @@ static int xmp_truncate(const char *path, off_t size,
|
|||||||
if (fi)
|
if (fi)
|
||||||
res = ftruncate(fi->fh, size);
|
res = ftruncate(fi->fh, size);
|
||||||
else
|
else
|
||||||
res = truncate(path, size);
|
res = source_truncate(path, size);
|
||||||
|
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
@ -358,7 +360,7 @@ static int xmp_create(const char *path, mode_t mode,
|
|||||||
struct fuse_file_info *fi) {
|
struct fuse_file_info *fi) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(path, fi->flags, mode);
|
fd = source_create(path, fi->flags, mode);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
@ -369,7 +371,7 @@ static int xmp_create(const char *path, mode_t mode,
|
|||||||
static int xmp_open(const char *path, struct fuse_file_info *fi) {
|
static int xmp_open(const char *path, struct fuse_file_info *fi) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(path, fi->flags);
|
fd = source_open(path, fi->flags);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
@ -386,6 +388,7 @@ static int xmp_open(const char *path, struct fuse_file_info *fi) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
|
static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
|
||||||
struct fuse_file_info *fi) {
|
struct fuse_file_info *fi) {
|
||||||
int res;
|
int res;
|
||||||
@ -398,6 +401,7 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_read_buf(const char *path, struct fuse_bufvec **bufp,
|
static int xmp_read_buf(const char *path, struct fuse_bufvec **bufp,
|
||||||
size_t size, off_t offset, struct fuse_file_info *fi) {
|
size_t size, off_t offset, struct fuse_file_info *fi) {
|
||||||
struct fuse_bufvec *src;
|
struct fuse_bufvec *src;
|
||||||
@ -419,6 +423,7 @@ static int xmp_read_buf(const char *path, struct fuse_bufvec **bufp,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_write(const char *path, const char *buf, size_t size,
|
static int xmp_write(const char *path, const char *buf, size_t size,
|
||||||
off_t offset, struct fuse_file_info *fi) {
|
off_t offset, struct fuse_file_info *fi) {
|
||||||
int res;
|
int res;
|
||||||
@ -431,6 +436,7 @@ static int xmp_write(const char *path, const char *buf, size_t size,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_write_buf(const char *path, struct fuse_bufvec *buf,
|
static int xmp_write_buf(const char *path, struct fuse_bufvec *buf,
|
||||||
off_t offset, struct fuse_file_info *fi) {
|
off_t offset, struct fuse_file_info *fi) {
|
||||||
struct fuse_bufvec dst = FUSE_BUFVEC_INIT(fuse_buf_size(buf));
|
struct fuse_bufvec dst = FUSE_BUFVEC_INIT(fuse_buf_size(buf));
|
||||||
@ -454,6 +460,7 @@ static int xmp_statfs(const char *path, struct statvfs *stbuf) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_flush(const char *path, struct fuse_file_info *fi) {
|
static int xmp_flush(const char *path, struct fuse_file_info *fi) {
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -470,6 +477,7 @@ static int xmp_flush(const char *path, struct fuse_file_info *fi) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_release(const char *path, struct fuse_file_info *fi) {
|
static int xmp_release(const char *path, struct fuse_file_info *fi) {
|
||||||
(void)path;
|
(void)path;
|
||||||
close(fi->fh);
|
close(fi->fh);
|
||||||
@ -477,6 +485,7 @@ static int xmp_release(const char *path, struct fuse_file_info *fi) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_fsync(const char *path, int isdatasync,
|
static int xmp_fsync(const char *path, int isdatasync,
|
||||||
struct fuse_file_info *fi) {
|
struct fuse_file_info *fi) {
|
||||||
int res;
|
int res;
|
||||||
@ -551,6 +560,7 @@ static int xmp_lock(const char *path, struct fuse_file_info *fi, int cmd,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static int xmp_flock(const char *path, struct fuse_file_info *fi, int op) {
|
static int xmp_flock(const char *path, struct fuse_file_info *fi, int op) {
|
||||||
int res;
|
int res;
|
||||||
(void)path;
|
(void)path;
|
||||||
@ -580,6 +590,7 @@ static ssize_t xmp_copy_file_range(const char *path_in,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Complete copy of the example method(no need to modify anything so far) */
|
||||||
static off_t xmp_lseek(const char *path, off_t off, int whence,
|
static off_t xmp_lseek(const char *path, off_t off, int whence,
|
||||||
struct fuse_file_info *fi) {
|
struct fuse_file_info *fi) {
|
||||||
off_t res;
|
off_t res;
|
||||||
@ -592,15 +603,16 @@ static off_t xmp_lseek(const char *path, off_t off, int whence,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: look trough "optional"(commented out) operations.
|
||||||
static const struct fuse_operations xmp_oper = {
|
static const struct fuse_operations xmp_oper = {
|
||||||
.init = xmp_init,
|
.init = xmp_init,
|
||||||
.getattr = xmp_getattr,
|
.getattr = xmp_getattr,
|
||||||
.access = xmp_access,
|
// .access = xmp_access,
|
||||||
.readlink = xmp_readlink,
|
.readlink = xmp_readlink,
|
||||||
.opendir = xmp_opendir,
|
.opendir = xmp_opendir,
|
||||||
.readdir = xmp_readdir,
|
.readdir = xmp_readdir,
|
||||||
.releasedir = xmp_releasedir,
|
.releasedir = xmp_releasedir,
|
||||||
.mknod = xmp_mknod,
|
// .mknod = xmp_mknod,
|
||||||
.mkdir = xmp_mkdir,
|
.mkdir = xmp_mkdir,
|
||||||
.symlink = xmp_symlink,
|
.symlink = xmp_symlink,
|
||||||
.unlink = xmp_unlink,
|
.unlink = xmp_unlink,
|
||||||
@ -611,7 +623,7 @@ static const struct fuse_operations xmp_oper = {
|
|||||||
.chown = xmp_chown,
|
.chown = xmp_chown,
|
||||||
.truncate = xmp_truncate,
|
.truncate = xmp_truncate,
|
||||||
#ifdef HAVE_UTIMENSAT
|
#ifdef HAVE_UTIMENSAT
|
||||||
.utimens = xmp_utimens,
|
// .utimens = xmp_utimens,
|
||||||
#endif
|
#endif
|
||||||
.create = xmp_create,
|
.create = xmp_create,
|
||||||
.open = xmp_open,
|
.open = xmp_open,
|
||||||
@ -624,20 +636,20 @@ static const struct fuse_operations xmp_oper = {
|
|||||||
.release = xmp_release,
|
.release = xmp_release,
|
||||||
.fsync = xmp_fsync,
|
.fsync = xmp_fsync,
|
||||||
#ifdef HAVE_POSIX_FALLOCATE
|
#ifdef HAVE_POSIX_FALLOCATE
|
||||||
.fallocate = xmp_fallocate,
|
// .fallocate = xmp_fallocate,
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SETXATTR
|
#ifdef HAVE_SETXATTR
|
||||||
.setxattr = xmp_setxattr,
|
// .setxattr = xmp_setxattr,
|
||||||
.getxattr = xmp_getxattr,
|
// .getxattr = xmp_getxattr,
|
||||||
.listxattr = xmp_listxattr,
|
// .listxattr = xmp_listxattr,
|
||||||
.removexattr = xmp_removexattr,
|
// .removexattr = xmp_removexattr,
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBULOCKMGR
|
#ifdef HAVE_LIBULOCKMGR
|
||||||
.lock = xmp_lock,
|
// .lock = xmp_lock,
|
||||||
#endif
|
#endif
|
||||||
.flock = xmp_flock,
|
.flock = xmp_flock,
|
||||||
#ifdef HAVE_COPY_FILE_RANGE
|
#ifdef HAVE_COPY_FILE_RANGE
|
||||||
.copy_file_range = xmp_copy_file_range,
|
// .copy_file_range = xmp_copy_file_range,
|
||||||
#endif
|
#endif
|
||||||
.lseek = xmp_lseek,
|
.lseek = xmp_lseek,
|
||||||
};
|
};
|
||||||
|
@ -70,6 +70,47 @@ DIR *source_opendir(const char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int source_rename(const char *oldpath, const char *newpath) {
|
int source_rename(const char *oldpath, const char *newpath) {
|
||||||
printf("{\"%s\", \"%s\"}\n", oldpath, newpath);
|
const char *relative_oldpath = source_fname_translate(oldpath);
|
||||||
return -1;
|
const char *relative_newpath = source_fname_translate(newpath);
|
||||||
|
return renameat(handle.root_fd, relative_oldpath, handle.root_fd,
|
||||||
|
relative_newpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
int source_link(const char *oldpath, const char *newpath) {
|
||||||
|
const char *relative_oldpath = source_fname_translate(oldpath);
|
||||||
|
const char *relative_newpath = source_fname_translate(newpath);
|
||||||
|
return linkat(handle.root_fd, relative_oldpath, handle.root_fd,
|
||||||
|
relative_newpath, 0);
|
||||||
|
// NOTE: perhaps the flags here need to be reevaluated.
|
||||||
|
}
|
||||||
|
|
||||||
|
int source_chmod(const char *filename, mode_t mode) {
|
||||||
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
|
return fchmodat(handle.root_fd, relative_filename, mode, 0);
|
||||||
|
// NOTE: perhaps the flags here need to be reevaluated.
|
||||||
|
}
|
||||||
|
|
||||||
|
int source_chown(const char *filename, uid_t owner, gid_t group) {
|
||||||
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
|
return fchownat(handle.root_fd, filename, owner, group, AT_SYMLINK_NOFOLLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
int source_truncate(const char *filename, off_t length) {
|
||||||
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
|
int fd = openat(handle.root_fd, relative_filename, NULL);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror("Openat failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return ftruncate(fd, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int source_open(const char *filename, int flags) {
|
||||||
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
|
return openat(handle.root_fd, relative_filename, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
int source_create(const char *filename, int flags, mode_t mode) {
|
||||||
|
const char *relative_filename = source_fname_translate(filename);
|
||||||
|
return openat(handle.root_fd, relative_filename, flags, mode);
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,19 @@ int source_symlink(const char *target, const char *linkpath);
|
|||||||
|
|
||||||
int source_rename(const char *oldpath, const char *newpath);
|
int source_rename(const char *oldpath, const char *newpath);
|
||||||
|
|
||||||
|
int source_link(const char *oldpath, const char *newpath);
|
||||||
|
|
||||||
|
int source_chmod(const char *filename, mode_t mode);
|
||||||
|
|
||||||
|
int source_chown(const char *filename, uid_t owner, gid_t group);
|
||||||
|
|
||||||
|
int source_truncate(const char *filename, off_t length);
|
||||||
|
|
||||||
|
/* `open` and `create` are designed to correspond to fuse operations, not the
|
||||||
|
* libc's `open(2)`. Both of them actually call `openat`. */
|
||||||
|
|
||||||
|
int source_open(const char *filename, int flags);
|
||||||
|
|
||||||
|
int source_create(const char *filename, int flags, mode_t mode);
|
||||||
|
|
||||||
#endif // !SOURCEFS_H
|
#endif // !SOURCEFS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user