vfs:glusterfs_fuse: treat ENOATTR as ENOENT
[samba.git] / source3 / modules / vfs_glusterfs_fuse.c
1 /*
2    Unix SMB/CIFS implementation.
3
4    Copyright (c) 2019 Guenther Deschner <gd@samba.org>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "smbd/smbd.h"
22 #include "system/filesys.h"
23
24 #define GLUSTER_NAME_MAX 255
25
26 static int vfs_gluster_fuse_get_real_filename(struct vfs_handle_struct *handle,
27                                               const char *path,
28                                               const char *name,
29                                               TALLOC_CTX *mem_ctx,
30                                               char **_found_name)
31 {
32         int ret;
33         char key_buf[GLUSTER_NAME_MAX + 64];
34         char val_buf[GLUSTER_NAME_MAX + 1];
35         char *found_name = NULL;
36
37         if (strlen(name) >= GLUSTER_NAME_MAX) {
38                 errno = ENAMETOOLONG;
39                 return -1;
40         }
41
42         snprintf(key_buf, GLUSTER_NAME_MAX + 64,
43                  "glusterfs.get_real_filename:%s", name);
44
45         ret = getxattr(path, key_buf, val_buf, GLUSTER_NAME_MAX + 1);
46         if (ret == -1) {
47                 if (errno == ENOATTR) {
48                         errno = ENOENT;
49                 }
50                 return -1;
51         }
52
53         found_name = talloc_strdup(mem_ctx, val_buf);
54         if (found_name == NULL) {
55                 errno = ENOMEM;
56                 return -1;
57         }
58         *_found_name = found_name;
59         return 0;
60 }
61
62 struct vfs_fn_pointers glusterfs_fuse_fns = {
63
64         /* File Operations */
65         .get_real_filename_fn = vfs_gluster_fuse_get_real_filename,
66 };
67
68 static_decl_vfs;
69 NTSTATUS vfs_glusterfs_fuse_init(TALLOC_CTX *ctx)
70 {
71         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
72                                 "glusterfs_fuse", &glusterfs_fuse_fns);
73 }