From patchwork Thu Feb 15 21:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 201749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp121086dyb; Thu, 15 Feb 2024 13:05:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU1TRYhrSNLPMBjtZ082F3Ke+lAlvrgJhNJKSVJVswaF0/FaiZJYpEkuJY+bNCZoFdDTZDNFheyUykorn0wIC5DAotmSw== X-Google-Smtp-Source: AGHT+IG0sw5NLOsvdxvxWPVspVtpJc6jBZU8H/YVua+r37pOW5avFANQ1nqLU1uv3eIcczOjiYUz X-Received: by 2002:a05:6214:2405:b0:68c:6746:5f4 with SMTP id fv5-20020a056214240500b0068c674605f4mr4598884qvb.43.1708031151619; Thu, 15 Feb 2024 13:05:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708031151; cv=pass; d=google.com; s=arc-20160816; b=L2iqmCVhzTcYHPnKtN2GFtb/YbSQMr/vkEjy2MTWz6JXER8RdJwukCw/OM5jcw5i/g Z/nNlSdjrVg++m9DipnUXhLlB+diJm6uzWhv2M3OKc+/bPo6Hh35WiRUUj3rW+zocbi5 BrRcOsgH+G4IOadDHc82erVrkVZPmcUj8CdRYCO0eg+LZdKYSFKzI8hg3nCk8vULLBxM ubMNploe6nsJbaF6k0bDaalH0oOGrxzd1vnVg+KRBOI0l4lFQ8yCtvK0Cpn9S6tzhJds ZmD4x9omVU8iWu4GXhZDu2tKLs+YDDmwTuzJYes1yEy24JfgXX0bMwTCsos8SsmYXmMK iPmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=kbAHpNS+oOLTU8LAj4t0HslhUKwQH1LKk3gZ3VuSClk=; fh=IvJDhn2XbJ55zxf0p/e9A+SWoPpre/ymwh9Q/MPTdCg=; b=GAAuLs9QDF1oljjBlnkj4yRp4Fbo45tKVdE6Y9LBPyha6GdXfMt+9epTt3J81cBvtr lCoOA1Jl9QSYXZXwODan2IUoFugJ/t6JaKp842PyZR8YngnTUb5PMmmTFpEjkoST9TUM 8fyGhP1hV6rYBEM8EDHqRS1lZwU1k3TLmyyM5Hl03p4LtLyLOkVqBtos0odNWofRFnx1 lkkWQ63aoIYOcmB7oCiC4rGESmrCbtSkgL+cY+cUdNkbFIjgNBKHWF/bvGn0Cam6M46S d5EasQ3vT1LqGKv84JfxJ36vlH4S15n93NzolPSGh06kiu3w+KZPcAidyBPkC8n7q4oD MEdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Byb5wA+J; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-67681-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67681-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 5-20020a05621420a500b0068f028ee1f5si2230059qvd.373.2024.02.15.13.05.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 13:05:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67681-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Byb5wA+J; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-67681-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67681-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B560C1C232F6 for ; Thu, 15 Feb 2024 21:05:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D12913B790; Thu, 15 Feb 2024 21:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Byb5wA+J" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44A5213B2BF for ; Thu, 15 Feb 2024 21:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708031123; cv=none; b=Lov7t1m5om0HT3P9T9bgJVMYf2ZekUo1vzxPiXxov1w9oHU8WvUei+or1WvbLGsYKAF7I2hbz937p+A7xHuwP9PMnQdBORz9MHRQAQjPnjAbDtaXFAgjP0KEQ2HsOW9ajVokTNyXPenK3LAmWI8+AkLiCvAunXidQr2ajYE6ew8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708031123; c=relaxed/simple; bh=aMOIWeOt1jD9bnQnQmZK1m4Ewkdfriyjv1XCNsipuyk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ab2xRcOw2lezg0Q/Z5QdceUj39iz0RTH22bOx8qHp7ek+lWdFdXn8HzRXvs5hNp33zpzDoh9L+wTmqUPqMD0XlWyS+oyH05ep4+YaujdEgXfNWaVefpcbv3THLOmS16TQGU/3GnSPHQ6ZCRcYhogQ58wtoWOpLIrKy319UtgmvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Byb5wA+J; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso61877a12.3 for ; Thu, 15 Feb 2024 13:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708031121; x=1708635921; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kbAHpNS+oOLTU8LAj4t0HslhUKwQH1LKk3gZ3VuSClk=; b=Byb5wA+JqjWnkgnRts+lSag4fj/lu+6CTrLKONoK7d/Gfkpop5hPHUdy22W4G/1vyS spw00vq89Feo1CHo2pHp5TQ/XA9a4SDe4rSdlRCOfM48W0GtfJC1KLw58tGWkaiJasS7 gdj0flU1z58SwVMbbnWJRJTLn5dIwwlAv8ZhEdHnXrYmxbdQJfDdgOwVc/yhTFHBLCdp TRVtzzbfV7OlRfpiLe9BDnmZKPIdWXZOwC8Peejtqhp9vkiYHCJp23UBZenGnU97bneD 892TmBLPcRBWNlVDwCZON8bPjDTQa062Tr+9KUWyT6StjIJsvl3r2LQbp+BU2ngE9Net uOpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708031121; x=1708635921; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kbAHpNS+oOLTU8LAj4t0HslhUKwQH1LKk3gZ3VuSClk=; b=HfF7nriIAPDL8EPYCueIPaTHcBJZ+gwMix2hPWaOjuKoS/OfLp/rA/qF7gZM582Qsr 6E5m/iBIb/FMoaRfhoVWolaGgqtFXhxhVs9xmvkF1pJze0fZiznBA71OiqvV5LI/s1HB QrHG0Eq8b7VqAOW1heRgijF9QmuHj96lAFWp+gsPZ9TwVkN5rufkGzTxizlzWFxDOpU5 bRkS2u17zuMTdgIPzn/fsgFoVwFzduCqND+FELYedrXt+6HO1FpVEC+bVCIgkAryIWlD dUtWHUUyHAviecOks7foD6/oael1WCups6aWgvxDzKGjUiRNPo8HoWti8cjN+OuPzCt5 s3ZA== X-Gm-Message-State: AOJu0YwANYWvY9iZRYPJaA+tEG5wL4rpjvt5fEMQYN5ar4Pe/eA5DoO9 okoG8dDHZ8yhKBkv1aNzqdaZOl2FC/GmtCMeWabs8ncqt3rpnFpickO7gOTB X-Received: by 2002:a17:902:8c96:b0:1d9:df95:89dd with SMTP id t22-20020a1709028c9600b001d9df9589ddmr2819585plo.47.1708031121123; Thu, 15 Feb 2024 13:05:21 -0800 (PST) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:3772:8174:2d71:3b60]) by smtp.gmail.com with ESMTPSA id p9-20020a1709026b8900b001d8d90d4f67sm1677783plk.249.2024.02.15.13.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 13:05:20 -0800 (PST) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH v2] f2fs_io: add lseek command to execute lseek() Date: Thu, 15 Feb 2024 13:05:17 -0800 Message-ID: <20240215210517.2383647-1-daeho43@gmail.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790998639920094051 X-GMAIL-MSGID: 1791000472440760355 From: Daeho Jeong Added lseek command to support lseek() for SEEK_DATA and SEEK_HOLE. Signed-off-by: Daeho Jeong --- v2: add SEEK_SET, SEEK_CUR and SEEK_END --- tools/f2fs_io/f2fs_io.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index e7d286a..a5e151d 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -1630,6 +1630,52 @@ static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd) exit(0); } +#define lseek_desc "do lseek for a file" +#define lseek_help \ +"f2fs_io lseek [whence] [offset] [file_path]\n\n" \ +"Do lseek file data in file_path and return the adjusted file offset\n" \ +"whence can be\n" \ +" set : SEEK_SET, The file offset is set to offset bytes\n" \ +" cur : SEEK_CUR, The file offset is set to its current location plus offset bytes\n" \ +" end : SEEK_END, The file offset is set to the size of the file plus offset bytes\n" \ +" data : SEEK_DATA, set the file offset to the next data location from offset\n" \ +" hole : SEEK_HOLE, set the file offset to the next hole from offset\n" + +static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd) +{ + int fd, whence; + off_t offset, ret; + + if (argc != 4) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + offset = atoi(argv[2]); + + if (!strcmp(argv[1], "set")) + whence = SEEK_SET; + else if (!strcmp(argv[1], "cur")) + whence = SEEK_CUR; + else if (!strcmp(argv[1], "end")) + whence = SEEK_END; + else if (!strcmp(argv[1], "data")) + whence = SEEK_DATA; + else if (!strcmp(argv[1], "hole")) + whence = SEEK_HOLE; + else + die("Wrong whence type"); + + fd = xopen(argv[3], O_RDONLY, 0); + + ret = lseek(fd, offset, whence); + if (ret < 0) + die_errno("lseek failed"); + printf("returned offset=%ld\n", ret); + 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 } @@ -1671,6 +1717,7 @@ const struct cmd_desc cmd_list[] = { CMD(listxattr), CMD(setxattr), CMD(removexattr), + CMD(lseek), { NULL, NULL, NULL, NULL, 0 } };