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: Yuan Can <yuancan@huawei.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
This commit is contained in:
Yuan Can 2022-09-24 06:32:04 +00:00 committed by Konstantin Komarov
parent 887bfc5460
commit d45da67cae
No known key found for this signature in database
GPG Key ID: A9B0331F832407B6
1 changed files with 14 additions and 30 deletions

View File

@ -781,11 +781,9 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
{
int err;
struct ntfs_inode *ni = ntfs_i(inode);
size_t name_len = strlen(name);
/* Dispatch request. */
if (name_len == sizeof(SYSTEM_DOS_ATTRIB) - 1 &&
!memcmp(name, SYSTEM_DOS_ATTRIB, sizeof(SYSTEM_DOS_ATTRIB))) {
if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
/* system.dos_attrib */
if (!buffer) {
err = sizeof(u8);
@ -798,8 +796,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
goto out;
}
if (name_len == sizeof(SYSTEM_NTFS_ATTRIB) - 1 &&
!memcmp(name, SYSTEM_NTFS_ATTRIB, sizeof(SYSTEM_NTFS_ATTRIB))) {
if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
/* system.ntfs_attrib */
if (!buffer) {
err = sizeof(u32);
@ -812,8 +809,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
goto out;
}
if (name_len == sizeof(SYSTEM_NTFS_SECURITY) - 1 &&
!memcmp(name, SYSTEM_NTFS_SECURITY, sizeof(SYSTEM_NTFS_SECURITY))) {
if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
/* system.ntfs_security*/
struct SECURITY_DESCRIPTOR_RELATIVE *sd = NULL;
size_t sd_size = 0;
@ -853,16 +849,12 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
}
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
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)))) {
if (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
!strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT)) {
/* TODO: init_user_ns? */
err = ntfs_xattr_get_acl(
&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_DEFAULT,
buffer, size);
@ -870,7 +862,7 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
}
#endif
/* 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:
return err;
@ -887,20 +879,17 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
{
int err = -EINVAL;
struct ntfs_inode *ni = ntfs_i(inode);
size_t name_len = strlen(name);
enum FILE_ATTRIBUTE new_fa;
/* Dispatch request. */
if (name_len == sizeof(SYSTEM_DOS_ATTRIB) - 1 &&
!memcmp(name, SYSTEM_DOS_ATTRIB, sizeof(SYSTEM_DOS_ATTRIB))) {
if (!strcmp(name, SYSTEM_DOS_ATTRIB)) {
if (sizeof(u8) != size)
goto out;
new_fa = cpu_to_le32(*(u8 *)value);
goto set_new_fa;
}
if (name_len == sizeof(SYSTEM_NTFS_ATTRIB) - 1 &&
!memcmp(name, SYSTEM_NTFS_ATTRIB, sizeof(SYSTEM_NTFS_ATTRIB))) {
if (!strcmp(name, SYSTEM_NTFS_ATTRIB)) {
if (size != sizeof(u32))
goto out;
new_fa = cpu_to_le32(*(u32 *)value);
@ -938,8 +927,7 @@ set_new_fa:
goto out;
}
if (name_len == sizeof(SYSTEM_NTFS_SECURITY) - 1 &&
!memcmp(name, SYSTEM_NTFS_SECURITY, sizeof(SYSTEM_NTFS_SECURITY))) {
if (!strcmp(name, SYSTEM_NTFS_SECURITY)) {
/* system.ntfs_security*/
__le32 security_id;
bool inserted;
@ -982,15 +970,11 @@ set_new_fa:
}
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
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)))) {
if (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
!strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT)) {
err = ntfs_xattr_set_acl(
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_DEFAULT,
value, size);
@ -998,7 +982,7 @@ set_new_fa:
}
#endif
/* 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:
inode->i_ctime = current_time(inode);