本文整理匯總了Golang中syscall.Fstatfs函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fstatfs函數的具體用法?Golang Fstatfs怎麽用?Golang Fstatfs使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fstatfs函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFStatFs
func TestFStatFs(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
fOrig, err := os.OpenFile(ts.orig+"/file", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
if err != nil {
t.Fatalf("OpenFile failed: %v", err)
}
defer fOrig.Close()
empty := syscall.Statfs_t{}
s1 := empty
errno := syscall.Fstatfs(int(fOrig.Fd()), &s1)
if errno != nil {
t.Fatal("statfs orig", err)
}
fMnt, err := os.OpenFile(ts.mnt+"/file", os.O_RDWR, 0644)
if err != nil {
t.Fatalf("OpenFile failed: %v", err)
}
defer fMnt.Close()
s2 := empty
errno = syscall.Fstatfs(int(fMnt.Fd()), &s2)
if errno != nil {
t.Fatal("statfs mnt", err)
}
clearStatfs(&s1)
clearStatfs(&s2)
if fmt.Sprintf("%v", s2) != fmt.Sprintf("%v", s1) {
t.Errorf("statfs mismatch: %#v != %#v", s1, s2)
}
}
示例2: init_disk_usage
func init_disk_usage(disk_usage *DiskUsage) bool {
if disk_usage.reserved_blocks == 0 {
disk_usage.reserved_blocks = DEFAULT_FS_RESERVED_BLOCKS
}
disk_usage.total_size = 0
disk_usage.static_size = 0
disk_usage.dynamic_size = 0
disk_usage.ratio = 0.0
base_dir := "/store/instance"
fd, err := syscall.Open(base_dir, syscall.O_RDONLY, 0x664)
if err != nil {
logger.Error("%s does not exist, ignore disk quota filter.", base_dir)
return false
}
defer syscall.Close(fd)
var statfs syscall.Statfs_t
err = syscall.Fstatfs(fd, &statfs)
if err != nil {
logger.Error("Failed to get %s file system stats [%s].", base_dir, err)
return false
}
total_size := uint64(statfs.Bsize) * uint64(float64(statfs.Blocks)*
float64(1.0-disk_usage.reserved_blocks))
logger.Debug("Get total disk size %d.", total_size)
disk_usage.total_size = total_size
return true
}
示例3: TestStatfs
func TestStatfs(t *testing.T) {
fuse.Debugf = log.Printf
dir, err := ioutil.TempDir("", "fusetest")
if err != nil {
t.Fatal(err)
}
os.MkdirAll(dir, 0777)
c, err := fuse.Mount(dir)
if err != nil {
t.Fatal(err)
}
defer umount(dir)
go func() {
err := Serve(c, testStatFS{})
if err != nil {
fmt.Printf("SERVE ERROR: %v\n", err)
}
}()
waitForMount_inode1(t, dir)
{
var st syscall.Statfs_t
err = syscall.Statfs(dir, &st)
if err != nil {
t.Errorf("Statfs failed: %v", err)
}
t.Logf("Statfs got: %#v", st)
if g, e := st.Blocks, uint64(42); g != e {
t.Errorf("got Blocks = %q; want %q", g, e)
}
if g, e := st.Namelen, int64(13); g != e {
t.Errorf("got Namelen = %q; want %q", g, e)
}
}
{
var st syscall.Statfs_t
f, err := os.Open(dir)
if err != nil {
t.Errorf("Open for fstatfs failed: %v", err)
}
defer f.Close()
err = syscall.Fstatfs(int(f.Fd()), &st)
if err != nil {
t.Errorf("Fstatfs failed: %v", err)
}
t.Logf("Fstatfs got: %#v", st)
if g, e := st.Blocks, uint64(42); g != e {
t.Errorf("got Blocks = %q; want %q", g, e)
}
if g, e := st.Namelen, int64(13); g != e {
t.Errorf("got Namelen = %q; want %q", g, e)
}
}
}
示例4: Fstatfs
func (k *PosixKernel) Fstatfs(fd co.Fd, statfs co.Obuf) uint64 {
var tmp syscall.Statfs_t
if err := syscall.Fstatfs(int(fd), &tmp); err != nil {
return Errno(err)
}
if err := statfs.Pack(&tmp); err != nil {
return UINT64_MAX // FIXME
}
return 0
}
示例5: GetFSMagic
func GetFSMagic(rootpath string) (FsMagic, error) {
var buf syscall.Statfs_t
fd, err := syscall.Open(filepath.Dir(rootpath), 0, 0700)
if err != nil {
return 0, err
}
if err := syscall.Fstatfs(fd, &buf); err != nil {
return 0, err
}
return FsMagic(buf.Type), nil
}
示例6: HeartBeat
func (v *volume) HeartBeat() (stat maggiefs.VolumeStat, err error) {
sysstat := syscall.Statfs_t{}
err = syscall.Fstatfs(int(v.rootFile.Fd()), &sysstat)
if err != nil {
return stat, err
}
stat.VolumeInfo = v.info
// these sizes are in blocks of 512
stat.Size = sysstat.Blocks * uint64(sysstat.Bsize)
stat.Used = (uint64(sysstat.Blocks-sysstat.Bfree) * uint64(sysstat.Bsize))
stat.Free = sysstat.Bfree * uint64(sysstat.Bsize)
return stat, nil
}
示例7: TestStatfs
func TestStatfs(t *testing.T) {
t.Parallel()
mnt, err := fstestutil.MountedT(t, testStatFS{})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
{
var st syscall.Statfs_t
err = syscall.Statfs(mnt.Dir, &st)
if err != nil {
t.Errorf("Statfs failed: %v", err)
}
t.Logf("Statfs got: %#v", st)
if g, e := st.Blocks, uint64(42); g != e {
t.Errorf("got Blocks = %d; want %d", g, e)
}
if g, e := st.Files, uint64(13); g != e {
t.Errorf("got Files = %d; want %d", g, e)
}
}
{
var st syscall.Statfs_t
f, err := os.Open(mnt.Dir)
if err != nil {
t.Errorf("Open for fstatfs failed: %v", err)
}
defer f.Close()
err = syscall.Fstatfs(int(f.Fd()), &st)
if err != nil {
t.Errorf("Fstatfs failed: %v", err)
}
t.Logf("Fstatfs got: %#v", st)
if g, e := st.Blocks, uint64(42); g != e {
t.Errorf("got Blocks = %d; want %d", g, e)
}
if g, e := st.Files, uint64(13); g != e {
t.Errorf("got Files = %d; want %d", g, e)
}
}
}
示例8: processMountLine
func (p *prober) processMountLine(line string) error {
var device, mountPoint, fsType, fsOptions, junk string
nScanned, err := fmt.Sscanf(line, "%s %s %s %s %s",
&device, &mountPoint, &fsType, &fsOptions, &junk)
if err != nil {
return err
}
if nScanned < 4 {
return errors.New(fmt.Sprintf("only read %d values from %s",
nScanned, line))
}
if !strings.HasPrefix(device, "/dev/") {
return nil
}
device = device[5:]
fs := p.fileSystems[device]
if fs == nil {
fs = new(fileSystem)
p.fileSystems[device] = fs
if mountPoint == "/" {
fs.dir = p.dir
} else {
fs.dir, err = p.dir.RegisterDirectory(mountPoint)
if err != nil {
return err
}
}
fs.mountPoint = mountPoint
metricsDir, err := fs.dir.RegisterDirectory("METRICS")
if err != nil {
return err
}
if err := metricsDir.RegisterMetric("available", &fs.available,
units.Byte, "space available to unprivileged users"); err != nil {
return err
}
if err := metricsDir.RegisterMetric("device", &fs.device,
units.None, "device "); err != nil {
return err
}
if err := metricsDir.RegisterMetric("free", &fs.free,
units.Byte, "free space"); err != nil {
return err
}
if err := metricsDir.RegisterMetric("options", &fs.options,
units.None, "options "); err != nil {
return err
}
if err := metricsDir.RegisterMetric("size", &fs.size,
units.Byte, "available space"); err != nil {
return err
}
if err := metricsDir.RegisterMetric("writable", &fs.writable,
units.None, "true if writable, else read-only"); err != nil {
return err
}
}
if fs.probed {
return nil
}
if fd, err := syscall.Open(mountPoint, syscall.O_RDONLY, 0); err != nil {
return errors.New(fmt.Sprintf("error opening: %s %s", mountPoint, err))
} else {
defer syscall.Close(fd)
var statbuf syscall.Statfs_t
if err := syscall.Fstatfs(fd, &statbuf); err != nil {
return err
}
fs.available = statbuf.Bavail * uint64(statbuf.Bsize)
fs.free = statbuf.Bfree * uint64(statbuf.Bsize)
fs.size = statbuf.Blocks * uint64(statbuf.Bsize)
}
fs.device = device
fs.options = fsOptions
fs.writable = strings.HasPrefix(fs.options, "rw,")
fs.probed = true
return nil
}