]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/patches/grub-0.97-once.patch
strongswan: Update to 5.0.1.
[people/teissler/ipfire-2.x.git] / src / patches / grub-0.97-once.patch
CommitLineData
82705b6e
MT
1--- grub-0.97/stage2/builtins.c.bootonce 2005-12-12 18:23:12.000000000 -0500
2+++ grub-0.97/stage2/builtins.c 2005-12-12 18:29:20.000000000 -0500
3@@ -3217,146 +3217,175 @@
4 };
5
6 \f
7-/* savedefault */
8+
9+#if !defined(SUPPORT_DISKLESS) && !defined(GRUB_UTIL)
10+/* Write specified default entry number into stage2 file. */
11 static int
12-savedefault_func (char *arg, int flags)
13+savedefault_helper(int new_default)
14 {
15-#if !defined(SUPPORT_DISKLESS) && !defined(GRUB_UTIL)
16- unsigned long tmp_drive = saved_drive;
17- unsigned long tmp_partition = saved_partition;
18- char *default_file = (char *) DEFAULT_FILE_BUF;
19- char buf[10];
20- char sect[SECTOR_SIZE];
21- int entryno;
22- int sector_count = 0;
23- int saved_sectors[2];
24- int saved_offsets[2];
25- int saved_lengths[2];
26-
27- /* Save sector information about at most two sectors. */
28- auto void disk_read_savesect_func (int sector, int offset, int length);
29- void disk_read_savesect_func (int sector, int offset, int length)
30- {
31- if (sector_count < 2)
32- {
33- saved_sectors[sector_count] = sector;
34- saved_offsets[sector_count] = offset;
35- saved_lengths[sector_count] = length;
36- }
37- sector_count++;
38- }
39-
40- /* This command is only useful when you boot an entry from the menu
41- interface. */
42- if (! (flags & BUILTIN_SCRIPT))
43+ char buffer[512];
44+ int *entryno_ptr;
45+
46+ /* Get the geometry of the boot drive (i.e. the disk which contains
47+ this stage2). */
48+ if (get_diskinfo (boot_drive, &buf_geom))
49 {
50- errnum = ERR_UNRECOGNIZED;
51+ errnum = ERR_NO_DISK;
52 return 1;
53 }
54
55- /* Determine a saved entry number. */
56- if (*arg)
57+ /* Load the second sector of this stage2. */
58+ if (! rawread (boot_drive, install_second_sector, 0, SECTOR_SIZE, buffer))
59 {
60- if (grub_memcmp (arg, "fallback", sizeof ("fallback") - 1) == 0)
61- {
62- int i;
63- int index = 0;
64-
65- for (i = 0; i < MAX_FALLBACK_ENTRIES; i++)
66- {
67- if (fallback_entries[i] < 0)
68- break;
69- if (fallback_entries[i] == current_entryno)
70- {
71- index = i + 1;
72- break;
73- }
74- }
75-
76- if (index >= MAX_FALLBACK_ENTRIES || fallback_entries[index] < 0)
77- {
78- /* This is the last. */
79- errnum = ERR_BAD_ARGUMENT;
80- return 1;
81- }
82+ return 1;
83+ }
84
85- entryno = fallback_entries[index];
86- }
87- else if (! safe_parse_maxint (&arg, &entryno))
88- return 1;
89+ /* Sanity check. */
90+ if (buffer[STAGE2_STAGE2_ID] != STAGE2_ID_STAGE2
91+ || *((short *) (buffer + STAGE2_VER_MAJ_OFFS)) != COMPAT_VERSION)
92+ {
93+ errnum = ERR_BAD_VERSION;
94+ return 1;
95 }
96- else
97- entryno = current_entryno;
98+
99+ entryno_ptr = (int *) (buffer + STAGE2_SAVED_ENTRYNO);
100
101- /* Open the default file. */
102- saved_drive = boot_drive;
103- saved_partition = install_partition;
104- if (grub_open (default_file))
105+ /* Check if the saved entry number differs from current entry number. */
106+ if (*entryno_ptr != new_default)
107 {
108- int len;
109+ /* Overwrite the saved entry number. */
110+ *entryno_ptr = new_default;
111
112- disk_read_hook = disk_read_savesect_func;
113- len = grub_read (buf, sizeof (buf));
114- disk_read_hook = 0;
115- grub_close ();
116+ /* Save the image in the disk. */
117+ if (! rawwrite (boot_drive, install_second_sector, buffer))
118+ return 1;
119
120- if (len != sizeof (buf))
121- {
122- /* This is too small. Do not modify the file manually, please! */
123- errnum = ERR_READ;
124- goto fail;
125- }
126+ /* Clear the cache. */
127+ buf_track = -1;
128+ }
129
130- if (sector_count > 2)
131- {
132- /* Is this possible?! Too fragmented! */
133- errnum = ERR_FSYS_CORRUPT;
134- goto fail;
135- }
136-
137- /* Set up a string to be written. */
138- grub_memset (buf, '\n', sizeof (buf));
139- grub_sprintf (buf, "%d", entryno);
140-
141- if (saved_lengths[0] < sizeof (buf))
142- {
143- /* The file is anchored to another file and the first few bytes
144- are spanned in two sectors. Uggh... */
145- if (! rawread (current_drive, saved_sectors[0], 0, SECTOR_SIZE,
146- sect))
147- goto fail;
148- grub_memmove (sect + saved_offsets[0], buf, saved_lengths[0]);
149- if (! rawwrite (current_drive, saved_sectors[0], sect))
150- goto fail;
151+ return 0;
152+}
153+#endif
154
155- if (! rawread (current_drive, saved_sectors[1], 0, SECTOR_SIZE,
156- sect))
157- goto fail;
158- grub_memmove (sect + saved_offsets[1],
159- buf + saved_lengths[0],
160- sizeof (buf) - saved_lengths[0]);
161- if (! rawwrite (current_drive, saved_sectors[1], sect))
162- goto fail;
163- }
164+#if !defined(SUPPORT_DISKLESS) && defined(GRUB_UTIL)
165+/*
166+ * Full implementation of new `savedefault' for GRUB shell.
167+ * XXX This needs fixing for stage2 files which aren't accessible
168+ * through a mounted filesystem.
169+ */
170+static int
171+savedefault_shell(char *arg, int flags)
172+{
173+ char *stage2_os_file = "/boot/grub/stage2"; /* Default filename */
174+ FILE *fp;
175+ char buffer[512];
176+ int *entryno_ptr;
177+ int new_default = 0;
178+ int old_default = 0;
179+
180+ while (1)
181+ {
182+ if (grub_memcmp ("--stage2=", arg, sizeof ("--stage2=") - 1) == 0)
183+ {
184+ stage2_os_file = arg + sizeof ("--stage2=") - 1;
185+ arg = skip_to (0, arg);
186+ nul_terminate (stage2_os_file);
187+ }
188+ else if (grub_memcmp ("--default=", arg, sizeof ("--default=") - 1) == 0)
189+ {
190+ char *p = arg + sizeof ("--default=") - 1;
191+ if (! safe_parse_maxint (&p, &new_default))
192+ return 1;
193+ arg = skip_to (0, arg);
194+ }
195+ else if (grub_memcmp ("--once", arg, sizeof ("--once") - 1) == 0)
196+ {
197+ new_default <<= 8;
198+ new_default |= STAGE2_ONCEONLY_ENTRY;
199+ arg = skip_to (0, arg);
200+ }
201 else
202- {
203- /* This is a simple case. It fits into a single sector. */
204- if (! rawread (current_drive, saved_sectors[0], 0, SECTOR_SIZE,
205- sect))
206- goto fail;
207- grub_memmove (sect + saved_offsets[0], buf, sizeof (buf));
208- if (! rawwrite (current_drive, saved_sectors[0], sect))
209- goto fail;
210- }
211+ break;
212+ }
213
214- /* Clear the cache. */
215- buf_track = -1;
216+ if (! (fp = fopen(stage2_os_file, "r+")))
217+ {
218+ errnum = ERR_FILE_NOT_FOUND;
219+ return 1;
220+ }
221+
222+ if (fseek (fp, SECTOR_SIZE, SEEK_SET) != 0)
223+ {
224+ fclose (fp);
225+ errnum = ERR_BAD_VERSION;
226+ return 1;
227+ }
228+
229+ if (fread (buffer, 1, SECTOR_SIZE, fp) != SECTOR_SIZE)
230+ {
231+ fclose (fp);
232+ errnum = ERR_READ;
233+ return 1;
234 }
235
236- fail:
237- saved_drive = tmp_drive;
238- saved_partition = tmp_partition;
239- return errnum;
240+ /* Sanity check. */
241+ if (buffer[STAGE2_STAGE2_ID] != STAGE2_ID_STAGE2
242+ || *((short *) (buffer + STAGE2_VER_MAJ_OFFS)) != COMPAT_VERSION)
243+ {
244+ errnum = ERR_BAD_VERSION;
245+ return 1;
246+ }
247+
248+ entryno_ptr = (int *) (buffer + STAGE2_SAVED_ENTRYNO);
249+ if (new_default & STAGE2_ONCEONLY_ENTRY)
250+ {
251+ old_default=*entryno_ptr;
252+ *entryno_ptr = new_default + (old_default & 0xFF);
253+ }
254+ else
255+ {
256+ *entryno_ptr = new_default;
257+ }
258+
259+ if (fseek (fp, SECTOR_SIZE, SEEK_SET) != 0)
260+ {
261+ fclose (fp);
262+ errnum = ERR_BAD_VERSION;
263+ return 1;
264+ }
265+
266+ if (fwrite (buffer, 1, SECTOR_SIZE, fp) != SECTOR_SIZE)
267+ {
268+ fclose (fp);
269+ errnum = ERR_WRITE;
270+ return 1;
271+ }
272+
273+ (void)fflush (fp);
274+ fclose (fp);
275+ return 0;
276+}
277+#endif
278+
279+/* savedefault */
280+static int
281+savedefault_func (char *arg, int flags)
282+{
283+#if !defined(SUPPORT_DISKLESS)
284+#if !defined(GRUB_UTIL)
285+ /* This command is only useful when you boot an entry from the menu
286+ interface. */
287+ if (! (flags & BUILTIN_SCRIPT))
288+ {
289+ errnum = ERR_UNRECOGNIZED;
290+ return 1;
291+ }
292+
293+ return savedefault_helper(current_entryno);
294+#else /* defined(GRUB_UTIL) */
295+ return savedefault_shell(arg, flags);
296+#endif
297 #else /* ! SUPPORT_DISKLESS && ! GRUB_UTIL */
298 errnum = ERR_UNRECOGNIZED;
299 return 1;
300@@ -3368,10 +3397,14 @@
301 "savedefault",
302 savedefault_func,
303 BUILTIN_CMDLINE,
304- "savedefault [NUM | `fallback']",
305- "Save the current entry as the default boot entry if no argument is"
306- " specified. If a number is specified, this number is saved. If"
307- " `fallback' is used, next fallback entry is saved."
308+#ifdef GRUB_UTIL
309+ "savedefault [--stage2=STAGE2_FILE] [--default=DEFAULT] [--once]",
310+ "Save DEFAULT as the default boot entry in STAGE2_FILE. If '--once'"
311+ " is specified, the default is reset after the next reboot."
312+#else
313+ "savedefault",
314+ "Save the current entry as the default boot entry."
315+#endif
316 };
317
318 \f
319@@ -4598,6 +4631,15 @@
320 static int
321 timeout_func (char *arg, int flags)
322 {
323+ /* One-shot default shenanigans -- don't piss around with the menu! */
324+ if (grub_timeout != -1)
325+ return 0;
326+ if ((saved_entryno & STAGE2_ONCEONLY_ENTRY) != 0)
327+ {
328+ grub_timeout = 0;
329+ return 0;
330+ }
331+
332 if (! safe_parse_maxint (&arg, &grub_timeout))
333 return 1;
334
335--- grub-0.97/stage2/shared.h.bootonce 2005-12-12 18:23:13.000000000 -0500
336+++ grub-0.97/stage2/shared.h 2005-12-12 18:23:13.000000000 -0500
337@@ -200,6 +200,8 @@
338 #define STAGE2_FORCE_LBA 0x11
339 #define STAGE2_VER_STR_OFFS 0x12
340
341+#define STAGE2_ONCEONLY_ENTRY 0x10000
342+
343 /* Stage 2 identifiers */
344 #define STAGE2_ID_STAGE2 0
345 #define STAGE2_ID_FFS_STAGE1_5 1
346--- grub-0.97/stage2/builtins.c.bootonce 2006-03-13 16:55:11.000000000 -0500
347+++ grub-0.97/stage2/builtins.c 2006-03-13 16:56:01.000000000 -0500
348@@ -761,11 +761,25 @@
349 };
350
351 \f
352+#if !defined(SUPPORT_DISKLESS) && !defined(GRUB_UTIL)
353+static int savedefault_helper(int);
354+#endif
355 /* default */
356 static int
357 default_func (char *arg, int flags)
358 {
359 #ifndef SUPPORT_DISKLESS
360+#ifndef GRUB_UTIL
361+ /* Has a forced once-only default been specified? */
362+ if ((saved_entryno & STAGE2_ONCEONLY_ENTRY) != 0)
363+ {
364+ int old_defaults=saved_entryno & ~STAGE2_ONCEONLY_ENTRY;
365+ grub_timeout = 0;
366+ default_entry = old_defaults >> 8;
367+ savedefault_helper(old_defaults & 0xff);
368+ return 0;
369+ }
370+#endif
371 if (grub_strcmp (arg, "saved") == 0)
372 {
373 default_entry = saved_entryno;
374--- grub-0.97/stage2/stage2.c.bootonce 2006-03-13 17:27:40.000000000 -0500
375+++ grub-0.97/stage2/stage2.c 2006-03-13 17:29:11.000000000 -0500
376@@ -960,38 +960,8 @@
377 if (use_config_file)
378 #endif /* GRUB_UTIL */
379 {
380- char *default_file = (char *) DEFAULT_FILE_BUF;
381 int i;
382-
383- /* Get a saved default entry if possible. */
384- saved_entryno = 0;
385- *default_file = 0;
386- grub_strncat (default_file, config_file, DEFAULT_FILE_BUFLEN);
387- for (i = grub_strlen(default_file); i >= 0; i--)
388- if (default_file[i] == '/')
389- {
390- i++;
391- break;
392- }
393- default_file[i] = 0;
394- grub_strncat (default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
395- if (grub_open (default_file))
396- {
397- char buf[10]; /* This is good enough. */
398- char *p = buf;
399- int len;
400-
401- len = grub_read (buf, sizeof (buf));
402- if (len > 0)
403- {
404- buf[sizeof (buf) - 1] = 0;
405- safe_parse_maxint (&p, &saved_entryno);
406- }
407
408- grub_close ();
409- }
410- errnum = ERR_NONE;
411-
412 do
413 {
414 /* STATE 0: Before any title command.
415--- grub-0.97/util/grub-install.in.bootonce 2006-03-13 17:39:35.000000000 -0500
416+++ grub-0.97/util/grub-install.in 2006-03-13 17:39:50.000000000 -0500
417@@ -30,7 +30,6 @@
418 pkglibdir=${libdir}/${PACKAGE}/${host_cpu}-${host_vendor}
419
420 grub_shell=${sbindir}/grub
421-grub_set_default=${sbindir}/grub-set-default
422 log_file=/tmp/grub-install.log.$$
423 img_file=/tmp/grub-install.img.$$
424 rootdir=
425@@ -432,9 +431,6 @@
426 exit 1
427 fi
428
429-# Make a default file.
430-${grub_set_default} --root-directory=${rootdir} default
431-
432 # Make sure that GRUB reads the same images as the host OS.
433 test -n "$mkimg" && img_file=`$mkimg`
434 test -n "$mklog" && log_file=`$mklog`
435--- grub-0.97/configure.bootonce 2006-03-13 17:49:05.000000000 -0500
436+++ grub-0.97/configure 2006-03-13 17:49:16.000000000 -0500
437@@ -6135,7 +6135,7 @@
438
439
440
441- ac_config_files="$ac_config_files Makefile stage1/Makefile stage2/Makefile docs/Makefile lib/Makefile util/Makefile grub/Makefile netboot/Makefile util/grub-image util/grub-install util/grub-md5-crypt util/grub-terminfo util/grub-set-default"
442+ ac_config_files="$ac_config_files Makefile stage1/Makefile stage2/Makefile docs/Makefile lib/Makefile util/Makefile grub/Makefile netboot/Makefile util/grub-image util/grub-install util/grub-md5-crypt util/grub-terminfo"
443
444 cat >confcache <<\_ACEOF
445 # This file is a shell script that caches the results of configure
446@@ -6754,7 +6754,6 @@
447 "util/grub-install" ) CONFIG_FILES="$CONFIG_FILES util/grub-install" ;;
448 "util/grub-md5-crypt" ) CONFIG_FILES="$CONFIG_FILES util/grub-md5-crypt" ;;
449 "util/grub-terminfo" ) CONFIG_FILES="$CONFIG_FILES util/grub-terminfo" ;;
450- "util/grub-set-default" ) CONFIG_FILES="$CONFIG_FILES util/grub-set-default" ;;
451 "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
452 "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
453 *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
454--- grub-0.97/configure.ac.bootonce 2006-03-13 17:47:24.000000000 -0500
455+++ grub-0.97/configure.ac 2006-03-13 17:47:37.000000000 -0500
456@@ -666,5 +666,5 @@
457 docs/Makefile lib/Makefile util/Makefile \
458 grub/Makefile netboot/Makefile util/grub-image \
459 util/grub-install util/grub-md5-crypt \
460- util/grub-terminfo util/grub-set-default])
461+ util/grub-terminfo])
462 AC_OUTPUT
463--- grub-0.97/util/Makefile.am.bootonce 2006-03-13 17:48:39.000000000 -0500
464+++ grub-0.97/util/Makefile.am 2006-03-13 17:48:45.000000000 -0500
465@@ -1,6 +1,5 @@
466 bin_PROGRAMS = mbchk
467-sbin_SCRIPTS = grub-install grub-md5-crypt grub-terminfo \
468- grub-set-default
469+sbin_SCRIPTS = grub-install grub-md5-crypt grub-terminfo
470 noinst_SCRIPTS = grub-image mkbimage
471
472 EXTRA_DIST = mkbimage
473--- grub-0.97/util/Makefile.in.bootonce 2006-03-13 17:47:56.000000000 -0500
474+++ grub-0.97/util/Makefile.in 2006-03-13 17:48:34.000000000 -0500
475@@ -43,8 +43,7 @@
476 subdir = util
477 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
478 $(srcdir)/grub-image.in $(srcdir)/grub-install.in \
479- $(srcdir)/grub-md5-crypt.in $(srcdir)/grub-set-default.in \
480- $(srcdir)/grub-terminfo.in
481+ $(srcdir)/grub-md5-crypt.in $(srcdir)/grub-terminfo.in
482 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
483 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
484 $(top_srcdir)/configure.ac
485@@ -52,8 +51,7 @@
486 $(ACLOCAL_M4)
487 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
488 CONFIG_HEADER = $(top_builddir)/config.h
489-CONFIG_CLEAN_FILES = grub-image grub-install grub-md5-crypt \
490- grub-terminfo grub-set-default
491+CONFIG_CLEAN_FILES = grub-image grub-install grub-md5-crypt grub-terminfo
492 am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)"
493 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
494 PROGRAMS = $(bin_PROGRAMS)
495@@ -183,8 +181,7 @@
496 sharedstatedir = @sharedstatedir@
497 sysconfdir = @sysconfdir@
498 target_alias = @target_alias@
499-sbin_SCRIPTS = grub-install grub-md5-crypt grub-terminfo \
500- grub-set-default
501+sbin_SCRIPTS = grub-install grub-md5-crypt grub-terminfo
502
503 noinst_SCRIPTS = grub-image mkbimage
504 EXTRA_DIST = mkbimage
505@@ -234,8 +231,6 @@
506 cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
507 grub-terminfo: $(top_builddir)/config.status $(srcdir)/grub-terminfo.in
508 cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
509-grub-set-default: $(top_builddir)/config.status $(srcdir)/grub-set-default.in
510- cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
511 install-binPROGRAMS: $(bin_PROGRAMS)
512 @$(NORMAL_INSTALL)
513 test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"