projects
/
debian
/
efibootmgr
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
incorporate Fedora patch for sector sizes > 512 bytes
[debian/efibootmgr]
/
src
/
lib
/
gpt.c
diff --git
a/src/lib/gpt.c
b/src/lib/gpt.c
index d90ddaf235c072ffe3626c0f358345f1042a59d9..83e7a94fe3eed3231a9b19d2763c29bb2f6818f3 100644
(file)
--- a/
src/lib/gpt.c
+++ b/
src/lib/gpt.c
@@
-215,26
+215,24
@@
read_lastoddsector(int fd, uint64_t lba, void *buffer, size_t count)
static ssize_t
read_lba(int fd, uint64_t lba, void *buffer, size_t bytes)
{
static ssize_t
read_lba(int fd, uint64_t lba, void *buffer, size_t bytes)
{
- int sector_size = get_sector_size(fd);
- off_t offset = lba * sector_size;
+
int sector_size = get_sector_size(fd);
+
off_t offset = lba * sector_size;
ssize_t bytesread;
ssize_t bytesread;
- void *aligned;
- void *unaligned;
-
- if (bytes % sector_size)
- return EINVAL;
+ void *iobuf;
+ size_t iobuf_size;
+ int rc;
-
unaligned = malloc(bytes+sector_size-1
);
- aligned = (void *)
- (((unsigned long)unaligned + sector_size - 1) &
-
~(unsigned long)(sector_size-1))
;
-
memset(aligned
, 0, bytes);
+
iobuf_size = lcm(bytes, sector_size
);
+ rc = posix_memalign(&iobuf, sector_size, iobuf_size);
+ if (rc)
+
return rc
;
+
memset(iobuf
, 0, bytes);
- lseek(fd, offset, SEEK_SET);
-
bytesread = read(fd, aligned, bytes
);
- memcpy(buffer,
aligned, bytesread
);
- free(
unaligned
);
+
lseek(fd, offset, SEEK_SET);
+
bytesread = read(fd, iobuf, iobuf_size
);
+ memcpy(buffer,
iobuf, bytes
);
+ free(
iobuf
);
/* Kludge. This is necessary to read/write the last
block of an odd-sized disk, until Linux 2.5.x kernel fixes.
/* Kludge. This is necessary to read/write the last
block of an odd-sized disk, until Linux 2.5.x kernel fixes.