当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Statfs函数代码示例

本文整理汇总了Golang中syscall.Statfs函数的典型用法代码示例。如果您正苦于以下问题:Golang Statfs函数的具体用法?Golang Statfs怎么用?Golang Statfs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Statfs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestStatFs

// This test is racy. If an external process consumes space while this
// runs, we may see spurious differences between the two statfs() calls.
func TestStatFs(t *testing.T) {
	ts := NewTestCase(t)
	defer ts.Cleanup()

	empty := syscall.Statfs_t{}
	s1 := empty
	err := syscall.Statfs(ts.orig, &s1)
	if err != 0 {
		t.Fatal("statfs orig", err)
	}

	s2 := syscall.Statfs_t{}
	err = syscall.Statfs(ts.mnt, &s2)

	s1.Type = 0
	s2.Type = 0

	s1.Fsid = empty.Fsid
	s2.Fsid = empty.Fsid

	s1.Spare = empty.Spare
	s2.Spare = empty.Spare

	if err != 0 {
		t.Fatal("statfs mnt", err)
	}

	if fmt.Sprintf("%v", s2) != fmt.Sprintf("%v", s1) {
		t.Error("Mismatch", s1, s2)
	}
}
开发者ID:lht,项目名称:go-fuse,代码行数:33,代码来源:loopback_test.go

示例2: TestClientStatVFS

