1 Star 1 Fork 0

hh/etcd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
btrfs_linux.go 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
// +build linux,amd64
package btrfs
import (
"fmt"
"os"
"runtime"
"syscall"
"unsafe"
"github.com/coreos/etcd/log"
)
const (
// from Linux/include/uapi/linux/magic.h
BTRFS_SUPER_MAGIC = 0x9123683E
// from Linux/include/uapi/linux/fs.h
FS_NOCOW_FL = 0x00800000
FS_IOC_GETFLAGS = 0x80086601
FS_IOC_SETFLAGS = 0x40086602
)
// IsBtrfs checks whether the file is in btrfs
func IsBtrfs(path string) bool {
// btrfs is linux-only filesystem
// exit on other platforms
if runtime.GOOS != "linux" {
return false
}
var buf syscall.Statfs_t
if err := syscall.Statfs(path, &buf); err != nil {
log.Warnf("Failed to statfs: %v", err)
return false
}
log.Debugf("The type of path %v is %v", path, buf.Type)
if buf.Type != BTRFS_SUPER_MAGIC {
return false
}
log.Infof("The path %v is in btrfs", path)
return true
}
// SetNOCOWFile sets NOCOW flag for file
func SetNOCOWFile(path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
fileinfo, err := file.Stat()
if err != nil {
return err
}
if fileinfo.IsDir() {
return fmt.Errorf("skip directory")
}
if fileinfo.Size() != 0 {
return fmt.Errorf("skip nonempty file")
}
var attr int
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, file.Fd(), FS_IOC_GETFLAGS, uintptr(unsafe.Pointer(&attr))); errno != 0 {
return errno
}
attr |= FS_NOCOW_FL
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, file.Fd(), FS_IOC_SETFLAGS, uintptr(unsafe.Pointer(&attr))); errno != 0 {
return errno
}
log.Infof("Set NOCOW to path %v succeeded", path)
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/w1229748769/etcd.git
git@gitee.com:w1229748769/etcd.git
w1229748769
etcd
etcd
v0.4.8

搜索帮助