From 86319248974744f5173a4d15b34dbccd2ef60b5e Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Wed, 5 Dec 2018 12:55:00 -0800 Subject: [PATCH] move inode to path lookup outside of open by id --- examples/inodestat/main.go | 9 ++++++++- scoutfs.go | 11 +++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/inodestat/main.go b/examples/inodestat/main.go index 964bcc4..44a82d2 100644 --- a/examples/inodestat/main.go +++ b/examples/inodestat/main.go @@ -32,16 +32,23 @@ func main() { log.Fatalln("error parsing inode:", err) } - f, err := scoutfs.OpenByID(dirf, u, os.O_RDONLY) + name, err := scoutfs.InoToPath(dirf, u) + if err != nil { + log.Fatalln("error getting pathname:", err) + } + + f, err := scoutfs.OpenByID(dirf, u, os.O_RDONLY, name) if err != nil { log.Fatalln("error open by id:", err) } + defer f.Close() fi, err := f.Stat() if err != nil { log.Fatalln("error stat:", err) } + fmt.Println("Full name relative to mount:", name) fmt.Println("Name:", fi.Name()) fmt.Println("Size:", fi.Size()) fmt.Println("Mode:", fi.Mode()) diff --git a/scoutfs.go b/scoutfs.go index 366fd43..d8383e8 100644 --- a/scoutfs.go +++ b/scoutfs.go @@ -181,14 +181,9 @@ func InoToPath(dirfd *os.File, ino uint64) (string, error) { // OpenByID will open a file by inode returning a typical *os.File // An open file within scoutfs is supplied for ioctls // (usually just the base mount point directory) -// The filename is available through the *os.File and is populated with -// the scoutfs InoToPath -func OpenByID(dirfd *os.File, ino uint64, flags int) (*os.File, error) { - name, err := InoToPath(dirfd, ino) - if err != nil { - return nil, err - } - +// The filename supplied is used for the *os.File info, but can be "" if +// not known or needed +func OpenByID(dirfd *os.File, ino uint64, flags int, name string) (*os.File, error) { fd, err := OpenByHandle(dirfd, ino, flags) if err != nil { return nil, err