func TestClientStatVFS(t *testing.T) {
	if *testServerImpl {
		t.Skipf("go server does not support FXP_EXTENDED")
	}
	sftp, cmd := testClient(t, READWRITE, NO_DELAY)
	defer cmd.Wait()
	defer sftp.Close()

	vfs, err := sftp.StatVFS("/")
	if err != nil {
		t.Fatal(err)
	}

	// get system stats
	s := syscall.Statfs_t{}
	err = syscall.Statfs("/", &s)
	if err != nil {
		t.Fatal(err)
	}

	// check some stats
	if vfs.Files != uint64(s.Files) {
		t.Fatal("fr_size does not match")
	}

	if vfs.Bfree != uint64(s.Bfree) {
		t.Fatal("f_bsize does not match")
	}

	if vfs.Favail != uint64(s.Ffree) {
		t.Fatal("f_namemax does not match")
	}
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:33,代码来源:client_integration_darwin_test.go

示例3: Mounted

// Mounted checks if the given path is mounted as the fs type
func Mounted(fsType FsMagic, mountPath string) (bool, error) {
	var buf syscall.Statfs_t
	if err := syscall.Statfs(mountPath, &buf); err != nil {
		return false, err
	}
	return FsMagic(buf.Type) == fsType, nil
}
开发者ID:CrocdileChan,项目名称:docker,代码行数:8,代码来源:driver_freebsd.go

示例4: getSelinuxMountPoint

// getSelinuxMountPoint returns the path to the mountpoint of an selinuxfs
// filesystem or an empty string if no mountpoint is found.  Selinuxfs is
// a proc-like pseudo-filesystem that exposes the selinux policy API to
// processes.  The existence of an selinuxfs mount is used to determine
// whether selinux is currently enabled or not.
func getSelinuxMountPoint() string {
	if selinuxfs != "unknown" {
		return selinuxfs
	}
	selinuxfs = ""

	mounts, err := mount.GetMounts()
	if err != nil {
		return selinuxfs
	}
	for _, mount := range mounts {
		if mount.Fstype == "selinuxfs" {
			selinuxfs = mount.Mountpoint
			break
		}
	}
	if selinuxfs != "" {
		var buf syscall.Statfs_t
		syscall.Statfs(selinuxfs, &buf)
		if (buf.Flags & stRdOnly) == 1 {
			selinuxfs = ""
		}
	}
	return selinuxfs
}
开发者ID:previousnext,项目名称:kube-ingress,代码行数:30,代码来源:selinux.go

示例5: New

// New - instantiate new disk
func New(diskPath string) (Disk, error) {
	if diskPath == "" {
		return Disk{}, iodine.New(InvalidArgument{}, nil)
	}
	st, err := os.Stat(diskPath)
	if err != nil {
		return Disk{}, iodine.New(err, nil)
	}
	if !st.IsDir() {
		return Disk{}, iodine.New(syscall.ENOTDIR, nil)
	}
	s := syscall.Statfs_t{}
	err = syscall.Statfs(diskPath, &s)
	if err != nil {
		return Disk{}, iodine.New(err, nil)
	}
	disk := Disk{
		lock:   &sync.Mutex{},
		path:   diskPath,
		fsInfo: make(map[string]string),
	}
	if fsType := getFSType(s.Type); fsType != "UNKNOWN" {
		disk.fsInfo["FSType"] = fsType
		disk.fsInfo["MountPoint"] = disk.path
		return disk, nil
	}
	return Disk{}, iodine.New(UnsupportedFilesystem{Type: strconv.FormatInt(int64(s.Type), 10)},
		map[string]string{"Type": strconv.FormatInt(int64(s.Type), 10)})
}
开发者ID:wangtuanjie,项目名称:minio,代码行数:30,代码来源:disk.go

示例6: filesystemDetect

/*
 * filesystemDetect returns the filesystem on which
 * the passed-in path sits
 */
func filesystemDetect(path string) (string, error) {
	fs := syscall.Statfs_t{}

	err := syscall.Statfs(path, &fs)
	if err != nil {
		return "", err
	}

	switch fs.Type {
	case filesystemSuperMagicBtrfs:
		return "btrfs", nil
	case filesystemSuperMagicZfs:
		return "zfs", nil
	case filesystemSuperMagicTmpfs:
		return "tmpfs", nil
	case filesystemSuperMagicExt4:
		return "ext4", nil
	case filesystemSuperMagicXfs:
		return "xfs", nil
	case filesystemSuperMagicNfs:
		return "nfs", nil
	default:
		shared.Debugf("Unknown backing filesystem type: 0x%x", fs.Type)
		return string(fs.Type), nil
	}
}
开发者ID:jameinel,项目名称:lxd,代码行数:30,代码来源:storage.go

示例7: isPathInDMG

// isPathInDMG errors if the path is inside dmg
func isPathInDMG(p string) (inDMG bool, bundlePath string, err error) {
	var stat syscall.Statfs_t
	err = syscall.Statfs(p, &stat)
	if err != nil {
		return
	}

	// mntRootFS identifies the root filesystem (http://www.opensource.apple.com/source/xnu/xnu-344.26/bsd/sys/mount.h)
	const mntRootFS = 0x00004000

	if (stat.Flags & mntRootFS) != 0 {
		// We're on the root filesystem so we're not in a DMG
		return
	}

	bundlePath = bundleDirForPath(p)
	if bundlePath != "" {
		// Look for Applications symlink in the same folder as Keybase.app, and if
		// we find it, we're really likely to be in a mounted dmg
		appLink := filepath.Join(filepath.Dir(bundlePath), "Applications")
		fi, ferr := os.Lstat(appLink)
		if os.IsNotExist(ferr) {
			return
		}
		isLink := (fi.Mode()&os.ModeSymlink != 0)
		if isLink {
			inDMG = true
			return
		}
	}

	return
}
开发者ID:jacobhaven,项目名称:client,代码行数:34,代码来源:install_osx.go

示例8: BuildDeviceUsage

func BuildDeviceUsage(_fsSpec, _fsFile, _fsVfstype string) (*DeviceUsage, error) {
	ret := &DeviceUsage{FsSpec: _fsSpec, FsFile: _fsFile, FsVfstype: _fsVfstype}

	fs := syscall.Statfs_t{}
	err := syscall.Statfs(_fsFile, &fs)
	if err != nil {
		return nil, err
	}

	// blocks
	used := fs.Blocks - fs.Bfree
	ret.BlocksAll = uint64(fs.Frsize) * fs.Blocks
	ret.BlocksUsed = uint64(fs.Frsize) * used
	ret.BlocksFree = uint64(fs.Frsize) * fs.Bavail
	if fs.Blocks == 0 {
		ret.BlocksUsedPercent = 100.0
	} else {
		ret.BlocksUsedPercent = float64(used) * 100.0 / float64(used+fs.Bavail)
	}
	ret.BlocksFreePercent = 100.0 - ret.BlocksUsedPercent

	// inodes
	ret.InodesAll = fs.Files
	ret.InodesFree = fs.Ffree
	ret.InodesUsed = fs.Files - fs.Ffree
	if fs.Files == 0 {
		ret.InodesUsedPercent = 100.0
	} else {
		ret.InodesUsedPercent = float64(ret.InodesUsed) * 100.0 / float64(ret.InodesAll)
	}
	ret.InodesFreePercent = 100.0 - ret.InodesUsedPercent

	return ret, nil
}
开发者ID:ziyel,项目名称:nux,代码行数:34,代码来源:dfstat_linux.go

示例9: getImageAndWrite

func getImageAndWrite(imageClient *rpc.Client,
	objectClient *objectclient.ObjectClient, name, dirname string) error {
	inodesDir := dirname + ".inodes"
	if err := os.Mkdir(inodesDir, dirPerms); err != nil {
		return err
	}
	defer os.RemoveAll(inodesDir)
	fs, err := getImage(imageClient, name)
	if err != nil {
		return err
	}
	var statfs syscall.Statfs_t
	if err := syscall.Statfs(inodesDir, &statfs); err != nil {
		return errors.New(fmt.Sprintf("Unable to Statfs: %s %s\n",
			inodesDir, err))
	}
	if fs.TotalDataBytes > uint64(statfs.Bsize)*statfs.Bfree {
		return errors.New("image will not fit on file-system")
	}
	hashes, inums, lengths := getHashes(fs)
	err = writeObjects(objectClient, hashes, inums, lengths, inodesDir)
	if err != nil {
		return err
	}
	if err := writeInodes(fs.InodeTable, inodesDir); err != nil {
		return err
	}
	if err = fs.DirectoryInode.Write(dirname); err != nil {
		return err
	}
	return buildTree(&fs.DirectoryInode, dirname, inodesDir)
}
开发者ID:JohnTheodore,项目名称:Dominator,代码行数:32,代码来源:getImage.go

示例10: Update

// Expose filesystem fullness.
func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
	mpds, err := mountPointDetails()
	if err != nil {
		return err
	}
	for _, mpd := range mpds {
		if c.ignoredMountPointsPattern.MatchString(mpd.mountPoint) {
			log.Debugf("Ignoring mount point: %s", mpd.mountPoint)
			continue
		}
		buf := new(syscall.Statfs_t)
		err := syscall.Statfs(mpd.mountPoint, buf)
		if err != nil {
			return fmt.Errorf("Statfs on %s returned %s", mpd.mountPoint, err)
		}

		c.size.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Blocks) * float64(buf.Bsize))
		c.free.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Bfree) * float64(buf.Bsize))
		c.avail.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Bavail) * float64(buf.Bsize))
		c.files.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Files))
		c.filesFree.WithLabelValues(mpd.device, mpd.mountPoint, mpd.fsType).Set(float64(buf.Ffree))
	}
	c.size.Collect(ch)
	c.free.Collect(ch)
	c.avail.Collect(ch)
	c.files.Collect(ch)
	c.filesFree.Collect(ch)
	return err
}
开发者ID:robbiet480,项目名称:node_exporter,代码行数:30,代码来源:filesystem_linux.go

