Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ require (
golang.org/x/term v0.9.0
)

require (
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c // indirect
)

require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
Expand All @@ -44,6 +51,7 @@ require (
github.com/ipfs/go-bitfield v1.1.0 // indirect
github.com/ipfs/go-block-format v0.1.2 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-api v0.6.0
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
github.com/ipfs/go-ipld-legacy v0.2.1 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc=
github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc=
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg=
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
Expand Down Expand Up @@ -85,6 +87,8 @@ github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LK
github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk=
github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8=
github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk=
github.com/ipfs/go-ipfs-api v0.6.0 h1:JARgG0VTbjyVhO5ZfesnbXv9wTcMvoKRBLF1SzJqzmg=
github.com/ipfs/go-ipfs-api v0.6.0/go.mod h1:iDC2VMwN9LUpQV/GzEeZ2zNqd8NUdRmWcFM+K/6odf0=
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
github.com/ipfs/go-ipfs-cmds v0.9.0 h1:K0VcXg1l1k6aY6sHnoxYcyimyJQbcV1ueXuWgThmK9Q=
github.com/ipfs/go-ipfs-cmds v0.9.0/go.mod h1:SBFHK8WNwC416QWH9Vz1Ql42SSMAOqKpaHUMBu3jpLo=
Expand Down Expand Up @@ -140,6 +144,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro=
github.com/libp2p/go-libp2p v0.27.7 h1:nhMs03CRxslKkkK2uLuN8f72uwNkE6RJS1JFb3H9UIQ=
github.com/libp2p/go-libp2p v0.27.7/go.mod h1:oMfQGTb9CHnrOuSM6yMmyK2lXz3qIhnkn2+oK3B1Y2g=
github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s=
Expand Down Expand Up @@ -274,6 +280,9 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:X
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa h1:EyA027ZAkuaCLoxVX4r1TZMPy1d31fM6hbfQ4OU4I5o=
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c h1:GGsyl0dZ2jJgVT+VvWBf/cNijrHRhkrTjkmp5wg7li0=
github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c/go.mod h1:xxcJeBb7SIUl/Wzkz1eVKJE/CB34YNrqX2TQI6jY9zs=
github.com/winfsp/cgofuse v1.5.1-0.20230130140708-f87f5db493b5 h1:jxZvjx8Ve5sOXorZG0KzTxbp0Cr1n3FEegfmyd9br1k=
github.com/winfsp/cgofuse v1.5.1-0.20230130140708-f87f5db493b5/go.mod h1:uxjoF2jEYT3+x+vC2KJddEGdk/LU8pRowXmyVMHSV5I=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
44 changes: 44 additions & 0 deletions internal/commands/mountpoint_ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type (
keyFSSettings ipfs.KeyFSGuest
keyFSOption func(*keyFSSettings) error
keyFSOptions []keyFSOption
filesSettings ipfs.FilesGuest
filesOption func(*filesSettings) error
filesOptions []filesOption
)

const (
Expand All @@ -49,6 +52,7 @@ func makeIPFSCommands[
](host filesystem.Host,
) []command.Command {
return []command.Command{
makeMountCommand[HC, HM, filesOptions, filesSettings](host, ipfs.FilesID),
makeMountCommand[HC, HM, ipfsOptions, ipfsSettings](host, ipfs.IPFSID),
makeMountCommand[HC, HM, pinFSOptions, pinFSSettings](host, ipfs.PinFSID),
makeMountCommand[HC, HM, ipnsOptions, ipnsSettings](host, ipfs.IPNSID),
Expand All @@ -65,6 +69,7 @@ func makeIPFSGuests[
guests[ipfs.IPNSID] = newMountPointFunc[HC, ipfs.IPNSGuest](path)
guests[ipfs.KeyFSID] = newMountPointFunc[HC, ipfs.KeyFSGuest](path)
guests[ipfs.PinFSID] = newMountPointFunc[HC, ipfs.PinFSGuest](path)
guests[ipfs.FilesID] = newMountPointFunc[HC, ipfs.FilesGuest](path)
}

func guestOverlayText(overlay, overlaid filesystem.ID) string {
Expand Down Expand Up @@ -274,6 +279,45 @@ func (set keyFSSettings) marshal(string) ([]byte, error) {
return json.Marshal(set)
}

func (*filesOptions) usage(filesystem.Host) string {
return string(ipfs.FilesID) + " provides access to the node's FilesAPI."
}

func (fo *filesOptions) BindFlags(flagSet *flag.FlagSet) {
var (
flagPrefix = prefixIDFlag(ipfs.FilesID)
apiUsage = string(ipfs.FilesID) + " API node `maddr`"
apiName = flagPrefix + ipfsAPIFileName
)
flagSetFunc(flagSet, apiName, apiUsage, fo,
func(value multiaddr.Multiaddr, settings *filesSettings) error {
settings.APIMaddr = value
return nil
})
}

func (fo filesOptions) make() (filesSettings, error) {
settings, err := makeWithOptions(fo...)
if err != nil {
return filesSettings{}, err
}
if settings.APIMaddr == nil {
maddrs, err := getIPFSAPI()
if err != nil {
return filesSettings{}, fmt.Errorf(
"could not get default value for API: %w",
err,
)
}
settings.APIMaddr = maddrs[0]
}
return settings, nil
}

func (set filesSettings) marshal(string) ([]byte, error) {
return json.Marshal(set)
}

func getIPFSAPI() ([]multiaddr.Multiaddr, error) {
location, err := getIPFSAPIPath()
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion internal/filesystem/cgofuse/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ import (

func (gw *goWrapper) Statfs(path string, stat *fuse.Statfs_t) errNo {
defer gw.systemLock.Access(path)()
return -fuse.ENOSYS
// TODO: optional "freesize" on host init
// tracked in write, delete, etc. calls
// (^ lots of software checks for free space
// before even trying to call `write`, so we need to
// emulate that somehow)
errNo, err := statfs(path, stat)
if err != nil {
gw.logError(path, err)
return -fuse.EIO
}
return errNo
}

func (gw *goWrapper) Getattr(path string, stat *fuse.Stat_t, fh fileDescriptor) errNo {
Expand Down Expand Up @@ -61,6 +71,7 @@ func (gw *goWrapper) infoFromPath(path string) (fs.FileInfo, error) {

func (gw *goWrapper) Utimens(path string, tmsp []fuse.Timespec) errNo {
defer gw.systemLock.Modify(path)()
return operationSuccess
return -fuse.ENOSYS
}

Expand Down
33 changes: 33 additions & 0 deletions internal/filesystem/cgofuse/stat_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cgofuse

import (
"syscall"

"github.com/winfsp/cgofuse/fuse"
"golang.org/x/sys/unix"
)

func statfs(path string, fStatfs *fuse.Statfs_t) (int, error) {
// HACK: see note in stat_windows.go
path = "/"
sysStat := &unix.Statfs_t{}
if err := unix.Statfs(path, sysStat); err != nil {
if errno, ok := err.(syscall.Errno); ok {
return int(errno), err
}
return -fuse.EACCES, err
}

// NOTE: These values are ignored by cgofuse
// but fsid might be incorrect on some platforms too
fStatfs.Fsid = uint64(sysStat.Fsid.Val[0])<<32 | uint64(sysStat.Fsid.Val[1])
fStatfs.Flag = uint64(sysStat.Flags)

fStatfs.Bsize = uint64(sysStat.Bsize)
fStatfs.Blocks = sysStat.Blocks
fStatfs.Bfree = sysStat.Bfree
fStatfs.Bavail = sysStat.Bavail
fStatfs.Files = sysStat.Files
fStatfs.Ffree = sysStat.Ffree
return operationSuccess, nil
}
35 changes: 35 additions & 0 deletions internal/filesystem/cgofuse/stat_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cgofuse

import (
"syscall"

"github.com/winfsp/cgofuse/fuse"
"golang.org/x/sys/unix"
)

func statfs(path string, fStatfs *fuse.Statfs_t) (int, error) {
// HACK: see note in stat_windows.go
path = "/"
sysStat := &unix.Statfs_t{}
if err := unix.Statfs(path, sysStat); err != nil {
if errno, ok := err.(syscall.Errno); ok {
return int(errno), err
}
return -fuse.EACCES, err
}

// NOTE: These values are ignored by cgofuse
// but fsid might be incorrect on some platforms too
fStatfs.Fsid = uint64(sysStat.Fsid.Val[0])<<32 | uint64(sysStat.Fsid.Val[1])
fStatfs.Flag = uint64(sysStat.Flags)

fStatfs.Bsize = sysStat.Bsize
fStatfs.Blocks = sysStat.Blocks
fStatfs.Bfree = sysStat.Bfree
fStatfs.Bavail = uint64(sysStat.Bavail)
fStatfs.Files = sysStat.Files
fStatfs.Ffree = uint64(sysStat.Ffree)
fStatfs.Frsize = uint64(sysStat.Bsize)
fStatfs.Namemax = uint64(sysStat.Namemax)
return operationSuccess, nil
}
35 changes: 35 additions & 0 deletions internal/filesystem/cgofuse/stat_openbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cgofuse

import (
"syscall"

"github.com/winfsp/cgofuse/fuse"
"golang.org/x/sys/unix"
)

func statfs(path string, fStatfs *fuse.Statfs_t) (int, error) {
// HACK: see note in stat_windows.go
path = "/"
sysStat := &unix.Statfs_t{}
if err := unix.Statfs(path, sysStat); err != nil {
if errno, ok := err.(syscall.Errno); ok {
return int(errno), err
}
return -fuse.EACCES, err
}

// NOTE: These values are ignored by cgofuse
// but fsid might be incorrect on some platforms too
fStatfs.Fsid = uint64(sysStat.F_fsid.Val[0])<<32 | uint64(sysStat.F_fsid.Val[1])
fStatfs.Flag = uint64(sysStat.F_flags)

fStatfs.Bsize = uint64(sysStat.F_bsize)
fStatfs.Blocks = sysStat.F_blocks
fStatfs.Bfree = sysStat.F_bfree
fStatfs.Bavail = uint64(sysStat.F_bavail)
fStatfs.Files = sysStat.F_files
fStatfs.Ffree = uint64(sysStat.F_ffree)
fStatfs.Frsize = uint64(sysStat.F_bsize)
fStatfs.Namemax = uint64(sysStat.F_namemax)
return operationSuccess, nil
}
37 changes: 37 additions & 0 deletions internal/filesystem/cgofuse/stat_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build !windows && !darwin && !freebsd && !openbsd && !netbsd

package cgofuse

import (
"syscall"

"github.com/winfsp/cgofuse/fuse"
"golang.org/x/sys/unix"
)

func statfs(path string, fStatfs *fuse.Statfs_t) (int, error) {
// HACK: see note in stat_windows.go
path = "/"
sysStat := &unix.Statfs_t{}
if err := unix.Statfs(path, sysStat); err != nil {
if errno, ok := err.(syscall.Errno); ok {
return int(errno), err
}
return -fuse.EACCES, err
}

// NOTE: These values are ignored by cgofuse
// but fsid might be incorrect on some platforms too
fStatfs.Fsid = uint64(sysStat.Fsid.Val[0])<<32 | uint64(sysStat.Fsid.Val[1])
fStatfs.Flag = uint64(sysStat.Flags)

fStatfs.Bsize = uint64(sysStat.Bsize)
fStatfs.Blocks = sysStat.Blocks
fStatfs.Bfree = sysStat.Bfree
fStatfs.Bavail = sysStat.Bavail
fStatfs.Files = sysStat.Files
fStatfs.Ffree = sysStat.Ffree
fStatfs.Frsize = uint64(sysStat.Frsize)
fStatfs.Namemax = uint64(sysStat.Namelen)
return operationSuccess, nil
}
Loading