Skip to content
Open
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
33 changes: 33 additions & 0 deletions filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ import (
"log"
"fmt"
"io"
"path/filepath"
)

type fs struct {
sb *Superblock
dev *os.File
}

func (fs *fs) List() []string {
inodeNum := int64(ROOT_INO)
inode := fs.getInode(inodeNum)
files := fs.walk("/", inode, []string{})

return files
}

func (fs *fs) Open(name string) (*File, error) {
parts := strings.Split(name, "/")

Expand Down Expand Up @@ -278,4 +287,28 @@ func (fs *fs) GetFreeBlocks(n int) (int64, int64) {
}
log.Fatalf("Failed to find free block")
return 0, 0
}

func (fs *fs) walk(path string, inode *Inode, files []string) []string {
dirContents := inode.ReadDirectory()

for _, content := range dirContents {
if content.Name == "." || content.Name == ".." {
continue
}

i := fs.getInode(int64(content.Inode))

if (i.Mode & uint16(0x4000)) == 0 {
files = append(files, filepath.Join(path, content.Name))
continue
}

if i.UsesDirectoryHashTree() {
continue
}
files = fs.walk(filepath.Join(path, content.Name), i, files)
}

return files
}
1 change: 1 addition & 0 deletions gexto.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type File struct {
type FileSystem interface {
Open(name string) (*File, error)
Create(name string) (*File, error)
List() []string
Remove(name string) error
Mkdir(name string, perm os.FileMode) error
Close() error
Expand Down