Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
eadfaa07
Commit
eadfaa07
authored
Sep 25, 2016
by
Nemanja Zbiljić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support OSXFUSE 3.x, fall back to 2.x if needed
Also supports custom bundled OSXFUSE installs.
parent
0b9db0a7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
27 deletions
+103
-27
mount_config.go
mount_config.go
+43
-0
mount_darwin.go
mount_darwin.go
+60
-27
No files found.
mount_config.go
View file @
eadfaa07
...
@@ -135,6 +135,14 @@ type MountConfig struct {
...
@@ -135,6 +135,14 @@ type MountConfig struct {
// default name involving the string 'osxfuse' is used.
// default name involving the string 'osxfuse' is used.
VolumeName
string
VolumeName
string
// OS X only.
//
// OSXFUSELocations sets where to look for OSXFUSE files. The arguments are
// all the possible locations. The previous locations are replaced.
//
// Without this option, OSXFUSELocationV3 and OSXFUSELocationV2 are used.
OSXFUSELocations
[]
OSXFUSEPaths
// Additional key=value options to pass unadulterated to the underlying mount
// Additional key=value options to pass unadulterated to the underlying mount
// command. See `man 8 mount`, the fuse documentation, etc. for
// command. See `man 8 mount`, the fuse documentation, etc. for
// system-specific information.
// system-specific information.
...
@@ -230,3 +238,38 @@ func (c *MountConfig) toOptionsString() string {
...
@@ -230,3 +238,38 @@ func (c *MountConfig) toOptionsString() string {
return
strings
.
Join
(
components
,
","
)
return
strings
.
Join
(
components
,
","
)
}
}
// OSXFUSEPaths describes the paths used by an installed OSXFUSE version.
// See OSXFUSELocationV3 for typical values.
type
OSXFUSEPaths
struct
{
// Prefix for the device file. At mount time, an incrementing number is
// suffixed until a free FUSE device is found.
DevicePrefix
string
// Path of the load helper, used to load the kernel extension if no device
// files are found.
Load
string
// Path of the mount helper, used for the actual mount operation.
Mount
string
// Environment variable used to pass the path to the executable calling the
// mount helper.
DaemonVar
string
}
// Default paths for OSXFUSE. See OSXFUSELocations.
var
(
OSXFUSELocationV3
=
OSXFUSEPaths
{
DevicePrefix
:
"/dev/osxfuse"
,
Load
:
"/Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse"
,
Mount
:
"/Library/Filesystems/osxfuse.fs/Contents/Resources/mount_osxfuse"
,
DaemonVar
:
"MOUNT_OSXFUSE_DAEMON_PATH"
,
}
OSXFUSELocationV2
=
OSXFUSEPaths
{
DevicePrefix
:
"/dev/osxfuse"
,
Load
:
"/Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs"
,
Mount
:
"/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs"
,
DaemonVar
:
"MOUNT_FUSEFS_DAEMON_PATH"
,
}
)
mount_darwin.go
View file @
eadfaa07
...
@@ -14,10 +14,16 @@ import (
...
@@ -14,10 +14,16 @@ import (
)
)
var
errNoAvail
=
errors
.
New
(
"no available fuse devices"
)
var
errNoAvail
=
errors
.
New
(
"no available fuse devices"
)
var
errNotLoaded
=
errors
.
New
(
"osxfuse
fs
is not loaded"
)
var
errNotLoaded
=
errors
.
New
(
"osxfuse is not loaded"
)
func
loadOSXFUSE
()
error
{
// errOSXFUSENotFound is returned from Mount when the OSXFUSE installation is
cmd
:=
exec
.
Command
(
"/Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs"
)
// not detected.
//
// Make sure OSXFUSE is installed, or see OSXFUSELocations for customization.
var
errOSXFUSENotFound
=
errors
.
New
(
"cannot locate OSXFUSE"
)
func
loadOSXFUSE
(
bin
string
)
error
{
cmd
:=
exec
.
Command
(
bin
)
cmd
.
Dir
=
"/"
cmd
.
Dir
=
"/"
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
cmd
.
Stderr
=
os
.
Stderr
...
@@ -25,10 +31,10 @@ func loadOSXFUSE() error {
...
@@ -25,10 +31,10 @@ func loadOSXFUSE() error {
return
err
return
err
}
}
func
openOSXFUSEDev
()
(
dev
*
os
.
File
,
err
error
)
{
func
openOSXFUSEDev
(
devPrefix
string
)
(
dev
*
os
.
File
,
err
error
)
{
// Try each device name.
// Try each device name.
for
i
:=
uint64
(
0
);
;
i
++
{
for
i
:=
uint64
(
0
);
;
i
++
{
path
:=
fmt
.
Sprintf
(
"/dev/osxfuse%d"
,
i
)
path
:=
devPrefix
+
strconv
.
FormatUint
(
i
,
10
)
dev
,
err
=
os
.
OpenFile
(
path
,
os
.
O_RDWR
,
0000
)
dev
,
err
=
os
.
OpenFile
(
path
,
os
.
O_RDWR
,
0000
)
if
os
.
IsNotExist
(
err
)
{
if
os
.
IsNotExist
(
err
)
{
if
i
==
0
{
if
i
==
0
{
...
@@ -52,11 +58,12 @@ func openOSXFUSEDev() (dev *os.File, err error) {
...
@@ -52,11 +58,12 @@ func openOSXFUSEDev() (dev *os.File, err error) {
}
}
func
callMount
(
func
callMount
(
bin
string
,
daemonVar
string
,
dir
string
,
dir
string
,
cfg
*
MountConfig
,
cfg
*
MountConfig
,
dev
*
os
.
File
,
dev
*
os
.
File
,
ready
chan
<-
error
)
(
err
error
)
{
ready
chan
<-
error
)
(
err
error
)
{
const
bin
=
"/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs"
// The mount helper doesn't understand any escaping.
// The mount helper doesn't understand any escaping.
for
k
,
v
:=
range
cfg
.
toMap
()
{
for
k
,
v
:=
range
cfg
.
toMap
()
{
...
@@ -85,8 +92,15 @@ func callMount(
...
@@ -85,8 +92,15 @@ func callMount(
)
)
cmd
.
ExtraFiles
=
[]
*
os
.
File
{
dev
}
cmd
.
ExtraFiles
=
[]
*
os
.
File
{
dev
}
cmd
.
Env
=
os
.
Environ
()
cmd
.
Env
=
os
.
Environ
()
// OSXFUSE <3.3.0
cmd
.
Env
=
append
(
cmd
.
Env
,
"MOUNT_FUSEFS_CALL_BY_LIB="
)
cmd
.
Env
=
append
(
cmd
.
Env
,
"MOUNT_FUSEFS_CALL_BY_LIB="
)
cmd
.
Env
=
append
(
cmd
.
Env
,
"MOUNT_FUSEFS_DAEMON_PATH="
+
bin
)
// OSXFUSE >=3.3.0
cmd
.
Env
=
append
(
cmd
.
Env
,
"MOUNT_OSXFUSE_CALL_BY_LIB="
)
daemon
:=
os
.
Args
[
0
]
if
daemonVar
!=
""
{
cmd
.
Env
=
append
(
cmd
.
Env
,
daemonVar
+
"="
+
daemon
)
}
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
cmd
.
Stdout
=
&
buf
cmd
.
Stdout
=
&
buf
...
@@ -122,19 +136,34 @@ func mount(
...
@@ -122,19 +136,34 @@ func mount(
dir
string
,
dir
string
,
cfg
*
MountConfig
,
cfg
*
MountConfig
,
ready
chan
<-
error
)
(
dev
*
os
.
File
,
err
error
)
{
ready
chan
<-
error
)
(
dev
*
os
.
File
,
err
error
)
{
// get OSXFUSE locations
locations
:=
cfg
.
OSXFUSELocations
if
locations
==
nil
{
locations
=
[]
OSXFUSEPaths
{
OSXFUSELocationV3
,
OSXFUSELocationV2
,
}
}
for
_
,
loc
:=
range
locations
{
if
_
,
err
:=
os
.
Stat
(
loc
.
Mount
);
os
.
IsNotExist
(
err
)
{
// try the other locations
continue
}
// Open the device.
// Open the device.
dev
,
err
=
openOSXFUSEDev
(
)
dev
,
err
=
openOSXFUSEDev
(
loc
.
DevicePrefix
)
// Special case: we may need to explicitly load osxfuse. Load it, then try
// Special case: we may need to explicitly load osxfuse. Load it, then
//
again.
// try
again.
if
err
==
errNotLoaded
{
if
err
==
errNotLoaded
{
err
=
loadOSXFUSE
(
)
err
=
loadOSXFUSE
(
loc
.
Load
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"loadOSXFUSE: %v"
,
err
)
err
=
fmt
.
Errorf
(
"loadOSXFUSE: %v"
,
err
)
return
return
}
}
dev
,
err
=
openOSXFUSEDev
(
)
dev
,
err
=
openOSXFUSEDev
(
loc
.
DevicePrefix
)
}
}
// Propagate errors.
// Propagate errors.
...
@@ -144,12 +173,16 @@ func mount(
...
@@ -144,12 +173,16 @@ func mount(
}
}
// Call the mount binary with the device.
// Call the mount binary with the device.
err
=
callMount
(
dir
,
cfg
,
dev
,
ready
)
err
=
callMount
(
loc
.
Mount
,
loc
.
DaemonVar
,
dir
,
cfg
,
dev
,
ready
)
if
err
!=
nil
{
if
err
!=
nil
{
dev
.
Close
()
dev
.
Close
()
err
=
fmt
.
Errorf
(
"callMount: %v"
,
err
)
err
=
fmt
.
Errorf
(
"callMount: %v"
,
err
)
return
return
}
}
return
}
err
=
errOSXFUSENotFound
return
return
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment