2 * Store streams in xattrs
4 * Copyright (C) Volker Lendecke, 2008
6 * Partly based on James Peach's Darwin module, which is
8 * Copyright (C) James Peach 2006-2007
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #define DBGC_CLASS DBGC_VFS
34 vfs_handle_struct *handle;
37 static SMB_INO_T stream_inode(const SMB_STRUCT_STAT *sbuf, const char *sname)
39 struct MD5Context ctx;
40 unsigned char hash[16];
44 DEBUG(10, ("stream_inode called for %lu/%lu [%s]\n",
45 (unsigned long)sbuf->st_ex_dev,
46 (unsigned long)sbuf->st_ex_ino, sname));
48 upper_sname = talloc_strdup_upper(talloc_tos(), sname);
49 SMB_ASSERT(upper_sname != NULL);
52 MD5Update(&ctx, (unsigned char *)&(sbuf->st_ex_dev),
53 sizeof(sbuf->st_ex_dev));
54 MD5Update(&ctx, (unsigned char *)&(sbuf->st_ex_ino),
55 sizeof(sbuf->st_ex_ino));
56 MD5Update(&ctx, (unsigned char *)upper_sname,
57 talloc_get_size(upper_sname)-1);
60 TALLOC_FREE(upper_sname);
62 /* Hopefully all the variation is in the lower 4 (or 8) bytes! */
63 memcpy(&result, hash, sizeof(result));
65 DEBUG(10, ("stream_inode returns %lu\n", (unsigned long)result));
70 static ssize_t get_xattr_size(connection_struct *conn,
73 const char *xattr_name)
79 status = get_ea_value(talloc_tos(), conn, fsp, fname,
82 if (!NT_STATUS_IS_OK(status)) {
86 result = ea.value.length-1;
87 TALLOC_FREE(ea.value.data);
92 * Given a stream name, populate xattr_name with the xattr name to use for
93 * accessing the stream.
95 static NTSTATUS streams_xattr_get_name(TALLOC_CTX *ctx,
96 const char *stream_name,
101 stype = strchr_m(stream_name + 1, ':');
103 *xattr_name = talloc_asprintf(ctx, "%s%s",
104 SAMBA_XATTR_DOSSTREAM_PREFIX,
106 if (*xattr_name == NULL) {
107 return NT_STATUS_NO_MEMORY;
111 /* Append an explicit stream type if one wasn't specified. */
112 *xattr_name = talloc_asprintf(ctx, "%s:$DATA",
114 if (*xattr_name == NULL) {
115 return NT_STATUS_NO_MEMORY;
118 /* Normalize the stream type to upercase. */
119 strupper_m(strrchr_m(*xattr_name, ':') + 1);
122 DEBUG(10, ("xattr_name: %s, stream_name: %s\n", *xattr_name,
128 static bool streams_xattr_recheck(struct stream_io *sio)
133 char *xattr_name = NULL;
135 if (sio->fsp->fsp_name == sio->fsp_name_ptr) {
139 status = split_ntfs_stream_name(talloc_tos(), sio->fsp->fsp_name,
141 if (!NT_STATUS_IS_OK(status)) {
146 /* how can this happen */
151 xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
152 SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
153 if (xattr_name == NULL) {
157 TALLOC_FREE(sio->xattr_name);
158 TALLOC_FREE(sio->base);
159 sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
161 sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
163 sio->fsp_name_ptr = sio->fsp->fsp_name;
165 if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
173 * Helper to stat/lstat the base file of an smb_fname.
175 static int streams_xattr_stat_base(vfs_handle_struct *handle,
176 struct smb_filename *smb_fname,
179 char *tmp_stream_name;
182 tmp_stream_name = smb_fname->stream_name;
183 smb_fname->stream_name = NULL;
185 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
187 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
189 smb_fname->stream_name = tmp_stream_name;
193 static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
194 SMB_STRUCT_STAT *sbuf)
196 struct smb_filename *smb_fname_base = NULL;
199 struct stream_io *io = (struct stream_io *)
200 VFS_FETCH_FSP_EXTENSION(handle, fsp);
202 DEBUG(10, ("streams_xattr_fstat called for %d\n", fsp->fh->fd));
204 if (io == NULL || fsp->base_fsp == NULL) {
205 return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
208 if (!streams_xattr_recheck(io)) {
212 /* Create an smb_filename with stream_name == NULL. */
213 status = create_synthetic_smb_fname(talloc_tos(),
217 if (!NT_STATUS_IS_OK(status)) {
218 errno = map_errno_from_nt_status(status);
222 if (lp_posix_pathnames()) {
223 ret = SMB_VFS_LSTAT(handle->conn, smb_fname_base);
225 ret = SMB_VFS_STAT(handle->conn, smb_fname_base);
227 *sbuf = smb_fname_base->st;
228 TALLOC_FREE(smb_fname_base);
234 sbuf->st_ex_size = get_xattr_size(handle->conn, fsp->base_fsp,
235 io->base, io->xattr_name);
236 if (sbuf->st_ex_size == -1) {
240 DEBUG(10, ("sbuf->st_ex_size = %d\n", (int)sbuf->st_ex_size));
242 sbuf->st_ex_ino = stream_inode(sbuf, io->xattr_name);
243 sbuf->st_ex_mode &= ~S_IFMT;
244 sbuf->st_ex_mode |= S_IFREG;
245 sbuf->st_ex_blocks = sbuf->st_ex_size % STAT_ST_BLOCKSIZE + 1;
250 static int streams_xattr_stat(vfs_handle_struct *handle,
251 struct smb_filename *smb_fname)
255 char *xattr_name = NULL;
257 if (!is_ntfs_stream_smb_fname(smb_fname)) {
258 return SMB_VFS_NEXT_STAT(handle, smb_fname);
261 /* If the default stream is requested, just stat the base file. */
262 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
263 return streams_xattr_stat_base(handle, smb_fname, true);
266 /* Populate the stat struct with info from the base file. */
267 if (streams_xattr_stat_base(handle, smb_fname, true) == -1) {
271 /* Derive the xattr name to lookup. */
272 status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
274 if (!NT_STATUS_IS_OK(status)) {
275 errno = map_errno_from_nt_status(status);
279 /* Augment the base file's stat information before returning. */
280 smb_fname->st.st_ex_size = get_xattr_size(handle->conn, NULL,
281 smb_fname->base_name,
283 if (smb_fname->st.st_ex_size == -1) {
289 smb_fname->st.st_ex_ino = stream_inode(&smb_fname->st, xattr_name);
290 smb_fname->st.st_ex_mode &= ~S_IFMT;
291 smb_fname->st.st_ex_mode |= S_IFREG;
292 smb_fname->st.st_ex_blocks =
293 smb_fname->st.st_ex_size % STAT_ST_BLOCKSIZE + 1;
297 TALLOC_FREE(xattr_name);
301 static int streams_xattr_lstat(vfs_handle_struct *handle,
302 struct smb_filename *smb_fname)
306 char *xattr_name = NULL;
308 if (!is_ntfs_stream_smb_fname(smb_fname)) {
309 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
312 /* If the default stream is requested, just stat the base file. */
313 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
314 return streams_xattr_stat_base(handle, smb_fname, false);
317 /* Populate the stat struct with info from the base file. */
318 if (streams_xattr_stat_base(handle, smb_fname, false) == -1) {
322 /* Derive the xattr name to lookup. */
323 status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
325 if (!NT_STATUS_IS_OK(status)) {
326 errno = map_errno_from_nt_status(status);
330 /* Augment the base file's stat information before returning. */
331 smb_fname->st.st_ex_size = get_xattr_size(handle->conn, NULL,
332 smb_fname->base_name,
334 if (smb_fname->st.st_ex_size == -1) {
340 smb_fname->st.st_ex_ino = stream_inode(&smb_fname->st, xattr_name);
341 smb_fname->st.st_ex_mode &= ~S_IFMT;
342 smb_fname->st.st_ex_mode |= S_IFREG;
343 smb_fname->st.st_ex_blocks =
344 smb_fname->st.st_ex_size % STAT_ST_BLOCKSIZE + 1;
349 TALLOC_FREE(xattr_name);
353 static int streams_xattr_open(vfs_handle_struct *handle,
354 struct smb_filename *smb_fname,
355 files_struct *fsp, int flags, mode_t mode)
358 struct smb_filename *smb_fname_base = NULL;
359 struct stream_io *sio;
361 char *xattr_name = NULL;
365 DEBUG(10, ("streams_xattr_open called for %s\n",
366 smb_fname_str_dbg(smb_fname)));
368 if (!is_ntfs_stream_smb_fname(smb_fname)) {
369 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
372 /* If the default stream is requested, just open the base file. */
373 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
374 char *tmp_stream_name;
377 tmp_stream_name = smb_fname->stream_name;
378 smb_fname->stream_name = NULL;
380 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
382 smb_fname->stream_name = tmp_stream_name;
387 status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
389 if (!NT_STATUS_IS_OK(status)) {
390 errno = map_errno_from_nt_status(status);
394 /* Create an smb_filename with stream_name == NULL. */
395 status = create_synthetic_smb_fname(talloc_tos(),
396 smb_fname->base_name,
399 if (!NT_STATUS_IS_OK(status)) {
400 errno = map_errno_from_nt_status(status);
405 * We use baseflags to turn off nasty side-effects when opening the
409 baseflags &= ~O_TRUNC;
410 baseflags &= ~O_EXCL;
411 baseflags &= ~O_CREAT;
413 hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
416 TALLOC_FREE(smb_fname_base);
418 /* It is legit to open a stream on a directory, but the base
419 * fd has to be read-only.
421 if ((hostfd == -1) && (errno == EISDIR)) {
422 baseflags &= ~O_ACCMODE;
423 baseflags |= O_RDONLY;
424 hostfd = SMB_VFS_OPEN(handle->conn, smb_fname, fsp, baseflags,
432 status = get_ea_value(talloc_tos(), handle->conn, NULL,
433 smb_fname->base_name, xattr_name, &ea);
435 DEBUG(10, ("get_ea_value returned %s\n", nt_errstr(status)));
437 if (!NT_STATUS_IS_OK(status)
438 && !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
440 * The base file is not there. This is an error even if we got
441 * O_CREAT, the higher levels should have created the base
444 DEBUG(10, ("streams_xattr_open: base file %s not around, "
445 "returning ENOENT\n", smb_fname->base_name));
450 if (!NT_STATUS_IS_OK(status)) {
452 * The attribute does not exist
455 if (flags & O_CREAT) {
457 * Darn, xattrs need at least 1 byte
461 DEBUG(10, ("creating attribute %s on file %s\n",
462 xattr_name, smb_fname->base_name));
464 if (fsp->base_fsp->fh->fd != -1) {
465 if (SMB_VFS_FSETXATTR(
466 fsp->base_fsp, xattr_name,
468 flags & O_EXCL ? XATTR_CREATE : 0) == -1) {
472 if (SMB_VFS_SETXATTR(
473 handle->conn, smb_fname->base_name,
474 xattr_name, &null, sizeof(null),
475 flags & O_EXCL ? XATTR_CREATE : 0) == -1) {
482 if (flags & O_TRUNC) {
484 if (fsp->base_fsp->fh->fd != -1) {
485 if (SMB_VFS_FSETXATTR(
486 fsp->base_fsp, xattr_name,
488 flags & O_EXCL ? XATTR_CREATE : 0) == -1) {
492 if (SMB_VFS_SETXATTR(
493 handle->conn, smb_fname->base_name,
494 xattr_name, &null, sizeof(null),
495 flags & O_EXCL ? XATTR_CREATE : 0) == -1) {
501 sio = (struct stream_io *)VFS_ADD_FSP_EXTENSION(handle, fsp,
509 sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
511 sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
512 smb_fname->base_name);
513 sio->fsp_name_ptr = fsp->fsp_name;
514 sio->handle = handle;
517 if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
527 * BUGBUGBUG -- we would need to call fd_close_posix here, but
528 * we don't have a full fsp yet
536 static int streams_xattr_unlink(vfs_handle_struct *handle, const char *fname)
544 if (!is_ntfs_stream_name(fname)) {
545 return SMB_VFS_NEXT_UNLINK(handle, fname);
548 status = split_ntfs_stream_name(talloc_tos(), fname, &base, &sname);
549 if (!NT_STATUS_IS_OK(status)) {
555 return SMB_VFS_NEXT_UNLINK(handle, base);
558 xattr_name = talloc_asprintf(talloc_tos(), "%s%s",
559 SAMBA_XATTR_DOSSTREAM_PREFIX, sname);
560 if (xattr_name == NULL) {
565 ret = SMB_VFS_REMOVEXATTR(handle->conn, base, xattr_name);
567 if ((ret == -1) && (errno == ENOATTR)) {
580 static int streams_xattr_rename(vfs_handle_struct *handle,
581 const struct smb_filename *smb_fname_src,
582 const struct smb_filename *smb_fname_dst)
586 char *src_xattr_name = NULL;
587 char *dst_xattr_name = NULL;
588 bool src_is_stream, dst_is_stream;
593 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
594 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
596 if (!src_is_stream && !dst_is_stream) {
597 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
601 /* For now don't allow renames from or to the default stream. */
602 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
603 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
608 /* Don't rename if the streams are identical. */
609 if (StrCaseCmp(smb_fname_src->stream_name,
610 smb_fname_dst->stream_name) == 0) {
614 /* Get the xattr names. */
615 status = streams_xattr_get_name(talloc_tos(),
616 smb_fname_src->stream_name,
618 if (!NT_STATUS_IS_OK(status)) {
619 errno = map_errno_from_nt_status(status);
622 status = streams_xattr_get_name(talloc_tos(),
623 smb_fname_dst->stream_name,
625 if (!NT_STATUS_IS_OK(status)) {
626 errno = map_errno_from_nt_status(status);
630 /* read the old stream */
631 status = get_ea_value(talloc_tos(), handle->conn, NULL,
632 smb_fname_src->base_name, src_xattr_name, &ea);
633 if (!NT_STATUS_IS_OK(status)) {
638 /* (over)write the new stream */
639 nret = SMB_VFS_SETXATTR(handle->conn, smb_fname_src->base_name,
640 dst_xattr_name, ea.value.data, ea.value.length,
643 if (errno == ENOATTR) {
649 /* remove the old stream */
650 oret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname_src->base_name,
653 if (errno == ENOATTR) {
663 TALLOC_FREE(src_xattr_name);
664 TALLOC_FREE(dst_xattr_name);
668 static NTSTATUS walk_xattr_streams(connection_struct *conn, files_struct *fsp,
670 bool (*fn)(struct ea_struct *ea,
677 size_t prefix_len = strlen(SAMBA_XATTR_DOSSTREAM_PREFIX);
679 status = get_ea_names_from_file(talloc_tos(), conn, fsp, fname,
681 if (!NT_STATUS_IS_OK(status)) {
685 for (i=0; i<num_names; i++) {
688 if (strncmp(names[i], SAMBA_XATTR_DOSSTREAM_PREFIX,
693 status = get_ea_value(names, conn, fsp, fname, names[i], &ea);
694 if (!NT_STATUS_IS_OK(status)) {
695 DEBUG(10, ("Could not get ea %s for file %s: %s\n",
696 names[i], fname, nt_errstr(status)));
700 ea.name = talloc_asprintf(ea.value.data, ":%s",
701 names[i] + prefix_len);
702 if (ea.name == NULL) {
703 DEBUG(0, ("talloc failed\n"));
707 if (!fn(&ea, private_data)) {
708 TALLOC_FREE(ea.value.data);
712 TALLOC_FREE(ea.value.data);
719 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
720 struct stream_struct **streams,
721 const char *name, SMB_OFF_T size,
722 SMB_OFF_T alloc_size)
724 struct stream_struct *tmp;
726 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, *streams, struct stream_struct,
732 tmp[*num_streams].name = talloc_strdup(tmp, name);
733 if (tmp[*num_streams].name == NULL) {
737 tmp[*num_streams].size = size;
738 tmp[*num_streams].alloc_size = alloc_size;
745 struct streaminfo_state {
747 vfs_handle_struct *handle;
748 unsigned int num_streams;
749 struct stream_struct *streams;
753 static bool collect_one_stream(struct ea_struct *ea, void *private_data)
755 struct streaminfo_state *state =
756 (struct streaminfo_state *)private_data;
758 if (!add_one_stream(state->mem_ctx,
759 &state->num_streams, &state->streams,
760 ea->name, ea->value.length-1,
761 smb_roundup(state->handle->conn,
762 ea->value.length-1))) {
763 state->status = NT_STATUS_NO_MEMORY;
770 static NTSTATUS streams_xattr_streaminfo(vfs_handle_struct *handle,
771 struct files_struct *fsp,
774 unsigned int *pnum_streams,
775 struct stream_struct **pstreams)
777 SMB_STRUCT_STAT sbuf;
780 struct streaminfo_state state;
782 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
783 if (is_ntfs_stream_name(fsp->fsp_name)) {
784 return NT_STATUS_INVALID_PARAMETER;
786 ret = SMB_VFS_FSTAT(fsp, &sbuf);
789 if (is_ntfs_stream_name(fname)) {
790 return NT_STATUS_INVALID_PARAMETER;
792 if (lp_posix_pathnames()) {
793 ret = vfs_lstat_smb_fname(handle->conn, fname, &sbuf);
795 ret = vfs_stat_smb_fname(handle->conn, fname, &sbuf);
800 return map_nt_error_from_unix(errno);
803 state.streams = NULL;
804 state.num_streams = 0;
806 if (!S_ISDIR(sbuf.st_ex_mode)) {
807 if (!add_one_stream(mem_ctx,
808 &state.num_streams, &state.streams,
809 "::$DATA", sbuf.st_ex_size,
810 SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp,
812 return NT_STATUS_NO_MEMORY;
816 state.mem_ctx = mem_ctx;
817 state.handle = handle;
818 state.status = NT_STATUS_OK;
820 status = walk_xattr_streams(handle->conn, fsp, fname,
821 collect_one_stream, &state);
823 if (!NT_STATUS_IS_OK(status)) {
824 TALLOC_FREE(state.streams);
828 if (!NT_STATUS_IS_OK(state.status)) {
829 TALLOC_FREE(state.streams);
833 *pnum_streams = state.num_streams;
834 *pstreams = state.streams;
838 static uint32_t streams_xattr_fs_capabilities(struct vfs_handle_struct *handle)
840 return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
843 static ssize_t streams_xattr_pwrite(vfs_handle_struct *handle,
844 files_struct *fsp, const void *data,
845 size_t n, SMB_OFF_T offset)
847 struct stream_io *sio =
848 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
853 DEBUG(10, ("streams_xattr_pwrite called for %d bytes\n", (int)n));
856 return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
859 if (!streams_xattr_recheck(sio)) {
863 status = get_ea_value(talloc_tos(), handle->conn, fsp->base_fsp,
864 sio->base, sio->xattr_name, &ea);
865 if (!NT_STATUS_IS_OK(status)) {
869 if ((offset + n) > ea.value.length-1) {
872 tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), ea.value.data, uint8,
876 TALLOC_FREE(ea.value.data);
881 ea.value.length = offset + n + 1;
882 ea.value.data[offset+n] = 0;
885 memcpy(ea.value.data + offset, data, n);
887 if (fsp->base_fsp->fh->fd != -1) {
888 ret = SMB_VFS_FSETXATTR(fsp->base_fsp,
890 ea.value.data, ea.value.length, 0);
892 ret = SMB_VFS_SETXATTR(fsp->conn, fsp->base_fsp->fsp_name,
894 ea.value.data, ea.value.length, 0);
896 TALLOC_FREE(ea.value.data);
905 static ssize_t streams_xattr_pread(vfs_handle_struct *handle,
906 files_struct *fsp, void *data,
907 size_t n, SMB_OFF_T offset)
909 struct stream_io *sio =
910 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
913 size_t length, overlap;
916 return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
919 if (!streams_xattr_recheck(sio)) {
923 status = get_ea_value(talloc_tos(), handle->conn, fsp->base_fsp,
924 sio->base, sio->xattr_name, &ea);
925 if (!NT_STATUS_IS_OK(status)) {
929 length = ea.value.length-1;
931 /* Attempt to read past EOF. */
932 if (length <= offset) {
937 overlap = (offset + n) > length ? (length - offset) : n;
938 memcpy(data, ea.value.data + offset, overlap);
940 TALLOC_FREE(ea.value.data);
944 static int streams_xattr_ftruncate(struct vfs_handle_struct *handle,
945 struct files_struct *fsp,
952 struct stream_io *sio =
953 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
955 DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
960 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
963 if (!streams_xattr_recheck(sio)) {
967 status = get_ea_value(talloc_tos(), handle->conn, fsp->base_fsp,
968 sio->base, sio->xattr_name, &ea);
969 if (!NT_STATUS_IS_OK(status)) {
973 tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), ea.value.data, uint8,
977 TALLOC_FREE(ea.value.data);
982 /* Did we expand ? */
983 if (ea.value.length < offset + 1) {
984 memset(&tmp[ea.value.length], '\0',
985 offset + 1 - ea.value.length);
989 ea.value.length = offset + 1;
990 ea.value.data[offset] = 0;
992 if (fsp->base_fsp->fh->fd != -1) {
993 ret = SMB_VFS_FSETXATTR(fsp->base_fsp,
995 ea.value.data, ea.value.length, 0);
997 ret = SMB_VFS_SETXATTR(fsp->conn, fsp->base_fsp->fsp_name,
999 ea.value.data, ea.value.length, 0);
1002 TALLOC_FREE(ea.value.data);
1011 /* VFS operations structure */
1013 static vfs_op_tuple streams_xattr_ops[] = {
1014 {SMB_VFS_OP(streams_xattr_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
1015 SMB_VFS_LAYER_TRANSPARENT},
1016 {SMB_VFS_OP(streams_xattr_open), SMB_VFS_OP_OPEN,
1017 SMB_VFS_LAYER_TRANSPARENT},
1018 {SMB_VFS_OP(streams_xattr_stat), SMB_VFS_OP_STAT,
1019 SMB_VFS_LAYER_TRANSPARENT},
1020 {SMB_VFS_OP(streams_xattr_fstat), SMB_VFS_OP_FSTAT,
1021 SMB_VFS_LAYER_TRANSPARENT},
1022 {SMB_VFS_OP(streams_xattr_lstat), SMB_VFS_OP_LSTAT,
1023 SMB_VFS_LAYER_TRANSPARENT},
1024 {SMB_VFS_OP(streams_xattr_pread), SMB_VFS_OP_PREAD,
1025 SMB_VFS_LAYER_TRANSPARENT},
1026 {SMB_VFS_OP(streams_xattr_pwrite), SMB_VFS_OP_PWRITE,
1027 SMB_VFS_LAYER_TRANSPARENT},
1028 {SMB_VFS_OP(streams_xattr_unlink), SMB_VFS_OP_UNLINK,
1029 SMB_VFS_LAYER_TRANSPARENT},
1030 {SMB_VFS_OP(streams_xattr_rename), SMB_VFS_OP_RENAME,
1031 SMB_VFS_LAYER_TRANSPARENT},
1032 {SMB_VFS_OP(streams_xattr_ftruncate), SMB_VFS_OP_FTRUNCATE,
1033 SMB_VFS_LAYER_TRANSPARENT},
1034 {SMB_VFS_OP(streams_xattr_streaminfo), SMB_VFS_OP_STREAMINFO,
1035 SMB_VFS_LAYER_OPAQUE},
1036 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
1039 NTSTATUS vfs_streams_xattr_init(void);
1040 NTSTATUS vfs_streams_xattr_init(void)
1042 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_xattr",