mirror of
https://github.com/versity/scoutfs-go.git
synced 2026-01-08 12:41:11 +00:00
fix ListXattrRaw, add examples for listxattr and findxattr
This commit is contained in:
42
examples/findxattr/main.go
Normal file
42
examples/findxattr/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2018 Versity Software, Inc.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-3-Clause license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
scoutfs "github.com/versity/scoutfs-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 || os.Args[1] == "-h" {
|
||||
fmt.Fprintln(os.Stderr, "usage:", os.Args[0], "<mount point> <xattr key>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
f, err := os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatalf("open %v: %v", os.Args[1], err)
|
||||
}
|
||||
|
||||
q := scoutfs.NewXattrQuery(f, os.Args[2])
|
||||
|
||||
for {
|
||||
inodes, err := q.Next()
|
||||
if err != nil {
|
||||
log.Fatalf("Next(): %v", err)
|
||||
}
|
||||
if inodes == nil {
|
||||
break
|
||||
}
|
||||
for _, inode := range inodes {
|
||||
fmt.Println(inode)
|
||||
}
|
||||
}
|
||||
}
|
||||
42
examples/listxattr/main.go
Normal file
42
examples/listxattr/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2018 Versity Software, Inc.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-3-Clause license
|
||||
// that can be found in the LICENSE file in the root of the source
|
||||
// tree.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
scoutfs "github.com/versity/scoutfs-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 || os.Args[1] == "-h" {
|
||||
fmt.Fprintln(os.Stderr, "usage:", os.Args[0], "<filepath>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
f, err := os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatalf("open %v: %v", os.Args[1], err)
|
||||
}
|
||||
|
||||
lxr := scoutfs.NewListXattrRaw(f)
|
||||
|
||||
for {
|
||||
attrs, err := lxr.Next()
|
||||
if err != nil {
|
||||
log.Fatalf("next(): %v", err)
|
||||
}
|
||||
if attrs == nil {
|
||||
break
|
||||
}
|
||||
for _, attr := range attrs {
|
||||
fmt.Println(attr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -447,7 +447,7 @@ func (l *ListXattrRaw) Next() ([]string, error) {
|
||||
buf := make([]byte, 256*1024)
|
||||
l.lxr.buf = uintptr(unsafe.Pointer(&buf[0]))
|
||||
|
||||
n, err := scoutfsctl(l.f.Fd(), IOCFINDXATTRS, uintptr(unsafe.Pointer(&l.lxr)))
|
||||
n, err := scoutfsctl(l.f.Fd(), IOCLISTXATTRRAW, uintptr(unsafe.Pointer(l.lxr)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user