2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - xattr support using filesystem xattrs
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "system/filesys.h"
25 #include "vfs_posix.h"
28 pull a xattr as a blob, from either a file or a file descriptor
30 NTSTATUS pull_xattr_blob_system(struct pvfs_state *pvfs,
32 const char *attr_name,
35 size_t estimated_size,
38 #if HAVE_XATTR_SUPPORT
41 *blob = data_blob_talloc(mem_ctx, NULL, estimated_size);
42 if (blob->data == NULL) {
43 return NT_STATUS_NO_MEMORY;
48 ret = fgetxattr(fd, attr_name, blob->data, estimated_size);
50 ret = getxattr(fname, attr_name, blob->data, estimated_size);
52 if (ret == -1 && errno == ERANGE) {
54 blob->data = talloc_realloc(mem_ctx, blob->data, estimated_size);
55 if (blob->data == NULL) {
56 return NT_STATUS_NO_MEMORY;
58 blob->length = estimated_size;
64 return pvfs_map_errno(pvfs, errno);
71 return NT_STATUS_NOT_SUPPORTED;
76 push a xattr as a blob, from either a file or a file descriptor
78 NTSTATUS push_xattr_blob_system(struct pvfs_state *pvfs,
79 const char *attr_name,
82 const DATA_BLOB *blob)
84 #if HAVE_XATTR_SUPPORT
88 ret = fsetxattr(fd, attr_name, blob->data, blob->length, 0);
90 ret = setxattr(fname, attr_name, blob->data, blob->length, 0);
93 return pvfs_map_errno(pvfs, errno);
98 return NT_STATUS_NOT_SUPPORTED;
106 NTSTATUS delete_xattr_system(struct pvfs_state *pvfs, const char *attr_name,
107 const char *fname, int fd)
109 #if HAVE_XATTR_SUPPORT
113 ret = fremovexattr(fd, attr_name);
115 ret = removexattr(fname, attr_name);
118 return pvfs_map_errno(pvfs, errno);
123 return NT_STATUS_NOT_SUPPORTED;
128 unlink a file - cleanup any xattrs
130 NTSTATUS unlink_xattr_system(struct pvfs_state *pvfs, const char *fname)
132 /* nothing needs to be done for filesystem based xattrs */