Conversation
/proc/PID/fd does not exist on freebsd.
|
So some interesting findings using rsync. Just as a test, I am rsyncing the gocryptfs repo into a gocryptfs mount. Every file write has these errors: But all of the files are indeed written... The perms are indeed not set correctly after writing. umask is As a thought experiment, I wanted to try mounting the fs with So repeating above, now mounted with the allow other flag as root, I no longer get the The permissions that get set are also interesting I suppose this makes sense - since the fuse daemon is running as root - but it's interesting the group was set correctly. Also note, no files in any sub directory under Anyway... I don't know if these findings are related to the missing implementation in the API stubs or limitations in the FreeBSD fuse driver. Likely the former... but I'll do some more digging. Thanks again! |
FreeBSD supports the Fchmodat system call, with the AT_SYMLINK_NOFOLLOW flag. FchmodatNofollow has been modified to use this system call and flag.
|
@schlomie Great test with rsync! I think the issue you have observed with rsync was due to the implementation of the However, FreeBSD also supports the As a side note, it looks like Linux added support for the As a test, I created the following directory with test files and a test directory, to be copied over to the gocryptfs mount point: Then I issued the command to mount the (empty) gocryptfs directory to the mount point I then used rsync to copy the files from I'd been keen to see the results of your previous test with the new commit. Thanks! |
|
@ankushjp I see you also merged in my commits from https://github.com/rfjakob/gocryptfs/commits/freebsd-support/ . Very good. Can you post the freebsd results of with your latest commit? |
|
Output from |
|
@ankushjp thanks! I built with your latest commits and observed your results - no errors. I think that will work. I also tried the allow other flag - again mounted as root and observed the failed to set time errors as before (as well as permission errors in sub folders - which is kind of expected with fuse running as root.) As to the failures in your |
| } | ||
| defer unix.Close(d.dirfd) | ||
|
|
||
| procPath := fmt.Sprintf("/proc/self/fd/%d/%s", d.dirfd, d.pName) |
There was a problem hiding this comment.
Does not make sense on freebsd. Please fix or just stub it with EOPNOTSUPP.
Same for the other functions in this file.
There was a problem hiding this comment.
The Functions in this file have been stubbed in the latest commit.
| // WARNING this function is not complete, and always runs f() as if context is nil. | ||
| // FreeBSD does not support changing uid/gid per thread. | ||
| func asUser(f func() (int, error), context *fuse.Context) (int, error) { | ||
| return f() |
There was a problem hiding this comment.
No, this is dangerous. This allows any user to create suid-root binaries.
If not possible to implement, log a warning and return an error.
There was a problem hiding this comment.
Updated so that f() is executed is context is nil, otherwise a warning is logged and unix.EOPNOTSUPP.
internal/syscallcompat/emulate.go
Outdated
| @@ -1,3 +1,5 @@ | |||
| //go:build darwin | |||
There was a problem hiding this comment.
Does this cause problems on freebsd? Then please use
//go:build !freebsd
There was a problem hiding this comment.
This should be built on Linux so it can be tested on Linux
There was a problem hiding this comment.
This was causing a problem on FreeBSD as the dev parameter to Mknod is uint64 on FreeBSD (instead of int used by Linux and Mac OS).
I've added the suggested build parameter to emulate.go, and created the file internal/syscallcompat/emulate_freebsd.go for FreeBSD with dev cast to uint64.
| @@ -1,3 +1,4 @@ | |||
| //go:build darwin | |||
There was a problem hiding this comment.
Does this cause problems on freebsd? Then please use
//go:build !freebsd
There was a problem hiding this comment.
This file will now build on FreeBSD after the above change to emulate.go.
| return unix.EINVAL | ||
| } | ||
|
|
||
| return unix.Renameat(olddirfd, oldpath, newdirfd, newpath) |
There was a problem hiding this comment.
This does not emulate RENAME_EXCHANGE at all?
There was a problem hiding this comment.
Sorry, I didn't read the Linux Renameat2 properly the first time.
FreeBSD does not provide a way to atomically swap two files as far as I can tell, so I've changed the function to return a unix.EINVAL error if the flags include RENAME_EXCHANGE.
| package syscallcompat | ||
|
|
||
| import ( | ||
| "syscall" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| // Unix2syscall converts a unix.Stat_t struct to a syscall.Stat_t struct. | ||
| // A direct cast does not work because the padding is named differently in | ||
| // unix.Stat_t for some reason ("X__unused" in syscall, "_" in unix). | ||
| func Unix2syscall(u unix.Stat_t) syscall.Stat_t { | ||
| return syscall.Stat_t{ | ||
| Dev: u.Dev, | ||
| Ino: u.Ino, | ||
| Nlink: u.Nlink, | ||
| Mode: u.Mode, | ||
| Uid: u.Uid, | ||
| Gid: u.Gid, | ||
| Rdev: u.Rdev, | ||
| Size: u.Size, | ||
| Blksize: u.Blksize, | ||
| Blocks: u.Blocks, | ||
| Atimespec: syscall.NsecToTimespec(unix.TimespecToNsec(u.Atim)), | ||
| Mtimespec: syscall.NsecToTimespec(unix.TimespecToNsec(u.Mtim)), | ||
| Ctimespec: syscall.NsecToTimespec(unix.TimespecToNsec(u.Ctim)), | ||
| } | ||
| } |
There was a problem hiding this comment.
Doesn't unix2syscall_darwin.go also work for FreeBSD? If so, adjust the build contraints to build on both.
There was a problem hiding this comment.
I've renamed internal/syscallcompat/unix2syscall_darwin.go to internal/syscallcompat/unix2syscall_darwin_freebsd.go, so it builds on both Mac OS and FreeBSD. I've removed internal/syscallcompat/unix2syscall_freebsd.go.
tests/matrix/atime_freebsd.go
Outdated
| package matrix | ||
|
|
||
| import ( | ||
| "syscall" | ||
| ) | ||
|
|
||
| func extractAtimeMtime(st syscall.Stat_t) [2]syscall.Timespec { | ||
| return [2]syscall.Timespec{st.Atimespec, st.Mtimespec} | ||
| } |
There was a problem hiding this comment.
Identical to atime_darwin.go. Please instead adjust the build contraints in atime_darwin.go.
There was a problem hiding this comment.
Same as above, modified file names to build on the appropriate OSes.
* Functions in fusefrontend_reverse/node_xattr_freebsd.go have been stubbed for now. * asuser_freebsd.go updated to only run f() when context is nil; otherwise log a warning and return an error. * emulate.go build flags updated, and FreeBSD specific version added. * sys_freebsd.go bug in Renameat2 with RENAME_EXCHANGE flag fixed. FreeBSD does not support atomic file swapping, so this flag now returns an error. * unix2syscall and atime is identical between FreeBSD and Darwin, updated filenames so Go will build the file for FreeBSD and Mac OS.
|
I've attempted to fix/address all the PR comments. Here is the output of Thanks. |
This PR adds support for the FreeBSD operating system, as mentioned in this discussion.
The FreeBSD build has been added to the
crossbuild.bashscript.Note that on FreeBSD, bash is not installed at
/bin/bash(it is installed at/usr/local/bin/bash) - its may be a good idea to modify the other bash scripts (e.g.tests/*.bash) to invoke bash via the more portable#!/usr/bin/env bashshebang.