diff options
Diffstat (limited to 'meta-linaro/recipes-extra/efibootmgr/files/efibootmgr-0.5.4-support-4k-sectors.patch')
-rw-r--r-- | meta-linaro/recipes-extra/efibootmgr/files/efibootmgr-0.5.4-support-4k-sectors.patch | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/meta-linaro/recipes-extra/efibootmgr/files/efibootmgr-0.5.4-support-4k-sectors.patch b/meta-linaro/recipes-extra/efibootmgr/files/efibootmgr-0.5.4-support-4k-sectors.patch new file mode 100644 index 0000000..c380c61 --- /dev/null +++ b/meta-linaro/recipes-extra/efibootmgr/files/efibootmgr-0.5.4-support-4k-sectors.patch | |||
@@ -0,0 +1,176 @@ | |||
1 | Return-Path: pjones@redhat.com | ||
2 | Received: from zmta02.collab.prod.int.phx2.redhat.com (LHLO | ||
3 | zmta02.collab.prod.int.phx2.redhat.com) (10.5.5.32) by | ||
4 | mail04.corp.redhat.com with LMTP; Wed, 14 Jul 2010 14:25:52 -0400 (EDT) | ||
5 | Received: from localhost (localhost.localdomain [127.0.0.1]) | ||
6 | by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id B69C19F152 | ||
7 | for <pjones@redhat.com>; Wed, 14 Jul 2010 14:25:52 -0400 (EDT) | ||
8 | Received: from zmta02.collab.prod.int.phx2.redhat.com ([127.0.0.1]) | ||
9 | by localhost (zmta02.collab.prod.int.phx2.redhat.com [127.0.0.1]) (amavisd-new, port 10024) | ||
10 | with ESMTP id jCHcGZehMQ5J for <pjones@redhat.com>; | ||
11 | Wed, 14 Jul 2010 14:25:52 -0400 (EDT) | ||
12 | Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) | ||
13 | by zmta02.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id A601C9F14C | ||
14 | for <pjones@mail.corp.redhat.com>; Wed, 14 Jul 2010 14:25:52 -0400 (EDT) | ||
15 | Received: from pjones4.install.bos.redhat.com (pjones4.install.bos.redhat.com [10.16.52.154]) | ||
16 | by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6EIPpGh017771; | ||
17 | Wed, 14 Jul 2010 14:25:52 -0400 | ||
18 | From: Peter Jones <pjones@redhat.com> | ||
19 | To: Matt Domsch <Matt_Domsch@dell.com> | ||
20 | Cc: Peter Jones <pjones@redhat.com>, Stuart Hayes <stuart_hayes@dell.com> | ||
21 | Subject: [efibootmgr patch] Handle sector_size != 512. | ||
22 | Date: Wed, 14 Jul 2010 14:26:49 -0400 | ||
23 | Message-Id: <1279132009-26635-1-git-send-email-pjones@redhat.com> | ||
24 | In-Reply-To: <1279121617-17961-1-git-send-email-pjones@redhat.com> | ||
25 | References: <1279121617-17961-1-git-send-email-pjones@redhat.com> | ||
26 | X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 | ||
27 | |||
28 | Disks can have 4kB sectors now, so don't just bail out when that's the | ||
29 | case. | ||
30 | --- | ||
31 | src/include/disk.h | 3 +++ | ||
32 | src/lib/disk.c | 43 +++++++++++++++++++++++++++++++++---------- | ||
33 | src/lib/gpt.c | 30 ++++++++++++++---------------- | ||
34 | 3 files changed, 50 insertions(+), 26 deletions(-) | ||
35 | |||
36 | diff --git a/src/include/disk.h b/src/include/disk.h | ||
37 | index eb93d10..8aa37d7 100644 | ||
38 | --- a/src/include/disk.h | ||
39 | +++ b/src/include/disk.h | ||
40 | @@ -65,6 +65,9 @@ enum _interface_type {interface_type_unknown, | ||
41 | ata, atapi, scsi, usb, | ||
42 | i1394, fibre, i2o, md}; | ||
43 | |||
44 | + | ||
45 | +unsigned int lcm(unsigned int x, unsigned int y); | ||
46 | + | ||
47 | int disk_get_pci(int fd, | ||
48 | unsigned char *bus, | ||
49 | unsigned char *device, | ||
50 | diff --git a/src/lib/disk.c b/src/lib/disk.c | ||
51 | index 883864f..9c3a878 100644 | ||
52 | --- a/src/lib/disk.c | ||
53 | +++ b/src/lib/disk.c | ||
54 | @@ -420,6 +420,27 @@ get_sector_size(int filedes) | ||
55 | return sector_size; | ||
56 | } | ||
57 | |||
58 | +/************************************************************ | ||
59 | + * lcm | ||
60 | + * Requires: | ||
61 | + * - numbers of which to find the lowest common multiple | ||
62 | + * Modifies: nothing | ||
63 | + * Returns: | ||
64 | + * lowest common multiple of x and y | ||
65 | + ************************************************************/ | ||
66 | +unsigned int | ||
67 | +lcm(unsigned int x, unsigned int y) | ||
68 | +{ | ||
69 | + unsigned int m = x, n = y, o; | ||
70 | + | ||
71 | + while ((o = m % n)) { | ||
72 | + m = n; | ||
73 | + n = o; | ||
74 | + } | ||
75 | + | ||
76 | + return (x / n) * y; | ||
77 | +} | ||
78 | + | ||
79 | /** | ||
80 | * disk_get_partition_info() | ||
81 | * @fd - open file descriptor to disk | ||
82 | @@ -442,26 +463,27 @@ disk_get_partition_info (int fd, | ||
83 | uint8_t *mbr_type, uint8_t *signature_type) | ||
84 | { | ||
85 | legacy_mbr *mbr; | ||
86 | - void *mbr_unaligned; | ||
87 | + void *mbr_sector; | ||
88 | + size_t mbr_size; | ||
89 | off_t offset; | ||
90 | int this_bytes_read = 0; | ||
91 | int gpt_invalid=0, mbr_invalid=0; | ||
92 | int rc=0; | ||
93 | int sector_size = get_sector_size(fd); | ||
94 | |||
95 | - if (sizeof(*mbr) != sector_size) | ||
96 | - return 1; | ||
97 | - mbr_unaligned = malloc(sizeof(*mbr)+sector_size-1); | ||
98 | - mbr = (legacy_mbr *) | ||
99 | - (((unsigned long)mbr_unaligned + sector_size - 1) & | ||
100 | - ~(unsigned long)(sector_size-1)); | ||
101 | - memset(mbr, 0, sizeof(*mbr)); | ||
102 | + | ||
103 | + mbr_size = lcm(sizeof(*mbr), sector_size); | ||
104 | + if ((rc = posix_memalign(&mbr_sector, sector_size, mbr_size)) != 0) | ||
105 | + goto error; | ||
106 | + memset(mbr_sector, '\0', mbr_size); | ||
107 | + | ||
108 | offset = lseek(fd, 0, SEEK_SET); | ||
109 | - this_bytes_read = read(fd, mbr, sizeof(*mbr)); | ||
110 | + this_bytes_read = read(fd, mbr_sector, mbr_size); | ||
111 | if (this_bytes_read < sizeof(*mbr)) { | ||
112 | rc=1; | ||
113 | goto error_free_mbr; | ||
114 | } | ||
115 | + mbr = (legacy_mbr *)mbr_sector; | ||
116 | gpt_invalid = gpt_disk_get_partition_info(fd, num, | ||
117 | start, size, | ||
118 | signature, | ||
119 | @@ -479,7 +501,8 @@ disk_get_partition_info (int fd, | ||
120 | } | ||
121 | } | ||
122 | error_free_mbr: | ||
123 | - free(mbr_unaligned); | ||
124 | + free(mbr_sector); | ||
125 | + error: | ||
126 | return rc; | ||
127 | } | ||
128 | |||
129 | diff --git a/src/lib/gpt.c b/src/lib/gpt.c | ||
130 | index d90ddaf..83e7a94 100644 | ||
131 | --- a/src/lib/gpt.c | ||
132 | +++ b/src/lib/gpt.c | ||
133 | @@ -215,26 +215,24 @@ read_lastoddsector(int fd, uint64_t lba, void *buffer, size_t count) | ||
134 | static ssize_t | ||
135 | read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) | ||
136 | { | ||
137 | - int sector_size = get_sector_size(fd); | ||
138 | - off_t offset = lba * sector_size; | ||
139 | + int sector_size = get_sector_size(fd); | ||
140 | + off_t offset = lba * sector_size; | ||
141 | ssize_t bytesread; | ||
142 | - void *aligned; | ||
143 | - void *unaligned; | ||
144 | - | ||
145 | - if (bytes % sector_size) | ||
146 | - return EINVAL; | ||
147 | + void *iobuf; | ||
148 | + size_t iobuf_size; | ||
149 | + int rc; | ||
150 | |||
151 | - unaligned = malloc(bytes+sector_size-1); | ||
152 | - aligned = (void *) | ||
153 | - (((unsigned long)unaligned + sector_size - 1) & | ||
154 | - ~(unsigned long)(sector_size-1)); | ||
155 | - memset(aligned, 0, bytes); | ||
156 | + iobuf_size = lcm(bytes, sector_size); | ||
157 | + rc = posix_memalign(&iobuf, sector_size, iobuf_size); | ||
158 | + if (rc) | ||
159 | + return rc; | ||
160 | + memset(iobuf, 0, bytes); | ||
161 | |||
162 | |||
163 | - lseek(fd, offset, SEEK_SET); | ||
164 | - bytesread = read(fd, aligned, bytes); | ||
165 | - memcpy(buffer, aligned, bytesread); | ||
166 | - free(unaligned); | ||
167 | + lseek(fd, offset, SEEK_SET); | ||
168 | + bytesread = read(fd, iobuf, iobuf_size); | ||
169 | + memcpy(buffer, iobuf, bytes); | ||
170 | + free(iobuf); | ||
171 | |||
172 | /* Kludge. This is necessary to read/write the last | ||
173 | block of an odd-sized disk, until Linux 2.5.x kernel fixes. | ||
174 | -- | ||
175 | 1.7.1.1 | ||
176 | |||