From fa3deaab4127b835da9a3db25fe18c43c901927b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 27 Apr 2012 01:46:31 -0700 Subject: [PATCH] cammount: some more fuse work. Change-Id: I84df5c10eca3bb7c4617077f28d3b00bcda75a67 --- dev-cammount | 2 +- pkg/fs/fs.go | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/dev-cammount b/dev-cammount index a2b0f6c67..82ff95dae 100755 --- a/dev-cammount +++ b/dev-cammount @@ -16,7 +16,7 @@ mkdir $dir, 0700 unless -d $dir; try_unmount(); print "Mounting on $dir ...\n"; -system("$cammount", "--blobserver=localhost:3179/bs", $blobref, $dir) +system("$cammount", "--blobserver=http://localhost:3179/bs", $blobref, $dir) and warn "cammount failure: $!\n"; warn "Failed to unmount\n" unless try_unmount(); diff --git a/pkg/fs/fs.go b/pkg/fs/fs.go index 1d94f1ab6..d4c81e309 100644 --- a/pkg/fs/fs.go +++ b/pkg/fs/fs.go @@ -24,6 +24,7 @@ import ( "log" "os" "syscall" + "time" "camlistore.org/pkg/blobref" "camlistore.org/pkg/lru" @@ -71,14 +72,46 @@ func NewCamliFileSystem(fetcher blobref.SeekFetcher, root *blobref.BlobRef) *Cam type node struct { fs *CamliFileSystem blobref *blobref.BlobRef + attr fuse.Attr } func (n *node) Attr() (attr fuse.Attr) { - return + return n.attr +} + +func (n *node) populateAttr(ss *schema.Superset) error { + // TODO: common stuff: + // Uid uint32 + // Gid uint32 + // Mtime time.Time + // inode? + + switch ss.Type { + case "directory": + n.attr.Mode = os.ModeDir + case "file": + n.attr.Size = ss.SumPartsSize() + n.attr.Blocks = 0 // TODO: set? + n.attr.Mtime = time.Time{} // TODO: set, for sure. + n.attr.Mode = 0 + default: + err := fmt.Errorf("unknown attr type %q in populateAttr", ss.Type) + log.Print(err.Error()) + return err + } + return nil } func (fs *CamliFileSystem) Root() (fuse.Node, fuse.Error) { - return &node{fs: fs, blobref: fs.root}, nil + ss, err := fs.fetchSchemaSuperset(fs.root) + if err != nil { + // TODO: map these to fuse.Error better + log.Printf("Error fetching root: %v", err) + return nil, fuse.EIO + } + n := &node{fs: fs, blobref: fs.root} + n.populateAttr(ss) + return n, nil } // Errors returned are: @@ -89,7 +122,6 @@ func (fs *CamliFileSystem) fetchSchemaSuperset(br *blobref.BlobRef) (*schema.Sup if ss, ok := fs.blobToSchema.Get(blobStr); ok { return ss.(*schema.Superset), nil } - log.Printf("schema cache MISS on %q", blobStr) rsc, _, err := fs.fetcher.Fetch(br) if err != nil {