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


Golang syscall.Pwrite函数代码示例

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


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

示例1: Write

func (constor *Constor) Write(input *fuse.WriteIn, data []byte) (written uint32, code fuse.Status) {
	constor.log("%d", input.Fh)
	ptr := uintptr(input.Fh)
	offset := input.Offset

	F := constor.getfd(ptr)
	if F == nil {
		constor.error("F == nil")
		return 0, fuse.EIO
	}
	inode, err := constor.inodemap.findInode(input.NodeId)
	if err != nil {
		constor.error("%s", err)
		return 0, fuse.ToStatus(err)
	}
	if F.layer != 0 && inode.layer != 0 {
		err = constor.copyup(inode)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		path, err := constor.dentrymap.getPath(inode.ino)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		pathl := Path.Join(constor.layers[0], path)
		syscall.Close(F.fd)
		fd, err := syscall.Open(pathl, F.flags, 0)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		F.fd = fd
		F.layer = 0
		constor.log("reset fd for %s", path)
	} else if F.layer != 0 && inode.layer == 0 {
		syscall.Close(F.fd)
		path, err := constor.dentrymap.getPath(inode.ino)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		pathl := Path.Join(constor.layers[0] + path)
		fd, err := syscall.Open(pathl, F.flags, 0)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		F.fd = fd
		F.layer = 0
		constor.log("reset fd for %s", path)
	}

	fd := F.fd
	n, err := syscall.Pwrite(fd, data, int64(offset))
	return uint32(n), fuse.ToStatus(err)
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:58,代码来源:main.go

示例2: Pwrite64

func (k *PosixKernel) Pwrite64(fd co.Fd, buf co.Buf, size co.Len, offset int64) uint64 {
	p := make([]byte, size)
	if err := buf.Unpack(p); err != nil {
		return UINT64_MAX // FIXME
	}
	n, err := syscall.Pwrite(int(fd), p, offset)
	if err != nil {
		return Errno(err)
	}
	return uint64(n)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:11,代码来源:io.go

示例3: Write

func (constor *Constor) Write(input *fuse.WriteIn, data []byte) (written uint32, code fuse.Status) {
	constor.log("%d %d", input.Fh, len(data))
	ptr := uintptr(input.Fh)
	offset := input.Offset
	wdata := data

	F := constor.getfd(ptr)
	if F == nil {
		constor.error("F == nil")
		return 0, fuse.EIO
	}
	if F.flags&syscall.O_DIRECT != 0 {
		wdata = directio.AlignedBlock(len(data))
		copy(wdata, data)
	}
	inode := constor.inodemap.findInodePtr(input.NodeId)
	if inode == nil {
		return 0, fuse.ENOENT
	}
	if F.layer != 0 && inode.layer != 0 {
		err := constor.copyup(inode)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		path := constor.getPath(0, inode.id)
		syscall.Close(F.fd)
		fd, err := syscall.Open(path, F.flags, 0)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		F.fd = fd
		F.layer = 0
		constor.log("reset fd for %s", path)
	} else if F.layer != 0 && inode.layer == 0 {
		syscall.Close(F.fd)
		path := constor.getPath(0, inode.id)
		fd, err := syscall.Open(path, F.flags, 0)
		if err != nil {
			constor.error("%s", err)
			return 0, fuse.ToStatus(err)
		}
		F.fd = fd
		F.layer = 0
		constor.log("reset fd for %s", path)
	}

	fd := F.fd
	n, err := syscall.Pwrite(fd, wdata, int64(offset))
	return uint32(n), fuse.ToStatus(err)
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:52,代码来源:main.go

示例4: WriteInt16

func (b Bone) WriteInt16(addr int, val uint16) error {
	data := make([]byte, 2)
	data[0] = byte((val) & 0x00FF)
	data[1] = byte((val >> 8) & 0x00FF)
	count, err := syscall.Pwrite(int(b), data, int64(addr))
	if err != nil {
		return err
	}
	if count != 2 {
		return errors.New("wrong number of bytes written")
	}
	return nil
}
开发者ID:enjenye,项目名称:beaglebone,代码行数:13,代码来源:beaglebone.go

示例5: WriteAt

// WriteAt writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an Error, if any.
// WriteAt returns a non-nil Error when n != len(b).
func (file *File) WriteAt(b []byte, off int64) (n int, err Error) {
	if file == nil {
		return 0, EINVAL
	}
	for len(b) > 0 {
		m, e := syscall.Pwrite(file.fd, b, off)
		if e != 0 {
			err = &PathError{"write", file.name, Errno(e)}
			break
		}
		n += m
		b = b[m:]
		off += int64(m)
	}
	return
}
开发者ID:lougxing,项目名称:golang-china,代码行数:19,代码来源:file.go

示例6: pwrite

// pwrite writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an error, if any.
// Since Plan 9 preserves message boundaries, never allow
// a zero-byte write.
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
	if len(b) == 0 {
		return 0, nil
	}
	return syscall.Pwrite(f.fd, b, off)
}
开发者ID:kostyll,项目名称:gccpy,代码行数:10,代码来源:file_plan9.go

示例7: pwrite

// pwrite writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an error, if any.
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
	if needsMaxRW && len(b) > maxRW {
		b = b[:maxRW]
	}
	return fixCount(syscall.Pwrite(f.fd, b, off))
}
开发者ID:kuangchanglang,项目名称:go,代码行数:8,代码来源:file_unix.go

示例8: pwrite

// pwrite writes len(b) bytes to the File starting at byte offset off.
// It returns the number of bytes written and an error, if any.
func (f *File) pwrite(b []byte, off int64) (n int, err error) {
	return syscall.Pwrite(f.fd, b, off)
}
开发者ID:gnanderson,项目名称:go,代码行数:5,代码来源:file_unix.go

示例9: Write

func (s *SyncFile) Write(buf []byte, off int64) (n int, err error) {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	return syscall.Pwrite(int(s.fp.Fd()), buf, off)
}
开发者ID:lovefcaaa,项目名称:split,代码行数:5,代码来源:syncio.go


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