From patchwork Wed Jul 1 22:39:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 11637445 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7208B618 for ; Wed, 1 Jul 2020 22:43:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 314072082F for ; Wed, 1 Jul 2020 22:43:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Lu8zj/NU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 314072082F Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593643424; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QrPNIXmEtumeUVrw1ma8hqK5SXFJqCqF1u/8LGmJd1g=; b=Lu8zj/NU4fl0KnaXiB0ZzvMohuPbCmiqK93CVDFJm+fc53ra73z1ZqC6851dn2t0QjjboQ iT/J2drT8Pzjk7AZRrAeSwhTnTDShkXR1wWGhJlaDuIpIUIPxNqbGfMB/t5o0A8Q9EloI2 06pD1WozY6KoJ1j+kaKXywbnBjjfDKg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-ZbiE5dx8O8uTI3m9pg5LdQ-1; Wed, 01 Jul 2020 18:43:41 -0400 X-MC-Unique: ZbiE5dx8O8uTI3m9pg5LdQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E155710059A7; Wed, 1 Jul 2020 22:43:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7A06741B5; Wed, 1 Jul 2020 22:43:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9F2106C9C6; Wed, 1 Jul 2020 22:43:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 061MdiEv020034 for ; Wed, 1 Jul 2020 18:39:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B7CF5C1C5; Wed, 1 Jul 2020 22:39:44 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from octiron.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 273CA5C1BB; Wed, 1 Jul 2020 22:39:41 +0000 (UTC) Received: from octiron.msp.redhat.com (localhost.localdomain [127.0.0.1]) by octiron.msp.redhat.com (8.14.9/8.14.9) with ESMTP id 061Mddg3006256; Wed, 1 Jul 2020 17:39:40 -0500 Received: (from bmarzins@localhost) by octiron.msp.redhat.com (8.14.9/8.14.9/Submit) id 061Mddas006255; Wed, 1 Jul 2020 17:39:39 -0500 From: Benjamin Marzinski To: Christophe Varoqui Date: Wed, 1 Jul 2020 17:39:35 -0500 Message-Id: <1593643176-6206-4-git-send-email-bmarzins@redhat.com> In-Reply-To: <1593643176-6206-1-git-send-email-bmarzins@redhat.com> References: <1593643176-6206-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: device-mapper development , Martin Wilck Subject: [dm-devel] [PATCH 3/4] kpartx: handle alternate bsd disklabel location X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com bsd disk labels can either be at the start of the second sector, or 64 bytes into the first sector, but kpartx only handled the first case. However the second case is what parted creates, and what the linux kernel partition code expects. kpartx should handle both cases. Signed-off-by: Benjamin Marzinski Reviewed-by: Martin Wilck --- kpartx/bsd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kpartx/bsd.c b/kpartx/bsd.c index 0e661fbc..950b0f92 100644 --- a/kpartx/bsd.c +++ b/kpartx/bsd.c @@ -1,6 +1,7 @@ #include "kpartx.h" #include +#define BSD_LABEL_OFFSET 64 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ #define XBSD_MAXPARTITIONS 16 #define BSD_FS_UNUSED 0 @@ -60,8 +61,19 @@ read_bsd_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) { return -1; l = (struct bsd_disklabel *) bp; - if (l->d_magic != BSD_DISKMAGIC) - return -1; + if (l->d_magic != BSD_DISKMAGIC) { + /* + * BSD disklabels can also start 64 bytes offset from the + * start of the first sector + */ + bp = getblock(fd, offset); + if (bp == NULL) + return -1; + + l = (struct bsd_disklabel *)(bp + 64); + if (l->d_magic != BSD_DISKMAGIC) + return -1; + } max_partitions = 16; if (l->d_npartitions < max_partitions)