forked from hanwen/go-fuse
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from juicedata/feat/fd
fuse: support special /dev/fd/N mountpoint
- Loading branch information
Showing
4 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package fuse | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
// TestMountDevFd tests the special `/dev/fd/N` mountpoint syntax, where a | ||
// privileged parent process opens /dev/fuse and calls mount() for us. | ||
// | ||
// In this test, we simulate a privileged parent by using the `fusermount` suid | ||
// helper. | ||
func TestMountDevFd(t *testing.T) { | ||
realMountPoint, err := ioutil.TempDir("", t.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer syscall.Rmdir(realMountPoint) | ||
|
||
// Call the fusermount suid helper to obtain the file descriptor in place | ||
// of a privileged parent. | ||
var fuOpts MountOptions | ||
fd, err := callFusermount(realMountPoint, &fuOpts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
fdMountPoint := fmt.Sprintf("/dev/fd/%d", fd) | ||
|
||
// Real test starts here: | ||
// See if we can feed fdMountPoint to NewServer | ||
fs := NewDefaultRawFileSystem() | ||
opts := MountOptions{ | ||
Debug: true, | ||
} | ||
srv, err := NewServer(fs, fdMountPoint, &opts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
go srv.Serve() | ||
if err := srv.WaitMount(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// If we are actually mounted, we should get ENOSYS. | ||
// | ||
// This won't deadlock despite pollHack not working for `/dev/fd/N` mounts | ||
// because functions in the syscall package don't use the poller. | ||
var st syscall.Stat_t | ||
err = syscall.Stat(realMountPoint, &st) | ||
if err != syscall.ENOSYS { | ||
t.Errorf("expected ENOSYS, got %v", err) | ||
} | ||
|
||
// Cleanup is somewhat tricky because `srv` does not know about | ||
// `realMountPoint`, so `srv.Unmount()` cannot work. | ||
// | ||
// A normal user has to call `fusermount -u` for themselves to unmount. | ||
// But in this test we can monkey-patch `srv.mountPoint`. | ||
srv.mountPoint = realMountPoint | ||
if err := srv.Unmount(); err != nil { | ||
t.Error(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters