From patchwork Tue Jul 16 07:13:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 2827944 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E396E9F7D6 for ; Tue, 16 Jul 2013 07:18:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EB6922017F for ; Tue, 16 Jul 2013 07:18:52 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id CBD1120188 for ; Tue, 16 Jul 2013 07:18:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6G7E3rk030476; Tue, 16 Jul 2013 03:14:03 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6G7DS7E027802 for ; Tue, 16 Jul 2013 03:13:28 -0400 Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.17]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6G7DSWk010126 for ; Tue, 16 Jul 2013 03:13:28 -0400 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6G7DQhm013881 for ; Tue, 16 Jul 2013 03:13:26 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 68979A5539; Tue, 16 Jul 2013 09:13:24 +0200 (CEST) From: Hannes Reinecke To: Christophe Varoqui Date: Tue, 16 Jul 2013 09:13:01 +0200 Message-Id: <1373958801-103613-11-git-send-email-hare@suse.de> In-Reply-To: <1373958801-103613-1-git-send-email-hare@suse.de> References: <1373958801-103613-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.69 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, URIBL_BLOCKED) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.17 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Petr Uzel Subject: [dm-devel] [PATCH 10/30] kpartx: support disk with non-512B sectors X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development 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-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Petr Uzel libdevmapper expects sector size to be recalculated to 512B, so we need to teach kpartx to do so if the underlying DM device has different sector size (for GPT and msods partition tables). Signed-off-by: Petr Uzel --- kpartx/dos.c | 17 ++++++++++------- kpartx/gpt.c | 20 +------------------- kpartx/kpartx.c | 12 ++++++++++++ kpartx/kpartx.h | 8 ++++++++ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/kpartx/dos.c b/kpartx/dos.c index a1a9961..0e57f0e 100644 --- a/kpartx/dos.c +++ b/kpartx/dos.c @@ -26,7 +26,9 @@ read_extended_partition(int fd, struct partition *ep, int en, int moretodo = 1; int i, n=0; - next = start = le32_to_cpu(ep->start_sect); + int sector_size_mul = get_sector_size(fd)/512; + + next = start = sector_size_mul * le32_to_cpu(ep->start_sect); while (moretodo) { here = next; @@ -45,14 +47,14 @@ read_extended_partition(int fd, struct partition *ep, int en, memcpy(&p, bp + 0x1be + i * sizeof (p), sizeof (p)); if (is_extended(p.sys_type)) { if (p.nr_sects && !moretodo) { - next = start + le32_to_cpu(p.start_sect); + next = start + sector_size_mul * le32_to_cpu(p.start_sect); moretodo = 1; } continue; } if (n < ns) { - sp[n].start = here + le32_to_cpu(p.start_sect); - sp[n].size = le32_to_cpu(p.nr_sects); + sp[n].start = here + sector_size_mul * le32_to_cpu(p.start_sect); + sp[n].size = sector_size_mul * le32_to_cpu(p.nr_sects); sp[n].container = en + 1; n++; } else { @@ -77,6 +79,7 @@ read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) { unsigned long offset = all.start; int i, n=4; unsigned char *bp; + int sector_size_mul = get_sector_size(fd)/512; bp = (unsigned char *)getblock(fd, offset); if (bp == NULL) @@ -90,15 +93,15 @@ read_dos_pt(int fd, struct slice all, struct slice *sp, int ns) { if (is_gpt(p.sys_type)) return 0; if (i < ns) { - sp[i].start = le32_to_cpu(p.start_sect); - sp[i].size = le32_to_cpu(p.nr_sects); + sp[i].start = sector_size_mul * le32_to_cpu(p.start_sect); + sp[i].size = sector_size_mul * le32_to_cpu(p.nr_sects); } else { fprintf(stderr, "dos_partition: too many slices\n"); break; } if (is_extended(p.sys_type)) { - sp[i].size = 2; /* extended partitions only get two + sp[i].size = sector_size_mul * 2; /* extended partitions only get two sectors mapped for LILO to install */ n += read_extended_partition(fd, &p, i, sp+n, ns-n); } diff --git a/kpartx/gpt.c b/kpartx/gpt.c index 0a22927..5a54970 100644 --- a/kpartx/gpt.c +++ b/kpartx/gpt.c @@ -38,6 +38,7 @@ #include #include #include "crc32.h" +#include "kpartx.h" #if BYTE_ORDER == LITTLE_ENDIAN # define __le16_to_cpu(x) (x) @@ -116,25 +117,6 @@ is_pmbr_valid(legacy_mbr *mbr) /************************************************************ - * get_sector_size - * Requires: - * - filedes is an open file descriptor, suitable for reading - * Modifies: nothing - * Returns: - * sector size, or 512. - ************************************************************/ -static int -get_sector_size(int filedes) -{ - int rc, sector_size = 512; - - rc = ioctl(filedes, BLKSSZGET, §or_size); - if (rc) - sector_size = 512; - return sector_size; -} - -/************************************************************ * _get_num_sectors * Requires: * - filedes is an open file descriptor, suitable for reading diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c index 98d88c0..1369542 100644 --- a/kpartx/kpartx.c +++ b/kpartx/kpartx.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -695,3 +696,14 @@ getblock (int fd, unsigned int secnr) { return bp->block; } + +int +get_sector_size(int filedes) +{ + int rc, sector_size = 512; + + rc = ioctl(filedes, BLKSSZGET, §or_size); + if (rc) + sector_size = 512; + return sector_size; +} diff --git a/kpartx/kpartx.h b/kpartx/kpartx.h index 61d31b6..a55c211 100644 --- a/kpartx/kpartx.h +++ b/kpartx/kpartx.h @@ -2,6 +2,7 @@ #define _KPARTX_H #include +#include /* * For each partition type there is a routine that takes @@ -18,6 +19,13 @@ #define safe_sprintf(var, format, args...) \ snprintf(var, sizeof(var), format, ##args) >= sizeof(var) +#ifndef BLKSSZGET +#define BLKSSZGET _IO(0x12,104) /* get block device sector size */ +#endif + +int +get_sector_size(int filedes); + /* * units: 512 byte sectors */