From patchwork Mon Apr 23 12:31:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 902920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::239; helo=mail-wr0-x239.google.com; envelope-from=swupdate+bncbdd6bwv65qpbb5ve67lakgqeravij3a@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=siemens.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="IRi8QcE4"; dkim-atps=neutral Received: from mail-wr0-x239.google.com (mail-wr0-x239.google.com [IPv6:2a00:1450:400c:c0c::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40V5TP3XSBz9rx7 for ; Mon, 23 Apr 2018 22:32:57 +1000 (AEST) Received: by mail-wr0-x239.google.com with SMTP id v11-v6sf18776054wri.13 for ; Mon, 23 Apr 2018 05:32:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1524486774; cv=pass; d=google.com; s=arc-20160816; b=zx31mdxZ7VpWvrsiv1DI76GITRSgKmh3G5am6wL9k5a0BTKJEc9QUFE6QeVzDdh1Zr synie6UgRQ6XFLOdmGN9StDWN2EOIkheiqn3rmjVSDL8LYeyHsKaYdxZqa5HciBkppvq KXE0aog0d3rGPA5Py4yf1eD4iYdUqZoJWDCh61RXHyZauIA0dC4argO5sSnyq+JPo1JY DHRg0k6mYKtEI2at9eXgpczcn5D/3yMitkQeSkS2z5wcwwzhXEmwYskXJuJRuIvXEnSD zpw6vEuDRJ9Dnf0zS3d9oQpECjLVsAAcKupqXtRJQ0iYoGpHTz0r9M8I/Mm5vlqIYnLU eB1A== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=Muy5yJiNjZrt1tcGegrczpkPfY0QnqXuYm5yUL6g8nE=; b=ghugK/qh3G3dSAPaIyBYLqRi75aODSuAc/2gjDATPMZJa0WaVZ46I2TXwsTq2m3OTy hzguekLatdhGzH/1n50s7XWB3QeKsuz/rY6JGq1lmlWgknvaNfVoDvpEyvr1P/QkDhm6 EYw+EIe81jNhJEQ5NblPrhrKguV20nU8fRBLrlnk5kfBFEZrR+tTU8zxi2vPP115mW6x A3R863oRYKK7WwhbMNX2i9OEEnwHhgDrLp7h4k5CGBi8bbUO9h5/+sODKIv7sovUbj65 dZgHiC1mHp/6n8hmuNa/zfvz/cgUOm/h0gHa4O2Hc5B2Bvodg65a/scSwWVHHmmfkXwv vrsA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Muy5yJiNjZrt1tcGegrczpkPfY0QnqXuYm5yUL6g8nE=; b=IRi8QcE4THELyaKUn7m/cVk9U5NduXgVR8GAVicPKJmJpg7gr8LXuFxpIW8TMdmGDb Nb4rFrczlLUMCQ6vXUwkLhOVjq2kmlXDrebQ4kZFAsqNm8mMfZMNsRt0tRktyt+QMce0 bYwu55SXgIv8qBe68/KVfEpcxgEo+gesBj1M8tkpIru2WroVoTuRdgMjzOvdUI/jVf16 sj211PF2ZnB8fG7iu4Ly5p+YH9eXWOvjByBKvGqJq3RJ7w5IFyBzbrNVLruZY6qIFBXH epFqpODLOABLNf6L4IjkrP7CrRUpyWFUSIVUQS+JUmK/kBPD/B1FUf3zEHhDs/PXudSj Tvxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=Muy5yJiNjZrt1tcGegrczpkPfY0QnqXuYm5yUL6g8nE=; b=IXchAXaGBDXxvRCJnl6N0KrJ7oGf+9XKok7doYsqh99V08epKMeNHfBBsqGxV/nnKd OHQy7ZizrcMebAYJbPYzv88dJtuKnPrNtKNFjaqjbOqwrJQ96C0alJWaoE7UXy0yjSI7 ESnVxNjum/8rACF2aftQdFVS0q8rjNP9QxoQO3x/M7Lj+gVusWAAfOBS5ntv2V6nxOIy hZsxex/Hytf6+f5oJEb5cb657mCyMFBoAxSuLKeYS8lXPJ1+RCT/ePqWU3ibYmbak9aG 4eeRzn5uvfkD6V9DicnDYO6XM+gSI8NBAiSo51MpgzuLvhgcJAIFIYvBRx0SJ3c9vrMh p5bg== Sender: swupdate@googlegroups.com X-Gm-Message-State: ALQs6tBplCHadSeI7neHuUGcxUC5QJHycu2R481edpb1H5/75mARFMsl 1+X9+SLZLTvCmpgg0ygwPk0= X-Google-Smtp-Source: AB8JxZqB3esOZCR5NTOuzwxeuDxMLwqoCV/g8UwWGWZ33mPebkoZljVQa0/sCPny6yP9QUIVlXrmBA== X-Received: by 10.28.23.9 with SMTP id 9mr138638wmx.6.1524486774913; Mon, 23 Apr 2018 05:32:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.186.135 with SMTP id x7ls247247ede.6.gmail; Mon, 23 Apr 2018 05:32:54 -0700 (PDT) X-Received: by 10.80.135.236 with SMTP id 41mr6030930edz.5.1524486774142; Mon, 23 Apr 2018 05:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524486774; cv=none; d=google.com; s=arc-20160816; b=KifIZxxa8y8oIeBraBbnjqC+BKVHOkIUHFhkqWwXGIcLeEhYr6NBtmDmxztXqcBVJu tyQPdrEtV/Jcz1XIV8vv4NHuV7hwRFhz/D9lMgrc+Ai8gz0rRx5LxEtonk3DnwPZQ3fe f/Fx/2X03hoJSiLx2+h0DnuA7erWn2V8QOwK4/A2EObkdupvC0ctq0NDLq4f3VsDRJ7h Slzziv5f7XaT6VEDDqyvhv9tXboz1uMy4oamMaMFC17aJ7kOXaRCV+DFn7JBIKibScWv TDlUZDd/gLwt43OZin2FMqdi23YMfdjNGsswxf7QyUw98jtKtp8Gc7xE83tCX01ZAkC3 k8ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=tYZYIp/+gOgrV9ucvGv51FivdwzhZvagnVLzHV+4xrk=; b=j73gUvcWaAbS2F2PW6nR9Zzs7BLvxlr/hHT7K5lip6BCH5SAOv1Ra79vh8Tm5Wp4eO Z4sog3Q4ScfmlBN/9eKjZaoCK3MRiyfJyq2OWiGgF3DWcAt09ym2EyDLRCHT5l0oXhhf rGH821taWhgiP7cRFmwcd1GwE5vciS/VI6q/2C+7MkT745ZdPZgcTMIrCvGj9UGe6vBb 3tcYWoWd/Sp6NseNel7HU1pBkm7iY6GRVkyDX8AeTwnmdzNnIGe6BQw6K+iLpzyFS9rp fr5D7CxidnB7XyVhGD9U/pL/NXgoWH0uAs0fySltkXtbo6RA4oXC2Ps7W3CNlGCEtkyN KiZg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id 4si394090edx.3.2018.04.23.05.32.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 05:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w3NCWrp4002087 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 23 Apr 2018 14:32:53 +0200 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.174]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id w3NCWX87018649; Mon, 23 Apr 2018 14:32:53 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 7/8] handler: add FreeBSD-compatible copy_write() callback Date: Mon, 23 Apr 2018 14:31:08 +0200 Message-Id: <20180423123109.18590-7-christian.storm@siemens.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180423123109.18590-1-christian.storm@siemens.com> References: <20180423123109.18590-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.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: , As FreeBSD likes to have writes to device nodes being multiples of 512 bytes, provide an according padding callback function as default for the raw handler. Signed-off-by: Christian Storm Reviewed-by: Stefano Babic --- handlers/raw_handler.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c index ac8e47a..e57367e 100644 --- a/handlers/raw_handler.c +++ b/handlers/raw_handler.c @@ -19,6 +19,31 @@ void raw_handler(void); void raw_filecopy_handler(void); +#if defined(__FreeBSD__) +/* + * FreeBSD likes to have multiples of 512 bytes written + * to a device node, hence slice the buffer in palatable + * chunks assuming that only the last written buffer's + * length is smaller than cpio_utils.c's BUFF_SIZE and + * doesn't satisfy length % 512 == 0. + */ +static int copy_write_padded(void *out, const void *buf, unsigned int len) +{ + if (len % 512 == 0) { + return copy_write(out, buf, len); + } + + uint8_t buffer[512] = { 0 }; + int chunklen = len - (len % 512); + int res = copy_write(out, buf, chunklen); + if (res != 0) { + return res; + } + memcpy(&buffer, buf+chunklen, len-chunklen); + return copy_write(out, buffer, 512); +} +#endif + static int install_raw_image(struct img_type *img, void __attribute__ ((__unused__)) *data) { @@ -31,8 +56,11 @@ static int install_raw_image(struct img_type *img, img->device, strerror(errno)); return -1; } - +#if defined(__FreeBSD__) + ret = copyimage(&fdout, img, copy_write_padded); +#else ret = copyimage(&fdout, img, NULL); +#endif close(fdout); return ret;