Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
0831928c
提交
0831928c
authored
7月 06, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
using bazil.org/fuse
上级
e9bc9236
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
92 行增加
和
86 行删除
+92
-86
mount.go
cli/mount.go
+1
-8
readonly.go
fuse/readonly/readonly.go
+91
-78
没有找到文件。
cli/mount.go
浏览文件 @
0831928c
...
...
@@ -36,12 +36,5 @@ func mountCmd(c *commander.Command, inp []string) error {
mp
:=
inp
[
0
]
fmt
.
Printf
(
"Mounting at %s
\n
"
,
mp
)
fs
:=
rofs
.
NewFileSystem
(
n
)
s
,
err
:=
rofs
.
Mount
(
fs
,
mp
)
if
err
!=
nil
{
return
err
}
s
.
SetDebug
(
true
)
s
.
Serve
()
return
nil
return
rofs
.
Mount
(
n
,
mp
)
}
fuse/readonly/readonly.go
浏览文件 @
0831928c
...
...
@@ -3,103 +3,116 @@
package
readonly
import
(
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
core
"github.com/jbenet/go-ipfs/core"
"os"
"bazil.org/fuse"
"bazil.org/fuse/fs"
core
"github.com/jbenet/go-ipfs/core"
mdag
"github.com/jbenet/go-ipfs/merkledag"
)
type
FileSystem
struct
{
Ipfs
*
core
.
IpfsNode
pathfs
.
FileSystem
Ipfs
*
core
.
IpfsNode
}
func
NewFileSystem
(
ipfs
*
core
.
IpfsNode
)
*
FileSystem
{
return
&
FileSystem
{
Ipfs
:
ipfs
,
FileSystem
:
pathfs
.
NewDefaultFileSystem
(),
}
return
&
FileSystem
{
Ipfs
:
ipfs
}
}
func
(
f
FileSystem
)
Root
()
(
fs
.
Node
,
fuse
.
Error
)
{
return
Root
{
Ipfs
:
f
.
Ipfs
},
nil
}
type
Root
struct
{
Ipfs
*
core
.
IpfsNode
}
func
(
Root
)
Attr
()
fuse
.
Attr
{
return
fuse
.
Attr
{
Inode
:
1
,
Mode
:
os
.
ModeDir
|
0111
}
// -rw+x
}
func
(
s
*
Root
)
Lookup
(
name
string
,
intr
fs
.
Intr
)
(
fs
.
Node
,
fuse
.
Error
)
{
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
return
Node
{
Ipfs
:
s
.
Ipfs
,
Nd
:
nd
},
nil
}
func
(
s
*
FileSystem
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
if
name
==
"/"
{
// -rw +x on root
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0111
},
fuse
.
OK
}
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
// links? say dir. could have data...
if
len
(
nd
.
Links
)
>
0
{
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0555
},
fuse
.
OK
}
// size
size
,
_
:=
nd
.
Size
()
// file.
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0444
,
Size
:
uint64
(
size
),
},
fuse
.
OK
func
(
Root
)
ReadDir
(
intr
fs
.
Intr
)
([]
fuse
.
Dirent
,
fuse
.
Error
)
{
return
nil
,
fuse
.
EPERM
}
func
(
s
*
FileSystem
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
c
[]
fuse
.
DirEntry
,
code
fuse
.
Status
)
{
if
name
==
"/"
{
// nope
return
nil
,
fuse
.
EPERM
}
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
entries
:=
make
([]
fuse
.
DirEntry
,
len
(
nd
.
Links
))
for
i
,
link
:=
range
nd
.
Links
{
n
:=
link
.
Name
if
len
(
n
)
==
0
{
n
=
link
.
Hash
.
B58String
()
}
entries
[
i
]
=
fuse
.
DirEntry
{
Name
:
n
,
Mode
:
fuse
.
S_IFREG
|
0444
}
}
if
len
(
entries
)
>
0
{
return
entries
,
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
type
Node
struct
{
Ipfs
*
core
.
IpfsNode
Nd
*
mdag
.
Node
}
func
(
s
*
FileSystem
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
file
nodefs
.
File
,
code
fuse
.
Status
)
{
func
(
s
Node
)
Attr
()
fuse
.
Attr
{
if
len
(
s
.
Nd
.
Links
)
>
0
{
return
fuse
.
Attr
{
Mode
:
os
.
ModeDir
|
0555
}
}
size
,
_
:=
s
.
Nd
.
Size
()
return
fuse
.
Attr
{
Mode
:
0444
,
Size
:
uint64
(
size
)}
}
// read only, bro!
if
flags
&
fuse
.
O_ANYWRITE
!=
0
{
return
nil
,
fuse
.
EPERM
}
func
(
s
*
Node
)
Lookup
(
name
string
,
intr
fs
.
Intr
)
(
fs
.
Node
,
fuse
.
Error
)
{
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolveLinks
(
s
.
Nd
,
[]
string
{
name
}
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
return
nodefs
.
NewDataFile
([]
byte
(
nd
.
Data
)),
fuse
.
OK
return
Node
{
Ipfs
:
s
.
Ipfs
,
Nd
:
nd
},
nil
}
func
(
s
*
FileSystem
)
String
()
string
{
return
"IpfsReadOnly"
func
(
s
*
Node
)
ReadDir
(
intr
fs
.
Intr
)
([]
fuse
.
Dirent
,
fuse
.
Error
)
{
entries
:=
make
([]
fuse
.
Dirent
,
len
(
s
.
Nd
.
Links
))
for
i
,
link
:=
range
s
.
Nd
.
Links
{
n
:=
link
.
Name
if
len
(
n
)
==
0
{
n
=
link
.
Hash
.
B58String
()
}
entries
[
i
]
=
fuse
.
Dirent
{
Name
:
n
,
Type
:
fuse
.
DT_File
}
}
if
len
(
entries
)
>
0
{
return
entries
,
nil
}
return
nil
,
fuse
.
ENOENT
}
func
(
s
*
FileSystem
)
OnMount
(
nodeFs
*
pathfs
.
PathNodeFs
)
{
func
(
s
*
Node
)
ReadAll
(
intr
fs
.
Intr
)
([]
byte
,
fuse
.
Error
)
{
return
[]
byte
(
s
.
Nd
.
Data
),
nil
}
func
Mount
(
s
*
FileSystem
,
path
string
)
(
*
fuse
.
Server
,
error
)
{
rfs
:=
pathfs
.
NewReadonlyFileSystem
(
s
)
fs
:=
pathfs
.
NewPathNodeFs
(
rfs
,
nil
)
ser
,
_
,
err
:=
nodefs
.
MountRoot
(
path
,
fs
.
Root
(),
nil
)
return
ser
,
err
func
Mount
(
ipfs
*
core
.
IpfsNode
,
fpath
string
)
(
error
)
{
c
,
err
:=
fuse
.
Mount
(
fpath
)
if
err
!=
nil
{
return
err
}
defer
c
.
Close
()
err
=
fs
.
Serve
(
c
,
FileSystem
{
Ipfs
:
ipfs
})
if
err
!=
nil
{
return
err
}
// check if the mount process has an error to report
<-
c
.
Ready
if
err
:=
c
.
MountError
;
err
!=
nil
{
return
err
}
return
nil
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论