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


Golang syscall.Fallocate函数代码示例

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


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

示例1: TestFallocate

func TestFallocate(t *testing.T) {
	ts := NewTestCase(t)
	defer ts.Cleanup()
	if ts.state.KernelSettings().Minor < 19 {
		t.Log("FUSE does not support Fallocate.")
		return
	}

	rwFile, err := os.OpenFile(ts.mnt+"/file", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
	if err != nil {
		t.Fatalf("OpenFile failed: %v", err)
	}
	defer rwFile.Close()
	err = syscall.Fallocate(int(rwFile.Fd()), 0, 1024, 4096)
	if err != nil {
		t.Fatalf("FUSE Fallocate failed: %v", err)
	}
	fi, err := os.Lstat(ts.orig + "/file")
	if err != nil {
		t.Fatalf("Lstat failed: %v", err)
	}
	if fi.Size() < (1024 + 4096) {
		t.Fatalf("fallocate should have changed file size. Got %d bytes",
			fi.Size())
	}
}
开发者ID:jszwedko,项目名称:ec2-metadatafs,代码行数:26,代码来源:loopback_linux_test.go

示例2: New

func New(capacity int, filename string) (*Buffer, error) {
	if _, err := os.Stat(filename); !os.IsNotExist(err) {
		return nil, ErrFileExists
	}

	f, err := os.Create(filename)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	fsize := capacity + metadata
	if err := syscall.Fallocate(int(f.Fd()), 0, 0, int64(fsize)); err != nil {
		return nil, err
	}

	data, err := syscall.Mmap(
		int(f.Fd()), 0, fsize,
		syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED,
	)
	// TODO(ashish): Call msync periodically.
	if err != nil {
		return nil, err
	}

	b := &Buffer{
		capacity: uint64(capacity), // since it's used with uint64s a lot more
		filename: f.Name(),
		data:     data,
	}
	b.updateMeta()

	return b, nil
}
开发者ID:postfix,项目名称:buffer,代码行数:34,代码来源:buffer.go

示例3: fallocate

func fallocate(f *os.File, sz int64) error {
	err := syscall.Fallocate(int(f.Fd()), 0, 0, sz)
	if err == syscall.ENOTSUP {
		return f.Truncate(sz)
	}
	return err
}
开发者ID:Castcloud,项目名称:castcloud-go-server,代码行数:7,代码来源:advise_linux.go

示例4: punchHoleLinux

// puncHoleLinux punches a hole into the given file starting at offset,
// measuring "size" bytes
func punchHoleLinux(file *os.File, offset int64, size int64) error {
	err := syscall.Fallocate(int(file.Fd()),
		falloc_fl_punch_hole|falloc_fl_keep_size,
		offset, size)
	if err == syscall.ENOSYS || err == syscall.EOPNOTSUPP {
		return errNoPunch
	}
	return err
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:11,代码来源:punch_linux.go

示例5: Allocate

func (f *LoopbackFile) Allocate(off uint64, sz uint64, mode uint32) Status {
	f.lock.Lock()
	err := syscall.Fallocate(int(f.File.Fd()), mode, int64(off), int64(sz))
	f.lock.Unlock()
	if err != nil {
		return ToStatus(err)
	}
	return OK
}
开发者ID:seacoastboy,项目名称:go-fuse,代码行数:9,代码来源:files_linux.go

示例6: fallocateRetry

// fallocateRetry - syscall.Fallocate() with retry for EINTR.
func fallocateRetry(fd int, mode uint32, off int64, len int64) (err error) {
	for {
		err = syscall.Fallocate(fd, mode, off, len)
		if err == syscall.EINTR {
			continue
		}
		return err
	}
}
开发者ID:thinkingo,项目名称:gocryptfs,代码行数:10,代码来源:file.go

示例7: Allocate

func (f *AzukiFile) Allocate(off uint64, sz uint64, mode uint32) fuse.Status {
	f.lock.Lock()
	err := syscall.Fallocate(int(f.File.Fd()), mode, int64(off), int64(sz))
	f.lock.Unlock()
	if err != nil {
		return fuse.ToStatus(err)
	}
	go event.Notify(event.Fallocate, f.File.Name())
	return fuse.OK
}
开发者ID:rizki96,项目名称:kakigoori,代码行数:10,代码来源:node.go

示例8: prealloc

// prealloc - preallocate space without changing the file size. This prevents
// us from running out of space in the middle of an operation.
func prealloc(fd int, off int64, len int64) (err error) {
	for {
		err = syscall.Fallocate(fd, FALLOC_FL_KEEP_SIZE, off, len)
		if err == syscall.EINTR {
			// fallocate, like many syscalls, can return EINTR. This is not an
			// error and just signifies that the operation was interrupted by a
			// signal and we should try again.
			continue
		}
		return err
	}
}
开发者ID:louisyoo,项目名称:gocryptfs,代码行数:14,代码来源:compat_linux.go

示例9: preallocFixed

func preallocFixed(f *os.File, sizeInBytes int64) error {
	// use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE
	err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes)
	if err != nil {
		errno, ok := err.(syscall.Errno)
		// treat not supported as nil error
		if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) {
			return nil
		}
	}
	return err
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:12,代码来源:preallocate_unix.go

示例10: createBackingFile

func createBackingFile(backing string) error {
	flags := syscall.O_RDWR | syscall.O_CREAT | syscall.O_EXCL
	file, err := os.OpenFile(backing, flags, 0755)
	if err != nil {
		return fmt.Errorf("Failed to create backing file %s: %s.", backing, err)
	}
	err = syscall.Fallocate(int(file.Fd()), 0, 0, fileSizeInBytes)
	if err != nil {
		return fmt.Errorf("Failed to allocate %s: %s.", backing, err)
	}
	return nil
}
开发者ID:vmware,项目名称:docker-volume-vsphere,代码行数:12,代码来源:mock_vmdkcmd.go

示例11: preallocExtend

func preallocExtend(f *os.File, sizeInBytes int64) error {
	// use mode = 0 to change size
	err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes)
	if err != nil {
		errno, ok := err.(syscall.Errno)
		// treat not support as nil error
		if ok && errno == syscall.ENOTSUP {
			return preallocExtendTrunc(f, sizeInBytes)
		}
	}
	return err
}
开发者ID:40a,项目名称:bootkube,代码行数:12,代码来源:preallocate_unix.go

