From: Baolin Liu <liubaolin12138@163.com>
To: linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
chenxiaosong@chenxiaosong.com, Baolin Liu <liubaolin@kylinos.cn>
Subject: [PATCH v2 05/10] ntfs: distinguish empty EA values from removal
Date: Sun, 20 Sep 2026 16:31:26 +0800 [thread overview]
Message-ID: <20260920083131.1880061-6-liubaolin12138@163.com> (raw)
In-Reply-To: <20260920083131.1880061-1-liubaolin12138@163.com>
From: Baolin Liu <liubaolin@kylinos.cn>
The EA setter identifies removal using a zero value length together
with XATTR_REPLACE. A replacement with a valid empty value is therefore
mistaken for deletion.
Use a NULL value to identify removal and keep zero-length values valid.
Reject removal or XATTR_REPLACE for an absent entry before creating
metadata, including when the file has no EA attributes.
Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
---
fs/ntfs/ea.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/fs/ntfs/ea.c b/fs/ntfs/ea.c
index f5a112495fc9..15bfcdddc7ee 100644
--- a/fs/ntfs/ea.c
+++ b/fs/ntfs/ea.c
@@ -244,6 +244,8 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
if (!err != !ea_err)
return -EUCLEAN;
has_ea = !err;
+ if (!has_ea && (!value || (flags & XATTR_REPLACE)))
+ return -ENODATA;
if (has_ea) {
p_ea_info = ntfs_attr_readall(ni, AT_EA_INFORMATION, NULL, 0,
&ea_info_size);
@@ -308,7 +310,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
err = -EEXIST;
goto out;
}
- if ((flags & XATTR_REPLACE) && !val_size) {
+ if (!value) {
old_ea_info = *p_ea_info;
old_ea_buf = kvmemdup(ea_buf, all_ea_size, GFP_NOFS);
if (!old_ea_buf) {
@@ -318,7 +320,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
}
/* Check the final $EA size before removing the old entry. */
- if (val_size &&
+ if (value &&
ntfs_attr_size_bounds_check(ni->vol, AT_EA,
ea_info_qsize - ea_size + new_ea_size)) {
err = -EFBIG;
@@ -327,7 +329,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
p_ea = (struct ea_attr *)(ea_buf + ea_off);
- if (val_size &&
+ if (value &&
le16_to_cpu(p_ea->ea_value_length) == val_size &&
!memcmp(p_ea->ea_name + p_ea->ea_name_length + 1, value,
val_size))
@@ -342,7 +344,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
ea_info_qsize -= ea_size;
p_ea_info->ea_query_length = cpu_to_le32(ea_info_qsize);
- if ((flags & XATTR_REPLACE) && !val_size && !ea_info_qsize) {
+ if (!value && !ea_info_qsize) {
err = ntfs_attr_remove(ni, AT_EA, AT_UNNAMED, 0);
if (err)
goto out;
@@ -357,7 +359,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
goto out;
}
- if ((flags & XATTR_REPLACE) && !val_size) {
+ if (!value) {
err = ntfs_write_ea(ni, AT_EA, ea_buf, 0, ea_info_qsize,
true);
if (err) {
@@ -378,7 +380,7 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
goto out;
}
} else {
- if (flags & XATTR_REPLACE) {
+ if (!value || (flags & XATTR_REPLACE)) {
err = -ENODATA;
goto out;
}
--
2.51.0
next prev parent reply other threads:[~2026-09-20 8:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 8:31 [PATCH v2 00/10] ntfs: persist Linux file attributes in an EA Baolin Liu
2026-09-20 8:31 ` [PATCH v2 01/10] ntfs: keep the EA presence flag after creating the first entry Baolin Liu
2026-09-20 8:31 ` [PATCH v2 02/10] ntfs: validate EA chains and link zero-terminated tails Baolin Liu
2026-09-21 6:17 ` Namjae Jeon
2026-09-21 10:34 ` liubaolin
2026-09-20 8:31 ` [PATCH v2 03/10] ntfs: propagate EA write and truncate errors Baolin Liu
2026-09-20 8:31 ` [PATCH v2 04/10] ntfs: preserve EA attribute lookup errors Baolin Liu
2026-09-20 8:31 ` Baolin Liu [this message]
2026-09-20 8:31 ` [PATCH v2 06/10] ntfs: restore EA attributes when an update fails Baolin Liu
2026-09-20 8:31 ` [PATCH v2 07/10] ntfs: add fileattr query support Baolin Liu
2026-09-20 8:31 ` [PATCH v2 08/10] ntfs: persist immutable in the $LXFLAGS EA Baolin Liu
2026-09-22 1:21 ` Hyunchul Lee
2026-09-22 3:26 ` liubaolin
2026-09-22 5:25 ` Hyunchul Lee
2026-09-22 6:02 ` liubaolin
2026-09-20 8:31 ` [PATCH v2 09/10] ntfs: persist append-only " Baolin Liu
2026-09-20 8:31 ` [PATCH v2 10/10] ntfs: persist nodump " Baolin Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260920083131.1880061-6-liubaolin12138@163.com \
--to=liubaolin12138@163.com \
--cc=chenxiaosong@chenxiaosong.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liubaolin@kylinos.cn \
--cc=ntfs@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®