Exemple #1
0
func (r *RadosIoCtx) GetXattr(oid, name string) (string, error) {
	var buf [MAX_XATTR_LEN]C.char
	cname := C.CString(name)
	coid := C.CString(oid)
	defer func() {
		C.free(unsafe.Pointer(cname))
		C.free(unsafe.Pointer(coid))
	}()
	cerr := C.rados_getxattr(*r.ctx, coid, cname, &buf[0], MAX_XATTR_LEN)
	if cerr < 0 {
		return "", errors.New("get xattr failed")
	}

	return C.GoString(&buf[0]), nil
}
Exemple #2
0
// Get an xattr for an object identified by its key.
func (c *Context) GetXattr(key, name string) ([]byte, error) {
	ckey := C.CString(key)
	defer C.free(unsafe.Pointer(ckey))
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	buf := (*C.char)(C.malloc(512))
	defer C.free(unsafe.Pointer(buf))

	ret := C.rados_getxattr(c.ctx, ckey, cname, buf, C.size_t(512))
	if ret < 0 {
		return nil, radosReturnCodeError(ret)
	}

	return C.GoBytes(unsafe.Pointer(buf), ret), nil
}
Exemple #3
0
// Attribute returns an extended attribute of the object.
func (o *Object) Attribute(attributeName string) (io.Reader, error) {
	object := C.CString(o.name)
	attribute := C.CString(attributeName)
	defer freeString(object)
	defer freeString(attribute)

	bufLen := 2048
	bufAddr := bufferAddress(bufLen)

	ret := C.rados_getxattr(o.ioContext, object, attribute, bufAddr, C.size_t(bufLen))
	if err := toRadosError(ret); err != nil {
		err.Message = fmt.Sprintf("Unable to get attribute %s of object %s.", attributeName, o.name)
		return nil, err
	}
	attribbuf := bufToReader(bufAddr, ret)
	return attribbuf, nil
}
Exemple #4
0
// GetXattr gets an xattr with key `name`, it returns the length of
// the key read or an error if not successful
func (ioctx *IOContext) GetXattr(object string, name string, data []byte) (int, error) {
	c_object := C.CString(object)
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_object))
	defer C.free(unsafe.Pointer(c_name))

	ret := C.rados_getxattr(
		ioctx.ioctx,
		c_object,
		c_name,
		(*C.char)(unsafe.Pointer(&data[0])),
		(C.size_t)(len(data)))

	if ret >= 0 {
		return int(ret), nil
	} else {
		return 0, GetRadosError(ret)
	}
}