Merge lp:~jm-leddy/ubuntu/precise/efibootmgr/4k-sectors into lp:ubuntu/precise/efibootmgr

Proposed by James M. Leddy
Status: Merged
Merged at revision: 10
Proposed branch: lp:~jm-leddy/ubuntu/precise/efibootmgr/4k-sectors
Merge into: lp:ubuntu/precise/efibootmgr
Diff against target: 155 lines (+60/-29)
4 files modified
debian/changelog (+7/-0)
src/include/disk.h (+3/-0)
src/lib/disk.c (+33/-10)
src/lib/gpt.c (+17/-19)
To merge this branch: bzr merge lp:~jm-leddy/ubuntu/precise/efibootmgr/4k-sectors
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+179558@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

The version is wrong (s/3/2/), but I'll fix that up. Otherwise this looks fine. Thanks, and sorry for the delay!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2008-06-09 14:05:32 +0000
3+++ debian/changelog 2013-08-10 01:02:47 +0000
4@@ -1,3 +1,10 @@
5+efibootmgr (0.5.4-3ubuntu1.1) precise; urgency=low
6+
7+ * Apply Fedora patch (efibootmgr-0.5.4-support-4k-sectors.patch) to
8+ support non-512-byte logical sectors (LP: #1065281).
9+
10+ -- James M Leddy <james.leddy@canonical.com> Fri, 09 Aug 2013 20:49:39 -0400
11+
12 efibootmgr (0.5.4-2ubuntu1) intrepid; urgency=low
13
14 * Merge from debian unstable, remaining changes:
15
16=== modified file 'src/include/disk.h'
17--- src/include/disk.h 2004-08-27 23:12:38 +0000
18+++ src/include/disk.h 2013-08-10 01:02:47 +0000
19@@ -65,6 +65,9 @@
20 ata, atapi, scsi, usb,
21 i1394, fibre, i2o, md};
22
23+
24+unsigned int lcm(unsigned int x, unsigned int y);
25+
26 int disk_get_pci(int fd,
27 unsigned char *bus,
28 unsigned char *device,
29
30=== modified file 'src/lib/disk.c'
31--- src/lib/disk.c 2006-04-01 22:00:02 +0000
32+++ src/lib/disk.c 2013-08-10 01:02:47 +0000
33@@ -420,6 +420,27 @@
34 return sector_size;
35 }
36
37+/************************************************************
38+ * lcm
39+ * Requires:
40+ * - numbers of which to find the lowest common multiple
41+ * Modifies: nothing
42+ * Returns:
43+ * lowest common multiple of x and y
44+ ************************************************************/
45+unsigned int
46+lcm(unsigned int x, unsigned int y)
47+{
48+ unsigned int m = x, n = y, o;
49+
50+ while ((o = m % n)) {
51+ m = n;
52+ n = o;
53+ }
54+
55+ return (x / n) * y;
56+}
57+
58 /**
59 * disk_get_partition_info()
60 * @fd - open file descriptor to disk
61@@ -442,26 +463,27 @@
62 uint8_t *mbr_type, uint8_t *signature_type)
63 {
64 legacy_mbr *mbr;
65- void *mbr_unaligned;
66+ void *mbr_sector;
67+ size_t mbr_size;
68 off_t offset;
69 int this_bytes_read = 0;
70 int gpt_invalid=0, mbr_invalid=0;
71 int rc=0;
72 int sector_size = get_sector_size(fd);
73
74- if (sizeof(*mbr) != sector_size)
75- return 1;
76- mbr_unaligned = malloc(sizeof(*mbr)+sector_size-1);
77- mbr = (legacy_mbr *)
78- (((unsigned long)mbr_unaligned + sector_size - 1) &
79- ~(unsigned long)(sector_size-1));
80- memset(mbr, 0, sizeof(*mbr));
81+
82+ mbr_size = lcm(sizeof(*mbr), sector_size);
83+ if ((rc = posix_memalign(&mbr_sector, sector_size, mbr_size)) != 0)
84+ goto error;
85+ memset(mbr_sector, '\0', mbr_size);
86+
87 offset = lseek(fd, 0, SEEK_SET);
88- this_bytes_read = read(fd, mbr, sizeof(*mbr));
89+ this_bytes_read = read(fd, mbr_sector, mbr_size);
90 if (this_bytes_read < sizeof(*mbr)) {
91 rc=1;
92 goto error_free_mbr;
93 }
94+ mbr = (legacy_mbr *)mbr_sector;
95 gpt_invalid = gpt_disk_get_partition_info(fd, num,
96 start, size,
97 signature,
98@@ -479,7 +501,8 @@
99 }
100 }
101 error_free_mbr:
102- free(mbr_unaligned);
103+ free(mbr_sector);
104+ error:
105 return rc;
106 }
107
108
109=== modified file 'src/lib/gpt.c'
110--- src/lib/gpt.c 2008-04-28 18:12:40 +0000
111+++ src/lib/gpt.c 2013-08-10 01:02:47 +0000
112@@ -215,26 +215,24 @@
113 static ssize_t
114 read_lba(int fd, uint64_t lba, void *buffer, size_t bytes)
115 {
116- int sector_size = get_sector_size(fd);
117- off_t offset = lba * sector_size;
118+ int sector_size = get_sector_size(fd);
119+ off_t offset = lba * sector_size;
120 ssize_t bytesread;
121- void *aligned;
122- void *unaligned;
123-
124- if (bytes % sector_size)
125- return EINVAL;
126-
127- unaligned = malloc(bytes+sector_size-1);
128- aligned = (void *)
129- (((unsigned long)unaligned + sector_size - 1) &
130- ~(unsigned long)(sector_size-1));
131- memset(aligned, 0, bytes);
132-
133-
134- lseek(fd, offset, SEEK_SET);
135- bytesread = read(fd, aligned, bytes);
136- memcpy(buffer, aligned, bytesread);
137- free(unaligned);
138+ void *iobuf;
139+ size_t iobuf_size;
140+ int rc;
141+
142+ iobuf_size = lcm(bytes, sector_size);
143+ rc = posix_memalign(&iobuf, sector_size, iobuf_size);
144+ if (rc)
145+ return rc;
146+ memset(iobuf, 0, bytes);
147+
148+
149+ lseek(fd, offset, SEEK_SET);
150+ bytesread = read(fd, iobuf, iobuf_size);
151+ memcpy(buffer, iobuf, bytes);
152+ free(iobuf);
153
154 /* Kludge. This is necessary to read/write the last
155 block of an odd-sized disk, until Linux 2.5.x kernel fixes.

Subscribers

People subscribed via source and target branches