View | Details | Raw Unified | Return to bug 14795
Collapse All | Expand All

(-)a/.gear/rules (+2 lines)
Line 0 Link Here
1
tar: @name@-@version@:.
2
diff: @name@-@version@:. .
(-)a/.gear/tags/607d849b5fb32b41822516380089de50078ed12b (+6 lines)
Line 0 Link Here
1
object bc19bc026c057091d3ff25c0312afd200a153ef8
2
type commit
3
tag grub-0.97
4
tagger Alexey I. Froloff <raorn@altlinux.org> 1202825111 +0300
5
6
grub 0.97
(-)a/.gear/tags/list (+1 lines)
Line 0 Link Here
1
607d849b5fb32b41822516380089de50078ed12b grub-0.97
(-)a/Makefile.am (+1 lines)
Lines 2-4 Link Here
2
AUTOMAKE_OPTIONS = 1.7 gnu
2
AUTOMAKE_OPTIONS = 1.7 gnu
3
SUBDIRS = netboot stage2 stage1 lib grub util docs
3
SUBDIRS = netboot stage2 stage1 lib grub util docs
4
EXTRA_DIST = BUGS MAINTENANCE
4
EXTRA_DIST = BUGS MAINTENANCE
5
pkgdatadir=$(datadir)
(-)a/configure.ac (-2 / +1 lines)
Lines 60-67 AC_PROG_CC Link Here
60
_AM_DEPENDENCIES(CC)
60
_AM_DEPENDENCIES(CC)
61
61
62
dnl Because recent automake complains about AS, set it here.
62
dnl Because recent automake complains about AS, set it here.
63
CCAS="$CC"
63
AM_PROG_AS
64
AC_SUBST(CCAS)
65
64
66
AC_ARG_WITH(binutils,
65
AC_ARG_WITH(binutils,
67
  [  --with-binutils=DIR     search the directory DIR to find binutils])
66
  [  --with-binutils=DIR     search the directory DIR to find binutils])
(-)a/docs/grub-install.8 (+2 lines)
Lines 30-35 BIOS Link Here
30
.TP
30
.TP
31
\fB\-\-recheck\fR
31
\fB\-\-recheck\fR
32
probe a device map even if it already exists
32
probe a device map even if it already exists
33
34
This option is unreliable and its use is strongly discouraged.
33
.PP
35
.PP
34
INSTALL_DEVICE can be a GRUB device name or a system device filename.
36
INSTALL_DEVICE can be a GRUB device name or a system device filename.
35
.PP
37
.PP
(-)a/docs/grub.texi (-3 / +58 lines)
Lines 2118-2125 These commands can only be used in the menu: Link Here
2118
* default::                     Set the default entry
2118
* default::                     Set the default entry
2119
* fallback::                    Set the fallback entry
2119
* fallback::                    Set the fallback entry
2120
* hiddenmenu::                  Hide the menu interface
2120
* hiddenmenu::                  Hide the menu interface
2121
* gfxmenu::                     Use graphical menu interface
2121
* timeout::                     Set the timeout
2122
* timeout::                     Set the timeout
2122
* title::                       Start a menu entry
2123
* title::                       Start a menu entry
2124
* wildcard::                    Define a wildcard boot entry
2123
@end menu
2125
@end menu
2124
2126
2125
2127
Lines 2150-2155 fallback entry numbers. Link Here
2150
@end deffn
2152
@end deffn
2151
2153
2152
2154
2155
@node gfxmenu
2156
@subsection gfxmenu
2157
2158
@deffn Command gfxmenu file
2159
Use the graphical menu interface. The graphics data are taken from
2160
@var{file} and must be created using 'mkbootmsg' from the gfxboot package.
2161
@end deffn
2162
2163
2153
@node hiddenmenu
2164
@node hiddenmenu
2154
@subsection hiddenmenu
2165
@subsection hiddenmenu
2155
2166
Lines 2180-2185 the line, starting with the first non-space character. Link Here
2180
@end deffn
2191
@end deffn
2181
2192
2182
2193
2194
@node wildcard
2195
@subsection wildcard
2196
2197
@deffn Command wildcard pathname
2198
Treat this boot entry as a wildcard entry: The
2199
wildcard, title, kernel, and initrd commands (see @ref{Menu-specific
2200
commands} and @ref{Command-line and menu entry commands}) each have an
2201
asterisk (*) in their value. A filename match is performed on the
2202
@var{pathname} of the wildcard command. For each match, the entire boot
2203
entry is duplicated. The part of the filename whcih matches the asterisk
2204
in the wildcard command replaces the asterisks in the title, kernel, and
2205
initrd commands. For example, with the files vmlinuz-2.6.5-1 and
2206
vmlinuz-2.6.8-8 below (hd0,7)/boot, the following entry in the stage 2
2207
configuration file:
2208
2209
@example
2210
title Linux-*
2211
    wildcard (hd0,7)/boot/vmlinuz-*
2212
    kernel (hd0,7)/boot/vmlinuz-* root=/dev/hda8
2213
    initrd (hd0,7)/boot/initrd-*
2214
@end example
2215
2216
would expand as follows:
2217
2218
@example
2219
title Linux-2.6.5-1
2220
    wildcard (hd0,7)/boot/vmlinuz-2.6.5-1
2221
    kernel (hd0,7)/boot/vmlinuz-2.6.5-1 root=/dev/hda8
2222
    initrd (hd0,7)/boot/initrd-2.6.5-1
2223
title Linux-2.6.8-8
2224
    wildcard (hd0,7)/boot/vmlinuz-2.6.8-8
2225
    kernel (hd0,7)/boot/vmlinuz-2.6.8-8 root=/dev/hda8
2226
    initrd (hd0,7)/boot/initrd-2.6.8-8
2227
@end example
2228
@end deffn
2229
2183
@node General commands
2230
@node General commands
2184
@section The list of general commands
2231
@section The list of general commands
2185
2232
Lines 2909-2915 appropriate parameters in the Linux setup area in memory. See also Link Here
2909
@node install
2956
@node install
2910
@subsection install
2957
@subsection install
2911
2958
2912
@deffn Command install [@option{--force-lba}] [@option{--stage2=os_stage2_file}] stage1_file [@option{d}] dest_dev stage2_file [addr] [@option{p}] [config_file] [real_config_file]
2959
@deffn Command install [@option{--force-lba[=off]}] [@option{--stage2=os_stage2_file}] stage1_file [@option{d}] dest_dev stage2_file [addr] [@option{p}] [config_file] [real_config_file]
2913
This command is fairly complex, and you should not use this command
2960
This command is fairly complex, and you should not use this command
2914
unless you are familiar with GRUB. Use @command{setup} (@pxref{setup})
2961
unless you are familiar with GRUB. Use @command{setup} (@pxref{setup})
2915
instead.
2962
instead.
Lines 2956-2961 HP Vectra XU 6/200 BIOS version GG.06.11 Link Here
2956
bitmap even if they do have the support. So GRUB provides a solution to
3003
bitmap even if they do have the support. So GRUB provides a solution to
2957
ignore the wrong bitmap, that is, the option @option{--force-lba}. Don't
3004
ignore the wrong bitmap, that is, the option @option{--force-lba}. Don't
2958
use this option if you know that your BIOS doesn't have LBA support.
3005
use this option if you know that your BIOS doesn't have LBA support.
3006
On the other hand there is at least one known BIOS that does the opposite,
3007
it claims to support LBA and then fails to provide it. Iff you have an
3008
Adaptec 2940 with BIOS revision 1.21 ( newer ones just work and older ones
3009
don't make the false claim ), or otherwise experience grub hanging
3010
after stage1, you can try to use the option @option{--force-lba=off},
3011
as long as all disk blocks involved in booting reside
3012
within the first 1024 cylinders.
2959
3013
2960
@strong{Caution3:} You must specify the option @option{--stage2} in the
3014
@strong{Caution3:} You must specify the option @option{--stage2} in the
2961
grub shell, if you cannot unmount the filesystem where your stage2 file
3015
grub shell, if you cannot unmount the filesystem where your stage2 file
Lines 3702-3709 Use @var{file} as the grub shell. You can append arbitrary options to Link Here
3702
3756
3703
@item --recheck
3757
@item --recheck
3704
Recheck the device map, even if @file{/boot/grub/device.map} already
3758
Recheck the device map, even if @file{/boot/grub/device.map} already
3705
exists. You should use this option whenever you add/remove a disk
3759
exists.
3706
into/from your computer.
3760
3761
This option is unreliable and its use is strongly discouraged.
3707
@end table
3762
@end table
3708
3763
3709
3764
(-)a/grub.spec (+323 lines)
Line 0 Link Here
1
Name: grub
2
Version: 0.97
3
Release: alt3
4
5
Summary: GRand Unified Bootloader
6
Group: System/Kernel and hardware
7
License: GPL
8
URL: http://www.gnu.org/software/grub/grub.en.html
9
10
ExclusiveArch: %ix86
11
12
Packager: Sir Raorn <raorn@altlinux.ru>
13
14
Source: ftp://alpha.gnu.org/gnu/grub/%name-%version.tar
15
Patch: %name-%version-%release.patch
16
17
Provides: %name-doc = %version, %name-graph = %version
18
Obsoletes: %name-doc, %name-graph
19
20
# Automatically added by buildreq on Mon Feb 25 2008
21
BuildRequires: libncurses-devel tetex-latex
22
23
##BuildRequires: libncurses-devel reiser4progs-minimal-devel tetex-latex
24
25
%package utils
26
Group: System/Kernel and hardware
27
Summary: Additional utilites for %name
28
29
%description
30
GNU GRUB is a multiboot boot loader. It was derived from GRUB. It is an
31
attempt to produce a boot loader for IBM PC-compatible machines that
32
has both the ability to be friendly to beginning or otherwise
33
nontechnically interested users and the flexibility to help experts in
34
diverse environments. It is compatible with Free/Net/OpenBSD and Linux.
35
It supports Win 9x/NT and OS/2 via chainloaders. It has a menu
36
interface and a command line interface.
37
It implements the Multiboot standard, which allows for flexible loading
38
of multiple boot images (needed for modular kernels such as the GNU
39
Hurd).
40
41
%description utils
42
Additional utilites for %name
43
44
%prep
45
%setup
46
%patch -p1
47
48
%build
49
%autoreconf
50
51
%define _optlevel s
52
%add_optflags -DNDEBUG -W -Wall -Wpointer-arith
53
%add_optflags -fno-stack-protector -fno-strict-aliasing -minline-all-stringops
54
%ifarch x86_64
55
 %add_optflags -m32 -fno-asynchronous-unwind-tables
56
%endif  
57
%configure \
58
  --bindir=/bin --sbindir=/sbin \
59
  --disable-auto-linux-mem-opt --enable-diskless \
60
  --enable-{3c50{3,7},3c5{0,2}9,3c595,3c90x,cs89x0,davicom,depca,eepro{,100},epic100} \
61
  --enable-{exos205,lance,ne,ne2100,ni{50,52,65}00,ns8390} \
62
  --enable-{rtl8139,sk-g16,smc9000,tiara,tulip,via-rhine,w89c840,wd} 
63
%make_build
64
(cd stage2; mv nbgrub pxegrub ..)
65
mv stage2/stage2{,.netboot}
66
%make_build clean
67
%configure \
68
  --bindir=/bin --sbindir=/sbin \
69
  --prefix=/usr --infodir=%{_infodir} --mandir=%{_mandir} --datadir=%{_datadir} \
70
  --libexecdir=%{_libexecdir} \
71
  --disable-auto-linux-mem-opt 
72
%make_build
73
%make_build -C docs dvi
74
75
%install
76
%make_install DESTDIR=%buildroot install
77
mkdir -p %buildroot/boot/grub/pictures
78
ln -sfn . %buildroot/boot/boot
79
install -p {nb,pxe}grub stage2/stage2{,.netboot} %buildroot/boot/grub
80
install -m755 -p grubonce %buildroot/sbin
81
mv %buildroot%_libexecdir/grub/* %buildroot/boot/grub
82
rm -rf %buildroot%_libexecdir/grub
83
ln -sfn ../../boot/grub %buildroot%_libexecdir 
84
85
%post
86
if [ -x /usr/sbin/detectloader -a -f /proc/partitions ]; then
87
  LOADER=$(/usr/sbin/detectloader)
88
  if [ "$LOADER" = "GRUB" ]; then
89
    if [ -f /boot/grub/install.sh ]; then
90
      # Old grub installation
91
      sh /boot/grub/install.sh > /dev/null
92
    elif [ -s /etc/sysconfig/grub -a grep -q quit /etc/sysconfig/grub 1>/dev/null 2>/dev/null ]; then
93
      # This file should be created by (future) alterator-grub
94
      /sbin/grub --batch < /etc/sysconfig/grub > /dev/null
95
    else
96
      cat <<EOF >&2
97
Please install GRUB manually.
98
EOF
99
    fi
100
  fi
101
fi
102
103
%install_info %name.info
104
%install_info multiboot.info
105
106
%preun
107
%uninstall_info %name.info
108
%uninstall_info multiboot.info
109
110
111
%files
112
%doc BUGS NEWS TODO README THANKS AUTHORS INSTALL ChangeLog COPYING docs/menu.lst
113
%dir /boot/grub
114
%dir /boot/boot
115
/boot/grub/*stage*
116
/boot/grub/nbgrub
117
/boot/grub/pxegrub
118
%_infodir/*
119
%_mandir/*/*
120
/sbin/*
121
/bin/*
122
%exclude /sbin/grub-terminfo
123
%dir %_libexecdir/grub
124
125
%files utils
126
/sbin/grub-terminfo
127
128
%changelog
129
* Thu Feb 28 2008 Sir Raorn <raorn@altlinux.ru> 0.97-alt3
130
- Resurrected from orphaned
131
- Removed ReiserFS4 support
132
- Updated gfxboot support from SuSE
133
- mdraid/dmraid support in grub-install(8) from Fedora
134
- All binaries moved to /bin and /sbin
135
- Wildcard menu.lst entries support from SuSE
136
137
* Tue May 30 2006 Andriy Stepanov <stanv@altlinux.ru> 0.97-alt2
138
- Add support for reiser4 FS
139
140
* Wed May 24 2006 Andriy Stepanov <stanv@altlinux.ru> 0.97-alt1
141
- Switch to new version. Dual plain grub and with PXE support.
142
143
* Wed Oct 20 2004 Stanislav Ievlev <inger@altlinux.org> 0.95-alt1
144
- 0.95
145
146
* Tue Mar 09 2004 Stanislav Ievlev <inger@altlinux.org> 0.94-alt1
147
- 0.94
148
149
* Wed Jan 14 2004 Stanislav Ievlev <inger@altlinux.org> 0.93-alt2
150
- fix building with gcc3.3
151
152
* Tue Apr 08 2003 Stanislav Ievlev <inger@altlinux.ru> 0.93-alt1
153
- removed patches for old graphics support
154
- removed grub-splashes too
155
- patch (nodeprecatedflags) removed
156
- dump patch turned off
157
- new grub-terminfo utility placed into grub-utils subpackage (to avoid deps on termutils-devel)
158
159
* Fri Feb 07 2003 Stanislav Ievlev <inger@altlinux.ru> 0.92-alt3.1
160
- removed old graphics support
161
- removed grub-graph package (now obsolete)
162
163
* Mon Feb 03 2003 Rider <rider@altlinux.ru> 0.92-alt3
164
- GFX menu support from SuSE
165
166
* Sun Oct  6 2002 Ivan Zakharyaschev <imz@altlinux.ru> 0.92-alt2
167
- try to fix graph menu cursor clearing passed items: keypressclear patch 
168
  modified -- now it refreshes the screen multiple times 
169
  (not only the first time)
170
171
* Mon Apr 01 2002 Stanislav Ievlev <inger@altlinux.ru> 0.91-alt5
172
- Added patch to fix meminfo displaying
173
174
* Fri Feb 15 2002 Stanislav Ievlev <inger@altlinux.ru> 0.91-alt4
175
- fixed grub-install
176
177
* Mon Feb 04 2002 Stanislav Ievlev <inger@altlinux.ru> 0.91-alt3
178
- real dump terminal fix and some other patches from grub-bug mailing list
179
 
180
181
* Wed Jan 30 2002 Stanislav Ievlev <inger@altlinux.ru> 0.91-alt2
182
- added temporary hack for the DUMB_TERMINAL mode
183
184
* Tue Jan 29 2002 Stanislav Ievlev <inger@altlinux.ru> 0.91-alt1
185
- 0.91
186
- all mandrake patches removed
187
188
* Fri Nov 16 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt8
189
- Added latest XFS+JFS patches 
190
- Added some RH patches
191
192
* Wed Nov 14 2001 Dmitry V. Levin <ldv@alt-linux.org> 0.90-alt7
193
- Moved rebootin utility to bootloader-utils package.
194
195
* Wed Aug 22 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt6
196
- New image and new package (graph).
197
198
* Wed Aug 15 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt5
199
- Added first picture ( Junior ;) ).
200
201
* Mon Aug 13 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt4
202
- Added patch for JFS support
203
204
* Wed Aug 08 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt3
205
- Removed Mandrake's builtins. We don't need it
206
- Added vga16 support.
207
- We don't  need previous hack now. All works.
208
  Problem was: some bad function set errnum nonzero.
209
210
* Thu Aug 02 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt2
211
- Temporary hack: memcheck() function doesn't work.
212
213
* Thu Jul 26 2001 Stanislav Ievlev <inger@altlinux.ru> 0.90-alt1
214
- 0.90. Little changes from previous snapshot
215
216
* Thu Jun 28 2001 Stanislav Ievlev <inger@altlinux.ru> 0.5.96.1-ipl5mdk
217
- Update to CVS at 20010530
218
219
* Mon May 28 2001 Stanislav Ievlev <inger@altlinux.ru> 0.5.96.1-ipl4mdk
220
- New patches from Mandrake
221
222
* Mon Dec 18 2000 AEN <aen@logic.ru>
223
- adopted for RE
224
225
* Mon Dec 11 2000 Pixel <pixel@mandrakesoft.com> 0.5.96.1-2mdk
226
- add a call to /boot/grub/install.sh if needed
227
228
* Sat Dec  9 2000 Pixel <pixel@mandrakesoft.com> 0.5.96.1-1mdk
229
- new version
230
  * patch fixbiosbug-nbsectors no more needed (unless you define NO_BUGGY_BIOS_IN_THE_WORLD)
231
232
* Thu Aug 24 2000 Pixel <pixel@mandrakesoft.com> 0.5.95-7mdk
233
- %%uninstall_info is fixed, yeepee :)
234
235
* Tue Aug 22 2000 Pixel <pixel@mandrakesoft.com> 0.5.95-6mdk
236
- fixbiosbug-nbsectors for some Geom Errors (warly's case)
237
238
* Wed Aug 16 2000 Pixel <pixel@mandrakesoft.com> 0.5.95-5mdk
239
- fix erroneous remove_info macro (sillyme)
240
241
* Mon Aug 07 2000 Frederic Lepied <flepied@mandrakesoft.com> 0.5.95-4mdk
242
- automatically added BuildRequires
243
244
* Fri Jul 21 2000 Pixel <pixel@mandrakesoft.com> 0.5.95-3mdk
245
- macroization, BM
246
247
* Wed Jul 12 2000 Pixel <pixel@mandrakesoft.com> 0.5.95-2mdk
248
- add a patch for ezbios nonsense
249
250
* Mon Jul  3 2000 Pixel <pixel@mandrakesoft.com> 0.5.95-1mdk
251
- new version
252
253
* Sat May 20 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-14mdk
254
- add rebootin command (use altconfigfile cmd in menu.lst)
255
- add altconfigfile (read once)
256
257
* Mon May  8 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-12mdk
258
- add reiserfs handling (missing symlink handling though)
259
260
* Wed May  3 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-11mdk
261
- fix for linux-extended extended partition
262
263
* Tue May  2 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-10mdk
264
- fix case of not found keytable
265
266
* Tue Apr 18 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-9mdk
267
- remove a patch from caldera
268
269
* Sun Apr 16 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-8mdk
270
- nicer menu
271
- don't add automatic mem= if one is given
272
273
* Tue Apr  4 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-7mdk
274
- fix install path
275
276
* Mon Apr  3 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-6mdk
277
- integrate patches from caldera
278
279
* Fri Mar 31 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-5mdk
280
- re-rebuild
281
282
* Wed Mar 29 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-4mdk
283
- big patch (i18n & look)
284
285
* Sat Mar 25 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-3mdk
286
- split printable doc and some more to have smaller package (keep mainly info in
287
main package, very good one)
288
- cleanup install-info in %% post scripts
289
290
* Fri Mar 24 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-2mdk
291
- remove unneeded patch
292
- use of %% { ix86 }
293
294
* Wed Mar 22 2000 Pixel <pixel@mandrakesoft.com> 0.5.94-1mdk
295
- remove now unneeded --disable-gunzip
296
- added option --disable-lba-support-bitmap-check
297
- patch for *very* buggy bioses (tells grub every hd is gigantic)
298
- new version
299
300
* Mon Mar 13 2000 Pixel <pixel@mandrakesoft.com> 0.5.93.1-7mdk
301
- configure with --disable-gunzip
302
(so that initrd is not gunzip'ed and fits in memory, that's the kernel's job anyway)
303
304
* Wed Mar  1 2000 Pixel <pixel@mandrakesoft.com> 0.5.93.1-6mdk
305
- remove no-device-check (was stupid)
306
- replace by something better (option --devices)
307
308
* Tue Feb 29 2000 Pixel <pixel@mandrakesoft.com> 0.5.93.1-5mdk
309
- add option no-device-check for grub binary (mainly for non-interactive use)
310
311
* Sun Jan 16 2000 Chmouel Boudjnah <chmouel@mandrakesoft.com> 0.5.93.1-4mdk
312
- Add Exclusivearch.
313
314
* Tue Jan 4 2000 Chmouel Boudjnah <chmouel@mandrakesoft.com> 0.5.93.1-3mdk
315
- Add install_grub_on_floppy script (thnks b.bodin).
316
- Add dvi docs (tknks b.bodin).
317
318
* Mon Jan  3 2000 Chmouel Boudjnah <chmouel@mandrakesoft.com> 0.5.93.1-2mdk
319
- Add %%packager (thnks rpmlint).
320
- Remove CFLAGS.
321
322
* Mon Jan  3 2000 Chmouel Boudjnah <chmouel@mandrakesoft.com>
323
- First spec file for Mandrake distribution based on debian version.
(-)a/grub/asmstub.c (-4 / +48 lines)
Lines 43-48 int grub_stage2 (void); Link Here
43
#include <termios.h>
43
#include <termios.h>
44
#include <signal.h>
44
#include <signal.h>
45
45
46
#include <sys/mman.h>
47
46
#ifdef __linux__
48
#ifdef __linux__
47
# include <sys/ioctl.h>		/* ioctl */
49
# include <sys/ioctl.h>		/* ioctl */
48
# if !defined(__GLIBC__) || \
50
# if !defined(__GLIBC__) || \
Lines 142-155 grub_stage2 (void) Link Here
142
    }
144
    }
143
145
144
  assert (grub_scratch_mem == 0);
146
  assert (grub_scratch_mem == 0);
145
  scratch = malloc (0x100000 + EXTENDED_MEMSIZE + 15);
147
#ifdef MAP_32BIT
148
#define MY_MAP_SET MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_32BIT
149
#else
150
#define MY_MAP_SET MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS
151
#endif
152
  scratch = mmap(NULL,
153
                 0x100000 + EXTENDED_MEMSIZE + 15,
154
                 PROT_EXEC | PROT_READ | PROT_WRITE,
155
                 MY_MAP_SET,
156
                 -1,
157
                 0);
158
146
  assert (scratch);
159
  assert (scratch);
147
  grub_scratch_mem = (char *) ((((int) scratch) >> 4) << 4);
160
  grub_scratch_mem = (char *) ((((int) scratch) >> 4) << 4);
148
161
149
  /* FIXME: simulate the memory holes using mprot, if available. */
162
  /* FIXME: simulate the memory holes using mprot, if available. */
