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) }
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) }
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) }
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 }
// 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 }
// 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) }
// 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)) }
// 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) }
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) }