Beispiel #1
0
// Getxattr will return the value for the named attribute from a file at path
func Getxattr(path string, name string, options int) ([]byte, error) {
	p := C.CString(path)
	n := C.CString(name)
	defer C.free(unsafe.Pointer(p))
	defer C.free(unsafe.Pointer(n))

	// get size of data for attribute, type _Ctype_ssize_t
	attrsize, err := C.getxattr(p, n, nil, 0, 0, 0)
	if err != nil {
		return nil, err
	}
	size := int(attrsize)

	// get data for attribute
	buf := make([]byte, size)
	x, err := C.getxattr(p, n, unsafe.Pointer(&buf[0]), C.size_t(size), 0, C.int(options))
	if err != nil {
		return nil, err
	}

	return buf[:x], nil
}
Beispiel #2
0
func readdelattr(filepath string) (bool, error) {
	val := C.char(0)
	err := C.getxattr(
		C.CString(filepath),
		C.CString("novm-deleted"),
		unsafe.Pointer(&val),
		C.size_t(1))
	if err != C.ssize_t(1) {
		var stat syscall.Stat_t
		err := syscall.Stat(
			path.Join(filepath, ".deleted"),
			&stat)
		if err != nil {
			return false, err
		}
		return true, nil
	}
	return val == C.char(1), nil
}