From: fdmanana@kernel.org
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH v2 6/7] fsstress: add operation for listing xattrs from files and directories
Date: Mon, 1 Apr 2019 13:51:52 +0100 [thread overview]
Message-ID: <20190401125152.10263-1-fdmanana@kernel.org> (raw)
From: Filipe Manana <fdmanana@suse.com>
The previous patches added support for operations to set, get and delete
xattrs on regular files and directories, this patch just adds an operation
to list the xattrs of a file/directory.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
V2: New patch in the series, the first version of the patchset did not include
this patch.
ltp/fsstress.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index 1694c5a2..ff560d6e 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -72,6 +72,7 @@ typedef enum {
OP_GETDENTS,
OP_GETFATTR,
OP_LINK,
+ OP_LISTFATTR,
OP_MKDIR,
OP_MKNOD,
OP_MREAD,
@@ -188,6 +189,7 @@ void getattr_f(int, long);
void getdents_f(int, long);
void getfattr_f(int, long);
void link_f(int, long);
+void listfattr_f(int, long);
void mkdir_f(int, long);
void mknod_f(int, long);
void mread_f(int, long);
@@ -242,6 +244,7 @@ opdesc_t ops[] = {
{ OP_GETDENTS, "getdents", getdents_f, 1, 0 },
{ OP_GETFATTR, "getfattr", getfattr_f, 2, 0 },
{ OP_LINK, "link", link_f, 1, 1 },
+ { OP_LISTFATTR, "listfattr", listfattr_f, 1, 0 },
{ OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
{ OP_MKNOD, "mknod", mknod_f, 2, 1 },
{ OP_MREAD, "mread", mread_f, 2, 0 },
@@ -3751,6 +3754,69 @@ link_f(int opno, long r)
}
void
+listfattr_f(int opno, long r)
+{
+ int fd;
+ fent_t *fep;
+ int e;
+ pathname_t f;
+ int v;
+ char *buffer = NULL;
+ int buffer_len;
+ DIR *dir;
+
+ init_pathname(&f);
+ if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
+ if (v)
+ printf("%d/%d: listfattr - no filename\n", procid, opno);
+ free_pathname(&f);
+ return;
+ }
+ fd = open_file_or_dir(&f, O_RDONLY, &dir);
+ e = fd < 0 ? errno : 0;
+ if (fd < 0) {
+ if (v)
+ printf("%d/%d: listfattr - open %s failed %d\n",
+ procid, opno, f.path, e);
+ free_pathname(&f);
+ return;
+ }
+ check_cwd();
+
+ e = flistxattr(fd, NULL, 0);
+ if (e < 0) {
+ if (v)
+ printf("%d/%d: listfattr %s failed %d\n",
+ procid, opno, f.path, errno);
+ goto out;
+ }
+ buffer_len = e;
+ if (buffer_len == 0) {
+ if (v)
+ printf("%d/%d: listfattr %s - has no extended attributes\n",
+ procid, opno, f.path);
+ goto out;
+ }
+
+ buffer = malloc(buffer_len);
+ if (!buffer) {
+ if (v)
+ printf("%d/%d: listfattr %s failed to allocate buffer with %d bytes\n",
+ procid, opno, f.path, buffer_len);
+ goto out;
+ }
+
+ e = flistxattr(fd, buffer, buffer_len) < 0 ? errno : 0;
+ if (v)
+ printf("%d/%d: listfattr %s buffer length %d %d\n",
+ procid, opno, f.path, buffer_len, e);
+out:
+ free(buffer);
+ free_pathname(&f);
+ close_file_or_dir(fd, dir);
+}
+
+void
mkdir_f(int opno, long r)
{
int e;
--
2.11.0
reply other threads:[~2019-04-01 12:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20190401125152.10263-1-fdmanana@kernel.org \
--to=fdmanana@kernel.org \
--cc=fdmanana@suse.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@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).