150
163
151
  assert (disks == 0);
164
  assert (disks == 0);
152
  disks = malloc (NUM_DISKS * sizeof (*disks));
165
  disks = mmap(NULL,
166
               NUM_DISKS * sizeof (*disks),
167
               PROT_EXEC | PROT_READ | PROT_WRITE,
168
               MY_MAP_SET,
169
               -1,
170
               0);
153
  assert (disks);
171
  assert (disks);
154
  /* Initialize DISKS.  */
172
  /* Initialize DISKS.  */
155
  for (i = 0; i < NUM_DISKS; i++)
173
  for (i = 0; i < NUM_DISKS; i++)
Lines 215-223 grub_stage2 (void) Link Here
215
  /* Release memory. */
233
  /* Release memory. */
216
  restore_device_map (device_map);
234
  restore_device_map (device_map);
217
  device_map = 0;
235
  device_map = 0;
218
  free (disks);
236
  munmap(disks, NUM_DISKS * sizeof (*disks));
219
  disks = 0;
237
  disks = 0;
220
  free (scratch);
238
  munmap(scratch, 0x100000 + EXTENDED_MEMSIZE + 15);
221
  grub_scratch_mem = 0;
239
  grub_scratch_mem = 0;
222
240
223
  if (serial_device)
241
  if (serial_device)
Lines 480-485 set_vbe_mode (int mode_number) Link Here
480
  return 0;
498
  return 0;
481
}
499
}
482
500
501
/* graphical menu functions .  */
502
int
503
gfx_init (gfx_data_t *gfx_data)
504
{
505
  return 0;
506
}
507
508
int
509
gfx_done (gfx_data_t *gfx_data)
510
{
511
  return 0;
512
}
513
514
int
515
gfx_input (gfx_data_t *gfx_data, int *menu_entry)
516
{
517
  return 0;
518
}
519
520
int
521
gfx_setup_menu (gfx_data_t *gfx_data)
522
{
523
  return 0;
524
}
525
526
483
/* low-level timing info */
527
/* low-level timing info */
484
int
528
int
485
getrtsecs (void)
529
getrtsecs (void)
(-)a/grub/main.c (-1 / +1 lines)
Lines 44-50 int use_curses = 0; Link Here
44
int verbose = 0;
44
int verbose = 0;
45
int read_only = 0;
45
int read_only = 0;
46
int floppy_disks = 1;
46
int floppy_disks = 1;
47
char *device_map_file = 0;
47
char *device_map_file = "/boot/grub/device.map";
48
static int default_boot_drive;
48
static int default_boot_drive;
49
static int default_install_partition;
49
static int default_install_partition;
50
static char *default_config_file;
50
static char *default_config_file;
(-)a/grubonce (+57 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Keep this sort of configurable for the future.
4
$GRUBDIR="/boot/grub";
5
6
# Parse the menu file, and see if we can get a match for a maybe given arg.
7
open(MENU, "<$GRUBDIR/menu.lst") || die "no menu.lst in $GRUBDIR";
8
$gotit = 0;
9
$titleno = -1;
10
$global_default = undef;
11
while(<MENU>) {
12
  m,\s*default\s+(.+), && $titleno == -1 && ($global_default = $1);
13
  next unless m,\s*title\s+(.*),i;
14
  $title_name = $1;
15
  $titleno++;
16
17
  if (@ARGV > 0) {
18
    # Argument may be entirely numerical, in which case it is an index,
19
    # or a perl RE that leads to the first title matching.
20
    if (( $ARGV[0] =~ m,^[0-9]+$, && $titleno    eq   $ARGV[0] ) ||
21
	( $ARGV[0] !~ m,^[0-9]+$, && $title_name =~ m,$ARGV[0],i) ) {
22
      $gotit = 1;
23
      last;
24
    }
25
  } else {
26
    print "$titleno: $title_name\n";
27
  }
28
}
29
close(MENU);
30
31
print "Warning: you haven't set a global default!\n" if !defined($global_default);
32
33
# Without a command line argument, we have now listet the titles and are done.
34
exit 0 if @ARGV < 1;
35
36
# Else the user wants to write the default file. We have better found a match!
37
if ($gotit > 0) {
38
  print "Warning: your global default is 'saved'; changing default permanently!"
39
    if $global_default eq "saved";
40
41
  print "Using entry #$titleno: $title_name\n";
42
43
  # set the magic one-time flag
44
  $titleno |= 0x4000;
45
46
  open(DEFFILE, ">$GRUBDIR/default") ||
47
    die "Cannot open default file for writing";
48
  $buf = $titleno . "\0" .  "\n" x 9;
49
  syswrite(DEFFILE, $buf, 10);
50
  close(DEFFILE);
51
52
  exit 0;
53
} else {
54
  print $ARGV[0] . " not found in $GRUBDIR/menu.lst\n";
55
  exit 1;
56
}
57
(-)a/lib/device.c (-19 / +250 lines)
Lines 131-136 get_kfreebsd_version () Link Here
131
#include <shared.h>
131
#include <shared.h>
132
#include <device.h>
132
#include <device.h>
133
133
134
#if defined(__linux__)
135
/* The 2.6 kernel has removed all of the geometry handling for IDE drives
136
 * that did fixups for LBA, etc.  This means that the geometry we get
137
 * with the ioctl has a good chance of being wrong.  So, we get to 
138
 * also know about partition tables and try to read what the geometry
139
 * is there. *grumble*   Very closely based on code from cfdisk
140
 */
141
static void get_kernel_geometry(int fd, int *cyl, int *heads, int *sectors) {
142
    struct hd_geometry hdg;
143
    
144
    if (ioctl (fd, HDIO_GETGEO, &hdg))
145
        return;
146
147
    *cyl = hdg.cylinders;
148
    *heads = hdg.heads;
149
    *sectors = hdg.sectors;
150
}
151
152
struct partition {
153
        unsigned char boot_ind;         /* 0x80 - active */
154
        unsigned char head;             /* starting head */
155
        unsigned char sector;           /* starting sector */
156
        unsigned char cyl;              /* starting cylinder */
157
        unsigned char sys_ind;          /* What partition type */
158
        unsigned char end_head;         /* end head */
159
        unsigned char end_sector;       /* end sector */
160
        unsigned char end_cyl;          /* end cylinder */
161
        unsigned char start4[4];        /* starting sector counting from 0 */
162
        unsigned char size4[4];         /* nr of sectors in partition */
163
};
164
165
#define ALIGNMENT 2
166
typedef union {
167
    struct {
168
	unsigned char align[ALIGNMENT];
169
	unsigned char b[SECTOR_SIZE];
170
    } c;
171
    struct {
172
	unsigned char align[ALIGNMENT];
173
	unsigned char buffer[0x1BE];
174
	struct partition part[4];
175
	unsigned char magicflag[2];
176
    } p;
177
} partition_table;
178
179
#define PART_TABLE_FLAG0 0x55
180
#define PART_TABLE_FLAG1 0xAA
181
182
static void
183
get_partition_table_geometry(partition_table *bufp, int *cyl, int *heads, 
184
                             int *sectors) {
185
    struct partition *p;
186
    int i,h,s,hh,ss;
187
    int first = 1;
188
    int bad = 0;
189
190
    if (bufp->p.magicflag[0] != PART_TABLE_FLAG0 ||
191
	bufp->p.magicflag[1] != PART_TABLE_FLAG1) {
192
	    /* Matthew Wilcox: slightly friendlier version of
193
	       fatal(_("Bad signature on partition table"), 3);
194
	    */
195
            fprintf(stderr, "Unknown partition table signature\n");
196
	    return;
197
    }
198
199
    hh = ss = 0;
200
    for (i=0; i<4; i++) {
201
	p = &(bufp->p.part[i]);
202
	if (p->sys_ind != 0) {
203
	    h = p->end_head + 1;
204
	    s = (p->end_sector & 077);
205
	    if (first) {
206
		hh = h;
207
		ss = s;
208
		first = 0;
209
	    } else if (hh != h || ss != s)
210
		bad = 1;
211
	}
212
    }
213
214
    if (!first && !bad) {
215
	*heads = hh;
216
	*sectors = ss;
217
    }
218
}
219
220
static void get_linux_geometry (int fd, struct geometry *geom) {
221
    int kern_cyl = 0, kern_head = 0, kern_sectors = 0;
222
    int pt_cyl = 0, pt_head = 0, pt_sectors = 0;
223
    partition_table bufp;
224
225
    get_kernel_geometry(fd, &kern_cyl, &kern_head, &kern_sectors);
226
227
    if (read(fd, bufp.c.b, SECTOR_SIZE) == SECTOR_SIZE) {
228
        get_partition_table_geometry(&bufp, &pt_cyl, &pt_head, &pt_sectors);
229
    } else {
230
        fprintf(stderr, "Unable to read partition table: %s\n", strerror(errno));
231
    }
232
233
    if (pt_head && pt_sectors) {
234
        int cyl_size;
235
236
        geom->heads = pt_head;
237
        geom->sectors = pt_sectors;
238
        cyl_size = pt_head * pt_sectors;
239
        geom->cylinders = geom->total_sectors/cyl_size;
240
    } else {
241
        geom->heads = kern_head;
242
        geom->sectors = kern_sectors;
243
        geom->cylinders = kern_cyl;
244
    }
245
246
    return;
247
}
248
#endif
249
134
/* Get the geometry of a drive DRIVE.  */
250
/* Get the geometry of a drive DRIVE.  */
135
void
251
void
136
get_drive_geometry (struct geometry *geom, char **map, int drive)
252
get_drive_geometry (struct geometry *geom, char **map, int drive)
Lines 151-170 get_drive_geometry (struct geometry *geom, char **map, int drive) Link Here
151
#if defined(__linux__)
267
#if defined(__linux__)
152
  /* Linux */
268
  /* Linux */
153
  {
269
  {
154
    struct hd_geometry hdg;
155
    unsigned long nr;
270
    unsigned long nr;
156
    
271
    
157
    if (ioctl (fd, HDIO_GETGEO, &hdg))
158
      goto fail;
159
160
    if (ioctl (fd, BLKGETSIZE, &nr))
272
    if (ioctl (fd, BLKGETSIZE, &nr))
161
      goto fail;
273
      goto fail;
162
    
274
163
    /* Got the geometry, so save it. */
164
    geom->cylinders = hdg.cylinders;
165
    geom->heads = hdg.heads;
166
    geom->sectors = hdg.sectors;
167
    geom->total_sectors = nr;
275
    geom->total_sectors = nr;
276
    get_linux_geometry(fd, geom);
277
278
    if (!geom->heads && !geom->cylinders && !geom->sectors)
279
        goto fail;
168
    
280
    
169
    goto success;
281
    goto success;
170
  }
282
  }
Lines 403-412 get_dac960_disk_name (char *name, int controller, int drive) Link Here
403
}
515
}
404
516
405
static void
517
static void
518
get_cciss_disk_name (char * name, int controller, int drive)
519
{
520
  sprintf (name, "/dev/cciss/c%dd%d", controller, drive);
521
}
522
523
static void
524
get_cpqarray_disk_name (char * name, int controller, int drive)
525
{
526
  sprintf (name, "/dev/ida/c%dd%d", controller, drive);
527
}
528
static void
406
get_ataraid_disk_name (char *name, int unit)
529
get_ataraid_disk_name (char *name, int unit)
407
{
530
{
408
  sprintf (name, "/dev/ataraid/d%c", unit + '0');
531
  sprintf (name, "/dev/ataraid/d%c", unit + '0');
409
}
532
}
533
534
static void
535
get_i2o_disk_name (char *name, int unit)
536
{
537
  sprintf (name, "/dev/i2o/hd%c", unit + 'a');
538
}
410
#endif
539
#endif
411
540
412
/* Check if DEVICE can be read. If an error occurs, return zero,
541
/* Check if DEVICE can be read. If an error occurs, return zero,
Lines 515-520 read_device_map (FILE *fp, char **map, const char *map_file) Link Here
515
     probing devices.  */
644
     probing devices.  */
516
  char buf[1024];		/* XXX */
645
  char buf[1024];		/* XXX */
517
  int line_number = 0;
646
  int line_number = 0;
647
  int retval = 0;		/* default to failure */
518
  
648
  
519
  while (fgets (buf, sizeof (buf), fp))
649
  while (fgets (buf, sizeof (buf), fp))
520
    {
650
    {
Lines 541-554 read_device_map (FILE *fp, char **map, const char *map_file) Link Here
541
      if (*ptr != '(')
671
      if (*ptr != '(')
542
	{
672
	{
543
	  show_error (line_number, "No open parenthesis found");
673
	  show_error (line_number, "No open parenthesis found");
544
	  return 0;
674
	  continue;
545
	}
675
	}
546
      
676
      
547
      ptr++;
677
      ptr++;
548
      if ((*ptr != 'f' && *ptr != 'h') || *(ptr + 1) != 'd')
678
      if ((*ptr != 'f' && *ptr != 'h') || *(ptr + 1) != 'd')
549
	{
679
	{
550
	  show_error (line_number, "Bad drive name");
680
	  show_error (line_number, "Bad drive name");
551
	  return 0;
681
	  continue;
552
	}
682
	}
553
      
683
      
554
      if (*ptr == 'f')
684
      if (*ptr == 'f')
Lines 559-565 read_device_map (FILE *fp, char **map, const char *map_file) Link Here
559
      if (drive < 0)
689
      if (drive < 0)
560
	{
690
	{
561
	  show_error (line_number, "Bad device number");
691
	  show_error (line_number, "Bad device number");
562
	  return 0;
692
	  continue;
563
	}
693
	}
564
      else if (drive > 127)
694
      else if (drive > 127)
565
	{
695
	{
Lines 575-581 read_device_map (FILE *fp, char **map, const char *map_file) Link Here
575
      if (*ptr != ')')
705
      if (*ptr != ')')
576
	{
706
	{
577
	  show_error (line_number, "No close parenthesis found");
707
	  show_error (line_number, "No close parenthesis found");
578
	  return 0;
708
	  continue;
579
	}
709
	}
580
      
710
      
581
      ptr++;
711
      ptr++;
Lines 586-592 read_device_map (FILE *fp, char **map, const char *map_file) Link Here
586
      if (! *ptr)
716
      if (! *ptr)
587
	{
717
	{
588
	  show_error (line_number, "No filename found");
718
	  show_error (line_number, "No filename found");
589
	  return 0;
719
	  continue;
590
	}
720
	}
591
      
721
      
592
      /* Terminate the filename.  */
722
      /* Terminate the filename.  */
Lines 604-612 read_device_map (FILE *fp, char **map, const char *map_file) Link Here
604
      
734
      
605
      map[drive] = strdup (ptr);
735
      map[drive] = strdup (ptr);
606
      assert (map[drive]);
736
      assert (map[drive]);
737
738
      retval = 1;	/* at least 1 drive configured successfully */
607
    }
739
    }
608
  
740
  
609
  return 1;
741
  return retval;
610
}
742
}
611
743
612
/* Initialize the device map MAP. *MAP will be allocated from the heap
744
/* Initialize the device map MAP. *MAP will be allocated from the heap
Lines 782-788 init_device_map (char ***map, const char *map_file, int floppy_disks) Link Here
782
    
914
    
783
    for (controller = 0; controller < 8; controller++)
915
    for (controller = 0; controller < 8; controller++)
784
      {
916
      {
785
	for (drive = 0; drive < 15; drive++)
917
	for (drive = 0; drive < 32; drive++)
786
	  {
918
	  {
787
	    char name[24];
919
	    char name[24];
788
	    
920
	    
Lines 801-806 init_device_map (char ***map, const char *map_file, int floppy_disks) Link Here
801
	  }
933
	  }
802
      }
934
      }
803
  }
935
  }
936
937
  /* I2O disks.  */
938
  for (i = 0; i < 8; i++)
939
    {
940
      char name[16];
941
      
942
      get_i2o_disk_name (name, i);
943
      if (check_device (name))
944
	{
945
	  (*map)[num_hd + 0x80] = strdup (name);
946
	  assert ((*map)[num_hd + 0x80]);
947
	  
948
	  /* If the device map file is opened, write the map.  */
949
	  if (fp)
950
	    fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
951
	  
952
	  num_hd++;
953
	}
954
    }
955
  
956
#endif /* __linux__ */
957
958
#ifdef __linux__
959
  /* This is for cciss - we have
960
     /dev/cciss/c<controller>d<logical drive>p<partition>.
961
     
962
     cciss driver currently supports up to 8 controllers, 16 logical
963
     drives, and 7 partitions.  */
964
  {
965
    int controller, drive;
966
    
967
    for (controller = 0; controller < 8; controller++)
968
      {
969
	for (drive = 0; drive < 16; drive++)
970
	  {
971
	    char name[24];
972
	    
973
	    get_cciss_disk_name (name, controller, drive);
974
	    if (check_device (name))
975
	      {
976
		(*map)[num_hd + 0x80] = strdup (name);
977
		assert ((*map)[num_hd + 0x80]);
978
		
979
		/* If the device map file is opened, write the map.  */
980
		if (fp)
981
		  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
982
		
983
		num_hd++;
984
	      }
985
	  }
986
      }
987
  }
988
#endif /* __linux__ */
989
990
#ifdef __linux__
991
  /* This is for cpqarray - we have
992
     /dev/ida/c<controller>d<logical drive>p<partition>.
993
     
994
     cpqarray driver currently supports up to 8 controllers, 16 logical
995
     drives, and 15 partitions.  */
996
  {
997
    int controller, drive;
998
    
999
    for (controller = 0; controller < 8; controller++)
1000
      {
1001
	for (drive = 0; drive < 15; drive++)
1002
	  {
1003
	    char name[24];
1004
	    
1005
	    get_cpqarray_disk_name (name, controller, drive);
1006
	    if (check_device (name))
1007
	      {
1008
		(*map)[num_hd + 0x80] = strdup (name);
1009
		assert ((*map)[num_hd + 0x80]);
1010
		
1011
		/* If the device map file is opened, write the map.  */
1012
		if (fp)
1013
		  fprintf (fp, "(hd%d)\t%s\n", num_hd, name);
1014
		
1015
		num_hd++;
1016
	      }
1017
	  }
1018
      }
1019
  }
804
#endif /* __linux__ */
1020
#endif /* __linux__ */
805
  
1021
  
806
  /* OK, close the device map file if opened.  */
1022
  /* OK, close the device map file if opened.  */
Lines 831-839 int Link Here
831
is_disk_device (char **map, int drive)
1047
is_disk_device (char **map, int drive)
832
{
1048
{
833
  struct stat st;
1049
  struct stat st;
1050
  int retval;
834
  
1051
  
835
  assert (map[drive] != 0);
1052
  assert (map[drive] != 0);
836
  assert (stat (map[drive], &st) == 0);
1053
  retval = stat (map[drive], &st);
1054
  assert (retval == 0);
837
  /* For now, disk devices under Linux are all block devices.  */
1055
  /* For now, disk devices under Linux are all block devices.  */
838
  return S_ISBLK (st.st_mode);
1056
  return S_ISBLK (st.st_mode);
839
}
1057
}
Lines 843-849 write_to_partition (char **map, int drive, int partition, Link Here
843
		    int sector, int size, const char *buf)
1061
		    int sector, int size, const char *buf)
844
{
1062
{
845
  char dev[PATH_MAX];	/* XXX */
1063
  char dev[PATH_MAX];	/* XXX */
846
  int fd;
1064
  int fd, len, pnum;
847
  
1065
  
848
  if ((partition & 0x00FF00) != 0x00FF00)
1066
  if ((partition & 0x00FF00) != 0x00FF00)
849
    {
1067
    {
Lines 861-867 write_to_partition (char **map, int drive, int partition, Link Here
861
      if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
1079
      if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
862
	strcpy (dev + strlen(dev) - 5, "/part");
1080
	strcpy (dev + strlen(dev) - 5, "/part");
863
    }
1081
    }
864
  sprintf (dev + strlen(dev), "%d", ((partition >> 16) & 0xFF) + 1);
1082
1083
  len = strlen(dev);
1084
  pnum = ((partition >> 16) & 0xFF);
1085
  if (strncmp (dev, "/dev/disk/by-id/", 16) == 0)
1086
    {
1087
      sprintf (dev + len, "-part%d",  pnum + 1);
1088
    }
1089
  else if (isdigit(dev[len-1]))
1090
    {
1091
      /* It is obviously some RAID disk: "/dev/<dsk>/c0d0" . "p1" */
1092
      sprintf (dev + len, "p%d",  pnum + 1);
1093
    }
1094
  else
1095
    sprintf (dev + len, "%d",  pnum + 1);
865
  
1096
  
866
  /* Open the partition.  */
1097
  /* Open the partition.  */
867
  fd = open (dev, O_RDWR);
1098
  fd = open (dev, O_RDWR);
(-)a/netboot/config.c (+12 lines)
Lines 122-127 static struct pci_device pci_nic_list[] = Link Here
122
    "Intel EtherExpressPro100 ID1029", 0, 0, 0, 0},
122
    "Intel EtherExpressPro100 ID1029", 0, 0, 0, 0},
123
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_ID1030,
123
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_ID1030,
124
    "Intel Corporation 82559 InBusiness 10/100", 0, 0, 0, 0},
124
    "Intel Corporation 82559 InBusiness 10/100", 0, 0, 0, 0},
125
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_ID1031,
126
    "Intel EtherExpressPro100 ID1031", 0, 0, 0, 0},
127
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_ID1039,
128
    "Intel EtherExpressPro100 ID1039", 0, 0, 0, 0},
129
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_ID103B,
130
    "Intel 82801BD PRO/100 VM", 0, 0, 0, 0},
131
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_ID1050,
132
    "Intel EtherExpressPro100 82555 10/100", 0, 0, 0, 0},
125
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_82562,
133
  { PCI_VENDOR_ID_INTEL,	PCI_DEVICE_ID_INTEL_82562,
126
    "Intel EtherExpressPro100 82562EM", 0, 0, 0, 0},
134
    "Intel EtherExpressPro100 82562EM", 0, 0, 0, 0},
127
#endif
135
#endif
Lines 281-286 static struct pci_dispatch_table PCI_NIC[] = Link Here
281
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82559ER,   eepro100_probe },
289
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82559ER,   eepro100_probe },
282
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1029,    eepro100_probe },
290
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1029,    eepro100_probe },
283
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1030,    eepro100_probe },
291
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1030,    eepro100_probe },
292
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1031,    eepro100_probe },
293
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1039,    eepro100_probe },
294
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID103B,    eepro100_probe },
295
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ID1050,    eepro100_probe },
284
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82562,     eepro100_probe },
296
  { PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82562,     eepro100_probe },
285
# endif /* INCLUDE_EEPRO100 */
297
# endif /* INCLUDE_EEPRO100 */
286
# ifdef	INCLUDE_EPIC100
298
# ifdef	INCLUDE_EPIC100
(-)a/netboot/fsys_tftp.c (-2 / +2 lines)
Lines 409-415 tftp_read (char *addr, int size) Link Here
409
/* Check if the file DIRNAME really exists. Get the size and save it in
409
/* Check if the file DIRNAME really exists. Get the size and save it in
410
   FILEMAX.  */
410
   FILEMAX.  */
