From patchwork Fri Oct 20 01:22:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 13429960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D79E9C001DF for ; Fri, 20 Oct 2023 01:22:24 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qteDW-0000rO-Dk; Fri, 20 Oct 2023 01:22:22 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qteDV-0000rI-Ra for linux-f2fs-devel@lists.sourceforge.net; Fri, 20 Oct 2023 01:22:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Mp3m7Wck8Tj+/JZMkV3nskRyj8t4yVSOK4ORBNaBNco=; b=ZV/L2lyppHbxXS4XAGfbW3GXYn eJV+MaNspBn9Ze4s9p/Tp4d6onkS6bileoq5xPEg/z0lOwANeORk3Ozbx+Emngy9GAxs1JK84LBpj AjWLbDLUP1nibcCrTwebYgYhruVerhgxpo6i6MF5s8eGj06BPaEUKKd2JyoVca9d6IeA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=Mp3m7Wck8Tj+/JZMkV3nskRyj8t4yVSOK4ORBNaBNco=; b=a GwNA3rVhSx0oTrlUXWLIKQCY4CR7TX0xh4NeFLEi/V22VsIKEbjzqePqOKfiSvdKcEPrn3aJxZVC+ ilzAtR93D5uNPrOMPtafqDbI2a9FWHa9nMjLvdWsa3obw8zbWVBv0FCZ2jOpfXECy7vGYJ0fmbggO tBKuDzvl7WUUCgPY=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qteDU-003siL-VQ for linux-f2fs-devel@lists.sourceforge.net; Fri, 20 Oct 2023 01:22:21 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 77C5161C5D for ; Fri, 20 Oct 2023 01:22:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16D46C433C8; Fri, 20 Oct 2023 01:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764935; bh=bsUAFvciYZ5H5iM4IYuVPHhbmudSIbqO7L1aINivF3Y=; h=From:To:Cc:Subject:Date:From; b=f6M0Eolx0lmrHIW2yfDbpG+9r8eERp43RZoD7jNy8rMgVZtClnmjMMEIKdn2yVbuO ldzDQvczTJzKRA5aaNdyej9hdDW6DmfNAjp+8Uc4cxMBTUsUtmeIsN8jFJ6e6Msn2m dXgEuoN6Aop6MfNXP5y9cay4in/w1Vcj7FK4c9C3sJQ6+05HTjw1KnDx/N9cmNNIYz 9+ANsgpXE9JrFmUG5+/+pvUbBM9EaFtw1Y/zFHRnbkOGWmxQb0vZp68dWVikJdRfHi aan5jTTXjhoXj6l75Sgmmhcz9PiaR4I0x1B6oaj9lUsrpY1+5AAHIWjzR8/PX4fO+X 9klOH2Y+Z+5Kw== From: Jaegeuk Kim To: linux-f2fs-devel@lists.sourceforge.net Date: Thu, 19 Oct 2023 18:22:13 -0700 Message-ID: <20231020012213.2606422-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog MIME-Version: 1.0 X-Headers-End: 1qteDU-003siL-VQ Subject: [f2fs-dev] [PATCH] f2fs_io: add list/setattr command X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaegeuk Kim Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Let's add list/setattrs commands. Signed-off-by: Jaegeuk Kim Signed-off-by: Jaegeuk Kim --- tools/f2fs_io/f2fs_io.c | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index c812aa1458a2..a6a0de6d8dbd 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -35,6 +35,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -1526,6 +1527,91 @@ static void do_gc_range(int argc, char **argv, const struct cmd_desc *cmd) exit(0); } +#define listxattr_desc "listxattr" +#define listxattr_help "f2fs_io listxattr [file_path]\n\n" + +static void do_listxattr(int argc, char **argv, const struct cmd_desc *cmd) +{ + char *buf, *key, *val; + ssize_t buflen, vallen, keylen; + + if (argc != 2) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + buflen = listxattr(argv[1], NULL, 0); + if (buflen == -1) { + perror("listxattr"); + exit(1); + } + if (buflen == 0) { + printf("%s has no attributes.\n", argv[1]); + exit(0); + } + buf = xmalloc(buflen); + buflen = listxattr(argv[1], buf, buflen); + if (buflen == -1) { + perror("listxattr"); + exit(1); + } + + key = buf; + while (buflen > 0) { + printf("%s: ", key); + vallen = getxattr(argv[1], key, NULL, 0); + if (vallen == -1) { + perror("getxattr"); + exit(1); + } + if (vallen == 0) { + printf(""); + } else { + val = xmalloc(vallen + 1); + vallen = getxattr(argv[1], key, val, vallen); + if (vallen == -1) { + perror("getxattr"); + exit(1); + } + val[vallen] = 0; + printf("%s", val); + free(val); + } + printf("\n"); + keylen = strlen(key) + 1; + buflen -= keylen; + key += keylen; + } + exit(0); +} + +#define setxattr_desc "setxattr" +#define setxattr_help "f2fs_io setxattr [name] [value] [file_path]\n\n" + +static void do_setxattr(int argc, char **argv, const struct cmd_desc *cmd) +{ + int ret; + + if (argc != 4) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), XATTR_CREATE); + printf("setxattr %s CREATE: name: %s, value: %s: ret=%d\n", + argv[3], argv[1], argv[2], ret); + if (ret < 0 && errno == EEXIST) { + ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), XATTR_REPLACE); + printf("setxattr %s REPLACE: name: %s, value: %s: ret=%d\n", + argv[3], argv[1], argv[2], ret); + } + if (ret < 0) + perror("setxattr"); + exit(0); +} + #define CMD_HIDDEN 0x0001 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 } #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN } @@ -1564,6 +1650,8 @@ const struct cmd_desc cmd_list[] = { CMD(precache_extents), CMD(move_range), CMD(gc_range), + CMD(listxattr), + CMD(setxattr), { NULL, NULL, NULL, NULL, 0 } };