Indented and started off the long journey to becoming an Automakified GNU package.

This commit is contained in:
gord 1999-02-28 18:37:50 +00:00
parent 8b2e640b8c
commit 5cf05b32d2
37 changed files with 2704 additions and 2622 deletions

9
AUTHORS Normal file
View file

@ -0,0 +1,9 @@
Erich Boleyn originally designed and implemented GRUB.
VaX#n8 (real name unknown) wrote shared_src/fsys_ext2fs.c.
Heiko Schroeder rewrote shared_src/stage1.S to be more readable.
Gordon Matzigkeit adopted GRUB into the GNU Project. He fixed several
bugs, added symbolic link support to shared_src/fsys_ext2fs.c, and
implemented the grub configuration program.

View file

@ -1,3 +1,14 @@
1999-02-28 Gordon Matzigkeit <gord@trick.fig.org>
* AUTHORS, INSTALL: New files.
1999-02-24 Gordon Matzigkeit <gord@trick.fig.org>
* stage1/stage1.S (after_BPB): Do a hard disk probe first, so that
we can work with IDE floppies (like the LS-120).
* Run GNU Indent on */*.[ch].
1999-02-21 Gordon Matzigkeit <gord@trick.fig.org>
* debian: Add to the distribution, since we maintain the GRUB

43
INSTALL Normal file
View file

@ -0,0 +1,43 @@
Soon, we hope that GRUB will fully support GNU-standard installation,
and simple runtime configuration, but until then, here are the old
instructions for installing GRUB:
Instructions for installing can be found in "docs/install.html".
Building From Source
To build GRUB from source, first run the bourne-shell script "configure"
(options can be found by running "./configure --help"). It will complain
of missing or bad tools determined by it's tests. If it completes
successfully, then just type "make".
Note that the binary names correspond to subdirectories in the top level
of the distribution. See the makefiles in there for details on where
the source files are drawn from, but in general, the "stage1" only uses
the "stage1.S" file, and the others use source files from the "shared_src"
subdirectory.
IMPORTANT SIZE LIMITS:
- For the various stage2's, if they are being loaded from a block-list
in the stage1, then be sure your blocklist is big enough. The
automated install will generally do this for you, it's just when
dropping it on a raw floppy, you get the default compiled in, which
is 512 * 80 disk sectors, or 40960 bytes.
- For the FFS stage1.5, if you want to fit into the "bootloader" area
of an FFS partition, it cannot be larger than 512 * 14 disk sectors,
or 7168 bytes.
Other Documentation
Pretty much all of the documentation and other helpful information is
in the "docs" directory mostly as HTML files, the root of which is
"index.html".
The FAQ and Installation instructions really need to be updated and
improved!
The TODO and NEWS files are always up-to-date.

89
README
View file

@ -1,76 +1,23 @@
This is GRUB, the GRand Unified Boot-loader. Note that this version
is maintained by Gordon Matzigkeit <gord@debian.org>, until Erich
Boleyn has a chance to catch up with all the patches needed for
Debian. Please do not bother Erich about this release, because he
hasn't approved of it.
This is GNU GRUB, the GRand Unified Bootloader. GRUB is intended to
provide important bootloader features that are missing from typical
personal computer BIOSes:
Here is the original README:
- provides fully-featured command line and graphical interfaces
- recognizes fdisk partitions and BSD disklabels
- can dynamically read Linux ext2fs, BSD ufs, and MS-DOS FAT
filesystems, plus hardcoded blocklists
- can boot Multiboot-compliant kernels (such as GNU Mach), as well
as standard Linux and BSD kernels
See the file docs/NEWS for a description of recent changes to GRUB.
See the file INSTALL for instructions on how to build and install
GRUB.
GRUB -- GRand Unified Boot-loader
If you have any suggestions or bug reports, please send electronic
mail to the GRUB mailing list <bug-grub@gnu.org>.
version 0.5
by Erich Boleyn <erich@uruk.org>
Introduction
This is the public release of GRUB version 0.5, a bootloader for
PC-compatible machines.
Installation
Precompiled versions are included in the "bin" directory:
bin/
stage1 This is the 512-byte stage1 which reads
in the rest of GRUB at boot-time.
ffs_stage1_5 This is an example for how to build a
"stage 1.5" to automatically load a stage2
from the filesystem.
stage2 This is the main part of GRUB.
stage2_debug Same as "stage2", but compiled with the
debug features enabled.
Instructions for installing can be found in "docs/install.html".
Building From Source
To build GRUB from source, first run the bourne-shell script "configure"
(options can be found by running "./configure --help"). It will complain
of missing or bad tools determined by it's tests. If it completes
successfully, then just type "make".
Note that the binary names correspond to subdirectories in the top level
of the distribution. See the makefiles in there for details on where
the source files are drawn from, but in general, the "stage1" only uses
the "stage1.S" file, and the others use source files from the "shared_src"
subdirectory.
IMPORTANT SIZE LIMITS:
- For the various stage2's, if they are being loaded from a block-list
in the stage1, then be sure your blocklist is big enough. The
automated install will generally do this for you, it's just when
dropping it on a raw floppy, you get the default compiled in, which
is 512 * 80 disk sectors, or 40960 bytes.
- For the FFS stage1.5, if you want to fit into the "bootloader" area
of an FFS partition, it cannot be larger than 512 * 14 disk sectors,
or 7168 bytes.
Other Documentation
Pretty much all of the documentation and other helpful information is
in the "docs" directory mostly as HTML files, the root of which is
"index.html".
The FAQ and Installation instructions really need to be updated and
improved!
The TODO and NEWS files are always up-to-date.
DEVELOPERS: to subscribe to the mailing list, send e-mail to
<bug-grub-request@gnu.org>. You can get the latest GRUB CVS tree from
`:pserver:anoncvs@anoncvs.gnu.org:/gd/gnu/anoncvsroot', module `grub'.
Just hit enter when CVS prompts you for a password.

View file

@ -1,9 +1,6 @@
Known problems/bugs:
- Try `d' to delete the selected line while editing a menu entry
(maybe only when deleting the last line). Everything goes to hell.
- FreeBSD boot command-line options are slightly problematic, and
OpenBSD options are probably quite wrong. This is because they
use options that are bits in a data word passed at boot time, and

View file

@ -1,8 +1,9 @@
NEWS - list of user-visible changes between releases of GRUB
New in 0.5.2 - 1999-01-31, Gordon Matzigkeit:
New in 0.6 - FIXME, Gordon Matzigkeit:
* Bug fixes.
*
* GRUB understands symlinks on ext2fs (but not ffs).
* Many source code and build cleanups to comply with GNU standards.
Version 0.5:

View file

@ -1,17 +1,25 @@
Treat `(hd)/boot/grub/menu.lst' as searching through the hard drives
for a partition that contains /boot/grub/menu.lst. Either this, or
`(hd:0x82)' means the first partition of type 0x82. We need one of
these dynamic search mechanisms for clean Hurd install floppies.
Get /sbin/grub to work.
Syntax:
Change partition syntax to correspond with BSD ``slice'' syntax
(`(hd0,1a)' -> `/dev/hd0s2a').
(hd0,0) -> hd0s1
(hd0,1,b) -> hd0s1b
(hd0) -> hd0
Add a partition naming syntax that means ``the first partition of this
type''. We need this for clean Hurd install floppies.
Find out the size restrictions for FAT and ext2fs stage1.5 boot blocks.
Find out the size restrictions for FAT and ext2fs stage1.5 boot
blocks. Enforce all arbitrary limits using the Makefiles.
Check for other patches sent in e-mail!!! There are several...
Look at network booting.
Add stripped-down Guile support, and rewrite current behaviour in
Scheme. Make sure not to break backward compatibilty, or else we'll
be roasted by anti-Guile people.
Add internationalization support, emulating gettext as much as is
feasible.
Maybe add BIOS password support. In any event, improve the existing
password support.
Add support/delays so that a floppy can be installed from
another floppy.
@ -25,7 +33,7 @@ Find out the size restrictions for FAT and ext2fs stage1.5 boot blocks.
Add indirect block support to the BSD FFS filesystem code, so files
larger than 16MB can be read.
??? Make symbolic links work for BSD FFS and Linux ext2fs filesystems.
??? Make symbolic links work for BSD FFS.
??? Add command for modifying partition types.

View file

@ -85,7 +85,7 @@ initial implementation for the ext2fs filesystem.<P>
<LI><B>Miles Bader (miles@gnu.ai.mit.edu)</B> -- for testing feedback.<P>
<LI><B>Eric Hanchrow (erich@microsoft.com)</B> -- for interstate remote
debugging by hand.<P>
<LI><B>Gord Matzigkeit (gord@enci.ucalgary.ca)</B> -- for lots of
<LI><B>Gord Matzigkeit (gord@fig.org)</B> -- for lots of
testing feedback.<P>
<LI><B>Heiko Schroeder (heiko@pool.informatik.rwth-aachen.de)</B> -- for
a re-writing stage1 to be much more readable, plus several patches.<P>
@ -117,4 +117,3 @@ Here are links to the <A HREF=NEWS>NEWS file</A>,
</BODY>
</HTML>

View file

@ -39,14 +39,14 @@ start_stage2 (void)
/* calls for direct boot-loader chaining */
void
chain_stage1(int segment, int offset, int part_table_addr)
chain_stage1 (int segment, int offset, int part_table_addr)
{
}
void
chain_stage2(int segment, int offset)
chain_stage2 (int segment, int offset)
{
}
@ -54,7 +54,7 @@ chain_stage2(int segment, int offset)
/* do some funky stuff, then boot linux */
void
linux_boot(void)
linux_boot (void)
{
}
@ -62,7 +62,7 @@ linux_boot(void)
/* For bzImage kernels. */
void
big_linux_boot(void)
big_linux_boot (void)
{
}
@ -70,7 +70,7 @@ big_linux_boot(void)
/* booting a multiboot executable */
void
multi_boot(int start, int mbi)
multi_boot (int start, int mbi)
{
}
@ -87,7 +87,7 @@ gateA20 (int linear)
int
get_memsize (int type)
{
if (! type)
if (!type)
return 640 * 1024; /* 640kB conventional */
else
return 4 * 1024 * 1024; /* 4MB extended */
@ -125,20 +125,20 @@ getrtsecs (void)
/* low-level character I/O */
void
cls(void)
cls (void)
{
}
/* returns packed values, LSB+1 is x, LSB is y */
int
getxy(void)
getxy (void)
{
}
void
gotoxy(int x, int y)
gotoxy (int x, int y)
{
}
@ -146,47 +146,47 @@ gotoxy(int x, int y)
/* displays an ASCII character. IBM displays will translate some
characters to special graphical ones */
void
putchar(int c)
putchar (int c)
{
}
/* returns packed BIOS/ASCII code */
int
asm_getkey(void)
asm_getkey (void)
{
}
/* like 'getkey', but doesn't wait, returns -1 if nothing available */
int
checkkey(void)
checkkey (void)
{
}
/* sets text mode character attribute at the cursor position */
void
set_attrib(int attr)
set_attrib (int attr)
{
}
/* low-level disk I/O */
int
get_diskinfo(int drive)
get_diskinfo (int drive)
{
}
int
biosdisk(int subfunc, int drive, int geometry,
biosdisk (int subfunc, int drive, int geometry,
int sector, int nsec, int segment)
{
}
void
stop_floppy(void)
stop_floppy (void)
{
}

198
mail
View file

@ -1,198 +0,0 @@
From nobody Mon Feb 1 15:36:44 1999
X-From-Line: debian-hurd-request@lists.debian.org Sat Jan 09 01:50:49 1999
Return-Path: <debian-hurd-request@lists.debian.org>
Delivered-To: gord@trick.fig.org
Received: (qmail 25241 invoked from network); 9 Jan 1999 01:50:48 -0000
Received: from gen2-93ip34.cadvision.com (HELO bambam.m-tech.ab.ca) (209.91.93.34)
by ip223.net247210.cr.sk.ca with SMTP; 9 Jan 1999 01:50:48 -0000
Received: from murphy.novare.net (gateway [10.0.0.1])
by bambam.m-tech.ab.ca (8.8.7/8.8.7) with SMTP id SAA19193
for <gord@m-tech.ab.ca>; Fri, 8 Jan 1999 18:47:34 -0700
Received: (qmail 13337 invoked by uid 38); 9 Jan 1999 01:47:33 -0000
Resent-Date: 9 Jan 1999 01:47:32 -0000
Resent-Cc: recipient list not shown: ;
X-Envelope-Sender: ege@rano.demon.co.uk
To: Matthias.Pfisterer@gmx.de
CC: debian-hurd@lists.debian.org
In-reply-to: <36966815.9DA7E110@rupert.informatik.uni-stuttgart.de> (message
from Matthias Pfisterer on Fri, 08 Jan 1999 21:18:29 +0100)
Subject: Re: Debian GNU/Hurd Base Set "gnu-19990104" available now!
From: edmundo@rano.demon.co.uk
Message-Id: <E0zymXI-0001PY-00@localhost>
Sender: Edmund GRIMLEY EVANS <ege@rano.demon.co.uk>
Date: Sat, 9 Jan 1999 00:45:52 +0000
Resent-Message-ID: <"nJdi8B.A.LQD.zUrl2"@murphy>
Resent-From: debian-hurd@lists.debian.org
X-Mailing-List: <debian-hurd@lists.debian.org> archive/latest/581
X-Loop: debian-hurd@lists.debian.org
Precedence: list
Resent-Sender: debian-hurd-request@lists.debian.org
Lines: 64
Xref: trick.fig.org list.debian-hurd:748
> Also, there seems to be a problem booting from internal LS-120 drives.
> Normal operating systems (Windows...) can boot from internal drives if
> the BIOS can handle it. GRUB hangs when I try to boot from an ordinary
> 3,5" disk inserted into the LS-120. I've tested GRUB 0.4, but not
> further explored this issue. It may be a problem of GRUB, but perhaps it
> is a problem of the chipset or the BIOS. I will give a detailed report
> once I've tested it with the newest version of GRUB.
I wrote about this problem earlier in debian-hurd (2 Dec).
I hacked my copy of GRUB so that it works from my internal LS-120. I'm
copying the relevant paragraphs again, below.
By the way, SYSLINUX boots off my LS-120 without problems: it applies
a different algorithm for deciding whether the device is a floppy or a
hard disc. Boot sectors can be quite amusing, really ...
Edmund
As I wrote before, the GRUB boot floppy provided with gnu-0.2.tar.gz
doesn't work off my LS120 IDE floppy. Neither does the 0.5 release of
GRUB, which I built from source. However, after many failed
experiments, I managed to modify grub-0.5's boot sector so that it
works with both my ordinary and my IDE floppies. (I include the patch
below, and I will tell Erich about my experiences.)
...
My GRUB patch:
It's just a hack, not a serious attempt to improve the software, but it
did give a floppy that boots off both my ordinary and my IDE floppy drives.
In grub-0.5/stage1/stage1.S the patch is:
< andb $BIOS_HD_FLAG, %al
<
< /* jz floppy_probe */
< .byte 0x0f, 0x84; REL(floppy_probe)
---
> orb $BIOS_HD_FLAG, %al
>
> /* jz floppy_probe */
> .byte 0x0f, 0x84; REL(floppy_probe)
If you prefer to patch the binary boot sector, the change is:
< 24 80
---
> 0c 80
That's at address 0x55 in grub-0.5/bin/stage1; the address is
different, no doubt, in the Hurd's boot floppy, which is based on an
earlier release of GRUB, but the same change might work for that too.
Edmund
--
To UNSUBSCRIBE, email to debian-hurd-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
To: Erich Boleyn <erich@uruk.org>
cc: debian-hurd@lists.debian.org
Subject: GRUB installation thoughts
X-Attribution: Gord
Gcc: nnml:archive
Mime-Version: 1.0 (generated by tm-edit 7.106)
Content-Type: text/plain; charset=US-ASCII
From: Gordon Matzigkeit <gord@trick.fig.org>
Date: 02 Feb 1999 13:24:24 -0600
Message-ID: <86iudk1udz.fsf@trick.fig.org>
Lines: 47
--text follows this line--
Hi!
I've been thinking about GRUB and how to make installation easier.
Here is my plan of how Debian GNU/Hurd installation should work:
1) Boot from floppy or CD or whatever, and GRUB starts. You get
a menu like this:
Install Debian GNU/Hurd
Boot an installed Debian GNU/Hurd system
Install GRUB
2) Go through a typical Debian installation. The install process will
ask you to mark your partition(s) as type 63 (currently reserved
for the GNU Hurd, for some odd reason... I wonder how that
happened?).
3) When the base set is installed, the system reboots from the floppy
again. At that point, all the other menu options should work.
I'd like to implement a GRUB feature so that `(hd:0x63)' means `the
first hard disk partition that is of type 0x63'.
So, the floppy's menu.lst can look something like this:
title = Install Debian GNU/Hurd
root = (fd0)
kernel = /boot/gnumach.gz
title = Boot an installed Debian GNU/Hurd system
root = (hd:0x63)
kernel = /boot/gnumach.gz
title = Install GRUB in the Debian GNU/Hurd root partition
root = (hd:0x63)
install= (fd0)+1 (hd:0x63) (hd:0x63)/boot/grub/fs_stage1_5 0x2000 p
The last bit of magic is to make sure gnumach uses the Multiboot
`boot_device' parameter as its default root, so that we don't need to
specify a root= option to Mach.
Comments?
--
Gordon Matzigkeit <gord@fig.org> //\ I'm a FIG (http://www.fig.org/)
Lovers of freedom, unite! \// I use GNU (http://www.gnu.org/)
[Unfortunately, www.fig.org is broken. Please stay tuned for details.]
From nobody Sun Feb 21 01:59:03 1999
X-From-Line: dunham@cse.msu.edu Sat Feb 20 17:43:34 1999
Return-Path: <dunham@cse.msu.edu>
Delivered-To: gord@trick.fig.org
Received: (qmail 16082 invoked from network); 20 Feb 1999 17:43:34 -0000
Received: from sargasso.cse.msu.edu (35.9.20.14)
by ip223.net247210.cr.sk.ca with SMTP; 20 Feb 1999 17:43:34 -0000
Received: from fatneck.cse.msu.edu (dunham@fatneck.cse.msu.edu [35.9.20.47])
by sargasso.cse.msu.edu (8.8.8/8.8.8) with ESMTP id MAA25678
for <gord@trick.fig.org>; Sat, 20 Feb 1999 12:43:26 -0500 (EST)
Received: (from dunham@localhost)
by fatneck.cse.msu.edu (8.9.2/8.9.2/Debian/GNU) id MAA19662;
Sat, 20 Feb 1999 12:45:10 -0500 (EST)
To: Gordon Matzigkeit <gord@trick.fig.org>
Subject: GRUB
Mime-Version: 1.0 (generated by tm-edit 7.108)
Content-Type: text/plain; charset=US-ASCII
From: Steve Dunham <dunham@cse.msu.edu>
Date: 20 Feb 1999 12:45:09 -0500
In-Reply-To: Gordon Matzigkeit's message of "18 Feb 1999 09:12:49 -0600"
Message-ID: <m9bemnl6kbe.fsf_-_@fatneck.cse.msu.edu>
X-Mailer: Gnus v5.5/XEmacs 20.4 - "Emerald"
Lines: 18
Xref: trick.fig.org misc:2354
IIRC, you took over the Grub package and upstream Grub.
You might be interested in the work by the "Fiasco" (aka L4) people at
tu-dresden - they taken Grub 0.4.1 and added network booting to it.
You can get their code at:
ftp://ftp.inf.tu-dresden.de/pub/os/L4/devel/
or grab a local copy of it that I put up at:
http://www.cse.msu.edu/~dunham/out/grub-l4-981207.tar.gz
Steve
dunham@cse.msu.edu

View file

@ -70,4 +70,3 @@
#define LAPIC_TDCR 0x3E0
#endif /* _APIC_H */

View file

