Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2566099rwd; Sun, 28 May 2023 19:09:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6noQowqV50Qj5Y40GlqK8ySJNIO0PoWkVSfy9cBah6hpkmgZD6q7jH53/CJIjSbY+JprgW X-Received: by 2002:a17:90a:98f:b0:255:a904:7a7b with SMTP id 15-20020a17090a098f00b00255a9047a7bmr10396310pjo.26.1685326170030; Sun, 28 May 2023 19:09:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1685326170; cv=pass; d=google.com; s=arc-20160816; b=aQhKokOuaMh1Z42xJGgtaCyuyHbFeMndnocouremgYmBOmajKCGiX8t4ruz4X40cwB TqcXIN/vGFzuV02oaAmrKR9nFQaJDHBOApYImXRnZh9IrBt4YN8zWYXUoyKpTV8YIhAo wem+szlt76QHOYtP51WSoD7dlotGqK8hcNfOs0CeM3vuBBQl9QZ8d2y4bnYAbRcoz72c 8xTfBXZ4NDIhyhGbpfK4+K5pTCNT9IqfsplV05kWog/SbjbYP081tVXGrs2473pk9nKt 1iI2MAOJKEhpDhdW2olVl5+Hbv4jSnarmHaRBS9+ViDHDGezhUnoX3Q9NZVTiyx5jSeI wVOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WLvxepq//Nr0ZocNEPavwrXeDuP1FmcGw8Ja5RHm/LA=; b=p95E5Ny/CDO0CBXTAnOv6dIdrTrlI7iTg1O2sLuFca9OAfpi49uBHE4PhYMbCGWGjW O+pdRSTGKVbh4gH8L1YKG9Boo/hnTEbpImaifwdhemIaJ5iYwtUKESNGiX8+p2TSWQiq vdUnlXQ/PP1GDo5RmiivShRbVbaFTw7L34FAp5QDRKM5EhOWHIaiDnKuDwJNq/nAOAms DmmJvqYbutRM5euMoc8GIhaxx5Zrh6FzqbXPEgh9rFBmUqlOozzJU8+m+pUzpRGYe+GC 8ZJGBxlFDqcJzBCB17T1F74G+FJJmw6uTN1jWkSD8c6verDBWwBZu3UsUrv3y1euNzy9 Pc0Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oppo.com header.s=selector1 header.b=UNrsoSak; arc=pass (i=1 spf=pass spfdomain=oppo.com dkim=pass dkdomain=oppo.com dmarc=pass fromdomain=oppo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne10-20020a17090b374a00b002477fad79d5si10411107pjb.63.2023.05.28.19.09.16; Sun, 28 May 2023 19:09:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oppo.com header.s=selector1 header.b=UNrsoSak; arc=pass (i=1 spf=pass spfdomain=oppo.com dkim=pass dkdomain=oppo.com dmarc=pass fromdomain=oppo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oppo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjE2Bf6 (ORCPT + 99 others); Sun, 28 May 2023 21:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjE2Bf4 (ORCPT ); Sun, 28 May 2023 21:35:56 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on20600.outbound.protection.outlook.com [IPv6:2a01:111:f403:704b::600]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 961B3C4 for ; Sun, 28 May 2023 18:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QnJrCe/0711rBX7nOiG9CJMtma7pa3IxIyLkfqRRIsdomKfxIGfjHG+zjS91z5ITGw096EVmpchosJmHkuCvHtm5qiZ95l2iTjpCrWkCGWTTdDa4vtrdgY5Mbvq+2UyoDltMqEjiUfzyhxrP9ro+X/U38cJtNZKWwbrfrg8IWn3CnwPtaWpYAnJ2oP3OxZ0W2KWd0e6ibTSabI4BSCJzfY2V8NjUiXQFlNPs/krkaOOYd1LGzu6q5BjwspOshoi80JFKDtsYZGSusQlipLaLR9uqcY/oC/JEdu6UGTkE/8dNQam7g00Elbvol5K/sZm3O2DkuJJlOHwNH71wA72xRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WLvxepq//Nr0ZocNEPavwrXeDuP1FmcGw8Ja5RHm/LA=; b=OD8Kk+U5FBRNWdqj3z6Tv8o1+KuFwtw8Cs4KaglIU67tu+VvjgMVdwlg+nrHERf1nj+6m0vl551zN8zFxjBVZfsZp7raxdrwEUekgUa7QIvDYSSyBanOYTorGZM98P4uWvh3GFbGWPSLsM0XiU3W7z7bJaTecGDqrj2p0DTx+eLoB8VWPP4n5ZVUozGcdzLlqrtrN0JmjWdMnC1O0RI8mrYvgjFVZTd7sMHiqasR3w3j4QR9lYWy3JNn5g4eBjwpCk2dY2HcSBcTgMVxpmIR2SkHBBbpY0MSqTiYHYyumPt5lbMLzCZ3rJSnwTSiXxJRcK16muRFibwYB6XSRbW9bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oppo.com; dmarc=pass action=none header.from=oppo.com; dkim=pass header.d=oppo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WLvxepq//Nr0ZocNEPavwrXeDuP1FmcGw8Ja5RHm/LA=; b=UNrsoSaklyNM+spd22cZ4Hm6tym1l0HxKmIhAZ8lbELyhoQ3ooydT42ISq+S/flgupKhyyi+TQkw+ZITyNS+JMZP9YF6YLQfvPxTkXF4cE69zewoVf2WXQClt/TCZroqmxGYvH96p//J/XVRDVHMQJOu/92bREcW69G1znenm54= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oppo.com; Received: from SI2PR02MB5148.apcprd02.prod.outlook.com (2603:1096:4:153::6) by SI2PR02MB4617.apcprd02.prod.outlook.com (2603:1096:4:ec::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.18; Mon, 29 May 2023 01:35:40 +0000 Received: from SI2PR02MB5148.apcprd02.prod.outlook.com ([fe80::1bc4:fbb5:b757:83ee]) by SI2PR02MB5148.apcprd02.prod.outlook.com ([fe80::1bc4:fbb5:b757:83ee%5]) with mapi id 15.20.6455.020; Mon, 29 May 2023 01:35:40 +0000 From: Sheng Yong To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sheng Yong Subject: [PATCH 1/2] f2fs_io: add [get|set_attr] to access inode extra attributes Date: Mon, 29 May 2023 09:35:01 +0800 Message-Id: <20230529013502.2230810-2-shengyong@oppo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230529013502.2230810-1-shengyong@oppo.com> References: <20230529013502.2230810-1-shengyong@oppo.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR01CA0175.apcprd01.prod.exchangelabs.com (2603:1096:4:28::31) To SI2PR02MB5148.apcprd02.prod.outlook.com (2603:1096:4:153::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SI2PR02MB5148:EE_|SI2PR02MB4617:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f79a084-e32a-4a2b-247b-08db5fe502c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kYI7Tn6tNgaHK0Qle9Xq3xdHBQeKtCEKyPxs8cJWn6G3zKqOg6A/ufYn/nIKgSdiunVs7Uum5ogYICHi2ydss6uxSw68xw9Fq0OQHdEN1ECTuQAdRfugDarcy977e9vQxGxggipLg6T5WEpngWoltEpQ6yRLwDnQBoVjDSR0IO/7Qa/CCcu+em2hRAFtW2cOwC1+VUuY4qEJ+ShlmSJHUKHogQ52D4FQP0lGAp7hLJt1E1vWOnE/liJ2NbZIwcSrbAoSCPGu2o3ZQxmrSg5OIL2w1uTPNsh+m6Zq5E2I1Qk5Ab0ox+wixu4FTuIV+lxCzsnQn0mzzkgwF6hTytcueSiIcDHZ/JbdN4D64FrI6wPZE7HsrmaqxDuY/P1P6Vov+/w8v5/cO5PzoVa5OIU4ld4bQi++xZnd7mRap/UamZzT2draAdjkFmrcn+KdiwxXy6hCQNiIQbI6WfM5Nmk+/ilgw7FAShS1kajecrIIt979f5uO+PJHW5djLyARpxWaYEK+N1G8dqXygKF/DO7rX/5GIUizDfH3ajf7JC/ZtejkFdoPsJeAe6H9iwGj3Sxb/U9caNpCR141G82CaUglueDq8J1/fQId59C6o8qHJLfjia954/513h4Yjwq0slXs X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SI2PR02MB5148.apcprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(39860400002)(396003)(136003)(366004)(451199021)(2616005)(186003)(83380400001)(2906002)(4326008)(5660300002)(26005)(1076003)(6506007)(6512007)(36756003)(86362001)(107886003)(478600001)(8676002)(8936002)(66946007)(66556008)(66476007)(6666004)(316002)(38100700002)(38350700002)(41300700001)(6486002)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?9ffX4wunB8UDopP7mSRjtrEWyLOmoG8bsrfz/AyzEXUm6hTaciJ5ysS61zyc?= =?us-ascii?Q?KWi7DzJd35t3OBCFqrGDLqDizv0G9exOjw+qG+wzaJ+nxKlWFqmRxV1foh8A?= =?us-ascii?Q?ZEWWXpFrPdYdp6k3L8Na6rPvvRL2s2VPusP8Z/jQEKVLFLRDX15Ijvq63kWe?= =?us-ascii?Q?mTtQDxbIW9N1j2nExt2izJFsG7nO7GVKlsxA0HzDAPY/Vb+j8kEGQzs0t11C?= =?us-ascii?Q?OHzThBnm5MxnXjfY56yxrgM1K++J78HzjQINzrO0jNsaOTx4tm0tvWtO46z0?= =?us-ascii?Q?73OaklvQ6tQYCfaC+yUqPnelK8W/05gMH6Q4TO8xgQ+oJzC5iFv/RuxOE1E6?= =?us-ascii?Q?+Cz1fXi2IDvnbsfyRIpylz12Z8XBolRC5zPfIyrDGFBm7WGVV6+UOEg2iIdR?= =?us-ascii?Q?T7GEyx9iLoWSpddxL9iK1DuRokYajH7/TuVSGzJAfH2M28CWnXSB3hhwGPw0?= =?us-ascii?Q?urt+BBpybhDz6jbj8Zi6tj0Z3ctc/NNotvmw5R2//W8wmKmLJknITn3hOb3P?= =?us-ascii?Q?j7yaskg+Z1SUDGFailfbLugM6aDNEHJdKc+zGw0ztEflN/gzQ0ykUNZ7iPQ5?= =?us-ascii?Q?6YQcalI067STUMEHa80WE+rhHP3gL1Z0Fj4+FmWIj/xUCb9nktrR1S8oS29h?= =?us-ascii?Q?jNzz6VyHW1NDqf9+Gcr6quiGVQiVFyh8mAs4EDV3Nw57dROunHQ52lymaAPv?= =?us-ascii?Q?NPfIcCrcOyP1svQuhI31XCYME0uSnEsCc+Yw+yq460U/6G2p+g0RdJJX+MQ/?= =?us-ascii?Q?Jlggj+1BCtFM+KAwTZdMHVJ20AJ4Y5n4LCpF7uQR7YTDqjI4ycw6kmfhAVEG?= =?us-ascii?Q?+x7obBY48bvXGpl/SYgzQmTdkflF+tKfGpWZrl9iN0NYZGylzmPuL3vBSJNl?= =?us-ascii?Q?h+mEihuJlOdeVV9qdXV0JtS0p1uiIQ/0vtpR4Kzsp5/9lsMPtoUH3cWfktJb?= =?us-ascii?Q?R86kE5tQEQiUKK93EY9DP8AuOHABoHLYKMVsf/6k/AAPpdWj6xj7Xt71iImm?= =?us-ascii?Q?la85pBLF5Swj0TtE6oKBRsfnatbEoRKShnlitFWBZRurZkhuJkYHh2EwwEAT?= =?us-ascii?Q?b4mm5kwgdoEJrXQotcVVseGUAI1H05ZFipk7Aj5MU9W10dG3eo8BTUSzV9ub?= =?us-ascii?Q?iLOaO4PjMcrS1LgpiOyGsdz2vW+3MDrx1zgN+Eqc2eJbOHX6EOClMZ3P7x/E?= =?us-ascii?Q?PeikepAeKGi3nh8YyHanZo5erv89bpUNLFRS1wq1XkDK5eSYtSqLO4CYmayc?= =?us-ascii?Q?4udubVz5QDC0pfLHcLyzqU1OxtaTD0+t/PUckDfM95K+etHZOrzd3uGvIfHM?= =?us-ascii?Q?ZFIn/2JO7A2izYp0XVNgD+skQVhbLZWGyllOG5TpV8QIHuE+NkP1bZ57m39t?= =?us-ascii?Q?HoHQ5STSVLXMTPWsVfJw49InYavY9nWOFCAhJVgbItWwk7HgWygFSI14IwEK?= =?us-ascii?Q?vf0CARuLAYLlOSgDiGFEo5HhlIseQAOEa+MXQIXtH31AEj7WVX/9PBys3cfP?= =?us-ascii?Q?cYPui/y+I6sinN/tqj04KgtEoeNbVk/gwYLy5SoVfqG6EeDqMEPuhlvy9aOr?= =?us-ascii?Q?w1NsEkIOzadhLoGx2XONqSEcsiXYOdFtTtxeOZma?= X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f79a084-e32a-4a2b-247b-08db5fe502c9 X-MS-Exchange-CrossTenant-AuthSource: SI2PR02MB5148.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 01:35:40.4256 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vAKfW4aLkJh/dVrmtqN4hgR6fM4f1SQz633bkZVcdtMvLGS3F9syGadoYvncBNlH4E3HVb9B9Q8m7Dni5B5TNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR02MB4617 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds get_attr and set_attr to access inode's extra attributes. Signed-off-by: Sheng Yong --- tools/f2fs_io/f2fs_io.c | 165 ++++++++++++++++++++++++++++++++++++++++ tools/f2fs_io/f2fs_io.h | 34 +++++++++ 2 files changed, 199 insertions(+) diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index 5bc0baf..70e0347 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -1311,6 +1311,169 @@ static void do_gc(int argc, char **argv, const struct cmd_desc *cmd) exit(0); } +#define get_attr_desc "get inode extra attribute" +#define get_attr_help "f2fs_io get_attr [field] [file_path]\n\n" \ +"field can be\n" \ +" total_size\n" \ +" isize\n" \ +" inline_xattr_size\n" \ +" projid\n" \ +" inode_chksum\n" \ +" crtime\n" \ +" cblocks\n" \ +" coption\n" + +static const char *extra_attr_fields[] = { + [F2FS_EXTRA_ATTR_TOTAL_SIZE] = "total_size", + [F2FS_EXTRA_ATTR_ISIZE] = "isize", + [F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE] = "inline_xattr_size", + [F2FS_EXTRA_ATTR_PROJID] = "projid", + [F2FS_EXTRA_ATTR_INODE_CHKSUM] = "inode_chksum", + [F2FS_EXTRA_ATTR_CRTIME] = "crtime", + [F2FS_EXTRA_ATTR_COMPR_BLOCKS] = "cblocks", + [F2FS_EXTRA_ATTR_COMPR_OPTION] = "coption", +}; + +static void do_get_attr(int argc, char **argv, const struct cmd_desc *cmd) +{ + struct f2fs_extra_attr attr = {0}; + struct timespec ts = {0}; + struct f2fs_comp_option_v2 coption = {0}; + int ret, fd; + + if (argc != 3) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + for (attr.field = 0; attr.field < F2FS_EXTRA_ATTR_MAX; attr.field++) { + if (!strcmp(extra_attr_fields[attr.field], argv[1])) + break; + } + + switch (attr.field) { + case F2FS_EXTRA_ATTR_TOTAL_SIZE: + case F2FS_EXTRA_ATTR_ISIZE: + case F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE: + case F2FS_EXTRA_ATTR_PROJID: + case F2FS_EXTRA_ATTR_INODE_CHKSUM: + case F2FS_EXTRA_ATTR_COMPR_BLOCKS: + attr.attr_size = sizeof(attr.attr); + break; + case F2FS_EXTRA_ATTR_CRTIME: + attr.attr_size = sizeof(ts); + attr.attr = (unsigned long)&ts; + break; + case F2FS_EXTRA_ATTR_COMPR_OPTION: + attr.attr_size = sizeof(coption); + attr.attr = (unsigned long)&coption; + break; + default: + die("Unknown field"); + } + + fd = xopen(argv[2], O_RDONLY, 0); + + ret = ioctl(fd, F2FS_IOC_GET_EXTRA_ATTR, &attr); + if (ret < 0) + die_errno("F2FS_IOC_GET_EXTRA_ATTR failed"); + + switch (attr.field) { + case F2FS_EXTRA_ATTR_TOTAL_SIZE: + case F2FS_EXTRA_ATTR_ISIZE: + case F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE: + case F2FS_EXTRA_ATTR_PROJID: + case F2FS_EXTRA_ATTR_COMPR_BLOCKS: + printf("%"PRIu64"\n", attr.attr); + break; + case F2FS_EXTRA_ATTR_INODE_CHKSUM: + printf("0x%"PRIx64"\n", attr.attr); + break; + case F2FS_EXTRA_ATTR_CRTIME: + printf("sec: %lu\nnsec: %lu\n", ts.tv_sec, ts.tv_nsec); + break; + case F2FS_EXTRA_ATTR_COMPR_OPTION: + printf("compression algorithm:%u\n", coption.algorithm); + printf("compression cluster log size:%u\n", coption.log_cluster_size); + printf("compression level:%u\n", coption.level); + printf("compression flag:0x%x\n", coption.flag); + break; + default: + die("Unknown field"); + } + + exit(0); +} + +#define set_attr_desc "set inode extra attribute" +#define set_attr_help "f2fs_io set_attr [field] [values] [file_path]\n\n" \ +"field can be\n" \ +" inline_xattr_size : [values] is [size]\n" \ +" coption : [values] are [algorithm] [log_cluster_size] [level] [flag]\n" \ +" algorithm : compression algorithm (0:lzo, 1: lz4, 2:zstd, 3:lzorle)\n" \ +" log_cluster_size : compression cluster log size (2 <= log_size <= 8)\n" \ +" level : compression level\n" \ +" flag : compression flag (1:chksum)\n" + +static void do_set_attr(int argc, char **argv, const struct cmd_desc *cmd) +{ + struct f2fs_extra_attr attr = {0}; + struct f2fs_comp_option_v2 coption = {0}; + int i; + int ret, fd; + + if (argc < 4) + goto out; + + if (!strcmp(argv[1], extra_attr_fields[F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE])) { + if (argc != 4) + goto out; + i = 2; + attr.field = F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE; + attr.attr_size = sizeof(attr.attr); + attr.attr = atoi(argv[i++]); + } else if (!strcmp(argv[1], extra_attr_fields[F2FS_EXTRA_ATTR_COMPR_OPTION])) { + if (argc != 7) + goto out; + i = 2; + coption.algorithm = atoi(argv[i++]); + coption.log_cluster_size = atoi(argv[i++]); + coption.level = atoi(argv[i++]); + coption.flag = atoi(argv[i++]); + attr.field = F2FS_EXTRA_ATTR_COMPR_OPTION; + attr.attr_size = sizeof(coption); + attr.attr = (unsigned long)&coption; + } else { + die("Unknown or read only field"); + } + + fd = xopen(argv[i], O_WRONLY, 0); + + ret = ioctl(fd, F2FS_IOC_SET_EXTRA_ATTR, &attr); + if (ret < 0) + die_errno("F2FS_IOC_SET_EXTRA_ATTR failed"); + + switch (attr.field) { + case F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE: + printf("set inline_xattr_size:%"PRIu64"\n", attr.attr); + break; + case F2FS_EXTRA_ATTR_COMPR_OPTION: + printf("set compression option: algorithm=%u, " + "log_cluster_size=%u, level=%u, flag=0x%x\n", + coption.algorithm, coption.log_cluster_size, + coption.level, coption.flag); + break; + } + + exit(0); +out: + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); +} + + #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 } @@ -1343,6 +1506,8 @@ const struct cmd_desc cmd_list[] = { CMD(get_filename_encrypt_mode), CMD(rename), CMD(gc), + CMD(get_attr), + CMD(set_attr), { NULL, NULL, NULL, NULL, 0 } }; diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h index 58be8f8..b0be15c 100644 --- a/tools/f2fs_io/f2fs_io.h +++ b/tools/f2fs_io/f2fs_io.h @@ -91,6 +91,10 @@ typedef u32 __be32; #define F2FS_IOC_DECOMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 23) #define F2FS_IOC_COMPRESS_FILE _IO(F2FS_IOCTL_MAGIC, 24) #define F2FS_IOC_START_ATOMIC_REPLACE _IO(F2FS_IOCTL_MAGIC, 25) +#define F2FS_IOC_GET_EXTRA_ATTR _IOR(F2FS_IOCTL_MAGIC, 26, \ + struct f2fs_extra_attr) +#define F2FS_IOC_SET_EXTRA_ATTR _IOW(F2FS_IOCTL_MAGIC, 27, \ + struct f2fs_extra_attr) #ifndef FSCRYPT_POLICY_V1 #define FSCRYPT_POLICY_V1 0 @@ -216,3 +220,33 @@ struct f2fs_comp_option { u8 algorithm; u8 log_cluster_size; }; + +struct f2fs_comp_option_v2 { + u8 algorithm; + u8 log_cluster_size; + u8 level; + u8 flag; +}; + +enum { + F2FS_EXTRA_ATTR_TOTAL_SIZE, /* ro, size of extra attr area */ + F2FS_EXTRA_ATTR_ISIZE, /* ro, i_extra_isize */ + F2FS_EXTRA_ATTR_INLINE_XATTR_SIZE, /* r2, i_inline_xattr_size */ + F2FS_EXTRA_ATTR_PROJID, /* ro, i_projid */ + F2FS_EXTRA_ATTR_INODE_CHKSUM, /* ro, i_inode_chksum */ + F2FS_EXTRA_ATTR_CRTIME, /* ro, i_crtime, i_crtime_nsec */ + F2FS_EXTRA_ATTR_COMPR_BLOCKS, /* ro, i_compr_blocks */ + F2FS_EXTRA_ATTR_COMPR_OPTION, /* rw, i_compress_algorithm, + * i_log_cluster_size, + * i_compress_flag + */ + F2FS_EXTRA_ATTR_MAX, +}; + +struct f2fs_extra_attr { + u8 field; /* F2FS_EXTRA_ATTR_* */ + u8 rsvd1; + u16 attr_size; /* size of @attr */ + u32 rsvd2; + u64 attr; /* attr value or pointer */ +}; -- 2.40.1