2 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 /************************************************************************/
20 /* PROJECT : exFAT & FAT12/16/32 File System */
22 /* PURPOSE : sdFAT code for supporting xattr(Extended File Attributes) */
24 /*----------------------------------------------------------------------*/
28 /************************************************************************/
30 #include <linux/file.h>
32 #include <linux/xattr.h>
33 #include <linux/dcache.h>
36 #ifndef CONFIG_SDFAT_VIRTUAL_XATTR_SELINUX_LABEL
37 #define CONFIG_SDFAT_VIRTUAL_XATTR_SELINUX_LABEL ("undefined")
40 static const char default_xattr
[] = CONFIG_SDFAT_VIRTUAL_XATTR_SELINUX_LABEL
;
42 static int can_support(const char *name
)
44 if (!name
|| strcmp(name
, "security.selinux"))
49 ssize_t
sdfat_listxattr(struct dentry
*dentry
, char *list
, size_t size
)
55 /*************************************************************************
56 * INNER FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
57 *************************************************************************/
58 static int __sdfat_xattr_check_support(const char *name
)
60 if (can_support(name
))
66 ssize_t
__sdfat_getxattr(const char *name
, void *value
, size_t size
)
68 if (can_support(name
))
71 if ((size
> strlen(default_xattr
)+1) && value
)
72 strcpy(value
, default_xattr
);
74 return strlen(default_xattr
);
78 /*************************************************************************
79 * FUNCTIONS WHICH HAS KERNEL VERSION DEPENDENCY
80 *************************************************************************/
81 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
82 static int sdfat_xattr_get(const struct xattr_handler
*handler
,
83 struct dentry
*dentry
, struct inode
*inode
,
84 const char *name
, void *buffer
, size_t size
)
86 return __sdfat_getxattr(name
, buffer
, size
);
89 static int sdfat_xattr_set(const struct xattr_handler
*handler
,
90 struct dentry
*dentry
, struct inode
*inode
,
91 const char *name
, const void *value
, size_t size
,
94 return __sdfat_xattr_check_support(name
);
97 const struct xattr_handler sdfat_xattr_handler
= {
98 .prefix
= "", /* match anything */
99 .get
= sdfat_xattr_get
,
100 .set
= sdfat_xattr_set
,
103 const struct xattr_handler
*sdfat_xattr_handlers
[] = {
104 &sdfat_xattr_handler
,
108 void setup_sdfat_xattr_handler(struct super_block
*sb
)
110 sb
->s_xattr
= sdfat_xattr_handlers
;
112 #else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) */
113 int sdfat_setxattr(struct dentry
*dentry
, const char *name
, const void *value
, size_t size
, int flags
)
115 return __sdfat_xattr_check_support(name
);
118 ssize_t
sdfat_getxattr(struct dentry
*dentry
, const char *name
, void *value
, size_t size
)
120 return __sdfat_getxattr(name
, value
, size
);
123 int sdfat_removexattr(struct dentry
*dentry
, const char *name
)
125 return __sdfat_xattr_check_support(name
);
128 void setup_sdfat_xattr_handler(struct super_block
*sb
)