mirror of
https://github.com/versity/scoutfs-go.git
synced 2025-12-23 13:15:19 +00:00
move inode to path lookup outside of open by id
This commit is contained in:
@@ -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())
|
||||
|
||||
11
scoutfs.go
11
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
|
||||
|
||||
Reference in New Issue
Block a user