From patchwork Fri May 12 12:52:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1780589 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::43a; helo=mail-wr1-x43a.google.com; envelope-from=swupdate+bncbcxploxj6ikrba7n7cramgqe6sn5i2q@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20221208 header.b=o8U15w15; dkim-atps=neutral Received: from mail-wr1-x43a.google.com (mail-wr1-x43a.google.com [IPv6:2a00:1450:4864:20::43a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHpZJ4cTjz20KJ for ; Fri, 12 May 2023 22:52:23 +1000 (AEST) Received: by mail-wr1-x43a.google.com with SMTP id ffacd0b85a97d-30633999815sf3795338f8f.1 for ; Fri, 12 May 2023 05:52:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683895940; cv=pass; d=google.com; s=arc-20160816; b=XBqUh5BoyTjvHSBi7lip1E4OTBQmEQLTqzVwGTkCj3TE7iYr4hqWLYUZI06usfASen fGupdRvJ5OtMQsjp9IxW7v3elf9ZhnjwXp04BKvsVeqsU2WJoSx96AI01Tc6DQ2xJfIB Qp3hQiy+fMVb4KztMBUbV5GgwQFu+gfcjIyPSEoi8z/zybtntuqQ1taAjsqdgvOuaMrj D4xWIacnbOlO3QFMXjPh732W3KZh+mQr8OiUGYLkYvAcvdEuoSp2jIDeOX+jGxKsDYQq uNnUaZVntFdMSMYExmyyEKO0ykSaFP2FhjCnJG1iMocGEv+mt+uljopD9SsTn+/ileGb AAow== 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:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=O5toe8fzCt1IwuVIIqWMNDcAslKZ550QIrGYJl4/M1U=; b=cbWVVEL6kx0lq/cYvZ5U3sZUdAU9nKsKfvI78MSpZWAOTQ5sMFF1qLCrdlDpNSEgw1 7cSSf7FU1D6u5AE9muj5bJhtPkXBujCNKnrNAdLqlsUyk3VDIfRJBdc5CVyUKG4nSn4w bgfpHbrHGvokwn2GwJ5jrwNhgynVmtnyCKnyzhjZd5VPQZh9/7gu2pdBOLk/uPuUH28s 4Kdn9Ct3F3cpaIjh9sknCpqiXXtfYrz9YhFZPEHaH6jHw0xjVoZu5Z4sPQ0HfpVwdrUO LKoyde6rUdwzQ0RurCIomcgV42BYCrtois2fWYj3lwKpsiPImYABvfl1QOqdFVuLsKF8 mT5A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683895940; x=1686487940; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=O5toe8fzCt1IwuVIIqWMNDcAslKZ550QIrGYJl4/M1U=; b=o8U15w15tSZPtpm3GjqzdQzMJzhyFh2CpqQL/uNcjW6FRIzWKDstWlRBLUgbC0wsvm BVaZwWu9p69sDclHxjUjNs6Z8al8BVbutTKwA58PCc3uwrujhBNwxTU9gTF8JHYz0i3L PE2kbiM18Oz4tS2bO+K1kpz8LMPe5tLRljheZssDzPNn+IcrRI7GpFSGx8eCX0Lv4TNP zmMdWSoFTIqkzlRdVyBY35Uc8LsCdve3vVeMxLL8kUG/sNZM4mHhfk9wt+I6IZ5fYH+R tJNxjmywTloKI5Qqk2tn93gZCSJtEz92QD/0Kb8q6YXGkUc9PXoRSuPi/FUAKqYbC4R2 Icuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683895940; x=1686487940; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=O5toe8fzCt1IwuVIIqWMNDcAslKZ550QIrGYJl4/M1U=; b=MfpBz1EKa29ghtj+rDsKMTwEWCeC6MPerWmEK0o2h2qeosDcZnFbPpOAvmtEF6Z107 BecQ551X6QVqqjfEwcIHA1lR16yZqSex7WOmidf+p+TH+yoSncfn2YY1L6mxTHmRJxjc oiO78wf9RqPQJQ9C175aOroQvaSwJHsrOmvcNM8hTZaLO81tIX8pdnUOwKlqOUALV+Gq HeBpdNKa7tPqh/v4wx9fIkuCn1ac6Isnu2MkgbU9AeP8/C6erM2+EmSpZ0O26O6dygPP bKjKpm4AzY5ErderT7UB848AYWIeyD7OfPb2jqLNCH1kSnMwDhNgTHwpkv9XPJJ/FzbB jXYA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AC+VfDyqle3+Sd0sNgt9Ud8bWACsTlCAJMglxiO31yyd54sdgpbb1AeL S5wDsmBVeDrMwBzJViRJtqg= X-Google-Smtp-Source: ACHHUZ4VkjLIrKBosXFhzZaHcsSuHeXCA3TPnDR5GyMLfGCAsf+7a3tVlwU2LED+2hRbNswrSrhGmw== X-Received: by 2002:adf:de8d:0:b0:306:5a7d:7ca3 with SMTP id w13-20020adfde8d000000b003065a7d7ca3mr4111576wrl.8.1683895940271; Fri, 12 May 2023 05:52:20 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:600c:45c4:b0:3f0:b128:14c0 with SMTP id s4-20020a05600c45c400b003f0b12814c0ls370831wmo.2.-pod-control-gmail; Fri, 12 May 2023 05:52:18 -0700 (PDT) X-Received: by 2002:a05:600c:3b04:b0:3f4:2736:b5e6 with SMTP id m4-20020a05600c3b0400b003f42736b5e6mr10707228wms.14.1683895938839; Fri, 12 May 2023 05:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683895938; cv=none; d=google.com; s=arc-20160816; b=kU/ngO9Ku+8PW3fpez3mVZ0DMoNTV5k3JudhNZmxkNLU3lbkqIVytkiYwMQ3d09vPh 5nNfXwZrlynIsY5lnytZ0tNZ2BVCJ7d5UYvVeegK6R3Ok/WWQYsrXoBdTbArkm6wbhIx d6+3Jiklm2nlPIwAbpaxZlLcg8KafkLGDJD6hk0VlNavDMry9/yR5ojEPk9n/0kC+qQu RnqPpghIIef4zL3+1GiRxY/0HpJYCBBegPMV+Wanu8W0wy1d8rxMTaMzuNlkRQkgiYbv S1R4UGP69gHPw/IJEhJ7D8AN1u/cbglw8I2CBbxVw2giCa7drnTQAZZwwqvKe9ImVLHg Ae1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=Zm5SQMuEtQIAwC6q+KAMCRYn8P7jmpK3GgDE3HXcrZ0=; b=t5idxzhQxG9EWtGFDILf/XQ7lNBa68+NKAPW+A36N4np6+Tdts7uQEMqqM+7pTrqQW OUOCMRYohFrvEuIppWc0rK++StQkzDROqAXp0gTrVS4Y4lUsq6nvNTzCv6PfRLqC5ZlZ KGJmTOospPFpC3BYFsIb4SdzYrKzGWhXVSqTDO2G3HCap2XzssfhOpZhLqytRUE9X49l mUDjDeGMb+sW+DIasZwyeuW5OvE+c6CMmD77YUR66wY1JMht3dUgPz+aDH2Yx0Gbk5zu 4AAo00rGzwOZXOJTNQp8m2r8M7asKla/ZaHLdM6hmeEz8jTZh3bTc46S1Wdcfb3quIYu UxKQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id az37-20020a05600c602500b003f42786c7b4si1016121wmb.0.2023.05.12.05.52.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2023 05:52:18 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4QHpZB3HKrz1r1gP; Fri, 12 May 2023 14:52:18 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4QHpZB33rZz1qqlS; Fri, 12 May 2023 14:52:18 +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 wKia0PQkOaxx; Fri, 12 May 2023 14:52:17 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Fri, 12 May 2023 14:52:17 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 092DD4541350; Fri, 12 May 2023 14:52:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id RQIEGzZhu9yE; Fri, 12 May 2023 14:52:13 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 26E42454098F; Fri, 12 May 2023 14:52:13 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/2] diskpart: add support for btrfs filesystem Date: Fri, 12 May 2023 14:52:10 +0200 Message-Id: <20230512125211.160912-1-sbabic@denx.de> X-Mailer: git-send-email 2.34.1 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.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=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 allows to link with a modified version of btrfs-tools, that makes availale mkfs.btrfs as library and SWupdate can call it : https://github.com/kdave/btrfs-progs/compare/master...sbabic:btrfs-progs:swupdate Standard default parameters are taken, there is currently no support for btrfs tuning. Signed-off-by: Stefano Babic --- Kconfig | 4 ++++ Makefile.deps | 4 ++++ Makefile.flags | 4 ++++ fs/Config.in | 10 ++++++++ fs/Makefile | 5 +++- fs/btrfs.c | 52 ++++++++++++++++++++++++++++++++++++++++++ fs/diskformat.c | 3 +++ include/fs_interface.h | 3 +++ 8 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs.c diff --git a/Kconfig b/Kconfig index fb2e70f..0bf3ae1 100644 --- a/Kconfig +++ b/Kconfig @@ -65,6 +65,10 @@ config HAVE_LIBEXT2FS bool option env="HAVE_LIBEXT2FS" +config HAVE_LIBBTRFS + bool + option env="HAVE_LIBBTRFS" + config HAVE_LIBZEROMQ bool option env="HAVE_LIBZEROMQ" diff --git a/Makefile.deps b/Makefile.deps index 6486a2f..56028c5 100644 --- a/Makefile.deps +++ b/Makefile.deps @@ -66,6 +66,10 @@ ifeq ($(HAVE_LIBEXT2FS),) export HAVE_LIBEXT2FS = y endif +ifeq ($(HAVE_LIBBTRFS),) +export HAVE_LIBBTRFS = y +endif + ifeq ($(HAVE_LIBSSL),) export HAVE_LIBSSL = y endif diff --git a/Makefile.flags b/Makefile.flags index c44412d..0224a39 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -193,6 +193,10 @@ ifeq ($(CONFIG_EXT_FILESYSTEM),y) LDLIBS += ext2fs uuid blkid endif +ifeq ($(CONFIG_BTRFS_FILESYSTEM),y) +LDLIBS += mkfsbtrfs btrfs btrfsutil udev +endif + ifeq ($(CONFIG_UNIQUEUUID),y) LDLIBS += blkid endif diff --git a/fs/Config.in b/fs/Config.in index dae855a..df6c185 100644 --- a/fs/Config.in +++ b/fs/Config.in @@ -18,4 +18,14 @@ config EXT_FILESYSTEM comment "EXT2 / EXT3 / EXT4 file system creation support needs libext2fs" depends on !HAVE_LIBEXT2FS + +config BTRFS_FILESYSTEM + bool "BTRFS file system creation support" + depends on HAVE_LIBBTRFS + default n + help + Enable support for creating BTRFS file systems. + +comment "BTRFS file system creation support needs libbtrfs libbtrfsutil" + depends on !HAVE_LIBBTRFS endif diff --git a/fs/Makefile b/fs/Makefile index 0ffe4e1..c7ceef8 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -6,4 +6,7 @@ lib-$(CONFIG_DISKFORMAT) += diskformat.o lib-$(CONFIG_FAT_FILESYSTEM) += diskio.o \ fat_fs.o \ ff.o -lib-$(CONFIG_EXT_FILESYSTEM) += mke2fs.o \ +lib-$(CONFIG_EXT_FILESYSTEM) += mke2fs.o + +#lib-$(CONFIG_BTRFS_FILESYSTEM) += btrfs/hash.o btrfs/crc32c.o btrfs/btrfs.o btrfs/common.o btrfs/hash.o btrfs/xxhash.o btrfs/blake2b-ref.o btrfs/sha224-256.o btrfs/inode-item.o +lib-$(CONFIG_BTRFS_FILESYSTEM) += btrfs.o diff --git a/fs/btrfs.c b/fs/btrfs.c new file mode 100644 index 0000000..b7e2f87 --- /dev/null +++ b/fs/btrfs.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 Stefano Babic, sbabic@denx.de + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "util.h" +#include "fs_interface.h" +#include "pctl.h" + +extern int mkfs_main(int argc, const char **argv); +int btrfs_mkfs(const char *device_name, const char __attribute__ ((__unused__)) *fstype) +{ + int fd, ret; + int argc; + const char *argv[3] = { "mkfs.btrfs", "-f", NULL }; + + if (!device_name) + return -EINVAL; + + fd = open(device_name, O_RDWR); + + if (fd < 0) { + ERROR("%s cannot be opened", device_name); + return -EINVAL; + } + close(fd); + + optind = 1; + argv[2] = device_name; + argc = 3; + + ret = run_function_background(mkfs_main, argc, (char **)argv); + + return ret; +} diff --git a/fs/diskformat.c b/fs/diskformat.c index 8d58fc3..ed1f9f0 100644 --- a/fs/diskformat.c +++ b/fs/diskformat.c @@ -33,6 +33,9 @@ static struct supported_filesystems fs[] = { {"ext3", ext_mkfs_short}, {"ext4", ext_mkfs_short}, #endif +#if defined(CONFIG_BTRFS_FILESYSTEM) + {"btrfs", btrfs_mkfs}, +#endif }; /* diff --git a/include/fs_interface.h b/include/fs_interface.h index 581f02a..dabdec3 100644 --- a/include/fs_interface.h +++ b/include/fs_interface.h @@ -21,4 +21,7 @@ extern int ext_mkfs(const char *device_name, const char *fstype, unsigned long f const char *volume_label); #endif +#if defined (CONFIG_BTRFS_FILESYSTEM) +extern int btrfs_mkfs(const char *device_name, const char *fstype); +#endif #endif From patchwork Fri May 12 12:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1780590 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53c; helo=mail-ed1-x53c.google.com; envelope-from=swupdate+bncbcxploxj6ikrbaxn7cramgqenuejzgy@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20221208 header.b=DgYalAyZ; dkim-atps=neutral Received: from mail-ed1-x53c.google.com (mail-ed1-x53c.google.com [IPv6:2a00:1450:4864:20::53c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHpZJ4Pyqz1yfq for ; Fri, 12 May 2023 22:52:22 +1000 (AEST) Received: by mail-ed1-x53c.google.com with SMTP id 4fb4d7f45d1cf-50bca29a1desf11078367a12.2 for ; Fri, 12 May 2023 05:52:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683895939; cv=pass; d=google.com; s=arc-20160816; b=qlVuZjUxQu5D6ebb9L+0OrMNsAfGhXqqmF2erTC9urYml2C8XWOQtpYWHvo1YCnB0W yj+l3qWVBZ9wnVUWnCgjl/qJ/el7GxTbQQ53D2Yb5aqQh/GtA79wsHIfCkoB0dd2DHBx jyYbJrO5KoghOh3JRQuEptvdvPda0Zm06DWX6EpJoZu3sufI2tCcO5EGpShKR0U61vCJ sHqRumWiRJEdLBZYk79CDe1FF/siC0nZTOaYZvXpGz41eY0lNdb1KkmfZgBQmsduqwAk 3uZdvYuQIFRxHdiJaInOY5l8pcgBevES5CoRzrzfMsbzK6UCuuYh232coA7k02S9z3H9 2flA== 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=JxJBPJZXdrMvs3B2wNCf5klohheg6D2jpdQdSuHtmLw=; b=OBUImpcT78WLN18K8cCGpZ9zLA0FUH2yEkWa4t9XCJW+/f3q5aVnVlMpry/oDld/81 oNUDnBBYOmpztulRvJ5ES1bK1/R0koA6J2QntjmCTGszamSKvK3JOk+heKYJX9t61pBA o56IY263rEeQ3qgoxry4kpBrFFcYKV5vRKD51+gFXY1Xonp160i2hSvKmew/v28x6FGI rX0xg5apvDzJsRNbMpFbnYORT0rN9ur7DpudLf4Wna2urKpNBVTtKIZAInKM5Jo9Ftzt J2vRf4lAl7umNsPFBXadWe+0vGDr1q+Z2jYrBKLWs1vwTfUI7yYN8kwCYvp5BgFzki16 OCjg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683895939; x=1686487939; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=JxJBPJZXdrMvs3B2wNCf5klohheg6D2jpdQdSuHtmLw=; b=DgYalAyZp+yN4/MC2PK+GBuMbLEN7FhQBormA6NnoT3CUYf8Hxxzang8xpxGz1qnfl movVoZGlUrCMiNPxiKHJLmAGMju4TeFUOGxuoTIiQ+4eFFS/wAOoHvvAs+6oVu8EF1GD htiWnTaOeRH9dPaarCjwVhYBh9gt/+dbV6NViuDko7zQHLqLN8L9d8S8xaITFvMRpSWS 7MM9wQBof9KLsaBdigsISwVv+tgIgMOReCbOJZf8aoBbjDXpp6rzDuuoW7byUQk1tppH ndc3i58tSiC2A6aRHNpVv8WOdT6mlZGC+gNcBbYZIsn71D335ClNtMqx+JgwilFVQjTa y1/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683895939; x=1686487939; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=JxJBPJZXdrMvs3B2wNCf5klohheg6D2jpdQdSuHtmLw=; b=BZuwGFHc9bkqvoBcb9RVrqHhh0YuKJs3bm3dNA0/RiZVFQViBNEFMqn7lHng8nRkl3 /bxjcOQtLALhQo7X3gIa/FMzbLgQ8cDX4xzWUHQRhFy1zoTqsbwn6EIQ0IOH4RVezjq9 p6KOjQEpM+bLeLui3yD8ZCcU9dLPHCcAuQCzf8ngLtvC7ewi7AfB47R5hGdJdNnZQDSR 9MbHEzLXZoQHU21ZRieyROZzferYILTQKWsa2qf1ylqp50GyfrIYA0pEEUktMKhiCDFY uf9GyvtFcImIeA3YlE27xTJDgzPAdsGZn7J6zNB1ktZUH8cou6cMNA7HFemteliKlgL+ Tn8w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AC+VfDyLx6vn7cnhBFCwCfOkLVZ6aF9enhyF3ytkack1EaFtdFEb4nLc xtnLLtEoft3V1X6DGhdpPTs= X-Google-Smtp-Source: ACHHUZ719EmlVQEdzsjd+eaTLAe4oYw4J05pdnGNOLcH5D4jYD2kybaevKSquydTV0YVaW3GovIfIQ== X-Received: by 2002:a50:d09d:0:b0:50b:c79d:5201 with SMTP id v29-20020a50d09d000000b0050bc79d5201mr8909497edd.6.1683895939389; Fri, 12 May 2023 05:52:19 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6402:4d7:b0:50d:9cf2:645e with SMTP id n23-20020a05640204d700b0050d9cf2645els2881650edw.1.-pod-prod-05-eu; Fri, 12 May 2023 05:52:18 -0700 (PDT) X-Received: by 2002:a17:907:36c6:b0:94f:562b:2979 with SMTP id bj6-20020a17090736c600b0094f562b2979mr22025051ejc.31.1683895937971; Fri, 12 May 2023 05:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683895937; cv=none; d=google.com; s=arc-20160816; b=Lwye43J92w0oApoc0WjSD1TMhOCF32h1c8m5FqQ9GK1pSWUWBU3doQHrUrQt6/AiM2 ryFazm81n1Lf/qo3so7cQthfo/nVf2Azk0y17OGrB6L9tFU5q+M2STlyyBA+xFO4D2bb B9Lt/4aKuuPetYie6war0PZGYZwFFOFP+pxQFVfdHplQdyUC0dPT5P8tplbAeWS8AvEA UdTgD4JBXuoUxljtNkG37QmVGjOaMaeqkMo/hWEw5zYSKWHKC+q8wPLL1tXHVK8skWmr 2GhS4uTrTAkWA3X0qhNy/Iu2t4B2qanFnPFzlrtIWu70RdO8rMS982zihTz3GaZ3tlB9 VxPw== 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=QH8SFp9Lux/gwKvAkRmIlDLD2dzDNg9pjVFVjIot/Fo=; b=CBTYhDucobc+zoNdazIkxz4XU7qp43UZEUVawvDFY9bM1+9cMohNKPD916AL50i0Do x5W+MhMmcBrMXIXS5934nwkJ/P0hmbez4qKL1pWH/4xb3WdH+SiCqs7H/AIrZ1Lm3Pst LZdbZGpbKGNxi+AEx8rH1HL/Jg1SP3HTC4+zlNs3XfUMAAwvcjN9rUu3tzVRJqX/aY01 tRITQlUF9+uAzpJN3e46UdrAFfPX90KQE4hTkDTvoYgUe+6uH5zau3OTH9cbs6SM8Sqy 5Gv3/mRV0cbalddACN/4GWSuQzTJX3LIo1Od9G+XsmZxEysqiK+MY7yAuVwx1akHWSIV XxxQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=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 ci17-20020a170906c35100b00965600719e4si985116ejb.1.2023.05.12.05.52.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2023 05:52:17 -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 4QHpZ955Qtz1s953; Fri, 12 May 2023 14:52:17 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4QHpZ94K75z1qqlS; Fri, 12 May 2023 14:52:17 +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 0wO8-Rscf2zT; Fri, 12 May 2023 14:52:16 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Fri, 12 May 2023 14:52:16 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id F0BDD4541370; Fri, 12 May 2023 14:52:15 +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 kr3iLhO-1GOH; Fri, 12 May 2023 14:52:13 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 38FA04541350; Fri, 12 May 2023 14:52:13 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 2/2] handler: handler for operation on BTRFS Date: Fri, 12 May 2023 14:52:11 +0200 Message-Id: <20230512125211.160912-2-sbabic@denx.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512125211.160912-1-sbabic@denx.de> References: <20230512125211.160912-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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=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: , Add an handler that works as wrapper for libbtrfsutil and add support to sw-description. Creation / deletion of subvolumes are supported. Signed-off-by: Stefano Babic --- doc/source/handlers.rst | 27 +++++++++- handlers/Makefile | 1 + handlers/btrfs_handler.c | 105 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 handlers/btrfs_handler.c diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 1ee09e0..06999e6 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -985,7 +985,8 @@ supported: | fstype | string | Optional filesystem type to be created on the | | | | partition. If no fstype key is given, no file | | | | will be created on the corresponding partition. | - | | | vfat / ext2 / ext3 /ext4 file system is supported | + | | | vfat / ext2 / ext3 /ext4 / btrfs | + | | | file system is supported | +-------------+----------+----------------------------------------------------+ | partuuid | string | The partition UUID (GPT only). If omitted, a UUID | | | | will be generated automatically. | @@ -1152,6 +1153,30 @@ found on the device. It is a partition handler and it runs before any image is i } }); +BTRFS Handler +------------- + +This handler is activated if support for BTRFS is on. It allows to created and delete subvolumes +during an update. + +:: + + partitions: ( + { + type = "btrfs"; + device = "/dev/loop0p1"; + + properties: { + command = < one of create" or "delete" > + path = ; + mount = "true" or missing; + } + }) + + +If `mount` is set, SWUpdate will mount the device and the path is appenden to the +mountpoint used with mount. If device is already mounted, path is the absolute path. + Delta Update Handler -------------------- diff --git a/handlers/Makefile b/handlers/Makefile index 847d59f..b5203f9 100644 --- a/handlers/Makefile +++ b/handlers/Makefile @@ -10,6 +10,7 @@ obj-y += dummy_handler.o chain_handler.o obj-$(CONFIG_ARCHIVE) += archive_handler.o obj-$(CONFIG_BOOTLOADERHANDLER) += boot_handler.o +obj-$(CONFIG_BTRFS_FILESYSTEM) += btrfs_handler.o obj-$(CONFIG_COPY) += copy_handler.o obj-$(CONFIG_CFI) += flash_handler.o obj-$(CONFIG_DELTA) += delta_handler.o delta_downloader.o zchunk_range.o diff --git a/handlers/btrfs_handler.c b/handlers/btrfs_handler.c new file mode 100644 index 0000000..517f753 --- /dev/null +++ b/handlers/btrfs_handler.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2023 + * Stefano Babic, DENX Software Engineering, sbabic@denx.de. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include +#include +#include +#include +#include +#include "fs_interface.h" +#include "progress.h" +#include "swupdate_image.h" +#include "handler.h" + +typedef enum { + BTRFS_UNKNOWN, + BTRFS_CREATE_SUBVOLUME, + BTRFS_DELETE_SUBVOLUME +} btrfs_op_t; + +void btrfs_handler(void); + +static int btrfs(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + int ret = 0; + btrfs_op_t op; + enum btrfs_util_error btrfs_error; + + char *subvol_path = dict_get_value(&img->properties, "path"); + char *cmd = dict_get_value(&img->properties, "command"); + char *globalpath; + char *mountpoint; + + op = IS_STR_EQUAL(cmd, "create") ? BTRFS_CREATE_SUBVOLUME : + IS_STR_EQUAL(cmd, "delete") ? BTRFS_DELETE_SUBVOLUME : BTRFS_UNKNOWN; + + if (op == BTRFS_UNKNOWN) { + ERROR("Wrong operation of btrfs filesystem: %s", cmd); + return -EINVAL; + } + bool tomount = IS_STR_EQUAL(dict_get_value(&img->properties, "mount"), "true"); + if (tomount) { + if (!strlen(img->device)) { + ERROR("btrfs must be mounted, no device set"); + return -EINVAL; + } + globalpath = alloca(strlen(get_tmpdir()) + + strlen(DATADST_DIR_SUFFIX) + strlen(subvol_path) + 2); + sprintf(globalpath, "%s%s", get_tmpdir(), DATADST_DIR_SUFFIX); + mountpoint = strdupa(globalpath); + DEBUG("Try to mount %s as BTRFS", mountpoint); + ret = swupdate_mount(img->device, mountpoint, "btrfs"); + if (ret) { + ERROR("%s cannot be mounted with btrfs", img->device); + return -1; + } + globalpath = strcat(globalpath, subvol_path); + } else + globalpath = subvol_path; + + DEBUG("%s subvolume %s...", (op == BTRFS_CREATE_SUBVOLUME) ? "Creating" : "Deleting", subvol_path); + switch (op) { + case BTRFS_CREATE_SUBVOLUME: + btrfs_error = btrfs_util_create_subvolume(globalpath, 0, NULL, NULL); + break; + case BTRFS_DELETE_SUBVOLUME: + btrfs_error = btrfs_util_delete_subvolume(globalpath, BTRFS_UTIL_DELETE_SUBVOLUME_RECURSIVE); + break; + default: + btrfs_error = BTRFS_UTIL_ERROR_FS_INFO_FAILED; + break; + } + + if (btrfs_error != BTRFS_UTIL_OK) { + ERROR("BTRFS %s failed with btrfs error : %s", cmd, + btrfs_util_strerror(btrfs_error)); + ret = -1; + } + + if (tomount) { + /* + * btrfs needs some time after creating a subvolume, + * so just delay here + */ + sleep(1); + swupdate_umount(mountpoint); + } + /* + * Declare that handler has finished + */ + swupdate_progress_update(100); + + return ret; +} + +__attribute__((constructor)) +void btrfs_handler(void) +{ + register_handler("btrfs", btrfs, + PARTITION_HANDLER | NO_DATA_HANDLER, NULL); +}