From patchwork Wed Feb 24 12:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Gaudig X-Patchwork-Id: 1443854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23b; helo=mail-lj1-x23b.google.com; envelope-from=swupdate+bncbaabbxez3gaqmgqejjste5i@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=lc0FTCCt; dkim-atps=neutral Received: from mail-lj1-x23b.google.com (mail-lj1-x23b.google.com [IPv6:2a00:1450:4864:20::23b]) (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 ozlabs.org (Postfix) with ESMTPS id 4Dlwrz4X0Bz9sBy for ; Wed, 24 Feb 2021 23:56:00 +1100 (AEDT) Received: by mail-lj1-x23b.google.com with SMTP id m13sf487819ljb.19 for ; Wed, 24 Feb 2021 04:56:00 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1614171356; cv=pass; d=google.com; s=arc-20160816; b=QagjlFvlvz+KfDcNGvlRvuK4aXzXVsN65eV0A9HROxc5Sjtya9YuV3eXXnetsXrj6A ZhHhkdySAgWpIDYmlQ2lSijOqKQRg7hpj5bPDAEgFmCST0RQO3dkxPcWp4HaToq4rztj avRN4hDOkwaPNpIec6lsY2V3AN/PUPU8UjyjG98J6tyL/uNCGZUO8BJK1vX8LPUuLbWN Q4EkbrpsN4FwoUzcW8a4VCRwzdk6MCu/Dv70CcY1conxIGVceEYjN+ExqSq9urhYj0/N YinWKG2/xUZl1D8xvAErAeMO3/HPFjHCeCsp2QSO38o3G1JCbCzqib5/eP2XuTmBGbL5 yI7A== ARC-Message-Signature: i=3; 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=ZSA8FldcZkXMWXkuMMXQN/iA0ETljbTvDyn9NB4vXrA=; b=VIHEr4U8wPuXsyJ7GRdBlHCMlbjo15sgMWnpELNy59FxXp+sFJvabUdvYgoV4V1iS+ kkPJWCMEJ3uoM1owtcXShWrv5jc5SO9pWma+XgdGzCfdbxG0yB5AJ19G9kjneynfjYD1 kI/KLI70QyfPV0+5Okwr18YtTsMk2TPhnTg/SV5eA4o0gfLt77gzi59y5XVNKWFyCx6G j9PcXJeCf4MQh3sdWFnK3OTdIT/1fCuFfEpnM6FiOPjwnJnn0VW88fuKa7UPbkBCiGXQ 4pXN0ip8uN54DrAmcOkW5wl9vIQNPw25t+RfBuP2HhyOdOQIMVicBp1OBhJrPnD+Pcno 4pBA== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@weidmueller.onmicrosoft.com header.s=selector1-weidmueller-onmicrosoft-com header.b=GdWaGrSm; arc=pass (i=1 spf=pass spfdomain=weidmueller.com dkim=pass dkdomain=weidmueller.com dmarc=pass fromdomain=weidmueller.com); spf=pass (google.com: domain of roland.gaudig-oss@weidmueller.com designates 40.107.14.44 as permitted sender) smtp.mailfrom=roland.gaudig-oss@weidmueller.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=weidmueller.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id: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=ZSA8FldcZkXMWXkuMMXQN/iA0ETljbTvDyn9NB4vXrA=; b=lc0FTCCtqlWKcWxto/PVV0zY4Kn8BCY4cywPQCzxHa+aimesYAxnX7La7UQUebIvH6 hhPcexh3pGMbuSx9mic4WA1C22ET85K9I/zx5LAADi5SdsDn8jFK/ET3evjkvqCF4f4x e2uv5LB3g6VenZeFa4UFkKoA9h3JJw56sJG5BhngQKHwpzGitx5dnGfvxQKAywTGpbzQ G6XJY9Sa6raPxiUAupc3528G3zDqwi8yY33rvFbnTwBfiUH1v6GPs632fyV/SmjtUvwU 9PE8SN8VBp54OmPk4TX2/DV4KFPgBT6jmv93GEzn0GIC2hlaeseVQ3IYU0eT0kGGjYtI ihFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :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=ZSA8FldcZkXMWXkuMMXQN/iA0ETljbTvDyn9NB4vXrA=; b=KgJW5E82MnuXbTKfVC3V2QBNYthh1Ji1lbbkEhYKK+u6c4EVqIOmMZLRfzzHguByrl JG5hak8IcMoWv8bmES6gIifwV3HlB/boh+Fm0MtlxnAXcWqxMtUeB+hMwTegre5I2A8M d2zDPE4w/aB2VTV/3kqJtPntPnckFnL+RpnsoY00d+H6MS+8w2Z011ojumEut36+6VO6 fk9/AJz3cTfTuHkFxdLgt05yWL5fzUQYEMkD1+W7a4L91jd/krvo7tJQPySohLTN/CzL r3rTD9CCWcuTmXWOKP65ScHjVAlR1fSTdIUtKoIIARyAWStsez/E15nj/tqu/XPKulYc dcmA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532NcAgHFsqZ4aE7fxO4qop6hy3MwwmF3Yex0JAfjOEhLCKht3lf TkJxaE15elcIt+KsCSOAvG4= X-Google-Smtp-Source: ABdhPJwiEv64sH6vWlz7xw+NySXVPVUm6oeClKtru/CQtTYAcoN7+9785yv7yAA0WFBh4yK8DUaQ5w== X-Received: by 2002:a05:6512:b07:: with SMTP id w7mr20966131lfu.345.1614171356596; Wed, 24 Feb 2021 04:55:56 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:ac46:: with SMTP id r6ls1605858lfc.2.gmail; Wed, 24 Feb 2021 04:55:55 -0800 (PST) X-Received: by 2002:ac2:43b0:: with SMTP id t16mr4163519lfl.351.1614171355705; Wed, 24 Feb 2021 04:55:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1614171355; cv=pass; d=google.com; s=arc-20160816; b=W4+fBA0WwYtFNnsXzOIjYUpyyo/CYYXrNu1FcYhBROC5xqBEHUkFT+hFi+MQdX60oc je/iJ2xdt9aNpOchWl5/jkxp8fAAHWjVK9ITf9dHfZN7ElbQdru7/HMIfKphWMFTA0Jx szyuYkEhLK1KpSFKR0ehUcQarqzzvnDallP0rVhcgIt5Nh4a1aDtPP6GywgLlY7OApom w7mYerrTnbdO3OVjQ0aHmf/PvY5/FQNqp35+T8/oriYfOJyiZFY/QfV2UrymzMAhchCZ +kGLGrE0Xbl5vKR6KvIIxqGY1lD+LITKPUMp5cM8msG4/yj+xwlUXrGTxIhBZHFv0do1 E2dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:message-id:date:subject:cc :to:from:dkim-signature; bh=wGQJ2MW385PZ5VLFyhB2nGrGCMm8iecmrMYRLlUs4A8=; b=CdX6nc8+kP9IpPFZhj2nm+2Cd5T+324MqErFAoLfUHT3agsc927W/nZcecN3yEwIby GwunnKp6nGdDY2wA3bSqShS3krBvPT0q+dQOupdYqV4rEZNyxg5wX699J+qAKp3eNFqt dfsQygjYYdZk1ObNq+bNNJQpaedVzX+GS8Nlz5s5I1ZsSE5WNNxik/2/l3J3gzN4478w AJGqD+hR4kAuFcJELexmwr8oBwLUUP+GLrypmI6ZgVLbnYqV5nCYJq5gL3yfbdWlD7Al /MTNurMPGp6rmHLvPehCkCVbPIfbwPP/ZMT46oiRYnke6C0sUlEl0lCd0Jwb+CTaASYj HExw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@weidmueller.onmicrosoft.com header.s=selector1-weidmueller-onmicrosoft-com header.b=GdWaGrSm; arc=pass (i=1 spf=pass spfdomain=weidmueller.com dkim=pass dkdomain=weidmueller.com dmarc=pass fromdomain=weidmueller.com); spf=pass (google.com: domain of roland.gaudig-oss@weidmueller.com designates 40.107.14.44 as permitted sender) smtp.mailfrom=roland.gaudig-oss@weidmueller.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=weidmueller.com Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140044.outbound.protection.outlook.com. [40.107.14.44]) by gmr-mx.google.com with ESMTPS id c6si111326ljk.2.2021.02.24.04.55.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2021 04:55:55 -0800 (PST) Received-SPF: pass (google.com: domain of roland.gaudig-oss@weidmueller.com designates 40.107.14.44 as permitted sender) client-ip=40.107.14.44; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TXzUvEjNxLwEtUVQ89EFPuNr008+z8v5a5CTinEmeMRxH2LhR1ky6zYv1yl2hA//EJhvrclorKsUi3WVmEKXxipdjuUC9UahvBMSv6bX0NpczQUjJBcsdsX4xEWZ+jn+39DY9FLMSHRllxBRqj6xVlp4VCrfXVrFymbUZQA2onRS0uPS5mlu07qsLeXoESvKmHcysqd9+7CFginFIwRRaMHO56pjSpvY2da0RCATP80kVTv1WzmIEpJkoiMzqaJsbkHziGIO9NjepmzMN/7+DR+BmsymEHP0VOlmweqwnL6gwPIIoW2E3lPWKLU+rgukWBqBcoAT4YgqbM/wpb6MPg== 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-SenderADCheck; bh=wGQJ2MW385PZ5VLFyhB2nGrGCMm8iecmrMYRLlUs4A8=; b=UtmrCOpcYRe4K5JPkiwZR0xrdmJFCREF1ODu8fpBDpIsGqzynftZAdrh69ou4xTV+mSC5aQ/nR68wVU+d4myLgGPMCJDVSADx9+IRzuoM1bJBHPtNj9oVIGLgRLLhpW8AR2j76RWVQLHzvrfDMe98JuhJGpSoBv7sJ50QRx3IO9vv7yxtAwnW15T9J7ZPKpjXIZ5W3jhwnSAJe/kM50kD1ZqB8Wfb25BNuGMvysxYg70ZOR4EHkEWfpcD1jxGMA/Pao1opohl+wCnvBcOtwTmRfJKBdeMVn0k17YRbh8n/k1cYJyypeEeWkrK5cup0MlsuHkv5kdHrzX8vcx2FCjDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=weidmueller.com; dmarc=pass action=none header.from=weidmueller.com; dkim=pass header.d=weidmueller.com; arc=none Received: from DB9PR08MB6729.eurprd08.prod.outlook.com (2603:10a6:10:2ac::15) by DB6PR0801MB1639.eurprd08.prod.outlook.com (2603:10a6:4:3b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27; Wed, 24 Feb 2021 12:55:53 +0000 Received: from DB9PR08MB6729.eurprd08.prod.outlook.com ([fe80::f50d:de2c:9666:b097]) by DB9PR08MB6729.eurprd08.prod.outlook.com ([fe80::f50d:de2c:9666:b097%7]) with mapi id 15.20.3868.034; Wed, 24 Feb 2021 12:55:53 +0000 From: roland.gaudig-oss@weidmueller.com To: swupdate@googlegroups.com Cc: Roland Gaudig Subject: [swupdate] [PATCH] handlers: add filesystem handler Date: Wed, 24 Feb 2021 13:55:34 +0100 Message-Id: <20210224125534.27259-1-roland.gaudig-oss@weidmueller.com> X-Mailer: git-send-email 2.25.1 X-Originating-IP: [84.138.69.37] X-ClientProxiedBy: AM0PR01CA0101.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::42) To DB9PR08MB6729.eurprd08.prod.outlook.com (2603:10a6:10:2ac::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from DE12086.weidmueller.com.com (84.138.69.37) by AM0PR01CA0101.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Wed, 24 Feb 2021 12:55:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6dd1e1e6-2436-4344-e164-08d8d8c384f6 X-MS-TrafficTypeDiagnostic: DB6PR0801MB1639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IB70zN2lLOWaINs59EXT/iufYaH8eIGf8zUSI3bmhSHslqRX33H/DSLir8bKitjzYVu82xhAzrh6h/VntpGQreKg8Ds7rKZqDHRpAIPiG5o6EDQWjrAfShfOPl5JKzKA9BYpOiDKvs163r+1hoSKADa9Grpkr14AR7yTR+u92U2SB5ata58nx1DD9pkSIIu3f77kUtFrKybB8t3Y/bccxwQG9CJcTqL+4LHIo5ohMk+3ChftvmIoSTzNWLOKts9cE+WYqygk3b8kGibH6XMyov2Pgbtl0x6PCVuSP5fuemvlT4rDRlH/y0+VUJAM+4hAo8r8zG2I2ckejGAVAZhUsglTWIMcfq6tg3QwlEJ5S0ebHc/BJfjn9MflnyuDDmhTOdRT0nkIMBZFuYIDK8V63jO3HcAY6znPim7XhLstsXbYSIvQAQoXyClb8TMUbMWMLlsxWneG2fP2u0x4WX4KXr5XqY9knq00iqwbEMMtBpFgoxwnZ1RbBK5CEdzkhu3Rl6YCf3M1Brkza4bdbHL1dw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR08MB6729.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(39850400004)(396003)(346002)(366004)(6512007)(6666004)(9686003)(16526019)(4326008)(2616005)(66946007)(7696005)(5660300002)(956004)(8676002)(6486002)(6916009)(6506007)(478600001)(66476007)(107886003)(66556008)(86362001)(2906002)(186003)(8936002)(52116002)(1076003)(316002)(36756003)(26005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: E9nYCLbZcpkePJxDC0+2tiCy9YxUbHVcUdXOE8vPM4VR+/Y/ZtQiKGz7OLRj3QuoPasbl1qB6ekVxBwukGkm4MvOVhyUjCcECuaWIOnkv2rn1WnA5veOhLfHuZIi8uNAAF2F+hUQNx47OfhHLOKo4po6fmuXUK+nGWyqIwyVeB5Cir+tjKn4mgMEiATqq1V9RlBEUqkrk9OFVR1gwh93vlzo6hwodAa6VFfbzrzOiGGVaglT610TeHgDV3pFq67XhCbdOXLXmI6ZXdSeWG9GSUVkMftrJFgoOKQ6roT4UMNOXMIXap9w+wpA+MdFQysbRAjQlK66B35cJdqhH4upsx9cRHsKqtKZ/Ih8mZBX61yedY3whC9orAjOM4YjG5/WNVAY8+ji4CrhG4jDWL6ZOCdXfT1x0B3c5g0WPN9hEnffHMRUiAVtdvY//R4xA9fTujCRd5KGfAqj0FWQ55uJ2x2n2Uxy72aClbFCpfOAJcPYnGe4mGYOg5vmYwTFrx/lQuQ6aJs+5nNXZGQd/2V68SFnZ5qCpBixuoFbRPLlLW/h7fnlbpY8pvlefEKR57kbktcSP5phIsFZqusxM4RlC9lgtxcifkAOW+VtQ31waVN4bXwD7I3ymNWoOP6UmLYE/oJlxiuScBCDK0WQyXPjlJIbnn9HoHQDuLlVZOh4BEHXQ5ccDKOamRo2JW+G1s7CzIp7U/S/GpE4o5UnRI2qbL+xmPr3zCKNWJZNoH4T2ZJp1r+ZUN578pVeoRcDtUOx/waXBPwYZSgVQPc4+j8hBmixpTk1f7yRTeRo6IMp6hLrCqPmOutvOrmr3gB4fACjYL/5fUKTKQO85Vq8Ksm/7xjPZBRMcKhPliC8sin3nykmmi795rwfR+MU7fMca48tuywWpcYww+EBApGzUP6Sof29ZJj+aD0++eq7SQQFxSG7GOJ4PyrZrJ7Kp1KGzj/fyWsQCXeMyt+YWvQ5ZO1Iy08PEeQXq+Yv/2ZbMvVJSoWElhNuwGuTBelnXu/suodLot0/HpmmX2g6LFlT9I74OM15Yr7N0/6++yqv4Ke/uqki7R2bv6paZ/PuMy2j8PWiXFL3NW78EXD0nOBdGE8fvW4zRvgZuO6NErmEVkPjSd5c8UkW6fjjdkjCVYjLTT+W/rkTjvZo3yLFtfgW19mY1+pkoyZ96qGLAwh9GMgQjSp487LdZq5Rps/0Q0NrRgQOPNZEDypcse6lpRqQJFzeprimL5hmwm+rT+edUFWrjBgTgNamwx/XBO/JL8+3s8gTKOyxwS5JEhje1YSwRdrwiFp+9ot5SVcmtPCr9KSg19Ya9XmypNivKfmGrUVDf9OU X-OriginatorOrg: weidmueller.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6dd1e1e6-2436-4344-e164-08d8d8c384f6 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB6729.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2021 12:55:53.5442 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e4289438-1c5f-4c95-a51a-ee553b8b18ec X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: H69hneeCnCqf306Z7IpRo0yb9HoEG2qNgB4ZYEdF5wJy/nblQ87GUUedZRwhKE3t4oqEAf8w9N8ZWua62h2IUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1639 X-Original-Sender: roland.gaudig-oss@weidmueller.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@weidmueller.onmicrosoft.com header.s=selector1-weidmueller-onmicrosoft-com header.b=GdWaGrSm; arc=pass (i=1 spf=pass spfdomain=weidmueller.com dkim=pass dkdomain=weidmueller.com dmarc=pass fromdomain=weidmueller.com); spf=pass (google.com: domain of roland.gaudig-oss@weidmueller.com designates 40.107.14.44 as permitted sender) smtp.mailfrom=roland.gaudig-oss@weidmueller.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=weidmueller.com 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: , From: Roland Gaudig Signed-off-by: Roland Gaudig --- This patch introduces a handler for creating file systems on spare partitions. It checks if the desired filesystem exists. In case it doesn't the file system will be created. In case there is already a filesystem of the desired type on that partition, nothing will be changed. doc/source/handlers.rst | 20 ++++++ doc/source/sw-description.rst | 5 +- handlers/Config.in | 7 ++ handlers/Makefile | 1 + handlers/filesystem_handler.c | 120 ++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 handlers/filesystem_handler.c diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 07fb6c2..f9b4fbc 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -857,3 +857,23 @@ found on the device. It is a partition handler and it runs before any image is i "18e12df1-d8e1-4283-8727-37727eb4261d"]; } }); + +Filesystem Handler +------------------ + +This handler checks if the device already has a filesystem of the specified type. +If the filesystem does not yet exist, it will be created. + +:: + + scripts: ( + { + device = "/dev/mmcblk0p1"; + type = "filesystem"; + filesystem = "vfat"; + }, + { + device = "/dev/mmcblk0p2"; + type = "filesystem"; + filesystem = "ext2"; + }) diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index fd8bd11..98001d9 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -1242,8 +1242,11 @@ There are 4 main sections inside sw-description: | | | | rootfs will be used. | +-------------+----------+------------+---------------------------------------+ | filesystem | string | files | indicates the filesystem type where | - | | | | the file must be installed. Only | + | | | scripts | the file must be installed. Only | | | | | used if "device" attribute is set. | + | | | | In combination witht the filesystem | + | | | | handler it indicates the filesystem | + | | | | which shall be created. | +-------------+----------+------------+---------------------------------------+ | path | string | files | For files: indicates the path | | | | | (absolute) where the file must be | diff --git a/handlers/Config.in b/handlers/Config.in index 8571c0c..a646610 100644 --- a/handlers/Config.in +++ b/handlers/Config.in @@ -99,6 +99,13 @@ config DISKPART help Handler to partition a disk, eMMC or SD +config FILESYSTEM + bool "filesystem handler for creating file systems on empty partitions" + default n + help + The filesystem handler checks if a partition already contains the + specified filesystem. If not, the file system will be created. + comment "diskpart support needs libfdisk" depends on !HAVE_LIBFDISK diff --git a/handlers/Makefile b/handlers/Makefile index 1449139..c0d78b6 100644 --- a/handlers/Makefile +++ b/handlers/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_ARCHIVE) += archive_handler.o obj-$(CONFIG_BOOTLOADERHANDLER) += boot_handler.o obj-$(CONFIG_CFI) += flash_handler.o obj-$(CONFIG_DISKPART) += diskpart_handler.o +obj-$(CONFIG_FILESYSTEM) += filesystem_handler.o obj-$(CONFIG_UNIQUEUUID) += uniqueuuid_handler.o obj-$(CONFIG_CFIHAMMING1)+= flash_hamming1_handler.o obj-$(CONFIG_LUASCRIPTHANDLER) += lua_scripthandler.o diff --git a/handlers/filesystem_handler.c b/handlers/filesystem_handler.c new file mode 100644 index 0000000..f7ba3ee --- /dev/null +++ b/handlers/filesystem_handler.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2021 Weidmueller Interface GmbH & Co. KG + * Roland Gaudig + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +#include "swupdate.h" +#include "handler.h" +#include "pctl.h" +#include "util.h" + +void filesystem_handler_init(void); + + +static int filesystem(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + char *lbltype = img->filesystem; + int ret = 0; + char command[SWUPDATE_GENERAL_STRING_SIZE]; + int len; + int exit_code; + + if (!data) + return -EINVAL; + + script_fn scriptfn = *(script_fn *)data; + + /* + * Run only in case of pre-install + */ + if (scriptfn != PREINSTALL) + return 0; + + if (!strlen(img->device)) { + ERROR("File system handler requires setting \"device\" attribute"); + return -EINVAL; + } + + if (!lbltype) { + ERROR("File system handler requires setting \"filesystem\" attribute"); + return -EINVAL; + } + + /* Check if filesystem exists */ + len = snprintf(command, SWUPDATE_GENERAL_STRING_SIZE, + "fsck.%s -n %s", lbltype, img->device); + if (len < 0) { + ERROR("File snprintf"); + return -1; + } + + if (len > (SWUPDATE_GENERAL_STRING_SIZE - 1)) { + ERROR("Path name to device is to long"); + return -1; + } + + TRACE("Check if %s file system exists on %s ...", lbltype, img->device); + exit_code = run_system_cmd(command); + + if (exit_code == -1) { + ERROR("Could not run %s", command); + return -1; + } + + if (exit_code == 127) { + ERROR("fsck.%s not found, %s filesystem not supported", lbltype, lbltype); + return -1; + } + + if (exit_code == 0) { + TRACE("Found %s file system on %s", lbltype, img->device); + return 0; + } + + if (exit_code > 0) { + /* File system does not exist, create new file system */ + TRACE("Creating new %s file system on %s", lbltype, img->device); + len = snprintf(command, SWUPDATE_GENERAL_STRING_SIZE, + "mkfs.%s %s", lbltype, img->device); + + if (len < 0) { + ERROR("File snprintf"); + return -1; + } + + if (len > (SWUPDATE_GENERAL_STRING_SIZE - 1)) { + ERROR("Path name to device is to long"); + return -1; + } + + exit_code = run_system_cmd(command); + + if (exit_code) { + if (exit_code == -1) { + ERROR("File could not run %s", command); + return -1; + } else { + ERROR("Couldn't create %s filesystem on %s", + lbltype, img->device); + return -1; + } + } + } + + return ret; +} + + +__attribute__((constructor)) +void filesystem_handler_init(void) +{ + register_handler("filesystem", filesystem, + SCRIPT_HANDLER | NO_DATA_HANDLER, NULL); +}