From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: aalbersh@kernel.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/4] xfs_io: make ls/chattr work with special files
Date: Mon, 11 Aug 2025 08:12:17 -0700 [thread overview]
Message-ID: <20250811151217.GC7965@frogsfrogsfrogs> (raw)
In-Reply-To: <20250808-xattrat-syscall-v1-3-48567c29e45c@kernel.org>
On Fri, Aug 08, 2025 at 09:30:18PM +0200, Andrey Albershteyn wrote:
> From: Andrey Albershteyn <aalbersh@redhat.com>
>
> With new file_getattr/file_setattr syscalls we can now list/change file
> attributes on special files instead for ignoring them.
>
> Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
> ---
> io/attr.c | 130 ++++++++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 75 insertions(+), 55 deletions(-)
>
> diff --git a/io/attr.c b/io/attr.c
> index fd82a2e73801..1cce602074f4 100644
> --- a/io/attr.c
> +++ b/io/attr.c
> @@ -8,6 +8,7 @@
> #include "input.h"
> #include "init.h"
> #include "io.h"
> +#include "libfrog/file_attr.h"
>
> static cmdinfo_t chattr_cmd;
> static cmdinfo_t lsattr_cmd;
> @@ -156,36 +157,35 @@ lsattr_callback(
> int status,
> struct FTW *data)
> {
> - struct fsxattr fsx;
> - int fd;
> + struct file_attr fa;
> + int error;
>
> if (recurse_dir && !S_ISDIR(stat->st_mode))
> return 0;
>
> - if ((fd = open(path, O_RDONLY)) == -1) {
> - fprintf(stderr, _("%s: cannot open %s: %s\n"),
> - progname, path, strerror(errno));
> - exitcode = 1;
> - } else if ((xfsctl(path, fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
> + error = file_getattr(AT_FDCWD, path, stat, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> progname, path, strerror(errno));
> exitcode = 1;
> - } else
> - printxattr(fsx.fsx_xflags, 0, 1, path, 0, 1);
> + return 0;
> + }
> +
> + printxattr(fa.fa_xflags, 0, 1, path, 0, 1);
Maybe it's time to rename this printxflags or something that's less
easily confused with extended attributes...
>
> - if (fd != -1)
> - close(fd);
> return 0;
> }
>
> static int
> lsattr_f(
> - int argc,
> - char **argv)
> + int argc,
> + char **argv)
> {
> - struct fsxattr fsx;
> - char *name = file->name;
> - int c, aflag = 0, vflag = 0;
> + struct file_attr fa;
> + char *name = file->name;
> + int c, aflag = 0, vflag = 0;
> + struct stat st;
> + int error;
>
> recurse_all = recurse_dir = 0;
> while ((c = getopt(argc, argv, "DRav")) != EOF) {
> @@ -211,17 +211,27 @@ lsattr_f(
> if (recurse_all || recurse_dir) {
> nftw(name, lsattr_callback,
> 100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
> - } else if ((xfsctl(name, file->fd, FS_IOC_FSGETXATTR, &fsx)) < 0) {
> + return 0;
> + }
> +
> + error = stat(name, &st);
> + if (error)
> + return error;
> +
> + error = file_getattr(AT_FDCWD, name, &st, &fa, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> progname, name, strerror(errno));
> exitcode = 1;
> - } else {
> - printxattr(fsx.fsx_xflags, vflag, !aflag, name, vflag, !aflag);
> - if (aflag) {
> - fputs("/", stdout);
> - printxattr(-1, 0, 1, name, 0, 1);
> - }
> + return 0;
> }
> +
> + printxattr(fa.fa_xflags, vflag, !aflag, name, vflag, !aflag);
> + if (aflag) {
> + fputs("/", stdout);
> + printxattr(-1, 0, 1, name, 0, 1);
> + }
> +
> return 0;
> }
>
> @@ -232,44 +242,43 @@ chattr_callback(
> int status,
> struct FTW *data)
> {
> - struct fsxattr attr;
> - int fd;
> + struct file_attr attr;
> + int error;
>
> if (recurse_dir && !S_ISDIR(stat->st_mode))
> return 0;
>
> - if ((fd = open(path, O_RDONLY)) == -1) {
> - fprintf(stderr, _("%s: cannot open %s: %s\n"),
> - progname, path, strerror(errno));
> - exitcode = 1;
> - } else if (xfsctl(path, fd, FS_IOC_FSGETXATTR, &attr) < 0) {
> + error = file_getattr(AT_FDCWD, path, stat, &attr, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> progname, path, strerror(errno));
> exitcode = 1;
> - } else {
> - attr.fsx_xflags |= orflags;
> - attr.fsx_xflags &= ~andflags;
> - if (xfsctl(path, fd, FS_IOC_FSSETXATTR, &attr) < 0) {
> - fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
> - progname, path, strerror(errno));
> - exitcode = 1;
> - }
> + return 0;
> + }
> +
> + attr.fa_xflags |= orflags;
> + attr.fa_xflags &= ~andflags;
> + error = file_setattr(AT_FDCWD, path, stat, &attr, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> + fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
> + progname, path, strerror(errno));
> + exitcode = 1;
> }
>
> - if (fd != -1)
> - close(fd);
> return 0;
> }
>
> static int
> chattr_f(
> - int argc,
> - char **argv)
> + int argc,
> + char **argv)
> {
> - struct fsxattr attr;
> - struct xflags *p;
> - unsigned int i = 0;
> - char *c, *name = file->name;
> + struct file_attr attr;
> + struct xflags *p;
> + unsigned int i = 0;
> + char *c, *name = file->name;
> + struct stat st;
> + int error;
>
> orflags = andflags = 0;
> recurse_all = recurse_dir = 0;
> @@ -326,19 +335,30 @@ chattr_f(
> if (recurse_all || recurse_dir) {
> nftw(name, chattr_callback,
> 100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
> - } else if (xfsctl(name, file->fd, FS_IOC_FSGETXATTR, &attr) < 0) {
> + return 0;
> + }
> +
> + error = stat(name, &st);
> + if (error)
> + return error;
> +
> + error = file_getattr(AT_FDCWD, name, &st, &attr, AT_SYMLINK_NOFOLLOW);
> + if (error) {
> fprintf(stderr, _("%s: cannot get flags on %s: %s\n"),
> progname, name, strerror(errno));
> exitcode = 1;
> - } else {
> - attr.fsx_xflags |= orflags;
> - attr.fsx_xflags &= ~andflags;
> - if (xfsctl(name, file->fd, FS_IOC_FSSETXATTR, &attr) < 0) {
> - fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
> - progname, name, strerror(errno));
> - exitcode = 1;
> - }
> + return 0;
> }
> +
> + attr.fa_xflags |= orflags;
> + attr.fa_xflags &= ~andflags;
> + error = file_setattr(AT_FDCWD, name, &st, &attr, AT_SYMLINK_NOFOLLOW);
For my own curiosity, if you wanted to do the get/set sequence on a file
that's already open, is that just:
file_getattr(fd, "", &attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
...
file_setattr(fd, "", &attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
--D
> + if (error) {
> + fprintf(stderr, _("%s: cannot set flags on %s: %s\n"),
> + progname, name, strerror(errno));
> + exitcode = 1;
> + }
> +
> return 0;
> }
>
>
> --
> 2.49.0
>
>
next prev parent reply other threads:[~2025-08-11 15:12 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 19:28 Tests for file_getattr()/file_setattr() and xfsprogs update Andrey Albershteyn
2025-08-08 19:30 ` [PATCH 0/4] xfsprogs: utilize file_getattr() and file_setattr() Andrey Albershteyn
2025-08-08 19:30 ` [PATCH 1/4] libfrog: add wrappers for file_getattr/file_setattr syscalls Andrey Albershteyn
2025-08-11 15:02 ` Darrick J. Wong
2025-08-11 17:44 ` Andrey Albershteyn
2025-08-12 14:53 ` Darrick J. Wong
2025-08-08 19:30 ` [PATCH 2/4] xfs_quota: utilize file_setattr to set prjid on special files Andrey Albershteyn
2025-08-11 15:07 ` Darrick J. Wong
2025-08-11 17:51 ` Andrey Albershteyn
2025-08-08 19:30 ` [PATCH 3/4] xfs_io: make ls/chattr work with " Andrey Albershteyn
2025-08-11 15:12 ` Darrick J. Wong [this message]
2025-08-11 17:57 ` Andrey Albershteyn
2025-08-12 17:28 ` Darrick J. Wong
2025-08-08 19:30 ` [PATCH 4/4] xfs_db: use file_setattr to copy attributes on special files with rdump Andrey Albershteyn
2025-08-11 15:14 ` Darrick J. Wong
2025-08-11 17:59 ` Andrey Albershteyn
2025-08-08 19:31 ` [PATCH 0/3] Test file_getattr and file_setattr syscalls Andrey Albershteyn
2025-08-08 19:31 ` [PATCH 1/3] file_attr: introduce program to set/get fsxattr Andrey Albershteyn
2025-08-11 15:23 ` Darrick J. Wong
2025-08-11 18:06 ` Andrey Albershteyn
2025-08-11 17:51 ` Zorro Lang
2025-08-11 18:12 ` Andrey Albershteyn
2025-08-08 19:31 ` [PATCH 2/3] generic: introduce test to test file_getattr/file_setattr syscalls Andrey Albershteyn
2025-08-11 15:17 ` Darrick J. Wong
2025-08-11 18:13 ` Andrey Albershteyn
2025-08-11 17:55 ` Zorro Lang
2025-08-11 18:18 ` Andrey Albershteyn
2025-08-11 18:43 ` Zorro Lang
2025-08-08 19:31 ` [PATCH 3/3] xfs: test quota's project ID on special files Andrey Albershteyn
2025-08-11 15:21 ` Darrick J. Wong
2025-08-11 18:21 ` Andrey Albershteyn
2025-08-11 17:46 ` Zorro Lang
2025-08-11 18:20 ` Andrey Albershteyn
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=20250811151217.GC7965@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@kernel.org \
--cc=aalbersh@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).