if __name__ == "__main__":
if len(sys.argv) < 3:
raise RuntimeError('Need a grub version ("grub" or "grub2") and a grub.conf or grub.cfg to read')
-diff -urN xen-4.16.2.orig/tools/pygrub/src/pygrub xen-4.16.2/tools/pygrub/src/pygrub
---- xen-4.16.2.orig/tools/pygrub/src/pygrub 2023-07-23 20:27:00.751415259 +0200
-+++ xen-4.16.2/tools/pygrub/src/pygrub 2023-07-23 20:27:33.483877715 +0200
-@@ -46,7 +46,7 @@
+--- xen-4.17.3/tools/pygrub/src/pygrub.orig 2024-04-05 06:22:57.454008289 +0200
++++ xen-4.17.3/tools/pygrub/src/pygrub 2024-04-05 06:27:33.762543552 +0200
+@@ -173,7 +173,7 @@ def enable_cursor(ison):
val = 2
else:
val = 0
try:
curses.curs_set(val)
except _curses.error:
-@@ -114,7 +114,7 @@
+@@ -241,7 +241,7 @@ FDISK_PART_GPT=0xee
def get_partition_offsets(file):
image_type = identify_disk_image(file)
if image_type == DISK_TYPE_RAW:
# single partition starting at 0
return [0]
elif image_type == DISK_TYPE_HYBRIDISO:
-@@ -136,7 +136,7 @@
+@@ -263,7 +263,7 @@ def get_partition_offsets(file):
partbuf = buf[poff:poff+16]
offset = struct.unpack("<L", partbuf[8:12])[0] * SECTOR_SIZE
type = struct.unpack("<B", partbuf[4:5])[0]
# offset == 0 implies this partition is not enabled
if offset == 0:
offzerocount += 1
-@@ -176,7 +176,7 @@
+@@ -303,7 +303,7 @@ class GrubLineEditor(curses.textpad.Text
screen.noutrefresh()
win = curses.newwin(1, 74, startx, starty + 2)
curses.textpad.Textbox.__init__(self, win)
self.line = list(line)
self.pos = len(line)
self.cancelled = False
-@@ -242,7 +242,7 @@
+@@ -369,7 +369,7 @@ class GrubLineEditor(curses.textpad.Text
if self.cancelled:
return None
return string.join(self.line, "")
class Grub:
ENTRY_WIN_LINES = 8
-@@ -266,7 +266,7 @@
+@@ -393,7 +393,7 @@ class Grub:
self.entry_win = curses.newwin(Grub.ENTRY_WIN_LINES + 2, 74, 2, 1)
self.text_win = curses.newwin(10, 70, 12, 5)
curses.def_prog_mode()
curses.reset_prog_mode()
self.screen.erase()
-@@ -284,7 +284,7 @@
+@@ -411,7 +411,7 @@ class Grub:
self.start_image = self.selected_image
if self.selected_image < self.start_image:
self.start_image = self.selected_image
for y in range(self.start_image, len(self.cf.images)):
i = self.cf.images[y]
if y > self.start_image + maxy:
-@@ -334,7 +334,7 @@
+@@ -461,7 +461,7 @@ class Grub:
l = img.lines[idx].expandtabs().ljust(70)
if len(l) > 70:
l = l[:69] + ">"
self.entry_win.addstr(idp, 2, l)
if idx == curline:
self.entry_win.attroff(curses.A_REVERSE)
-@@ -372,7 +372,7 @@
+@@ -499,7 +499,7 @@ class Grub:
self.command_line_mode()
if self.isdone:
return
# bound at the top and bottom
if curline < 0:
curline = 0
-@@ -405,7 +405,7 @@
+@@ -532,7 +532,7 @@ class Grub:
lines = []
while 1:
t = GrubLineEditor(self.screen, y, 2)
ret = t.edit()
if ret:
if ret in ("quit", "return"):
-@@ -415,7 +415,7 @@
+@@ -542,7 +542,7 @@ class Grub:
lines.append(ret)
continue
img = self.cf.new_image("entered", lines)
self.cf.add_image(img)
self.selected_image = len(self.cf.images) - 1
-@@ -428,7 +428,7 @@
+@@ -555,7 +555,7 @@ class Grub:
def read_config(self, fn, fs = None):
"""Read the given file to parse the config. If fs = None, then
we're being given a raw config file rather than a disk image."""
if not os.access(fn, os.R_OK):
raise RuntimeError("Unable to access %s" %(fn,))
-@@ -504,7 +504,7 @@
+@@ -631,7 +631,7 @@ class Grub:
while not self.isdone:
self.run_main(timeout)
timeout = -1
return self.selected_image
def run_main(self, timeout = -1):
-@@ -534,7 +534,7 @@
+@@ -661,7 +661,7 @@ class Grub:
self.start_image = 0
while (timeout == -1 or mytime < int(timeout)):
draw()
self.screen.addstr(20, 5, "Will boot selected entry in %2d seconds"
%(int(timeout) - mytime))
else:
-@@ -605,7 +605,7 @@
+@@ -732,7 +732,7 @@ class Grub:
self.selected_image = 0
elif self.selected_image >= len(self.cf.images):
self.selected_image = len(self.cf.images) - 1
def get_entry_idx(cf, entry):
# first, see if the given entry is numeric
try:
-@@ -702,10 +702,10 @@
+@@ -820,10 +820,10 @@ def sniff_solaris(fs, cfg):
# Unpleasant. Typically we'll have 'root=foo -k' or 'root=foo /kernel -k',
# and we need to maintain Xen properties (root= and ip=) and the kernel
# before any user args.
if not cfg["args"]:
cfg["args"] = cfg["kernel"]
else:
-@@ -717,7 +717,7 @@
+@@ -835,7 +835,7 @@ def sniff_solaris(fs, cfg):
cfg["args"] = xenargs + " " + cfg["kernel"] + " " + userargs
return cfg
def sniff_netware(fs, cfg):
if not fs.file_exists("/nwserver/xnloader.sys"):
return cfg
-@@ -734,7 +734,7 @@
+@@ -852,7 +852,7 @@ def format_sxp(kernel, ramdisk, args):
if args:
s += "(args %s)" % repr(args)
return s
def format_simple(kernel, ramdisk, args, sep):
for check in (kernel, ramdisk, args):
if check is not None and sep in check:
-@@ -749,7 +749,7 @@
+@@ -867,7 +867,7 @@ def format_simple(kernel, ramdisk, args,
if __name__ == "__main__":
sel = None
-
+
def usage():
- print("Usage: %s [-q|--quiet] [-i|--interactive] [-l|--list-entries] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] [--offset=] <image>" %(sys.argv[0],), file=sys.stderr)
-
-@@ -788,7 +788,7 @@
- opts, args = getopt.gnu_getopt(sys.argv[1:], 'qilnh::',
- ["quiet", "interactive", "list-entries", "not-really", "help",
- "output=", "output-format=", "output-directory=", "offset=",
-- "entry=", "kernel=",
-+ "entry=", "kernel=",
- "ramdisk=", "args=", "isconfig", "debug"])
- except getopt.GetoptError:
- usage()
-@@ -972,4 +972,4 @@
+ print("Usage: %s [-q|--quiet] [-i|--interactive] [-l|--list-entries] [-n|--not-really] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] [--output-directory=] [--output-format=sxp|simple|simple0] [--runas=] [--offset=] <image>" %(sys.argv[0],), file=sys.stderr)
+
+@@ -1113,4 +1113,4 @@ if __name__ == "__main__":
os.write(fd, ostring)
else:
os.write(fd, ostring.encode())