/[linux-patches]/genpatches-2.6/trunk/2.6.32/1910_sector-size-for-EFI-GPT-fix.patch
Gentoo

Contents of /genpatches-2.6/trunk/2.6.32/1910_sector-size-for-EFI-GPT-fix.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1646 - (show annotations) (download) (as text)
Sat Dec 19 19:11:24 2009 UTC (10 years, 11 months ago) by mpagano
File MIME type: text/x-diff
File size: 4127 byte(s)
Patches to correct sector size reads for EFI GPT
1 From: Karel Zak <kzak@redhat.com>
2 Date: Mon, 23 Nov 2009 08:29:13 +0000 (+0100)
3 Subject: partitions: use sector size for EFI GPT
4 X-Git-Tag: v2.6.33-rc1~379^2~54
5 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=7d13af3279985f554784a45cc961f706dbcdbdd1
6
7 partitions: use sector size for EFI GPT
8
9 Currently, kernel uses strictly 512-byte sectors for EFI GPT parsing.
10 That's wrong.
11
12 UEFI standard (version 2.3, May 2009, 5.3.1 GUID Format overview, page
13 95) defines that LBA is always based on the logical block size. It
14 means bdev_logical_block_size() (aka BLKSSZGET) for Linux.
15
16 This patch removes static sector size from EFI GPT parser.
17
18 The problem is reproducible with the latest GNU Parted:
19
20 # modprobe scsi_debug dev_size_mb=50 sector_size=4096
21
22 # ./parted /dev/sdb print
23 Model: Linux scsi_debug (scsi)
24 Disk /dev/sdb: 52.4MB
25 Sector size (logical/physical): 4096B/4096B
26 Partition Table: gpt
27
28 Number Start End Size File system Name Flags
29 1 24.6kB 3002kB 2978kB primary
30 2 3002kB 6001kB 2998kB primary
31 3 6001kB 9003kB 3002kB primary
32
33 # blockdev --rereadpt /dev/sdb
34 # dmesg | tail -1
35 sdb: unknown partition table <---- !!!
36
37 with this patch:
38
39 # blockdev --rereadpt /dev/sdb
40 # dmesg | tail -1
41 sdb: sdb1 sdb2 sdb3
42
43 Signed-off-by: Karel Zak <kzak@redhat.com>
44 Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
45 ---
46
47 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
48 index 038a602..80eeff5 100644
49 --- a/fs/partitions/efi.c
50 +++ b/fs/partitions/efi.c
51 @@ -1,7 +1,9 @@
52 /************************************************************
53 * EFI GUID Partition Table handling
54 - * Per Intel EFI Specification v1.02
55 - * http://developer.intel.com/technology/efi/efi.htm
56 + *
57 + * http://www.uefi.org/specs/
58 + * http://www.intel.com/technology/efi/
59 + *
60 * efi.[ch] by Matt Domsch <Matt_Domsch@dell.com>
61 * Copyright 2000,2001,2002,2004 Dell Inc.
62 *
63 @@ -92,6 +94,7 @@
64 *
65 ************************************************************/
66 #include <linux/crc32.h>
67 +#include <linux/math64.h>
68 #include "check.h"
69 #include "efi.h"
70
71 @@ -141,7 +144,8 @@ last_lba(struct block_device *bdev)
72 {
73 if (!bdev || !bdev->bd_inode)
74 return 0;
75 - return (bdev->bd_inode->i_size >> 9) - 1ULL;
76 + return div_u64(bdev->bd_inode->i_size,
77 + bdev_logical_block_size(bdev)) - 1ULL;
78 }
79
80 static inline int
81 @@ -188,6 +192,7 @@ static size_t
82 read_lba(struct block_device *bdev, u64 lba, u8 * buffer, size_t count)
83 {
84 size_t totalreadcount = 0;
85 + sector_t n = lba * (bdev_logical_block_size(bdev) / 512);
86
87 if (!bdev || !buffer || lba > last_lba(bdev))
88 return 0;
89 @@ -195,7 +200,7 @@ read_lba(struct block_device *bdev, u64 lba, u8 * buffer, size_t count)
90 while (count) {
91 int copied = 512;
92 Sector sect;
93 - unsigned char *data = read_dev_sector(bdev, lba++, &sect);
94 + unsigned char *data = read_dev_sector(bdev, n++, &sect);
95 if (!data)
96 break;
97 if (copied > count)
98 @@ -601,6 +606,7 @@ efi_partition(struct parsed_partitions *state, struct block_device *bdev)
99 gpt_header *gpt = NULL;
100 gpt_entry *ptes = NULL;
101 u32 i;
102 + unsigned ssz = bdev_logical_block_size(bdev) / 512;
103
104 if (!find_valid_gpt(bdev, &gpt, &ptes) || !gpt || !ptes) {
105 kfree(gpt);
106 @@ -611,13 +617,14 @@ efi_partition(struct parsed_partitions *state, struct block_device *bdev)
107 pr_debug("GUID Partition Table is valid! Yea!\n");
108
109 for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) && i < state->limit-1; i++) {
110 + u64 start = le64_to_cpu(ptes[i].starting_lba);
111 + u64 size = le64_to_cpu(ptes[i].ending_lba) -
112 + le64_to_cpu(ptes[i].starting_lba) + 1ULL;
113 +
114 if (!is_pte_valid(&ptes[i], last_lba(bdev)))
115 continue;
116
117 - put_partition(state, i+1, le64_to_cpu(ptes[i].starting_lba),
118 - (le64_to_cpu(ptes[i].ending_lba) -
119 - le64_to_cpu(ptes[i].starting_lba) +
120 - 1ULL));
121 + put_partition(state, i+1, start * ssz, size * ssz);
122
123 /* If this is a RAID volume, tell md */
124 if (!efi_guidcmp(ptes[i].partition_type_guid,
125

  ViewVC Help
Powered by ViewVC 1.1.20