411
int
411
int
412
tftp_dir (char *dirname)
412
tftp_dir (char *dirname, void (*handle)(char *))
413
{
413
{
414
  int ch;
414
  int ch;
415
415
Lines 418-424 tftp_dir (char *dirname) Link Here
418
#endif
418
#endif
419
  
419
  
420
  /* In TFTP, there is no way to know what files exist.  */
420
  /* In TFTP, there is no way to know what files exist.  */
421
  if (print_possibilities)
421
  if (handle)
422
    return 1;
422
    return 1;
423
423
424
  /* Don't know the size yet.  */
424
  /* Don't know the size yet.  */
(-)a/netboot/i82586.c (-1 / +1 lines)
Lines 735-741 static unsigned char exos_i186_init[] = Link Here
735
static int exos205_probe2(void)
735
static int exos205_probe2(void)
736
{
736
{
737
	unsigned short		i;
737
	unsigned short		i;
738
	unsigned short		shmem[10];
738
	unsigned short		shmem[10] = { 0,0,0,0,0,0,0,0,0,0 };
739
739
740
	/* Fix the ISCP address and base. */
740
	/* Fix the ISCP address and base. */
741
	init_words[3] = scb_base;
741
	init_words[3] = scb_base;
(-)a/netboot/main.c (-2 / +2 lines)
Lines 54-62 struct rom_info rom; Link Here
54
54
55
static int vendorext_isvalid;
55
static int vendorext_isvalid;
56
static unsigned long netmask;
56
static unsigned long netmask;
57
static struct bootpd_t bootp_data;
57
struct bootpd_t bootp_data;
58
static unsigned long xid;
58
static unsigned long xid;
59
static unsigned char *end_of_rfc1533 = NULL;
59
unsigned char *end_of_rfc1533 = NULL;
60
60
61
#ifndef	NO_DHCP_SUPPORT
61
#ifndef	NO_DHCP_SUPPORT
62
#endif /* NO_DHCP_SUPPORT */
62
#endif /* NO_DHCP_SUPPORT */
(-)a/netboot/pci.h (+4 lines)
Lines 129-134 __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory") Link Here
129
#define PCI_DEVICE_ID_INTEL_82559ER	0x1209
129
#define PCI_DEVICE_ID_INTEL_82559ER	0x1209
130
#define PCI_DEVICE_ID_INTEL_ID1029	0x1029
130
#define PCI_DEVICE_ID_INTEL_ID1029	0x1029
131
#define PCI_DEVICE_ID_INTEL_ID1030	0x1030
131
#define PCI_DEVICE_ID_INTEL_ID1030	0x1030
132
#define PCI_DEVICE_ID_INTEL_ID1031	0x1031
133
#define PCI_DEVICE_ID_INTEL_ID1039	0x1039
134
#define PCI_DEVICE_ID_INTEL_ID103B	0x103B
135
#define PCI_DEVICE_ID_INTEL_ID1050	0x1050
132
#define PCI_DEVICE_ID_INTEL_82562	0x2449
136
#define PCI_DEVICE_ID_INTEL_82562	0x2449
133
#define PCI_VENDOR_ID_AMD		0x1022
137
#define PCI_VENDOR_ID_AMD		0x1022
134
#define PCI_DEVICE_ID_AMD_LANCE		0x2000
138
#define PCI_DEVICE_ID_AMD_LANCE		0x2000
(-)a/stage1/Makefile.am (-1 / +1 lines)
Lines 1-4 Link Here
1
pkglibdir = $(libdir)/$(PACKAGE)/$(host_cpu)-$(host_vendor)
1
pkglibdir = /usr/lib/grub
2
nodist_pkglib_DATA = stage1
2
nodist_pkglib_DATA = stage1
3
3
4
CLEANFILES = $(nodist_pkglib_DATA)
4
CLEANFILES = $(nodist_pkglib_DATA)
(-)a/stage1/stage1.S (-2 / +9 lines)
Lines 69-77 mode: Link Here
69
	.byte	0
69
	.byte	0
70
disk_address_packet:	
70
disk_address_packet:	
71
sectors:
71
sectors:
72
	.long	0
72
	.byte	0
73
	.ascii	"GRU"
73
heads:
74
heads:
74
	.long	0
75
	.ascii "B"
76
	.byte	0
77
	.word	0
75
cylinders:
78
cylinders:
76
	.word	0
79
	.word	0
77
sector_start:
80
sector_start:
Lines 177-183 real_start: Link Here
177
	/* check if AH=0x42 is supported if FORCE_LBA is zero */
180
	/* check if AH=0x42 is supported if FORCE_LBA is zero */
178
	MOV_MEM_TO_AL(ABS(force_lba))	/* movb	ABS(force_lba), %al */
181
	MOV_MEM_TO_AL(ABS(force_lba))	/* movb	ABS(force_lba), %al */
179
	testb	%al, %al
182
	testb	%al, %al
183
	/* check if LBA is forced OFF 0x80 <= %al <= 0xff */
184
	js	chs_mode
185
	/* or forced ON 0x01 <= %al <= 0x7f */
180
	jnz	lba_mode
186
	jnz	lba_mode
187
	/* otherwise trust BIOS int's result */
181
	andw	$1, %cx
188
	andw	$1, %cx
182
	jz	chs_mode
189
	jz	chs_mode
183
	
190
	
(-)a/stage2/Makefile.am (-1 / +1 lines)
Lines 27-33 libgrub_a_CFLAGS = $(GRUB_CFLAGS) -I$(top_srcdir)/lib \ Link Here
27
	-DUSE_MD5_PASSWORDS=1 -DSUPPORT_SERIAL=1 -DSUPPORT_HERCULES=1
27
	-DUSE_MD5_PASSWORDS=1 -DSUPPORT_SERIAL=1 -DSUPPORT_HERCULES=1
28
28
29
# Stage 2 and Stage 1.5's.
29
# Stage 2 and Stage 1.5's.
30
pkglibdir = $(libdir)/$(PACKAGE)/$(host_cpu)-$(host_vendor)
30
pkglibdir = /usr/lib/grub
31
31
32
EXTRA_PROGRAMS = nbloader.exec pxeloader.exec diskless.exec
32
EXTRA_PROGRAMS = nbloader.exec pxeloader.exec diskless.exec
33
33
(-)a/stage2/asm.S (-25 / +346 lines)
Lines 1091-1097 ENTRY(check_int13_extensions) Link Here
1091
	/* check if AH=0x42 is supported if FORCE_LBA is zero */
1091
	/* check if AH=0x42 is supported if FORCE_LBA is zero */
1092
	movb	EXT_C(force_lba), %al
1092
	movb	EXT_C(force_lba), %al
1093
	testb	%al, %al
1093
	testb	%al, %al
1094
	/* check if LBA is forced OFF 0x80 <= %al <= 0xff */
1095
	js	1f
1096
	/* or forced ON 0x01 <= %al <= 0x7f */
1094
	jnz	2f
1097
	jnz	2f
1098
	/* otherwise trust BIOS int's result */
1095
	andw	$1, %cx
1099
	andw	$1, %cx
1096
	jnz	2f
1100
	jnz	2f
1097
	
1101
	
Lines 1610-1657 ENTRY(set_vbe_mode) Link Here
1610
	popl	%ebp
1614
	popl	%ebp
1611
	ret
1615
	ret
1612
1616
1617
1618
/*
1619
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1620
 *
1621
 * graphical menu functions
1622
 *
1623
 */
1624
1625
/*
1626
 * int gfx_init (gfx_data_t *gfx_data)
1627
 *
1628
 * init gfx things
1629
 *
1630
 * return vales:
1631
 *   0: ok
1632
 *   1: failed
1633
 *   sets gfx_data->ok
1634
 */
1635
1636
ENTRY(gfx_init)
1637
	pushl	%ebp
1638
	movl	%esp, %ebp
1639
	
1640
	pushl	%edi
1641
	pushl	%esi
1642
	pushl	%ebx
1643
1644
	movl	8(%ebp),%edx
1645
	movl	%edx,%edi
1646
	leal	gfx_ofs_sys_cfg(%edx),%esi
1647
	andl	$0xf,%edi
1648
	shrl	$4,%edx
1649
1650
	pushl	%ebp
1651
1652
	call	EXT_C(prot_to_real)
1653
	.code16
1654
1655
	pushw	%ds
1656
	movw	%dx,%ds
1657
1658
	lcall	*gfx_ofs_jmp_table + 4 * 0 (%di)
1659
1660
	sbbl	%ebx,%ebx
1661
	negl	%ebx
1662
1663
	popw	%ds
1664
1665
	DATA32	call	EXT_C(real_to_prot)
1666
	.code32
1667
1668
	popl	%ebp
1669
1670
	movl	%ebx,%eax
1671
	xorl	$1,%ebx
1672
	movl	8(%ebp),%edx
1673
	movl	%ebx,gfx_ofs_ok(%edx)
1674
1675
	popl	%ebx
1676
	popl	%esi
1677
	popl	%edi
1678
1679
	popl	%ebp
1680
	ret
1681
1682
1683
/*
1684
 * int gfx_done (gfx_data_t *gfx_data)
1685
 *
1686
 * shut down gfx things
1687
 *
1688
 * return vales:
1689
 *   always 0
1690
 *   sets gfx_data->ok
1691
 */
1692
1693
ENTRY(gfx_done)
1694
	pushl	%ebp
1695
	movl	%esp, %ebp
1696
	
1697
	pushl	%edi
1698
	pushl	%esi
1699
	pushl	%ebx
1700
1701
	movl	8(%ebp),%edx
1702
	movl	%edx,%ebx
1703
	andl	$0xf,%ebx
1704
	shrl	$4,%edx
1705
1706
	pushl	%ebp
1707
1708
	call	EXT_C(prot_to_real)
1709
	.code16
1710
1711
	pushw	%ds
1712
1713
	movw	%dx,%ds
1714
1715
	lcall	*gfx_ofs_jmp_table + 4 * 1 (%bx)
1716
1717
	popw	%ds
1718
1719
	DATA32	call	EXT_C(real_to_prot)
1720
	.code32
1721
1722
	popl	%ebp
1723
1724
	xorl	%eax,%eax
1725
	movl	8(%ebp),%edx
1726
	movl	%eax,gfx_ofs_ok(%edx)
1727
1728
	popl	%ebx
1729
	popl	%esi
1730
	popl	%edi
1731
1732
	popl	%ebp
1733
	ret
1734
1735
1736
/*
1737
 * int gfx_input (gfx_data_t *gfx_data, int *menu_entry)
1738
 *
1739
 * let user enter a command line
1740
 *
1741
 * uses gfx_data->cmdline as buffer
1742
 *
1743
 * return values:
1744
 *   1: abort
1745
 *   2: boot
1746
 *   menu_entry: selected entry
1747
 */
1748
1749
ENTRY(gfx_input)
1750
	pushl	%ebp
1751
	movl	%esp, %ebp
1752
	
1753
	pushl	%edi
1754
	pushl	%esi
1755
	pushl	%ebx
1756
1757
	movl	8(%ebp),%edx
1758
	movl	%edx,%ebx
1759
	leal	gfx_ofs_sys_cfg(%edx),%esi
1760
	andl	$0xf,%ebx
1761
	shrl	$4,%edx
1762
1763
	pushl	%ebp
1764
1765
	call	EXT_C(prot_to_real)
1766
	.code16
1767
1768
	pushw	%ds
1769
1770
	movw	%dx,%ds
1771
1772
	movl	gfx_ofs_cmdline(%bx),%edi
1773
	movl	gfx_ofs_cmdline_len(%bx),%ecx
1774
	movl	gfx_ofs_timeout(%bx),%eax
1775
	imull	$18,%eax
1776
1777
	lcall	*gfx_ofs_jmp_table + 4 * 2 (%bx)
1778
1779
	movl	%eax,%ecx
1780
1781
	popw	%ds
1782
1783
	DATA32	call	EXT_C(real_to_prot)
1784
	.code32
1785
1786
	popl	%ebp
1787
1788
	movl	12(%ebp),%edx
1789
	movl	%ebx,(%edx)
1790
1791
	movl	%ecx,%eax
1792
1793
	popl	%ebx
1794
	popl	%esi
1795
	popl	%edi
1796
1797
	popl	%ebp
1798
	ret
1799
1800
1801
/*
1802
 * int gfx_setup_menu (gfx_data_t *gfx_data)
1803
 *
1804
 * draw boot menu
1805
 *
1806
 * return values:
1807
 *   always 0
1808
 */
1809
1810
/* menu entry descriptor */
1811
#define menu_entries		0
1812
#define menu_default		2	/* seg:ofs */
1813
#define menu_ent_list		6	/* seg:ofs */
1814
#define menu_ent_size		10
1815
#define menu_arg_list		12	/* seg:ofs */
1816
#define menu_arg_size		16
1817
#define sizeof_menu_desc	18
1818
1819
ENTRY(gfx_setup_menu)
1820
	pushl	%ebp
1821
	movl	%esp, %ebp
1822
	
1823
	pushl	%edi
1824
	pushl	%esi
1825
	pushl	%ebx
1826
1827
	movl	8(%ebp),%edx
1828
	movl	%edx,%ebx
1829
	andl	$0xf,%ebx
1830
	shrl	$4,%edx
1831
1832
	call	EXT_C(prot_to_real)
1833
	.code16
1834
1835
	pushw	%ds
1836
1837
	movw	%dx,%ds
1838
	shll	$4,%edx
1839
1840
	subw	$sizeof_menu_desc,%sp
1841
	movw	%esp,%ebp
1842
1843
	movl	gfx_ofs_menu_entries(%bx),%eax
1844
	movw	%ax,menu_entries(%bp)
1845
1846
	movl	gfx_ofs_menu_default_entry(%bx),%eax
1847
	subl	%edx,%eax
1848
	movw	%ax,menu_default(%bp)
1849
	movw	%ds,menu_default+2(%bp)
1850
1851
	movl	gfx_ofs_menu_list(%bx),%eax
1852
	subl	%edx,%eax
1853
	movw	%ax,menu_ent_list(%bp)
1854
	movw	%ds,menu_ent_list+2(%bp)
1855
1856
	movl	gfx_ofs_menu_entry_len(%bx),%eax
1857
	movw	%ax,menu_ent_size(%bp)
1858
1859
	movl	gfx_ofs_args_list(%bx),%eax
1860
	subl	%edx,%eax
1861
	movw	%ax,menu_arg_list(%bp)
1862
	movw	%ds,menu_arg_list+2(%bp)
1863
1864
	movl	gfx_ofs_args_entry_len(%bx),%eax
1865
	movw	%ax,menu_arg_size(%bp)
1866
1867
	movl	%ss,%esi
1868
	shll	$4,%esi
1869
	addl	%ebp,%esi
1870
	
1871
	lcall	%ds: *gfx_ofs_jmp_table + 4 * 3 (%bx)
1872
1873
	addw	$sizeof_menu_desc,%sp
1874
1875
	popw	%ds
1876
1877
	DATA32	call	EXT_C(real_to_prot)
1878
	.code32
1879
1880
	xorl	%eax,%eax
1881
1882
	popl	%ebx
1883
	popl	%esi
1884
	popl	%edi
1885
1886
	popl	%ebp
1887
	ret
1888
1889
1890
/*
1891
 *
1892
 * end graphics stuff
1893
 *
1894
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1895
 */
1896
1613
		
1897
		
1614
/*
1898
/*
1615
 * gateA20(int linear)
1899
 * gateA20(int linear)
1616
 *
1900
 *
1617
 * Gate address-line 20 for high memory.
1901
 * Gate address-line 20 for high memory.
1618
 *
1902
 *
1619
 * This routine is probably overconservative in what it does, but so what?
1903
 * Try to disable the A20 gate by all means. (The argument is ignored)
1620
 *
1904
 * On success (the memory world is free), a -1 is returned,  0 on failure.
1621
 * It also eats any keystrokes in the keyboard buffer.  :-(
1905
 * It may also eat any keystrokes in the keyboard buffer.  :-(
1622
 */
1906
 */
1623
1907
1624
ENTRY(gateA20)
1908
ENTRY(gateA20)
1909
	pushl	%ebx
1910
	pushl	%edx
1911
	call	testA20
1912
	jnz	1f
1913
	call	A20_BIOS
1914
	call	testA20
1915
	jnz	1f
1916
	call	A20_PORT92
1917
	call	testA20
1918
	jnz	1f
1919
	call	A20_KBDCTL
1920
	call	testA20
1921
	jnz	1f
1922
	movl	$0,%eax
1923
	jmp	2f
1924
1:	movl	$-1,%eax
1925
2:	popl	%edx
1926
	popl	%ebx
1927
	ret
1928
1929
testA20:
1930
	movl	0x500,%eax
1931
	movl	0x100500,%ebx
1932
	notl	%eax
1933
	movl	%eax,0x100500
1934
	cmpl	%eax,0x500
1935
	pushfl
1936
	movl	%ebx,0x100500
1937
	notl	%eax
1938
	movl	%eax,0x500
1939
	popfl
1940
	ret
1941
1942
A20_BIOS:	
1625
	/* first, try a BIOS call */
1943
	/* first, try a BIOS call */
1626
	pushl	%ebp
1627
	movl	8(%esp), %edx
1628
	
1944
	
1629
	call	EXT_C(prot_to_real)
1945
	call	EXT_C(prot_to_real)
1630
	
1946
	
1631
	.code16
1947
	.code16
1632
	movw	$0x2400, %ax
1948
	movw	$0x2401, %ax
1633
	testw	%dx, %dx
1634
	jz	1f
1635
	incw	%ax
1636
1:	stc
1949
1:	stc
1637
	int	$0x15
1950
	int	$0x15
1638
	jnc	2f
1639
1640
	/* set non-zero if failed */
1641
	movb	$1, %ah
1642
1643
	/* save the status */
1644
2:	movb	%ah, %dl
1645
1951
1646
	DATA32	call	EXT_C(real_to_prot)
1952
	DATA32	call	EXT_C(real_to_prot)
1647
	.code32
1953
	.code32
1648
1649
	popl	%ebp
1650
	testb	%dl, %dl
1651
	jnz	3f
1652
	ret
1954
	ret
1653
1955
1654
3:	/* use keyboard controller */
1956
1957
A20_PORT92:
1958
	/*
1959
	 * try to switch gateA20 using PORT92, the "Fast A20 and Init"
1960
	 * register
1961
	 */
1962
	mov     $0x92, %dx
1963
	inb     %dx, %al
1964
	/* skip the port92 code if it's unimplemented (read returns 0xff) */
1965
	cmpb    $0xff, %al
1966
	jz      6f
1967
1968
	/* set bit1, the ALT_A20_GATE bit */
1969
	orb     $2, %al
1970
/*	and     $0xfd, %al */
1971
1972
	/* clear the INIT_NOW bit; don't accidently reset the machine */
1973
	and     $0xfe, %al
1974
	outb    %al, %dx
1975
6:	ret
1976
1977
1978
A20_KBDCTL:	
1979
	/* use keyboard controller */
1655
	pushl	%eax
1980
	pushl	%eax
1656
1981
1657
	call    gloop1
1982
	call    gloop1
Lines 1665-1675 gloopint1: Link Here
1665
	jnz	gloopint1
1990
	jnz	gloopint1
1666
1991
1667
	movb	$KB_OUTPUT_MASK, %al
1992
	movb	$KB_OUTPUT_MASK, %al
1668
	cmpb	$0, 0x8(%esp)
1669
	jz	gdoit
1670
1671
	orb	$KB_A20_ENABLE, %al
1993
	orb	$KB_A20_ENABLE, %al
1672
gdoit:
1673
	outb	$K_RDWR
1994
	outb	$K_RDWR
1674
1995
1675
	call	gloop1
1996
	call	gloop1
(-)a/stage2/boot.c (-2 / +5 lines)
Lines 824-831 load_initrd (char *initrd) Link Here
824
    moveto = (mbi.mem_upper + 0x400) << 10;
824
    moveto = (mbi.mem_upper + 0x400) << 10;
825
  
825
  
826
  moveto = (moveto - len) & 0xfffff000;
826
  moveto = (moveto - len) & 0xfffff000;
827
  max_addr = (lh->header == LINUX_MAGIC_SIGNATURE && lh->version >= 0x0203
827
  max_addr = LINUX_INITRD_MAX_ADDRESS;
828
	      ? lh->initrd_addr_max : LINUX_INITRD_MAX_ADDRESS);
828
  if (lh->header == LINUX_MAGIC_SIGNATURE &&
829
      lh->version >= 0x0203 &&
830
      lh->initrd_addr_max < max_addr)
831
    max_addr = lh->initrd_addr_max;
829
  if (moveto + len >= max_addr)
832
  if (moveto + len >= max_addr)
830
    moveto = (max_addr - len) & 0xfffff000;
833
    moveto = (max_addr - len) & 0xfffff000;
831
  
834
  
(-)a/stage2/builtins.c (-15 / +133 lines)
Lines 63-68 int fallback_entryno; Link Here
63
int fallback_entries[MAX_FALLBACK_ENTRIES];
63
int fallback_entries[MAX_FALLBACK_ENTRIES];
64
/* The number of current entry.  */
64
/* The number of current entry.  */
65
int current_entryno;
65
int current_entryno;
66
/* graphics file */
67
char graphics_file[64];
66
/* The address for Multiboot command-line buffer.  */
68
/* The address for Multiboot command-line buffer.  */
67
static char *mb_cmdline;
69
static char *mb_cmdline;
68
/* The password.  */
70
/* The password.  */
Lines 455-460 chainloader_func (char *arg, int flags) Link Here
455
    *((unsigned long *) (BOOTSEC_LOCATION + BOOTSEC_BPB_HIDDEN_SECTORS))
457
    *((unsigned long *) (BOOTSEC_LOCATION + BOOTSEC_BPB_HIDDEN_SECTORS))
456
      = part_start;
458
      = part_start;
457
459
460
  /* if a new device was specified, make sure DX is passed correctly */
461
  if ('(' == *file)
462
    set_device(file);
463
458
  errnum = ERR_NONE;
464
  errnum = ERR_NONE;
459
  
465
  
460
  return 0;
466
  return 0;
Lines 766-776 static int Link Here
766
default_func (char *arg, int flags)
772
default_func (char *arg, int flags)
767
{
773
{
768
#ifndef SUPPORT_DISKLESS
774
#ifndef SUPPORT_DISKLESS
769
  if (grub_strcmp (arg, "saved") == 0)
775
  if (grub_strcmp (arg, "saved") == 0 || (saved_entryno & 0x4000))
770
    {
776
    {
771
      default_entry = saved_entryno;
777
      default_entry = saved_entryno & 0x3fff;
772
      return 0;
773
    }
778
    }
779
  else
774
#endif /* SUPPORT_DISKLESS */
780
#endif /* SUPPORT_DISKLESS */
775
  
781
  
776
  if (! safe_parse_maxint (&arg, &default_entry))
782
  if (! safe_parse_maxint (&arg, &default_entry))
Lines 791-796 static struct builtin builtin_default = Link Here
791
#endif
797
#endif
792
};
798
};
793
799
800
#ifndef SUPPORT_DISKLESS
801
static int savedefault_func (char *arg, int flags);
802
void __savedefault_once_reset()
803
{
804
  if (saved_entryno & 0x4000)
805
    {
806
      int saved_current_entryno = current_entryno;
807
      grub_timeout = 0;
808
      current_entryno = default_entry;
809
      savedefault_func("\0", BUILTIN_SCRIPT);
810
      current_entryno = saved_current_entryno;
811
      saved_entryno &= 0x3fff;
812
    }
813
}
814
#endif /* SUPPORT_DISKLESS */
815
794
816
795
#ifdef GRUB_UTIL
817
#ifdef GRUB_UTIL
796
/* device */
818
/* device */
Lines 1331-1336 static struct builtin builtin_fstest = Link Here
1331
};
1353
};
1332
1354
1333
1355
1356
/* graphics */
1357
static int
1358
gfxmenu_func (char *arg, int flags)
1359
{
1360
  memmove(graphics_file, arg, sizeof graphics_file - 1);
1361
  graphics_file[sizeof graphics_file - 1] = 0;
1362
1363
  return 0;
1364
}
1365
1366
static struct builtin builtin_gfxmenu =
1367
{
1368
  "gfxmenu",
1369
  gfxmenu_func,
1370
  BUILTIN_MENU | BUILTIN_HELP_LIST,
1371
  "gfxmenu FILE",
1372
  "Use the graphical menu from FILE."
1373
};
1374
1375
1334
/* geometry */
1376
/* geometry */
1335
static int
1377
static int
1336
geometry_func (char *arg, int flags)
1378
geometry_func (char *arg, int flags)
Lines 1834-1840 install_func (char *arg, int flags) Link Here
1834
  /* First, check the GNU-style long option.  */
1876
  /* First, check the GNU-style long option.  */
1835
  while (1)
1877
  while (1)
1836
    {
1878
    {
1837
      if (grub_memcmp ("--force-lba", arg, sizeof ("--force-lba") - 1) == 0)
1879
      if (grub_memcmp ("--force-lba=off", arg, sizeof ("--force-lba=off") - 1) == 0)
1880
	{
1881
	  is_force_lba = 0xff;
1882
	  arg = skip_to (0, arg);
1883
	}
1884
      else if (grub_memcmp ("--force-lba", arg, sizeof ("--force-lba") - 1) == 0)
1838
	{
1885
	{
1839
	  is_force_lba = 1;
1886
	  is_force_lba = 1;
1840
	  arg = skip_to (0, arg);
1887
	  arg = skip_to (0, arg);
Lines 1842-1850 install_func (char *arg, int flags) Link Here
1842
#ifdef GRUB_UTIL
1889
#ifdef GRUB_UTIL
1843
      else if (grub_memcmp ("--stage2=", arg, sizeof ("--stage2=") - 1) == 0)
1890
      else if (grub_memcmp ("--stage2=", arg, sizeof ("--stage2=") - 1) == 0)
1844
	{
1891
	{
1892
	  int fd;
1845
	  stage2_os_file = arg + sizeof ("--stage2=") - 1;
1893
	  stage2_os_file = arg + sizeof ("--stage2=") - 1;
1846
	  arg = skip_to (0, arg);
1894
	  arg = skip_to (0, arg);
1847
	  nul_terminate (stage2_os_file);
1895
	  nul_terminate (stage2_os_file);
1896
1897
#if defined(__linux__) && defined (FSYS_REISERFS)
1898
	  if ((fd=open(stage2_os_file, O_RDONLY)) >= 0)
1899
	    {
1900
	      struct statfs buf;
1901
	      /* see if the file sits on a reiserfs,
1902
		 and try do defragment it if so. */
1903
	      fstatfs(fd, &buf);
1904
	      if (buf.f_type == REISERFS_SUPER_MAGIC)
1905
		ioctl (fd, REISERFS_IOC_UNPACK, 1);
1906
	    }
1907
#endif	/* __linux__ && FSYS_REISERFS */
1908
1848
	}
1909
	}
1849
#endif /* GRUB_UTIL */
1910
#endif /* GRUB_UTIL */
1850
      else
1911
      else
Lines 2263-2269 static struct builtin builtin_install = Link Here
2263
  "install",
2324
  "install",
2264
  install_func,
2325
  install_func,
2265
  BUILTIN_CMDLINE,
2326
  BUILTIN_CMDLINE,
2266
  "install [--stage2=STAGE2_FILE] [--force-lba] STAGE1 [d] DEVICE STAGE2 [ADDR] [p] [CONFIG_FILE] [REAL_CONFIG_FILE]",
2327
  "install [--stage2=STAGE2_FILE] [--force-lba[=off]] STAGE1 [d] DEVICE STAGE2 [ADDR] [p] [CONFIG_FILE] [REAL_CONFIG_FILE]",
2267
  "Install STAGE1 on DEVICE, and install a blocklist for loading STAGE2"
2328
  "Install STAGE1 on DEVICE, and install a blocklist for loading STAGE2"
2268
  " as a Stage 2. If the option `d' is present, the Stage 1 will always"
2329
  " as a Stage 2. If the option `d' is present, the Stage 1 will always"
2269
  " look for the disk where STAGE2 was installed, rather than using"
2330
  " look for the disk where STAGE2 was installed, rather than using"
Lines 2276-2283 static struct builtin builtin_install = Link Here
2276
  " 1.5 and REAL_CONFIG_FILE is present, then the Stage 2 CONFIG_FILE is"
2337
  " 1.5 and REAL_CONFIG_FILE is present, then the Stage 2 CONFIG_FILE is"
2277
  " patched with the configuration filename REAL_CONFIG_FILE."
2338
  " patched with the configuration filename REAL_CONFIG_FILE."
2278
  " If the option `--force-lba' is specified, disable some sanity checks"
2339
  " If the option `--force-lba' is specified, disable some sanity checks"
2279
  " for LBA mode. If the option `--stage2' is specified, rewrite the Stage"
2340
  " for LBA mode, `--force-lba=off' will disable it completely. If the"
2280
  " 2 via your OS's filesystem instead of the raw device."
2341
  " option `--stage2' is specified, rewrite the Stage 2 via your OS's"
2342
  " filesystem instead of the raw device."
2281
};
2343
};
2282
2344
2283
2345
Lines 3890-3896 setup_func (char *arg, int flags) Link Here
3890
  /* Check if the user specifies --force-lba.  */
3952
  /* Check if the user specifies --force-lba.  */
3891
  while (1)
3953
  while (1)
3892
    {
3954
    {
3893
      if (grub_memcmp ("--force-lba", arg, sizeof ("--force-lba") - 1) == 0)
3955
      if (grub_memcmp ("--force-lba=off", arg, sizeof ("--force-lba=off") - 1) == 0)
3956
	{
3957
	  is_force_lba = 0xff;
3958
	  arg = skip_to (0, arg);
3959
	}
3960
      else if (grub_memcmp ("--force-lba", arg, sizeof ("--force-lba") - 1) == 0)
3894
	{
3961
	{
3895
	  is_force_lba = 1;
3962
	  is_force_lba = 1;
3896
	  arg = skip_to (0, arg);
3963
	  arg = skip_to (0, arg);
Lines 4011-4016 setup_func (char *arg, int flags) Link Here
4011
	}
4078
	}
4012
  }
4079
  }
4013
4080
4081
  /* force buffer cache invalidation after embedding */
4082
  buf_drive = -1;
4083
4014
  /* Construct a string that is used by the command "install" as its
4084
  /* Construct a string that is used by the command "install" as its
4015
     arguments.  */
4085
     arguments.  */
4016
  sprint_device (installed_drive, installed_partition);
4086
  sprint_device (installed_drive, installed_partition);
Lines 4018-4024 setup_func (char *arg, int flags) Link Here
4018
#if 1
4088
#if 1
4019
  /* Don't embed a drive number unnecessarily.  */
4089
  /* Don't embed a drive number unnecessarily.  */
4020
  grub_sprintf (cmd_arg, "%s%s%s%s %s%s %s p %s %s",
4090
  grub_sprintf (cmd_arg, "%s%s%s%s %s%s %s p %s %s",
4021
		is_force_lba? "--force-lba " : "",
4091
		is_force_lba ?
4092
		 (is_force_lba == 0xff ? "--force-lba=off " : "--force-lba ")
4093
		 : "",
4022
		stage2_arg? stage2_arg : "",
4094
		stage2_arg? stage2_arg : "",
4023
		stage2_arg? " " : "",
4095
		stage2_arg? " " : "",
4024
		stage1,
4096
		stage1,
Lines 4071-4087 static struct builtin builtin_setup = Link Here
4071
  "setup",
4143
  "setup",
4072
  setup_func,
4144
  setup_func,
4073
  BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
4145
  BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
4074
  "setup [--prefix=DIR] [--stage2=STAGE2_FILE] [--force-lba] INSTALL_DEVICE [IMAGE_DEVICE]",
4146
  "setup [--prefix=DIR] [--stage2=STAGE2_FILE] [--force-lba[=off]] INSTALL_DEVICE [IMAGE_DEVICE]",
4075
  "Set up the installation of GRUB automatically. This command uses"
4147
  "Set up the installation of GRUB automatically. This command uses"
4076
  " the more flexible command \"install\" in the backend and installs"
4148
  " the more flexible command \"install\" in the backend and installs"
4077
  " GRUB into the device INSTALL_DEVICE. If IMAGE_DEVICE is specified,"
4149
  " GRUB into the device INSTALL_DEVICE. If IMAGE_DEVICE is specified,"
4078
  " then find the GRUB images in the device IMAGE_DEVICE, otherwise"
4150
  " then find the GRUB images in the device IMAGE_DEVICE, otherwise"
4079
  " use the current \"root device\", which can be set by the command"
4151
  " use the current \"root device\", which can be set by the command"
4080
  " \"root\". If you know that your BIOS should support LBA but GRUB"
4152
  " \"root\". If you know that your BIOS should support LBA but GRUB"
4081
  " doesn't work in LBA mode, specify the option `--force-lba'."
4153
  " doesn't work in LBA mode, specify the option `--force-lba'. If the"
4082
  " If you install GRUB under the grub shell and you cannot unmount the"
4154
  " BIOS claims to support LBA mode but really doesn't, use"
4083
  " partition where GRUB images reside, specify the option `--stage2'"
4155
  " `--force-lba=off'. If you install GRUB under the grub shell and"
4084
  " to tell GRUB the file name under your OS."
4156
  " you cannot unmount the partition where GRUB images reside, specify"
4157
  " the option `--stage2' to tell GRUB the file name under your OS."
4085
};
4158
};
4086
4159
4087
4160
Lines 4186-4192 terminal_func (char *arg, int flags) Link Here
4186
4259
4187
  /* If multiple terminals are specified, wait until the user pushes any
4260
  /* If multiple terminals are specified, wait until the user pushes any
4188
     key on one of the terminals.  */
4261
     key on one of the terminals.  */
4189
  if (term_bitmap & ~(1 << default_term))
4262
  if ((term_bitmap & ~(1 << default_term)) && !(saved_entryno & 0x4000))
4190
    {
4263
    {
4191
      int time1, time2 = -1;
4264
      int time1, time2 = -1;
4192
4265
Lines 4792-4797 static struct builtin builtin_vbeprobe = Link Here
4792
};
4865
};
4793
  
4866
  
4794
4867
4868
/* wildcard */
4869
 static int
4870
wildcard_func (char *arg, int flags)
4871
{
4872
#ifdef DEBUG_WILDCARD
4873
  char *w = wildcard (arg);
4874
4875
  if (w)
4876
    {
4877
      while (*w)
4878
       {
4879
         grub_printf("%s  ", w);
4880
         w += strlen (w) + 1;
4881
        }
4882
      grub_printf("\n");
4883
      return 1;
4884
    }
4885
  else
4886
    print_error();
4887
#endif
4888
4889
  /* This special command is interpreted in the config file parser. */
4890
  return 0;
4891
}
4892
4893
static struct builtin builtin_wildcard =
4894
 {
4895
  "wildcard",
4896
  wildcard_func,
4897
#ifndef DEBUG_WILDCARD
4898
  BUILTIN_MENU,
4899
#else
4900
  BUILTIN_CMDLINE | BUILTIN_MENU | BUILTIN_HELP_LIST,
4901
  "wildcard GLOB",
4902
  "Declare this menu entry as a wildcard entry. GLOB is a path containing"
4903
  " one asterisk. All files matching this expression are looked up; the"
4904
  " menu entry is duplicated for each match with asterisks in other"
4905
  " commands replaced by the string matching the asterisk in the wildcard"
4906
  " command."
4907
#endif
4908
};
4909
4910
4795
/* The table of builtin commands. Sorted in dictionary order.  */
4911
/* The table of builtin commands. Sorted in dictionary order.  */
4796
struct builtin *builtin_table[] =
4912
struct builtin *builtin_table[] =
4797
{
4913
{
Lines 4823-4828 struct builtin *builtin_table[] = Link Here
4823
  &builtin_find,
4939
  &builtin_find,
4824
  &builtin_fstest,
4940
  &builtin_fstest,
4825
  &builtin_geometry,
4941
  &builtin_geometry,
4942
  &builtin_gfxmenu,
4826
  &builtin_halt,
4943
  &builtin_halt,
4827
  &builtin_help,
4944
  &builtin_help,
4828
  &builtin_hiddenmenu,
4945
  &builtin_hiddenmenu,
Lines 4880-4884 struct builtin *builtin_table[] = Link Here
4880
  &builtin_unhide,
4997
  &builtin_unhide,
4881
  &builtin_uppermem,
4998
  &builtin_uppermem,
4882
  &builtin_vbeprobe,
4999
  &builtin_vbeprobe,
5000
  &builtin_wildcard,
4883
  0
5001
  0
4884
};
5002
};
(-)a/stage2/disk_io.c (-23 / +16 lines)
Lines 36-42 void (*disk_read_hook) (int, int, int) = NULL; Link Here
36
void (*disk_read_func) (int, int, int) = NULL;
36
void (*disk_read_func) (int, int, int) = NULL;
37
37
38
#ifndef STAGE1_5
38
#ifndef STAGE1_5
39
int print_possibilities;
40
39
41
static int do_completion;
40
static int do_completion;
42
static int unique;
41
static int unique;
Lines 128-134 int filepos; Link Here
128
int filemax;
127
int filemax;
129
128
130
static inline unsigned long
129
static inline unsigned long
131
log2 (unsigned long word)
130
grub_log2 (unsigned long word)
132
{
131
{
133
  asm volatile ("bsfl %1,%0"
132
  asm volatile ("bsfl %1,%0"
134
		: "=r" (word)
133
		: "=r" (word)
Lines 140-146 int Link Here
140
rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
139
rawread (int drive, int sector, int byte_offset, int byte_len, char *buf)
141
{
140
{
142
  int slen, sectors_per_vtrack;
141
  int slen, sectors_per_vtrack;
143
  int sector_size_bits = log2 (buf_geom.sector_size);
142
  int sector_size_bits = grub_log2 (buf_geom.sector_size);
144
143
145
  if (byte_len <= 0)
144
  if (byte_len <= 0)
146
    return 1;
145
    return 1;
Lines 163-169 rawread (int drive, int sector, int byte_offset, int byte_len, char *buf) Link Here
163
	    }
162
	    }
164
	  buf_drive = drive;
163
	  buf_drive = drive;
165
	  buf_track = -1;
164
	  buf_track = -1;
166
	  sector_size_bits = log2 (buf_geom.sector_size);
165
	  sector_size_bits = grub_log2 (buf_geom.sector_size);
167
	}
166
	}
168
167
169
      /* Make sure that SECTOR is valid.  */
168
      /* Make sure that SECTOR is valid.  */
Lines 1479-1485 print_completions (int is_filename, int is_completion) Link Here
1479
	  if (! is_completion)
1478
	  if (! is_completion)
1480
	    grub_printf (" Possible files are:");
1479
	    grub_printf (" Possible files are:");
1481
	  
1480
	  
1482
	  dir (buf);
1481
	  dir (buf, print_a_completion);
1483
	  
1482
	  
1484
	  if (is_completion && *unique_string)
1483
	  if (is_completion && *unique_string)
1485
	    {
1484
	    {
Lines 1498-1504 print_completions (int is_filename, int is_completion) Link Here
1498
		  *ptr = '/';
1497
		  *ptr = '/';
1499
		  *(ptr + 1) = 0;
1498
		  *(ptr + 1) = 0;
1500
		  
1499
		  
1501
		  dir (buf);
1500
		  dir (buf, print_a_completion);
1502
		  
1501
		  
1503
		  /* Restore the original unique value.  */
1502
		  /* Restore the original unique value.  */
1504
		  unique = 1;
1503
		  unique = 1;
Lines 1626-1637 grub_open (char *filename) Link Here
1626
  if (!errnum && fsys_type == NUM_FSYS)
1625
  if (!errnum && fsys_type == NUM_FSYS)
1627
    errnum = ERR_FSYS_MOUNT;
1626
    errnum = ERR_FSYS_MOUNT;
1628
1627
1629
# ifndef STAGE1_5
1628
  if (!errnum && (*(fsys_table[fsys_type].dir_func)) (filename, NULL))
1630
  /* set "dir" function to open a file */
1631
  print_possibilities = 0;
1632
# endif
1633
1634
  if (!errnum && (*(fsys_table[fsys_type].dir_func)) (filename))
1635
    {
1629
    {
1636
#ifndef NO_DECOMPRESSION
1630
#ifndef NO_DECOMPRESSION
1637
      return gunzip_test_header ();
1631
      return gunzip_test_header ();
Lines 1752-1758 grub_seek (int offset) Link Here
1752
}
1746
}
1753
1747
1754
int
1748
int
1755
dir (char *dirname)
1749
dir (char *dirname, void (*handle)(char *))
1756
{
1750
{
1757
#ifndef NO_DECOMPRESSION
1751
#ifndef NO_DECOMPRESSION
1758
  compressed_file = 0;
1752
  compressed_file = 0;
Lines 1761-1779 dir (char *dirname) Link Here
1761
  if (!(dirname = setup_part (dirname)))
1755
  if (!(dirname = setup_part (dirname)))
1762
    return 0;
1756
    return 0;
1763
1757
1758
  errnum = 0;
1764
  if (*dirname != '/')
1759
  if (*dirname != '/')
1765
    errnum = ERR_BAD_FILENAME;
1760
    errnum = ERR_BAD_FILENAME;
1766
1761
  else if (fsys_type == NUM_FSYS)
1767
  if (fsys_type == NUM_FSYS)
1768
    errnum = ERR_FSYS_MOUNT;
1762
    errnum = ERR_FSYS_MOUNT;
1769
1763
  else
1770
  if (errnum)
1764
    {
1771
    return 0;
1765
      fsys_table[fsys_type].dir_func (dirname, handle);
1772
1766
      if (errnum == ERR_FILE_NOT_FOUND)
1773
  /* set "dir" function to list completions */
1767
	errnum = 0;
1774
  print_possibilities = 1;
1768
    }
1775
1769
  return errnum == 0;
1776
  return (*(fsys_table[fsys_type].dir_func)) (dirname);
1777
}
1770
}
1778
#endif /* STAGE1_5 */
1771
#endif /* STAGE1_5 */
1779
1772
(-)a/stage2/filesys.h (-18 / +22 lines)
Lines 24-30 Link Here
24
#define FSYS_FFS_NUM 1
24
#define FSYS_FFS_NUM 1
25
int ffs_mount (void);
25
int ffs_mount (void);
26
int ffs_read (char *buf, int len);
26
int ffs_read (char *buf, int len);
27
int ffs_dir (char *dirname);
27
int ffs_dir (char *dirname, void (*handle)(char *));
28
int ffs_embed (int *start_sector, int needed_sectors);
28
int ffs_embed (int *start_sector, int needed_sectors);
29
#else
29
#else
30
#define FSYS_FFS_NUM 0
30
#define FSYS_FFS_NUM 0
Lines 34-40 int ffs_embed (int *start_sector, int needed_sectors); Link Here
34
#define FSYS_UFS2_NUM 1
34
#define FSYS_UFS2_NUM 1
35
int ufs2_mount (void);
35
int ufs2_mount (void);
36
int ufs2_read (char *buf, int len);
36
int ufs2_read (char *buf, int len);
37
int ufs2_dir (char *dirname);
37
int ufs2_dir (char *dirname, void (*handle)(char *));
38
int ufs2_embed (int *start_sector, int needed_sectors);
38
int ufs2_embed (int *start_sector, int needed_sectors);
39
#else
39
#else
40
#define FSYS_UFS2_NUM 0
40
#define FSYS_UFS2_NUM 0
Lines 44-50 int ufs2_embed (int *start_sector, int needed_sectors); Link Here
44
#define FSYS_FAT_NUM 1
44
#define FSYS_FAT_NUM 1
45
int fat_mount (void);
45
int fat_mount (void);
46
int fat_read (char *buf, int len);
46
int fat_read (char *buf, int len);
47
int fat_dir (char *dirname);
47
int fat_dir (char *dirname, void (*handle)(char *));
48
#else
48
#else
49
#define FSYS_FAT_NUM 0
49
#define FSYS_FAT_NUM 0
50
#endif
50
#endif
Lines 53-59 int fat_dir (char *dirname); Link Here
53
#define FSYS_EXT2FS_NUM 1
53
#define FSYS_EXT2FS_NUM 1
54
int ext2fs_mount (void);
54
int ext2fs_mount (void);
55
int ext2fs_read (char *buf, int len);
55
int ext2fs_read (char *buf, int len);
56
int ext2fs_dir (char *dirname);
56
int ext2fs_dir (char *dirname, void (*handle)(char *));
57
#else
57
#else
58
#define FSYS_EXT2FS_NUM 0
58
#define FSYS_EXT2FS_NUM 0
59
#endif
59
#endif
Lines 62-68 int ext2fs_dir (char *dirname); Link Here
62
#define FSYS_MINIX_NUM 1
62
#define FSYS_MINIX_NUM 1
63
int minix_mount (void);
63
int minix_mount (void);
64
int minix_read (char *buf, int len);
64
int minix_read (char *buf, int len);
65
int minix_dir (char *dirname);
65
int minix_dir (char *dirname, void (*handle)(char *));
66
#else
66
#else
67
#define FSYS_MINIX_NUM 0
67
#define FSYS_MINIX_NUM 0
68
#endif
68
#endif
Lines 71-78 int minix_dir (char *dirname); Link Here
71
#define FSYS_REISERFS_NUM 1
71
#define FSYS_REISERFS_NUM 1
72
int reiserfs_mount (void);
72
int reiserfs_mount (void);
73
int reiserfs_read (char *buf, int len);
73
int reiserfs_read (char *buf, int len);
74
int reiserfs_dir (char *dirname);
74
int reiserfs_dir (char *dirname, void (*handle)(char *));
75
int reiserfs_embed (int *start_sector, int needed_sectors);
75
int reiserfs_embed (int *start_sector, int needed_sectors);
76
#if defined(__linux__) && defined (GRUB_UTIL)
77
#include <sys/types.h>
78
#include <sys/stat.h>
79
#include <sys/ioctl.h>
80
#include <sys/statfs.h>
81
#include <fcntl.h>
82
/* from <linux/reiserfs_fs.h> */
83
#define REISERFS_SUPER_MAGIC 0x52654973
84
#define REISERFS_IOC_UNPACK  _IOW(0xCD,1,long)
85
#endif
76
#else
86
#else
77
#define FSYS_REISERFS_NUM 0
87
#define FSYS_REISERFS_NUM 0
78
#endif
88
#endif
Lines 81-87 int reiserfs_embed (int *start_sector, int needed_sectors); Link Here
81
#define FSYS_VSTAFS_NUM 1
91
#define FSYS_VSTAFS_NUM 1
82
int vstafs_mount (void);
92
int vstafs_mount (void);
83
int vstafs_read (char *buf, int len);
93
int vstafs_read (char *buf, int len);
84
int vstafs_dir (char *dirname);
94
int vstafs_dir (char *dirname, void (*handle)(char *));
85
#else
95
#else
86
#define FSYS_VSTAFS_NUM 0
96
#define FSYS_VSTAFS_NUM 0
87
#endif
97
#endif
Lines 90-96 int vstafs_dir (char *dirname); Link Here
90
#define FSYS_JFS_NUM 1
100
#define FSYS_JFS_NUM 1
91
int jfs_mount (void);
101
int jfs_mount (void);
92
int jfs_read (char *buf, int len);
102
int jfs_read (char *buf, int len);
93
int jfs_dir (char *dirname);
103
int jfs_dir (char *dirname, void (*handle)(char *));
94
int jfs_embed (int *start_sector, int needed_sectors);
104
int jfs_embed (int *start_sector, int needed_sectors);
95
#else
105
#else
96
#define FSYS_JFS_NUM 0
106
#define FSYS_JFS_NUM 0
Lines 100-106 int jfs_embed (int *start_sector, int needed_sectors); Link Here
100
#define FSYS_XFS_NUM 1
110
#define FSYS_XFS_NUM 1
101
int xfs_mount (void);
111
int xfs_mount (void);
102
int xfs_read (char *buf, int len);
112
int xfs_read (char *buf, int len);
103
int xfs_dir (char *dirname);
113
int xfs_dir (char *dirname, void (*handle)(char *));
104
#else
114
#else
105
#define FSYS_XFS_NUM 0
115
#define FSYS_XFS_NUM 0
106
#endif
116
#endif
Lines 109-115 int xfs_dir (char *dirname); Link Here
109
#define FSYS_TFTP_NUM 1
119
#define FSYS_TFTP_NUM 1
110
int tftp_mount (void);
120
int tftp_mount (void);
111
int tftp_read (char *buf, int len);
121
int tftp_read (char *buf, int len);
112
int tftp_dir (char *dirname);
122
int tftp_dir (char *dirname, void (*handle)(char *));
113
void tftp_close (void);
123
void tftp_close (void);
114
#else
124
#else
115
#define FSYS_TFTP_NUM 0
125
#define FSYS_TFTP_NUM 0
Lines 119-125 void tftp_close (void); Link Here
119
#define FSYS_ISO9660_NUM 1
129
#define FSYS_ISO9660_NUM 1
120
int iso9660_mount (void);
130
int iso9660_mount (void);
121
int iso9660_read (char *buf, int len);
131
int iso9660_read (char *buf, int len);
122
int iso9660_dir (char *dirname);
132
int iso9660_dir (char *dirname, void (*handle)(char *));
123
#else
133
#else
124
#define FSYS_ISO9660_NUM 0
134
#define FSYS_ISO9660_NUM 0
125
#endif
135
#endif
Lines 150-165 struct fsys_entry Link Here
150
  char *name;
160
  char *name;
151
  int (*mount_func) (void);
161
  int (*mount_func) (void);
152
  int (*read_func) (char *buf, int len);
162
  int (*read_func) (char *buf, int len);
153
  int (*dir_func) (char *dirname);
163
  int (*dir_func) (char *dirname, void (*print_one)(char *));
154
  void (*close_func) (void);
164
  void (*close_func) (void);
155
  int (*embed_func) (int *start_sector, int needed_sectors);
165
  int (*embed_func) (int *start_sector, int needed_sectors);
156
};
166
};
157
167
158
#ifdef STAGE1_5
159
# define print_possibilities 0
160
#else
161
extern int print_possibilities;
162
#endif
163
164
extern int fsmax;
168
extern int fsmax;
165
extern struct fsys_entry fsys_table[NUM_FSYS + 1];
169
extern struct fsys_entry fsys_table[NUM_FSYS + 1];
(-)a/stage2/fsys_ext2fs.c (-26 / +13 lines)
Lines 193-199 struct ext2_dir_entry Link Here
193
193
194
194
195
/* ext2/super.c */
195
/* ext2/super.c */
196
#define log2(n) ffz(~(n))
196
#define grub_log2(n) ffz(~(n))
197
197
198
#define EXT2_SUPER_MAGIC      0xEF53	/* include/linux/ext2_fs.h */
198
#define EXT2_SUPER_MAGIC      0xEF53	/* include/linux/ext2_fs.h */
199
#define EXT2_ROOT_INO              2	/* include/linux/ext2_fs.h */
199
#define EXT2_ROOT_INO              2	/* include/linux/ext2_fs.h */
Lines 216-222 struct ext2_dir_entry Link Here
216
216
217
/* linux/ext2_fs.h */
217
/* linux/ext2_fs.h */
218
#define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
218
#define EXT2_ADDR_PER_BLOCK(s)          (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
219
#define EXT2_ADDR_PER_BLOCK_BITS(s)		(log2(EXT2_ADDR_PER_BLOCK(s)))
219
#define EXT2_ADDR_PER_BLOCK_BITS(s)		(grub_log2(EXT2_ADDR_PER_BLOCK(s)))
220
220
221
/* linux/ext2_fs.h */
221
/* linux/ext2_fs.h */
222
#define EXT2_BLOCK_SIZE_BITS(s)        ((s)->s_log_block_size + 10)
222
#define EXT2_BLOCK_SIZE_BITS(s)        ((s)->s_log_block_size + 10)
Lines 257-262 ext2fs_mount (void) Link Here
257
  if ((((current_drive & 0x80) || (current_slice != 0))
257
  if ((((current_drive & 0x80) || (current_slice != 0))
258
       && (current_slice != PC_SLICE_TYPE_EXT2FS)
258
       && (current_slice != PC_SLICE_TYPE_EXT2FS)
259
       && (current_slice != PC_SLICE_TYPE_LINUX_RAID)
259
       && (current_slice != PC_SLICE_TYPE_LINUX_RAID)
260
       && (current_slice != PC_SLICE_TYPE_ZEN)
261
       && (current_slice != PC_SLICE_TYPE_ZEN_DISABLED)
260
       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_EXT2FS))
262
       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_EXT2FS))
261
       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER)))
263
       && (! IS_PC_SLICE_TYPE_BSD_WITH_FS (current_slice, FS_OTHER)))
262
      || part_length < (SBLOCK + (sizeof (struct ext2_super_block) / DEV_BSIZE))
264
      || part_length < (SBLOCK + (sizeof (struct ext2_super_block) / DEV_BSIZE))
Lines 495-501 int ext2_is_fast_symlink (void) Link Here
495
 * side effects: messes up GROUP_DESC buffer area
497
 * side effects: messes up GROUP_DESC buffer area
496
 */
498
 */
497
int
499
int
498
ext2fs_dir (char *dirname)
500
ext2fs_dir (char *dirname, void (*handle)(char *))
499
{
501
{
500
  int current_ino = EXT2_ROOT_INO;	/* start at the root */
502
  int current_ino = EXT2_ROOT_INO;	/* start at the root */
501
  int updir_ino = current_ino;	/* the parent of the current directory */
503
  int updir_ino = current_ino;	/* the parent of the current directory */
Lines 521-527 ext2fs_dir (char *dirname) Link Here
521
#ifdef E2DEBUG
523
#ifdef E2DEBUG
522
  unsigned char *i;
524
  unsigned char *i;
523
#endif	/* E2DEBUG */
525
#endif	/* E2DEBUG */
524
525
  /* loop invariants:
526
  /* loop invariants:
526
     current_ino = inode to lookup
527
     current_ino = inode to lookup
527
     dirname = pointer to filename component we are cur looking up within
528
     dirname = pointer to filename component we are cur looking up within
Lines 537-543 ext2fs_dir (char *dirname) Link Here
537
538
538
      /* look up an inode */
539
      /* look up an inode */
539
      group_id = (current_ino - 1) / (SUPERBLOCK->s_inodes_per_group);
540
      group_id = (current_ino - 1) / (SUPERBLOCK->s_inodes_per_group);
540
      group_desc = group_id >> log2 (EXT2_DESC_PER_BLOCK (SUPERBLOCK));
541
      group_desc = group_id >> grub_log2 (EXT2_DESC_PER_BLOCK (SUPERBLOCK));
541
      desc = group_id & (EXT2_DESC_PER_BLOCK (SUPERBLOCK) - 1);
542
      desc = group_id & (EXT2_DESC_PER_BLOCK (SUPERBLOCK) - 1);
542
#ifdef E2DEBUG
543
#ifdef E2DEBUG
543
      printf ("ipg=%d, dpb=%d\n", SUPERBLOCK->s_inodes_per_group,
544
      printf ("ipg=%d, dpb=%d\n", SUPERBLOCK->s_inodes_per_group,
Lines 553-559 ext2fs_dir (char *dirname) Link Here
553
      gdp = GROUP_DESC;
554
      gdp = GROUP_DESC;
554
      ino_blk = gdp[desc].bg_inode_table +
555
      ino_blk = gdp[desc].bg_inode_table +
555
	(((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
556
	(((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
556
	 >> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
557
	 >> grub_log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
557
#ifdef E2DEBUG
558
#ifdef E2DEBUG
558
      printf ("inode table fsblock=%d\n", ino_blk);
559
      printf ("inode table fsblock=%d\n", ino_blk);
559
#endif /* E2DEBUG */
560
#endif /* E2DEBUG */
Lines 713-730 ext2fs_dir (char *dirname) Link Here
713
	     give up */
714
	     give up */
714
	  if (loc >= INODE->i_size)
715
	  if (loc >= INODE->i_size)
715
	    {
716
	    {
716
	      if (print_possibilities < 0)
717
	      errnum = ERR_FILE_NOT_FOUND;
717
		{
718
	      *rest = ch;
718
# if 0
719
	      return 0;
719
		  putchar ('\n');
720
# endif
721
		}
722
	      else
723
		{
724
		  errnum = ERR_FILE_NOT_FOUND;
725
		  *rest = ch;
726
		}
727
	      return (print_possibilities < 0);
728
	    }
720
	    }
729
721
730
	  /* else, find the (logical) block component of our location */
722
	  /* else, find the (logical) block component of our location */
Lines 765-784 ext2fs_dir (char *dirname) Link Here
765
	      str_chk = substring (dirname, dp->name);
757
	      str_chk = substring (dirname, dp->name);
766
758
767
# ifndef STAGE1_5
759
# ifndef STAGE1_5
768
	      if (print_possibilities && ch != '/'
760
	      if (handle && ch != '/' && (!*dirname || str_chk <= 0))
769
		  && (!*dirname || str_chk <= 0))
761
		handle (dp->name);
770
		{
771
		  if (print_possibilities > 0)
772
		    print_possibilities = -print_possibilities;
773
		  print_a_completion (dp->name);
774
		}
775
# endif
762
# endif
776
763
777
	      dp->name[dp->name_len] = saved_c;
764
	      dp->name[dp->name_len] = saved_c;
778
	    }
765
	    }
779
766
780
	}
767
	}
781
      while (!dp->inode || (str_chk || (print_possibilities && ch != '/')));
768
      while (!dp->inode || (str_chk || (handle && ch != '/')));
782
769
783
      current_ino = dp->inode;
770
      current_ino = dp->inode;
784
      *(dirname = rest) = ch;
771
      *(dirname = rest) = ch;
(-)a/stage2/fsys_fat.c (-20 / +6 lines)
Lines 55-61 struct fat_superblock Link Here
55
#define FAT_CACHE_SIZE 2048
55
#define FAT_CACHE_SIZE 2048
56
56
57
static __inline__ unsigned long
57
static __inline__ unsigned long
58
log2 (unsigned long word)
58
grub_log2 (unsigned long word)
59
{
59
{
60
  __asm__ ("bsfl %1,%0"
60
  __asm__ ("bsfl %1,%0"
61
	   : "=r" (word)
61
	   : "=r" (word)
Lines 84-92 fat_mount (void) Link Here
84
  if (bpb.sects_per_clust == 0)
84
  if (bpb.sects_per_clust == 0)
85
    return 0;
85
    return 0;
86
  
86
  
87
  FAT_SUPER->sectsize_bits = log2 (FAT_CVT_U16 (bpb.bytes_per_sect));
87
  FAT_SUPER->sectsize_bits = grub_log2 (FAT_CVT_U16 (bpb.bytes_per_sect));
88
  FAT_SUPER->clustsize_bits
88
  FAT_SUPER->clustsize_bits
89
    = FAT_SUPER->sectsize_bits + log2 (bpb.sects_per_clust);
89
    = FAT_SUPER->sectsize_bits + grub_log2 (bpb.sects_per_clust);
90
  
90
  
91
  /* Fill in info about super block */
91
  /* Fill in info about super block */
92
  FAT_SUPER->num_sectors = FAT_CVT_U16 (bpb.short_sectors) 
92
  FAT_SUPER->num_sectors = FAT_CVT_U16 (bpb.short_sectors) 
Lines 289-295 fat_read (char *buf, int len) Link Here
289
}
289
}
290
290
291
int
291
int
292
fat_dir (char *dirname)
292
fat_dir (char *dirname, void (*handle)(char *))
293
{
293
{
294
  char *rest, ch, dir_buf[FAT_DIRENTRY_LENGTH];
294
  char *rest, ch, dir_buf[FAT_DIRENTRY_LENGTH];
295
  char *filename = (char *) NAME_BUF;
295
  char *filename = (char *) NAME_BUF;
Lines 345-351 fat_dir (char *dirname) Link Here
345
  *rest = 0;
345
  *rest = 0;
346
  
346
  
347
# ifndef STAGE1_5
347
# ifndef STAGE1_5
348
  if (print_possibilities && ch != '/')
348
  if (handle && ch != '/')
349
    do_possibilities = 1;
349
    do_possibilities = 1;
350
# endif
350
# endif
351
  
351
  
Lines 356-371 fat_dir (char *dirname) Link Here
356
	{
356
	{
357
	  if (!errnum)
357
	  if (!errnum)
358
	    {
358
	    {
359
# ifndef STAGE1_5
360
	      if (print_possibilities < 0)
361
		{
362
#if 0
363
		  putchar ('\n');
364
#endif
365
		  return 1;
366
		}
367
# endif /* STAGE1_5 */
368
	      
369
	      errnum = ERR_FILE_NOT_FOUND;
359
	      errnum = ERR_FILE_NOT_FOUND;
370
	      *rest = ch;
360
	      *rest = ch;
371
	    }
361
	    }
Lines 460-470 fat_dir (char *dirname) Link Here
460
	{
450
	{
461
	print_filename:
451
	print_filename:
462
	  if (substring (dirname, filename) <= 0)
452
	  if (substring (dirname, filename) <= 0)
463
	    {
453
	    handle (filename);
464
	      if (print_possibilities > 0)
465
		print_possibilities = -print_possibilities;
466
	      print_a_completion (filename);
467
	    }
468
	  continue;
454
	  continue;
469
	}
455
	}
470
# endif /* STAGE1_5 */
456
# endif /* STAGE1_5 */
(-)a/stage2/fsys_ffs.c (-16 / +4 lines)
Lines 180-186 ffs_read (char *buf, int len) Link Here
180
180
181
181
182
int
182
int
183
ffs_dir (char *dirname)
183
ffs_dir (char *dirname, void (*handle)(char *))
184
{
184
{
185
  char *rest, ch;
185
  char *rest, ch;
186
  int block, off, loc, map, ino = ROOTINO;
186
  int block, off, loc, map, ino = ROOTINO;
Lines 236-248 loop: Link Here
236
    {
236
    {
237
      if (loc >= INODE->i_size)
237
      if (loc >= INODE->i_size)
238
	{
238
	{
239
#if 0
240
	  putchar ('\n');
241
#endif
242
243
	  if (print_possibilities < 0)
244
	    return 1;
245
246
	  errnum = ERR_FILE_NOT_FOUND;
239
	  errnum = ERR_FILE_NOT_FOUND;
247
	  *rest = ch;
240
	  *rest = ch;
248
	  return 0;
241
	  return 0;
Lines 267-284 loop: Link Here
267
      loc += dp->d_reclen;
260
      loc += dp->d_reclen;
268
261
269
#ifndef STAGE1_5
262
#ifndef STAGE1_5
270
      if (dp->d_ino && print_possibilities && ch != '/'
263
      if (dp->d_ino && handle && ch != '/'
271
	  && (!*dirname || substring (dirname, dp->d_name) <= 0))
264
	  && (!*dirname || substring (dirname, dp->d_name) <= 0))
272
	{
265
	handle (dp->d_name);
273
	  if (print_possibilities > 0)
274
	    print_possibilities = -print_possibilities;
275
276
	  print_a_completion (dp->d_name);
277
	}
278
#endif /* STAGE1_5 */
266
#endif /* STAGE1_5 */
279
    }
267
    }
280
  while (!dp->d_ino || (substring (dirname, dp->d_name) != 0
268
  while (!dp->d_ino || (substring (dirname, dp->d_name) != 0
281
			|| (print_possibilities && ch != '/')));
269
			|| (handle && ch != '/')));
282
270
283
  /* only get here if we have a matching directory entry */
271
  /* only get here if we have a matching directory entry */
284
272
(-)a/stage2/fsys_iso9660.c (-8 / +6 lines)
Lines 57-63 struct iso_inode_info { Link Here
57
57
58
58
59
static inline unsigned long
59
static inline unsigned long
60
log2 (unsigned long word)
60
grub_log2 (unsigned long word)
61
{
61
{
62
  asm volatile ("bsfl %1,%0"
62
  asm volatile ("bsfl %1,%0"
63
		:          "=r" (word)
63
		:          "=r" (word)
Lines 68-74 log2 (unsigned long word) Link Here
68
static int
68
static int
69
iso9660_devread (int sector, int byte_offset, int byte_len, char *buf)
69
iso9660_devread (int sector, int byte_offset, int byte_len, char *buf)
70
{
70
{
71
  unsigned short sector_size_lg2 = log2(buf_geom.sector_size);
71
  unsigned short sector_size_lg2 = grub_log2(buf_geom.sector_size);
72
72
73
  /*
73
  /*
74
   * We have to use own devread() function since BIOS return wrong geometry
74
   * We have to use own devread() function since BIOS return wrong geometry
Lines 133-139 iso9660_mount (void) Link Here
133
}
133
}
134
134
135
int
135
int
136
iso9660_dir (char *dirname)
136
iso9660_dir (char *dirname, void (*handle)(char *))
137
{
137
{
138
  struct iso_directory_record *idr;
138
  struct iso_directory_record *idr;
139
  RR_ptr_t rr_ptr;
139
  RR_ptr_t rr_ptr;
Lines 346-352 iso9660_dir (char *dirname) Link Here
346
	      if (name_len >= pathlen
346
	      if (name_len >= pathlen
347
		  && !memcmp(name, dirname, pathlen))
347
		  && !memcmp(name, dirname, pathlen))
348
		{
348
		{
349
		  if (dirname[pathlen] == '/' || !print_possibilities)
349
		  if (dirname[pathlen] == '/' || !handle)
350
		    {
350
		    {
351
		      /*
351
		      /*
352
		       *  DIRNAME is directory component of pathname,
352
		       *  DIRNAME is directory component of pathname,
Lines 377-387 iso9660_dir (char *dirname) Link Here
377
		  else	/* Completion */
377
		  else	/* Completion */
378
		    {
378
		    {
379
#ifndef STAGE1_5
379
#ifndef STAGE1_5
380
		      if (print_possibilities > 0)
381
			print_possibilities = -print_possibilities;
382
		      memcpy(NAME_BUF, name, name_len);
380
		      memcpy(NAME_BUF, name, name_len);
383
		      NAME_BUF[name_len] = '\0';
381
		      NAME_BUF[name_len] = '\0';
384
		      print_a_completion (NAME_BUF);
382
		      handle (NAME_BUF);
385
#endif
383
#endif
386
		    }
384
		    }
387
		}
385
		}
Lines 390-396 iso9660_dir (char *dirname) Link Here
390
	  size -= ISO_SECTOR_SIZE;
388
	  size -= ISO_SECTOR_SIZE;
391
	} /* size>0 */
389
	} /* size>0 */
392
390
393
      if (dirname[pathlen] == '/' || print_possibilities >= 0)
391
      if (dirname[pathlen] == '/' || handle)
394
	{
392
	{
395
	  errnum = ERR_FILE_NOT_FOUND;
393
	  errnum = ERR_FILE_NOT_FOUND;
396
	  return 0;
394
	  return 0;
(-)a/stage2/fsys_jfs.c (-10 / +4 lines)
Lines 270-276 jfs_read (char *buf, int len) Link Here
270
}
270
}
271
271
272
int
272
int
273
jfs_dir (char *dirname)
273
jfs_dir (char *dirname, void (*handle)(char *))
274
{
274
{
275
	char *ptr, *rest, ch;
275
	char *ptr, *rest, ch;
276
	ldtentry_t *de;
276
	ldtentry_t *de;
Lines 357-368 jfs_dir (char *dirname) Link Here
357
357
358
			cmp = (!*dirname) ? -1 : substring (dirname, namebuf);
358
			cmp = (!*dirname) ? -1 : substring (dirname, namebuf);
359
#ifndef STAGE1_5
359
#ifndef STAGE1_5
360
			if (print_possibilities && ch != '/'
360
			if (handle && ch != '/' && cmp <= 0)
361
			    && cmp <= 0) {
361
				handle (namebuf);
362
				if (print_possibilities > 0)
362
			else
363
					print_possibilities = -print_possibilities;
364
				print_a_completion (namebuf);
365
			} else
366
#endif
363
#endif
367
			if (cmp == 0) {
364
			if (cmp == 0) {
368
				parent_inum = inum;
365
				parent_inum = inum;
Lines 372-380 jfs_dir (char *dirname) Link Here
372
			}
369
			}
373
			de = next_dentry ();
370
			de = next_dentry ();
374
			if (de == NULL) {
371
			if (de == NULL) {
375
				if (print_possibilities < 0)
376
					return 1;
377
378
				errnum = ERR_FILE_NOT_FOUND;
372
				errnum = ERR_FILE_NOT_FOUND;
379
				*rest = ch;
373
				*rest = ch;
380
				return 0;
374
				return 0;
(-)a/stage2/fsys_minix.c (-21 / +7 lines)
Lines 294-300 minix_read (char *buf, int len) Link Here
294
     inode of the file we were trying to look up
294
     inode of the file we were trying to look up
295
   side effects: none yet  */
295
   side effects: none yet  */
296
int
296
int
297
minix_dir (char *dirname)
297
minix_dir (char *dirname, void (*handle)(char *))
298
{
298
{
299
  int current_ino = MINIX_ROOT_INO;  /* start at the root */
299
  int current_ino = MINIX_ROOT_INO;  /* start at the root */
300
  int updir_ino = current_ino;	     /* the parent of the current directory */
300
  int updir_ino = current_ino;	     /* the parent of the current directory */
Lines 457-474 minix_dir (char *dirname) Link Here
457
	     give up */
457
	     give up */
458
	  if (loc >= INODE->i_size)
458
	  if (loc >= INODE->i_size)
459
	    {
459
	    {
460
	      if (print_possibilities < 0)
460
	      errnum = ERR_FILE_NOT_FOUND;
461
		{
461
	      *rest = ch;
462
#if 0
462
	      return 0;
463
		  putchar ('\n');
464
#endif
465
		}
466
	      else
467
		{
468
		  errnum = ERR_FILE_NOT_FOUND;
469
		  *rest = ch;
470
		}
471
	      return (print_possibilities < 0);
472
	    }
463
	    }
473
464
474
	  /* else, find the (logical) block component of our location */
465
	  /* else, find the (logical) block component of our location */
Lines 510-529 minix_dir (char *dirname) Link Here
510
	      str_chk = substring (dirname, dp->name);
501
	      str_chk = substring (dirname, dp->name);
511
502
512
# ifndef STAGE1_5
503
# ifndef STAGE1_5
513
	      if (print_possibilities && ch != '/'
504
	      if (handle && ch != '/' && (!*dirname || str_chk <= 0))
514
		  && (!*dirname || str_chk <= 0))
505
		handle (dp->name);
515
		{
516
		  if (print_possibilities > 0)
517
		    print_possibilities = -print_possibilities;
518
		  print_a_completion (dp->name);
519
		}
520
# endif
506
# endif
521
507
522
	      dp->name[namelen] = saved_c;
508
	      dp->name[namelen] = saved_c;
523
	    }
509
	    }
524
510
525
	}
511
	}
526
      while (!dp->inode || (str_chk || (print_possibilities && ch != '/')));
512
      while (!dp->inode || (str_chk || (handle && ch != '/')));
527
513
528
      current_ino = dp->inode;
514
      current_ino = dp->inode;
529
      *(dirname = rest) = ch;
515
      *(dirname = rest) = ch;
(-)a/stage2/fsys_reiserfs.c (-13 / +5 lines)
Lines 367-373 struct fsys_reiser_info Link Here
367
367
368
368
369
static __inline__ unsigned long
369
static __inline__ unsigned long
370
log2 (unsigned long word)
370
grub_log2 (unsigned long word)
371
{
371
{
372
  __asm__ ("bsfl %1,%0"
372
  __asm__ ("bsfl %1,%0"
373
	   : "=r" (word)
373
	   : "=r" (word)
Lines 609-615 reiserfs_mount (void) Link Here
609
  
609
  
610
  INFO->version = super.s_version;
610
  INFO->version = super.s_version;
611
  INFO->blocksize = super.s_blocksize;
611
  INFO->blocksize = super.s_blocksize;
612
  INFO->fullblocksize_shift = log2 (super.s_blocksize);
612
  INFO->fullblocksize_shift = grub_log2 (super.s_blocksize);
613
  INFO->blocksize_shift = INFO->fullblocksize_shift - SECTOR_BITS;
613
  INFO->blocksize_shift = INFO->fullblocksize_shift - SECTOR_BITS;
614
  INFO->cached_slots = 
614
  INFO->cached_slots = 
615
    (FSYSREISER_CACHE_SIZE >> INFO->fullblocksize_shift) - 1;
615
    (FSYSREISER_CACHE_SIZE >> INFO->fullblocksize_shift) - 1;
Lines 991-997 reiserfs_read (char *buf, int len) Link Here
991
 *   the size of the file.
991
 *   the size of the file.
992
 */
992
 */
993
int
993
int
994
reiserfs_dir (char *dirname)
994
reiserfs_dir (char *dirname, void (*handle)(char *))
995
{
995
{
996
  struct reiserfs_de_head *de_head;
996
  struct reiserfs_de_head *de_head;
997
  char *rest, ch;
997
  char *rest, ch;
Lines 1123-1129 reiserfs_dir (char *dirname) Link Here
1123
      *rest = 0;
1123
      *rest = 0;
1124
      
1124
      
1125
# ifndef STAGE1_5
1125
# ifndef STAGE1_5
1126
      if (print_possibilities && ch != '/')
1126
      if (handle && ch != '/')
1127
	do_possibilities = 1;
1127
	do_possibilities = 1;
1128
# endif /* ! STAGE1_5 */
1128
# endif /* ! STAGE1_5 */
1129
      
1129
      
Lines 1170-1179 reiserfs_dir (char *dirname) Link Here
1170
		    {
1170
		    {
1171
		      if (cmp <= 0)
1171
		      if (cmp <= 0)
1172
			{
1172
			{
1173
			  if (print_possibilities > 0)
1174
			    print_possibilities = -print_possibilities;
1175
			  *name_end = 0;
1173
			  *name_end = 0;
1176
			  print_a_completion (filename);
1174
			  handle (filename);
1177
			  *name_end = tmp;
1175
			  *name_end = tmp;
1178
			}
1176
			}
1179
		    }
1177
		    }
Lines 1189-1200 reiserfs_dir (char *dirname) Link Here
1189
	      num_entries--;
1187
	      num_entries--;
1190
	    }
1188
	    }
1191
	}
1189
	}
1192
      
1193
# ifndef STAGE1_5
1194
      if (print_possibilities < 0)
1195
	return 1;
1196
# endif /* ! STAGE1_5 */
1197
      
1198
      errnum = ERR_FILE_NOT_FOUND;
1190
      errnum = ERR_FILE_NOT_FOUND;
1199
      *rest = ch;
1191
      *rest = ch;
1200
      return 0;
1192
      return 0;
(-)a/stage2/fsys_ufs2.c (-12 / +4 lines)
Lines 204-210 ufs2_read (char *buf, int len) Link Here
204
}
204
}
205
205
206
int
206
int
207
ufs2_dir (char *dirname)
207
ufs2_dir (char *dirname, void (*handle)(char *))
208
{
208
{
209
  char *rest, ch;
209
  char *rest, ch;
210
  int block, off, loc, ino = ROOTINO;
210
  int block, off, loc, ino = ROOTINO;
Lines 261-269 loop: Link Here
261
    {
261
    {
262
      if (loc >= INODE_UFS2->di_size)
262
      if (loc >= INODE_UFS2->di_size)
263
	{
263
	{
264
	  if (print_possibilities < 0)
265
	    return 1;
266
267
	  errnum = ERR_FILE_NOT_FOUND;
264
	  errnum = ERR_FILE_NOT_FOUND;
268
	  *rest = ch;
265
	  *rest = ch;
269
	  return 0;
266
	  return 0;
Lines 288-305 loop: Link Here
288
      loc += dp->d_reclen;
285
      loc += dp->d_reclen;
289
286
290
#ifndef STAGE1_5
287
#ifndef STAGE1_5
291
      if (dp->d_ino && print_possibilities && ch != '/'
288
      if (dp->d_ino && handle && ch != '/'
292
	  && (!*dirname || substring (dirname, dp->d_name) <= 0))
289
	  && (!*dirname || substring (dirname, dp->d_name) <= 0))
293
	{
290
	handle (dp->d_name);
294
	  if (print_possibilities > 0)
295
	    print_possibilities = -print_possibilities;
296
297
	  print_a_completion (dp->d_name);
298
	}
299
#endif /* STAGE1_5 */
291
#endif /* STAGE1_5 */
300
    }
292
    }
301
  while (!dp->d_ino || (substring (dirname, dp->d_name) != 0
293
  while (!dp->d_ino || (substring (dirname, dp->d_name) != 0
302
			|| (print_possibilities && ch != '/')));
294
			|| (handle && ch != '/')));
303
295
304
  /* only get here if we have a matching directory entry */
296
  /* only get here if we have a matching directory entry */
305
297
(-)a/stage2/fsys_vstafs.c (-14 / +3 lines)
Lines 115-121 vstafs_nextdir (void) Link Here
115
}
115
}
116
116
117
int 
117
int 
118
vstafs_dir (char *dirname)
118
vstafs_dir (char *dirname, void (*handle)(char *))
119
{
119
{
120
  char *fn, ch;
120
  char *fn, ch;
121
  struct dir_entry *d;
121
  struct dir_entry *d;
Lines 146-159 vstafs_dir (char *dirname) Link Here
146
	    continue;
146
	    continue;
147
	  
147
	  
148
#ifndef STAGE1_5
148
#ifndef STAGE1_5
149
	  if (print_possibilities && ch != '/'
149
	  if (handle && ch != '/'
150
	      && (! *dirname || strcmp (dirname, d->name) <= 0))
150
	      && (! *dirname || strcmp (dirname, d->name) <= 0))
151
	    {
151
	    handle(d->name);
152
	      if (print_possibilities > 0)
153
		print_possibilities = -print_possibilities;
154
	      
155
	      printf ("  %s", d->name);
156
	    }
157
#endif
152
#endif
158
	  if (! grub_strcmp (dirname, d->name))
153
	  if (! grub_strcmp (dirname, d->name))
159
	    {
154
	    {
Lines 168-179 vstafs_dir (char *dirname) Link Here
168
      *(dirname = fn) = ch;
163
      *(dirname = fn) = ch;
169
      if (! d)
164
      if (! d)
170
	{
165
	{
171
	  if (print_possibilities < 0)
172
	    {
173
	      putchar ('\n');
174
	      return 1;
175
	    }
176
	  
177
	  errnum = ERR_FILE_NOT_FOUND;
166
	  errnum = ERR_FILE_NOT_FOUND;
178
	  return 0;
167
	  return 0;
179
	}
168
	}
(-)a/stage2/fsys_xfs.c (-9 / +4 lines)
Lines 534-540 xfs_read (char *buf, int len) Link Here
534
}
534
}
535
535
536
int
536
int
537
xfs_dir (char *dirname)
537
xfs_dir (char *dirname, void (*handle)(char *))
538
{
538
{
539
	xfs_ino_t ino, parent_ino, new_ino;
539
	xfs_ino_t ino, parent_ino, new_ino;
540
	xfs_fsize_t di_size;
540
	xfs_fsize_t di_size;
Lines 595-605 xfs_dir (char *dirname) Link Here
595
		for (;;) {
595
		for (;;) {
596
			cmp = (!*dirname) ? -1 : substring (dirname, name);
596
			cmp = (!*dirname) ? -1 : substring (dirname, name);
597
#ifndef STAGE1_5
597
#ifndef STAGE1_5
598
			if (print_possibilities && ch != '/' && cmp <= 0) {
598
			if (handle && ch != '/' && cmp <= 0)
599
				if (print_possibilities > 0)
599
				handle (name);
600
					print_possibilities = -print_possibilities;
600
			else
601
				print_a_completion (name);
602
			} else
603
#endif
601
#endif
604
			if (cmp == 0) {
602
			if (cmp == 0) {
605
				parent_ino = ino;
603
				parent_ino = ino;
Lines 610-618 xfs_dir (char *dirname) Link Here
610
			}
608
			}
611
			name = next_dentry (&new_ino);
609
			name = next_dentry (&new_ino);
612
			if (name == NULL) {
610
			if (name == NULL) {
613
				if (print_possibilities < 0)
614
					return 1;
615
616
				errnum = ERR_FILE_NOT_FOUND;
611
				errnum = ERR_FILE_NOT_FOUND;
617
				*rest = ch;
612
				*rest = ch;
618
				return 0;
613
				return 0;
(-)a/stage2/iso9660.h (-2 / +2 lines)
Lines 73-83 typedef union { Link Here
73
73
74
typedef	struct __iso_16bit {
74
typedef	struct __iso_16bit {
75
  u_int16_t l, b;
75
  u_int16_t l, b;
76
} iso_16bit_t __attribute__ ((packed));
76
} iso_16bit_t;
77
77
78
typedef	struct __iso_32bit {
78
typedef	struct __iso_32bit {
79
  u_int32_t l, b;
79
  u_int32_t l, b;
80
} iso_32bit_t __attribute__ ((packed));
80
} iso_32bit_t;
81
81
82
typedef u_int8_t		iso_date_t[7];
82
typedef u_int8_t		iso_date_t[7];
83
83
(-)a/stage2/pc_slice.h (+2 lines)
Lines 114-119 Link Here
114
#define PC_SLICE_TYPE_EXT2FS       	0x83
114
#define PC_SLICE_TYPE_EXT2FS       	0x83
115
#define PC_SLICE_TYPE_LINUX_EXTENDED	0x85
115
#define PC_SLICE_TYPE_LINUX_EXTENDED	0x85
116
#define PC_SLICE_TYPE_VSTAFS		0x9e
116
#define PC_SLICE_TYPE_VSTAFS		0x9e
117
#define PC_SLICE_TYPE_ZEN		0xbc
118
#define PC_SLICE_TYPE_ZEN_DISABLED	0xbd
117
#define PC_SLICE_TYPE_DELL_UTIL		0xde
119
#define PC_SLICE_TYPE_DELL_UTIL		0xde
118
#define PC_SLICE_TYPE_LINUX_RAID	0xfd
120
#define PC_SLICE_TYPE_LINUX_RAID	0xfd
119
121
(-)a/stage2/shared.h (-5 / +55 lines)
Lines 174-181 extern char *grub_scratch_mem; Link Here
174
174
175
#define BOOTSEC_LOCATION		RAW_ADDR (0x7C00)
175
#define BOOTSEC_LOCATION		RAW_ADDR (0x7C00)
176
#define BOOTSEC_SIGNATURE		0xAA55
176
#define BOOTSEC_SIGNATURE		0xAA55
177
#define BOOTSEC_BPB_OFFSET		0x3
177
#define BOOTSEC_BPB_OFFSET		0xA
178
#define BOOTSEC_BPB_LENGTH		0x3B
178
#define BOOTSEC_BPB_LENGTH		0x34
179
#define BOOTSEC_BPB_SYSTEM_ID		0x3
179
#define BOOTSEC_BPB_SYSTEM_ID		0x3
180
#define BOOTSEC_BPB_HIDDEN_SECTORS	0x1C
180
#define BOOTSEC_BPB_HIDDEN_SECTORS	0x1C
181
#define BOOTSEC_PART_OFFSET		0x1BE
181
#define BOOTSEC_PART_OFFSET		0x1BE
Lines 374-379 extern char *grub_scratch_mem; Link Here
374
#endif /* WITHOUT_LIBC_STUBS */
374
#endif /* WITHOUT_LIBC_STUBS */
375
375
376
376
377
/* see typedef gfx_data_t below */
378
#define gfx_ofs_ok			0x00
379
#define gfx_ofs_code_seg		0x04
380
#define gfx_ofs_jmp_table		0x08
381
#define gfx_ofs_sys_cfg			0x38
382
#define gfx_ofs_cmdline			0x6c
383
#define gfx_ofs_cmdline_len		0x70
384
#define gfx_ofs_menu_list		0x74
385
#define gfx_ofs_menu_default_entry	0x78
386
#define gfx_ofs_menu_entries		0x7c
387
#define gfx_ofs_menu_entry_len		0x80
388
#define gfx_ofs_args_list		0x84
389
#define gfx_ofs_args_entry_len		0x88
390
#define gfx_ofs_timeout			0x8c
391
392
377
#ifndef ASM_FILE
393
#ifndef ASM_FILE
378
/*
394
/*
379
 *  Below this should be ONLY defines and other constructs for C code.
395
 *  Below this should be ONLY defines and other constructs for C code.
Lines 595-600 extern int fallback_entryno; Link Here
595
extern int default_entry;
611
extern int default_entry;
596
extern int current_entryno;
612
extern int current_entryno;
597
613
614
615
/*
616
 * graphics menu stuff
617
 *
618
 * Note: gfx_data and all data referred to in it must lie within a 64k area.
619
 */
620
typedef struct {
621
  unsigned ok;			/* set while we're in graphics mode */
622
  unsigned code_seg;		/* code segment of binary graphics code */
623
  unsigned jmp_table[12];	/* link to graphics functions */
624
  unsigned char sys_cfg[52];	/* sys_cfg[0]: identifies boot loader (grub == 2) */
625
  char *cmdline;		/* command line returned by gfx_input() */
626
  unsigned cmdline_len;		/* length of the above */
627
  char *menu_list;		/* list of menu entries, each of fixed length (menu_entry_len) */
628
  char *menu_default_entry;	/* the default entry */
629
  unsigned menu_entries;	/* number of entries in menu_list */
630
  unsigned menu_entry_len;	/* one entry */
631
  char *args_list;		/* same structure as menu_list, menu_entries entries */
632
  unsigned args_entry_len;	/* one entry */
633
  unsigned timeout;		/* in seconds (0: no timeout) */
634
} __attribute__ ((packed)) gfx_data_t;
635
636
extern gfx_data_t *graphics_data;
637
638
/* pointer to graphics image data */
639
extern char graphics_file[64];
640
641
int gfx_init(gfx_data_t *gfx_data);
642
int gfx_done(gfx_data_t *gfx_data);
643
int gfx_input(gfx_data_t *gfx_data, int *menu_entry);
644
int gfx_setup_menu(gfx_data_t *gfx_data);
645
598
/* The constants for password types.  */
646
/* The constants for password types.  */
599
typedef enum
647
typedef enum
600
{
648
{
Lines 956-964 int grub_seek (int offset); Link Here
956
/* Close a file.  */
1004
/* Close a file.  */
957
void grub_close (void);
1005
void grub_close (void);
958
1006
959
/* List the contents of the directory that was opened with GRUB_OPEN,
1007
/* List the contents of DIRECTORY. */
960
   printing all completions. */
1008
int dir (char *dirname, void (*handle)(char *));
961
int dir (char *dirname);
1009
 
1010
/* Wildcard expand the last pathname component of GLOB. */
1011
char *wildcard (char *glob, int *len);
962
1012
963
int set_bootdev (int hdbias);
1013
int set_bootdev (int hdbias);
964
1014
(-)a/stage2/stage2.c (-11 / +885 lines)
Lines 22-27 Link Here
22
22
23
grub_jmp_buf restart_env;
23
grub_jmp_buf restart_env;
24
24
25
gfx_data_t *graphics_data;
26
25
#if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
27
#if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
26
28
27
# if defined(PRESET_MENU_STRING)
29
# if defined(PRESET_MENU_STRING)
Lines 234-239 run_menu (char *menu_entries, char *config_entries, int num_entries, Link Here
234
  int c, time1, time2 = -1, first_entry = 0;
236
  int c, time1, time2 = -1, first_entry = 0;
235
  char *cur_entry = 0;
237
  char *cur_entry = 0;
236
238
239
  cls();
240
237
  /*
241
  /*
238
   *  Main loop for menu UI.
242
   *  Main loop for menu UI.
239
   */
243
   */
Lines 261-274 restart: Link Here
261
      /* Get current time.  */
265
      /* Get current time.  */
262
      while ((time1 = getrtsecs ()) == 0xFF)
266
      while ((time1 = getrtsecs ()) == 0xFF)
263
	;
267
	;
268
      grub_printf("\rPress any key to enter the menu\n\n\n");
264
269
265
      while (1)
270
      while (1)
266
	{
271
	{
267
	  /* Check if ESC is pressed.  */
272
	  /* Check if ESC is pressed.  */
268
	  if (checkkey () != -1 && ASCII_CHAR (getkey ()) == '\e')
273
	  if (checkkey () != -1)
269
	    {
274
	    {
270
	      grub_timeout = -1;
275
	      grub_timeout = -1;
271
	      show_menu = 1;
276
	      show_menu = 1;
277
	      getkey ();
272
	      break;
278
	      break;
273
	    }
279
	    }
274
280
Lines 287-293 restart: Link Here
287
	      grub_timeout--;
293
	      grub_timeout--;
288
	      
294
	      
289
	      /* Print a message.  */
295
	      /* Print a message.  */
290
	      grub_printf ("\rPress `ESC' to enter the menu... %d   ",
296
	      grub_printf ("\rBooting %s in %d seconds...",
297
			   get_entry(menu_entries, first_entry + entryno, 0),
291
			   grub_timeout);
298
			   grub_timeout);
292
	    }
299
	    }
293
	}
300
	}
Lines 310-315 restart: Link Here
310
      
317
      
311
      if (! auth && password)
318
      if (! auth && password)
312
	{
319
	{
320
	  if (*graphics_file)
321
	    {
322
	      printf ("\
323
	WARNING: graphical menu doesn\'t work\
324
	in conjunction with the password feature\n" );
325
	    }
313
	  printf ("\
326
	  printf ("\
314
      Press enter to boot the selected OS or \'p\' to enter a\n\
327
      Press enter to boot the selected OS or \'p\' to enter a\n\
315
      password to unlock the next set of features.");
328
      password to unlock the next set of features.");
Lines 319-325 restart: Link Here
319
	  if (config_entries)
332
	  if (config_entries)
320
	    printf ("\
333
	    printf ("\
321
      Press enter to boot the selected OS, \'e\' to edit the\n\
334
      Press enter to boot the selected OS, \'e\' to edit the\n\
322
      commands before booting, or \'c\' for a command-line.");
335
      commands before booting, \'a\' to modify the kernel arguments\n\
336
      before booting, or \'c\' for a command-line.");
323
	  else
337
	  else
324
	    printf ("\
338
	    printf ("\
325
      Press \'b\' to boot, \'e\' to edit the selected command in the\n\
339
      Press \'b\' to boot, \'e\' to edit the selected command in the\n\
Lines 697-702 restart: Link Here
697
		  enter_cmdline (heap, 0);
711
		  enter_cmdline (heap, 0);
698
		  goto restart;
712
		  goto restart;
699
		}
713
		}
714
	      if (config_entries && c == 'a')
715
		{
716
		  int new_num_entries = 0, i = 0, j;
717
		  char *new_heap;
718
		  char * entries;
719
		  char * entry_copy;
720
		  char * append_line;
721
		  char * start;
722
723
		  entry_copy = new_heap = heap;
724
		  cur_entry = get_entry (config_entries, first_entry + entryno,
725
					 1);
726
		  
727
		  do
728
		    {
729
		      while ((*(new_heap++) = cur_entry[i++]) != 0);
730
		      new_num_entries++;
731
		    }
732
		  while (config_entries && cur_entry[i]);
733
734
		  /* this only needs to be done if config_entries is non-NULL,
735
		     but it doesn't hurt to do it always */
736
		  *(new_heap++) = 0;
737
738
		  new_heap = heap + NEW_HEAPSIZE + 1;
739
740
		  entries = entry_copy;
741
		  while (*entries) 
742
		    {
743
		      if ((strstr(entries, "kernel") == entries) &&
744
			  isspace(entries[6])) 
745
			  break;
746
747
		      while (*entries) entries++;
748
		      entries++;
749
		    }
750
751
		  if (!*entries)
752
		      goto restart;
753
754
		  start = entries + 6;
755
756
		  /* skip the white space */
757
		  while (*start && isspace(*start)) start++;
758
		  /* skip the kernel name */
759
		  while (*start && !isspace(*start)) start++;
760
		  /* skip the white space */
761
		  while (*start && isspace(*start)) start++;
762
763
		  append_line = new_heap;
764
		  grub_strcpy(append_line, start);
765
766
		  cls();
767
		  print_cmdline_message (0);
768
769
		  if (get_cmdline(PACKAGE " append> ", 
770
				    append_line, NEW_HEAPSIZE + 1, 
771
				    0, 1))
772
		      goto restart;
773
774
		  /* have new args; append_line points to the
775
		     new args and start points to the old
776
		     args */
777
778
		  i = grub_strlen(start);
779
		  j = grub_strlen(append_line);
780
	      
781
		  /* align rest of commands properly */
782
		  memmove (start + j, start + i,
783
		       ((int) append_line) - ((int) start) - (i > j ? i : j));
784
785
		  /* copy command to correct area */
786
		  memmove (start, append_line, j);
787
788
		  /* set up this entry to boot */
789
		  config_entries = NULL;
790
		  cur_entry = entry_copy;
791
		  heap = new_heap;
792
793
		  break;
794
		}
700
#ifdef GRUB_UTIL
795
#ifdef GRUB_UTIL
701
	      if (c == 'q')
796
	      if (c == 'q')
702
		{
797
		{
Lines 753-758 restart: Link Here
753
}
848
}
754
849
755
850
851
852
#if 0
853
/* for debugging */
854
static void hexdump(unsigned char *buf, unsigned len)
855
{
856
  int i, j = 0;
857
  char s[17];
858
  unsigned addr = (unsigned) buf;
859
860
  s[16] = 0;
861
  while(len--) {
862
    i = buf[j];
863
    i = i & 0xff;
864
    s[j & 15] = (i >= 0x20 && i <= 0x7e) ? i : '.';
865
    if(!(j & 15)) {
866
      printf("%x  ", j + addr);
867
    }
868
    if(!(j & 7) && (j & 15)) printf(" ");
869
    /* stupid grub_printf */
870
    printf("%x", (i >> 4) & 0x0f);
871
    printf("%x ", i & 0x0f);
872
    if(!(++j & 15)) {
873
      printf(" %s\n", s);
874
    }
875
  }
876
877
  if(j & 15) {
878
    s[j & 15] = 0;
879
    if(!(j & 8)) printf(" ");
880
    i = 1 + 3 * (16 - (j & 15));
881
    while(i--) printf(" ");
882
    printf("%s\n", s);
883
  }
884
}
885
#endif
886
887
888
/* kernel + (grub-)module options */
889
#define GFX_CMD_BUF_SIZE 512
890
891
/* command line separator char */
892
#define GFX_CMD_SEP 1
893
894
/*
895
 * Go through config entry and find kernel args, if any.
896
 * Put things into buf and return it.
897
 */
898
static char *get_kernel_args(char *cfg, char *buf)
899
{
900
  int i, j;
901
  char *s, *t = "", *p, *t2;
902
903
  *(p = buf) = 0;
904
905
  for(j = 0; ; j++) {
906
    s = get_entry(cfg, j, 0);
907
    if(!*s) break;
908
    if(
909
      (!memcmp(s, "kernel", 6) || !memcmp(s, "module", 6)) &&
910
      (s[6] == ' ' || s[6] == '\t')
911
    ) {
912
      t = skip_to(0, s);
913
      t2 = s[0] == 'm' ? strstr(t, "initrd") : NULL;
914
      if(*t) t = skip_to(0, t);
915
      if(t2 && t2 < t) break;	/* module is likely a normal initrd -> skip */
916
      i = strlen(t);
917
      if(p - buf + i > GFX_CMD_BUF_SIZE - 2) break;
918
      *p++ = GFX_CMD_SEP;
919
      strcpy(p, t);
920
      p += i;
921
922
      continue;
923
    }
924
  }
925
926
  if(*buf) buf++;	/* skip initial separator char */
927
928
  return buf;
929
}
930
931
932
/*
933
 * Check header and return code start offset.
934
 */
935
static unsigned magic_ok(unsigned char *buf)
936
{
937
  if(
938
    *(unsigned *) buf == 0x0b2d97f00 &&		/* magic id */
939
    (buf[4] == 8)				/* version 8 */
940
  ) {
941
    return *(unsigned *) (buf + 8);
942
  }
943
944
  return 0;
945
}
946
947
948
/*
949
 * Search cpio archive for gfx file.
950
 */
951
static unsigned find_file(unsigned char *buf, unsigned len, unsigned *gfx_file_start, unsigned *file_len)
952
{
953
  unsigned i, fname_len, code_start = 0;
954
955
  *gfx_file_start = 0;
956
957
  for(i = 0; i < len;) {
958
    if((len - i) >= 0x1a && (buf[i] + (buf[i + 1] << 8)) == 0x71c7) {
959
      fname_len = *(unsigned short *) (buf + i + 20);
960
      *file_len = *(unsigned short *) (buf + i + 24) + (*(unsigned short *) (buf + i + 22) << 16);
961
      i += 26 + fname_len;
962
      i = ((i + 1) & ~1);
963
      if((code_start = magic_ok(buf + i))) {
964
        *gfx_file_start = i;
965
        return code_start;
966
      }
967
      i += *file_len;
968
      i = ((i + 1) & ~1);
969
    }
970
    else {
971
      break;
972
    }
973
  }
974
975
  return code_start;
976
}
977
978
static inline unsigned char * stack_ptr(void)
979
{
980
  unsigned char * u;
981
982
  asm("movl %%esp, %0" : "=r" (u));
983
984
  return u;
985
}
986
987
static void sleep(int delay)
988
{
989
  int tick, last_tick = currticks();
990
991
  delay *= 18;
992
993
  while(delay--) {
994
    while((tick = currticks()) == last_tick) { }
995
    last_tick = tick;
996
  }
997
}  
998
999
static void wait_for_key()
1000
{
1001
  printf("Press a key to continue...");
1002
  getkey();
1003
  printf("\r                          \r");
1004
}
1005
1006
1007
/*
1008
 * Leave that much space on the heap. Everything else goes to the graphics
1009
 * functions.
1010
 *
1011
 * 0x2000 is _not_ enough
1012
 */
1013
#define MIN_HEAP_SIZE	0x4000
1014
#define MIN_GFX_FREE	0x1000
1015
1016
#define SC_BOOTLOADER		0
1017
#define SC_FAILSAFE		3
1018
#define SC_SYSCONFIG_SIZE	4
1019
#define SC_BOOTLOADER_SEG	8
1020
#define SC_XMEM_0		24
1021
#define SC_XMEM_1		26
1022
#define SC_XMEM_2		28
1023
#define SC_XMEM_3		30
1024
#define SC_FILE			32
1025
#define SC_ARCHIVE_START	36
1026
#define SC_ARCHIVE_END		40
1027
#define SC_MEM0_START		44
1028
#define SC_MEM0_END		48
1029
1030
/*
1031
 * Does normally not return.
1032
 */
1033
static void
1034
run_graphics_menu (char *menu_entries, char *config_entries, int num_entries,
1035
	  char *heap, int entryno)
1036
{
1037
  unsigned char *buf, *buf_ext;
1038
  unsigned buf_size, buf_ext_size, code_start, file_start;
1039
  char *s, *t, *t2, *cfg, *new_config, *p;
1040
  char *saved_heap;
1041
  int i, j, max_len, gfx_file_size, verbose;
1042
  int selected_entry;
1043
  gfx_data_t *gfx_data;
1044
  char *cmd_buf;
1045
  unsigned mem0_start, mem0_end, file_len;
1046
1047
  /*
1048
   * check gfx_data_t struct offsets for consistency; gcc will optimize away
1049
   * the whole block
1050
   */
1051
1052
  /* dummy function to make ld fail */
1053
  {
1054
    extern void wrong_struct_size(void);
1055
    #define gfx_ofs_check(a) if(gfx_ofs_##a != (char *) &gfx_data->a - (char *) gfx_data) wrong_struct_size();
1056
    gfx_ofs_check(ok);
1057
    gfx_ofs_check(code_seg);
1058
    gfx_ofs_check(jmp_table);
1059
    gfx_ofs_check(sys_cfg);
1060
    gfx_ofs_check(cmdline);
1061
    gfx_ofs_check(cmdline_len);
1062
    gfx_ofs_check(menu_list);
1063
    gfx_ofs_check(menu_default_entry);
1064
    gfx_ofs_check(menu_entries);
1065
    gfx_ofs_check(menu_entry_len);
1066
    gfx_ofs_check(args_list);
1067
    gfx_ofs_check(args_entry_len);
1068
    gfx_ofs_check(timeout);
1069
    #undef gfx_ofs_check
1070
  }
1071
1072
  if(!num_entries) return;
1073
1074
  graphics_data = gfx_data = (gfx_data_t *) heap;
1075
  heap += sizeof *gfx_data;
1076
  memset(gfx_data, 0, sizeof *gfx_data);
1077
1078
  gfx_data->sys_cfg[SC_BOOTLOADER] = 2;			/* bootloader: grub */
1079
  gfx_data->sys_cfg[SC_SYSCONFIG_SIZE] = 52;		/* config data size */
1080
  *(unsigned short *) (gfx_data->sys_cfg + SC_BOOTLOADER_SEG) = (unsigned) gfx_data >> 4;	/* segment */
1081
  gfx_data->sys_cfg[SC_XMEM_0] = 0x21;			/* 1MB @ 2MB */
1082
  gfx_data->sys_cfg[SC_XMEM_1] = 0x41;			/* 1MB @ 4MB */
1083
  verbose = (*(unsigned char *) 0x417) & 3 ? 1 : 0;	/* SHIFT pressed */
1084
  gfx_data->sys_cfg[SC_FAILSAFE] = verbose;
1085
1086
  gfx_data->timeout = grub_timeout >= 0 ? grub_timeout : 0;
1087
1088
1089
  /* setup command line edit buffer */
1090
1091
  gfx_data->cmdline_len = 256;
1092
1093
  gfx_data->cmdline = heap;
1094
  heap += gfx_data->cmdline_len;
1095
  memset(gfx_data->cmdline, 0, gfx_data->cmdline_len);
1096
1097
  cmd_buf = heap;
1098
  heap += GFX_CMD_BUF_SIZE;
1099
1100
  /* setup menu entries */
1101
1102
  for(i = max_len = 0; i < num_entries; i++) {
1103
    j = strlen(get_entry(menu_entries, i, 0));
1104
    if(j > max_len) max_len = j;
1105
  }
1106
1107
  if(!max_len) return;
1108
1109
  gfx_data->menu_entry_len = max_len + 1;
1110
  gfx_data->menu_entries = num_entries;
1111
1112
  gfx_data->menu_list = heap;
1113
  heap += gfx_data->menu_entry_len * gfx_data->menu_entries;
1114
1115
  memset(gfx_data->menu_list, 0, gfx_data->menu_entry_len * gfx_data->menu_entries);
1116
1117
  for(i = 0; i < (int) gfx_data->menu_entries; i++) {
1118
    strcpy(gfx_data->menu_list + i * gfx_data->menu_entry_len, get_entry(menu_entries, i, 0));
1119
  }
1120
1121
  gfx_data->menu_default_entry = gfx_data->menu_list + entryno * gfx_data->menu_entry_len;
1122
1123
1124
  /* setup list of kernel args */
1125
1126
  for(i = max_len = 0; i < num_entries; i++) {
1127
    s = get_kernel_args(get_entry(config_entries, i, 1), cmd_buf);
1128
    j = strlen(s);
1129
    if(j > max_len) max_len = j;
1130
  }
1131
1132
  gfx_data->args_entry_len = max_len + 1;
1133
1134
  gfx_data->args_list = heap;
1135
  heap += gfx_data->args_entry_len * gfx_data->menu_entries;
1136
1137
  memset(gfx_data->args_list, 0, gfx_data->args_entry_len * gfx_data->menu_entries);
1138
1139
  for(i = 0; i < (int) gfx_data->menu_entries; i++) {
1140
    strcpy(gfx_data->args_list + i* gfx_data->args_entry_len, get_kernel_args(get_entry(config_entries, i, 1), cmd_buf));
1141
  }
1142
1143
1144
  /* go back here when we no longer need the graphics data */
1145
  saved_heap = heap;
1146
1147
1148
  /* get memory area to be used by graphics functions */
1149
1150
  /* use 1MB starting at 2MB as file buffer */
1151
  buf_ext = (unsigned char *) (2 << 20);
1152
  buf_ext_size = 1 << 20;
1153
1154
  /* must be 16-byte aligned */
1155
  buf = (unsigned char *) (((unsigned) heap + 0xf) & ~0xf);
1156
1157
  buf_size = stack_ptr() - buf - MIN_HEAP_SIZE;
1158
  buf_size &= ~0xf;
1159
1160
  mem0_start = (unsigned) buf;
1161
  mem0_end = mem0_start + buf_size;
1162
1163
  if(verbose) {
1164
    printf("low memory 0x%x - 0x%x (%d bytes)\n", mem0_start, mem0_end, buf_size);
1165
    wait_for_key();
1166
  }
1167
1168
  heap += buf_size;
1169
1170
  /* read the file */
1171
1172
  if(!grub_open(graphics_file)) {
1173
    printf("%s: file not found\n", graphics_file);
1174
    sleep(5);
1175
    heap = saved_heap;
1176
    return;
1177
  }
1178
1179
  gfx_file_size = grub_read(buf_ext, buf_ext_size);
1180
1181
  grub_close();
1182
1183
  if(gfx_file_size <= 0) {
1184
    printf("%s: read error\n", graphics_file);
1185
    sleep(5);
1186
    heap = saved_heap;
1187
    return;
1188
  }
1189
1190
  if(verbose) {
1191
    printf("%s: %d bytes (%d bytes left)\n", graphics_file, gfx_file_size, buf_ext_size - gfx_file_size);
1192
    wait_for_key();
1193
  }
1194
1195
  /* locate file inside cpio archive */
1196
  if(!(code_start = find_file(buf_ext, gfx_file_size, &file_start, &file_len))) {
1197
    printf("%s: invalid file format\n", graphics_file);
1198
    sleep(5);
1199
    heap = saved_heap;
1200
    return;
1201
  }
1202
1203
  if(verbose) {
1204
    printf("init: start 0x%x, len %d; code offset 0x%x\n", file_start, file_len, code_start);
1205
    wait_for_key();
1206
  }
1207
1208
  if(file_len - code_start + MIN_GFX_FREE > buf_size) {
1209
    printf("not enough free memory: %d extra bytes need\n", file_len - code_start + MIN_GFX_FREE - buf_size);
1210
    sleep(5);
1211
    heap = saved_heap;
1212
    return;
1213
  }
1214
1215
  memcpy((void *) buf, (void *) (buf_ext + file_start + code_start), file_len - code_start);
1216
1217
  mem0_start += file_len - code_start;
1218
  mem0_start = (mem0_start + 3) & ~3;		/* align */
1219
1220
  /* init interface to graphics functions */
1221
1222
  *(unsigned *) (gfx_data->sys_cfg + SC_FILE) = (unsigned) buf_ext + file_start;
1223
  *(unsigned *) (gfx_data->sys_cfg + SC_ARCHIVE_START) = (unsigned) buf_ext;
1224
  *(unsigned *) (gfx_data->sys_cfg + SC_ARCHIVE_END) = (unsigned) buf_ext + gfx_file_size;
1225
  *(unsigned *) (gfx_data->sys_cfg + SC_MEM0_START) = mem0_start;
1226
  *(unsigned *) (gfx_data->sys_cfg + SC_MEM0_END) = mem0_end;
1227
1228
  gfx_data->code_seg = (unsigned) buf >> 4;
1229
1230
  if(verbose) {
1231
    printf("init 0x%x, archive 0x%x - 0x%x, low mem 0x%x - 0x%x\ncode seg 0x%x\n",
1232
      (unsigned) buf_ext + file_start,
1233
      (unsigned) buf_ext, (unsigned) buf_ext + gfx_file_size,
1234
      mem0_start, mem0_end, gfx_data->code_seg
1235
    );
1236
    wait_for_key();
1237
  }
1238
1239
  for(i = 0; (unsigned) i < sizeof gfx_data->jmp_table / sizeof *gfx_data->jmp_table; i++) {
1240
    gfx_data->jmp_table[i] = (gfx_data->code_seg << 16) + ((unsigned short *) buf)[i];
1241
  }
1242
1243
  if(verbose) {
1244
    for(i = 0; i < 12; i++) {
1245
      printf("%d: 0x%x\n", i, gfx_data->jmp_table[i]);
1246
    }
1247
1248
    for(i = 0; i < gfx_data->menu_entries; i++) {
1249
      printf("\"%s\"  --  \"%s\"\n",
1250
        gfx_data->menu_list + i * gfx_data->menu_entry_len,
1251
        gfx_data->args_list + i * gfx_data->args_entry_len
1252
      );
1253
    }
1254
1255
    printf("default: \"%s\"\n", gfx_data->menu_default_entry);
1256
    wait_for_key();
1257
  }
1258
1259
  /* switch to graphics mode */
1260
1261
  if(gfx_init(gfx_data)) {
1262
    printf("graphics initialization failed\n");
1263
    sleep(5);
1264
    heap = saved_heap;
1265
    return;
1266
  }
1267
1268
  gfx_setup_menu(gfx_data);
1269
1270
  i = gfx_input(gfx_data, &selected_entry);
1271
1272
  /* ESC -> show text menu */
1273
  if(i == 1) {
1274
    gfx_done(gfx_data);
1275
    grub_timeout = -1;
1276
1277
    heap = saved_heap;
1278
    return;
1279
  }
1280
1281
  gfx_done(gfx_data);
1282
1283
  heap = saved_heap;	/* free most of the graphics data */
1284
1285
  // printf("cmdline: >%s<, entry = %d\n", gfx_data->cmdline, selected_entry);
1286
1287
  if(selected_entry < 0 || selected_entry > num_entries) return;
1288
1289
  /* for 'savedefault' */
1290
  current_entryno = selected_entry;
1291
1292
1293
  /* create new config with modified kernel option */
1294
1295
  cfg = get_entry(config_entries, selected_entry, 1);
1296
1297
  new_config = heap;
1298
1299
  for(p = gfx_data->cmdline, i = 0; ; i++) {
1300
    s = get_entry(cfg, i, 0);
1301
    if(!*s) {
1302
      if(!i) *heap++ = 0;
1303
      *heap++ = 0;
1304
      break;
1305
    }
1306
    /* note: must match get_kernel_args() */
1307
    if(
1308
      (!memcmp(s, "kernel", 6) || !memcmp(s, "module", 6)) &&
1309
      (s[6] == ' ' || s[6] == '\t')
1310
    ) {
1311
      t = skip_to(0, s);
1312
      t2 = s[0] == 'm' ? strstr(t, "initrd") : NULL;
1313
      if(*t) t = skip_to(0, t);
1314
      if(t2 && t2 < t) {	/* module is likely a normal initrd -> skip */
1315
        strcpy(heap, s);
1316
        heap += strlen(s) + 1;
1317
        continue;
1318
      }
1319
      memmove(heap, s, t - s);
1320
      heap += t - s;
1321
      *heap++ = ' ';
1322
      while(*p && *p != GFX_CMD_SEP) *heap++ = *p++;
1323
      *heap++ = 0;
1324
      if(*p == GFX_CMD_SEP) p++;
1325
    }
1326
    else {
1327
      strcpy(heap, s);
1328
      heap += strlen(s) + 1;
1329
    }
1330
  }
1331
1332
  *heap++ = 0;
1333
1334
  // hexdump(new_config, heap - new_config);
1335
  // getkey();
1336
1337
  run_script(new_config, heap);
1338
}
1339
1340
756
static int
1341
static int
757
get_line_from_config (char *cmdline, int maxlen, int read_from_file)
1342
get_line_from_config (char *cmdline, int maxlen, int read_from_file)
758
{
1343
{
Lines 827-832 get_line_from_config (char *cmdline, int maxlen, int read_from_file) Link Here
827
  return pos;
1412
  return pos;
828
}
1413
}
829
1414
1415
extern void __savedefault_once_reset();
1416
1417
char *wildcard_prefix, *wildcard_suffix;
1418
char wildcard_matches[1024], *end_wildcard_matches;
1419
1420
static void wildcard_handler(char *name);
1421
1422
/* Match one directory entry against the current wildcard. If the entry
1423
   matches, store it in WILDCARD_MATCHES. Silently ignore entries that
1424
   don't fit into WILDCARD_MATCHES anymore. */
1425
static void
1426
wildcard_handler(char *name)
1427
{
1428
  char *n = name, *p = wildcard_prefix;
1429
1430
  while (*p && *p == *n)
1431
    {
1432
      p++;
1433
      n++;
1434
    }
1435
  if (*p)
1436
    return; /* prefix mismatch */
1437
1438
  p = name + grub_strlen (name) - grub_strlen (wildcard_suffix);
1439
  /* [n .. p) is the part matching the asterisk */
1440
1441
  if (p < n || grub_strcmp (p, wildcard_suffix) != 0)
1442
    return; /* suffix mismatch */
1443
1444
  /* store this match */
1445
  if (p - n + 1 > sizeof (wildcard_matches) -
1446
		  (end_wildcard_matches - wildcard_matches))
1447
    return; /* out of space */
1448
  while (n < p)
1449
    *end_wildcard_matches++ = *n++;
1450
  *end_wildcard_matches++ = 0;
1451
}
1452
1453
/* Wildcard expand the GLOB argument. Return NULL upon failure, or
1454
   a list of 0-terminated expansions, terminated by a zero-length string. */
1455
char *
1456
wildcard (char *glob, int *len)
1457
{
1458
  char path[128], *p;
1459
  int ret;
1460
1461
  end_wildcard_matches = wildcard_matches;
1462
  if (grub_strlen (glob) + 1 > sizeof (path)) {
1463
    errnum = ERR_FILELENGTH;
1464
    return NULL;  /* cannot handle pathnames this long */
1465
  }
1466
  grub_strcpy (path, glob);
1467
  p = path;
1468
  while (*p)
1469
    p++;
1470
  wildcard_suffix = p;
1471
  while (p > path && *p != '/')
1472
    p--;
1473
  if (*p != '/')
1474
    {
1475
      errnum = ERR_BAD_FILETYPE;
1476
      return NULL; /* Cannot wildcard device names */
1477
    }
1478
  *(++p) = 0;
1479
  wildcard_prefix = glob + (p - path);
1480
  for (p = wildcard_prefix;; p++)
1481
    {
1482
      if (*p == 0)
1483
	{
1484
	  /* We cannot do exact matches: this cannot be represented in the
1485
	     result list. */
1486
	  return NULL;
1487
	}
1488
      else if (*p == '*')
1489
	{
1490
	  *p++ = 0;
1491
	  wildcard_suffix = p;
1492
	  break;
1493
	}
1494
    }
1495
1496
  ret = dir (path, wildcard_handler);
1497
  /* restore original argument */
1498
  wildcard_prefix[grub_strlen (wildcard_prefix)] = '*';
1499
  if (!ret)
1500
    return NULL;
1501
  *len = end_wildcard_matches - wildcard_matches;
1502
  return wildcard_matches;
1503
}
1504
1505
#define skip(str) ((str) + grub_strlen (str) + 1)
1506
1507
static void inplace_sort (char *str, int len);
1508
1509
static void
1510
inplace_sort (char *str, int len)
1511
{
1512
  int m, n = 0;
1513
  char *s, *t;
1514
1515
  /* we use x as temporary storage */
1516
  char *x = str + len;
1517
1518
  for (s = str; s < x; s = skip (s))
1519
    n++;
1520
1521
  for (; n >= 2; n--)
1522
    {
1523
      s = str;
1524
      t = skip (s);
1525
1526
      for (m = n; m >= 2; m--)
1527
	{
1528
	  if (grub_strcmp (s, t) > 0)
1529
	    {
1530
	      int ls = skip (s) - s;
1531
	      int lt = skip (t) - t;
1532
1533
	      memcpy (x, s, ls);
1534
	      grub_memmove (s + ls, s + lt, t - (s + ls));
1535
	      memcpy (s, t, lt);
1536
	      t = t + lt - ls;
1537
	      memcpy (t, x, ls);
1538
	    }
1539
	  s = t;
1540
	  t = skip (t);
1541
	}
1542
    }
1543
}
1544
1545
#undef skip
1546
1547
static int this_config_len (const char *config);
1548
static int
1549
this_config_len (const char *config)
1550
{
1551
  const char *c = config;
1552
  while (*c)
1553
    {
1554
      while (*c)
1555
	c++;
1556
      c++;
1557
    }
1558
  c++;
1559
  return c - config;
1560
}
1561
1562
static const char * expand_asterisks (const char *str, int *len,
1563
				      const char *subst);
1564
1565
/* Expand all asterisks (*) in a menu entry or commands section with its
1566
   substitution. Use a backslash as escape character. */
1567
static const char *
1568
expand_asterisks (const char *str, int *len, const char *subst)
1569
{
1570
  static char buffer[1024];
1571
  char *b = buffer, escaped = 0;
1572
  const char *end = str + *len;
1573
1574
  while (str < end)
1575
    {
1576
      if (*str == '*' && !escaped)
1577
        {
1578
	  if (b - buffer + grub_strlen (subst) > sizeof (buffer))
1579
	    {
1580
	      errnum = ERR_FILELENGTH;
1581
	      return NULL;
1582
	    }
1583
	  grub_strcpy (b, subst);
1584
	  b += grub_strlen (subst);
1585
	}
1586
      else if (*str == '\\' && !escaped)
1587
	escaped = 1;
1588
      else
1589
        {
1590
	  escaped = 0;
1591
	  if (b - buffer + 1 > sizeof (buffer))
1592
	    {
1593
	      errnum = ERR_FILELENGTH;
1594
	      return NULL;
1595
	    }
1596
	  *b++ = *str;
1597
	}
1598
      str++;
1599
    }
1600
    *len = b - buffer;
1601
1602
    return buffer;
1603
}
830
1604
831
/* This is the starting function in C.  */
1605
/* This is the starting function in C.  */
832
void
1606
void
Lines 848-853 cmain (void) Link Here
848
      init_config ();
1622
      init_config ();
849
    }
1623
    }
850
  
1624
  
1625
  auto void expand_wildcard_entries (void);
1626
  void expand_wildcard_entries (void)
1627
    {
1628
      char *config_entry = config_entries;
1629
      char *menu_entry = menu_entries;
1630
1631
      while (*menu_entry)
1632
        {
1633
	  char *command = config_entry;
1634
1635
	  do
1636
	    {
1637
	      char *c = command;
1638
	      const char *w = "wildcard";
1639
1640
	      while (*w && *c == *w)
1641
		{
1642
		  c++;
1643
		  w++;
1644
		}
1645
	      if (*w == 0 && (*c == ' ' || *c == '\t' || *c == '='))
1646
		{
1647
		  int len, wlen;
1648
1649
		  /* This is a wildcard command. Advance to the argument. */
1650
		  while (*c == ' ' || *c == '\t' || *c == '=')
1651
		    c++;
1652
1653
		  /* Expand wildcard entry. */
1654
		  w = wildcard (c, &wlen);
1655
		  if (w)
1656
		    inplace_sort (w, wlen);
1657
1658
		  /* Remove the wildcard command from the command section;
1659
		     it has no meaning beyond the wildcard expansion just
1660
		     performed. */
1661
		  len = grub_strlen (command) + 1;
1662
		  grub_memmove (command, command + len,
1663
		  		config_len - (command - config_entries));
1664
		  config_len -= len;
1665
1666
		  while (w && wlen)
1667
		    {
1668
		      /* Insert expansion before the wildcard entry in the
1669
		         list of entry names. */
1670
		      len = grub_strlen (menu_entry) + 1;
1671
		      const char *x = expand_asterisks (menu_entry, &len, w);
1672
		      grub_memmove (menu_entry + len, menu_entry,
1673
		      		    menu_len - (menu_entry - menu_entries));
1674
		      memcpy (menu_entry, x, len);
1675
		      menu_entry += len;
1676
		      menu_len += len;
1677
		      
1678
		      /* Insert expansion before the wildcard command section
1679
		         in the list of command sections. */
1680
		      len = this_config_len (config_entry);
1681
		      x = expand_asterisks (config_entry, &len, w);
1682
		      grub_memmove (config_entry + len, config_entry,
1683
		      		    config_len - (config_entry -
1684
				    		  config_entries));
1685
		      memcpy (config_entry, x, len);
1686
		      config_entry += len;
1687
		      config_len += len;
1688
1689
		      num_entries++;
1690
		      wlen -= grub_strlen (w) + 1;
1691
		      w += grub_strlen (w) + 1;
1692
		    }
1693
1694
		  /* Remove the wildcard command section; it has just
1695
		     been expanded. */
1696
		  len = grub_strlen (menu_entry) + 1;
1697
		  grub_memmove (menu_entry, menu_entry + len,
1698
		  		menu_len - (menu_entry - menu_entries));
1699
		  menu_len -= len;
1700
1701
		  len = this_config_len(config_entry);
1702
		  grub_memmove (config_entry, config_entry + len,
1703
		  		config_len - (config_entry - config_entries));
1704
		  config_len -= len;
1705
1706
		  num_entries--;
1707
		}
1708
	      command += grub_strlen (command) + 1;
1709
	    }
1710
	  while (*command);
1711
	  menu_entry += grub_strlen (menu_entry) + 1;
1712
	  config_entry += this_config_len(config_entry);
1713
	}
1714
    }
1715
851
  /* Initialize the environment for restarting Stage 2.  */
1716
  /* Initialize the environment for restarting Stage 2.  */
852
  grub_setjmp (restart_env);
1717
  grub_setjmp (restart_env);
853
  
1718
  
Lines 999-1006 cmain (void) Link Here
999
		  config_len = prev_config_len;
1864
		  config_len = prev_config_len;
1000
		}
1865
		}
1001
	      
1866
	      
1867
	      if (is_preset)
1868
		close_preset_menu ();
1869
	      else
1870
		grub_close ();
1871
	      
1002
	      menu_entries[menu_len++] = 0;
1872
	      menu_entries[menu_len++] = 0;
1003
	      config_entries[config_len++] = 0;
1873
	      config_entries[config_len++] = 0;
1874
1875
	      expand_wildcard_entries();
1876
1004
	      grub_memmove (config_entries + config_len, menu_entries,
1877
	      grub_memmove (config_entries + config_len, menu_entries,
1005
			    menu_len);
1878
			    menu_len);
1006
	      menu_entries = config_entries + config_len;
1879
	      menu_entries = config_entries + config_len;
Lines 1042-1055 cmain (void) Link Here
1042
		    default_entry = 0;
1915
		    default_entry = 0;
1043
		}
1916
		}
1044
	      
1917
	      
1045
	      if (is_preset)
1046
		close_preset_menu ();
1047
	      else
1048
		grub_close ();
1049
	    }
1918
	    }
1050
	  while (is_preset);
1919
	  while (is_preset);
1051
	}
1920
	}
1052
1921
#ifndef SUPPORT_DISKLESS
1922
      __savedefault_once_reset();
1923
#endif
1053
      if (! num_entries)
1924
      if (! num_entries)
1054
	{
1925
	{
1055
	  /* If no acceptable config file, goto command-line, starting
1926
	  /* If no acceptable config file, goto command-line, starting
Lines 1059-1067 cmain (void) Link Here
1059
	}
1930
	}
1060
      else
1931
      else
1061
	{
1932
	{
1062
	  /* Run menu interface.  */
1933
	  if (*graphics_file && !password && show_menu && grub_timeout)
1063
	  run_menu (menu_entries, config_entries, num_entries,
1934
	    {
1064
		    menu_entries + menu_len, default_entry);
1935
	      run_graphics_menu(menu_entries, config_entries, num_entries,menu_entries + menu_len, default_entry);
1936
	    }
1937
	    /* Run menu interface.  */
1938
            run_menu (menu_entries, config_entries, num_entries, menu_entries + menu_len, default_entry);
1065
	}
1939
	}
1066
    }
1940
    }
1067
}
1941
}
(-)a/util/grub-install.in (-52 / +226 lines)
Lines 27-41 VERSION=@VERSION@ Link Here
27
host_cpu=@host_cpu@
27
host_cpu=@host_cpu@
28
host_os=@host_os@
28
host_os=@host_os@
29
host_vendor=@host_vendor@
29
host_vendor=@host_vendor@
30
pkglibdir=${libdir}/${PACKAGE}/${host_cpu}-${host_vendor}
30
pkglibdir=${libdir}/${PACKAGE}/
31
31
32
grub_shell=${sbindir}/grub
32
grub_shell=${sbindir}/grub
33
mdadm=${sbindir}/mdadm
33
grub_set_default=${sbindir}/grub-set-default
34
grub_set_default=${sbindir}/grub-set-default
34
log_file=/tmp/grub-install.log.$$
35
log_file=/tmp/grub-install.log.$$
35
img_file=/tmp/grub-install.img.$$
36
img_file=/tmp/grub-install.img.$$
36
rootdir=
37
rootdir=
37
grub_prefix=/boot/grub
38
grub_prefix=/boot/grub
38
39
40
install_drives=
39
install_device=
41
install_device=
40
no_floppy=
42
no_floppy=
41
force_lba=
43
force_lba=
Lines 70-75 Install GRUB on your drive. Link Here
70
  --force-lba             force GRUB to use LBA mode even for a buggy
72
  --force-lba             force GRUB to use LBA mode even for a buggy
71
                          BIOS
73
                          BIOS
72
  --recheck               probe a device map even if it already exists
74
  --recheck               probe a device map even if it already exists
75
                          This flag is unreliable and its use is
76
                          strongly discouraged.
73
77
74
INSTALL_DEVICE can be a GRUB device name or a system device filename.
78
INSTALL_DEVICE can be a GRUB device name or a system device filename.
75
79
Lines 96-112 convert () { Link Here
96
    # Break the device name into the disk part and the partition part.
100
    # Break the device name into the disk part and the partition part.
97
    case "$host_os" in
101
    case "$host_os" in
98
    linux*)
102
    linux*)
99
	tmp_disk=`echo "$1" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
103
	tmp_disk=`echo "$1" | grep -v '/mapper/control$' |
104
		grep -v '/mapper/[[:alnum:]]\+-[[:alnum:]]\+$' | uniq |
105
		sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
100
				  -e 's%\(d[0-9]*\)p[0-9]*$%\1%' \
106
				  -e 's%\(d[0-9]*\)p[0-9]*$%\1%' \
101
				  -e 's%\(fd[0-9]*\)$%\1%' \
107
				  -e 's%\(fd[0-9]*\)$%\1%' \
102
				  -e 's%/part[0-9]*$%/disc%' \
108
				  -e 's%/part[0-9]*$%/disc%' \
103
				  -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
109
				  -e 's%\(c[0-7]d[0-9]*\).*$%\1%' \
104
	tmp_part=`echo "$1" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
110
	  -e 's%\(/mapper/[[:alpha:]]\+[[:digit:]]\+\)p[[:digit:]]\+$%\1%' \
111
	  -e 's%\(/mapper/[[:alpha:]]\+_[[:alpha:]]\+\)[[:digit:]]\+$%\1%'`
112
	tmp_part=`echo "$1" | grep -v '/mapper/control$' |
113
		grep -v '/mapper/[[:alnum:]]\+-[[:alnum:]]\+$' | uniq |
114
		sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
105
				  -e 's%.*d[0-9]*p%%' \
115
				  -e 's%.*d[0-9]*p%%' \
106
				  -e 's%.*/fd[0-9]*$%%' \
116
				  -e 's%.*/fd[0-9]*$%%' \
107
				  -e 's%.*/floppy/[0-9]*$%%' \
117
				  -e 's%.*/floppy/[0-9]*$%%' \
108
				  -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
118
				  -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
109
				  -e 's%.*c[0-7]d[0-9]*p%%'`
119
				  -e 's%.*c[0-7]d[0-9]*p%%' \
120
	  -e 's%.*/mapper/[[:alpha:]]\+[[:digit:]]\+p\([[:digit:]]\+\)$%\1%' \
121
	  -e 's%.*/mapper/[[:alpha:]]\+_[[:alpha:]]\+\([[:digit:]]\+\)$%\1%' |
122
		grep -v '.*/mapper/.*'`
110
	;;
123
	;;
111
    gnu*)
124
    gnu*)
112
	tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
125
	tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
Lines 211-233 resolve_symlink () { Link Here
211
	echo "$tmp_fname"
224
	echo "$tmp_fname"
212
}
225
}
213
226
227
# Usage: is_raid1_device devicename
228
# Returns 0 if devicename is a raid1 md device, 1 if it is not.
229
is_raid1_device () {
230
    case "$host_os" in
231
    linux*)
232
	level=`$mdadm --query --detail $1 2>/dev/null | \
233
		awk '/Raid Level :/ {print $4}'` 
234
	if [ "$level" = "raid1" ]; then
235
	    return 0
236
	fi
237
    ;;
238
    esac
239
    return 1
240
}
241
242
# Usage: find_real_devs device
243
# Returns space separated list of devices for linux if device is 
244
# a raid1 device. In all other cases, the provided value is returned.
245
find_real_devs () {
246
    source_device=$1
247
    case "$host_os" in
248
    linux*)
249
	if is_raid1_device $source_device ; then
250
	    list=""
251
	    for device in `$mdadm --query --detail "${source_device}" | \
252
		    awk '/\/dev\/[^(md)]/ {print $7}'` ; do
253
		list="$list $device"
254
	    done
255
	    echo $list
256
	    return 0
257
	fi
258
    ;;
259
    esac
260
    echo $source_device
261
    return 0
262
}
263
264
# Usage: stat_device file
265
# Find major:minor of a device node.
266
stat_device() {
267
    majmin=`stat -c "%t:%T" "$1" 2>/dev/null`
268
    if test -z "$majmin"; then
269
	echo "Could not find device for $1" 2>&1
270
	exit 1
271
    fi
272
273
    echo "$majmin"
274
}
275
276
# Usage: find_mapper_device file
277
# Find a file in /dev/mapper with the same major:minor as the specified node.
278
find_mapper_device() {
279
    if [ -b "$1" ]; then
280
	dev="$1"
281
    else
282
	mntpnt=`echo "$1" | sed 's,/,\\\\/,g'`
283
	dev=`awk '($2 ~ /'$mntpnt'/) { print $1 }' /etc/mtab`
284
    fi
285
    if test -z "$dev"; then
286
	echo "Could not find device for $1" 2>&1
287
	exit 1
288
    fi
289
	
290
    majmin=`stat_device $dev`
291
    for x in /dev/mapper/* ; do
292
	devmajmin=`stat_device "$x"`
293
	if [ "$majmin" == "$devmajmin" ]; then
294
	    echo "$x"
295
	    return 0
296
	fi
297
    done
298
    return 1
299
}
300
214
# Usage: find_device file
301
# Usage: find_device file
215
# Find block device on which the file resides.
302
# Find block device on which the file resides.
216
find_device () {
303
find_device () {
217
    # For now, this uses the program `df' to get the device name, but is
304
    # For now, this uses the program `df' to get the device name, but is
218
    # this really portable?
305
    # this really portable?
219
    tmp_fname=`df $1/ | sed -n 's%.*\(/dev/[^ 	]*\).*%\1%p'`
306
    tmp_fname=`df $1/ | awk '/\/dev\/|LABEL=|UUID=/{ print $1 }'`
307
308
    if echo "$tmp_fname" | grep -q LABEL= ; then
309
	label=`echo "$tmp_fname" | sed -e s/.*=//`
310
	tmp_fname=`readlink -f /dev/disk/by-label/$label`
311
    fi	
312
    if echo "$tmp_fname" | grep -q UUID= ; then
313
	uuid=`echo "$tmp_fname" | sed -e s/.*=//`
314
	tmp_fname=`readlink -f /dev/disk/by-uuid/$uuid`
315
    fi
220
316
221
    if test -z "$tmp_fname"; then
317
    if test -z "$tmp_fname"; then
222
	echo "Could not find device for $1" 2>&1
318
	echo "Could not find device for $1" 2>&1
223
	exit 1
319
	exit 1
224
    fi
320
    fi
225
321
226
	tmp_fname=`resolve_symlink $tmp_fname`
322
    ret_fname=`resolve_symlink $tmp_fname`
323
    tmp_fname=`find_mapper_device $ret_fname`
324
    if test -n "$tmp_fname"; then
325
	ret_fname="$tmp_fname"
326
    fi
227
327
228
    echo "$tmp_fname"
328
    echo "$ret_fname"
329
    return 0
229
}
330
}
230
331
332
333
dump_boot_block () {
334
    sync
335
    $grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
336
dump ${root_drive}${tmp} ${img_file}
337
quit
338
EOF
339
}
340
341
342
install_boot_block () {
343
    # Before all invocations of the grub shell, call sync to make sure
344
    # the raw device is in sync with any bufferring in filesystems.
345
    sync
346
347
    # Now perform the installation.
348
    $grub_shell --batch $no_floppy --device-map=$device_map <<EOF >>$log_file
349
root $1
350
setup $force_lba --stage2=$grubdir/stage2 --prefix=$grub_prefix $2
351
quit
352
EOF
353
}
354
355
231
# Check the arguments.
356
# Check the arguments.
232
for option in "$@"; do
357
for option in "$@"; do
233
    case "$option" in
358
    case "$option" in
Lines 293-298 esac Link Here
293
grubdir=${bootdir}/grub
418
grubdir=${bootdir}/grub
294
device_map=${grubdir}/device.map
419
device_map=${grubdir}/device.map
295
420
421
if [ "$recheck" == "yes" ]; then
422
    if grep 'mapper' ${device_map} >/dev/null; then
423
	echo 'grub-install does not support reprobing of device.map when' 1>&2
424
	echo 'using a device-mapper based boot device.' 1>&2
425
	exit 1
426
    fi
427
fi
428
296
# Check if GRUB is installed.
429
# Check if GRUB is installed.
297
# This is necessary, because the user can specify "grub --read-only".
430
# This is necessary, because the user can specify "grub --read-only".
298
set $grub_shell dummy
431
set $grub_shell dummy
Lines 326-332 test -d "$grubdir" || mkdir "$grubdir" || exit 1 Link Here
326
459
327
# If --recheck is specified, remove the device map, if present.
460
# If --recheck is specified, remove the device map, if present.
328
if test $recheck = yes; then
461
if test $recheck = yes; then
329
    rm -f $device_map
462
    mv $device_map ${device_map}.backup
330
fi
463
fi
331
464
332
# Create the device map file if it is not present.
465
# Create the device map file if it is not present.
Lines 336-341 else Link Here
336
    # Create a safe temporary file.
469
    # Create a safe temporary file.
337
    test -n "$mklog" && log_file=`$mklog`
470
    test -n "$mklog" && log_file=`$mklog`
338
471
472
    # Before all invocations of the grub shell, call sync to make sure
473
    # the raw device is in sync with any bufferring in filesystems.
474
    sync
475
 
339
    $grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
476
    $grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
340
quit
477
quit
341
EOF
478
EOF
Lines 351-357 fi Link Here
351
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
488
tmp=`sed -n '/^([fh]d[0-9]*)/s/\(^(.*)\).*/\1/p' $device_map \
352
    | sort | uniq -d | sed -n 1p`
489
    | sort | uniq -d | sed -n 1p`
353
if test -n "$tmp"; then
490
if test -n "$tmp"; then
354
    echo "The drive $tmp is defined multiple times in the device map $device_map" 1>&2
491
    echo "The drive $tmp is defined multiple times in the new device map." 1>&2
492
    if test $recheck = yes; then
493
        echo "Reverting to backed up copy." 1>&2
494
        mv ${device_map}.backup $device_map
495
    fi
496
    exit 1
497
fi
498
499
# Make sure device.map has at least one hd device
500
grep -q "^(hd[0-9]\+)" $device_map
501
if [ "x$?" != "x0" ]; then
502
    echo "No suitable drive was found in the generated device map." 1>&2
503
    if test $recheck = yes; then
504
        echo "Reverting to backed up copy." 1>&2
505
        mv ${device_map}.backup $device_map
506
    fi
355
    exit 1
507
    exit 1
356
fi
508
fi
357
509
Lines 359-381 fi Link Here
359
case "$install_device" in
511
case "$install_device" in
360
/dev/*)
512
/dev/*)
361
    install_device=`resolve_symlink "$install_device"`
513
    install_device=`resolve_symlink "$install_device"`
362
    install_drive=`convert "$install_device"`
514
    for install_drive in `find_real_devs $install_device` ; do
363
    # I don't know why, but some shells wouldn't die if exit is
515
	install_drive=`convert $install_drive`
364
    # called in a function.
516
	if is_raid1_device $install_device; then
365
    if test "x$install_drive" = x; then
517
		install_drive=`echo $install_drive | sed 's/,[0-9]*)/)/'`
518
	fi
519
	if [ "x$install_drive" = "x" ]; then
520
	    exit 1
521
	fi
522
	install_drives="${install_drives} ${install_drive}"
523
    done
524
    unset install_drive
525
	
526
    if test "x$install_drives" = x ; then
366
	exit 1
527
	exit 1
367
    fi ;;
528
    fi ;;
368
\([hf]d[0-9]*\))
529
\([hf]d[0-9]*\))
369
    install_drive="$install_device" ;;
530
    install_drives="$install_device" ;;
370
[hf]d[0-9]*)
531
[hf]d[0-9]*)
371
    # The GRUB format with no parenthesis.
532
    # The GRUB format with no parenthesis.
372
    install_drive="($install_device)" ;;
533
    install_drives="($install_device)" ;;
373
*)
534
*)
374
    echo "Format of install_device not recognized." 1>&2
535
    echo "Format of install_device not recognized." 1>&2
375
    usage
536
    usage
376
    exit 1 ;;
537
    exit 1 ;;
377
esac
538
esac
378
539
540
unset install_device
541
379
# Get the root drive.
542
# Get the root drive.
380
root_device=`find_device ${rootdir}`
543
root_device=`find_device ${rootdir}`
381
bootdir_device=`find_device ${bootdir}`
544
bootdir_device=`find_device ${bootdir}`
Lines 387-400 if test "x$root_device" != "x$bootdir_device"; then Link Here
387
    grub_prefix="/grub"
550
    grub_prefix="/grub"
388
fi
551
fi
389
552
390
# Convert the root device to a GRUB drive.
553
# Check if the root directory exists in the same device as the grub directory.
391
root_drive=`convert "$root_device"`
392
if test "x$root_drive" = x; then
393
    exit 1
394
fi
395
396
# Check if the root directory exists in the same device as the grub
397
# directory.
398
grubdir_device=`find_device ${grubdir}`
554
grubdir_device=`find_device ${grubdir}`
399
555
400
if test "x$grubdir_device" != "x$root_device"; then
556
if test "x$grubdir_device" != "x$root_device"; then
Lines 406-419 EOF Link Here
406
    exit 1
562
    exit 1
407
fi
563
fi
408
564
409
# Copy the GRUB images to the GRUB directory.
565
# FHS says that /usr/share is used for architecture independent data,
410
for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
566
# so all stage-files are directly installed to /usr/lib/grub.
411
    rm -f $file || exit 1
567
# Therefor this part is no longer needed.
412
done
568
# <--cut_here--> 
413
for file in \
569
## Copy the GRUB images to the GRUB directory.
414
    ${pkglibdir}/stage1 ${pkglibdir}/stage2 ${pkglibdir}/*stage1_5; do
570
#for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
415
    cp -f $file ${grubdir} || exit 1
571
#    rm -f $file || exit 1
416
done
572
#done
573
#for file in \
574
#    ${pkglibdir}/stage1 ${pkglibdir}/stage2 ${pkglibdir}/*stage1_5; do
575
#    cp -f $file ${grubdir} || exit 1
576
#done
577
# <--uncut-->
417
578
418
# Make a default file.
579
# Make a default file.
419
${grub_set_default} --root-directory=${rootdir} default
580
${grub_set_default} --root-directory=${rootdir} default
Lines 422-446 ${grub_set_default} --root-directory=${rootdir} default Link Here
422
test -n "$mkimg" && img_file=`$mkimg`
583
test -n "$mkimg" && img_file=`$mkimg`
423
test -n "$mklog" && log_file=`$mklog`
584
test -n "$mklog" && log_file=`$mklog`
424
585
586
# There's not a real root device, so just pick the first
587
if is_raid1_device $root_device ; then
588
    root_device=`find_real_devs $root_device | awk '{print $1}'`
589
fi
590
591
# Convert the root deviceto a GRUB drive.
592
root_drive=`convert "$root_device"`
593
if [ "x$root_drive" = x ]; then
594
    exit 1
595
fi
596
425
for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
597
for file in ${grubdir}/stage1 ${grubdir}/stage2 ${grubdir}/*stage1_5; do
426
    count=5
598
    count=5
427
    tmp=`echo $file | sed "s|^${grubdir}|${grub_prefix}|"`
599
    tmp=`echo $file | sed "s|^${grubdir}|${grub_prefix}|"`
428
    while test $count -gt 0; do
600
    while test $count -gt 0; do
429
	$grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
601
        dump_boot_block $root_drive $img_file
430
dump ${root_drive}${tmp} ${img_file}
602
        if grep "Error [0-9]*: " $log_file >/dev/null; then
431
quit
603
    	:
432
EOF
604
        elif cmp $file $img_file >/dev/null; then
433
	if grep "Error [0-9]*: " $log_file >/dev/null; then
605
    	break
434
	    :
606
        fi
435
	elif cmp $file $img_file >/dev/null; then
607
        sleep 1
436
	    break
608
        count=`expr $count - 1`    
437
	fi
438
	sleep 1
439
	count=`expr $count - 1`    
440
    done
609
    done
441
    if test $count -eq 0; then
610
    if test $count -eq 0; then
442
	echo "The file $file not read correctly." 1>&2
611
        echo "The file $file not read correctly." 1>&2
443
	exit 1
612
        exit 1
444
    fi
613
    fi
445
done
614
done
446
615
Lines 450-466 rm -f $log_file Link Here
450
# Create a safe temporary file.
619
# Create a safe temporary file.
451
test -n "$mklog" && log_file=`$mklog`
620
test -n "$mklog" && log_file=`$mklog`
452
621
453
# Now perform the installation.
622
for install_drive in $install_drives; do 
454
$grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
623
    # Convert the root deviceto a GRUB drive.
455
root $root_drive
624
    root_drive=`convert "$root_device"`
456
setup $force_lba --stage2=$grubdir/stage2 --prefix=$grub_prefix $install_drive
625
    if [ "x$root_drive" = x ]; then
457
quit
626
	exit 1
458
EOF
627
    fi
628
    install_boot_block $root_drive $install_drive
629
done
459
630
460
if grep "Error [0-9]*: " $log_file >/dev/null || test $debug = yes; then
631
if grep "Error [0-9]*: " $log_file >/dev/null ; then
461
    cat $log_file 1>&2
632
    cat $log_file 1>&2
462
    exit 1
633
    exit 1
463
fi
634
fi
635
if test $debug = yes; then
636
    cat $log_file 1>&2
637
fi
464
638
465
rm -f $log_file
639
rm -f $log_file
466
640
(-)a/util/grub-md5-crypt.in (-1 / +1 lines)
Lines 88-94 if test "x$password" != "x$password2"; then Link Here
88
fi
88
fi
89
89
90
# Run the grub shell.
90
# Run the grub shell.
91
$grub_shell --batch --device-map=/dev/null <<EOF \
91
$grub_shell --batch <<EOF \
92
    | grep "^Encrypted: " | sed 's/^Encrypted: //'
92
    | grep "^Encrypted: " | sed 's/^Encrypted: //'
93
md5crypt
93
md5crypt
94
$password
94
$password
(-)a/util/mbchk.c (-1 / +3 lines)
Lines 59-65 check_multiboot (const char *filename, FILE *fp) Link Here
59
  int i;
59
  int i;
60
  char buf[8192];
60
  char buf[8192];
61
61
62
  if (fread (buf, 1, 8192, fp) < 0)
62
  fread (buf, 1, 8192, fp);
63
  
64
  if (ferror(fp))
63
    {
65
    {
64
      fprintf (stderr, "%s: Read error.\n", filename);
66
      fprintf (stderr, "%s: Read error.\n", filename);
65
      return 0;
67
      return 0;

Return to bug 14795