forked from CalebQ42/squashfs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package squashfs | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
|
||
"github.com/CalebQ42/fuse" | ||
"github.com/CalebQ42/fuse/fs" | ||
"github.com/CalebQ42/squashfs/internal/inode" | ||
) | ||
|
||
func (r *Reader) Mount(mountpoint string) (con *fuse.Conn, err error) { | ||
con, err = fuse.Mount(mountpoint, fuse.ReadOnly()) | ||
if err != nil { | ||
return | ||
} | ||
err = fs.Serve(con, &squashFuse{r: r}) | ||
return | ||
} | ||
|
||
type squashFuse struct { | ||
r *Reader | ||
} | ||
|
||
func (s *squashFuse) Root() (fs.Node, error) { | ||
return &fileNode{File: s.r.FS.File}, nil | ||
} | ||
|
||
type fileNode struct { | ||
*File | ||
} | ||
|
||
func (f *fileNode) Attr(ctx context.Context, attr *fuse.Attr) error { | ||
attr.Blocks = f.r.s.Size / 512 | ||
if f.r.s.Size%512 > 0 { | ||
attr.Blocks++ | ||
} | ||
attr.Gid = f.r.ids[f.i.GidInd] | ||
attr.Inode = uint64(f.i.Num) | ||
attr.Mode = f.i.Mode() | ||
attr.Nlink = f.i.LinkCount() | ||
attr.Size = f.i.Size() | ||
attr.Uid = f.r.ids[f.i.UidInd] | ||
return nil | ||
} | ||
|
||
func (f *fileNode) Id() uint64 { | ||
return uint64(f.i.Num) | ||
} | ||
|
||
func (f *fileNode) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) { | ||
return f.SymlinkPath(), nil | ||
} | ||
|
||
func (f *fileNode) Lookup(ctx context.Context, name string) (fs.Node, error) { | ||
asFS, err := f.FS() | ||
if err != nil { | ||
return nil, fuse.ENOTDIR | ||
} | ||
ret, err := asFS.OpenFile(name) | ||
if err != nil { | ||
return nil, fuse.ENOENT | ||
} | ||
return &fileNode{File: ret}, nil | ||
} | ||
|
||
func (f *fileNode) ReadAll(ctx context.Context) ([]byte, error) { | ||
if f.IsRegular() { | ||
var buf bytes.Buffer | ||
_, err := f.WriteTo(&buf) | ||
return buf.Bytes(), err | ||
} | ||
return nil, fuse.ENODATA | ||
} | ||
|
||
func (f *fileNode) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { | ||
if f.IsRegular() { | ||
buf := make([]byte, req.Size) | ||
n, err := f.File.ReadAt(buf, req.Offset) | ||
if err == io.EOF { | ||
resp.Data = buf[:n] | ||
} | ||
return nil | ||
} | ||
return fuse.ENODATA | ||
} | ||
|
||
func (f *fileNode) ReadDirAll(ctx context.Context) (out []fuse.Dirent, err error) { | ||
asFS, err := f.FS() | ||
if err != nil { | ||
return nil, fuse.ENOTDIR | ||
} | ||
var t fuse.DirentType | ||
for i := range asFS.e { | ||
switch asFS.e[i].Type { | ||
case inode.Fil: | ||
t = fuse.DT_File | ||
case inode.Dir: | ||
t = fuse.DT_Dir | ||
case inode.Block: | ||
t = fuse.DT_Block | ||
case inode.Sym: | ||
t = fuse.DT_Link | ||
case inode.Char: | ||
t = fuse.DT_Char | ||
case inode.Fifo: | ||
t = fuse.DT_FIFO | ||
case inode.Sock: | ||
t = fuse.DT_Socket | ||
default: | ||
t = fuse.DT_Unknown | ||
} | ||
out = append(out, fuse.Dirent{ | ||
Inode: uint64(asFS.e[i].Num), | ||
Type: t, | ||
Name: asFS.e[i].Name, | ||
}) | ||
} | ||
return | ||
} |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= | ||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= | ||
github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0= | ||
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= | ||
github.com/CalebQ42/fuse v0.1.0 h1:KLCNjun7zcd2kBNVFfH+SWJyhuwJdE0nhw5/q8K8HGQ= | ||
github.com/CalebQ42/fuse v0.1.0/go.mod h1:pJpoKG03HJKVhsp8o0YQYqmfbFsr3Eowt90yQGQVO+4= | ||
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= | ||
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= | ||
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc= | ||
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= | ||
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs= | ||
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M= | ||
github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw= | ||
github.com/therootcompany/xz v1.0.1/go.mod h1:3K3UH1yCKgBneZYhuQUvJ9HPD19UEXEI0BWbMn8qNMY= | ||
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= | ||
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= | ||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= | ||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
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
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
Oops, something went wrong.