From e59a45f154a51af986170bb527f97ebbbd5ce876 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 9 Sep 2015 23:07:07 +1000 Subject: [PATCH] Added support for setting the OS X volume name. While I was at it, added tests for fsname. I can't figure out how to test the volume name. For GoogleCloudPlatform/gcsfuse#125. --- mount_config.go | 19 ++++++++++++++++--- samples/statfs/statfs_darwin_test.go | 9 ++------- samples/statfs/statfs_test.go | 7 +++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/mount_config.go b/mount_config.go index 50c4e6f..6828ed3 100644 --- a/mount_config.go +++ b/mount_config.go @@ -129,6 +129,12 @@ type MountConfig struct { // entries will be cached for an arbitrarily long time. EnableVnodeCaching bool + // OS X only. + // + // The name of the mounted volume, as displayed in the Finder. If empty, a + // default name involving the string 'osxfuse' is used. + VolumeName string + // Additional key=value options to pass unadulterated to the underlying mount // command. See `man 8 mount`, the fuse documentation, etc. for // system-specific information. @@ -172,9 +178,16 @@ func (c *MountConfig) toMap() (opts map[string]string) { opts["ro"] = "" } - // OS X: set novncache when appropriate. - if isDarwin && !c.EnableVnodeCaching { - opts["novncache"] = "" + // Handle OS X options. + if isDarwin { + if !c.EnableVnodeCaching { + opts["novncache"] = "" + } + + if c.VolumeName != "" { + // Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options#volname + opts["volname"] = c.VolumeName + } } // OS X: disable the use of "Apple Double" (._foo and .DS_Store) files, which diff --git a/samples/statfs/statfs_darwin_test.go b/samples/statfs/statfs_darwin_test.go index bb7c2a9..1ec9c7b 100644 --- a/samples/statfs/statfs_darwin_test.go +++ b/samples/statfs/statfs_darwin_test.go @@ -20,7 +20,6 @@ import ( "syscall" "github.com/jacobsa/fuse/fuseops" - . "github.com/jacobsa/oglematchers" . "github.com/jacobsa/ogletest" ) @@ -72,9 +71,7 @@ func (t *StatFSTest) Syscall_ZeroValues() { ExpectEq(0, stat.Ffree) ExpectEq("osxfusefs", convertName(stat.Fstypename[:])) ExpectEq(t.canonicalDir, convertName(stat.Mntonname[:])) - ExpectThat( - convertName(stat.Mntfromname[:]), - MatchesRegexp(`mount_osxfusefs@osxfuse\d+`)) + ExpectEq(fsName, convertName(stat.Mntfromname[:])) } func (t *StatFSTest) Syscall_NonZeroValues() { @@ -108,9 +105,7 @@ func (t *StatFSTest) Syscall_NonZeroValues() { ExpectEq(canned.InodesFree, stat.Ffree) ExpectEq("osxfusefs", convertName(stat.Fstypename[:])) ExpectEq(t.canonicalDir, convertName(stat.Mntonname[:])) - ExpectThat( - convertName(stat.Mntfromname[:]), - MatchesRegexp(`mount_osxfusefs@osxfuse\d+`)) + ExpectEq(fsName, convertName(stat.Mntfromname[:])) } func (t *StatFSTest) UnsupportedBlockSizes() { diff --git a/samples/statfs/statfs_test.go b/samples/statfs/statfs_test.go index 458ef73..e37be43 100644 --- a/samples/statfs/statfs_test.go +++ b/samples/statfs/statfs_test.go @@ -34,6 +34,9 @@ import ( func TestStatFS(t *testing.T) { RunTests(t) } +const fsName = "some_fs_name" +const volumeName = "Some volume" + //////////////////////////////////////////////////////////////////////// // Helpers //////////////////////////////////////////////////////////////////////// @@ -117,6 +120,10 @@ func (t *StatFSTest) SetUp(ti *TestInfo) { // being issued from the client. t.MountConfig.DisableWritebackCaching = true + // Configure names. + t.MountConfig.FSName = fsName + t.MountConfig.VolumeName = volumeName + // Create the file system. t.fs = statfs.New() t.Server = fuseutil.NewFileSystemServer(t.fs)