From patchwork Mon Oct 11 11:21:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1539227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=mWm50pSW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::439; helo=mail-wr1-x439.google.com; envelope-from=swupdate+bncbcxploxj6ikrbzn4scfqmgqegsfqmvy@googlegroups.com; receiver=) Received: from mail-wr1-x439.google.com (mail-wr1-x439.google.com [IPv6:2a00:1450:4864:20::439]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HSbx469vFz9sRN for ; Mon, 11 Oct 2021 22:22:16 +1100 (AEDT) Received: by mail-wr1-x439.google.com with SMTP id c4-20020a5d6cc4000000b00160edc8bb28sf7238066wrc.9 for ; Mon, 11 Oct 2021 04:22:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1633951333; cv=pass; d=google.com; s=arc-20160816; b=cT4dvYfFgBKBvbWoSrpXz7kYZtQ8GXttT+PB+Kwde6iCcwAaGMNrZSJFqBQxh0aPrH WhNagho7j5dh6HpcIM30uFwnQRT719wB/iOgwpRneAebgXby5JTFxawi46v42SoTnvaA gQcYilxaWauic3sgInwmOePr0Kw+UXTb5FpcCIdCiRZP1UZRKlrHqkQipIal9WoYxpry voAYsIzUvnaCgyT1wYrF4ct+ns7Xb9B9LDxNaTX9jQhTMIA8kcWzlbLeFbcp/S5clG3F lqxVk5mxxPsBVrTXia6Cq3rd8TbQfsI2hicf9tFvrYlqNEBjC2GFT06+5dnOBP/PIWJs n+Vg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=v6lIwzdp0i1eKGkN76jtRT229dHtTJIhggmtDsAUdbU=; b=ZmyIR2wvfvHHUHu/otKXarzu7MTWdSo7HnUyoK47VErbc5z2wzrdV6cnF/8nVhIGvw LANlkvNCXvxM+/lClvr583pCPEc8eLv0JOPRGPvBF40d1ZyvaFvrbU7kwWWt6PMQV3FT 2mA6K+l1kKRYED3bwXc69Ftr0vSb9txlyjx5dC5ysc1xFaLzhgAus4WV0V+YD6PJ4qZc MK9FXW+CQU5k16bZQOsWF5yWOeOVV8dj/oXUfonktOPUic1CrxAFZmvLSdD6NBO3F8TO //mYumGvanpyPMjW2Z6Z7CYMFiL0LJnjaK6jCEmIIgSIXRNGUUsUHos2k+7giFzMSrDq F0MQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=v6lIwzdp0i1eKGkN76jtRT229dHtTJIhggmtDsAUdbU=; b=mWm50pSW1lHj7BUlG3YQGea1DyH2Jqod1cOIJQxm7s7+fvxFc9Nsh3GDYJO8h1KhhZ WdtSkhpJJzZ0wo1wPidlQqXNa+IdW+gBQIJwXnbveYjHO2F7fyga84kVCKVaddJ+7eDw xVPEue2cm18X03OpWMY+wXJFuzRqlhRUrNL1UO6wl1n6AHRFToChc5liaould4fqmeeG hsFPOPjqBW+UGxM/quH+vpriH+dNygBr5oe5+HsIcxNNGgE55FTZgy50PK/Fek+yEHNR yicV8fievGeXr5JMnJmIEMhSL+2kN7qKbs7fEkR9vzV8vMdJS3jOq3Upzt7k5k159zZx aKhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=v6lIwzdp0i1eKGkN76jtRT229dHtTJIhggmtDsAUdbU=; b=TWi963BWxvFuHeww518vhCjDrWynyXYXPolraZrtTuzXgx50n6nrSbjwtxN0V82hgT FQgcp2k9mjlnjBwzOOw51zYUzQ9z5w95N1+6x/A0PbuMVMWYhYwdtJ1fYeM9pYWSN7XM aKs6IcNgVHqJokaVq3uBiMyh9m5mQh7sV5yTtfatFp9iFR8lMaxEtmO70bjeGjYxBhlL Eir7As+wQ31ir2AsC0C0caKrN8TAEXRQG9CXW/NvYchoFS8tz8of8hlvhnDHTjrBUDJz VwhHVo+3TYkqLeOKjOnL7OpsZKe+KsmDozpuOEqDhKK14jZ3e4/MiIRbYCVf42z/1BGa ShWA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533683TrKd3PKwZXwf6GsH9V9OO6oyP7Wmn2pfEQ5U9WoucJ8dmD OytbPbC/SsxQx6ffAj3pO/I= X-Google-Smtp-Source: ABdhPJx5SUfIztDAUSqhqmLTIOw2Xs2hckVJ3qV/BiMarBfhw16JqEA5s+5wUvAm4lyLpLaYwCz2Lw== X-Received: by 2002:a05:600c:1d0a:: with SMTP id l10mr1296196wms.46.1633951333389; Mon, 11 Oct 2021 04:22:13 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:600c:35cd:: with SMTP id r13ls358216wmq.2.gmail; Mon, 11 Oct 2021 04:22:12 -0700 (PDT) X-Received: by 2002:a1c:7911:: with SMTP id l17mr12328984wme.138.1633951332599; Mon, 11 Oct 2021 04:22:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633951332; cv=none; d=google.com; s=arc-20160816; b=Rv2jWaCW2e1Sclqh6AvUxXdsms4Q9LeG9pkU24VCb5WYtExOmiYRzvqWGp8ECib7py E5sPHi7ih7/9bZwZzZ5Xo7d0Q6ltoE9FYHV2w1Ndx8eC6crIuVHHpknrJefHE/Wn1d38 mwd1FzKDqD3dUWkGZcYABsSZVoyNioVE6fh5bBFQKN2fYg6qC4pFljDLC6+I1wIAACW+ FBvqLI3vx9uLUjzEZfA7HKn7Ugu/YT/+hHzCt61zs2fyHaI4NjakgVX6STYXQxOfZ0Y+ iJFjQFx2hDtAuar9kF0SbTU25tH/t9D1xKqVemb4HGBwHXKD8rVvRyMPK1FoafzK3Rlf 8Jvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Va7yFAnmv10dXQ2s5THX6ohh3bimkD64AqcXr5z7TUM=; b=tRJJaCyygOczrXOUgm8JTNN4iV+GP69Ie8LebuIDTunTtpiupKsD8BNIBe2xZGJyMS 1u1kVtZLvfaUMY/HIaiHDZ/rP34X/VTbN2rM9IuFIOREKGklXhoSTDEIjS3RmKkcf5Wb AFANWm4xNcCwAwSLU1XQfxA4xhJGOjHpPrGvDne3/g+AAmE/oO5xvJtJhv/JamldOU9w 4NC9ODb1ZrLZQU233wHPFHcVyszt0QvNE+t6ILayS9kzHclgmR5wAE+BvZSqV2/UTLCH KiXdgBp8Y0jUuUpxluQFNYQAjPJt2nkNy53efKi3qUkqJzMgZdaR6Pr2RomeWdKPdVYu huIA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.10]) by gmr-mx.google.com with ESMTPS id e2si525484wrj.4.2021.10.11.04.22.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Oct 2021 04:22:12 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4HSbx031lmz1sC06; Mon, 11 Oct 2021 13:22:12 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4HSbx02qsbz1qqkC; Mon, 11 Oct 2021 13:22:12 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id YrBgRGcucj8d; Mon, 11 Oct 2021 13:22:11 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Mon, 11 Oct 2021 13:22:11 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 137934541344; Mon, 11 Oct 2021 13:22:11 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2nUUgSFKGZdE; Mon, 11 Oct 2021 13:22:08 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id C2E8945413DC; Mon, 11 Oct 2021 13:22:03 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 03/29] Add utility function to detect filesystem Date: Mon, 11 Oct 2021 13:21:30 +0200 Message-Id: <20211011112156.44192-4-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211011112156.44192-1-sbabic@denx.de> References: <20211011112156.44192-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , This can be used to detect a filesystem from a device instead of specify the expected filesystem. Signed-off-by: Stefano Babic --- fs/diskformat.c | 28 ++++++++++++++++++++-------- include/fs_interface.h | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/fs/diskformat.c b/fs/diskformat.c index 0841f0b..8d58fc3 100644 --- a/fs/diskformat.c +++ b/fs/diskformat.c @@ -39,36 +39,48 @@ static struct supported_filesystems fs[] = { * Checks if file system fstype already exists on device. * return 0 if not exists, 1 if exists, negative values on failure */ -int diskformat_fs_exists(char *device, char *fstype) + +char *diskformat_fs_detect(char *device) { - char buf[10]; - const char *value = buf; + const char *value; + char *s = NULL; size_t len; blkid_probe pr; - int ret = 0; pr = blkid_new_probe_from_filename(device); if (!pr) { ERROR("%s: failed to create libblkid probe", device); - return -EFAULT; + return NULL; } while (blkid_do_probe(pr) == 0) { if (blkid_probe_lookup_value(pr, "TYPE", &value, &len)) { ERROR("blkid_probe_lookup_value failed"); - ret = -EFAULT; break; } - if (!strncmp(value, fstype, sizeof(buf))) { - ret = 1; + if (len > 0) { + s = strndup(value, len); break; } } blkid_free_probe(pr); + return s; +} + +int diskformat_fs_exists(char *device, char *fstype) +{ + int ret = 0; + char *filesystem = diskformat_fs_detect(device); + + if (filesystem) { + ret = !strcmp(fstype, filesystem); + } + + free(filesystem); return ret; } diff --git a/include/fs_interface.h b/include/fs_interface.h index 25c22e5..581f02a 100644 --- a/include/fs_interface.h +++ b/include/fs_interface.h @@ -7,6 +7,7 @@ #ifndef _FS_INTERFACE_H #define _FS_INTERFACE_H +char *diskformat_fs_detect(char *device); int diskformat_fs_exists(char *device, char *fstype); int diskformat_mkfs(char *device, char *fstype);