示例12: preallocExtend

func preallocExtend(f *os.File, sizeInBytes int64) error {
	// use mode = 0 to change size
	err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes)
	if err != nil {
		errno, ok := err.(syscall.Errno)
		// not supported; fallback
		// fallocate EINTRs frequently in some enviroments; fallback
		if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) {
			return preallocExtendTrunc(f, sizeInBytes)
		}
	}
	return err
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:13,代码来源:preallocate_unix.go

示例13: Preallocate

// Preallocate tries to allocate the space for given
// file. This operation is only supported on linux by a
// few filesystems (btrfs, ext4, etc.).
// If the operation is unsupported, no error will be returned.
// Otherwise, the error encountered will be returned.
func Preallocate(f *os.File, sizeInBytes int) error {
	// use mode = 1 to keep size
	// see FALLOC_FL_KEEP_SIZE
	err := syscall.Fallocate(int(f.Fd()), 1, 0, int64(sizeInBytes))
	if err != nil {
		errno, ok := err.(syscall.Errno)
		// treat not support as nil error
		if ok && errno == syscall.ENOTSUP {
			return nil
		}
		return err
	}
	return nil
}
开发者ID:CNDonny,项目名称:scope,代码行数:19,代码来源:preallocate.go

示例14: main

func main() {
	flag.Usage = usage
	flag.Parse()
	if flag.NArg() < 1 {
		usage()
	}

	status := 0
	for _, name := range flag.Args() {
		f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE, 0644)
		if ek(err) {
			continue
		}
		ek(syscall.Fallocate(int(f.Fd()), 0, *offset, *size))
	}
	os.Exit(status)
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:17,代码来源:fallocate.go

示例15: NewOutputValueFile

// NewOutputValueFile creates an entity implmenting the OutputValueFile interface
func NewOutputValueFile(fileSpaceInfo tools.FileSpaceInfo) (OutputValueFile, error) {
	var valueFile outputValueFile
	var err error

	valueFile.creationTime = tools.Timestamp()
	valueFile.md5Sum = md5.New()
	valueFile.collectionIDSet = make(map[uint32]struct{})
	repositoryPath := os.Getenv("NIMBUSIO_REPOSITORY_PATH")

	if valueFile.spaceID, err = fileSpaceInfo.FindMaxAvailSpaceID(tools.FileSpaceJournal); err != nil {
		return nil, err
	}

	if err = valueFile.insertValueFileRow(); err != nil {
		return nil, err
	}

	valueFile.filePath = tools.ComputeValueFilePath(repositoryPath, valueFile.spaceID,
		valueFile.valueFileID)

	fog.Debug("NewOutputValueFile %s", valueFile.filePath)

	dirPath := path.Dir(valueFile.filePath)
	if err = os.MkdirAll(dirPath, os.ModeDir|0755); err != nil {
		return nil, fmt.Errorf("os.MkdirAll(%s...", err)
	}

	valueFile.fileHandle, err = os.Create(valueFile.filePath)
	if err != nil {
		return nil, fmt.Errorf("os.Create(%s) %s", valueFile.filePath, err)
	}

	err = syscall.Fallocate(int(valueFile.fileHandle.Fd()), 0, 0,
		int64(MaxValueFileSize))
	if err != nil {
		return nil, fmt.Errorf("Fallocate failed %s", err)
	}

	valueFile.enableFsync = os.Getenv("NIMBUSIO_ENABLE_FSYNC") == "1"
	fog.Info("NewOutputValueFile: NIMBUSIO_ENABLE_FSYNC = %t", valueFile.enableFsync)

	return &valueFile, nil
}
开发者ID:HackLinux,项目名称:nimbus.io,代码行数:44,代码来源:output_value_file.go


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