]> git.pld-linux.org Git - packages/parted.git/blob - 0010-libparted-device-mapper-uses-512b-sectors.patch
- release 6 (by relup.sh)
[packages/parted.git] / 0010-libparted-device-mapper-uses-512b-sectors.patch
1 From f98f791e19669b900345dad7d96ea4df974e4596 Mon Sep 17 00:00:00 2001
2 From: "Brian C. Lane" <bcl@redhat.com>
3 Date: Wed, 4 Feb 2015 16:46:07 -0800
4 Subject: [PATCH 10/11] libparted: device mapper uses 512b sectors
5
6 device mapper doesn't use the device's sector size when creating a
7 table. It always uses 512b units. This causes partitions to be created
8 8x smaller than expected on devices with 4906b sectors.
9 ---
10  NEWS                   |  4 ++++
11  libparted/arch/linux.c | 21 +++++++++++++++++----
12  2 files changed, 21 insertions(+), 4 deletions(-)
13
14 diff --git a/NEWS b/NEWS
15 index 10c9a6e..96135ed 100644
16 --- a/NEWS
17 +++ b/NEWS
18 @@ -4,6 +4,10 @@ GNU parted NEWS                                    -*- outline -*-
19  
20  ** Bug Fixes
21  
22 +  Use 512b sector size when communicating with device-mapper. Fixes
23 +  problems with partitions being created too small on dm devices
24 +  with sector sizes > 5121b
25 +
26    Don't crash in the disk_set command when a disk label is not found
27  
28    libparted-fs-resize: Prevent crash resizing FAT16 file systems.
29 diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
30 index 0f18904..90ab21d 100644
31 --- a/libparted/arch/linux.c
32 +++ b/libparted/arch/linux.c
33 @@ -2763,6 +2763,12 @@ _dm_get_partition_start_and_length(PedPartition const *part,
34          if (sscanf (params, "%d:%d %Ld", &major, &minor, start) != 3)
35                  goto err;
36          rc = 1;
37 +
38 +        /* device-mapper uses 512b units, make sure we return length and start in terms of the device's
39 +         * sector size.
40 +         */
41 +        *start /= (part->disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT);
42 +        *length /= (part->disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT);
43  err:
44          free (path);
45          dm_task_destroy(task);
46 @@ -2810,8 +2816,10 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part)
47          /* Caution: dm_task_destroy frees dev_name.  */
48          dm_task_destroy (task);
49          task = NULL;
50 +        /* device-mapper uses 512b units, not the device's sector size */
51          if ( ! (params = zasprintf ("%d:%d %lld", arch_specific->major,
52 -                                    arch_specific->minor, part->geom.start)))
53 +                                    arch_specific->minor,
54 +                                    part->geom.start * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT))))
55                  goto err;
56  
57          task = dm_task_create (DM_DEVICE_CREATE);
58 @@ -2821,7 +2829,8 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part)
59          dm_task_set_name (task, vol_name);
60          if (vol_uuid)
61                  dm_task_set_uuid (task, vol_uuid);
62 -        dm_task_add_target (task, 0, part->geom.length,
63 +        /* device-mapper uses 512b units, not the device's sector size */
64 +        dm_task_add_target (task, 0, part->geom.length * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT),
65                  "linear", params);
66          if (!dm_task_set_cookie (task, &cookie, 0))
67                  goto err;
68 @@ -2878,8 +2887,11 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
69          /* Caution: dm_task_destroy frees dev_name.  */
70          dm_task_destroy (task);
71          task = NULL;
72 +
73 +        /* device-mapper uses 512b units, not the device's sector size */
74          if ( ! (params = zasprintf ("%d:%d %lld", arch_specific->major,
75 -                                    arch_specific->minor, part->geom.start)))
76 +                                    arch_specific->minor,
77 +                                    part->geom.start * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT))))
78                  goto err;
79  
80          task = dm_task_create (DM_DEVICE_RELOAD);
81 @@ -2887,7 +2899,8 @@ _dm_resize_partition (PedDisk* disk, const PedPartition* part)
82                  goto err;
83  
84          dm_task_set_name (task, vol_name);
85 -        dm_task_add_target (task, 0, part->geom.length,
86 +        /* device-mapper uses 512b units, not the device's sector size */
87 +        dm_task_add_target (task, 0, part->geom.length * (disk->dev->sector_size / PED_SECTOR_SIZE_DEFAULT),
88                  "linear", params);
89          if (!dm_task_set_cookie (task, &cookie, 0))
90                  goto err;
91 -- 
92 2.1.0
93
This page took 0.028707 seconds and 3 git commands to generate.