@ -39,16 +39,18 @@ static struct mod_list mll[99];
*/
int
load_image(void)
load_image (void)
{
int len, i, exec_type, align_4k = 1, type = 0;
unsigned long flags = 0, text_len, data_len, bss_len;
char *str, *str2;
union {
union
{
struct multiboot_header *mb;
struct exec *aout;
Elf32_Ehdr *elf;
} pu;
}
pu;
/* presuming that MULTIBOOT_SEARCH is large enough to encompass an
executable header */
unsigned char buffer[MULTIBOOT_SEARCH];
@ -57,10 +59,10 @@ load_image(void)
buffer by default */
pu.aout = (struct exec *) buffer;
if (!open(cur_cmdline))
if (!open (cur_cmdline))
return 0;
if (!(len = read((int)buffer, MULTIBOOT_SEARCH)) || len < 32)
if (!(len = read ((int) buffer, MULTIBOOT_SEARCH)) || len < 32)
{
if (!errnum)
errnum = ERR_EXEC_FORMAT;
@ -70,9 +72,9 @@ load_image(void)
for (i = 0; i < len; i++)
{
if (MULTIBOOT_FOUND((int)(buffer+i), len-i))
if (MULTIBOOT_FOUND ((int) (buffer + i), len - i))
{
flags = ((struct multiboot_header *) (buffer+i))->flags;
flags = ((struct multiboot_header *) (buffer + i))->flags;
if (flags & MULTIBOOT_UNSUPPORTED)
{
errnum = ERR_BOOT_FEATURES;
@ -85,12 +87,12 @@ load_image(void)
}
/* ELF loading only supported if kernel using multiboot */
if (type == 'm' && len > sizeof(Elf32_Ehdr)
&& BOOTABLE_I386_ELF((*((Elf32_Ehdr *)buffer))))
if (type == 'm' && len > sizeof (Elf32_Ehdr)
&& BOOTABLE_I386_ELF ((*((Elf32_Ehdr *) buffer))))
{
entry_addr = (entry_func) pu.elf->e_entry;
if (((int)entry_addr) < 0x100000)
if (((int) entry_addr) < 0x100000)
errnum = ERR_BELOW_1MB;
/* don't want to deal with ELF program header at some random
@ -105,7 +107,7 @@ load_image(void)
}
else if (flags & MULTIBOOT_AOUT_KLUDGE)
{
pu.mb = (struct multiboot_header *) (buffer+i);
pu.mb = (struct multiboot_header *) (buffer + i);
entry_addr = (entry_func) pu.mb->entry_addr;
cur_addr = pu.mb->load_addr;
/* first offset into file */
@ -127,7 +129,7 @@ load_image(void)
exec_type = 2;
str = "kludge";
}
else if (len > sizeof(struct exec) && !N_BADMAG((*(pu.aout))))
else if (len > sizeof (struct exec) && !N_BADMAG ((*(pu.aout))))
{
entry_addr = (entry_func) pu.aout->a_entry;
@ -147,14 +149,14 @@ load_image(void)
if (buffer[0] == 0xb && buffer[1] == 1)
{
type = 'f';
entry_addr = (entry_func) (((int)entry_addr) & 0xFFFFFF);
entry_addr = (entry_func) (((int) entry_addr) & 0xFFFFFF);
str2 = "FreeBSD";
}
else
{
type = 'n';
entry_addr = (entry_func) (((int)entry_addr) & 0xF00000);
if (N_GETMAGIC((*(pu.aout))) != NMAGIC)
entry_addr = (entry_func) (((int) entry_addr) & 0xF00000);
if (N_GETMAGIC ((*(pu.aout))) != NMAGIC)
align_4k = 0;
str2 = "NetBSD";
}
@ -162,7 +164,7 @@ load_image(void)
cur_addr = (int) entry_addr;
/* first offset into file */
filepos = N_TXTOFF((*(pu.aout)));
filepos = N_TXTOFF ((*(pu.aout)));
text_len = pu.aout->a_text;
data_len = pu.aout->a_data;
bss_len = pu.aout->a_bss;
@ -173,60 +175,60 @@ load_image(void)
exec_type = 1;
str = "a.out";
}
else if ((*((unsigned short *) (buffer+BOOTSEC_SIG_OFFSET))
else if ((*((unsigned short *) (buffer + BOOTSEC_SIG_OFFSET))
== BOOTSEC_SIGNATURE)
&& ((data_len
= (((long)*((unsigned char *)
(buffer+LINUX_SETUP_LEN_OFFSET))) << 9))
= (((long) *((unsigned char *)
(buffer + LINUX_SETUP_LEN_OFFSET))) << 9))
<= LINUX_SETUP_MAXLEN)
&& ((text_len
= (((long)*((unsigned short *)
(buffer+LINUX_KERNEL_LEN_OFFSET))) << 4)),
(data_len+text_len+SECTOR_SIZE) <= ((filemax+15)&0xFFFFFFF0)))
= (((long) *((unsigned short *)
(buffer + LINUX_KERNEL_LEN_OFFSET))) << 4)),
(data_len + text_len + SECTOR_SIZE) <= ((filemax + 15) & 0xFFFFFFF0)))
{
int big_linux = buffer[LINUX_SETUP_LOAD_FLAGS] & LINUX_FLAG_BIG_KERNEL;
buffer[LINUX_SETUP_LOADER] = 0x70;
if (!big_linux && text_len > LINUX_KERNEL_MAXLEN)
{
printf(" linux 'zImage' kernel too big, try 'make bzImage'\n");
printf (" linux 'zImage' kernel too big, try 'make bzImage'\n");
errnum = ERR_WONT_FIT;
return 0;
}
printf(" [Linux-%s, setup=0x%x, size=0x%x]\n",
printf (" [Linux-%s, setup=0x%x, size=0x%x]\n",
(big_linux ? "bzImage" : "zImage"), data_len, text_len);
if (mbi.mem_lower >= 608)
{
bcopy(buffer, (char *)LINUX_SETUP, data_len+SECTOR_SIZE);
bcopy (buffer, (char *) LINUX_SETUP, data_len + SECTOR_SIZE);
/* copy command-line plus memory hack to staging area */
{
char *src = cur_cmdline;
char *dest = (char *) (CL_MY_LOCATION+4);
char *dest = (char *) (CL_MY_LOCATION + 4);
bcopy("mem=", (char *)CL_MY_LOCATION, 4);
bcopy ("mem=", (char *) CL_MY_LOCATION, 4);
*((unsigned short *) CL_OFFSET) = CL_MY_LOCATION-CL_BASE_ADDR;
*((unsigned short *) CL_OFFSET) = CL_MY_LOCATION - CL_BASE_ADDR;
*((unsigned short *) CL_MAGIC_ADDR) = CL_MAGIC;
dest = convert_to_ascii(dest, 'u', (mbi.mem_upper+0x400));
dest = convert_to_ascii (dest, 'u', (mbi.mem_upper + 0x400));
*(dest++) = 'K';
*(dest++) = ' ';
while (*src && *src != ' ')
src++;
while (((int)dest) < CL_MY_END_ADDR && (*(dest++) = *(src++)));
while (((int) dest) < CL_MY_END_ADDR && (*(dest++) = *(src++)));
*dest = 0;
}
/* offset into file */
filepos = data_len+SECTOR_SIZE;
filepos = data_len + SECTOR_SIZE;
cur_addr = LINUX_STAGING_AREA + text_len;
if (read(LINUX_STAGING_AREA, text_len) >= (text_len-16))
if (read (LINUX_STAGING_AREA, text_len) >= (text_len - 16))
return (big_linux ? 'L' : 'l');
else if (!errnum)
errnum = ERR_EXEC_FORMAT;
@ -242,7 +244,7 @@ load_image(void)
return 0;
/* fill the multiboot info structure */
mbi.cmdline = (int)cur_cmdline;
mbi.cmdline = (int) cur_cmdline;
mbi.mods_count = 0;
mbi.mods_addr = 0;
mbi.boot_device = (saved_drive << 24) | saved_partition;
@ -252,7 +254,7 @@ load_image(void)
mbi.syms.a.addr = 0;
mbi.syms.a.pad = 0;
printf(" [%s-%s", str2, str);
printf (" [%s-%s", str2, str);
str = "";
@ -261,10 +263,10 @@ load_image(void)
if (flags & MULTIBOOT_AOUT_KLUDGE)
str = "-and-data";
printf(", loadaddr=0x%x, text%s=0x%x", cur_addr, str, text_len);
printf (", loadaddr=0x%x, text%s=0x%x", cur_addr, str, text_len);
/* read text, then read data */
if (read(cur_addr, text_len) == text_len)
if (read (cur_addr, text_len) == text_len)
{
cur_addr += text_len;
@ -274,21 +276,21 @@ load_image(void)
if (align_4k)
cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
else
printf(", C");
printf (", C");
printf(", data=0x%x", data_len);
printf (", data=0x%x", data_len);
if (read(cur_addr, data_len) != data_len && !errnum)
if (read (cur_addr, data_len) != data_len && !errnum)
errnum = ERR_EXEC_FORMAT;
cur_addr += data_len;
}
if (!errnum)
{
bzero((char*)cur_addr, bss_len);
bzero ((char *) cur_addr, bss_len);
cur_addr += bss_len;
printf(", bss=0x%x", bss_len);
printf (", bss=0x%x", bss_len);
}
}
else if (!errnum)
@ -304,26 +306,26 @@ load_image(void)
mbi.syms.a.addr = cur_addr;
*(((int *)cur_addr)++) = pu.aout->a_syms;
*(((int *) cur_addr)++) = pu.aout->a_syms;
printf(", symtab=0x%x", pu.aout->a_syms);
printf (", symtab=0x%x", pu.aout->a_syms);
if (read(cur_addr, pu.aout->a_syms) == pu.aout->a_syms)
if (read (cur_addr, pu.aout->a_syms) == pu.aout->a_syms)
{
cur_addr += pu.aout->a_syms;
mbi.syms.a.tabsize = pu.aout->a_syms;
if (read((int)(&i), sizeof(int)) == sizeof(int))
if (read ((int) (&i), sizeof (int)) == sizeof (int))
{
*(((int *)cur_addr)++) = i;
*(((int *) cur_addr)++) = i;
mbi.syms.a.strsize = i;
i -= sizeof(int);
i -= sizeof (int);
printf(", strtab=0x%x", i);
printf (", strtab=0x%x", i);
symtab_err = (read(cur_addr, i) != i);
symtab_err = (read (cur_addr, i) != i);
cur_addr += i;
}
else
@ -334,7 +336,7 @@ load_image(void)
if (symtab_err)
{
printf("(bad)");
printf ("(bad)");
cur_addr = orig_addr;
mbi.syms.a.tabsize = 0;
mbi.syms.a.strsize = 0;
@ -344,7 +346,8 @@ load_image(void)
mbi.flags |= MB_INFO_AOUT_SYMS;
}
}
else /* ELF executable */
else
/* ELF executable */
{
int loaded = 0, memaddr, memsiz, filesiz;
Elf32_Phdr *phdr;
@ -356,7 +359,7 @@ load_image(void)
for (i = 0; i < pu.elf->e_phnum; i++)
{
phdr = (Elf32_Phdr *)
(pu.elf->e_phoff + ((int)buffer)
(pu.elf->e_phoff + ((int) buffer)
+ (pu.elf->e_phentsize * i));
if (phdr->p_type == PT_LOAD)
{
@ -371,19 +374,19 @@ load_image(void)
if (filesiz > memsiz)
filesiz = memsiz;
/* mark memory as used */
if (cur_addr < memaddr+memsiz)
cur_addr = memaddr+memsiz;
printf(", <0x%x:0x%x:0x%x>", memaddr, filesiz,
memsiz-filesiz);
if (cur_addr < memaddr + memsiz)
cur_addr = memaddr + memsiz;
printf (", <0x%x:0x%x:0x%x>", memaddr, filesiz,
memsiz - filesiz);
/* increment number of segments */
loaded++;
/* load the segment */
if (memcheck(memaddr, memsiz)
&& read(memaddr, filesiz) == filesiz)
if (memcheck (memaddr, memsiz)
&& read (memaddr, filesiz) == filesiz)
{
if (memsiz > filesiz)
bzero((char *)(memaddr+filesiz), memsiz-filesiz);
bzero ((char *) (memaddr + filesiz), memsiz - filesiz);
}
else
break;
@ -402,10 +405,10 @@ load_image(void)
}
if (!errnum)
printf(", entry=0x%x]\n", (int)entry_addr);
printf (", entry=0x%x]\n", (int) entry_addr);
else
{
putchar('\n');
putchar ('\n');
type = 0;
}
@ -413,23 +416,23 @@ load_image(void)
}
int
load_module(void)
load_module (void)
{
int len;
/* if we are supposed to load on 4K boundaries */
cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
if (!open(cur_cmdline) || !(len = read(cur_addr, -1)))
if (!open (cur_cmdline) || !(len = read (cur_addr, -1)))
return 0;
printf(" [Multiboot-module @ 0x%x, 0x%x bytes]\n", cur_addr, len);
printf (" [Multiboot-module @ 0x%x, 0x%x bytes]\n", cur_addr, len);
/* these two simply need to be set if any modules are loaded at all */
mbi.flags |= MB_INFO_MODS;
mbi.mods_addr = (int)mll;
mbi.mods_addr = (int) mll;
mll[mbi.mods_count].cmdline = (int)cur_cmdline;
mll[mbi.mods_count].cmdline = (int) cur_cmdline;
mll[mbi.mods_count].mod_start = cur_addr;
cur_addr += len;
mll[mbi.mods_count].mod_end = cur_addr;
@ -442,20 +445,20 @@ load_module(void)
}
int
load_initrd(void)
load_initrd (void)
{
int len;
long *ramdisk, moveto;
if (!open(cur_cmdline) || !(len = read(cur_addr, -1)))
if (!open (cur_cmdline) || !(len = read (cur_addr, -1)))
return 0;
moveto = ((mbi.mem_upper+0x400)*0x400 - len) & 0xfffff000;
bcopy((void*)cur_addr, (void*)moveto, len);
moveto = ((mbi.mem_upper + 0x400) * 0x400 - len) & 0xfffff000;
bcopy ((void *) cur_addr, (void *) moveto, len);
printf(" [Linux-initrd @ 0x%x, 0x%x bytes]\n", moveto, len);
printf (" [Linux-initrd @ 0x%x, 0x%x bytes]\n", moveto, len);
ramdisk = (long*)(LINUX_SETUP+LINUX_SETUP_INITRD);
ramdisk = (long *) (LINUX_SETUP + LINUX_SETUP_INITRD);
ramdisk[0] = moveto;
ramdisk[1] = len;
@ -472,13 +475,13 @@ load_initrd(void)
void
bsd_boot(int type, int bootdev)
bsd_boot (int type, int bootdev)
{
char *str;
int clval = 0, i;
struct bootinfo bi;
stop_floppy();
stop_floppy ();
while (*(++cur_cmdline) && *cur_cmdline != ' ');
str = cur_cmdline;
@ -486,7 +489,7 @@ bsd_boot(int type, int bootdev)
{
if (*str == '-')
{
while(*str && *str != ' ')
while (*str && *str != ' ')
{
if (*str == 'C')
clval |= RB_CDROM;
@ -520,19 +523,19 @@ bsd_boot(int type, int bootdev)
bi.bi_version = BOOTINFO_VERSION;
*cur_cmdline = 0;
while ((--cur_cmdline) > (char *)(mbi.cmdline) && *cur_cmdline != '/');
while ((--cur_cmdline) > (char *) (mbi.cmdline) && *cur_cmdline != '/');
if (*cur_cmdline == '/')
bi.bi_kernelname = cur_cmdline+1;
bi.bi_kernelname = cur_cmdline + 1;
else
bi.bi_kernelname = 0;
bi.bi_nfs_diskless = 0;
bi.bi_n_bios_used = 0; /* this field is apparently unused */
for(i = 0; i < N_BIOS_GEOM; i++)
bi.bi_bios_geom[i] = get_diskinfo(i + 0x80);
for (i = 0; i < N_BIOS_GEOM; i++)
bi.bi_bios_geom[i] = get_diskinfo (i + 0x80);
bi.bi_size = sizeof(struct bootinfo);
bi.bi_size = sizeof (struct bootinfo);
bi.bi_memsizes_valid = 1;
bi.bi_basemem = mbi.mem_lower;
bi.bi_extmem = mbi.mem_upper;
@ -541,7 +544,7 @@ bsd_boot(int type, int bootdev)
+ mbi.syms.a.tabsize + mbi.syms.a.strsize;
/* call entry point */
(*entry_addr)(clval, bootdev, 0, 0, 0, ((int)(&bi)));
(*entry_addr) (clval, bootdev, 0, 0, 0, ((int) (&bi)));
}
else
{
@ -565,10 +568,9 @@ bsd_boot(int type, int bootdev)
*/
/* call entry point */
(*entry_addr)(clval, bootdev, 0,
(*entry_addr) (clval, bootdev, 0,
(mbi.syms.a.addr + 4
+ mbi.syms.a.tabsize + mbi.syms.a.strsize),
mbi.mem_upper, mbi.mem_lower);
}
}

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -24,23 +25,23 @@
#ifndef NO_FANCY_STUFF
int
getkey(void)
getkey (void)
{
buf_drive = -1;
return asm_getkey();
return asm_getkey ();
}
#endif /* NO_FANCY_STUFF */
void
print_error(void)
print_error (void)
{
if (errnum > ERR_NONE && errnum < MAX_ERR_NUM)
#ifndef NO_FANCY_STUFF
/* printf("\7\n %s\n", err_list[errnum]); */
printf("\n %s\n", err_list[errnum]);
printf ("\n %s\n", err_list[errnum]);
#else /* NO_FANCY_STUFF */
printf("Error: %d\n", errnum);
printf ("Error: %d\n", errnum);
#endif /* NO_FANCY_STUFF */
errnum = ERR_NONE;
@ -48,7 +49,7 @@ print_error(void)
char *
convert_to_ascii(char *buf, int c, ...)
convert_to_ascii (char *buf, int c,...)
{
unsigned long num = *((&c) + 1), mult = 10;
char *ptr = buf;
@ -58,7 +59,7 @@ convert_to_ascii(char *buf, int c, ...)
if ((num & 0x80000000uL) && c == 'd')
{
num = (~num)+1;
num = (~num) + 1;
*(ptr++) = '-';
buf++;
}
@ -66,13 +67,13 @@ convert_to_ascii(char *buf, int c, ...)
do
{
int dig = num % mult;
*(ptr++) = ( (dig > 9) ? dig + 'a' - 10 : '0' + dig );
*(ptr++) = ((dig > 9) ? dig + 'a' - 10 : '0' + dig);
}
while (num /= mult);
/* reorder to correct direction!! */
{
char *ptr1 = ptr-1;
char *ptr1 = ptr - 1;
char *ptr2 = buf;
while (ptr1 > ptr2)
{
@ -89,7 +90,7 @@ convert_to_ascii(char *buf, int c, ...)
void
printf(char *format, ... )
printf (char *format,...)
{
int *dataptr = (int *) &format;
char c, *ptr, str[16];
@ -99,26 +100,30 @@ printf(char *format, ... )
while (c = *(format++))
{
if (c != '%')
putchar(c);
putchar (c);
else
switch (c = *(format++))
{
case 'd': case 'u': case 'x':
*convert_to_ascii(str, c, *((unsigned long *) dataptr++)) = 0;
case 'd':
case 'u':
case 'x':
*convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
ptr = str;
while (*ptr)
putchar(*(ptr++));
putchar (*(ptr++));
break;
case 'c': putchar((*(dataptr++))&0xff); break;
case 'c':
putchar ((*(dataptr++)) & 0xff);
break;
case 's':
ptr = (char *)(*(dataptr++));
ptr = (char *) (*(dataptr++));
while (c = *(ptr++))
putchar(c);
putchar (c);
break;
}
}
@ -128,11 +133,11 @@ printf(char *format, ... )
#ifndef NO_FANCY_STUFF
void
init_page(void)
init_page (void)
{
cls();
cls ();
printf("\n GRUB version %s (%dK lower / %dK upper memory)\n\n",
printf ("\n GRUB version %s (%dK lower / %dK upper memory)\n\n",
version_string, mbi.mem_lower, mbi.mem_upper);
}
@ -145,23 +150,23 @@ init_page(void)
cmdline... the cmdline must be a valid string at the start */
int
get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
get_cmdline (char *prompt, char *commands, char *cmdline, int maxlen)
{
int ystart, yend, xend, lpos, c;
int plen = 0;
int llen = 0;
/* nested function definition for code simplicity XXX GCC only, I think */
void cl_print(char *str)
void cl_print (char *str)
{
while (*str != 0)
{
putchar(*(str++));
putchar (*(str++));
if (++xend > 78)
{
xend = 0;
putchar(' ');
if (yend == (getxy() & 0xFF))
putchar (' ');
if (yend == (getxy () & 0xFF))
ystart--;
else
yend++;
@ -169,41 +174,41 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
}
}
/* nested function definition for code simplicity XXX GCC only, I think */
void cl_setcpos(void)
void cl_setcpos (void)
{
yend = ((lpos+plen) / 79) + ystart;
xend = ((lpos+plen) % 79);
gotoxy(xend, yend);
yend = ((lpos + plen) / 79) + ystart;
xend = ((lpos + plen) % 79);
gotoxy (xend, yend);
}
/* nested function definition for initial command-line printing */
void cl_init()
void cl_init ()
{
/* distinguish us from other lines and error messages! */
putchar('\n');
putchar ('\n');
/* print full line and set position here */
ystart = (getxy() & 0xFF);
ystart = (getxy () & 0xFF);
yend = ystart;
xend = 0;
cl_print(prompt);
cl_print(cmdline);
cl_setcpos();
cl_print (prompt);
cl_print (cmdline);
cl_setcpos ();
}
/* nested function definition for erasing to the end of the line */
void cl_kill_to_end()
void cl_kill_to_end ()
{
int i;
cmdline[lpos] = 0;
for (i = lpos; i <= llen; i++)
{
if (i && ((i + plen) % 79) == 0)
putchar(' ');
putchar(' ');
putchar (' ');
putchar (' ');
}
llen = lpos;
cl_setcpos();
cl_setcpos ();
}
while (prompt[plen])
@ -222,9 +227,9 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
}
lpos = llen;
cl_init();
cl_init ();
while (ASCII_CHAR(c = getkey()) != '\n' && ASCII_CHAR(c) != '\r')
while (ASCII_CHAR (c = getkey ()) != '\n' && ASCII_CHAR (c) != '\r')
{
switch (c)
{
@ -245,11 +250,11 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
default:
}
c = ASCII_CHAR(c);
c = ASCII_CHAR (c);
switch (c)
{
case 27: /* ESC immediately return 1*/
case 27: /* ESC immediately return 1 */
return 1;
case 9: /* TAB lists completions */
{
@ -261,51 +266,52 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
/* since the command line cannot have a '\n', we're OK to use c */
c = cmdline[lpos];
cl_kill_to_end();
cl_kill_to_end ();
/* goto part after line here */
yend = ((llen+plen) / 79) + ystart;
gotoxy(0, yend); putchar('\n');
yend = ((llen + plen) / 79) + ystart;
gotoxy (0, yend);
putchar ('\n');
if (lpos > j)
{
for (i = lpos; i > 0 && cmdline[i-1] != ' '; i--);
for (i = lpos; i > 0 && cmdline[i - 1] != ' '; i--);
if (i <= j)
i = j+1;
i = j + 1;
/* print possible completions */
print_completions(cmdline+i);
print_completions (cmdline + i);
}
else if (commands)
printf(commands);
printf (commands);
else
break;
/* restore command-line */
cmdline[lpos] = c;
llen = llen_old;
cl_init();
cl_init ();
}
break;
case 1: /* C-a go to beginning of line */
lpos = 0;
cl_setcpos();
cl_setcpos ();
break;
case 5: /* C-e go to end of line */
lpos = llen;
cl_setcpos();
cl_setcpos ();
break;
case 6: /* C-f forward one character */
if (lpos < llen)
{
lpos++;
cl_setcpos();
cl_setcpos ();
}
break;
case 2: /* C-b backward one character */
if (lpos > 0)
{
lpos--;
cl_setcpos();
cl_setcpos ();
}
break;
case 4: /* C-d delete character under cursor */
@ -317,19 +323,19 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
if (lpos > 0)
{
int i;
for (i = lpos-1; i < llen; i++)
cmdline[i] = cmdline[i+1];
for (i = lpos - 1; i < llen; i++)
cmdline[i] = cmdline[i + 1];
i = lpos;
lpos = llen - 1;
cl_setcpos();
putchar(' ');
cl_setcpos ();
putchar (' ');
lpos = i - 1; /* restore lpos and decrement */
llen--;
cl_setcpos();
cl_setcpos ();
if (lpos != llen)
{
cl_print(cmdline+lpos);
cl_setcpos();
cl_print (cmdline + lpos);
cl_setcpos ();
}
}
break;
@ -338,45 +344,45 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
break;
{
int i;
for (i = 0; i < (llen-lpos); i++)
cmdline[i] = cmdline[lpos+i];
for (i = 0; i < (llen - lpos); i++)
cmdline[i] = cmdline[lpos + i];
}
lpos = llen-lpos;
cl_setcpos();
lpos = llen - lpos;
cl_setcpos ();
/* fallthrough on purpose! */
case 11: /* C-k kill to end of line */
if (lpos < llen)
{
cl_kill_to_end();
cl_kill_to_end ();
if (c == 21)
{
lpos = 0;
cl_setcpos();
cl_print(cmdline);
cl_setcpos();
cl_setcpos ();
cl_print (cmdline);
cl_setcpos ();
}
}
break;
default: /* insert printable character into line */
if (llen < (maxlen-1) && c >= ' ' && c <= '~')
if (llen < (maxlen - 1) && c >= ' ' && c <= '~')
{
if (lpos == llen)
{
cmdline[lpos] = c;
cmdline[lpos+1] = 0;
cl_print(cmdline+lpos);
cmdline[lpos + 1] = 0;
cl_print (cmdline + lpos);
lpos++;
}
else
{
int i;
for (i = llen; i >= lpos; i--)
cmdline[i+1] = cmdline[i];
cmdline[i + 1] = cmdline[i];
cmdline[lpos] = c;
cl_setcpos();
cl_print(cmdline+lpos);
cl_setcpos ();
cl_print (cmdline + lpos);
lpos++;
cl_setcpos();
cl_setcpos ();
}
llen++;
}
@ -384,8 +390,9 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
}
/* goto part after line here */
yend = ((llen+plen) / 79) + ystart;
gotoxy(0, yend); putchar('\n');
yend = ((llen + plen) / 79) + ystart;
gotoxy (0, yend);
putchar ('\n');
/* remove leading spaces */
/* use c and lpos as indexes now */
@ -412,12 +419,12 @@ get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen)
int
get_based_digit(int c, int base)
get_based_digit (int c, int base)
{
int digit = -1;
/* make sure letter in the the range we can check! */
c = tolower(c);
c = tolower (c);
/*
* Is it in the range between zero and nine?
@ -440,7 +447,7 @@ get_based_digit(int c, int base)
int
safe_parse_maxint(char **str_ptr, int *myint_ptr)
safe_parse_maxint (char **str_ptr, int *myint_ptr)
{
register char *ptr = *str_ptr;
register int myint = 0, digit;
@ -449,16 +456,16 @@ safe_parse_maxint(char **str_ptr, int *myint_ptr)
/*
* Is this a hex number?
*/
if (*ptr == '0' && tolower(*(ptr+1)) == 'x')
if (*ptr == '0' && tolower (*(ptr + 1)) == 'x')
{
ptr += 2;
mult = 16;
}
while ((digit = get_based_digit(*ptr, mult)) != -1)
while ((digit = get_based_digit (*ptr, mult)) != -1)
{
found = 1;
if (myint > ((MAXINT - digit)/mult))
if (myint > ((MAXINT - digit) / mult))
{
errnum = ERR_NUMBER_PARSING;
return 0;
@ -481,7 +488,7 @@ safe_parse_maxint(char **str_ptr, int *myint_ptr)
int
tolower(int c)
tolower (int c)
{
if (c >= 'A' && c <= 'Z')
return (c + ('a' - 'A'));
@ -491,7 +498,7 @@ tolower(int c)
int
isspace(int c)
isspace (int c)
{
if (c == ' ' || c == '\t' || c == '\n')
return 1;
@ -501,7 +508,7 @@ isspace(int c)
int
strncat(char *s1, char *s2, int n)
strncat (char *s1, char *s2, int n)
{
int i = -1;
@ -509,7 +516,7 @@ strncat(char *s1, char *s2, int n)
while (i < n && (s1[i++] = *(s2++)) != 0);
s1[n-1] = 0;
s1[n - 1] = 0;
if (i >= n)
return 0;
@ -521,7 +528,7 @@ strncat(char *s1, char *s2, int n)
int
substring(char *s1, char *s2)
substring (char *s1, char *s2)
{
while (*s1 == *s2)
{
@ -541,7 +548,7 @@ substring(char *s1, char *s2)
char *
strstr(char *s1, char *s2)
strstr (char *s1, char *s2)
{
char *ptr, *tmp;
@ -552,7 +559,7 @@ strstr(char *s1, char *s2)
while (*s1 && *s1++ == *tmp++);
if (tmp > s2 && !*(tmp-1))
if (tmp > s2 && !*(tmp - 1))
return ptr;
}
@ -561,12 +568,12 @@ strstr(char *s1, char *s2)
int
memcheck(int start, int len)
memcheck (int start, int len)
{
if ( (start < 0x1000) || (start < 0x100000
&& (mbi.mem_lower * 1024) < (start+len))
if ((start < 0x1000) || (start < 0x100000
&& (mbi.mem_lower * 1024) < (start + len))
|| (start >= 0x100000
&& (mbi.mem_upper * 1024) < ((start-0x100000)+len)) )
&& (mbi.mem_upper * 1024) < ((start - 0x100000) + len)))
errnum = ERR_WONT_FIT;
return (!errnum);
@ -574,16 +581,16 @@ memcheck(int start, int len)
int
bcopy(char *from, char *to, int len)
bcopy (char *from, char *to, int len)
{
if (memcheck((int)to, len))
if (memcheck ((int) to, len))
{
if ((to >= from+len) || (to <= from))
if ((to >= from + len) || (to <= from))
{
while (len >= sizeof (unsigned long))
{
len -= sizeof (unsigned long);
*(((unsigned long *)to)++) = *(((unsigned long *)from)++);
*(((unsigned long *) to)++) = *(((unsigned long *) from)++);
}
while (len-- > 0)
*(to++) = *(from++);
@ -602,9 +609,9 @@ bcopy(char *from, char *to, int len)
int
bzero(char *start, int len)
bzero (char *start, int len)
{
if (memcheck((int)start, len))
if (memcheck ((int) start, len))
{
while (len-- > 0)
*(start++) = 0;

View file

@ -42,7 +42,8 @@ int errnum = 0;
char *err_list[] =
{
[ERR_NONE] = 0,
[ERR_BAD_FILENAME] = "Bad filename (must be absolute pathname or blocklist)",
[ERR_BAD_FILENAME] =
"Bad filename (must be absolute pathname or blocklist)",
[ERR_BAD_FILETYPE] = "Bad file or directory type",
[ERR_BAD_GZIP_DATA] = "Bad or corrupt data while decompressing file",
[ERR_BAD_GZIP_HEADER] = "Bad or incompatible header on compressed file",
@ -55,7 +56,8 @@ char *err_list[] =
[ERR_DEV_FORMAT] = "Device string unrecognizable",
[ERR_DEV_VALUES] = "Invalid device requested",
[ERR_EXEC_FORMAT] = "Invalid or unsupported executable format",
[ERR_FILELENGTH] = "Filesystem compatibility error, cannot read whole file",
[ERR_FILELENGTH] =
"Filesystem compatibility error, cannot read whole file",
[ERR_FILE_NOT_FOUND] = "File not found",
[ERR_FSYS_CORRUPT] = "Inconsistent filesystem structure",
[ERR_FSYS_MOUNT] = "Cannot mount selected partition",
@ -77,9 +79,9 @@ char *err_list[] =
/* static for BIOS memory map fakery */
static struct AddrRangeDesc fakemap[3] =
{
{ 20, 0, 0, 0, 0, MB_ARD_MEMORY },
{ 20, 0x100000, 0, 0, 0, MB_ARD_MEMORY },
{ 20, 0x1000000, 0, 0, 0, MB_ARD_MEMORY }
{20, 0, 0, 0, 0, MB_ARD_MEMORY},
{20, 0x100000, 0, 0, 0, MB_ARD_MEMORY},
{20, 0x1000000, 0, 0, 0, MB_ARD_MEMORY}
};
#endif /* NO_FANCY_STUFF */
@ -89,7 +91,7 @@ static struct AddrRangeDesc fakemap[3] =
*/
void
init_bios_info(void)
init_bios_info (void)
{
int cont, memtmp, addr;
@ -97,8 +99,8 @@ init_bios_info(void)
* Get information from BIOS on installed RAM.
*/
mbi.mem_lower = get_memsize(0);
mbi.mem_upper = get_memsize(1);
mbi.mem_lower = get_memsize (0);
mbi.mem_upper = get_memsize (1);
#ifndef NO_FANCY_STUFF
/*
@ -107,7 +109,7 @@ init_bios_info(void)
* to 0. Not too desirable.
*/
gateA20(1);
gateA20 (1);
/*
* The "mbi.mem_upper" variable only recognizes upper memory in the
@ -122,13 +124,13 @@ init_bios_info(void)
do
{
cont = get_mem_map(addr, cont);
cont = get_mem_map (addr, cont);
if ( ! *((int *)addr) )
if (!*((int *) addr))
break;
mbi.mmap_length += *((int *)addr) + 4;
addr += *((int *)addr) + 4;
mbi.mmap_length += *((int *) addr) + 4;
addr += *((int *) addr) + 4;
}
while (cont);
@ -152,14 +154,14 @@ init_bios_info(void)
addr < mbi.mmap_addr + mbi.mmap_length;
addr += *((int *) addr) + 4)
{
if (((struct AddrRangeDesc *)addr)->BaseAddrHigh == 0
&& ((struct AddrRangeDesc *)addr)->Type == MB_ARD_MEMORY
&& ((struct AddrRangeDesc *)addr)->BaseAddrLow <= memtmp
&& (((struct AddrRangeDesc *)addr)->BaseAddrLow
+ ((struct AddrRangeDesc *)addr)->LengthLow) > memtmp)
if (((struct AddrRangeDesc *) addr)->BaseAddrHigh == 0
&& ((struct AddrRangeDesc *) addr)->Type == MB_ARD_MEMORY
&& ((struct AddrRangeDesc *) addr)->BaseAddrLow <= memtmp
&& (((struct AddrRangeDesc *) addr)->BaseAddrLow
+ ((struct AddrRangeDesc *) addr)->LengthLow) > memtmp)
{
memtmp = (((struct AddrRangeDesc *)addr)->BaseAddrLow
+ ((struct AddrRangeDesc *)addr)->LengthLow);
memtmp = (((struct AddrRangeDesc *) addr)->BaseAddrLow
+ ((struct AddrRangeDesc *) addr)->LengthLow);
cont++;
}
}
@ -168,7 +170,7 @@ init_bios_info(void)
mbi.mem_upper = (memtmp - 0x100000) >> 10;
}
else if ((memtmp = get_eisamemsize()) != -1)
else if ((memtmp = get_eisamemsize ()) != -1)
{
cont = memtmp & ~0xFFFF;
memtmp = memtmp & 0xFFFF;
@ -179,8 +181,8 @@ init_bios_info(void)
{
/* XXX should I do this at all ??? */
mbi.mmap_addr = (int)fakemap;
mbi.mmap_length = sizeof(fakemap);
mbi.mmap_addr = (int) fakemap;
mbi.mmap_length = sizeof (fakemap);
fakemap[0].LengthLow = (mbi.mem_lower << 10);
fakemap[1].LengthLow = (memtmp << 10);
fakemap[2].LengthLow = cont;
@ -210,5 +212,5 @@ init_bios_info(void)
* Start main routine here.
*/
cmain();
cmain ();
}

View file

@ -1,3 +1,4 @@
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
@ -50,9 +51,11 @@ typedef unsigned char u_char; /* unsigned char */
typedef unsigned short u_short; /* unsigned short */
typedef unsigned int u_int; /* unsigned int */
typedef struct _quad_ {
typedef struct _quad_
{
unsigned int val[2]; /* 2 int values make... */
} quad; /* an 8-byte item */
}
quad; /* an 8-byte item */
typedef unsigned int time_t; /* an unsigned int */
typedef unsigned int daddr_t; /* an unsigned int */
@ -90,4 +93,3 @@ typedef unsigned int ino_t;
#define MAXPATHLEN 1024
#define MAXSYMLINKS 8

View file

@ -1,3 +1,4 @@
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
@ -73,12 +74,13 @@
#define DIRBLKSIZ DEV_BSIZE
#define MAXNAMLEN 255
struct direct {
struct direct
{
u_int d_ino; /* inode number of entry */
u_short d_reclen; /* length of this record */
u_short d_namlen; /* length of string in d_name */
char d_name[MAXNAMLEN + 1]; /* name with length <= MAXNAMLEN */
};
};
/*
* The DIRSIZ macro gives the minimum record length which will hold
@ -96,7 +98,8 @@ struct direct {
* Should use struct direct's, but the name field
* is MAXNAMLEN - 1, and this just won't do.
*/
struct dirtemplate {
struct dirtemplate
{
u_int dot_ino;
short dot_reclen;
short dot_namlen;
@ -105,7 +108,7 @@ struct dirtemplate {
short dotdot_reclen;
short dotdot_namlen;
char dotdot_name[4]; /* ditto */
};
};
#endif
/*
@ -120,23 +123,25 @@ struct dirtemplate {
/*
* Definitions for library routines operating on directories.
*/
typedef struct _dirdesc {
typedef struct _dirdesc
{
int dd_fd;
int dd_loc;
int dd_size;
char dd_buf[DIRBLKSIZ];
} DIR;
}
DIR;
#define dirfd(dirp) ((dirp)->dd_fd)
#ifndef NULL
#define NULL 0
#endif
extern DIR *opendir();
extern struct direct *readdir();
extern int telldir();
extern void seekdir();
extern DIR *opendir ();
extern struct direct *readdir ();
extern int telldir ();
extern void seekdir ();
#define rewinddir(dirp) seekdir((dirp), (long)0)
extern void closedir();
extern void closedir ();
#endif /* not KERNEL */
#endif /* _BOOT_UFS_DIR_H_ */

View file

@ -58,7 +58,8 @@
#define FFS_MAX_FASTLINK_SIZE ((FFS_NDADDR + FFS_NIADDR) * sizeof(daddr_t))
struct icommon {
struct icommon
{
u_short ic_mode; /* 0: mode and type of file */
short ic_nlink; /* 2: number of links to file */
uid_t ic_uid; /* 4: owner's user id */
@ -70,14 +71,18 @@ struct icommon {
int ic_mtspare;
time_t ic_ctime; /* 32: last time inode changed */
int ic_ctspare;
union {
struct {
union
{
struct
{
daddr_t Mb_db[FFS_NDADDR]; /* 40: disk block addresses */
daddr_t Mb_ib[FFS_NIADDR]; /* 88: indirect blocks */
} ic_Mb;
}
ic_Mb;
char ic_Msymlink[FFS_MAX_FASTLINK_SIZE];
/* 40: symbolic link name */
} ic_Mun;
}
ic_Mun;
#define ic_db ic_Mun.ic_Mb.Mb_db
#define ic_ib ic_Mun.ic_Mb.Mb_ib
#define ic_symlink ic_Mun.ic_Msymlink
@ -85,17 +90,21 @@ struct icommon {
int ic_blocks; /* 104: blocks actually held */
int ic_gen; /* 108: generation number */
int ic_spare[4]; /* 112: reserved, currently unused */
} i_ic;
}
i_ic;
/*
* Same structure, but on disk.
*/
struct dinode {
union {
struct dinode
{
union
{
struct icommon di_com;
char di_char[128];
} di_un;
};
}
di_un;
};
#define di_ic di_un.di_com
#endif /* _BOOT_UFS_DISK_INODE_H_ */

View file

@ -98,4 +98,4 @@
#define f_blkno u.ffs.ffs_blkno
#endif /* EEK */
#endif _BOOT_UFS_DISK_INODE_FFS_H_
#endif /* _BOOT_UFS_DISK_INODE_FFS_H_ */

View file

@ -29,8 +29,8 @@
#ifndef NO_FANCY_STUFF
/* instrumentation variables */
void (*debug_fs)(int) = NULL;
void (*debug_fs_func)(int) = NULL;
void (*debug_fs) (int) = NULL;
void (*debug_fs_func) (int) = NULL;
#endif /* NO_FANCY_STUFF */
/* These have the same format as "boot_drive" and "install_partition", but
@ -68,9 +68,9 @@ int filemax;
int
rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
rawread (int drive, int sector, int byte_offset, int byte_len, int addr)
{
int slen = (byte_offset+byte_len+511)/SECTOR_SIZE;
int slen = (byte_offset + byte_len + 511) / SECTOR_SIZE;
if (byte_len <= 0)
return 1;
@ -85,7 +85,7 @@ rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
*/
if (buf_drive != drive)
{
buf_geom = get_diskinfo(drive);
buf_geom = get_diskinfo (drive);
buf_drive = drive;
buf_track = -1;
}
@ -97,14 +97,14 @@ rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
}
/* Get first sector of track */
soff = sector % SECTORS(buf_geom);
soff = sector % SECTORS (buf_geom);
track = sector - soff;
num_sect = SECTORS(buf_geom) - soff;
num_sect = SECTORS (buf_geom) - soff;
bufaddr = BUFFERADDR + (soff * SECTOR_SIZE) + byte_offset;
if (track != buf_track)
{
int bios_err, read_start = track, read_len = SECTORS(buf_geom);
int bios_err, read_start = track, read_len = SECTORS (buf_geom);
/*
* If there's more than one read in this entire loop, then
@ -118,7 +118,7 @@ rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
bufaddr = BUFFERADDR + byte_offset;
}
if (bios_err = biosdisk(BIOSDISK_SUBFUNC_READ, drive, buf_geom,
if (bios_err = biosdisk (BIOSDISK_SUBFUNC_READ, drive, buf_geom,
read_start, read_len, BUFFERSEG))
{
buf_track = -1;
@ -132,7 +132,7 @@ rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
* required sector(s) rather than failing completely.
*/
if (slen > num_sect
|| biosdisk(BIOSDISK_SUBFUNC_READ, drive, buf_geom,
|| biosdisk (BIOSDISK_SUBFUNC_READ, drive, buf_geom,
sector, slen, BUFFERSEG))
errnum = ERR_READ;
@ -153,14 +153,14 @@ rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
int sector_num = sector;
while (sector_num < sector_end)
(*debug_fs_func)(sector_num++);
(*debug_fs_func) (sector_num++);
}
#endif /* NO_FANCY_STUFF */
if (size > ((num_sect * SECTOR_SIZE) - byte_offset))
size = (num_sect * SECTOR_SIZE) - byte_offset;
bcopy((char *)bufaddr, (char *)addr, size);
bcopy ((char *) bufaddr, (char *) addr, size);
addr += size;
byte_len -= size;
@ -174,13 +174,13 @@ rawread(int drive, int sector, int byte_offset, int byte_len, int addr)
int
devread(int sector, int byte_offset, int byte_len, int addr)
devread (int sector, int byte_offset, int byte_len, int addr)
{
/*
* Check partition boundaries
*/
if (sector < 0
|| (sector + ((byte_offset+byte_len-1)/SECTOR_SIZE)) >= part_length)
|| (sector + ((byte_offset + byte_len - 1) / SECTOR_SIZE)) >= part_length)
{
errnum = ERR_OUTSIDE_PART;
return 0;
@ -197,7 +197,7 @@ devread(int sector, int byte_offset, int byte_len, int addr)
#if !defined(NO_FANCY_STUFF) && defined(DEBUG)
if (debug_fs)
printf("<%d, %d, %d>", sector, byte_offset, byte_len);
printf ("<%d, %d, %d>", sector, byte_offset, byte_len);
#endif /* !NO_FANCY_STUFF && DEBUG */
/*
@ -209,21 +209,21 @@ devread(int sector, int byte_offset, int byte_len, int addr)
* -- It doesn't handle offsets of more than 511 bytes into the
* sector.
*/
return rawread(current_drive, part_start+sector, byte_offset,
return rawread (current_drive, part_start + sector, byte_offset,
byte_len, addr);
}
int
sane_partition(void)
sane_partition (void)
{
if ( !(current_partition & 0xFF000000uL)
if (!(current_partition & 0xFF000000uL)
&& (current_drive & 0xFFFFFF7F) < 8
&& (current_partition & 0xFF) == 0xFF
&& ( (current_partition & 0xFF00) == 0xFF00
|| (current_partition & 0xFF00) < 0x800 )
&& ( (current_partition >> 16) == 0xFF
|| (current_drive & 0x80) ) )
&& ((current_partition & 0xFF00) == 0xFF00
|| (current_partition & 0xFF00) < 0x800)
&& ((current_partition >> 16) == 0xFF
|| (current_drive & 0x80)))
return 1;
errnum = ERR_DEV_VALUES;
@ -232,10 +232,10 @@ sane_partition(void)
static void
attempt_mount(void)
attempt_mount (void)
{
for ( fsys_type = 0; fsys_type < NUM_FSYS
&& (*(fsys_table[fsys_type].mount_func))() != 1; fsys_type++);
for (fsys_type = 0; fsys_type < NUM_FSYS
&& (*(fsys_table[fsys_type].mount_func)) () != 1; fsys_type++);
if (fsys_type == NUM_FSYS && errnum == ERR_NONE)
errnum = ERR_FSYS_MOUNT;
@ -244,7 +244,7 @@ attempt_mount(void)
#ifndef NO_FANCY_STUFF
int
make_saved_active(void)
make_saved_active (void)
{
if (saved_drive & 0x80)
{
@ -256,21 +256,21 @@ make_saved_active(void)
return 0;
}
if (!rawread(saved_drive, 0, 0, SECTOR_SIZE, SCRATCHADDR))
if (!rawread (saved_drive, 0, 0, SECTOR_SIZE, SCRATCHADDR))
return 0;
if (PC_SLICE_FLAG(SCRATCHADDR, part) != PC_SLICE_FLAG_BOOTABLE)
if (PC_SLICE_FLAG (SCRATCHADDR, part) != PC_SLICE_FLAG_BOOTABLE)
{
int i;
for (i = 0; i < 4; i++)
PC_SLICE_FLAG(SCRATCHADDR, i) = 0;
PC_SLICE_FLAG (SCRATCHADDR, i) = 0;
PC_SLICE_FLAG(SCRATCHADDR, part) = PC_SLICE_FLAG_BOOTABLE;
PC_SLICE_FLAG (SCRATCHADDR, part) = PC_SLICE_FLAG_BOOTABLE;
buf_track = -1;
if (biosdisk(BIOSDISK_SUBFUNC_WRITE, saved_drive, buf_geom,
if (biosdisk (BIOSDISK_SUBFUNC_WRITE, saved_drive, buf_geom,
0, 1, SCRATCHSEG))
{
errnum = ERR_WRITE;
@ -284,57 +284,57 @@ make_saved_active(void)
static void
check_and_print_mount(void)
check_and_print_mount (void)
{
attempt_mount();
attempt_mount ();
if (errnum == ERR_FSYS_MOUNT)
errnum = ERR_NONE;
if (!errnum)
print_fsys_type();
print_error();
print_fsys_type ();
print_error ();
}
#endif /* NO_FANCY_STUFF */
static int
check_BSD_parts(int flags)
check_BSD_parts (int flags)
{
char label_buf[SECTOR_SIZE];
int part_no, got_part = 0;
if ( part_length < (BSD_LABEL_SECTOR+1) )
if (part_length < (BSD_LABEL_SECTOR + 1))
{
errnum = ERR_BAD_PART_TABLE;
return 0;
}
if (!rawread(current_drive, part_start + BSD_LABEL_SECTOR,
if (!rawread (current_drive, part_start + BSD_LABEL_SECTOR,
0, SECTOR_SIZE, (int) label_buf))
return 0;
if ( BSD_LABEL_CHECK_MAG(label_buf) )
if (BSD_LABEL_CHECK_MAG (label_buf))
{
for (part_no = 0; part_no < BSD_LABEL_NPARTS(label_buf); part_no++)
for (part_no = 0; part_no < BSD_LABEL_NPARTS (label_buf); part_no++)
{
if (BSD_PART_TYPE(label_buf, part_no))
if (BSD_PART_TYPE (label_buf, part_no))
{
/* XXX should do BAD144 sector remapping setup here */
current_slice = ((BSD_PART_TYPE(label_buf, part_no) << 8)
current_slice = ((BSD_PART_TYPE (label_buf, part_no) << 8)
| PC_SLICE_TYPE_BSD);
part_start = BSD_PART_START(label_buf, part_no);
part_length = BSD_PART_LENGTH(label_buf, part_no);
part_start = BSD_PART_START (label_buf, part_no);
part_length = BSD_PART_LENGTH (label_buf, part_no);
#ifndef NO_FANCY_STUFF
if (flags)
{
if (!got_part)
{
printf("[BSD sub-partitions immediately follow]\n");
printf ("[BSD sub-partitions immediately follow]\n");
got_part = 1;
}
printf(" BSD Partition num: \'%c\', ", part_no + 'a');
check_and_print_mount();
printf (" BSD Partition num: \'%c\', ", part_no + 'a');
check_and_print_mount ();
}
else
#endif /* NO_FANCY_STUFF */
@ -343,14 +343,14 @@ check_BSD_parts(int flags)
}
}
if (part_no >= BSD_LABEL_NPARTS(label_buf) && !got_part)
if (part_no >= BSD_LABEL_NPARTS (label_buf) && !got_part)
{
errnum = ERR_NO_PART;
return 0;
}
if ((current_drive & 0x80)
&& BSD_LABEL_DTYPE(label_buf) == DTYPE_SCSI)
&& BSD_LABEL_DTYPE (label_buf) == DTYPE_SCSI)
bsd_evil_hack = 4;
return 1;
@ -364,7 +364,7 @@ check_BSD_parts(int flags)
static char cur_part_desc[16];
static int
real_open_partition(int flags)
real_open_partition (int flags)
{
char mbr_buf[SECTOR_SIZE];
int i, part_no, slice_no, ext = 0, part_offset = 0;
@ -373,14 +373,14 @@ real_open_partition(int flags)
* The "rawread" is probably unnecessary here, but it is good to
* know it works.
*/
if ( !sane_partition()
|| !rawread(current_drive, 0, 0, SECTOR_SIZE, (int) mbr_buf) )
if (!sane_partition ()
|| !rawread (current_drive, 0, 0, SECTOR_SIZE, (int) mbr_buf))
return 0;
bsd_evil_hack = 0;
current_slice = 0;
part_start = 0;
part_length = SECTORS(buf_geom) * HEADS(buf_geom) * CYLINDERS(buf_geom);
part_length = SECTORS (buf_geom) * HEADS (buf_geom) * CYLINDERS (buf_geom);
if (current_drive & 0x80)
{
@ -399,15 +399,15 @@ real_open_partition(int flags)
/*
* Load the current MBR-style PC partition table (4 entries)
*/
while ( slice_no < 255 && ext >= 0
while (slice_no < 255 && ext >= 0
&& (part_no == 0xFF || slice_no <= part_no)
&& rawread(current_drive, part_offset,
0, SECTOR_SIZE, (int) mbr_buf) )
&& rawread (current_drive, part_offset,
0, SECTOR_SIZE, (int) mbr_buf))
{
/*
* If the table isn't valid, we can't continue
*/
if ( !PC_MBR_CHECK_SIG(mbr_buf) )
if (!PC_MBR_CHECK_SIG (mbr_buf))
{
errnum = ERR_BAD_PART_TABLE;
return 0;
@ -422,10 +422,10 @@ real_open_partition(int flags)
{
current_partition = ((slice_no << 16)
| (current_partition & 0xFFFF));
current_slice = PC_SLICE_TYPE(mbr_buf, i);
part_start = part_offset + PC_SLICE_START(mbr_buf, i);
part_length = PC_SLICE_LENGTH(mbr_buf, i);
bcopy(mbr_buf+PC_SLICE_OFFSET+(i<<4), cur_part_desc, 16);
current_slice = PC_SLICE_TYPE (mbr_buf, i);
part_start = part_offset + PC_SLICE_START (mbr_buf, i);
part_length = PC_SLICE_LENGTH (mbr_buf, i);
bcopy (mbr_buf + PC_SLICE_OFFSET + (i << 4), cur_part_desc, 16);
/*
* Is this PC partition entry valid?
@ -449,11 +449,11 @@ real_open_partition(int flags)
else if (flags)
{
current_partition |= 0xFFFF;
printf(" Partition num: %d, ", slice_no);
printf (" Partition num: %d, ", slice_no);
if (current_slice != PC_SLICE_TYPE_BSD)
check_and_print_mount();
check_and_print_mount ();
else
check_BSD_parts(1);
check_BSD_parts (1);
errnum = ERR_NONE;
}
#endif /* NO_FANCY_STUFF */
@ -467,7 +467,7 @@ real_open_partition(int flags)
if ((current_partition & 0xFF00) != 0xFF00)
{
if (current_slice == PC_SLICE_TYPE_BSD)
check_BSD_parts(0);
check_BSD_parts (0);
else
errnum = ERR_NO_PART;
}
@ -488,7 +488,7 @@ real_open_partition(int flags)
slice_no++;
}
part_offset = ext_offset + PC_SLICE_START(mbr_buf, ext);
part_offset = ext_offset + PC_SLICE_START (mbr_buf, ext);
if (!ext_offset)
ext_offset = part_offset;
}
@ -500,7 +500,7 @@ real_open_partition(int flags)
*/
ext = -1;
if ((flags || (current_partition & 0xFF00) != 0xFF00)
&& check_BSD_parts(flags))
&& check_BSD_parts (flags))
ext = -2;
else
{
@ -518,7 +518,7 @@ real_open_partition(int flags)
else
{
current_partition = 0xFFFFFF;
check_and_print_mount();
check_and_print_mount ();
errnum = 0;
}
#endif /* NO_FANCY_STUFF */
@ -536,24 +536,25 @@ real_open_partition(int flags)
int
open_partition(void)
open_partition (void)
{
return real_open_partition(0);
return real_open_partition (0);
}
/* XX used for device completion in 'set_device' and 'print_completions' */
static int incomplete, disk_choice;
static enum
{
{
PART_UNSPECIFIED = 0,
PART_DISK,
PART_CHOSEN,
} part_choice;
}
part_choice;
char *
set_device(char *device)
set_device (char *device)
{
/* The use of retval in this function is not really clean, but it works */
char *retval = 0;
@ -571,10 +572,10 @@ set_device(char *device)
char ch = *device;
if ((*device == 'f' || *device == 'h')
&& (device += 2, (*(device-1) != 'd')))
&& (device += 2, (*(device - 1) != 'd')))
errnum = ERR_NUMBER_PARSING;
safe_parse_maxint(&device, (int*)&current_drive);
safe_parse_maxint (&device, (int *) &current_drive);
disk_choice = 0;
if (ch == 'h')
@ -602,7 +603,7 @@ set_device(char *device)
current_partition = 0;
if (!(current_drive & 0x80)
|| !safe_parse_maxint(&device, (int*)&current_partition)
|| !safe_parse_maxint (&device, (int *) &current_partition)
|| current_partition > 254)
{
errnum = ERR_DEV_FORMAT;
@ -612,7 +613,7 @@ set_device(char *device)
current_partition = (current_partition << 16) + 0xFFFF;
if (*device == ','
&& *(device+1) >= 'a' && *(device+1) <= 'h')
&& *(device + 1) >= 'a' && *(device + 1) <= 'h')
{
device++;
current_partition = (((*(device++) - 'a') << 8)
@ -657,10 +658,10 @@ set_device(char *device)
*/
int
open_device(void)
open_device (void)
{
if (open_partition())
attempt_mount();
if (open_partition ())
attempt_mount ();
if (errnum != ERR_NONE)
return 0;
@ -671,14 +672,14 @@ open_device(void)
#ifndef NO_FANCY_STUFF
int
set_bootdev(int hdbias)
set_bootdev (int hdbias)
{
int i, j;
/*
* Set chainloader boot device.
*/
bcopy(cur_part_desc, (char *)(BOOTSEC_LOCATION-16), 16);
bcopy (cur_part_desc, (char *) (BOOTSEC_LOCATION - 16), 16);
/*
* Set BSD boot device.
@ -694,29 +695,29 @@ set_bootdev(int hdbias)
if (saved_drive & 0x80)
j = bsd_evil_hack;
return MAKEBOOTDEV( j, (i >> 4), (i & 0xF),
return MAKEBOOTDEV (j, (i >> 4), (i & 0xF),
((saved_drive - hdbias) & 0x79),
((saved_partition >> 8) & 0xFF) );
((saved_partition >> 8) & 0xFF));
}
#endif /* NO_FANCY_STUFF */
static char *
setup_part(char *filename)
setup_part (char *filename)
{
if (*filename == '(')
{
if ( (filename = set_device(filename)) == 0 )
if ((filename = set_device (filename)) == 0)
{
current_drive = 0xFF;
return 0;
}
#ifndef NO_BLOCK_FILES
if (*filename != '/')
open_partition();
open_partition ();
else
#endif /* NO_BLOCK_FILES */
open_device();
open_device ();
}
else if (saved_drive != current_drive
|| saved_partition != current_partition
@ -729,10 +730,10 @@ setup_part(char *filename)
is found. This makes block files work fine on no filesystem */
#ifndef NO_BLOCK_FILES
if (*filename != '/')
open_partition();
open_partition ();
else
#endif /* NO_BLOCK_FILES */
open_device();
open_device ();
}
if (errnum && (*filename == '/' || errnum != ERR_FSYS_MOUNT))
@ -740,7 +741,7 @@ setup_part(char *filename)
else
errnum = 0;
if (!sane_partition())
if (!sane_partition ())
return 0;
return filename;
@ -753,19 +754,19 @@ setup_part(char *filename)
*/
void
print_fsys_type(void)
print_fsys_type (void)
{
printf(" Filesystem type ");
printf (" Filesystem type ");
if (fsys_type != NUM_FSYS)
printf("is %s, ", fsys_table[fsys_type].name);
printf ("is %s, ", fsys_table[fsys_type].name);
else
printf("unknown, ");
printf ("unknown, ");
if (current_partition == 0xFFFFFF)
printf("using whole disk\n");
printf ("using whole disk\n");
else
printf("partition type 0x%x\n", current_slice);
printf ("partition type 0x%x\n", current_slice);
}
/*
@ -774,11 +775,11 @@ print_fsys_type(void)
*/
void
print_completions(char *filename)
print_completions (char *filename)
{
char *ptr = filename;
if (*filename == '/' || (ptr = set_device(filename)) || incomplete)
if (*filename == '/' || (ptr = set_device (filename)) || incomplete)
{
errnum = 0;
@ -789,7 +790,7 @@ print_completions(char *filename)
/* disk completions */
int disk_no, i, j;
printf(" Possible disks are: ");
printf (" Possible disks are: ");
for (i = 0; i < 2; i++)
{
@ -797,39 +798,39 @@ print_completions(char *filename)
{
disk_no = (i * 0x80) + j;
if ((disk_choice || disk_no == current_drive)
&& get_diskinfo(disk_no))
printf(" %cd%d", (i ? 'h' : 'f'), j);
&& get_diskinfo (disk_no))
printf (" %cd%d", (i ? 'h' : 'f'), j);
}
}
putchar('\n');
putchar ('\n');
}
else
{
/* partition completions */
if (part_choice == PART_DISK)
{
printf(" Possible partitions are:\n");
real_open_partition(1);
printf (" Possible partitions are:\n");
real_open_partition (1);
}
else
{
if (open_partition())
check_and_print_mount();
if (open_partition ())
check_and_print_mount ();
}
}
}
else if (*ptr == '/')
{
/* filename completions */
printf(" Possible files are:");
dir(filename);
printf (" Possible files are:");
dir (filename);
}
else
errnum = ERR_BAD_FILENAME;
}
print_error();
print_error ();
}
#endif /* NO_FANCY_STUFF */
@ -839,7 +840,7 @@ print_completions(char *filename)
*/
int
open(char *filename)
open (char *filename)
{
#ifndef NO_DECOMPRESSION
compressed_file = 0;
@ -849,7 +850,7 @@ open(char *filename)
set it to zero before returning if opening a file! */
filepos = 0;
if (!(filename = setup_part(filename)))
if (!(filename = setup_part (filename)))
return 0;
#ifndef NO_BLOCK_FILES
@ -869,12 +870,12 @@ open(char *filename)
while (list_addr < BLK_MAX_ADDR)
{
tmp = 0;
safe_parse_maxint(&ptr, &tmp);
safe_parse_maxint (&ptr, &tmp);
errnum = 0;
if (*ptr != '+')
{
if ((*ptr && *ptr != '/' && !isspace(*ptr))
if ((*ptr && *ptr != '/' && !isspace (*ptr))
|| tmp == 0 || tmp > filemax)
errnum = ERR_BAD_FILENAME;
else
@ -887,18 +888,18 @@ open(char *filename)
be remounted */
fsys_type = NUM_FSYS;
BLK_BLKSTART(list_addr) = tmp;
BLK_BLKSTART (list_addr) = tmp;
ptr++;
if (!safe_parse_maxint(&ptr, &tmp)
if (!safe_parse_maxint (&ptr, &tmp)
|| tmp == 0
|| (*ptr && *ptr != ',' && *ptr != '/' && !isspace(*ptr)))
|| (*ptr && *ptr != ',' && *ptr != '/' && !isspace (*ptr)))
{
errnum = ERR_BAD_FILENAME;
break;
}
BLK_BLKLENGTH(list_addr) = tmp;
BLK_BLKLENGTH (list_addr) = tmp;
filemax += (tmp * SECTOR_SIZE);
list_addr += BLK_BLKLIST_INC_VAL;
@ -917,7 +918,7 @@ open(char *filename)
BLK_CUR_BLKNUM = 0;
#ifndef NO_DECOMPRESSION
return gunzip_test_header();
return gunzip_test_header ();
#else /* NO_DECOMPRESSION */
return 1;
#endif /* NO_DECOMPRESSION */
@ -933,10 +934,10 @@ open(char *filename)
/* set "dir" function to open a file */
print_possibilities = 0;
if (!errnum && (*(fsys_table[fsys_type].dir_func))(filename))
if (!errnum && (*(fsys_table[fsys_type].dir_func)) (filename))
{
#ifndef NO_DECOMPRESSION
return gunzip_test_header();
return gunzip_test_header ();
#else /* NO_DECOMPRESSION */
return 1;
#endif /* NO_DECOMPRESSION */
@ -947,7 +948,7 @@ open(char *filename)
int
read(int addr, int len)
read (int addr, int len)
{
/* Make sure "filepos" is a sane value */
if ((filepos < 0) | (filepos > filemax))
@ -960,7 +961,7 @@ read(int addr, int len)
/* if target file position is past the end of
the supported/configured filesize, then
there is an error */
if (filepos+len > fsmax)
if (filepos + len > fsmax)
{
errnum = ERR_FILELENGTH;
return 0;
@ -968,7 +969,7 @@ read(int addr, int len)
#ifndef NO_DECOMPRESSION
if (compressed_file)
return gunzip_read(addr, len);
return gunzip_read (addr, len);
#endif /* NO_DECOMPRESSION */
#ifndef NO_BLOCK_FILES
@ -987,15 +988,15 @@ read(int addr, int len)
}
/* run BLK_CUR_FILEPOS up to filepos */
while ( filepos > BLK_CUR_FILEPOS )
while (filepos > BLK_CUR_FILEPOS)
{
if ( (filepos - (BLK_CUR_FILEPOS & ~(SECTOR_SIZE - 1)))
>= SECTOR_SIZE )
if ((filepos - (BLK_CUR_FILEPOS & ~(SECTOR_SIZE - 1)))
>= SECTOR_SIZE)
{
BLK_CUR_FILEPOS += SECTOR_SIZE;
BLK_CUR_BLKNUM++;
if ( BLK_CUR_BLKNUM >= BLK_BLKLENGTH(BLK_CUR_BLKLIST) )
if (BLK_CUR_BLKNUM >= BLK_BLKLENGTH (BLK_CUR_BLKLIST))
{
BLK_CUR_BLKLIST += BLK_BLKLIST_INC_VAL;
BLK_CUR_BLKNUM = 0;
@ -1006,8 +1007,8 @@ read(int addr, int len)
}
off = filepos & (SECTOR_SIZE - 1);
size = ( ( BLK_BLKLENGTH(BLK_CUR_BLKLIST) - BLK_CUR_BLKNUM )
* SECTOR_SIZE ) - off;
size = ((BLK_BLKLENGTH (BLK_CUR_BLKLIST) - BLK_CUR_BLKNUM)
* SECTOR_SIZE) - off;
if (size > len)
size = len;
@ -1016,7 +1017,7 @@ read(int addr, int len)
#endif /* NO_FANCY_STUFF */
/* read current block and put it in the right place in memory */
devread(BLK_BLKSTART(BLK_CUR_BLKLIST) + BLK_CUR_BLKNUM,
devread (BLK_BLKSTART (BLK_CUR_BLKLIST) + BLK_CUR_BLKNUM,
off, size, addr);
#ifndef NO_FANCY_STUFF
@ -1042,18 +1043,18 @@ read(int addr, int len)
return 0;
}
return (*(fsys_table[fsys_type].read_func))(addr, len);
return (*(fsys_table[fsys_type].read_func)) (addr, len);
}
int
dir(char *dirname)
dir (char *dirname)
{
#ifndef NO_DECOMPRESSION
compressed_file = 0;
#endif /* NO_DECOMPRESSION */
if (!(dirname = setup_part(dirname)))
if (!(dirname = setup_part (dirname)))
return 0;
if (*dirname != '/')
@ -1068,5 +1069,5 @@ dir(char *dirname)
/* set "dir" function to list completions */
print_possibilities = 1;
return (*(fsys_table[fsys_type].dir_func))(dirname);
return (*(fsys_table[fsys_type].dir_func)) (dirname);
}

View file

@ -111,4 +111,3 @@
(*((unsigned short *) (entry+26)))
#define FAT_DIRENTRY_FILELENGTH(entry) \
(*((unsigned long *) (entry+28)))

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -35,18 +36,18 @@
#ifdef FSYS_FFS
#define FSYS_FFS_NUM 1
int ffs_mount(void);
int ffs_read(int addr, int len);
int ffs_dir(char *dirname);
int ffs_mount (void);
int ffs_read (int addr, int len);
int ffs_dir (char *dirname);
#else
#define FSYS_FFS_NUM 0
#endif
#ifdef FSYS_FAT
#define FSYS_FAT_NUM 1
int fat_mount(void);
int fat_mount (void);
/* XX FAT filesystem uses block filesystem code for read! */
int fat_dir(char *dirname);
int fat_dir (char *dirname);
#ifdef NO_BLOCK_FILES
#undef NO_BLOCK_FILES
#endif /* NO_BLOCK_FILES */
@ -56,9 +57,9 @@ int fat_dir(char *dirname);
#ifdef FSYS_EXT2FS
#define FSYS_EXT2FS_NUM 1
int ext2fs_mount(void);
int ext2fs_read(int addr, int len);
int ext2fs_dir(char *dirname);
int ext2fs_mount (void);
int ext2fs_read (int addr, int len);
int ext2fs_dir (char *dirname);
#else
#define FSYS_EXT2FS_NUM 0
#endif
@ -82,38 +83,37 @@ int ext2fs_dir(char *dirname);
/* this next part is pretty ugly, but it keeps it in one place! */
struct fsys_entry
{
{
char *name;
int (*mount_func)(void);
int (*read_func)(int addr, int len);
int (*dir_func)(char *dirname);
};
int (*mount_func) (void);
int (*read_func) (int addr, int len);
int (*dir_func) (char *dirname);
};
#ifndef _DISK_IO_C
extern int fsmax;
extern int print_possibilities;
extern struct fsys_entry fsys_table[NUM_FSYS+1];
extern struct fsys_entry fsys_table[NUM_FSYS + 1];
#else
int fsmax;
int print_possibilities;
struct fsys_entry fsys_table[NUM_FSYS+1] =
struct fsys_entry fsys_table[NUM_FSYS + 1] =
{
#ifdef FSYS_FAT
{ "fat", fat_mount, 0, fat_dir },
{"fat", fat_mount, 0, fat_dir},
#endif
#ifdef FSYS_EXT2FS
{ "ext2fs", ext2fs_mount, ext2fs_read, ext2fs_dir },
{"ext2fs", ext2fs_mount, ext2fs_read, ext2fs_dir},
#endif
/* XX FFS should come last as it's superblock is commonly crossing tracks
on floppies from track 1 to 2, while others only use 1. */
#ifdef FSYS_FFS
{ "ffs", ffs_mount, ffs_read, ffs_dir },
{"ffs", ffs_mount, ffs_read, ffs_dir},
#endif
{ 0, 0, 0, 0 }
{0, 0, 0, 0}
};
#endif

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -71,7 +72,8 @@
* Flags are used to indicate the validity of fields where zero is a
* normal value.
*/
struct bootinfo {
struct bootinfo
{
unsigned int bi_version;
unsigned char *bi_kernelname;
struct nfs_diskless *bi_nfs_diskless;
@ -86,5 +88,4 @@ struct bootinfo {
unsigned long bi_extmem;
unsigned long bi_symtab;
unsigned long bi_esymtab;
};
};

View file

@ -1,3 +1,4 @@
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
@ -131,21 +132,22 @@
* N.B. sizeof(struct csum) must be a power of two in order for
* the ``fs_cs'' macro to work (see below).
*/
struct csum {
struct csum
{
int cs_ndir; /* number of directories */
int cs_nbfree; /* number of free blocks */
int cs_nifree; /* number of free inodes */
int cs_nffree; /* number of free frags */
};
};
/*
* Super block for a file system.
*/
#define FS_MAGIC 0x011954
struct fs
{
int xxx1; /* struct fs *fs_link;*/
int xxx2; /* struct fs *fs_rlink;*/
{
int xxx1; /* struct fs *fs_link; */
int xxx2; /* struct fs *fs_rlink; */
daddr_t fs_sblkno; /* addr of super-block in filesys */
daddr_t fs_cblkno; /* offset of cyl-block in filesys */
daddr_t fs_iblkno; /* offset of inode-blocks in filesys */
@ -215,7 +217,7 @@ struct fs
#if 1
int was_fs_csp[MAXCSBUFS];
#else
struct csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
struct csum *fs_csp[MAXCSBUFS]; /* list of fs_cs info buffers */
#endif
int fs_cpc; /* cyl per cycle in postbl */
short fs_opostbl[16][8]; /* old rotation block list head */
@ -234,7 +236,7 @@ struct fs
int fs_magic; /* magic number */
u_char fs_space[1]; /* list of blocks for each rotation */
/* actually longer */
};
};
/*
* Preference for optimization.
*/
@ -270,8 +272,9 @@ struct fs
* Cylinder group block for a file system.
*/
#define CG_MAGIC 0x090255
struct cg {
int xxx1; /* struct cg *cg_link;*/
struct cg
{
int xxx1; /* struct cg *cg_link; */
int cg_magic; /* magic number */
time_t cg_time; /* time last written */
int cg_cgx; /* we are the cgx'th cylinder group */
@ -291,7 +294,7 @@ struct cg {
int cg_sparecon[16]; /* reserved for future use */
u_char cg_space[1]; /* space for cylinder group maps */
/* actually longer */
};
};
/*
* Macros for access to cylinder group array structures
*/
@ -318,9 +321,10 @@ struct cg {
* The following structure is defined
* for compatibility with old file systems.
*/
struct ocg {
int xxx1; /* struct ocg *cg_link;*/
int xxx2; /* struct ocg *cg_rlink;*/
struct ocg
{
int xxx1; /* struct ocg *cg_link; */
int xxx2; /* struct ocg *cg_rlink; */
time_t cg_time; /* time last written */
int cg_cgx; /* we are the cgx'th cylinder group */
short cg_ncyl; /* number of cyl's this cg */
@ -337,7 +341,7 @@ struct ocg {
int cg_magic; /* magic number */
u_char cg_free[1]; /* free block map */
/* actually longer */
};
};
/*
* Turn file system block numbers into disk block addresses.
@ -452,4 +456,3 @@ struct ocg {
* NINDIR is the number of indirects in a file system block.
*/
#define NINDIR(fs) ((fs)->fs_nindir)

View file

@ -52,7 +52,8 @@ typedef unsigned int __u32;
#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
/* include/linux/ext2_fs.h */
struct ext2_super_block {
struct ext2_super_block
{
__u32 s_inodes_count; /* Inodes count */
__u32 s_blocks_count; /* Blocks count */
__u32 s_r_blocks_count; /* Reserved blocks count */
@ -79,10 +80,10 @@ struct ext2_super_block {
__u16 s_def_resuid; /* Default uid for reserved blocks */
__u16 s_def_resgid; /* Default gid for reserved blocks */
__u32 s_reserved[235]; /* Padding to the end of the block */
};
};
struct ext2_group_desc
{
{
__u32 bg_block_bitmap; /* Blocks bitmap block */
__u32 bg_inode_bitmap; /* Inodes bitmap block */
__u32 bg_inode_table; /* Inodes table block */
@ -91,9 +92,10 @@ struct ext2_group_desc
__u16 bg_used_dirs_count; /* Directories count */
__u16 bg_pad;
__u32 bg_reserved[3];
};
};
struct ext2_inode {
struct ext2_inode
{
__u16 i_mode; /* File mode */
__u16 i_uid; /* Owner Uid */
__u32 i_size; /* 4: Size in bytes */
@ -105,45 +107,61 @@ struct ext2_inode {
__u16 i_links_count; /* 24: Links count */
__u32 i_blocks; /* Blocks count */
__u32 i_flags; /* 32: File flags */
union {
struct {
union
{
struct
{
__u32 l_i_reserved1;
} linux1;
struct {
}
linux1;
struct
{
__u32 h_i_translator;
} hurd1;
struct {
}
hurd1;
struct
{
__u32 m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS];/* 40: Pointers to blocks */
}
masix1;
}
osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS]; /* 40: Pointers to blocks */
__u32 i_version; /* File version (for NFS) */
__u32 i_file_acl; /* File ACL */
__u32 i_dir_acl; /* Directory ACL */
__u32 i_faddr; /* Fragment address */
union {
struct {
union
{
struct
{
__u8 l_i_frag; /* Fragment number */
__u8 l_i_fsize; /* Fragment size */
__u16 i_pad1;
__u32 l_i_reserved2[2];
} linux2;
struct {
}
linux2;
struct
{
__u8 h_i_frag; /* Fragment number */
__u8 h_i_fsize; /* Fragment size */
__u16 h_i_mode_high;
__u16 h_i_uid_high;
__u16 h_i_gid_high;
__u32 h_i_author;
} hurd2;
struct {
}
hurd2;
struct
{
__u8 m_i_frag; /* Fragment number */
__u8 m_i_fsize; /* Fragment size */
__u16 m_pad1;
__u32 m_i_reserved2[2];
} masix2;
} osd2; /* OS dependent 2 */
};
}
masix2;
}
osd2; /* OS dependent 2 */
};
/* linux/limits.h */
#define NAME_MAX 255 /* # chars in a file name */
@ -153,12 +171,13 @@ typedef long off_t;
/* linux/ext2fs.h */
#define EXT2_NAME_LEN 255
struct ext2_dir_entry {
struct ext2_dir_entry
{
__u32 inode; /* Inode number */
__u16 rec_len; /* Directory entry length */
__u16 name_len; /* Name length */
char name[EXT2_NAME_LEN]; /* File name */
};
};
/* linux/ext2fs.h */
/*
@ -219,25 +238,26 @@ struct ext2_dir_entry {
* ffz = Find First Zero in word. Undefined if no zero exists,
* so code should check against ~0UL first..
*/
__inline__ unsigned long ffz(unsigned long word)
__inline__ unsigned long
ffz (unsigned long word)
{
__asm__("bsfl %1,%0"
:"=r" (word)
:"r" (~word));
__asm__ ("bsfl %1,%0"
: "=r" (word)
: "r" (~word));
return word;
}
/* check filesystem types and read superblock into memory buffer */
int
ext2fs_mount(void)
ext2fs_mount (void)
{
int retval = 1;
if ( (((current_drive & 0x80) || (current_slice != 0))
if ((((current_drive & 0x80) || (current_slice != 0))
&& (current_slice != PC_SLICE_TYPE_EXT2FS)
&& (current_slice != (PC_SLICE_TYPE_BSD | (FS_OTHER<<8))))
|| part_length < (SBLOCK + (sizeof(struct ext2_super_block)/DEV_BSIZE))
|| !devread(SBLOCK, 0, sizeof(struct ext2_super_block), (int)SUPERBLOCK)
&& (current_slice != (PC_SLICE_TYPE_BSD | (FS_OTHER << 8))))
|| part_length < (SBLOCK + (sizeof (struct ext2_super_block) / DEV_BSIZE))
|| !devread (SBLOCK, 0, sizeof (struct ext2_super_block), (int) SUPERBLOCK)
|| SUPERBLOCK->s_magic != EXT2_SUPER_MAGIC)
retval = 0;
@ -248,12 +268,13 @@ ext2fs_mount(void)
takes a file system block number and reads it into area pointed
to by buffer */
int
ext2_rdfsb (int fsblock, int buffer) {
ext2_rdfsb (int fsblock, int buffer)
{
#ifdef E2DEBUG
printf("fsblock %d buffer %d\n", fsblock, buffer);
printf ("fsblock %d buffer %d\n", fsblock, buffer);
#endif /* E2DEBUG */
return devread(fsblock * (EXT2_BLOCK_SIZE(SUPERBLOCK) / DEV_BSIZE), 0,
EXT2_BLOCK_SIZE(SUPERBLOCK), (int)buffer);
return devread (fsblock * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE), 0,
EXT2_BLOCK_SIZE (SUPERBLOCK), (int) buffer);
}
/* from
@ -263,26 +284,34 @@ ext2_rdfsb (int fsblock, int buffer) {
maps "logical block" (the file offset div blocksize) into
"physical blocks" (the location in the file system) via an inode */
int
ext2fs_block_map(int logical_block)
ext2fs_block_map (int logical_block)
{
#ifdef E2DEBUG
unsigned char * i;
for (i = (unsigned char *)INODE;
i < ((unsigned char *)INODE + sizeof(struct ext2_inode));
i++) {
printf("%c", "0123456789abcdef"[*i >> 4]);
printf("%c", "0123456789abcdef"[*i % 16]);
if (!((i + 1 - (unsigned char *)INODE) % 16)) { printf("\n"); }
else { printf(" "); }
unsigned char *i;
for (i = (unsigned char *) INODE;
i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
i++)
{
printf ("%c", "0123456789abcdef"[*i >> 4]);
printf ("%c", "0123456789abcdef"[*i % 16]);
if (!((i + 1 - (unsigned char *) INODE) % 16))
{
printf ("\n");
}
printf("logical block %d\n", logical_block);
else
{
printf (" ");
}
}
printf ("logical block %d\n", logical_block);
#endif /* E2DEBUG */
/* if it is directly pointed to by the inode, return that physical addr */
if (logical_block < EXT2_NDIR_BLOCKS) {
if (logical_block < EXT2_NDIR_BLOCKS)
{
#ifdef E2DEBUG
printf ("returning %d\n", (unsigned char *)(INODE->i_block[logical_block]));
printf ("returning %d\n", (unsigned char *) (INODE->i_block[logical_block]));
printf ("returning %d\n", INODE->i_block[logical_block]);
#endif /* E2DEBUG */
return INODE->i_block[logical_block];
@ -290,66 +319,75 @@ ext2fs_block_map(int logical_block)
/* else */
logical_block -= EXT2_NDIR_BLOCKS;
/* try the indirect block */
if (logical_block < EXT2_ADDR_PER_BLOCK(SUPERBLOCK)) {
if ( mapblock1 != 1
&& !ext2_rdfsb(INODE->i_block[EXT2_IND_BLOCK], DATABLOCK1)) {
if (logical_block < EXT2_ADDR_PER_BLOCK (SUPERBLOCK))
{
if (mapblock1 != 1
&& !ext2_rdfsb (INODE->i_block[EXT2_IND_BLOCK], DATABLOCK1))
{
errnum = ERR_FSYS_CORRUPT;
return -1;
}
mapblock1 = 1;
return ((__u32 *)DATABLOCK1)[logical_block];
return ((__u32 *) DATABLOCK1)[logical_block];
}
/* else */
logical_block -= EXT2_ADDR_PER_BLOCK(SUPERBLOCK);
logical_block -= EXT2_ADDR_PER_BLOCK (SUPERBLOCK);
/* now try the double indirect block */
if (logical_block < (1 << (EXT2_ADDR_PER_BLOCK_BITS(SUPERBLOCK) * 2))) {
if (logical_block < (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2)))
{
int bnum;
if ( mapblock1 != 2
&& !ext2_rdfsb(INODE->i_block[EXT2_DIND_BLOCK], DATABLOCK1)) {
if (mapblock1 != 2
&& !ext2_rdfsb (INODE->i_block[EXT2_DIND_BLOCK], DATABLOCK1))
{
errnum = ERR_FSYS_CORRUPT;
return -1;
}
mapblock1 = 2;
if ( (bnum = (((__u32 *)DATABLOCK1)
[logical_block >> EXT2_ADDR_PER_BLOCK_BITS(SUPERBLOCK)]))
if ((bnum = (((__u32 *) DATABLOCK1)
[logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)]))
!= mapblock2
&& !ext2_rdfsb(bnum, DATABLOCK2)) {
&& !ext2_rdfsb (bnum, DATABLOCK2))
{
errnum = ERR_FSYS_CORRUPT;
return -1;
}
mapblock2 = bnum;
return ((__u32 *)DATABLOCK2)
[logical_block & (EXT2_ADDR_PER_BLOCK(SUPERBLOCK) - 1)];
return ((__u32 *) DATABLOCK2)
[logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
}
/* else */
mapblock2 = -1;
logical_block -= (1 << (EXT2_ADDR_PER_BLOCK_BITS(SUPERBLOCK) * 2));
if ( mapblock1 != 3
&& !ext2_rdfsb(INODE->i_block[EXT2_TIND_BLOCK], DATABLOCK1)) {
logical_block -= (1 << (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK) * 2));
if (mapblock1 != 3
&& !ext2_rdfsb (INODE->i_block[EXT2_TIND_BLOCK], DATABLOCK1))
{
errnum = ERR_FSYS_CORRUPT;
return -1;
}
mapblock1 = 3;
if (!ext2_rdfsb(((__u32 *)DATABLOCK1)
[logical_block >> (EXT2_ADDR_PER_BLOCK_BITS(SUPERBLOCK)*2)],
DATABLOCK2)) {
if (!ext2_rdfsb (((__u32 *) DATABLOCK1)
[logical_block >> (EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)
* 2)],
DATABLOCK2))
{
errnum = ERR_FSYS_CORRUPT;
return -1;
}
if (!ext2_rdfsb(((__u32 *)DATABLOCK2)
[(logical_block >> EXT2_ADDR_PER_BLOCK_BITS(SUPERBLOCK))
& (EXT2_ADDR_PER_BLOCK(SUPERBLOCK) - 1)],
DATABLOCK2)) {
if (!ext2_rdfsb (((__u32 *) DATABLOCK2)
[(logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK))
& (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)],
DATABLOCK2))
{
errnum = ERR_FSYS_CORRUPT;
return -1;
}
return ((__u32 *)DATABLOCK2)
[logical_block & (EXT2_ADDR_PER_BLOCK(SUPERBLOCK)-1)];
return ((__u32 *) DATABLOCK2)
[logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)];
}
/* preconditions: all preconds of ext2fs_block_map */
int
ext2fs_read(int addr, int len)
ext2fs_read (int addr, int len)
{
int logical_block;
int offset;
@ -359,28 +397,36 @@ ext2fs_read(int addr, int len)
#ifdef E2DEBUG
static char hexdigit[] = "0123456789abcdef";
unsigned char * i;
for (i = (unsigned char *)INODE;
i < ((unsigned char *)INODE + sizeof(struct ext2_inode));
i++) {
printf("%c", hexdigit[*i >> 4]);
printf("%c", hexdigit[*i % 16]);
if (!((i + 1 - (unsigned char *)INODE) % 16)) { printf("\n"); }
else { printf(" "); }
unsigned char *i;
for (i = (unsigned char *) INODE;
i < ((unsigned char *) INODE + sizeof (struct ext2_inode));
i++)
{
printf ("%c", hexdigit[*i >> 4]);
printf ("%c", hexdigit[*i % 16]);
if (!((i + 1 - (unsigned char *) INODE) % 16))
{
printf ("\n");
}
else
{
printf (" ");
}
}
#endif /* E2DEBUG */
while(len > 0) {
while (len > 0)
{
/* find the (logical) block component of our location */
logical_block = filepos >> EXT2_BLOCK_SIZE_BITS(SUPERBLOCK);
offset = filepos & (EXT2_BLOCK_SIZE(SUPERBLOCK) - 1);
map = ext2fs_block_map(logical_block);
logical_block = filepos >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
offset = filepos & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
map = ext2fs_block_map (logical_block);
#ifdef E2DEBUG
printf("map=%d\n", map);
printf ("map=%d\n", map);
#endif /* E2DEBUG */
if (map < 0)
break;
size = EXT2_BLOCK_SIZE(SUPERBLOCK);
size = EXT2_BLOCK_SIZE (SUPERBLOCK);
size -= offset;
if (size > len)
size = len;
@ -389,7 +435,7 @@ ext2fs_read(int addr, int len)
debug_fs_func = debug_fs;
#endif /* NO_FANCY_STUFF */
devread(map * (EXT2_BLOCK_SIZE(SUPERBLOCK) / DEV_BSIZE),
devread (map * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE),
offset, size, addr);
#ifndef NO_FANCY_STUFF
@ -440,7 +486,7 @@ ext2fs_read(int addr, int len)
* side effects: messes up GROUP_DESC buffer area
*/
int
ext2fs_dir(char *dirname)
ext2fs_dir (char *dirname)
{
int current_ino = EXT2_ROOT_INO; /* start at the root */
int updir_ino = current_ino; /* the parent of the current directory */
@ -449,8 +495,8 @@ ext2fs_dir(char *dirname)
int desc; /* index within that group */
int ino_blk; /* fs pointer of the inode's information */
int str_chk; /* used to hold the results of a string compare */
struct ext2_group_desc * gdp;
struct ext2_inode * raw_inode; /* inode info corresponding to current_ino */
struct ext2_group_desc *gdp;
struct ext2_inode *raw_inode; /* inode info corresponding to current_ino */
char linkbuf[PATH_MAX]; /* buffer for following symbolic links */
int link_count = 0;
@ -465,7 +511,7 @@ ext2fs_dir(char *dirname)
struct ext2_dir_entry *dp; /* pointer to directory entry */
#ifdef E2DEBUG
unsigned char *i;
#endif E2DEBUG
#endif /* E2DEBUG */
/* loop invariants:
current_ino = inode to lookup
@ -473,34 +519,37 @@ ext2fs_dir(char *dirname)
the directory known pointed to by current_ino (if any)
*/
while (1) {
while (1)
{
#ifdef E2DEBUG
printf("inode %d\n", current_ino);
printf("dirname=%s\n", dirname);
printf ("inode %d\n", current_ino);
printf ("dirname=%s\n", dirname);
#endif /* E2DEBUG */
/* look up an inode */
group_id = (current_ino - 1) / (SUPERBLOCK->s_inodes_per_group);
group_desc = group_id >> log2(EXT2_DESC_PER_BLOCK(SUPERBLOCK));
desc = group_id & (EXT2_DESC_PER_BLOCK(SUPERBLOCK) - 1);
group_desc = group_id >> log2 (EXT2_DESC_PER_BLOCK (SUPERBLOCK));
desc = group_id & (EXT2_DESC_PER_BLOCK (SUPERBLOCK) - 1);
#ifdef E2DEBUG
printf("ipg=%d, dpb=%d\n", SUPERBLOCK->s_inodes_per_group,
EXT2_DESC_PER_BLOCK(SUPERBLOCK));
printf("group_id=%d group_desc=%d desc=%d\n", group_id, group_desc, desc);
printf ("ipg=%d, dpb=%d\n", SUPERBLOCK->s_inodes_per_group,
EXT2_DESC_PER_BLOCK (SUPERBLOCK));
printf ("group_id=%d group_desc=%d desc=%d\n", group_id, group_desc, desc);
#endif /* E2DEBUG */
if (!ext2_rdfsb(
if (!ext2_rdfsb (
(WHICH_SUPER + group_desc + SUPERBLOCK->s_first_data_block),
(int)GROUP_DESC)) {
(int) GROUP_DESC))
{
return 0;
}
gdp = GROUP_DESC;
ino_blk = gdp[desc].bg_inode_table +
(((current_ino - 1) % (SUPERBLOCK->s_inodes_per_group))
>> log2(EXT2_BLOCK_SIZE(SUPERBLOCK) / sizeof(struct ext2_inode)));
>> log2 (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)));
#ifdef E2DEBUG
printf("inode table fsblock=%d\n", ino_blk);
printf ("inode table fsblock=%d\n", ino_blk);
#endif /* E2DEBUG */
if (!ext2_rdfsb(ino_blk, (int)INODE)) {
if (!ext2_rdfsb (ino_blk, (int) INODE))
{
return 0;
}
@ -509,34 +558,42 @@ ext2fs_dir(char *dirname)
raw_inode = INODE +
((current_ino - 1)
& (EXT2_BLOCK_SIZE(SUPERBLOCK) / sizeof(struct ext2_inode) - 1));
& (EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode) - 1));
#ifdef E2DEBUG
printf("ipb=%d, sizeof(inode)=%d\n",
(EXT2_BLOCK_SIZE(SUPERBLOCK) / sizeof(struct ext2_inode)),
sizeof(struct ext2_inode));
printf("inode=%x, raw_inode=%x\n", INODE, raw_inode);
printf("offset into inode table block=%d\n", (int)raw_inode - (int)INODE);
for (i = (unsigned char *)INODE; i <= (unsigned char *)raw_inode; i++) {
printf("%c", "0123456789abcdef"[*i >> 4]);
printf("%c", "0123456789abcdef"[*i % 16]);
if (!((i + 1 - (unsigned char *)INODE) % 16)) { printf("\n"); }
else { printf(" "); }
printf ("ipb=%d, sizeof(inode)=%d\n",
(EXT2_BLOCK_SIZE (SUPERBLOCK) / sizeof (struct ext2_inode)),
sizeof (struct ext2_inode));
printf ("inode=%x, raw_inode=%x\n", INODE, raw_inode);
printf ("offset into inode table block=%d\n", (int) raw_inode - (int) INODE);
for (i = (unsigned char *) INODE; i <= (unsigned char *) raw_inode;
i++)
{
printf ("%c", "0123456789abcdef"[*i >> 4]);
printf ("%c", "0123456789abcdef"[*i % 16]);
if (!((i + 1 - (unsigned char *) INODE) % 16))
{
printf ("\n");
}
printf("first word=%x\n", *((int *)raw_inode));
else
{
printf (" ");
}
}
printf ("first word=%x\n", *((int *) raw_inode));
#endif /* E2DEBUG */
/* copy inode to fixed location */
bcopy((void *)raw_inode, (void *)INODE, sizeof(struct ext2_inode));
bcopy ((void *) raw_inode, (void *) INODE, sizeof (struct ext2_inode));
#ifdef E2DEBUG
printf("first word=%x\n", *((int *)INODE));
printf ("first word=%x\n", *((int *) INODE));
#endif /* E2DEBUG */
/* If we've got a symbolic link, then chase it. */
if (S_ISLNK(INODE->i_mode))
if (S_ISLNK (INODE->i_mode))
{
int len, remaining;
if (++ link_count > MAX_LINK_COUNT)
if (++link_count > MAX_LINK_COUNT)
{
errnum = ERR_SYMLINK_LOOP;
return 0;
@ -545,7 +602,7 @@ ext2fs_dir(char *dirname)
/* Find out how long our remaining name is. */
len = 0;
while (dirname[len] && !isspace (dirname[len]))
len ++;
len++;
/* Get the symlink size. */
filemax = (INODE->i_size);
@ -601,9 +658,9 @@ ext2fs_dir(char *dirname)
}
/* if end of filename, INODE points to the file's inode */
if (!*dirname || isspace(*dirname))
if (!*dirname || isspace (*dirname))
{
if (!S_ISREG(INODE->i_mode))
if (!S_ISREG (INODE->i_mode))
{
errnum = ERR_BAD_FILETYPE;
return 0;
@ -621,33 +678,38 @@ ext2fs_dir(char *dirname)
dirname++;
/* if this isn't a directory of sufficient size to hold our file, abort */
if (!(INODE->i_size) || !S_ISDIR(INODE->i_mode))
if (!(INODE->i_size) || !S_ISDIR (INODE->i_mode))
{
errnum = ERR_BAD_FILETYPE;
return 0;
}
/* skip to next slash or end of filename (space) */
for (rest = dirname; (ch = *rest) && !isspace(ch) && ch != '/'; rest++) ;
for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/';
rest++);
/* look through this directory and find the next filename component */
/* invariant: rest points to slash after the next filename component */
*rest = 0;
loc = 0;
do {
do
{
#ifdef E2DEBUG
printf("dirname=%s, rest=%s, loc=%d\n", dirname, rest, loc);
printf ("dirname=%s, rest=%s, loc=%d\n", dirname, rest, loc);
#endif /* E2DEBUG */
/* if our location/byte offset into the directory exceeds the size,
give up */
if (loc >= INODE->i_size) {
if (print_possibilities < 0) {
putchar('\n');
if (loc >= INODE->i_size)
{
if (print_possibilities < 0)
{
putchar ('\n');
}
else {
else
{
errnum = ERR_FILE_NOT_FOUND;
*rest = ch;
}
@ -655,32 +717,33 @@ ext2fs_dir(char *dirname)
}
/* else, find the (logical) block component of our location */
blk = loc >> EXT2_BLOCK_SIZE_BITS(SUPERBLOCK);
blk = loc >> EXT2_BLOCK_SIZE_BITS (SUPERBLOCK);
/* we know which logical block of the directory entry we are looking
for, now we have to translate that to the physical (fs) block on
the disk */
map = ext2fs_block_map(blk);
map = ext2fs_block_map (blk);
#ifdef E2DEBUG
printf("fs block=%d\n", map);
printf ("fs block=%d\n", map);
#endif /* E2DEBUG */
mapblock2 = -1;
if ((map < 0) || !ext2_rdfsb(map, DATABLOCK2)) {
if ((map < 0) || !ext2_rdfsb (map, DATABLOCK2))
{
errnum = ERR_FSYS_CORRUPT;
*rest = ch;
return 0;
}
off = loc & (EXT2_BLOCK_SIZE(SUPERBLOCK) - 1);
dp = (struct ext2_dir_entry *)(DATABLOCK2 + off);
off = loc & (EXT2_BLOCK_SIZE (SUPERBLOCK) - 1);
dp = (struct ext2_dir_entry *) (DATABLOCK2 + off);
/* advance loc prematurely to next on-disk directory entry */
loc += dp->rec_len;
/* NOTE: ext2fs filenames are NOT null-terminated */
#ifdef E2DEBUG
printf("directory entry ino=%d\n", dp->inode);
printf ("directory entry ino=%d\n", dp->inode);
if (dp->inode)
printf("entry=%s\n", dp->name);
printf ("entry=%s\n", dp->name);
#endif /* E2DEBUG */
if (dp->inode)
@ -688,20 +751,21 @@ ext2fs_dir(char *dirname)
int saved_c = dp->name[dp->name_len];
dp->name[dp->name_len] = 0;
str_chk = substring(dirname, dp->name);
str_chk = substring (dirname, dp->name);
if (print_possibilities && ch != '/'
&& (!*dirname || str_chk <= 0))
{
if (print_possibilities > 0)
print_possibilities = -print_possibilities;
printf(" %s", dp->name);
printf (" %s", dp->name);
}
dp->name[dp->name_len] = saved_c;
}
} while (!dp->inode || (str_chk || (print_possibilities && ch != '/')) );
}
while (!dp->inode || (str_chk || (print_possibilities && ch != '/')));
current_ino = dp->inode;
*(dirname = rest) = ch;

View file

@ -34,27 +34,27 @@ static int fat_size;
#define FAT_BUF ( FSYS_BUF + 30208 ) /* 4 sector FAT buffer */
int
fat_mount(void)
fat_mount (void)
{
int retval = 1;
if ( (((current_drive & 0x80) || (current_slice != 0))
if ((((current_drive & 0x80) || (current_slice != 0))
&& (current_slice != PC_SLICE_TYPE_FAT12)
&& (current_slice != PC_SLICE_TYPE_FAT16_LT32M)
&& (current_slice != PC_SLICE_TYPE_FAT16_GT32M)
&& (current_slice != (PC_SLICE_TYPE_BSD | (FS_MSDOS<<8))))
|| !devread(0, 0, SECTOR_SIZE, BPB)
|| FAT_BPB_BYTES_PER_SECTOR(BPB) != SECTOR_SIZE
|| FAT_BPB_SECT_PER_CLUST(BPB) < 1 || FAT_BPB_SECT_PER_CLUST(BPB) > 64
|| (FAT_BPB_SECT_PER_CLUST(BPB) & (FAT_BPB_SECT_PER_CLUST(BPB) - 1))
|| !( (current_drive & 0x80)
|| FAT_BPB_FLOPPY_NUM_SECTORS(BPB) ) )
&& (current_slice != (PC_SLICE_TYPE_BSD | (FS_MSDOS << 8))))
|| !devread (0, 0, SECTOR_SIZE, BPB)
|| FAT_BPB_BYTES_PER_SECTOR (BPB) != SECTOR_SIZE
|| FAT_BPB_SECT_PER_CLUST (BPB) < 1 || FAT_BPB_SECT_PER_CLUST (BPB) > 64
|| (FAT_BPB_SECT_PER_CLUST (BPB) & (FAT_BPB_SECT_PER_CLUST (BPB) - 1))
|| !((current_drive & 0x80)
|| FAT_BPB_FLOPPY_NUM_SECTORS (BPB)))
retval = 0;
else
{
mapblock = -4096;
data_offset = FAT_BPB_DATA_OFFSET(BPB);
num_clust = FAT_BPB_NUM_CLUST(BPB) + 2;
data_offset = FAT_BPB_DATA_OFFSET (BPB);
num_clust = FAT_BPB_NUM_CLUST (BPB) + 2;
if (num_clust > FAT_MAX_12BIT_CLUST)
fat_size = 4;
else
@ -66,7 +66,7 @@ fat_mount(void)
static int
fat_create_blocklist(int first_fat_entry)
fat_create_blocklist (int first_fat_entry)
{
BLK_CUR_FILEPOS = 0;
BLK_CUR_BLKNUM = 0;
@ -78,11 +78,12 @@ fat_create_blocklist(int first_fat_entry)
{
/* root directory */
BLK_BLKSTART(BLK_BLKLIST_START) = FAT_BPB_ROOT_DIR_START(BPB);
fsmax = filemax = SECTOR_SIZE * (BLK_BLKLENGTH(BLK_BLKLIST_START)
= FAT_BPB_ROOT_DIR_LENGTH(BPB));
BLK_BLKSTART (BLK_BLKLIST_START) = FAT_BPB_ROOT_DIR_START (BPB);
fsmax = filemax = SECTOR_SIZE * (BLK_BLKLENGTH (BLK_BLKLIST_START)
= FAT_BPB_ROOT_DIR_LENGTH (BPB));
}
else /* any real directory/file */
else
/* any real directory/file */
{
int blk_cur_blklist = BLK_BLKLIST_START, blk_cur_blknum;
int last_fat_entry, new_mapblock;
@ -91,13 +92,13 @@ fat_create_blocklist(int first_fat_entry)
do
{
BLK_BLKSTART(blk_cur_blklist)
= (first_fat_entry-2) * FAT_BPB_SECT_PER_CLUST(BPB) + data_offset;
BLK_BLKSTART (blk_cur_blklist)
= (first_fat_entry - 2) * FAT_BPB_SECT_PER_CLUST (BPB) + data_offset;
blk_cur_blknum = 0;
do
{
blk_cur_blknum += FAT_BPB_SECT_PER_CLUST(BPB);
blk_cur_blknum += FAT_BPB_SECT_PER_CLUST (BPB);
last_fat_entry = first_fat_entry;
/*
@ -108,9 +109,9 @@ fat_create_blocklist(int first_fat_entry)
if (new_mapblock > (mapblock + 2045)
|| new_mapblock < (mapblock + 3))
{
mapblock = ( (new_mapblock < 6) ? 0 :
((new_mapblock - 6) & ~0x1FF) );
if (!devread((mapblock>>9)+FAT_BPB_FAT_START(BPB),
mapblock = ((new_mapblock < 6) ? 0 :
((new_mapblock - 6) & ~0x1FF));
if (!devread ((mapblock >> 9) + FAT_BPB_FAT_START (BPB),
0, SECTOR_SIZE * 4, FAT_BUF))
return 0;
}
@ -135,7 +136,7 @@ fat_create_blocklist(int first_fat_entry)
while (first_fat_entry == (last_fat_entry + 1)
&& first_fat_entry < num_clust);
BLK_BLKLENGTH(blk_cur_blklist) = blk_cur_blknum;
BLK_BLKLENGTH (blk_cur_blklist) = blk_cur_blknum;
fsmax += blk_cur_blknum * SECTOR_SIZE;
blk_cur_blklist += BLK_BLKLIST_INC_VAL;
}
@ -151,7 +152,7 @@ fat_create_blocklist(int first_fat_entry)
int
fat_dir(char *dirname)
fat_dir (char *dirname)
{
char *rest, ch, filename[13], dir_buf[FAT_DIRENTRY_LENGTH];
int attrib = FAT_ATTRIB_DIR, map = -1;
@ -159,13 +160,13 @@ fat_dir(char *dirname)
/* main loop to find desired directory entry */
loop:
if (!fat_create_blocklist(map))
if (!fat_create_blocklist (map))
return 0;
/* if we have a real file (and we're not just printing possibilities),
then this is where we want to exit */
if (!*dirname || isspace(*dirname))
if (!*dirname || isspace (*dirname))
{
if (attrib & FAT_ATTRIB_DIR)
{
@ -189,19 +190,19 @@ loop:
return 0;
}
for (rest = dirname; (ch = *rest) && !isspace(ch) && ch != '/'; rest++) ;
for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++);
*rest = 0;
do
{
if (read((int)dir_buf, FAT_DIRENTRY_LENGTH) != FAT_DIRENTRY_LENGTH)
if (read ((int) dir_buf, FAT_DIRENTRY_LENGTH) != FAT_DIRENTRY_LENGTH)
{
if (!errnum)
{
if (print_possibilities < 0)
{
putchar('\n');
putchar ('\n');
return 1;
}
@ -212,43 +213,43 @@ loop:
return 0;
}
if (!FAT_DIRENTRY_VALID(dir_buf))
if (!FAT_DIRENTRY_VALID (dir_buf))
continue;
/* XXX convert to 8.3 filename format here */
{
int i, j, c;
for (i = 0; i < 8 && (c = filename[i] = tolower(dir_buf[i]))
&& !isspace(c) ; i++) ;
for (i = 0; i < 8 && (c = filename[i] = tolower (dir_buf[i]))
&& !isspace (c); i++);
filename[i++] = '.';
for (j = 0; j < 3 && (c = filename[i+j] = tolower(dir_buf[8+j]))
&& !isspace(c) ; j++) ;
for (j = 0; j < 3 && (c = filename[i + j] = tolower (dir_buf[8 + j]))
&& !isspace (c); j++);
if (j == 0)
i--;
filename[i+j] = 0;
filename[i + j] = 0;
}
if (print_possibilities && ch != '/'
&& (!*dirname || substring(dirname, filename) <= 0))
&& (!*dirname || substring (dirname, filename) <= 0))
{
if (print_possibilities > 0)
print_possibilities = -print_possibilities;
printf(" %s", filename);
printf (" %s", filename);
}
}
while (substring(dirname, filename) != 0 ||
while (substring (dirname, filename) != 0 ||
(print_possibilities && ch != '/'));
*(dirname = rest) = ch;
attrib = FAT_DIRENTRY_ATTRIB(dir_buf);
filemax = FAT_DIRENTRY_FILELENGTH(dir_buf);
map = FAT_DIRENTRY_FIRST_CLUSTER(dir_buf);
attrib = FAT_DIRENTRY_ATTRIB (dir_buf);
filemax = FAT_DIRENTRY_FILELENGTH (dir_buf);
map = FAT_DIRENTRY_FIRST_CLUSTER (dir_buf);
/* go back to main loop at top of function */
goto loop;

View file

@ -75,15 +75,15 @@ static int mapblock;
int
ffs_mount(void)
ffs_mount (void)
{
int retval = 1;
if ( (((current_drive & 0x80) || (current_slice != 0))
&& current_slice != (PC_SLICE_TYPE_BSD | (FS_BSDFFS<<8)))
|| part_length < (SBLOCK + (SBSIZE/DEV_BSIZE))
|| !devread(SBLOCK, 0, SBSIZE, (int) SUPERBLOCK)
|| SUPERBLOCK->fs_magic != FS_MAGIC )
if ((((current_drive & 0x80) || (current_slice != 0))
&& current_slice != (PC_SLICE_TYPE_BSD | (FS_BSDFFS << 8)))
|| part_length < (SBLOCK + (SBSIZE / DEV_BSIZE))
|| !devread (SBLOCK, 0, SBSIZE, (int) SUPERBLOCK)
|| SUPERBLOCK->fs_magic != FS_MAGIC)
retval = 0;
mapblock = -1;
@ -92,16 +92,16 @@ ffs_mount(void)
}
int
block_map(int file_block)
block_map (int file_block)
{
int bnum;
if (file_block < NDADDR)
return(INODE->i_db[file_block]);
return (INODE->i_db[file_block]);
if ( (bnum = fsbtodb(SUPERBLOCK, INODE->i_ib[0])) != mapblock )
if ((bnum = fsbtodb (SUPERBLOCK, INODE->i_ib[0])) != mapblock)
{
if (!devread(bnum, 0, SUPERBLOCK->fs_bsize, MAPBUF))
if (!devread (bnum, 0, SUPERBLOCK->fs_bsize, MAPBUF))
{
mapblock = -1;
errnum = ERR_FSYS_CORRUPT;
@ -111,22 +111,22 @@ block_map(int file_block)
mapblock = bnum;
}
return (((int *)MAPBUF)[(file_block - NDADDR) % NINDIR(SUPERBLOCK)]);
return (((int *) MAPBUF)[(file_block - NDADDR) % NINDIR (SUPERBLOCK)]);
}
int
ffs_read(int addr, int len)
ffs_read (int addr, int len)
{
int logno, off, size, map, ret = 0;
while (len && !errnum)
{
off = blkoff(SUPERBLOCK, filepos);
logno = lblkno(SUPERBLOCK, filepos);
size = blksize(SUPERBLOCK, INODE, logno);
off = blkoff (SUPERBLOCK, filepos);
logno = lblkno (SUPERBLOCK, filepos);
size = blksize (SUPERBLOCK, INODE, logno);
if ((map = block_map(logno)) < 0)
if ((map = block_map (logno)) < 0)
break;
size -= off;
@ -138,7 +138,7 @@ ffs_read(int addr, int len)
debug_fs_func = debug_fs;
#endif /* NO_FANCY_STUFF */
devread(fsbtodb(SUPERBLOCK, map), off, size, addr);
devread (fsbtodb (SUPERBLOCK, map), off, size, addr);
#ifndef NO_FANCY_STUFF
debug_fs_func = NULL;
@ -158,7 +158,7 @@ ffs_read(int addr, int len)
int
ffs_dir(char *dirname)
ffs_dir (char *dirname)
{
char *rest, ch;
int block, off, loc, map, ino = ROOTINO;
@ -169,17 +169,17 @@ loop:
/* load current inode (defaults to the root inode) */
if (!devread(fsbtodb(SUPERBLOCK,itod(SUPERBLOCK,ino)),
if (!devread (fsbtodb (SUPERBLOCK, itod (SUPERBLOCK, ino)),
0, SUPERBLOCK->fs_bsize, FSYS_BUF))
return 0; /* XXX what return value? */
bcopy((void *)&(((struct dinode *)FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]),
(void *)INODE, sizeof (struct dinode));
bcopy ((void *) &(((struct dinode *) FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]),
(void *) INODE, sizeof (struct dinode));
/* if we have a real file (and we're not just printing possibilities),
then this is where we want to exit */
if (!*dirname || isspace(*dirname))
if (!*dirname || isspace (*dirname))
{
if ((INODE->i_mode & IFMT) != IFREG)
{
@ -190,7 +190,7 @@ loop:
filemax = INODE->i_size;
/* incomplete implementation requires this! */
fsmax = (NDADDR + NINDIR(SUPERBLOCK)) * SUPERBLOCK->fs_bsize;
fsmax = (NDADDR + NINDIR (SUPERBLOCK)) * SUPERBLOCK->fs_bsize;
return 1;
}
@ -205,7 +205,7 @@ loop:
return 0;
}
for (rest = dirname; (ch = *rest) && !isspace(ch) && ch != '/'; rest++) ;
for (rest = dirname; (ch = *rest) && !isspace (ch) && ch != '/'; rest++);
*rest = 0;
loc = 0;
@ -216,7 +216,7 @@ loop:
{
if (loc >= INODE->i_size)
{
putchar('\n');
putchar ('\n');
if (print_possibilities < 0)
return 1;
@ -226,13 +226,13 @@ loop:
return 0;
}
if (!(off = blkoff(SUPERBLOCK, loc)))
if (!(off = blkoff (SUPERBLOCK, loc)))
{
block = lblkno(SUPERBLOCK, loc);
block = lblkno (SUPERBLOCK, loc);
if ( (map = block_map(block)) < 0
|| !devread(fsbtodb(SUPERBLOCK, map), 0,
blksize(SUPERBLOCK, INODE, block), FSYS_BUF) )
if ((map = block_map (block)) < 0
|| !devread (fsbtodb (SUPERBLOCK, map), 0,
blksize (SUPERBLOCK, INODE, block), FSYS_BUF))
{
errnum = ERR_FSYS_CORRUPT;
*rest = ch;
@ -240,20 +240,20 @@ loop:
}
}
dp = (struct direct *)(FSYS_BUF + off);
dp = (struct direct *) (FSYS_BUF + off);
loc += dp->d_reclen;
if (dp->d_ino && print_possibilities && ch != '/'
&& (!*dirname || substring(dirname, dp->d_name) <= 0))
&& (!*dirname || substring (dirname, dp->d_name) <= 0))
{
if (print_possibilities > 0)
print_possibilities = -print_possibilities;
printf(" %s", dp->d_name);
printf (" %s", dp->d_name);
}
}
while (!dp->d_ino || (substring(dirname, dp->d_name) != 0
|| (print_possibilities && ch != '/')) );
while (!dp->d_ino || (substring (dirname, dp->d_name) != 0
|| (print_possibilities && ch != '/')));
/* only get here if we have a matching directory entry */

View file

@ -151,7 +151,7 @@ static int code_state;
/* Function prototypes */
static void initialize_tables(void);
static void initialize_tables (void);
/*
* Linear allocator.
@ -160,14 +160,14 @@ static void initialize_tables(void);
static unsigned long linalloc_topaddr;
static void *
linalloc(int size)
linalloc (int size)
{
linalloc_topaddr = (linalloc_topaddr - size) & ~3;
return (void *)linalloc_topaddr;
return (void *) linalloc_topaddr;
}
static void
reset_linalloc(void)
reset_linalloc (void)
{
linalloc_topaddr = (mbi.mem_upper << 10) + 0x100000;
}
@ -175,7 +175,7 @@ reset_linalloc(void)
/* internal variable swap function */
static void
gunzip_swap_values(void)
gunzip_swap_values (void)
{
register int itmp;
@ -198,7 +198,7 @@ gunzip_swap_values(void)
/* internal function for eating variable-length header fields */
static int
bad_field(int len)
bad_field (int len)
{
char ch = 1;
int not_retval = 1;
@ -216,7 +216,7 @@ bad_field(int len)
break;
}
}
while ((not_retval = read((int)&ch, 1)) == 1);
while ((not_retval = read ((int) &ch, 1)) == 1);
return (!not_retval);
}
@ -265,7 +265,7 @@ typedef unsigned long ulg;
int
gunzip_test_header(void)
gunzip_test_header (void)
{
unsigned char buf[10];
@ -276,7 +276,7 @@ gunzip_test_header(void)
* (other than a real error with the disk) then we don't think it
* is a compressed file, and simply mark it as such.
*/
if (no_decompression || read((int)buf, 10) != 10
if (no_decompression || read ((int) buf, 10) != 10
|| ((*((unsigned short *) buf) != GZIP_HDR_LE)
& (*((unsigned short *) buf) != OLD_GZIP_HDR_LE)))
{
@ -291,11 +291,11 @@ gunzip_test_header(void)
*/
if (buf[2] != DEFLATED || (buf[3] & UNSUPP_FLAGS)
|| ((buf[3] & EXTRA_FIELD)
&& (read((int)buf, 2) != 2 || bad_field(*((unsigned short *) buf))))
|| ((buf[3] & ORIG_NAME) && bad_field(-1))
|| ((buf[3] & COMMENT) && bad_field(-1))
&& (read ((int) buf, 2) != 2 || bad_field (*((unsigned short *) buf))))
|| ((buf[3] & ORIG_NAME) && bad_field (-1))
|| ((buf[3] & COMMENT) && bad_field (-1))
|| ((gzip_data_offset = filepos), (filepos = filemax - 8),
(read((int)buf, 8) != 8)))
(read ((int) buf, 8) != 8)))
{
if (!errnum)
errnum = ERR_BAD_GZIP_HEADER;
@ -304,12 +304,12 @@ gunzip_test_header(void)
}
gzip_crc = *((unsigned long *) buf);
gzip_fsmax = gzip_filemax = *((unsigned long *) (buf+4));
gzip_fsmax = gzip_filemax = *((unsigned long *) (buf + 4));
initialize_tables();
initialize_tables ();
compressed_file = 1;
gunzip_swap_values();
gunzip_swap_values ();
/*
* Now "gzip_*" values refer to the compressed data.
*/
@ -327,13 +327,16 @@ gunzip_test_header(void)
the next table, which codes e - 16 bits, and lastly e == 99 indicates
an unused code. If a code with e == 99 is looked up, this implies an
error in the data. */
struct huft {
struct huft
{
uch e; /* number of extra bits or operation */
uch b; /* number of bits in this code or subcode */
union {
union
{
ush n; /* literal, length base, or distance base */
struct huft *t; /* pointer to next level of table */
} v;
}
v;
};
@ -355,20 +358,25 @@ static unsigned wp;
/* Tables for deflate from PKZIP's appnote.txt. */
static unsigned border[] = { /* Order of the bit length code lengths */
static unsigned border[] =
{ /* Order of the bit length code lengths */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
static ush cplens[] = { /* Copy lengths for literal codes 257..285 */
static ush cplens[] =
{ /* Copy lengths for literal codes 257..285 */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
/* note: see note #13 above about the 258 in this list. */
static ush cplext[] = { /* Extra bits for literal codes 257..285 */
static ush cplext[] =
{ /* Extra bits for literal codes 257..285 */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */
static ush cpdist[] = { /* Copy offsets for distance codes 0..29 */
static ush cpdist[] =
{ /* Copy offsets for distance codes 0..29 */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
static ush cpdext[] = { /* Extra bits for distance codes */
static ush cpdext[] =
{ /* Extra bits for distance codes */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
@ -452,7 +460,8 @@ static unsigned hufts; /* track memory usage */
static ulg bb; /* bit buffer */
static unsigned bk; /* bits in bit buffer */
static ush mask_bits[] = {
static ush mask_bits[] =
{
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
@ -467,12 +476,12 @@ static uch inbuf[INBUFSIZ];
static int bufloc;
static int
get_byte(void)
get_byte (void)
{
if (filepos == gzip_data_offset || bufloc == INBUFSIZ)
{
bufloc = 0;
read((int)inbuf, INBUFSIZ);
read ((int) inbuf, INBUFSIZ);
}
return inbuf[bufloc++];
@ -486,9 +495,9 @@ static int bd; /* lookup bits for td */
/* more function prototypes */
static int huft_build(unsigned *, unsigned, unsigned, ush *, ush *,
static int huft_build (unsigned *, unsigned, unsigned, ush *, ush *,
struct huft **, int *);
static int inflate_codes_in_window(void);
static int inflate_codes_in_window (void);
/* Given a list of code lengths and a maximum table size, make a set of
@ -498,16 +507,16 @@ static int inflate_codes_in_window(void);
oversubscribed set of lengths), and three if not enough memory. */
static int
huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
unsigned n, /* number of codes (assumed <= N_MAX) */
unsigned s, /* number of simple-valued codes (0..s-1) */
ush *d, /* list of base values for non-simple codes */
ush *e, /* list of extra bits for non-simple codes */
ush * d, /* list of base values for non-simple codes */
ush * e, /* list of extra bits for non-simple codes */
struct huft **t, /* result: starting table */
int *m) /* maximum lookup bits, returns actual */
{
unsigned a; /* counter for codes of length k */
unsigned c[BMAX+1]; /* bit length count table */
unsigned c[BMAX + 1]; /* bit length count table */
unsigned f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
@ -521,21 +530,24 @@ huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
struct huft *u[BMAX]; /* table stack */
unsigned v[N_MAX]; /* values in order of bit length */
register int w; /* bits before this table == (l * h) */
unsigned x[BMAX+1]; /* bit offsets, then code stack */
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
unsigned *xp; /* pointer into x */
int y; /* number of dummy codes added */
unsigned z; /* number of entries in current table */
/* Generate counts for each bit length */
bzero((char *)c, sizeof(c));
p = b; i = n;
do {
bzero ((char *) c, sizeof (c));
p = b;
i = n;
do
{
c[*p]++; /* assume all entries <= BMAX */
p++; /* Can't combine with above line (Solaris bug) */
} while (--i);
}
while (--i);
if (c[0] == n) /* null input--all zero length codes */
{
*t = (struct huft *)NULL;
*t = (struct huft *) NULL;
*m = 0;
return 0;
}
@ -546,13 +558,13 @@ huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
if (c[j])
break;
k = j; /* minimum code length */
if ((unsigned)l < j)
if ((unsigned) l < j)
l = j;
for (i = BMAX; i; i--)
if (c[i])
break;
g = i; /* maximum code length */
if ((unsigned)l > i)
if ((unsigned) l > i)
l = i;
*m = l;
@ -566,25 +578,30 @@ huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
/* Generate starting offsets into the value table for each length */
x[1] = j = 0;
p = c + 1; xp = x + 2;
while (--i) { /* note that i == g from above */
p = c + 1;
xp = x + 2;
while (--i)
{ /* note that i == g from above */
*xp++ = (j += *p++);
}
/* Make a table of values in order of bit lengths */
p = b; i = 0;
do {
p = b;
i = 0;
do
{
if ((j = *p++) != 0)
v[x[j]++] = i;
} while (++i < n);
}
while (++i < n);
/* Generate the Huffman codes and for each, make the table entries */
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
u[0] = (struct huft *)NULL; /* just to keep compilers happy */
q = (struct huft *)NULL; /* ditto */
u[0] = (struct huft *) NULL; /* just to keep compilers happy */
q = (struct huft *) NULL; /* ditto */
z = 0; /* ditto */
/* go through the bit lengths (k already is bits in shortest code) */
@ -601,7 +618,7 @@ huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
w += l; /* previous table always l bits */
/* compute minimum size table less than or equal to l bits */
z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */
z = (z = g - w) > (unsigned) l ? l : z; /* upper limit on table size */
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
@ -616,38 +633,38 @@ huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
z = 1 << j; /* table entries for j-bit table */
/* allocate and link in new table */
q = (struct huft *)linalloc((z + 1)*sizeof(struct huft));
q = (struct huft *) linalloc ((z + 1) * sizeof (struct huft));
hufts += z + 1; /* track memory usage */
*t = q + 1; /* link to list for huft_free() */
*(t = &(q->v.t)) = (struct huft *)NULL;
*(t = &(q->v.t)) = (struct huft *) NULL;
u[h] = ++q; /* table starts after link */
/* connect to last table, if there is one */
if (h)
{
x[h] = i; /* save pattern for backing up */
r.b = (uch)l; /* bits to dump before this table */
r.e = (uch)(16 + j); /* bits in this table */
r.b = (uch) l; /* bits to dump before this table */
r.e = (uch) (16 + j); /* bits in this table */
r.v.t = q; /* pointer to this table */
j = i >> (w - l); /* (get around Turbo C bug) */
u[h-1][j] = r; /* connect to last table */
u[h - 1][j] = r; /* connect to last table */
}
}
/* set up table entry in r */
r.b = (uch)(k - w);
r.b = (uch) (k - w);
if (p >= v + n)
r.e = 99; /* out of values--invalid code */
else if (*p < s)
{
r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */
r.v.n = (ush)(*p); /* simple code is just the value */
r.e = (uch) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */
r.v.n = (ush) (*p); /* simple code is just the value */
p++; /* one compiler does not like *p++ */
}
else
{
r.e = (uch)e[*p - s]; /* non-simple--look up in lists */
r.e = (uch) e[*p - s]; /* non-simple--look up in lists */
r.v.n = d[*p++ - s];
}
@ -683,7 +700,7 @@ huft_build(unsigned *b, /* code lengths in bits (all assumed <= BMAX) */
static unsigned inflate_n, inflate_d;
static int
inflate_codes_in_window(void)
inflate_codes_in_window (void)
{
register unsigned e; /* table entry flag/number of extra bits */
unsigned n, d; /* length and index for copy */
@ -707,27 +724,30 @@ inflate_codes_in_window(void)
{
if (!code_state)
{
NEEDBITS((unsigned)bl);
if ((e = (t = tl + ((unsigned)b & ml))->e) > 16)
do {
NEEDBITS ((unsigned) bl);
if ((e = (t = tl + ((unsigned) b & ml))->e) > 16)
do
{
if (e == 99)
{
errnum = ERR_BAD_GZIP_DATA;
return 0;
}
DUMPBITS(t->b);
DUMPBITS (t->b);
e -= 16;
NEEDBITS(e);
} while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
DUMPBITS(t->b);
NEEDBITS (e);
}
while ((e = (t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
DUMPBITS (t->b);
if (e == 16) /* then it's a literal */
{
slide[w++] = (uch)t->v.n;
slide[w++] = (uch) t->v.n;
if (w == WSIZE)
break;
}
else /* it's an EOB or a length */
else
/* it's an EOB or a length */
{
/* exit if end of block */
if (e == 15)
@ -737,27 +757,30 @@ inflate_codes_in_window(void)
}
/* get length of block to copy */
NEEDBITS(e);
n = t->v.n + ((unsigned)b & mask_bits[e]);
DUMPBITS(e);
NEEDBITS (e);
n = t->v.n + ((unsigned) b & mask_bits[e]);
DUMPBITS (e);
/* decode distance of block to copy */
NEEDBITS((unsigned)bd);
if ((e = (t = td + ((unsigned)b & md))->e) > 16)
do {
NEEDBITS ((unsigned) bd);
if ((e = (t = td + ((unsigned) b & md))->e) > 16)
do
{
if (e == 99)
{
errnum = ERR_BAD_GZIP_DATA;
return 0;
}
DUMPBITS(t->b);
DUMPBITS (t->b);
e -= 16;
NEEDBITS(e);
} while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16);
DUMPBITS(t->b);
NEEDBITS(e);
d = w - t->v.n - ((unsigned)b & mask_bits[e]);
DUMPBITS(e);
NEEDBITS (e);
}
while ((e = (t = t->v.t + ((unsigned) b & mask_bits[e]))->e)
> 16);
DUMPBITS (t->b);
NEEDBITS (e);
d = w - t->v.n - ((unsigned) b & mask_bits[e]);
DUMPBITS (e);
code_state++;
}
}
@ -765,22 +788,26 @@ inflate_codes_in_window(void)
if (code_state)
{
/* do the copy */
do {
n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
do
{
n -= (e = (e = WSIZE - ((d &= WSIZE - 1) > w ? d : w)) > n ? n
: e);
if (w - d >= e)
{
bcopy(slide + d, slide + w, e);
bcopy (slide + d, slide + w, e);
w += e;
d += e;
}
else /* purposefully use the overlap for extra copies here!! */
else
/* purposefully use the overlap for extra copies here!! */
{
while (e--)
slide[w++] = slide[d++];
}
if (w == WSIZE)
break;
} while (n);
}
while (n);
if (!n)
code_state--;
@ -805,7 +832,7 @@ inflate_codes_in_window(void)
/* get header for an inflated type 0 (stored) block. */
static void
init_stored_block(void)
init_stored_block (void)
{
register ulg b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
@ -815,16 +842,16 @@ init_stored_block(void)
k = bk;
/* go to byte boundary */
DUMPBITS(k & 7);
DUMPBITS (k & 7);
/* get the length and its complement */
NEEDBITS(16);
block_len = ((unsigned)b & 0xffff);
DUMPBITS(16);
NEEDBITS(16);
if (block_len != (unsigned)((~b) & 0xffff))
NEEDBITS (16);
block_len = ((unsigned) b & 0xffff);
DUMPBITS (16);
NEEDBITS (16);
if (block_len != (unsigned) ((~b) & 0xffff))
errnum = ERR_BAD_GZIP_DATA;
DUMPBITS(16);
DUMPBITS (16);
/* restore global variables */
bb = b;
@ -837,7 +864,7 @@ init_stored_block(void)
Huffman tables. */
static void
init_fixed_block()
init_fixed_block ()
{
int i; /* temporary variable */
unsigned l[288]; /* length list for huft_build */
@ -852,7 +879,7 @@ init_fixed_block()
for (; i < 288; i++) /* make a complete, but wrong code set */
l[i] = 8;
bl = 7;
if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
if ((i = huft_build (l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
{
errnum = ERR_BAD_GZIP_DATA;
return;
@ -862,7 +889,7 @@ init_fixed_block()
for (i = 0; i < 30; i++) /* make an incomplete code set */
l[i] = 5;
bd = 5;
if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
if ((i = huft_build (l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
{
errnum = ERR_BAD_GZIP_DATA;
return;
@ -877,7 +904,7 @@ init_fixed_block()
/* get header for an inflated type 2 (dynamic Huffman codes) block. */
static void
init_dynamic_block(void)
init_dynamic_block (void)
{
int i; /* temporary variables */
unsigned j;
@ -887,7 +914,7 @@ init_dynamic_block(void)
unsigned nb; /* number of bit length codes */
unsigned nl; /* number of literal/length codes */
unsigned nd; /* number of distance codes */
unsigned ll[286+30]; /* literal/length and distance code lengths */
unsigned ll[286 + 30]; /* literal/length and distance code lengths */
register ulg b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
@ -896,15 +923,15 @@ init_dynamic_block(void)
k = bk;
/* read in table lengths */
NEEDBITS(5);
nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */
DUMPBITS(5);
NEEDBITS(5);
nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */
DUMPBITS(5);
NEEDBITS(4);
nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */
DUMPBITS(4);
NEEDBITS (5);
nl = 257 + ((unsigned) b & 0x1f); /* number of literal/length codes */
DUMPBITS (5);
NEEDBITS (5);
nd = 1 + ((unsigned) b & 0x1f); /* number of distance codes */
DUMPBITS (5);
NEEDBITS (4);
nb = 4 + ((unsigned) b & 0xf); /* number of bit length codes */
DUMPBITS (4);
if (nl > 286 || nd > 30)
{
errnum = ERR_BAD_GZIP_DATA;
@ -914,16 +941,16 @@ init_dynamic_block(void)
/* read in bit-length-code lengths */
for (j = 0; j < nb; j++)
{
NEEDBITS(3);
ll[border[j]] = (unsigned)b & 7;
DUMPBITS(3);
NEEDBITS (3);
ll[border[j]] = (unsigned) b & 7;
DUMPBITS (3);
}
for (; j < 19; j++)
ll[border[j]] = 0;
/* build decoding table for trees--single level, 7 bit lookup */
bl = 7;
if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
if ((i = huft_build (ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
{
errnum = ERR_BAD_GZIP_DATA;
return;
@ -933,20 +960,20 @@ init_dynamic_block(void)
n = nl + nd;
m = mask_bits[bl];
i = l = 0;
while ((unsigned)i < n)
while ((unsigned) i < n)
{
NEEDBITS((unsigned)bl);
j = (td = tl + ((unsigned)b & m))->b;
DUMPBITS(j);
NEEDBITS ((unsigned) bl);
j = (td = tl + ((unsigned) b & m))->b;
DUMPBITS (j);
j = td->v.n;
if (j < 16) /* length of code in bits (0..15) */
ll[i++] = l = j; /* save last length in l */
else if (j == 16) /* repeat last length 3 to 6 times */
{
NEEDBITS(2);
j = 3 + ((unsigned)b & 3);
DUMPBITS(2);
if ((unsigned)i + j > n)
NEEDBITS (2);
j = 3 + ((unsigned) b & 3);
DUMPBITS (2);
if ((unsigned) i + j > n)
{
errnum = ERR_BAD_GZIP_DATA;
return;
@ -956,10 +983,10 @@ init_dynamic_block(void)
}
else if (j == 17) /* 3 to 10 zero length codes */
{
NEEDBITS(3);
j = 3 + ((unsigned)b & 7);
DUMPBITS(3);
if ((unsigned)i + j > n)
NEEDBITS (3);
j = 3 + ((unsigned) b & 7);
DUMPBITS (3);
if ((unsigned) i + j > n)
{
errnum = ERR_BAD_GZIP_DATA;
return;
@ -968,12 +995,13 @@ init_dynamic_block(void)
ll[i++] = 0;
l = 0;
}
else /* j == 18: 11 to 138 zero length codes */
else
/* j == 18: 11 to 138 zero length codes */
{
NEEDBITS(7);
j = 11 + ((unsigned)b & 0x7f);
DUMPBITS(7);
if ((unsigned)i + j > n)
NEEDBITS (7);
j = 11 + ((unsigned) b & 0x7f);
DUMPBITS (7);
if ((unsigned) i + j > n)
{
errnum = ERR_BAD_GZIP_DATA;
return;
@ -985,7 +1013,7 @@ init_dynamic_block(void)
}
/* free decoding table for trees */
reset_linalloc();
reset_linalloc ();
/* restore the global bit buffer */
bb = b;
@ -993,22 +1021,22 @@ init_dynamic_block(void)
/* build the decoding tables for literal/length and distance codes */
bl = lbits;
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
if ((i = huft_build (ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
{
#if 0
if (i == 1)
printf("gunzip: incomplete literal tree\n");
printf ("gunzip: incomplete literal tree\n");
#endif
errnum = ERR_BAD_GZIP_DATA;
return;
}
bd = dbits;
if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
if ((i = huft_build (ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
{
#if 0
if (i == 1)
printf("gunzip: incomplete distance tree\n");
printf ("gunzip: incomplete distance tree\n");
#endif
errnum = ERR_BAD_GZIP_DATA;
@ -1022,7 +1050,7 @@ init_dynamic_block(void)
static void
get_new_block(void)
get_new_block (void)
{
register ulg b; /* bit buffer */
register unsigned k; /* number of bits in bit buffer */
@ -1034,30 +1062,30 @@ get_new_block(void)
k = bk;
/* read in last block bit */
NEEDBITS(1);
last_block = (int)b & 1;
DUMPBITS(1);
NEEDBITS (1);
last_block = (int) b & 1;
DUMPBITS (1);
/* read in block type */
NEEDBITS(2);
block_type = (unsigned)b & 3;
DUMPBITS(2);
NEEDBITS (2);
block_type = (unsigned) b & 3;
DUMPBITS (2);
/* restore the global bit buffer */
bb = b;
bk = k;
if (block_type == INFLATE_STORED)
init_stored_block();
init_stored_block ();
if (block_type == INFLATE_FIXED)
init_fixed_block();
init_fixed_block ();
if (block_type == INFLATE_DYNAMIC)
init_dynamic_block();
init_dynamic_block ();
}
static void
inflate_window(void)
inflate_window (void)
{
/* initialize window */
wp = 0;
@ -1073,7 +1101,7 @@ inflate_window(void)
if (last_block)
break;
get_new_block();
get_new_block ();
}
if (block_type > INFLATE_DYNAMIC)
@ -1095,7 +1123,7 @@ inflate_window(void)
while (block_len && w < WSIZE && !errnum)
{
slide[w++] = get_byte();
slide[w++] = get_byte ();
block_len--;
}
@ -1108,8 +1136,8 @@ inflate_window(void)
* Expand other kind of block.
*/
if (inflate_codes_in_window())
reset_linalloc();
if (inflate_codes_in_window ())
reset_linalloc ();
}
saved_filepos += WSIZE;
@ -1119,7 +1147,7 @@ inflate_window(void)
static void
initialize_tables(void)
initialize_tables (void)
{
saved_filepos = 0;
filepos = gzip_data_offset;
@ -1133,25 +1161,25 @@ initialize_tables(void)
block_len = 0;
/* reset memory allocation stuff */
reset_linalloc();
reset_linalloc ();
}
int
gunzip_read(int addr, int len)
gunzip_read (int addr, int len)
{
int size; /* last block flag */
int ret = 0;
compressed_file = 0;
gunzip_swap_values();
gunzip_swap_values ();
/*
* Now "gzip_*" values refer to the uncompressed data.
*/
/* do we reset decompression to the beginning of the file? */
if (saved_filepos > gzip_filepos+WSIZE)
initialize_tables();
if (saved_filepos > gzip_filepos + WSIZE)
initialize_tables ();
/*
* This loop operates upon uncompressed data only. The only
@ -1165,14 +1193,14 @@ gunzip_read(int addr, int len)
register char *srcaddr;
while (gzip_filepos >= saved_filepos)
inflate_window();
inflate_window ();
srcaddr = (char *)((gzip_filepos & (WSIZE - 1)) + slide);
srcaddr = (char *) ((gzip_filepos & (WSIZE - 1)) + slide);
size = saved_filepos - gzip_filepos;
if (size > len)
size = len;
bcopy(srcaddr, (char *)addr, size);
bcopy (srcaddr, (char *) addr, size);
addr += size;
len -= size;
@ -1181,7 +1209,7 @@ gunzip_read(int addr, int len)
}
compressed_file = 1;
gunzip_swap_values();
gunzip_swap_values ();
/*
* Now "gzip_*" values refer to the compressed data.
*/
@ -1191,4 +1219,3 @@ gunzip_read(int addr, int len)
return ret;
}

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -27,7 +28,8 @@ typedef unsigned long Elf32_Word;
/* "unsigned char" already exists */
/* ELF header */
typedef struct {
typedef struct
{
#define EI_NIDENT 16
@ -78,7 +80,8 @@ typedef struct {
#define SHN_COMMON 0xfff2
#define SHN_HIRESERVE 0xffff
Elf32_Half e_shstrndx; /* section header table index */
} Elf32_Ehdr;
}
Elf32_Ehdr;
#define BOOTABLE_I386_ELF(h) \
@ -91,14 +94,15 @@ typedef struct {
/* symbol table - page 4-25, figure 4-15 */
typedef struct
{
{
Elf32_Word st_name;
Elf32_Addr st_value;
Elf32_Word st_size;
unsigned char st_info;
unsigned char st_other;
Elf32_Half st_shndx;
} Elf32_Sym;
}
Elf32_Sym;
/* symbol type and binding attributes - page 4-26 */
@ -134,7 +138,8 @@ typedef struct
/* program header - page 5-2, figure 5-1 */
typedef struct {
typedef struct
{
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
@ -143,7 +148,8 @@ typedef struct {
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;
} Elf32_Phdr;
}
Elf32_Phdr;
/* segment types - page 5-3, figure 5-2 */
@ -168,13 +174,17 @@ typedef struct {
/* dynamic structure - page 5-15, figure 5-9 */
typedef struct {
typedef struct
{
Elf32_Sword d_tag;
union {
union
{
Elf32_Word d_val;
Elf32_Addr d_ptr;
} d_un;
} Elf32_Dyn;
}
d_un;
}
Elf32_Dyn;
/* Dynamic array tags - page 5-16, figure 5-10. */
@ -202,4 +212,3 @@ typedef struct {
#define DT_DEBUG 21
#define DT_TEXTREL 22
#define DT_JMPREL 23

View file

@ -1,3 +1,4 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@ -117,7 +118,8 @@
* N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h
*/
struct exec {
struct exec
{
unsigned long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */
unsigned long a_text; /* text segment size */
unsigned long a_data; /* initialized data size */
@ -126,7 +128,7 @@ struct exec {
unsigned long a_entry; /* entry point */
unsigned long a_trsize; /* text relocation size */
unsigned long a_drsize; /* data relocation size */
};
};
#define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */
/* a_magic */

View file

@ -22,7 +22,7 @@
*/
struct multiboot_header
{
{
/* Must be MULTIBOOT_MAGIC - see below. */
unsigned magic;
@ -42,7 +42,7 @@ struct multiboot_header
unsigned load_end_addr;
unsigned bss_end_addr;
unsigned entry_addr;
};
};
/*
* The entire multiboot_header must be contained
@ -76,4 +76,3 @@ struct multiboot_header
/* This flag indicates the use of the other fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -22,7 +23,7 @@
*/
struct mod_list
{
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
unsigned long mod_start;
unsigned long mod_end;
@ -32,7 +33,7 @@ struct mod_list
/* padding to take it to 16 bytes (must be zero) */
unsigned long pad;
};
};
/*
@ -43,7 +44,7 @@ struct mod_list
*/
struct AddrRangeDesc
{
{
unsigned long size;
unsigned long BaseAddrLow;
unsigned long BaseAddrHigh;
@ -52,7 +53,7 @@ struct AddrRangeDesc
unsigned long Type;
/* unspecified optional padding... */
};
};
/* usable memory "Type", all others are reserved. */
#define MB_ARD_MEMORY 1
@ -66,7 +67,7 @@ struct AddrRangeDesc
*/
struct multiboot_info
{
{
/* MultiBoot info version number */
unsigned long flags;
@ -93,7 +94,8 @@ struct multiboot_info
unsigned long strsize;
unsigned long addr;
unsigned long pad;
} a;
}
a;
struct
{
@ -102,13 +104,15 @@ struct multiboot_info
unsigned long size;
unsigned long addr;
unsigned long shndx;
} e;
} syms;
}
e;
}
syms;
/* Memory Mapping buffer */
unsigned long mmap_length;
unsigned long mmap_addr;
};
};
/*
* Flags to be set in the 'flags' parameter above
@ -138,4 +142,3 @@ struct multiboot_info
*/
#define MULTIBOOT_VALID 0x2BADB002

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -199,4 +200,3 @@
#endif /* _PC_SLICE_H */

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -178,18 +179,18 @@
static inline unsigned char
inb(unsigned short port)
inb (unsigned short port)
{
unsigned char data;
__asm __volatile("inb %1,%0" : "=a" (data) : "d" (port));
__asm __volatile ("inb %1,%0":"=a" (data):"d" (port));
return data;
}
static inline void
outb(unsigned short port, unsigned char val)
outb (unsigned short port, unsigned char val)
{
__asm __volatile("outb %0,%1" : :"a" (val), "d" (port));
__asm __volatile ("outb %0,%1"::"a" (val), "d" (port));
}
@ -201,7 +202,9 @@ outb(unsigned short port, unsigned char val)
extern char end[]; /* will be the end of the bss */
/* this function must be called somewhere... */
void cmain(void) __attribute__ ((noreturn));
void
cmain (void)
__attribute__ ((noreturn));
#define NULL ((void *) 0)
@ -210,37 +213,37 @@ void cmain(void) __attribute__ ((noreturn));
* From "asm.S"
*/
extern unsigned long install_partition;
extern unsigned long boot_drive;
extern char version_string[];
extern char config_file[];
extern unsigned long install_partition;
extern unsigned long boot_drive;
extern char version_string[];
extern char config_file[];
/* calls for direct boot-loader chaining */
void chain_stage1(int segment, int offset, int part_table_addr)
__attribute__ ((noreturn));
void chain_stage2(int segment, int offset) __attribute__ ((noreturn));
void chain_stage1 (int segment, int offset, int part_table_addr)
__attribute__ ((noreturn));
void chain_stage2 (int segment, int offset) __attribute__ ((noreturn));
/* do some funky stuff, then boot linux */
void linux_boot(void) __attribute__ ((noreturn));
void linux_boot (void) __attribute__ ((noreturn));
/* booting a multiboot executable */
void multi_boot(int start, int mbi) __attribute__ ((noreturn));
void multi_boot (int start, int mbi) __attribute__ ((noreturn));
/* sets it to linear or wired A20 operation */
void gateA20(int linear);
void gateA20 (int linear);
/* memory probe routines */
int get_memsize(int type);
int get_eisamemsize(void);
int get_mmap_entry(int buf, int cont);
int get_memsize (int type);
int get_eisamemsize (void);
int get_mmap_entry (int buf, int cont);
/* low-level timing info */
int getrtsecs(void);
int getrtsecs (void);
/* low-level character I/O */
void cls(void);
int getxy(void); /* returns packed values, LSB+1 is x, LSB is y */
void gotoxy(int x, int y);
void cls (void);
int getxy (void); /* returns packed values, LSB+1 is x, LSB is y */
void gotoxy (int x, int y);
/* displays an ASCII character. IBM displays will translate some
characters to special graphical ones */
@ -254,7 +257,7 @@ void gotoxy(int x, int y);
#define DISP_RIGHT 0x1a
#define DISP_UP 0x18
#define DISP_DOWN 0x19
void putchar(int c);
void putchar (int c);
/* returns packed BIOS/ASCII code */
#define BIOS_CODE(x) ((x) >> 8)
@ -269,24 +272,24 @@ void putchar(int c);
#define KEY_END 0x4F00
#define KEY_PGUP 0x4900
#define KEY_PGDN 0x5100
int asm_getkey(void);
int asm_getkey (void);
/* returns 0 if non-ASCII character */
#define getc() ASCII_CHAR(getkey())
/* like 'getkey', but doesn't wait, returns -1 if nothing available */
int checkkey(void);
int checkkey (void);
/* sets text mode character attribute at the cursor position */
#define ATTRIB_NORMAL 0x7
#define ATTRIB_INVERSE 0x70
void set_attrib(int attr);
void set_attrib (int attr);
/* low-level disk I/O */
int get_diskinfo(int drive);
int biosdisk(int subfunc, int drive, int geometry,
int get_diskinfo (int drive);
int biosdisk (int subfunc, int drive, int geometry,
int sector, int nsec, int segment);
void stop_floppy(void);
void stop_floppy (void);
/*
@ -295,15 +298,15 @@ void stop_floppy(void);
#ifndef _CMDLINE_C
extern int fallback;
extern char *password;
extern char commands[];
extern int fallback;
extern char *password;
extern char commands[];
#endif /* _CMDLINE_C */
char *skip_to(int after_equal, char *cmdline);
void init_cmdline(void);
int enter_cmdline(char *script, char *heap);
char *skip_to (int after_equal, char *cmdline);
void init_cmdline (void);
int enter_cmdline (char *script, char *heap);
/*
@ -312,11 +315,12 @@ int enter_cmdline(char *script, char *heap);
#ifndef _CHAR_IO_C
int special_attribute;
int special_attribute;
#endif /* _CHAR_IO_C */
enum grub_error_t {
enum grub_error_t
{
ERR_NONE = 0,
ERR_BAD_FILENAME,
ERR_BAD_FILETYPE,
@ -349,7 +353,7 @@ enum grub_error_t {
ERR_WRITE,
MAX_ERR_NUM
};
};
/* returns packed BIOS/ASCII code */
#define BIOS_CODE(x) ((x) >> 8)
@ -364,24 +368,24 @@ enum grub_error_t {
#define KEY_END 0x4F00
#define KEY_PGUP 0x4900
#define KEY_PGDN 0x5100
int getkey(void); /* actually just calls asm_getkey and invalidates the
int getkey (void); /* actually just calls asm_getkey and invalidates the
disk buffer */
void init_page(void);
void print_error(void);
char *convert_to_ascii(char *buf, int c, ...);
void printf(char *format, ... );
int get_cmdline(char *prompt, char *commands, char *cmdline, int maxlen);
int tolower(int c);
int isspace(int c);
int strncat(char *s1, char *s2, int n);
int substring(char *s1, char *s2);
char *strstr(char *s1, char *s2);
int bcopy(char *from, char *to, int len);
int bzero(char *start, int len);
int get_based_digit(int c, int base);
int safe_parse_maxint(char **str_ptr, int *myint_ptr);
int memcheck(int start, int len);
void init_page (void);
void print_error (void);
char *convert_to_ascii (char *buf, int c,...);
void printf (char *format,...);
int get_cmdline (char *prompt, char *commands, char *cmdline, int maxlen);
int tolower (int c);
int isspace (int c);
int strncat (char *s1, char *s2, int n);
int substring (char *s1, char *s2);
char *strstr (char *s1, char *s2);
int bcopy (char *from, char *to, int len);
int bzero (char *start, int len);
int get_based_digit (int c, int base);
int safe_parse_maxint (char **str_ptr, int *myint_ptr);
int memcheck (int start, int len);
/*
@ -390,13 +394,13 @@ int memcheck(int start, int len);
#ifndef _GUNZIP_C
extern int no_decompression;
extern int compressed_file;
extern int no_decompression;
extern int compressed_file;
#endif /* _GUNZIP_C */
int gunzip_test_header(void);
int gunzip_read(int addr, int len);
int gunzip_test_header (void);
int gunzip_read (int addr, int len);
/*
@ -407,54 +411,54 @@ int gunzip_read(int addr, int len);
#ifndef NO_FANCY_STUFF
/* instrumentation variables */
extern void (*debug_fs)(int);
extern void (*debug_fs_func)(int);
extern void (*debug_fs) (int);
extern void (*debug_fs_func) (int);
#endif /* NO_FANCY_STUFF */
extern unsigned long current_drive;
extern unsigned long current_partition;
extern unsigned long current_drive;
extern unsigned long current_partition;
extern int fsys_type;
extern int fsys_type;
#ifndef NO_BLOCK_FILES
extern int block_file;
extern int block_file;
#endif /* NO_BLOCK_FILES */
extern long part_start;
extern long part_length;
extern long part_start;
extern long part_length;
extern int current_slice;
extern int current_slice;
extern int buf_drive;
extern int buf_track;
extern int buf_geom;
extern int buf_drive;
extern int buf_track;
extern int buf_geom;
/* these are the current file position and maximum file position */
extern int filepos;
extern int filemax;
extern int filepos;
extern int filemax;
#endif /* _DISK_IO_C */
int rawread(int drive, int sector, int byte_offset, int byte_len, int addr);
int devread(int sector, int byte_offset, int byte_len, int addr);
int rawread (int drive, int sector, int byte_offset, int byte_len, int addr);
int devread (int sector, int byte_offset, int byte_len, int addr);
char *set_device(char *device); /* this gets a device from the string and
char *set_device (char *device); /* this gets a device from the string and
places it into the global parameters */
int open_device(void);
int make_saved_active(void); /* sets the active partition to the that
int open_device (void);
int make_saved_active (void); /* sets the active partition to the that
represented by the "saved_" parameters */
int open(char *filename);
int read(int addr, int len); /* if "length" is -1, read all the
int open (char *filename);
int read (int addr, int len); /* if "length" is -1, read all the
remaining data in the file */
int dir(char *dirname); /* list directory, printing all completions */
int dir (char *dirname); /* list directory, printing all completions */
int set_bootdev(int hdbias);
void print_fsys_type(void); /* this prints stats on the currently
int set_bootdev (int hdbias);
void print_fsys_type (void); /* this prints stats on the currently
mounted filesystem */
void print_completions(char *filename); /* this prints device and filename
void print_completions (char *filename); /* this prints device and filename
completions */
void copy_current_part_entry(int addr); /* copies the current partition data
void copy_current_part_entry (int addr); /* copies the current partition data
to the desired address */
@ -463,19 +467,19 @@ void copy_current_part_entry(int addr); /* copies the current partition data
*/
/* for the entry address */
typedef void
(*entry_func)(int, int, int, int, int, int) __attribute__ ((noreturn));
typedef void
(*entry_func) (int, int, int, int, int, int) __attribute__ ((noreturn));
#ifndef _BOOT_C
extern char *cur_cmdline;
extern entry_func entry_addr;
extern char *cur_cmdline;
extern entry_func entry_addr;
#endif /* _BOOT_C */
void bsd_boot(int type, int bootdev) __attribute__ ((noreturn));
int load_image(void);
int load_module(void);
void bsd_boot (int type, int bootdev) __attribute__ ((noreturn));
int load_image (void);
int load_module (void);
/*
@ -489,20 +493,20 @@ int load_module(void);
* Common BIOS/boot data.
*/
extern struct multiboot_info mbi;
extern unsigned long saved_drive;
extern unsigned long saved_partition;
extern unsigned long saved_mem_upper;
extern struct multiboot_info mbi;
extern unsigned long saved_drive;
extern unsigned long saved_partition;
extern unsigned long saved_mem_upper;
/*
* Error variables.
*/
extern int errnum;
extern char *err_list[];
extern int errnum;
extern char *err_list[];
#endif /* _COMMON_C */
void init_bios_info(void) __attribute__ ((noreturn));
void init_bios_info (void) __attribute__ ((noreturn));
#endif /* ASM_FILE */

View file

@ -1,3 +1,4 @@
/*
* <Insert copyright here : it must be BSD-like so anyone can use it>
*
@ -66,36 +67,121 @@
#define DEF_ENTRIES 23
static int lapic_dummy = 0;
static struct {
static struct
{
imps_processor proc[2];
imps_bus bus[2];
imps_ioapic ioapic;
imps_interrupt intin[16];
imps_interrupt lintin[2];
} defconfig = {
{ { IMPS_BCT_PROCESSOR, 0, 0, 0, 0, 0},
{ IMPS_BCT_PROCESSOR, 1, 0, 0, 0, 0} },
{ { IMPS_BCT_BUS, 0, {'E', 'I', 'S', 'A', ' ', ' '}},
{ 255, 1, {'P', 'C', 'I', ' ', ' ', ' '}} },
{ IMPS_BCT_IOAPIC, 0, 0, IMPS_FLAG_ENABLED, IOAPIC_ADDR_DEFAULT },
{ { IMPS_BCT_IO_INTERRUPT, IMPS_INT_EXTINT, 0, 0, 0, 0xFF, 0},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 1, 0xFF, 1},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 0, 0xFF, 2},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 3, 0xFF, 3},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 4, 0xFF, 4},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 5, 0xFF, 5},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 6, 0xFF, 6},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 7, 0xFF, 7},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 8, 0xFF, 8},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 9, 0xFF, 9},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 10, 0xFF, 10},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 11, 0xFF, 11},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 12, 0xFF, 12},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 13, 0xFF, 13},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 14, 0xFF, 14},
{ IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 15, 0xFF, 15} },
{ { IMPS_BCT_LOCAL_INTERRUPT, IMPS_INT_EXTINT, 0, 0, 15, 0xFF, 0},
{ IMPS_BCT_LOCAL_INTERRUPT, IMPS_INT_NMI, 0, 0, 15, 0xFF, 1} }
}
defconfig =
{
{
{
IMPS_BCT_PROCESSOR, 0, 0, 0, 0, 0
}
,
{
IMPS_BCT_PROCESSOR, 1, 0, 0, 0, 0
}
}
,
{
{
IMPS_BCT_BUS, 0,
{
'E', 'I', 'S', 'A', ' ', ' '
}
}
,
{
255, 1,
{
'P', 'C', 'I', ' ', ' ', ' '
}
}
}
,
{
IMPS_BCT_IOAPIC, 0, 0, IMPS_FLAG_ENABLED, IOAPIC_ADDR_DEFAULT
}
,
{
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_EXTINT, 0, 0, 0, 0xFF, 0
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 1, 0xFF, 1
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 0, 0xFF, 2
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 3, 0xFF, 3
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 4, 0xFF, 4
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 5, 0xFF, 5
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 6, 0xFF, 6
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 7, 0xFF, 7
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 8, 0xFF, 8
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 9, 0xFF, 9
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 10, 0xFF, 10
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 11, 0xFF, 11
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 12, 0xFF, 12
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 13, 0xFF, 13
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 14, 0xFF, 14
}
,
{
IMPS_BCT_IO_INTERRUPT, IMPS_INT_INT, 0, 0, 15, 0xFF, 15
}
}
,
{
{
IMPS_BCT_LOCAL_INTERRUPT, IMPS_INT_EXTINT, 0, 0, 15, 0xFF, 0
}
,
{
IMPS_BCT_LOCAL_INTERRUPT, IMPS_INT_NMI, 0, 0, 15, 0xFF, 1
}
}
};
/*
@ -106,7 +192,7 @@ int imps_any_new_apics = 0;
volatile int imps_release_cpus = 0;
int imps_enabled = 0;
int imps_num_cpus = 1;
unsigned imps_lapic_addr = ((unsigned)(&lapic_dummy)) - LAPIC_ID;
unsigned imps_lapic_addr = ((unsigned) (&lapic_dummy)) - LAPIC_ID;
unsigned char imps_cpu_apic_map[IMPS_MAX_CPUS];
unsigned char imps_apic_cpu_map[IMPS_MAX_CPUS];
@ -118,15 +204,16 @@ unsigned char imps_apic_cpu_map[IMPS_MAX_CPUS];
*/
static int
get_checksum(unsigned start, int length)
get_checksum (unsigned start, int length)
{
unsigned sum = 0;
while (length-- > 0) {
while (length-- > 0)
{
sum += *((unsigned char *) (start++));
}
return (sum&0xFF);
return (sum & 0xFF);
}
@ -138,51 +225,52 @@ get_checksum(unsigned start, int length)
*/
static int
boot_cpu(imps_processor *proc)
boot_cpu (imps_processor * proc)
{
int apicid = proc->apic_id;
unsigned bootaddr, send_status, accept_status, cfg;
unsigned bios_reset_vector = PHYS_TO_VIRTUAL(BIOS_RESET_VECTOR);
unsigned bios_reset_vector = PHYS_TO_VIRTUAL (BIOS_RESET_VECTOR);
/* %%%%% ESB */
extern char patch_code[];
bootaddr = 256*1024;
bcopy(patch_code, (char *)bootaddr, 32);
bootaddr = 256 * 1024;
bcopy (patch_code, (char *) bootaddr, 32);
/*
* Generic CPU startup sequence starts here.
*/
/* set BIOS reset vector */
CMOS_WRITE_BYTE(CMOS_RESET_CODE, CMOS_RESET_JUMP);
CMOS_WRITE_BYTE (CMOS_RESET_CODE, CMOS_RESET_JUMP);
*((volatile unsigned *) bios_reset_vector) = bootaddr << 12;
/* clear the error register */
if (proc->apic_ver & 0x10) {
IMPS_LAPIC_WRITE(LAPIC_ESR, 0);
accept_status = IMPS_LAPIC_READ(LAPIC_ESR);
if (proc->apic_ver & 0x10)
{
IMPS_LAPIC_WRITE (LAPIC_ESR, 0);
accept_status = IMPS_LAPIC_READ (LAPIC_ESR);
}
#if 0
/* assert INIT IPI */
cfg = IMPS_LAPIC_READ(LAPIC_ICR+1);
cfg = IMPS_LAPIC_READ (LAPIC_ICR + 1);
cfg &= LAPIC_DEST_MASK;
IMPS_LAPIC_WRITE(LAPIC_ICR+1, cfg);
cfg = IMPS_LAPIC_READ(LAPIC_ACR);
cfg &= ;
IMPS_LAPIC_WRITE (LAPIC_ICR + 1, cfg);
cfg = IMPS_LAPIC_READ (LAPIC_ACR);
cfg &=;
/* %%%%% ESB finish adding startup sequence */
#endif
/* clean up BIOS reset vector */
CMOS_WRITE_BYTE(CMOS_RESET_CODE, 0);
CMOS_WRITE_BYTE (CMOS_RESET_CODE, 0);
*((volatile unsigned *) bios_reset_vector) = 0;
/*
* Generic CPU startup sequence ends here.
*/
KERNEL_PRINT(("\n"));
KERNEL_PRINT (("\n"));
return 1;
@ -195,26 +283,30 @@ boot_cpu(imps_processor *proc)
*/
static void
add_processor(imps_processor *proc)
add_processor (imps_processor * proc)
{
int apicid = proc->apic_id;
KERNEL_PRINT((" Processor [APIC id %d ver %d]: ",
KERNEL_PRINT ((" Processor [APIC id %d ver %d]: ",
apicid, proc->apic_ver));
if (!(proc->flags & IMPS_FLAG_ENABLED)) {
KERNEL_PRINT(("DISABLED\n"));
if (!(proc->flags & IMPS_FLAG_ENABLED))
{
KERNEL_PRINT (("DISABLED\n"));
return;
}
if (proc->apic_ver > 0xF) {
if (proc->apic_ver > 0xF)
{
imps_any_new_apics = 1;
}
if (proc->flags & (IMPS_CPUFLAG_BOOT)) {
KERNEL_PRINT(("#0 Bootstrap Processor (BSP)\n"));
if (proc->flags & (IMPS_CPUFLAG_BOOT))
{
KERNEL_PRINT (("#0 Bootstrap Processor (BSP)\n"));
return;
}
imps_cpu_apic_map[imps_num_cpus] = apicid;
imps_apic_cpu_map[apicid] = imps_num_cpus;
if (boot_cpu(proc)) {
if (boot_cpu (proc))
{
/* XXXXX add OS-specific setup for secondary CPUs here */
@ -224,56 +316,59 @@ add_processor(imps_processor *proc)
static void
add_bus(imps_bus *bus)
add_bus (imps_bus * bus)
{
char str[8];
bcopy(bus->bus_type, str, 6);
bcopy (bus->bus_type, str, 6);
str[6] = 0;
KERNEL_PRINT((" Bus id %d is %s\n", bus->id, str));
KERNEL_PRINT ((" Bus id %d is %s\n", bus->id, str));
/* XXXXX add OS-specific code here */
}
static void
add_ioapic(imps_ioapic *ioapic)
add_ioapic (imps_ioapic * ioapic)
{
KERNEL_PRINT((" I/O APIC id %d ver %d, address: 0x%x ",
KERNEL_PRINT ((" I/O APIC id %d ver %d, address: 0x%x ",
ioapic->id, ioapic->ver, ioapic->addr));
if (!(ioapic->flags & IMPS_FLAG_ENABLED)) {
KERNEL_PRINT(("DISABLED\n"));
if (!(ioapic->flags & IMPS_FLAG_ENABLED))
{
KERNEL_PRINT (("DISABLED\n"));
return;
}
KERNEL_PRINT(("\n"));
KERNEL_PRINT (("\n"));
/* XXXXX add OS-specific code here */
}
static void
imps_read_config_table(unsigned start, int count)
imps_read_config_table (unsigned start, int count)
{
while (count-- > 0) {
switch (*((unsigned char *)start)) {
while (count-- > 0)
{
switch (*((unsigned char *) start))
{
case IMPS_BCT_PROCESSOR:
add_processor((imps_processor *)start);
add_processor ((imps_processor *) start);
start += 12; /* 20 total */
break;
case IMPS_BCT_BUS:
add_bus((imps_bus *)start);
add_bus ((imps_bus *) start);
break;
case IMPS_BCT_IOAPIC:
add_ioapic((imps_ioapic *)start);
add_ioapic ((imps_ioapic *) start);
break;
#if 0 /* XXXXX uncomment this if "add_io_interrupt" is implemented */
case IMPS_BCT_IO_INTERRUPT:
add_io_interrupt((imps_interrupt *)start);
add_io_interrupt ((imps_interrupt *) start);
break;
#endif
#if 0 /* XXXXX uncomment this if "add_local_interrupt" is implemented */
case IMPS_BCT_LOCAL_INTERRUPT:
add_local_interupt((imps_interrupt *)start);
add_local_interupt ((imps_interrupt *) start);
break;
#endif
default:
@ -284,41 +379,52 @@ imps_read_config_table(unsigned start, int count)
static int
imps_bad_bios(imps_fps *fps_ptr)
imps_bad_bios (imps_fps * fps_ptr)
{
int sum;
imps_cth *local_cth_ptr
= (imps_cth *) PHYS_TO_VIRTUAL(fps_ptr->cth_ptr);
= (imps_cth *) PHYS_TO_VIRTUAL (fps_ptr->cth_ptr);
if (fps_ptr->feature_info[0] > IMPS_FPS_DEFAULT_MAX) {
KERNEL_PRINT((" Invalid MP System Configuration type %d\n",
if (fps_ptr->feature_info[0] > IMPS_FPS_DEFAULT_MAX)
{
KERNEL_PRINT ((" Invalid MP System Configuration type %d\n",
fps_ptr->feature_info[0]));
return 1;
}
if (fps_ptr->cth_ptr) {
sum = get_checksum((unsigned)local_cth_ptr,
if (fps_ptr->cth_ptr)
{
sum = get_checksum ((unsigned) local_cth_ptr,
local_cth_ptr->base_length);
if (local_cth_ptr->sig != IMPS_CTH_SIGNATURE || sum) {
KERNEL_PRINT((" Bad MP Config Table sig 0x%x and/or checksum 0x%x\n", (unsigned)(fps_ptr->cth_ptr), sum));
if (local_cth_ptr->sig != IMPS_CTH_SIGNATURE || sum)
{
KERNEL_PRINT
((" Bad MP Config Table sig 0x%x and/or checksum 0x%x\n",
(unsigned) (fps_ptr->cth_ptr), sum));
return 1;
}
if (local_cth_ptr->spec_rev != fps_ptr->spec_rev) {
KERNEL_PRINT((" Bad MP Config Table sub-revision # %d\n", local_cth_ptr->spec_rev));
if (local_cth_ptr->spec_rev != fps_ptr->spec_rev)
{
KERNEL_PRINT ((" Bad MP Config Table sub-revision # %d\n", local_cth_ptr->spec_rev));
return 1;
}
if (local_cth_ptr->extended_length) {
sum = (get_checksum(((unsigned)local_cth_ptr)
if (local_cth_ptr->extended_length)
{
sum = (get_checksum (((unsigned) local_cth_ptr)
+ local_cth_ptr->base_length,
local_cth_ptr->extended_length)
+ local_cth_ptr->extended_checksum) & 0xFF;
if (sum) {
KERNEL_PRINT((" Bad Extended MP Config Table checksum 0x%x\n", sum));
if (sum)
{
KERNEL_PRINT
((" Bad Extended MP Config Table checksum 0x%x\n", sum));
return 1;
}
}
} else if (!fps_ptr->feature_info[0]) {
KERNEL_PRINT((" Missing configuration information\n"));
}
else if (!fps_ptr->feature_info[0])
{
KERNEL_PRINT ((" Missing configuration information\n"));
return 1;
}
@ -327,15 +433,15 @@ imps_bad_bios(imps_fps *fps_ptr)
static void
imps_read_bios(imps_fps *fps_ptr)
imps_read_bios (imps_fps * fps_ptr)
{
int apicid;
unsigned cth_start, cth_count;
imps_cth *local_cth_ptr
= (imps_cth *)PHYS_TO_VIRTUAL(fps_ptr->cth_ptr);
= (imps_cth *) PHYS_TO_VIRTUAL (fps_ptr->cth_ptr);
char *str_ptr;
KERNEL_PRINT(("Intel MultiProcessor Spec 1.%d BIOS support detected\n",
KERNEL_PRINT (("Intel MultiProcessor Spec 1.%d BIOS support detected\n",
fps_ptr->spec_rev));
/*
@ -343,81 +449,97 @@ imps_read_bios(imps_fps *fps_ptr)
* lead to failure of the SMP boot here.
*/
if (imps_bad_bios(fps_ptr)) {
KERNEL_PRINT((" Disabling MPS support\n"));
if (imps_bad_bios (fps_ptr))
{
KERNEL_PRINT ((" Disabling MPS support\n"));
return;
}
if (fps_ptr->feature_info[1] & IMPS_FPS_IMCRP_BIT) {
if (fps_ptr->feature_info[1] & IMPS_FPS_IMCRP_BIT)
{
str_ptr = "IMCR and PIC";
} else {
}
else
{
str_ptr = "Virtual Wire";
}
if (fps_ptr->cth_ptr) {
if (fps_ptr->cth_ptr)
{
imps_lapic_addr = local_cth_ptr->lapic_addr;
} else {
}
else
{
imps_lapic_addr = LAPIC_ADDR_DEFAULT;
}
KERNEL_PRINT((" APIC config: \"%s mode\" Local APIC address: 0x%x\n",
KERNEL_PRINT
((" APIC config: \"%s mode\" Local APIC address: 0x%x\n",
str_ptr, imps_lapic_addr));
imps_lapic_addr = PHYS_TO_VIRTUAL(imps_lapic_addr);
imps_lapic_addr = PHYS_TO_VIRTUAL (imps_lapic_addr);
/*
* Setup primary CPU.
*/
apicid = IMPS_LAPIC_READ(LAPIC_SPIV);
IMPS_LAPIC_WRITE(LAPIC_SPIV, apicid|LAPIC_SPIV_ENABLE_APIC);
imps_any_new_apics = IMPS_LAPIC_READ(LAPIC_VER) & 0xF0;
apicid = IMPS_APIC_ID(IMPS_LAPIC_READ(LAPIC_ID));
apicid = IMPS_LAPIC_READ (LAPIC_SPIV);
IMPS_LAPIC_WRITE (LAPIC_SPIV, apicid | LAPIC_SPIV_ENABLE_APIC);
imps_any_new_apics = IMPS_LAPIC_READ (LAPIC_VER) & 0xF0;
apicid = IMPS_APIC_ID (IMPS_LAPIC_READ (LAPIC_ID));
imps_cpu_apic_map[0] = apicid;
imps_apic_cpu_map[apicid] = 0;
if (fps_ptr->cth_ptr) {
if (fps_ptr->cth_ptr)
{
char str1[16], str2[16];
bcopy(local_cth_ptr->oem_id, str1, 8);
bcopy (local_cth_ptr->oem_id, str1, 8);
str1[8] = 0;
bcopy(local_cth_ptr->prod_id, str2, 12);
bcopy (local_cth_ptr->prod_id, str2, 12);
str2[12] = 0;
KERNEL_PRINT((" OEM id: %s Product id: %s\n", str1, str2));
cth_start = ((unsigned) local_cth_ptr) + sizeof(imps_cth);
KERNEL_PRINT ((" OEM id: %s Product id: %s\n", str1, str2));
cth_start = ((unsigned) local_cth_ptr) + sizeof (imps_cth);
cth_count = local_cth_ptr->entry_count;
} else {
}
else
{
*((volatile unsigned *) IOAPIC_ADDR_DEFAULT) = IOAPIC_ID;
defconfig.ioapic.id
= IMPS_APIC_ID(*((volatile unsigned *)
(IOAPIC_ADDR_DEFAULT+IOAPIC_RW)));
= IMPS_APIC_ID (*((volatile unsigned *)
(IOAPIC_ADDR_DEFAULT + IOAPIC_RW)));
*((volatile unsigned *) IOAPIC_ADDR_DEFAULT) = IOAPIC_VER;
defconfig.ioapic.ver
= APIC_VERSION(*((volatile unsigned *)
(IOAPIC_ADDR_DEFAULT+IOAPIC_RW)));
= APIC_VERSION (*((volatile unsigned *)
(IOAPIC_ADDR_DEFAULT + IOAPIC_RW)));
defconfig.proc[apicid].flags
= IMPS_FLAG_ENABLED|IMPS_CPUFLAG_BOOT;
= IMPS_FLAG_ENABLED | IMPS_CPUFLAG_BOOT;
defconfig.proc[!apicid].flags = IMPS_FLAG_ENABLED;
imps_num_cpus = 2;
if (fps_ptr->feature_info[0] == 1
|| fps_ptr->feature_info[0] == 5) {
bcopy("ISA ", defconfig.bus[0].bus_type, 6);
|| fps_ptr->feature_info[0] == 5)
{
bcopy ("ISA ", defconfig.bus[0].bus_type, 6);
}
if (fps_ptr->feature_info[0] == 4
|| fps_ptr->feature_info[0] == 7) {
bcopy("MCA ", defconfig.bus[0].bus_type, 6);
|| fps_ptr->feature_info[0] == 7)
{
bcopy ("MCA ", defconfig.bus[0].bus_type, 6);
}
if (fps_ptr->feature_info[0] > 4) {
if (fps_ptr->feature_info[0] > 4)
{
defconfig.proc[0].apic_ver = 0x10;
defconfig.proc[1].apic_ver = 0x10;
defconfig.bus[1].type = IMPS_BCT_BUS;
}
if (fps_ptr->feature_info[0] == 2) {
if (fps_ptr->feature_info[0] == 2)
{
defconfig.intin[2].type = 255;
defconfig.intin[13].type = 255;
}
if (fps_ptr->feature_info[0] == 7) {
if (fps_ptr->feature_info[0] == 7)
{
defconfig.intin[0].type = 255;
}
cth_start = (unsigned) &defconfig;
cth_count = DEF_ENTRIES;
}
imps_read_config_table(cth_start, cth_count);
imps_read_config_table (cth_start, cth_count);
/* %%%%% ESB read extended entries here */
@ -441,20 +563,22 @@ imps_read_bios(imps_fps *fps_ptr)
*/
static int
imps_scan(unsigned start, unsigned length)
imps_scan (unsigned start, unsigned length)
{
IMPS_DEBUG_PRINT(("Scanning from 0x%x for %d bytes\n",
IMPS_DEBUG_PRINT (("Scanning from 0x%x for %d bytes\n",
start, length));
while (length > 0) {
imps_fps *fps_ptr = (imps_fps *) PHYS_TO_VIRTUAL(start);
while (length > 0)
{
imps_fps *fps_ptr = (imps_fps *) PHYS_TO_VIRTUAL (start);
if (fps_ptr->sig == IMPS_FPS_SIGNATURE
&& fps_ptr->length == 1
&& (fps_ptr->spec_rev == 1 || fps_ptr->spec_rev == 4)
&& !get_checksum(start, 16)) {
IMPS_DEBUG_PRINT(("Found MP Floating Structure Pointer at %x\n", start));
imps_read_bios(fps_ptr);
&& !get_checksum (start, 16))
{
IMPS_DEBUG_PRINT (("Found MP Floating Structure Pointer at %x\n", start));
imps_read_bios (fps_ptr);
return 1;
}
@ -496,13 +620,13 @@ imps_scan(unsigned start, unsigned length)
*/
int
imps_probe(void)
imps_probe (void)
{
/*
* Determine possible address of the EBDA
*/
unsigned ebda_addr = *((unsigned short *)
PHYS_TO_VIRTUAL(EBDA_SEG_ADDR)) << 4;
PHYS_TO_VIRTUAL (EBDA_SEG_ADDR)) << 4;
/*
* Determine amount of installed lower memory (not *available*
@ -512,8 +636,8 @@ imps_probe(void)
* machine is at least a system that could possibly have
* MPS compatibility to begin with.
*/
unsigned mem_lower = ((CMOS_READ_BYTE(CMOS_BASE_MEMORY+1) << 8)
| CMOS_READ_BYTE(CMOS_BASE_MEMORY)) << 10;
unsigned mem_lower = ((CMOS_READ_BYTE (CMOS_BASE_MEMORY + 1) << 8)
| CMOS_READ_BYTE (CMOS_BASE_MEMORY)) << 10;
#ifdef IMPS_DEBUG
imps_enabled = 0;
@ -524,19 +648,22 @@ imps_probe(void)
* Sanity check : if this isn't reasonable, it is almost impossibly
* unlikely to be an MPS compatible machine, so return failure.
*/
if (mem_lower < 512*1024 || mem_lower > 640*1024) {
if (mem_lower < 512 * 1024 || mem_lower > 640 * 1024)
{
return 0;
}
if (ebda_addr > mem_lower - 1024
|| ebda_addr + *((unsigned char *) PHYS_TO_VIRTUAL(ebda_addr))
* 1024 > mem_lower) {
|| ebda_addr + *((unsigned char *) PHYS_TO_VIRTUAL (ebda_addr))
* 1024 > mem_lower)
{
ebda_addr = 0;
}
if (((ebda_addr && imps_scan(ebda_addr, 1024))
|| (!ebda_addr && imps_scan(mem_lower - 1024, 1024))
|| imps_scan(0xF0000, 0x10000)) && imps_enabled) {
if (((ebda_addr && imps_scan (ebda_addr, 1024))
|| (!ebda_addr && imps_scan (mem_lower - 1024, 1024))
|| imps_scan (0xF0000, 0x10000)) && imps_enabled)
{
return 1;
}
@ -546,4 +673,3 @@ imps_probe(void)
return 0;
}

View file

@ -101,14 +101,14 @@ typedef struct imps_interrupt imps_interrupt;
* this structure.
*/
struct imps_fps
{
{
unsigned sig;
imps_cth *cth_ptr;
unsigned char length;
unsigned char spec_rev;
unsigned char checksum;
unsigned char feature_info[5];
};
};
/*
* MP Configuration Table Header (cth)
@ -117,7 +117,7 @@ struct imps_fps
* this structure.
*/
struct imps_cth
{
{
unsigned sig;
unsigned short base_length;
unsigned char spec_rev;
@ -131,7 +131,7 @@ struct imps_cth
unsigned short extended_length;
unsigned char extended_checksum;
char reserved[1];
};
};
/*
* Base MP Configuration Table Types. They are sorted according to
@ -140,7 +140,7 @@ struct imps_cth
*/
struct imps_processor
{
{
unsigned char type; /* must be 0 */
unsigned char apic_id;
unsigned char apic_ver;
@ -148,26 +148,26 @@ struct imps_processor
unsigned signature;
unsigned features;
char reserved[8];
};
};
struct imps_bus
{
{
unsigned char type; /* must be 1 */
unsigned char id;
char bus_type[6];
};
};
struct imps_ioapic
{
{
unsigned char type; /* must be 2 */
unsigned char id;
unsigned char ver;
unsigned char flags;
unsigned addr;
};
};
struct imps_interrupt
{
{
unsigned char type; /* must be 3 or 4 */
unsigned char int_type;
unsigned short flags;
@ -175,7 +175,7 @@ struct imps_interrupt
unsigned char source_bus_irq;
unsigned char dest_apic_id;
unsigned char dest_apic_intin;
};
};
/*
@ -224,7 +224,7 @@ extern unsigned char imps_apic_cpu_map[IMPS_MAX_CPUS];
* Returns 1 if IMPS information was found and is valid, else 0.
*/
int imps_probe(void);
int imps_probe (void);
/*
@ -236,4 +236,3 @@ int imps_probe(void);
(*((volatile unsigned *) (imps_lapic_addr+(x))) = (y))
#endif /* !_SMP_IMPS_H */

View file

@ -1,3 +1,4 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
@ -20,23 +21,22 @@
#include "shared.h"
void
cmain(void)
cmain (void)
{
printf("\n\nGRUB loading, please wait...\n");
printf ("\n\nGRUB loading, please wait...\n");
/*
* Here load the true second-stage boot-loader.
*/
if (open(config_file) && read(0x8000, -1))
chain_stage2(0, 0x8000);
if (open (config_file) && read (0x8000, -1))
chain_stage2 (0, 0x8000);
/*
* If not, then print error message and die.
*/
print_error();
print_error ();
stop();
stop ();
}

View file

@ -112,21 +112,22 @@ after_BPB:
/* save drive reference first thing! */
pushw %dx
/*
* Jump to floppy probe instead of the hard disk probe ?
*/
movb %dl, %al
andb $BIOS_HD_FLAG, %al
jz floppy_probe
/*
* Determine the hard disk geometry from the BIOS!
* We do this first, so that LS-120 IDE floppies work correctly.
*/
movb $8, %ah
int $0x13
jnc final_init
/* if BIOS geometry call fails, display error and die! */
jc hd_probe_error
/*
* The call failed, so maybe use the floppy probe instead.
*/
andb $BIOS_HD_FLAG, %dl
jz floppy_probe
/* Nope, we definitely have a hard disk, and we're screwed. */
jmp hd_probe_error
final_init:
/* save number of heads */