Commit d45da67c authored by Yuan Can's avatar Yuan Can Committed by Konstantin Komarov

fs/ntfs3: Use strcmp to determine attribute type

The way of determin attribute type is just matching
name with the predefined string, do this with strcmp
to simplify the code.
Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent 887bfc54
...@@ -781,11 +781,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, ...@@ -781,11 +781,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
{ {
int err; int err;
struct ntfs_inode *ni = ntfs_i(inode); struct ntfs_inode *ni = ntfs_i(inode);
size_t name_len = strlen(name);
/* Dispatch request. */ /* Dispatch request. */
if (name_len == sizeof(SYSTEM_DOS_ATTRIB) - 1 && if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
!memcmp(name, SYSTEM_DOS_ATTRIB, sizeof(SYSTEM_DOS_ATTRIB))) {
/* system.dos_attrib */ /* system.dos_attrib */
if (!buffer) { if (!buffer) {
err = sizeof(u8); err = sizeof(u8);
...@@ -798,8 +796,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, ...@@ -798,8 +796,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
goto out; goto out;
} }
if (name_len == sizeof(SYSTEM_NTFS_ATTRIB) - 1 && if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
!memcmp(name, SYSTEM_NTFS_ATTRIB, sizeof(SYSTEM_NTFS_ATTRIB))) {
/* system.ntfs_attrib */ /* system.ntfs_attrib */
if (!buffer) { if (!buffer) {
err = sizeof(u32); err = sizeof(u32);
...@@ -812,8 +809,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, ...@@ -812,8 +809,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
goto out; goto out;
} }
if (name_len == sizeof(SYSTEM_NTFS_SECURITY) - 1 && if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
!memcmp(name, SYSTEM_NTFS_SECURITY, sizeof(SYSTEM_NTFS_SECURITY))) {
/* system.ntfs_security*/ /* system.ntfs_security*/
struct SECURITY_DESCRIPTOR_RELATIVE *sd = NULL; struct SECURITY_DESCRIPTOR_RELATIVE *sd = NULL;
size_t sd_size = 0; size_t sd_size = 0;
...@@ -853,16 +849,12 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, ...@@ -853,16 +849,12 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
} }
#ifdef CONFIG_NTFS3_FS_POSIX_ACL #ifdef CONFIG_NTFS3_FS_POSIX_ACL
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 && if (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS, !strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT)) {
sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
(name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
!memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
/* TODO: init_user_ns? */ /* TODO: init_user_ns? */
err = ntfs_xattr_get_acl( err = ntfs_xattr_get_acl(
&init_user_ns, inode, &init_user_ns, inode,
name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 strlen(name) == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
? ACL_TYPE_ACCESS ? ACL_TYPE_ACCESS
: ACL_TYPE_DEFAULT, : ACL_TYPE_DEFAULT,
buffer, size); buffer, size);
...@@ -870,7 +862,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de, ...@@ -870,7 +862,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
} }
#endif #endif
/* Deal with NTFS extended attribute. */ /* Deal with NTFS extended attribute. */
err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL); err = ntfs_get_ea(inode, name, strlen(name), buffer, size, NULL);
out: out:
return err; return err;
...@@ -887,20 +879,17 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, ...@@ -887,20 +879,17 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
{ {
int err = -EINVAL; int err = -EINVAL;
struct ntfs_inode *ni = ntfs_i(inode); struct ntfs_inode *ni = ntfs_i(inode);
size_t name_len = strlen(name);
enum FILE_ATTRIBUTE new_fa; enum FILE_ATTRIBUTE new_fa;
/* Dispatch request. */ /* Dispatch request. */
if (name_len == sizeof(SYSTEM_DOS_ATTRIB) - 1 && if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
!memcmp(name, SYSTEM_DOS_ATTRIB, sizeof(SYSTEM_DOS_ATTRIB))) {
if (sizeof(u8) != size) if (sizeof(u8) != size)
goto out; goto out;
new_fa = cpu_to_le32(*(u8 *)value); new_fa = cpu_to_le32(*(u8 *)value);
goto set_new_fa; goto set_new_fa;
} }
if (name_len == sizeof(SYSTEM_NTFS_ATTRIB) - 1 && if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
!memcmp(name, SYSTEM_NTFS_ATTRIB, sizeof(SYSTEM_NTFS_ATTRIB))) {
if (size != sizeof(u32)) if (size != sizeof(u32))
goto out; goto out;
new_fa = cpu_to_le32(*(u32 *)value); new_fa = cpu_to_le32(*(u32 *)value);
...@@ -938,8 +927,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, ...@@ -938,8 +927,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
goto out; goto out;
} }
if (name_len == sizeof(SYSTEM_NTFS_SECURITY) - 1 && if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
!memcmp(name, SYSTEM_NTFS_SECURITY, sizeof(SYSTEM_NTFS_SECURITY))) {
/* system.ntfs_security*/ /* system.ntfs_security*/
__le32 security_id; __le32 security_id;
bool inserted; bool inserted;
...@@ -982,15 +970,11 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, ...@@ -982,15 +970,11 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
} }
#ifdef CONFIG_NTFS3_FS_POSIX_ACL #ifdef CONFIG_NTFS3_FS_POSIX_ACL
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 && if (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS, !strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT)) {
sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
(name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
!memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
err = ntfs_xattr_set_acl( err = ntfs_xattr_set_acl(
mnt_userns, inode, mnt_userns, inode,
name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 strlen(name) == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
? ACL_TYPE_ACCESS ? ACL_TYPE_ACCESS
: ACL_TYPE_DEFAULT, : ACL_TYPE_DEFAULT,
value, size); value, size);
...@@ -998,7 +982,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler, ...@@ -998,7 +982,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
} }
#endif #endif
/* Deal with NTFS extended attribute. */ /* Deal with NTFS extended attribute. */
err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0); err = ntfs_set_ea(inode, name, strlen(name), value, size, flags, 0);
out: out:
inode->i_ctime = current_time(inode); inode->i_ctime = current_time(inode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment