def fgetxattr(self, key, size=0):
"""
Retrieve the value of the extended attribute identified by key
for the file.
:param key: Key of extended attribute
:param size: If size is specified as zero, we first determine the
size of xattr and then allocate a buffer accordingly.
If size is non-zero, it is assumed the caller knows
the size of xattr.
:returns: Value of extended attribute corresponding to key specified.
"""
if size == 0:
size = api.glfs_fgetxattr(self.fd, key, None, size)
if size < 0:
err = ctypes.get_errno()
raise OSError(err, os.strerror(err))
buf = ctypes.create_string_buffer(size)
rc = api.glfs_fgetxattr(self.fd, key, buf, size)
if rc < 0:
err = ctypes.get_errno()
raise OSError(err, os.strerror(err))
return buf.value[:rc]
评论列表
文章目录