diff --git a/filesystem.go b/filesystem.go index 4e9c73e..9fa8ad7 100644 --- a/filesystem.go +++ b/filesystem.go @@ -7,6 +7,7 @@ import ( "log" "fmt" "io" + "path/filepath" ) type fs struct { @@ -14,6 +15,14 @@ type fs struct { 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, "/") @@ -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 } \ No newline at end of file diff --git a/gexto.go b/gexto.go index 3742991..2d9ff27 100644 --- a/gexto.go +++ b/gexto.go @@ -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