From patchwork Thu Feb 21 09:00:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 158879 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp242705jaa; Thu, 21 Feb 2019 01:01:05 -0800 (PST) X-Google-Smtp-Source: AHgI3IacRboVTiQQC/acXHHe1uEJAWXUDaSBp8ykhIuO8aagcFFxncDxq61+s2T2mQHDSz2eOgXd X-Received: by 2002:a17:906:c811:: with SMTP id cx17-v6mr26086928ejb.50.1550739665154; Thu, 21 Feb 2019 01:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550739665; cv=none; d=google.com; s=arc-20160816; b=QB0IDyie3lt7BILWivJetUdM7Gv9p0OG0DOIrDQrFZjp0wuDiKOzcm85hcFqLya7bI ChAneph8vYhyU4f8Zv41IJgQRkriKreRk5EZvUHKmsDpoD2kAG7DHfv2W+/pQERJSrmL Ht/LjCYUKGf5bL0rmKZbQEo15S3EpV5656e2MTCmIOnVQnO9ps5B6Ph1307Fbn0/t6FA IJ/KFx03TEprdJdAGea42Z8o+YxGRCwbyZam/yzSGUdoQO03Mx1lIA1VFSFS01XUnobT lAZn/xsvyNaW+AO0cbEU6oAUG0HLU7ZVSGUbiSbSEWvax78x6YBBneEF5JrreHkphYIS urmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=WI/i8En7kEagnn6cKHHXseKEARZ4jrIgXbLLb4yMvtk=; b=SSNDUrE5eN/l2PqEXpoA++7asDGwNF8PVJPe+VlfZFMVYNV56zJ8NSIOMp//v4P0Sb NepoHVG962XWUxtnD8Od5nfIZ0nShByZwk7/aktGHSyTGD0yFtqBOjrBv7OlkVDwhKNR jcrOnMvcqCTCHe+H9tsEt640Dc8A5nZ6RiWrYrXFSPTCZfmds6Hm6S8v9IDJB/QZFv43 0eiBSdYs35hM1bMIEzvGyR/w4pqDPGlw9uRIilPD7KtYlWpTc02ZwMJLptzciJzJdVKi fHNB3ot8LOWnOoKY5XFTAxyI6c9YKtmqnhu3qqg6irlWjfM/i2XfzB43LsDiWKlXIrXg xAeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=rLo7nZwr; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id p13si929815ejx.192.2019.02.21.01.01.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 01:01:05 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=rLo7nZwr; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BB0EF294AA8 for ; Thu, 21 Feb 2019 10:01:04 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 69AA93EA1DB for ; Thu, 21 Feb 2019 10:00:55 +0100 (CET) Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 26462603451 for ; Thu, 21 Feb 2019 10:00:55 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id p19so2623553plo.2 for ; Thu, 21 Feb 2019 01:00:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ku8aYMwyBI0tAVhQgpsiM/AWo/PIHRtI4J3ODZmAkWU=; b=rLo7nZwrDhcTOizA9R6JhNLMqt164OUtXP4S5+sjE3DPmseuZ6PtQQUVONs5jGDi7w Xjfv+gRvgmkB7cL/TzMvI0zbzXT+Kc3i1UDmL2fR47VTvp6BtfEqBr1XfJFIHHFE/Ogp yHS0Uyot1jnBdnDBje9VWrLm4hbXfZhmATQaLt7Ckdrhq6sYF/iXd6IYUlVEn5iwdFZS BBx/DI9fm2RePSm4htJd95CGMha1WTtkeQHFzIrx2XYJ/U8SBQgbYOgp75LgcYF99Bxc ltlvibIniirI4ehq8ykbIwIE3eIla9lGFRsKGW1LPbV3X63o/7/ppY31Z5MKiXpLywRz XOYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ku8aYMwyBI0tAVhQgpsiM/AWo/PIHRtI4J3ODZmAkWU=; b=rKEuN8qB5sFFlFiBvNLuAj2xuD4UwkT+31Dsj6SLxZMZZA8IMwQlWIZdeZwCcitH5G yg9X78ZcGF0o+bN+kuhls9Ky74/dYwigczmQxPZgtjQQKOzggEwMJpXM5sZkV9DCRb5j Ml/5k94r9qsXIs/xxzBSsOdZxdtZ/D8akhmuXApu0beKkLsumkap15MTcEB6qts8cjWQ dCNS+lVsDgg90ZHKYcXj1M7Xq0rJvNR3J2jCa5ookTJGwK6NGY/v6cqsObuW5WgE/xbP JnrRgt0XraW9ppNU7CWf1cM6I3gHvhFRKQyp4cYmg5HkCH0CQxKBgotyvchN1+/h8hVD DDxg== X-Gm-Message-State: AHQUAubnAeMHb08vuVpdKt4kJpL2S10izEvpkqVg8WCBfnnVratyagc+ 75KvhxJgduLuyEaNI2lEUguMS0IaRaBHtA== X-Received: by 2002:a17:902:8e8b:: with SMTP id bg11mr42058317plb.332.1550739652466; Thu, 21 Feb 2019 01:00:52 -0800 (PST) Received: from localhost.localdomain ([117.252.69.94]) by smtp.gmail.com with ESMTPSA id v4sm27703948pff.77.2019.02.21.01.00.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Feb 2019 01:00:51 -0800 (PST) From: Sumit Garg To: chrubis@suse.cz, ltp@lists.linux.it Date: Thu, 21 Feb 2019 14:30:09 +0530 Message-Id: <1550739616-24054-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550739616-24054-1-git-send-email-sumit.garg@linaro.org> References: <1550739616-24054-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: daniel.thompson@linaro.org Subject: [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Split tst_fill_file() api to create new tst_fill_fd() api which could be used to fill file using fd and allows syscalls tests to operate on fd. Signed-off-by: Sumit Garg --- include/tst_fs.h | 9 +++++++++ lib/tst_fill_file.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/include/tst_fs.h b/include/tst_fs.h index 23f139d..b2b19ad 100644 --- a/include/tst_fs.h +++ b/include/tst_fs.h @@ -139,6 +139,15 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); int tst_get_path(const char *prog_name, char *buf, size_t buf_len); /* + * Fill a file with specified pattern + * @fd: file descriptor + * @pattern: pattern + * @bs: block size + * @bcount: blocks count + */ +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount); + +/* * Creates/ovewrites a file with specified pattern * @path: path to file * @pattern: pattern diff --git a/lib/tst_fill_file.c b/lib/tst_fill_file.c index 7baead8..f2bc52d 100644 --- a/lib/tst_fill_file.c +++ b/lib/tst_fill_file.c @@ -28,40 +28,46 @@ #include "test.h" -int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount) +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount) { - int fd; - size_t counter; + size_t i; char *buf; - fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); - if (fd < 0) - return -1; - /* Filling a memory buffer with provided pattern */ buf = malloc(bs); - if (buf == NULL) { - close(fd); - + if (buf == NULL) return -1; - } - for (counter = 0; counter < bs; counter++) - buf[counter] = pattern; + for (i = 0; i < bs; i++) + buf[i] = pattern; /* Filling the file */ - for (counter = 0; counter < bcount; counter++) { + for (i = 0; i < bcount; i++) { if (write(fd, buf, bs) != (ssize_t)bs) { free(buf); - close(fd); - unlink(path); - return -1; } } free(buf); + return 0; +} + +int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount) +{ + int fd; + + fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); + if (fd < 0) + return -1; + + if (tst_fill_fd(fd, pattern, bs, bcount)) { + close(fd); + unlink(path); + return -1; + } + if (close(fd) < 0) { unlink(path);