Ejemplo n.º 1
0
// Write writes len(data) bytes to the object with key oid starting at byte
// offset offset. It returns an error, if any.
func (ioctx *IOContext) Write(oid string, data []byte, offset uint64) error {
	c_oid := C.CString(oid)
	defer C.free(unsafe.Pointer(c_oid))

	ret := C.rados_write(ioctx.ioctx, c_oid,
		(*C.char)(unsafe.Pointer(&data[0])),
		(C.size_t)(len(data)),
		(C.uint64_t)(offset))

	return GetRadosError(ret)
}
Ejemplo n.º 2
0
// Write writes the data at a specific offset to the object.
func (o *Object) Write(data io.Reader, offset uint64) error {
	oid := C.CString(o.name)
	defer freeString(oid)
	bufAddr, length := readerToBuf(data)
	ret := C.rados_write(o.ioContext, oid, bufAddr, length, C.uint64_t(offset))
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to write data to object %s", o.name)
		return err
	}
	return nil
}
Ejemplo n.º 3
0
// Write writes len(data) bytes to the object with key oid starting at byte
// offset offset. It returns an error, if any.
func (p *Pool) Write(oid string, data []byte, offset uint64) error {
	c_oid := C.CString(oid)
	defer C.free(unsafe.Pointer(c_oid))

	ret := C.rados_write(p.ioctx, c_oid,
		(*C.char)(unsafe.Pointer(&data[0])),
		(C.size_t)(len(data)),
		(C.uint64_t)(offset))

	if ret == 0 {
		return nil
	} else {
		return RadosError(int(ret))
	}
}
Ejemplo n.º 4
0
func (r *RadosIoCtx) Write(oid string, bin []byte, offset uint64) error {
	coid := C.CString(oid)
	defer func() {
		C.free(unsafe.Pointer(coid))
	}()

	originLen := len(bin)

	if originLen == 0 {
		bin = []byte{0}
	}

	cerr := C.rados_write(*r.ctx, coid, (*C.char)(unsafe.Pointer(&bin[0])), C.size_t(originLen), C.uint64_t(offset))
	if cerr < 0 {
		return errors.New("write data failed")
	}
	return nil
}
Ejemplo n.º 5
0
// WriteAt writes len(data) bytes to the RADOS object at the byte offset
// off. It returns the number of bytes written and an error, if any.
// Write returns a non-nil error when n < len(data).
func (o *Object) WriteAt(data []byte, off int64) (n int, err error) {
	cname := C.CString(o.name)
	defer C.free(unsafe.Pointer(cname))

	for len(data) > 0 {
		cdata, cdatalen := byteSliceToBuffer(data)
		coff := C.uint64_t(off)

		cerr := C.rados_write(o.c.ctx, cname, cdata, cdatalen, coff)

		if cerr < 0 {
			err = fmt.Errorf("RADOS write %s: %s", o.name, strerror(cerr))
			break
		}

		n += int(cerr)
		data = data[cerr:]
		off += int64(cerr)
	}

	return
}
Ejemplo n.º 6
0
// WriteAt writes len(data) bytes to a RADOS object with a given key at the
// byte offset off. It returns the number of bytes written and an error, if
// any. Write returns a non-nil error when n < len(data).
func (c *Context) WriteAt(key string, data []byte, off int64) (n int, err error) {
	ckey := C.CString(key)
	defer C.free(unsafe.Pointer(ckey))

	for len(data) > 0 {
		cdata, cdatalen := byteSliceToBuffer(data)
		coff := C.uint64_t(off)

		cerr := C.rados_write(c.ctx, ckey, cdata, cdatalen, coff)

		if cerr < 0 {
			err = radosReturnCodeError(cerr)
			break
		}

		n += int(cerr)
		data = data[cerr:]
		off += int64(cerr)
	}

	return
}