示例11: IsNSorErr

func IsNSorErr(nspath string) error {
	stat := syscall.Statfs_t{}
	if err := syscall.Statfs(nspath, &stat); err != nil {
		if os.IsNotExist(err) {
			err = NSPathNotExistErr{msg: fmt.Sprintf("failed to Statfs %q: %v", nspath, err)}
		} else {
			err = fmt.Errorf("failed to Statfs %q: %v", nspath, err)
		}
		return err
	}

	switch stat.Type {
	case PROCFS_MAGIC:
		// Kernel < 3.19

		validPathContent := "ns/"
		validName := strings.Contains(nspath, validPathContent)
		if !validName {
			return NSPathNotNSErr{msg: fmt.Sprintf("path %q doesn't contain %q", nspath, validPathContent)}
		}

		return nil
	case NSFS_MAGIC:
		// Kernel >= 3.19

		return nil
	default:
		return NSPathNotNSErr{msg: fmt.Sprintf("unknown FS magic on %q: %x", nspath, stat.Type)}
	}
}
开发者ID:blablacar,项目名称:dgr,代码行数:30,代码来源:ns.go

示例12: BuildDeviceUsage

func BuildDeviceUsage(arr [3]string) (*DeviceUsageStruct, error) {
	ret := &DeviceUsageStruct{FsSpec: arr[0], FsFile: arr[1], FsVfstype: arr[2]}

	fs := syscall.Statfs_t{}
	err := syscall.Statfs(arr[1], &fs)
	if err != nil {
		return nil, err
	}

	// blocks
	used := fs.Blocks - fs.Bfree
	ret.BlocksAll = uint64(fs.Frsize) * fs.Blocks
	ret.BlocksUsed = uint64(fs.Frsize) * used
	ret.BlocksFree = uint64(fs.Frsize) * fs.Bfree
	if fs.Blocks == 0 {
		ret.BlocksUsedPercent = 100.0
	} else {
		ret.BlocksUsedPercent = float64(float64(used) * 100.0 / float64(fs.Blocks))
	}
	ret.BlocksFreePercent = 100.0 - ret.BlocksUsedPercent

	// inodes
	ret.InodesAll = fs.Files
	ret.InodesFree = fs.Ffree
	ret.InodesUsed = fs.Files - fs.Ffree
	if fs.Files == 0 {
		ret.InodesUsedPercent = 100.0
	} else {
		ret.InodesUsedPercent = float64(float64(ret.InodesUsed) * 100.0 / float64(ret.InodesAll))
	}
	ret.InodesFreePercent = 100.0 - ret.InodesUsedPercent

	return ret, nil
}
开发者ID:sdgdsffdsfff,项目名称:falcon,代码行数:34,代码来源:dfstat.go

