* [PATCH for-4.5] pygrub: fix read sizes on FreeBSD
@ 2014-09-26 15:31 Roger Pau Monne
2014-09-26 15:54 ` Ian Jackson
0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monne @ 2014-09-26 15:31 UTC (permalink / raw)
To: xen-devel
Cc: Wei Liu, Ian Campbell, Stefano Stabellini, Ian Jackson,
Roger Pau Monne
FreeBSD only allows reading multiples of sector size from raw disk devices
(character devices). This fix should only alter the behaviour of pygrub on
FreeBSD, the other supported OSes will continue using the same size.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
I request a code freeze exception on the basis that this is a bugfix and it
doesn't change the behaviour on platforms different than FreeBSD.
---
tools/pygrub/src/pygrub | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index e73a174..1ae34a2 100644
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -13,7 +13,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
-import os, sys, string, struct, tempfile, re, traceback
+import os, sys, string, struct, tempfile, re, traceback, stat
import copy
import logging
import platform
@@ -29,6 +29,16 @@ import grub.ExtLinuxConf
PYGRUB_VER = 0.6
FS_READ_MAX = 1024 * 1024
+SECTOR_SIZE = 512
+
+def read_size_roundup(fd, size):
+ if platform.system() != 'FreeBSD':
+ return size
+ st = os.fstat(fd)
+ if (not stat.S_ISCHR(st.st_mode)):
+ return size
+ # Round up to sector size if it's a raw character device
+ return (((size)+((SECTOR_SIZE)-1))&(~((SECTOR_SIZE)-1)))
def enable_cursor(ison):
if ison:
@@ -45,7 +55,7 @@ DISK_TYPE_RAW, DISK_TYPE_HYBRIDISO, DISK_TYPE_DOS = range(3)
def identify_disk_image(file):
"""Detect DOS partition table or HybridISO format."""
fd = os.open(file, os.O_RDONLY)
- buf = os.read(fd, 0x8006)
+ buf = os.read(fd, read_size_roundup(fd, 0x8006))
os.close(fd)
if len(buf) >= 512 and \
@@ -56,7 +66,6 @@ def identify_disk_image(file):
return DISK_TYPE_DOS
return DISK_TYPE_RAW
-SECTOR_SIZE=512
DK_LABEL_LOC=1
DKL_MAGIC=0xdabe
V_ROOT=0x2
@@ -91,7 +100,7 @@ def get_fs_offset_gpt(file):
i = partcount
offsets = []
while i>0:
- buf = os.read(fd, partsize)
+ buf = os.read(fd, read_size_roundup(fd, partsize))
offsets.append(struct.unpack("<Q", buf[32:40])[0] * SECTOR_SIZE)
i -= 1
os.close(fd)
--
1.9.3 (Apple Git-50)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH for-4.5] pygrub: fix read sizes on FreeBSD
2014-09-26 15:31 [PATCH for-4.5] pygrub: fix read sizes on FreeBSD Roger Pau Monne
@ 2014-09-26 15:54 ` Ian Jackson
2014-09-26 18:08 ` Konrad Rzeszutek Wilk
0 siblings, 1 reply; 4+ messages in thread
From: Ian Jackson @ 2014-09-26 15:54 UTC (permalink / raw)
To: Roger Pau Monne; +Cc: xen-devel, Wei Liu, Ian Campbell, Stefano Stabellini
Roger Pau Monne writes ("[PATCH for-4.5] pygrub: fix read sizes on FreeBSD"):
> FreeBSD only allows reading multiples of sector size from raw disk devices
> (character devices). This fix should only alter the behaviour of pygrub on
> FreeBSD, the other supported OSes will continue using the same size.
>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Wei Liu <wei.liu2@citrix.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
> I request a code freeze exception on the basis that this is a bugfix and it
> doesn't change the behaviour on platforms different than FreeBSD.
This sounds reasonable to me (but of course the decision is Konrad's).
Ian.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-4.5] pygrub: fix read sizes on FreeBSD
2014-09-26 15:54 ` Ian Jackson
@ 2014-09-26 18:08 ` Konrad Rzeszutek Wilk
2014-09-29 13:35 ` Ian Campbell
0 siblings, 1 reply; 4+ messages in thread
From: Konrad Rzeszutek Wilk @ 2014-09-26 18:08 UTC (permalink / raw)
To: Ian Jackson
Cc: xen-devel, Stefano Stabellini, Wei Liu, Ian Campbell,
Roger Pau Monne
On Fri, Sep 26, 2014 at 04:54:51PM +0100, Ian Jackson wrote:
> Roger Pau Monne writes ("[PATCH for-4.5] pygrub: fix read sizes on FreeBSD"):
> > FreeBSD only allows reading multiples of sector size from raw disk devices
> > (character devices). This fix should only alter the behaviour of pygrub on
> > FreeBSD, the other supported OSes will continue using the same size.
> >
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > Cc: Ian Campbell <ian.campbell@citrix.com>
> > Cc: Wei Liu <wei.liu2@citrix.com>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>
> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
>
> > I request a code freeze exception on the basis that this is a bugfix and it
> > doesn't change the behaviour on platforms different than FreeBSD.
>
> This sounds reasonable to me (but of course the decision is Konrad's).
Released-Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>
> Ian.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH for-4.5] pygrub: fix read sizes on FreeBSD
2014-09-26 18:08 ` Konrad Rzeszutek Wilk
@ 2014-09-29 13:35 ` Ian Campbell
0 siblings, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2014-09-29 13:35 UTC (permalink / raw)
To: Konrad Rzeszutek Wilk
Cc: xen-devel, Stefano Stabellini, Ian Jackson, Wei Liu,
Roger Pau Monne
On Fri, 2014-09-26 at 14:08 -0400, Konrad Rzeszutek Wilk wrote:
> On Fri, Sep 26, 2014 at 04:54:51PM +0100, Ian Jackson wrote:
> > Roger Pau Monne writes ("[PATCH for-4.5] pygrub: fix read sizes on FreeBSD"):
> > > FreeBSD only allows reading multiples of sector size from raw disk devices
> > > (character devices). This fix should only alter the behaviour of pygrub on
> > > FreeBSD, the other supported OSes will continue using the same size.
> > >
> > > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > > Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> > > Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > > Cc: Ian Campbell <ian.campbell@citrix.com>
> > > Cc: Wei Liu <wei.liu2@citrix.com>
> > > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> >
> > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
> >
> > > I request a code freeze exception on the basis that this is a bugfix and it
> > > doesn't change the behaviour on platforms different than FreeBSD.
> >
> > This sounds reasonable to me (but of course the decision is Konrad's).
>
> Released-Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Applied.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-29 13:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-26 15:31 [PATCH for-4.5] pygrub: fix read sizes on FreeBSD Roger Pau Monne
2014-09-26 15:54 ` Ian Jackson
2014-09-26 18:08 ` Konrad Rzeszutek Wilk
2014-09-29 13:35 ` Ian Campbell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).