From patchwork Thu Jun 16 12:40:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe REYNES X-Patchwork-Id: 1644308 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=M1CDgU2f; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13b; helo=mail-lf1-x13b.google.com; envelope-from=swupdate+bncbds5hgup7qgbbxojvskqmgqesowvcsq@googlegroups.com; receiver=) Received: from mail-lf1-x13b.google.com (mail-lf1-x13b.google.com [IPv6:2a00:1450:4864:20::13b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP1xd0LN0z9sGF for ; Thu, 16 Jun 2022 22:41:07 +1000 (AEST) Received: by mail-lf1-x13b.google.com with SMTP id u7-20020a05651206c700b00479723664a9sf741521lff.6 for ; Thu, 16 Jun 2022 05:41:06 -0700 (PDT) ARC-Seal: i=3; a=rsa-sha256; t=1655383262; cv=pass; d=google.com; s=arc-20160816; b=uBS4i9/EDJVMH+mMMvhuKgSdp0QuZTfc0G7rt4+sPyXi7OezvWWBA76LWB1SPqlXGQ PVvT0DbIfyLr2QZ6dVGQSHugMoZNuuHzW1faZTCUwlAkpi4MvgEN0jIk14YWj3L9dY2E oLYOR7mkWUIfSbSr3fRGV1Wmni10ZyggTZVwA5x0V/vro62Utn4arl+30AJWAxgujE2p roQsvDsw87guA7YjWFoHGOvFbvMCTIqgATQNqJryA0rC4D/vzXi/kFxzq5oNUJRZ/vV0 xSu/RpPsndsKKC6l7yYbAGTZxz90kUwzm6v1aE6fmPNxn9h+1aC07Zp5+VPMYnQAkPmu 8p3Q== 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:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=NjFBHTBpx9LV5bvKn5obgAnSYDAg9XDO+WNwjMPeZZE=; b=VxHHnPioyikH2QkBSN+DYd++7MFHh0upmCz5nHFVLmXNTTPRmu7mcS8PCUK6if9LA0 ykRoCiF7vKVZ/2szL5ejLwrLdJSQ9eDhXtBXLJwy/NLcy481Hrga4CP9l6mWXcip8PTC /mBn/sgLoXZIH5ieeUNivLunEISld3Cx+NncOf32NovSVu1fgov4ImVQNVhyEjeZoT4B 0hN5cyXhT47TxsXBbGMsu9WaL8krZucFiInM8HcMYsWmXkQHdvw3VplUplWwPB0sPcXw wU/2vtzXQhWAZlczmCaOJOpkayTmQpReuhp3C188X5nMEpZt9lJqrXYFEzRQCYgrKg2K lvAw== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@softathome1.onmicrosoft.com header.s=selector1-softathome1-onmicrosoft-com header.b=OqORYTXI; arc=pass (i=1 spf=pass spfdomain=softathome.com); spf=pass (google.com: domain of philippe.reynes@softathome.com designates 2a01:111:f400:7e18::624 as permitted sender) smtp.mailfrom=philippe.reynes@softathome.com 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=NjFBHTBpx9LV5bvKn5obgAnSYDAg9XDO+WNwjMPeZZE=; b=M1CDgU2fRwXojqKSQVfF0bX5SO8xQf61DY6LUjNK7THUw+FUJjyOuKjxd4j1S3eCxr qkOsHzmSPU5bdjDO6UcmQwMFGA2GuKMcttpq5neTtxJ5JBklXsTv4h7cXXHphpjJsTNV u8WRw2IDflwmEnwNhIW4HuZHX50k9DGkvz8NaUv9YFxcM70egDFfxbbjpPleDNoXMMhI M55Nwl+WqCWR66uZzV9o26riwkSIO2qlJF0Q38EdxAtTpyyTHyblE8uZysshcZ+3wf+s GjodDLQvCuzQSs5Jr1muZkaorEYB4BK5NgHKnSfz+vBo6A32r2R5o8R+Bko2mJDK8kIT xEsg== 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=NjFBHTBpx9LV5bvKn5obgAnSYDAg9XDO+WNwjMPeZZE=; b=j+Um4wqruZ1hu/XXd0Mx3ku1LzottEvcEP5EOp1Q3O4YI9vGc7Spt1xRots19oDq05 NLddkKzPmlezhmTH+g1CA1k6DcQQdqGPNXohi9SSWcy3/Yd1KMk3jeR0gQUpH+n5nAtu Dlfsk69HPEryG4s0kfL3v4mn39BYrgbUVDMNVyqU+jT5VcrLriSTX+iY9GSmes9XaBJW 9e00+t1V8eYbF1raNCu9k2qMu6B9IoMHJNYxdT5NQSrgSXnq0NOKd3eYrCCCbzzJ1gZ6 wzCwKPEZMIpPWxhXm4LXtgWJZVzn3DKKpIbEQ5MCycCRZmhLVt2hq/t6cbcNc/hP6PH3 cnMg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJIora8dqw37/aUkDu5nt4fzpnNjmNia8A4yvXbnKQ+TwU5ms0V1U+D8 Cv3OuZNnRGKk41UiauDEnkw= X-Google-Smtp-Source: AGRyM1t2HtoPiTxHMr6QTRojzXawTfscorDnNeb2OWLD6tgFzgzxQ0//TjP5F+CZpd8LGmkA43SyoA== X-Received: by 2002:a19:f203:0:b0:479:50a4:c925 with SMTP id q3-20020a19f203000000b0047950a4c925mr2560304lfh.329.1655383261917; Thu, 16 Jun 2022 05:41:01 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:1693:b0:448:3742:2320 with SMTP id bu19-20020a056512169300b0044837422320ls552169lfb.1.gmail; Thu, 16 Jun 2022 05:41:00 -0700 (PDT) X-Received: by 2002:a19:384a:0:b0:479:17b1:2e49 with SMTP id d10-20020a19384a000000b0047917b12e49mr2433459lfj.629.1655383260584; Thu, 16 Jun 2022 05:41:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655383260; cv=pass; d=google.com; s=arc-20160816; b=i3fYZFCD1EZlr6YCQ61VgPm20RzOQbkYJFZWVk6vfVXpULVm6Io1hZlwd2DhzhYdDl y899H16Wm3eGlNslKo+ysCcGuukAQ4oLjU7Kua4aWyp+9O7n2UgAc2+uF5RSM5RO670X 8NXoPYA8s8XmvF1RdSiLmWDcREq95jzdtYvCsdAsV31Pf7wsoeimCtXu4QUbo0yFtqgh UdJuSPHjI6uxrvkY3SyaomdBQo6mG7M8x4k2fglK6wyF3JwJnIhnko0qiWrPGOzt0c56 L+P4zmBbetGvYNXbj9Ls79dHU1ap1gacy1TBGp7N3E2HwEXH9O2P56C7Jh5/9TnZ8hBy URLQ== ARC-Message-Signature: i=2; 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:dkim-signature; bh=VfnJTnmvjGSW3AiDP4d7m/3hql8/rIsHU8HLFzmphms=; b=pBak2YJAAcVl45GTnN/FbbFH+Gkrjcfy5NAr3y1esfKjhRn8SGueDDOb/mdOFrhg6F q+LgTSj06Uc9/P883cuzzANOX0dLYgefe0/w5OyNMvNFyS6ZYHa65ZRTZup3QjLd0AO2 7aT0D5EF5DyLY1TJ29XqKNNPbu/jOIIJAtR9KNEpAJHryDEH5b7c09eAdUvygpRjHRJy o0S5iL2OLp95uduUTHRLiX4Xfe+ZFkTVEzUQc6H31rXaaLgXUH+kGevwCQED8RYRj4KT Jqx13/28R7enuqucNNeiMT1VFlS0ss6JmA7IDx26OiM/3jdPJ9/8qzI3Inx9zxgKYNkl bq2A== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@softathome1.onmicrosoft.com header.s=selector1-softathome1-onmicrosoft-com header.b=OqORYTXI; arc=pass (i=1 spf=pass spfdomain=softathome.com); spf=pass (google.com: domain of philippe.reynes@softathome.com designates 2a01:111:f400:7e18::624 as permitted sender) smtp.mailfrom=philippe.reynes@softathome.com Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01on0624.outbound.protection.outlook.com. [2a01:111:f400:7e18::624]) by gmr-mx.google.com with ESMTPS id a8-20020a05651c210800b0025594e68748si76112ljq.4.2022.06.16.05.41.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jun 2022 05:41:00 -0700 (PDT) Received-SPF: pass (google.com: domain of philippe.reynes@softathome.com designates 2a01:111:f400:7e18::624 as permitted sender) client-ip=2a01:111:f400:7e18::624; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ehqloeEXt8dFKE409KfrZddfsBwr4p7iaHOQUgltN/I78EhU/RvoPL3UuRy2cBD2XOH2Mli5XV/VT00FEce1TmiR2jkpcsc+ODlmHnEnJWS6bH7aeuoSfc8LNvSef/cbdxQaobE5gjvMoAxWdt/S10FrNCP3byGneWCWEGKdRkYuooi/aRIAhX8SDaV/9pxvPUk9DSbU6jLkRDPg2S3bI9YUuqmpa9G2/uqd9+Nh8PqO6ctX0Ch51Kp68gU5Jxyb0qyASV/PSJ6Vyu/Eok6bekaAasGhWsixso4sHae7EK6CSwTg/+70qOs4RyG4NgC84Yz9lxdg/qUAYIgHzC87WQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VfnJTnmvjGSW3AiDP4d7m/3hql8/rIsHU8HLFzmphms=; b=ZbERqprMQvuGv7RQQoHRYND1BGe9+rjnBYWCIG0UiJ1hK0+jAIR00bokgCOyCJ8Kv5f2d7GhIXZjvwDllhWi6+mxGJhZm5YoyWF9pivbdrAAQ3l7/v9RO+Qg/qs6TLmz8lljmzivQT4P/rUAdK85tCVzdugsnTwDw+4WbWeCeyQ0AUyut2v2jWid0HSvXNzIGiNTCB3px49wBgPNJjEKp4CtBt4JmIj9KFDBZLmdMMZfCI2hmZiLJ1B08ZXM4P5+YKBmHD+kjfACpA4OkXzI8RDdCEMnsBkTd++sHBS26H3G8WTmUPV6Hz3RtbphSadRh4jJocgvmDhVbuyRx+RqTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.6.166.170) smtp.rcpttodomain=googlegroups.com smtp.mailfrom=softathome.com; dmarc=bestguesspass action=none header.from=softathome.com; dkim=none (message not signed); arc=none Received: from MR2P264CA0187.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501::26) by MR1P264MB3907.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:20::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.13; Thu, 16 Jun 2022 12:40:57 +0000 Received: from MR2FRA01FT013.eop-fra01.prod.protection.outlook.com (2603:10a6:501:0:cafe::fc) by MR2P264CA0187.outlook.office365.com (2603:10a6:501::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.15 via Frontend Transport; Thu, 16 Jun 2022 12:40:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.6.166.170) smtp.mailfrom=softathome.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=softathome.com; Received-SPF: Pass (protection.outlook.com: domain of softathome.com designates 149.6.166.170 as permitted sender) receiver=protection.outlook.com; client-ip=149.6.166.170; helo=proxy.softathome.com; pr=C Received: from proxy.softathome.com (149.6.166.170) by MR2FRA01FT013.mail.protection.outlook.com (10.152.50.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14 via Frontend Transport; Thu, 16 Jun 2022 12:40:57 +0000 Received: from sah1lpt571.softathome.com (unknown [192.168.75.67]) by proxy.softathome.com (Postfix) with ESMTPSA id 618702003C; Thu, 16 Jun 2022 14:40:57 +0200 (CEST) From: Philippe Reynes To: swupdate@googlegroups.com Cc: Philippe Reynes Subject: [swupdate] [PATCH v2 2/2] handlers: diskpart_handler.c: add install_gpt_partition_image Date: Thu, 16 Jun 2022 14:40:55 +0200 Message-Id: <20220616124055.2163867-2-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616124055.2163867-1-philippe.reynes@softathome.com> References: <20220616124055.2163867-1-philippe.reynes@softathome.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cb7eeca1-73e3-4aa3-c560-08da4f957623 X-MS-TrafficTypeDiagnostic: MR1P264MB3907:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +EY1l8AodqLnsVEDLrSH6NZfX1/upxMhLgDnnWhfdLfyFIyx7uhzIg+hgi5dScSpXQkxtcLmRT8WUaIwSuq7WTDkCplXIn1asf63Ns/VooxRw0nKDFSbdkvMvaVpQ4/NRRB2b3UPefn4cvv0JvYxzBNI+yS3SxjkpbbYfiDPTJM7fKzpwJpNKZYv8gEHvKDlJc8mq2UQcGNWSBT3Vso4HPXhZznE+7GKUtmWLDOhWEnpo1RIGDAgwjOK5DkR0SH8Is8eu3M4GwYL+wD0PB7XW2QAOEtuJ/U+7Yh1jtSUIzOXS12XpWalJMBU9tZCo3uW09bS1EtcMFRE8XZV0EgCeridWrWy8X1nJ94RoK4Eno/0bzH9wduGjBslxiQ5zOgFgzChzeLjdQ1jc8DJznZCDMNIyeOzakGnP1hqAhVaTwUb+ZXKFKCyW//EiqnHgPatjM5T5eS4g/xi3jjhT/dFEW9kkUh3VK/mblFS/K9bg+hmwHokgGWS5DWzdD3JRINf5vYST6cX/Fm8wAPsud+c87O5dihOgRDSCFix1EQeMTcIh5K7wOI9W4yyUt/juH+fNije7xPzxO6UB5ZWy2kieRVq+A1Bs1nX5X7RZt2DlO0fpNu5ACbqXL9yJWVu1YTZhbK8NMAJRdAnVsy8DN7LjXzT7JFj46inrbV2USdOUkoUeQyDvG7dRJ0647cYSuZ3 X-Forefront-Antispam-Report: CIP:149.6.166.170;CTRY:FR;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:proxy.softathome.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(36840700001)(46966006)(44832011)(316002)(356005)(2616005)(5660300002)(6966003)(82310400005)(7696005)(498600001)(8936002)(82960400001)(186003)(107886003)(1076003)(81166007)(83380400001)(70586007)(426003)(336012)(47076005)(6266002)(2906002)(26005)(36860700001)(36756003)(86362001)(6916009)(8676002)(4326008)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2022 12:40:57.6342 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb7eeca1-73e3-4aa3-c560-08da4f957623 X-MS-Exchange-CrossTenant-Id: aa10e044-e405-4c10-8353-36b4d0cce511 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=aa10e044-e405-4c10-8353-36b4d0cce511;Ip=[149.6.166.170];Helo=[proxy.softathome.com] X-MS-Exchange-CrossTenant-AuthSource: MR2FRA01FT013.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR1P264MB3907 X-Original-Sender: philippe.reynes@softathome.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@softathome1.onmicrosoft.com header.s=selector1-softathome1-onmicrosoft-com header.b=OqORYTXI; arc=pass (i=1 spf=pass spfdomain=softathome.com); spf=pass (google.com: domain of philippe.reynes@softathome.com designates 2a01:111:f400:7e18::624 as permitted sender) smtp.mailfrom=philippe.reynes@softathome.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: , Add a handler to write in a GPT partition. With the handler raw, the device of the parition is provided to the raw handler. This handler use a device on the disk that contains the GPT partition and the name of the GPT partition to found the device of the partition to write. For example: images: ( { filename = "u-boot.bin"; type = "gptpart"; device = "/dev/vdb"; volume = "u-boot-1"; }, { filename = "kernel.bin"; type = "gptpart"; device = "/dev/vdb"; volume = "kernel-1"; }, ); Signed-off-by: Philippe Reynes --- Changelog: v2: - rebase on master - add a constructor to register the handler install_gpt_partition_image doc/source/handlers.rst | 24 ++++++++ handlers/diskpart_handler.c | 115 ++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 01ec221..029a70c 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -963,6 +963,30 @@ if the partition table is DOS. It reports an error if the table is GPT. } } +gpt partition installer +....................... + +There is a handler gptpart that allows writing an image into a gpt partition selected by +the name. This handler do not modify the gpt partition (type, size, ...), it just writes +the image in the GPT partition. + +:: + + images: ( + { + filename = "u-boot.bin"; + type = "gptpart"; + device = "/dev/vdb"; + volume = "u-boot-1"; + }, + { + filename = "kernel.bin"; + type = "gptpart"; + device = "/dev/vdb"; + volume = "kernel-1"; + }, + ); + gpt partition swap .................. diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c index 925976b..7408ee6 100644 --- a/handlers/diskpart_handler.c +++ b/handlers/diskpart_handler.c @@ -907,6 +907,114 @@ static int diskpart_reread_partition(char *device) return ret; } +static int install_gpt_partition_image(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + struct fdisk_context *cxt = NULL; + struct diskpart_table *tb = NULL; + int ret = 0; + unsigned long hybrid = 0; + struct hnd_priv priv = { + .labeltype = FDISK_DISKLABEL_DOS, + }; + struct create_table *createtable = NULL; + struct fdisk_partition *pa; + size_t partno; + char node[64]; + int fdout; + + LIST_INIT(&priv.listparts); + if (!strlen(img->device)) { + ERROR("Partition handler without setting the device"); + return -EINVAL; + } + + createtable = calloc(1, sizeof(*createtable)); + if (!createtable) { + ERROR("OOM allocating createtable !"); + return -ENOMEM; + } + + /* + * Reads flags: nolock and noinuse + */ + priv.nolock = strtobool(dict_get_value(&img->properties, "nolock")); + priv.noinuse = strtobool(dict_get_value(&img->properties, "noinuse")); + + /* + * Create context + */ + ret = diskpart_assign_context(&cxt, img, priv, hybrid, createtable); + if (ret == -EACCES) + goto handler_release; + else if (ret) + goto handler_exit; + + tb = calloc(1, sizeof(*tb)); + if (!tb) { + ERROR("OOM loading partitions !"); + ret = -ENOMEM; + goto handler_exit; + } + + /* + * Fill the in-memory partition table from the disk. + */ + ret = diskpart_get_partitions(cxt, tb, createtable); + if (ret) + goto handler_exit; + + /* + * Search partition to update + */ + pa = diskpart_get_partition_by_name(tb, img->volname); + if (!pa) { + ERROR("Can't find partition %s", img->volname); + ret = -1; + goto handler_exit; + } + + /* + * Open the node of the partition + */ + partno = fdisk_partition_get_partno(pa); + snprintf(node, sizeof(node), "%s%zu", img->device, partno + 1); + fdout = open(node, O_RDWR); + if (fdout < 0) { + ERROR("Node %s cannot be opened", node); + ret = -1; + goto handler_exit; + } + + /* + * Write image + */ + if (copyimage(&fdout, img, NULL) < 0) { + ERROR("Error copying extracted file"); + ret = -1; + goto handler_close; + } + +handler_close: + close(fdout); + +handler_exit: + if (tb) + diskpart_unref_table(tb); + if (cxt && fdisk_get_devfd(cxt) >= 0) + if (fdisk_deassign_device(cxt, 0)) + WARN("Error deassign device %s", img->device); + +handler_release: + if (cxt) + diskpart_unref_context(cxt); + + if (createtable) + free(createtable); + + return ret; +} + static int diskpart(struct img_type *img, void __attribute__ ((__unused__)) *data) { @@ -1472,3 +1580,10 @@ void diskpart_gpt_swap_partition(void) register_handler("gptswap", gpt_swap_partition, SCRIPT_HANDLER | NO_DATA_HANDLER, NULL); } + +__attribute__((constructor)) +void diskpart_install_gpt_partition_image(void) +{ + register_handler("gptpart", install_gpt_partition_image, + IMAGE_HANDLER, NULL); +}