示例13: Syscall_NonZeroValues

func (t *StatFSTest) Syscall_NonZeroValues() {
	var err error
	var stat syscall.Statfs_t

	// Set up the canned response.
	canned := fuseops.StatFSOp{
		BlockSize: 1 << 15,
		IoSize:    1 << 16,

		Blocks:          1<<51 + 3,
		BlocksFree:      1<<43 + 5,
		BlocksAvailable: 1<<41 + 7,

		Inodes:     1<<59 + 11,
		InodesFree: 1<<58 + 13,
	}

	t.fs.SetStatFSResponse(canned)

	// Stat.
	err = syscall.Statfs(t.Dir, &stat)
	AssertEq(nil, err)

	ExpectEq(canned.BlockSize, stat.Frsize)
	ExpectEq(canned.IoSize, stat.Bsize)
	ExpectEq(canned.Blocks, stat.Blocks)
	ExpectEq(canned.BlocksFree, stat.Bfree)
	ExpectEq(canned.BlocksAvailable, stat.Bavail)
	ExpectEq(canned.Inodes, stat.Files)
	ExpectEq(canned.InodesFree, stat.Ffree)
}
开发者ID:andrewgaul,项目名称:fuse,代码行数:31,代码来源:statfs_linux_test.go

示例14: DiskUsage

func DiskUsage(path string) (disk DiskStatus) {
	fs := syscall.Statfs_t{}
	err := syscall.Statfs(path, &fs)
	if err != nil {
		return
	}
	fmt.Print("",
		"Type:", fs.Type, "\n", /* Type of filesystem (see below) */
		"Bsize:", fs.Bsize, "\n", /* Optimal transfer block size */
		"Blocks:", fs.Blocks, "\n", /* Total data blocks in filesystem */
		"Bfree:", fs.Bfree, "\n", /* Free blocks in filesystem */
		"Bavail:", fs.Bavail, "\n", /* Free blocks available to unprivileged user*/
		"Files:", fs.Files, "\n", /* Total file nodes in filesystem */
		"Ffree:", fs.Ffree, "\n", /* Free file nodes in filesystem */
		//"Fsid:", fs.Bsize, "\n",/* Filesystem ID */
		"Namelen:", fs.Namelen, "\n", /* Maximum length of filenames */
		"Frsize:", fs.Frsize, "\n", /* Fragment size (since Linux 2.6) */
		"Flags:", fs.Flags, "\n", /* Mount flags of filesystem (since Linux 2.6.36) */
		//"Spare:", fs.Bsize, "\n", /* Padding bytes reserved for future use */
	)

	disk.All = fs.Blocks * uint64(fs.Bsize)
	disk.Free = fs.Bfree * uint64(fs.Bsize)
	disk.Used = disk.All - disk.Free
	fmt.Println("",
		"Total:", disk.All, bytefmt.ByteSize(disk.All), "\n",
		"Used:", disk.Used, bytefmt.ByteSize(disk.Used), "\n",
		"Free:", disk.Free, bytefmt.ByteSize(disk.Free))
	return
}
开发者ID:michalliu,项目名称:syncthing-wrapper,代码行数:30,代码来源:spaceStatus.go

示例15: Measure

func (m *DiskSpaceMeasurer) Measure() (float64, error) {
	var res syscall.Statfs_t
	if err := syscall.Statfs(m.path, &res); err != nil {
		return 0, err
	}
	return float64(res.Blocks-res.Bavail) * float64(res.Bsize), nil
}
开发者ID:CAFxX,项目名称:gojuggle,代码行数:7,代码来源:disk_space.go


注:本文中的syscall.Statfs函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。