move inode to path lookup outside of open by id

This commit is contained in:
Ben McClelland
2018-12-05 12:55:00 -08:00
parent 688e3df996
commit 8631924897
2 changed files with 11 additions and 9 deletions

View File

@@ -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())

View File

@@ -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