diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 000000000..814fa088c --- /dev/null +++ b/AUTHORS @@ -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. diff --git a/ChangeLog b/ChangeLog index d39a222de..fc0c39d03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +1999-02-28 Gordon Matzigkeit + + * AUTHORS, INSTALL: New files. + +1999-02-24 Gordon Matzigkeit + + * 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 * debian: Add to the distribution, since we maintain the GRUB diff --git a/INSTALL b/INSTALL new file mode 100644 index 000000000..3848c1548 --- /dev/null +++ b/INSTALL @@ -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. diff --git a/README b/README index 7e67c583c..975f891c6 100644 --- a/README +++ b/README @@ -1,76 +1,23 @@ -This is GRUB, the GRand Unified Boot-loader. Note that this version -is maintained by Gordon Matzigkeit , 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 . - version 0.5 - - by Erich Boleyn - - -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 +. 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. diff --git a/docs/BUGS b/docs/BUGS index 3edc7e6d1..4074391ee 100644 --- a/docs/BUGS +++ b/docs/BUGS @@ -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 diff --git a/docs/NEWS b/docs/NEWS index b05089c5e..340afd217 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -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: diff --git a/docs/TODO b/docs/TODO index c3273a06b..0dd3963ec 100644 --- a/docs/TODO +++ b/docs/TODO @@ -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. diff --git a/docs/grub.html b/docs/grub.html index 790e3696b..a06cf5ed5 100644 --- a/docs/grub.html +++ b/docs/grub.html @@ -85,7 +85,7 @@ initial implementation for the ext2fs filesystem.

  • Miles Bader (miles@gnu.ai.mit.edu) -- for testing feedback.

  • Eric Hanchrow (erich@microsoft.com) -- for interstate remote debugging by hand.

    -

  • Gord Matzigkeit (gord@enci.ucalgary.ca) -- for lots of +
  • Gord Matzigkeit (gord@fig.org) -- for lots of testing feedback.

  • Heiko Schroeder (heiko@pool.informatik.rwth-aachen.de) -- for a re-writing stage1 to be much more readable, plus several patches.

    @@ -117,4 +117,3 @@ Here are links to the NEWS file, - diff --git a/grub/asmstub.c b/grub/asmstub.c index f78e973c4..611965672 100644 --- a/grub/asmstub.c +++ b/grub/asmstub.c @@ -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, - int sector, int nsec, int segment) +biosdisk (int subfunc, int drive, int geometry, + int sector, int nsec, int segment) { } void -stop_floppy(void) +stop_floppy (void) { } diff --git a/mail b/mail deleted file mode 100644 index 79863e74d..000000000 --- a/mail +++ /dev/null @@ -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: -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 ; 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: -Sender: Edmund GRIMLEY EVANS -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: 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 -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 -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 //\ 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: -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 ; 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 -Subject: GRUB -Mime-Version: 1.0 (generated by tm-edit 7.108) -Content-Type: text/plain; charset=US-ASCII -From: Steve Dunham -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: -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 - - diff --git a/shared_src/apic.h b/shared_src/apic.h index b81bda365..9241329c7 100644 --- a/shared_src/apic.h +++ b/shared_src/apic.h @@ -69,5 +69,4 @@ #define LAPIC_TCCR 0x390 #define LAPIC_TDCR 0x3E0 -#endif /* _APIC_H */ - +#endif /* _APIC_H */ diff --git a/shared_src/boot.c b/shared_src/boot.c index e8b801730..b34b5cc81 100644 --- a/shared_src/boot.c +++ b/shared_src/boot.c @@ -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 { - struct multiboot_header *mb; - struct exec *aout; - Elf32_Ehdr *elf; - } pu; + union + { + struct multiboot_header *mb; + struct exec *aout; + Elf32_Ehdr *elf; + } + 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", - (big_linux ? "bzImage" : "zImage"), data_len, text_len); + 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; @@ -234,7 +236,7 @@ load_image(void) else errnum = ERR_WONT_FIT; } - else /* no recognizable format */ + else /* no recognizable format */ errnum = ERR_EXEC_FORMAT; /* return if error */ @@ -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,19 +254,19 @@ load_image(void) mbi.syms.a.addr = 0; mbi.syms.a.pad = 0; - printf(" [%s-%s", str2, str); + printf (" [%s-%s", str2, str); str = ""; - if (exec_type) /* can be loaded like a.out */ + if (exec_type) /* can be loaded like a.out */ { 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,8 +359,8 @@ load_image(void) for (i = 0; i < pu.elf->e_phnum; i++) { phdr = (Elf32_Phdr *) - (pu.elf->e_phoff + ((int)buffer) - + (pu.elf->e_phentsize * i)); + (pu.elf->e_phoff + ((int) buffer) + + (pu.elf->e_phentsize * i)); if (phdr->p_type == PT_LOAD) { /* offset into file */ @@ -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 */ + 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, - (mbi.syms.a.addr + 4 - + mbi.syms.a.tabsize + mbi.syms.a.strsize), - mbi.mem_upper, mbi.mem_lower); + (*entry_addr) (clval, bootdev, 0, + (mbi.syms.a.addr + 4 + + mbi.syms.a.tabsize + mbi.syms.a.strsize), + mbi.mem_upper, mbi.mem_lower); } } - diff --git a/shared_src/char_io.c b/shared_src/char_io.c index d7b9cbb12..0d3890946 100644 --- a/shared_src/char_io.c +++ b/shared_src/char_io.c @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -24,31 +25,31 @@ #ifndef NO_FANCY_STUFF int -getkey(void) +getkey (void) { buf_drive = -1; - return asm_getkey(); + return asm_getkey (); } -#endif /* NO_FANCY_STUFF */ +#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); -#endif /* NO_FANCY_STUFF */ + printf ("Error: %d\n", errnum); +#endif /* NO_FANCY_STUFF */ errnum = ERR_NONE; } 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,12 +133,12 @@ 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", - version_string, mbi.mem_lower, mbi.mem_upper); + printf ("\n GRUB version %s (%dK lower / %dK upper memory)\n\n", + version_string, mbi.mem_lower, mbi.mem_upper); } @@ -145,66 +150,66 @@ 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) - { - while (*str != 0) - { - putchar(*(str++)); - if (++xend > 78) - { - xend = 0; - putchar(' '); - if (yend == (getxy() & 0xFF)) - ystart--; - else - yend++; - } - } - } + void cl_print (char *str) + { + while (*str != 0) + { + putchar (*(str++)); + if (++xend > 78) + { + xend = 0; + putchar (' '); + if (yend == (getxy () & 0xFF)) + ystart--; + else + yend++; + } + } + } /* nested function definition for code simplicity XXX GCC only, I think */ - void cl_setcpos(void) - { - yend = ((lpos+plen) / 79) + ystart; - xend = ((lpos+plen) % 79); - gotoxy(xend, yend); - } + void cl_setcpos (void) + { + yend = ((lpos + plen) / 79) + ystart; + xend = ((lpos + plen) % 79); + gotoxy (xend, yend); + } /* nested function definition for initial command-line printing */ - void cl_init() - { - /* distinguish us from other lines and error messages! */ - putchar('\n'); + void cl_init () + { + /* distinguish us from other lines and error messages! */ + putchar ('\n'); - /* print full line and set position here */ - ystart = (getxy() & 0xFF); - yend = ystart; - xend = 0; - cl_print(prompt); - cl_print(cmdline); - cl_setcpos(); - } + /* print full line and set position here */ + ystart = (getxy () & 0xFF); + yend = ystart; + xend = 0; + cl_print (prompt); + cl_print (cmdline); + cl_setcpos (); + } /* nested function definition for erasing to the end of the line */ - void cl_kill_to_end() - { - int i; + void cl_kill_to_end () + { + int i; cmdline[lpos] = 0; - for (i = lpos; i <= llen; i++) - { - if (i && ((i + plen) % 79) == 0) - putchar(' '); - putchar(' '); - } - llen = lpos; - cl_setcpos(); - } + for (i = lpos; i <= llen; i++) + { + if (i && ((i + plen) % 79) == 0) + putchar (' '); + putchar (' '); + } + llen = lpos; + cl_setcpos (); + } while (prompt[plen]) 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,13 +250,13 @@ 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 */ + case 9: /* TAB lists completions */ { int i, j = 0, llen_old = llen; @@ -261,122 +266,123 @@ 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 */ + 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 */ + case 5: /* C-e go to end of line */ lpos = llen; - cl_setcpos(); + cl_setcpos (); break; - case 6: /* C-f forward one character */ + case 6: /* C-f forward one character */ if (lpos < llen) { lpos++; - cl_setcpos(); + cl_setcpos (); } break; - case 2: /* C-b backward one character */ + case 2: /* C-b backward one character */ if (lpos > 0) { lpos--; - cl_setcpos(); + cl_setcpos (); } break; - case 4: /* C-d delete character under cursor */ + case 4: /* C-d delete character under cursor */ if (lpos == llen) break; lpos++; /* fallthrough is on purpose! */ - case 8: /* C-h backspace */ + case 8: /* C-h backspace */ 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(' '); - lpos = i - 1; /* restore lpos and decrement */ + 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; - case 21: /* C-u kill to beginning of line */ + case 21: /* C-u kill to beginning of line */ if (lpos == 0) 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 */ + 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 <= '~') + default: /* insert printable character into line */ + 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)) - || (start >= 0x100000 - && (mbi.mem_upper * 1024) < ((start-0x100000)+len)) ) + if ((start < 0x1000) || (start < 0x100000 + && (mbi.mem_lower * 1024) < (start + len)) + || (start >= 0x100000 + && (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; diff --git a/shared_src/common.c b/shared_src/common.c index c12900377..cabb08d43 100644 --- a/shared_src/common.c +++ b/shared_src/common.c @@ -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,11 +79,11 @@ 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 */ +#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; @@ -197,7 +199,7 @@ init_bios_info(void) mbi.flags = MB_INFO_MEMORY | MB_INFO_CMDLINE | MB_INFO_BOOTDEV; -#endif /* NO_FANCY_STUFF */ +#endif /* NO_FANCY_STUFF */ /* * Set boot drive and partition. @@ -210,5 +212,5 @@ init_bios_info(void) * Start main routine here. */ - cmain(); + cmain (); } diff --git a/shared_src/defs.h b/shared_src/defs.h index 65d639894..f7267ff8f 100644 --- a/shared_src/defs.h +++ b/shared_src/defs.h @@ -1,3 +1,4 @@ + /* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University @@ -46,21 +47,23 @@ * Compatibility definitions for old type names. */ -typedef unsigned char u_char; /* unsigned char */ -typedef unsigned short u_short; /* unsigned short */ -typedef unsigned int u_int; /* unsigned int */ +typedef unsigned char u_char; /* unsigned char */ +typedef unsigned short u_short; /* unsigned short */ +typedef unsigned int u_int; /* unsigned int */ -typedef struct _quad_ { - unsigned int val[2]; /* 2 int values make... */ -} quad; /* an 8-byte item */ +typedef struct _quad_ + { + unsigned int val[2]; /* 2 int values make... */ + } +quad; /* an 8-byte item */ -typedef unsigned int time_t; /* an unsigned int */ -typedef unsigned int daddr_t; /* an unsigned int */ -typedef unsigned int off_t; /* another unsigned int */ +typedef unsigned int time_t; /* an unsigned int */ +typedef unsigned int daddr_t; /* an unsigned int */ +typedef unsigned int off_t; /* another unsigned int */ -typedef unsigned short uid_t; -typedef unsigned short gid_t; -typedef unsigned int ino_t; +typedef unsigned short uid_t; +typedef unsigned short gid_t; +typedef unsigned int ino_t; #define NBBY 8 @@ -90,4 +93,3 @@ typedef unsigned int ino_t; #define MAXPATHLEN 1024 #define MAXSYMLINKS 8 - diff --git a/shared_src/dir.h b/shared_src/dir.h index 208df5cef..287bf6029 100644 --- a/shared_src/dir.h +++ b/shared_src/dir.h @@ -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 { - 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 */ -}; +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,16 +98,17 @@ struct direct { * Should use struct direct's, but the name field * is MAXNAMLEN - 1, and this just won't do. */ -struct dirtemplate { - u_int dot_ino; - short dot_reclen; - short dot_namlen; - char dot_name[4]; /* must be multiple of 4 */ - u_int dotdot_ino; - short dotdot_reclen; - short dotdot_namlen; - char dotdot_name[4]; /* ditto */ -}; +struct dirtemplate + { + u_int dot_ino; + short dot_reclen; + short dot_namlen; + char dot_name[4]; /* must be multiple of 4 */ + u_int dotdot_ino; + 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 { - int dd_fd; - int dd_loc; - int dd_size; - char dd_buf[DIRBLKSIZ]; -} DIR; +typedef struct _dirdesc + { + int dd_fd; + int dd_loc; + int dd_size; + char dd_buf[DIRBLKSIZ]; + } +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_ */ diff --git a/shared_src/disk_inode.h b/shared_src/disk_inode.h index e0f49ea34..b724a3f7d 100644 --- a/shared_src/disk_inode.h +++ b/shared_src/disk_inode.h @@ -58,44 +58,53 @@ #define FFS_MAX_FASTLINK_SIZE ((FFS_NDADDR + FFS_NIADDR) * sizeof(daddr_t)) -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 */ - gid_t ic_gid; /* 6: owner's group id */ - quad ic_size; /* 8: number of bytes in file */ - time_t ic_atime; /* 16: time last accessed */ - int ic_atspare; - time_t ic_mtime; /* 24: time last modified */ - int ic_mtspare; - time_t ic_ctime; /* 32: last time inode changed */ - int ic_ctspare; - union { - struct { - daddr_t Mb_db[FFS_NDADDR]; /* 40: disk block addresses */ - daddr_t Mb_ib[FFS_NIADDR]; /* 88: indirect blocks */ - } ic_Mb; - char ic_Msymlink[FFS_MAX_FASTLINK_SIZE]; - /* 40: symbolic link name */ - } ic_Mun; +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 */ + gid_t ic_gid; /* 6: owner's group id */ + quad ic_size; /* 8: number of bytes in file */ + time_t ic_atime; /* 16: time last accessed */ + int ic_atspare; + time_t ic_mtime; /* 24: time last modified */ + int ic_mtspare; + time_t ic_ctime; /* 32: last time inode changed */ + int ic_ctspare; + union + { + struct + { + daddr_t Mb_db[FFS_NDADDR]; /* 40: disk block addresses */ + daddr_t Mb_ib[FFS_NIADDR]; /* 88: indirect blocks */ + } + ic_Mb; + char ic_Msymlink[FFS_MAX_FASTLINK_SIZE]; + /* 40: symbolic link name */ + } + 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 - int ic_flags; /* 100: status, currently unused */ - int ic_blocks; /* 104: blocks actually held */ - int ic_gen; /* 108: generation number */ - int ic_spare[4]; /* 112: reserved, currently unused */ -} i_ic; + int ic_flags; /* 100: status, currently unused */ + int ic_blocks; /* 104: blocks actually held */ + int ic_gen; /* 108: generation number */ + int ic_spare[4]; /* 112: reserved, currently unused */ + } +i_ic; /* * Same structure, but on disk. */ -struct dinode { - union { - struct icommon di_com; - char di_char[128]; - } di_un; -}; +struct dinode + { + union + { + struct icommon di_com; + char di_char[128]; + } + di_un; + }; #define di_ic di_un.di_com -#endif /* _BOOT_UFS_DISK_INODE_H_ */ +#endif /* _BOOT_UFS_DISK_INODE_H_ */ diff --git a/shared_src/disk_inode_ffs.h b/shared_src/disk_inode_ffs.h index 07aaf9b99..11170727d 100644 --- a/shared_src/disk_inode_ffs.h +++ b/shared_src/disk_inode_ffs.h @@ -50,7 +50,7 @@ #define MAX_FASTLINK_SIZE FFS_MAX_FASTLINK_SIZE -#define IC_FASTLINK 0x0001 /* Symbolic link in inode */ +#define IC_FASTLINK 0x0001 /* Symbolic link in inode */ #define i_mode ic_mode #define i_nlink ic_nlink @@ -58,7 +58,7 @@ #define i_gid ic_gid #if BYTE_MSF #define i_size ic_size.val[1] -#else /* BYTE_LSF */ +#else /* BYTE_LSF */ #define i_size ic_size.val[0] #endif #define i_db ic_db @@ -73,19 +73,19 @@ #define i_gen ic_gen /* modes */ -#define IFMT 0xf000 /* type of file */ -#define IFCHR 0x2000 /* character special */ -#define IFDIR 0x4000 /* directory */ -#define IFBLK 0x6000 /* block special */ -#define IFREG 0x8000 /* regular */ -#define IFLNK 0xa000 /* symbolic link */ -#define IFSOCK 0xc000 /* socket */ +#define IFMT 0xf000 /* type of file */ +#define IFCHR 0x2000 /* character special */ +#define IFDIR 0x4000 /* directory */ +#define IFBLK 0x6000 /* block special */ +#define IFREG 0x8000 /* regular */ +#define IFLNK 0xa000 /* symbolic link */ +#define IFSOCK 0xc000 /* socket */ -#define ISUID 0x0800 /* set user id on execution */ -#define ISGID 0x0400 /* set group id on execution */ -#define ISVTX 0x0200 /* save swapped text even after use */ -#define IREAD 0x0100 /* read, write, execute permissions */ +#define ISUID 0x0800 /* set user id on execution */ +#define ISGID 0x0400 /* set group id on execution */ +#define ISVTX 0x0200 /* save swapped text even after use */ +#define IREAD 0x0100 /* read, write, execute permissions */ #define IWRITE 0x0080 #define IEXEC 0x0040 @@ -96,6 +96,6 @@ #define f_blk u.ffs.ffs_blk #define f_blksize u.ffs.ffs_blksize #define f_blkno u.ffs.ffs_blkno -#endif /* EEK */ +#endif /* EEK */ -#endif _BOOT_UFS_DISK_INODE_FFS_H_ +#endif /* _BOOT_UFS_DISK_INODE_FFS_H_ */ diff --git a/shared_src/disk_io.c b/shared_src/disk_io.c index d555928ea..3bef84a6a 100644 --- a/shared_src/disk_io.c +++ b/shared_src/disk_io.c @@ -29,9 +29,9 @@ #ifndef NO_FANCY_STUFF /* instrumentation variables */ -void (*debug_fs)(int) = NULL; -void (*debug_fs_func)(int) = NULL; -#endif /* NO_FANCY_STUFF */ +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 are meant to be working values. */ @@ -49,7 +49,7 @@ int bsd_evil_hack; int fsys_type = NUM_FSYS; #ifndef NO_BLOCK_FILES int block_file = 0; -#endif /* NO_BLOCK_FILES */ +#endif /* NO_BLOCK_FILES */ /* these are the translated numbers for the open partition */ long part_start; @@ -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,8 +118,8 @@ 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, - read_start, read_len, BUFFERSEG)) + if (bios_err = biosdisk (BIOSDISK_SUBFUNC_READ, drive, buf_geom, + read_start, read_len, BUFFERSEG)) { buf_track = -1; @@ -132,8 +132,8 @@ 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, - sector, slen, BUFFERSEG)) + || biosdisk (BIOSDISK_SUBFUNC_READ, drive, buf_geom, + sector, slen, BUFFERSEG)) errnum = ERR_READ; bufaddr = BUFFERSEG + byte_offset; @@ -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 */ +#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,8 +197,8 @@ 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); -#endif /* !NO_FANCY_STUFF && DEBUG */ + printf ("<%d, %d, %d>", sector, byte_offset, byte_len); +#endif /* !NO_FANCY_STUFF && DEBUG */ /* * Call "rawread", which is very similar, but: @@ -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, - byte_len, addr); + return rawread (current_drive, part_start + sector, byte_offset, + byte_len, addr); } int -sane_partition(void) +sane_partition (void) { - 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) ) ) + 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))) 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,22 +256,22 @@ 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, - 0, 1, SCRATCHSEG)) + if (biosdisk (BIOSDISK_SUBFUNC_WRITE, saved_drive, buf_geom, + 0, 1, SCRATCHSEG)) { errnum = ERR_WRITE; return 0; @@ -284,73 +284,73 @@ 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 */ +#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, - 0, SECTOR_SIZE, (int) label_buf)) + 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 */ - if (part_no == ((current_partition >> 8) & 0xFF)) - break; +#endif /* NO_FANCY_STUFF */ + if (part_no == ((current_partition >> 8) & 0xFF)) + break; } } - 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 - && (part_no == 0xFF || slice_no <= part_no) - && rawread(current_drive, part_offset, - 0, SECTOR_SIZE, (int) mbr_buf) ) + while (slice_no < 255 && ext >= 0 + && (part_no == 0xFF || slice_no <= part_no) + && 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; @@ -421,11 +421,11 @@ real_open_partition(int flags) for (i = 0; i < PC_SLICE_MAX; i++) { 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_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); /* * Is this PC partition entry valid? @@ -449,14 +449,14 @@ 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 */ +#endif /* NO_FANCY_STUFF */ /* * If we've found the right partition, we're done */ @@ -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,10 +518,10 @@ real_open_partition(int flags) else { current_partition = 0xFFFFFF; - check_and_print_mount(); + check_and_print_mount (); errnum = 0; } -#endif /* NO_FANCY_STUFF */ +#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_UNSPECIFIED = 0, + PART_DISK, + PART_CHOSEN, + } +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*)¤t_drive); + safe_parse_maxint (&device, (int *) ¤t_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*)¤t_partition) + || !safe_parse_maxint (&device, (int *) ¤t_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,32 +695,32 @@ 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 ) - { - current_drive = 0xFF; - return 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 + || saved_partition != current_partition || (*filename == '/' && fsys_type == NUM_FSYS) || buf_drive == -1) { @@ -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,17 +840,17 @@ print_completions(char *filename) */ int -open(char *filename) +open (char *filename) { #ifndef NO_DECOMPRESSION compressed_file = 0; -#endif /* NO_DECOMPRESSION */ +#endif /* NO_DECOMPRESSION */ /* if any "dir" function uses/sets filepos, it must 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,14 +918,14 @@ open(char *filename) BLK_CUR_BLKNUM = 0; #ifndef NO_DECOMPRESSION - return gunzip_test_header(); -#else /* NO_DECOMPRESSION */ + return gunzip_test_header (); +#else /* NO_DECOMPRESSION */ return 1; -#endif /* NO_DECOMPRESSION */ +#endif /* NO_DECOMPRESSION */ } -#else /* NO_BLOCK_FILES */ +#else /* NO_BLOCK_FILES */ errnum = ERR_BAD_FILENAME; -#endif /* NO_BLOCK_FILES */ +#endif /* NO_BLOCK_FILES */ } if (!errnum && fsys_type == NUM_FSYS) @@ -933,13 +934,13 @@ 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(); -#else /* NO_DECOMPRESSION */ + return gunzip_test_header (); +#else /* NO_DECOMPRESSION */ return 1; -#endif /* NO_DECOMPRESSION */ +#endif /* NO_DECOMPRESSION */ } return 0; @@ -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,8 +969,8 @@ read(int addr, int len) #ifndef NO_DECOMPRESSION if (compressed_file) - return gunzip_read(addr, len); -#endif /* NO_DECOMPRESSION */ + return gunzip_read (addr, len); +#endif /* NO_DECOMPRESSION */ #ifndef NO_BLOCK_FILES if (block_file) @@ -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,22 +1007,22 @@ 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; #ifndef NO_FANCY_STUFF debug_fs_func = debug_fs; -#endif /* NO_FANCY_STUFF */ +#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, - off, size, addr); + devread (BLK_BLKSTART (BLK_CUR_BLKLIST) + BLK_CUR_BLKNUM, + off, size, addr); #ifndef NO_FANCY_STUFF debug_fs_func = NULL; -#endif /* NO_FANCY_STUFF */ +#endif /* NO_FANCY_STUFF */ len -= size; filepos += size; @@ -1034,7 +1035,7 @@ read(int addr, int len) return ret; } -#endif /* NO_BLOCK_FILES */ +#endif /* NO_BLOCK_FILES */ if (fsys_type == NUM_FSYS) { @@ -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 */ +#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); } diff --git a/shared_src/fat.h b/shared_src/fat.h index 9a08d087e..c1bce8471 100644 --- a/shared_src/fat.h +++ b/shared_src/fat.h @@ -71,13 +71,13 @@ * Defines minimum disk size to be considered a FAT partition */ -#define FAT_MIN_NUM_SECTORS 720 /* 360 K disk */ +#define FAT_MIN_NUM_SECTORS 720 /* 360 K disk */ /* * Defines how to differentiate a 12-bit and 16-bit FAT. */ -#define FAT_MAX_12BIT_CLUST 4087 /* 4085 + 2 */ +#define FAT_MAX_12BIT_CLUST 4087 /* 4085 + 2 */ #define FAT_BPB_FLOPPY_NUM_SECTORS(bpb) \ ( *((unsigned short *) (((int)bpb) + 19)) \ @@ -111,4 +111,3 @@ (*((unsigned short *) (entry+26))) #define FAT_DIRENTRY_FILELENGTH(entry) \ (*((unsigned long *) (entry+28))) - diff --git a/shared_src/filesys.h b/shared_src/filesys.h index a62506952..93a919d8d 100644 --- a/shared_src/filesys.h +++ b/shared_src/filesys.h @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -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); -}; + { + char *name; + 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 - diff --git a/shared_src/freebsd.h b/shared_src/freebsd.h index 18d564e2a..69fcbf6f4 100644 --- a/shared_src/freebsd.h +++ b/shared_src/freebsd.h @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -18,22 +19,22 @@ */ /* command-line parameter defines */ -#define RB_ASKNAME 0x01 /* ask for file name to reboot from */ -#define RB_SINGLE 0x02 /* reboot to single user only */ -#define RB_NOSYNC 0x04 /* dont sync before reboot */ -#define RB_HALT 0x08 /* don't reboot, just halt */ -#define RB_INITNAME 0x10 /* name given for /etc/init (unused) */ -#define RB_DFLTROOT 0x20 /* use compiled-in rootdev */ -#define RB_KDB 0x40 /* give control to kernel debugger */ -#define RB_RDONLY 0x80 /* mount root fs read-only */ -#define RB_DUMP 0x100 /* dump kernel memory before reboot */ -#define RB_MINIROOT 0x200 /* mini-root present in memory at boot time */ -#define RB_CONFIG 0x400 /* invoke user configuration routing */ -#define RB_VERBOSE 0x800 /* print all potentially useful info */ -#define RB_SERIAL 0x1000 /* user serial port as console */ -#define RB_CDROM 0x2000 /* use cdrom as root */ +#define RB_ASKNAME 0x01 /* ask for file name to reboot from */ +#define RB_SINGLE 0x02 /* reboot to single user only */ +#define RB_NOSYNC 0x04 /* dont sync before reboot */ +#define RB_HALT 0x08 /* don't reboot, just halt */ +#define RB_INITNAME 0x10 /* name given for /etc/init (unused) */ +#define RB_DFLTROOT 0x20 /* use compiled-in rootdev */ +#define RB_KDB 0x40 /* give control to kernel debugger */ +#define RB_RDONLY 0x80 /* mount root fs read-only */ +#define RB_DUMP 0x100 /* dump kernel memory before reboot */ +#define RB_MINIROOT 0x200 /* mini-root present in memory at boot time */ +#define RB_CONFIG 0x400 /* invoke user configuration routing */ +#define RB_VERBOSE 0x800 /* print all potentially useful info */ +#define RB_SERIAL 0x1000 /* user serial port as console */ +#define RB_CDROM 0x2000 /* use cdrom as root */ -#define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ +#define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ /* * Constants for converting boot-style device number to type, @@ -71,20 +72,20 @@ * Flags are used to indicate the validity of fields where zero is a * normal value. */ -struct bootinfo { - unsigned int bi_version; - unsigned char *bi_kernelname; - struct nfs_diskless *bi_nfs_diskless; - /* End of fields that are always present. */ +struct bootinfo + { + unsigned int bi_version; + unsigned char *bi_kernelname; + struct nfs_diskless *bi_nfs_diskless; + /* End of fields that are always present. */ #define bi_endcommon bi_n_bios_used - unsigned int bi_n_bios_used; - unsigned long bi_bios_geom[N_BIOS_GEOM]; - unsigned int bi_size; - unsigned char bi_memsizes_valid; - unsigned char bi_pad[3]; - unsigned long bi_basemem; - unsigned long bi_extmem; - unsigned long bi_symtab; - unsigned long bi_esymtab; -}; - + unsigned int bi_n_bios_used; + unsigned long bi_bios_geom[N_BIOS_GEOM]; + unsigned int bi_size; + unsigned char bi_memsizes_valid; + unsigned char bi_pad[3]; + unsigned long bi_basemem; + unsigned long bi_extmem; + unsigned long bi_symtab; + unsigned long bi_esymtab; + }; diff --git a/shared_src/fs.h b/shared_src/fs.h index 5809ed937..69e46341f 100644 --- a/shared_src/fs.h +++ b/shared_src/fs.h @@ -1,3 +1,4 @@ + /* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University @@ -131,110 +132,111 @@ * N.B. sizeof(struct csum) must be a power of two in order for * the ``fs_cs'' macro to work (see below). */ -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 */ -}; +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;*/ - 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 */ - daddr_t fs_dblkno; /* offset of first data after cg */ - int fs_cgoffset; /* cylinder group offset in cylinder */ - int fs_cgmask; /* used to calc mod fs_ntrak */ - time_t fs_time; /* last time written */ - int fs_size; /* number of blocks in fs */ - int fs_dsize; /* number of data blocks in fs */ - int fs_ncg; /* number of cylinder groups */ - int fs_bsize; /* size of basic blocks in fs */ - int fs_fsize; /* size of frag blocks in fs */ - int fs_frag; /* number of frags in a block in fs */ +struct fs + { + 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 */ + daddr_t fs_dblkno; /* offset of first data after cg */ + int fs_cgoffset; /* cylinder group offset in cylinder */ + int fs_cgmask; /* used to calc mod fs_ntrak */ + time_t fs_time; /* last time written */ + int fs_size; /* number of blocks in fs */ + int fs_dsize; /* number of data blocks in fs */ + int fs_ncg; /* number of cylinder groups */ + int fs_bsize; /* size of basic blocks in fs */ + int fs_fsize; /* size of frag blocks in fs */ + int fs_frag; /* number of frags in a block in fs */ /* these are configuration parameters */ - int fs_minfree; /* minimum percentage of free blocks */ - int fs_rotdelay; /* num of ms for optimal next block */ - int fs_rps; /* disk revolutions per second */ + int fs_minfree; /* minimum percentage of free blocks */ + int fs_rotdelay; /* num of ms for optimal next block */ + int fs_rps; /* disk revolutions per second */ /* these fields can be computed from the others */ - int fs_bmask; /* ``blkoff'' calc of blk offsets */ - int fs_fmask; /* ``fragoff'' calc of frag offsets */ - int fs_bshift; /* ``lblkno'' calc of logical blkno */ - int fs_fshift; /* ``numfrags'' calc number of frags */ + int fs_bmask; /* ``blkoff'' calc of blk offsets */ + int fs_fmask; /* ``fragoff'' calc of frag offsets */ + int fs_bshift; /* ``lblkno'' calc of logical blkno */ + int fs_fshift; /* ``numfrags'' calc number of frags */ /* these are configuration parameters */ - int fs_maxcontig; /* max number of contiguous blks */ - int fs_maxbpg; /* max number of blks per cyl group */ + int fs_maxcontig; /* max number of contiguous blks */ + int fs_maxbpg; /* max number of blks per cyl group */ /* these fields can be computed from the others */ - int fs_fragshift; /* block to frag shift */ - int fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ - int fs_sbsize; /* actual size of super block */ - int fs_csmask; /* csum block offset */ - int fs_csshift; /* csum block number */ - int fs_nindir; /* value of NINDIR */ - int fs_inopb; /* value of INOPB */ - int fs_nspf; /* value of NSPF */ + int fs_fragshift; /* block to frag shift */ + int fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ + int fs_sbsize; /* actual size of super block */ + int fs_csmask; /* csum block offset */ + int fs_csshift; /* csum block number */ + int fs_nindir; /* value of NINDIR */ + int fs_inopb; /* value of INOPB */ + int fs_nspf; /* value of NSPF */ /* yet another configuration parameter */ - int fs_optim; /* optimization preference, see below */ + int fs_optim; /* optimization preference, see below */ /* these fields are derived from the hardware */ - int fs_npsect; /* # sectors/track including spares */ - int fs_interleave; /* hardware sector interleave */ - int fs_trackskew; /* sector 0 skew, per track */ - int fs_headswitch; /* head switch time, usec */ - int fs_trkseek; /* track-to-track seek, usec */ + int fs_npsect; /* # sectors/track including spares */ + int fs_interleave; /* hardware sector interleave */ + int fs_trackskew; /* sector 0 skew, per track */ + int fs_headswitch; /* head switch time, usec */ + int fs_trkseek; /* track-to-track seek, usec */ /* sizes determined by number of cylinder groups and their sizes */ - daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ - int fs_cssize; /* size of cyl grp summary area */ - int fs_cgsize; /* cylinder group size */ + daddr_t fs_csaddr; /* blk addr of cyl grp summary area */ + int fs_cssize; /* size of cyl grp summary area */ + int fs_cgsize; /* cylinder group size */ /* these fields are derived from the hardware */ - int fs_ntrak; /* tracks per cylinder */ - int fs_nsect; /* sectors per track */ - int fs_spc; /* sectors per cylinder */ + int fs_ntrak; /* tracks per cylinder */ + int fs_nsect; /* sectors per track */ + int fs_spc; /* sectors per cylinder */ /* this comes from the disk driver partitioning */ - int fs_ncyl; /* cylinders in file system */ + int fs_ncyl; /* cylinders in file system */ /* these fields can be computed from the others */ - int fs_cpg; /* cylinders per group */ - int fs_ipg; /* inodes per group */ - int fs_fpg; /* blocks per group * fs_frag */ + int fs_cpg; /* cylinders per group */ + int fs_ipg; /* inodes per group */ + int fs_fpg; /* blocks per group * fs_frag */ /* this data must be re-computed after crashes */ - struct csum fs_cstotal; /* cylinder summary information */ + struct csum fs_cstotal; /* cylinder summary information */ /* these fields are cleared at mount time */ - char fs_fmod; /* super block modified flag */ - char fs_clean; /* file system is clean flag */ - char fs_ronly; /* mounted read-only flag */ - char fs_flags; /* currently unused flag */ - char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ + char fs_fmod; /* super block modified flag */ + char fs_clean; /* file system is clean flag */ + char fs_ronly; /* mounted read-only flag */ + char fs_flags; /* currently unused flag */ + char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ /* these fields retain the current block allocation info */ - int fs_cgrotor; /* last cg searched */ + int fs_cgrotor; /* last cg searched */ #if 1 - int was_fs_csp[MAXCSBUFS]; + 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 */ - long fs_sparecon[50]; /* reserved for future constants */ - long fs_contigsumsize; /* size of cluster summary array */ - long fs_maxsymlinklen; /* max length of an internal symlink */ - long fs_inodefmt; /* format of on-disk inodes */ - quad fs_maxfilesize; /* maximum representable file size */ - quad fs_qbmask; /* ~fs_bmask - for use with quad size */ - quad fs_qfmask; /* ~fs_fmask - for use with quad size */ - long fs_state; /* validate fs_clean field */ - int fs_postblformat; /* format of positional layout tables */ - int fs_nrpos; /* number of rotaional positions */ - int fs_postbloff; /* (short) rotation block list head */ - int fs_rotbloff; /* (u_char) blocks for each rotation */ - int fs_magic; /* magic number */ - u_char fs_space[1]; /* list of blocks for each rotation */ + int fs_cpc; /* cyl per cycle in postbl */ + short fs_opostbl[16][8]; /* old rotation block list head */ + long fs_sparecon[50]; /* reserved for future constants */ + long fs_contigsumsize; /* size of cluster summary array */ + long fs_maxsymlinklen; /* max length of an internal symlink */ + long fs_inodefmt; /* format of on-disk inodes */ + quad fs_maxfilesize; /* maximum representable file size */ + quad fs_qbmask; /* ~fs_bmask - for use with quad size */ + quad fs_qfmask; /* ~fs_fmask - for use with quad size */ + long fs_state; /* validate fs_clean field */ + int fs_postblformat; /* format of positional layout tables */ + int fs_nrpos; /* number of rotaional positions */ + int fs_postbloff; /* (short) rotation block list head */ + int fs_rotbloff; /* (u_char) blocks for each rotation */ + int fs_magic; /* magic number */ + u_char fs_space[1]; /* list of blocks for each rotation */ /* actually longer */ -}; + }; /* * Preference for optimization. */ @@ -270,28 +272,29 @@ struct fs * Cylinder group block for a file system. */ #define CG_MAGIC 0x090255 -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 */ - short cg_ncyl; /* number of cyl's this cg */ - short cg_niblk; /* number of inode blocks this cg */ - int cg_ndblk; /* number of data blocks this cg */ - struct csum cg_cs; /* cylinder summary information */ - int cg_rotor; /* position of last used block */ - int cg_frotor; /* position of last used frag */ - int cg_irotor; /* position of last used inode */ - int cg_frsum[MAXFRAG]; /* counts of available frags */ - int cg_btotoff; /* (long) block totals per cylinder */ - int cg_boff; /* (short) free block positions */ - int cg_iusedoff; /* (char) used inode map */ - int cg_freeoff; /* (u_char) free block map */ - int cg_nextfreeoff; /* (u_char) next available space */ - int cg_sparecon[16]; /* reserved for future use */ - u_char cg_space[1]; /* space for cylinder group maps */ +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 */ + short cg_ncyl; /* number of cyl's this cg */ + short cg_niblk; /* number of inode blocks this cg */ + int cg_ndblk; /* number of data blocks this cg */ + struct csum cg_cs; /* cylinder summary information */ + int cg_rotor; /* position of last used block */ + int cg_frotor; /* position of last used frag */ + int cg_irotor; /* position of last used inode */ + int cg_frsum[MAXFRAG]; /* counts of available frags */ + int cg_btotoff; /* (long) block totals per cylinder */ + int cg_boff; /* (short) free block positions */ + int cg_iusedoff; /* (char) used inode map */ + int cg_freeoff; /* (u_char) free block map */ + int cg_nextfreeoff; /* (u_char) next available space */ + 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,26 +321,27 @@ 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;*/ - 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 */ - short cg_niblk; /* number of inode blocks this cg */ - int cg_ndblk; /* number of data blocks this cg */ - struct csum cg_cs; /* cylinder summary information */ - int cg_rotor; /* position of last used block */ - int cg_frotor; /* position of last used frag */ - int cg_irotor; /* position of last used inode */ - int cg_frsum[8]; /* counts of available frags */ - int cg_btot[32]; /* block totals per cylinder */ - short cg_b[32][8]; /* positions of free blocks */ - char cg_iused[256]; /* used inode map */ - int cg_magic; /* magic number */ - u_char cg_free[1]; /* free block map */ +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 */ + short cg_niblk; /* number of inode blocks this cg */ + int cg_ndblk; /* number of data blocks this cg */ + struct csum cg_cs; /* cylinder summary information */ + int cg_rotor; /* position of last used block */ + int cg_frotor; /* position of last used frag */ + int cg_irotor; /* position of last used inode */ + int cg_frsum[8]; /* counts of available frags */ + int cg_btot[32]; /* block totals per cylinder */ + short cg_b[32][8]; /* positions of free blocks */ + char cg_iused[256]; /* used inode map */ + 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) - diff --git a/shared_src/fsys_ext2fs.c b/shared_src/fsys_ext2fs.c index c2563b0a6..6c25c40c1 100644 --- a/shared_src/fsys_ext2fs.c +++ b/shared_src/fsys_ext2fs.c @@ -28,11 +28,11 @@ static int mapblock1, mapblock2; #define DEV_BSIZE 512 /* include/linux/fs.h */ -#define BLOCK_SIZE 1024 /* initial block size for superblock read */ +#define BLOCK_SIZE 1024 /* initial block size for superblock read */ /* made up, defaults to 1 but can be passed via mount_opts */ #define WHICH_SUPER 1 /* kind of from fs/ext2/super.c */ -#define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE) /* = 2 */ +#define SBLOCK (WHICH_SUPER * BLOCK_SIZE / DEV_BSIZE) /* = 2 */ /* include/asm-i386/types.h */ typedef __signed__ char __s8; @@ -52,113 +52,132 @@ typedef unsigned int __u32; #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1) /* include/linux/ext2_fs.h */ -struct ext2_super_block { - __u32 s_inodes_count; /* Inodes count */ - __u32 s_blocks_count; /* Blocks count */ - __u32 s_r_blocks_count; /* Reserved blocks count */ - __u32 s_free_blocks_count; /* Free blocks count */ - __u32 s_free_inodes_count; /* Free inodes count */ - __u32 s_first_data_block; /* First Data Block */ - __u32 s_log_block_size; /* Block size */ - __s32 s_log_frag_size; /* Fragment size */ - __u32 s_blocks_per_group; /* # Blocks per group */ - __u32 s_frags_per_group; /* # Fragments per group */ - __u32 s_inodes_per_group; /* # Inodes per group */ - __u32 s_mtime; /* Mount time */ - __u32 s_wtime; /* Write time */ - __u16 s_mnt_count; /* Mount count */ - __s16 s_max_mnt_count; /* Maximal mount count */ - __u16 s_magic; /* Magic signature */ - __u16 s_state; /* File system state */ - __u16 s_errors; /* Behaviour when detecting errors */ - __u16 s_pad; - __u32 s_lastcheck; /* time of last check */ - __u32 s_checkinterval; /* max. time between checks */ - __u32 s_creator_os; /* OS */ - __u32 s_rev_level; /* Revision level */ - __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_super_block + { + __u32 s_inodes_count; /* Inodes count */ + __u32 s_blocks_count; /* Blocks count */ + __u32 s_r_blocks_count; /* Reserved blocks count */ + __u32 s_free_blocks_count; /* Free blocks count */ + __u32 s_free_inodes_count; /* Free inodes count */ + __u32 s_first_data_block; /* First Data Block */ + __u32 s_log_block_size; /* Block size */ + __s32 s_log_frag_size; /* Fragment size */ + __u32 s_blocks_per_group; /* # Blocks per group */ + __u32 s_frags_per_group; /* # Fragments per group */ + __u32 s_inodes_per_group; /* # Inodes per group */ + __u32 s_mtime; /* Mount time */ + __u32 s_wtime; /* Write time */ + __u16 s_mnt_count; /* Mount count */ + __s16 s_max_mnt_count; /* Maximal mount count */ + __u16 s_magic; /* Magic signature */ + __u16 s_state; /* File system state */ + __u16 s_errors; /* Behaviour when detecting errors */ + __u16 s_pad; + __u32 s_lastcheck; /* time of last check */ + __u32 s_checkinterval; /* max. time between checks */ + __u32 s_creator_os; /* OS */ + __u32 s_rev_level; /* Revision level */ + __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 */ - __u16 bg_free_blocks_count; /* Free blocks count */ - __u16 bg_free_inodes_count; /* Free inodes count */ - __u16 bg_used_dirs_count; /* Directories count */ - __u16 bg_pad; - __u32 bg_reserved[3]; -}; + { + __u32 bg_block_bitmap; /* Blocks bitmap block */ + __u32 bg_inode_bitmap; /* Inodes bitmap block */ + __u32 bg_inode_table; /* Inodes table block */ + __u16 bg_free_blocks_count; /* Free blocks count */ + __u16 bg_free_inodes_count; /* Free inodes count */ + __u16 bg_used_dirs_count; /* Directories count */ + __u16 bg_pad; + __u32 bg_reserved[3]; + }; -struct ext2_inode { - __u16 i_mode; /* File mode */ - __u16 i_uid; /* Owner Uid */ - __u32 i_size; /* 4: Size in bytes */ - __u32 i_atime; /* Access time */ - __u32 i_ctime; /* 12: Creation time */ - __u32 i_mtime; /* Modification time */ - __u32 i_dtime; /* 20: Deletion Time */ - __u16 i_gid; /* Group Id */ - __u16 i_links_count; /* 24: Links count */ - __u32 i_blocks; /* Blocks count */ - __u32 i_flags; /* 32: File flags */ - union { - struct { - __u32 l_i_reserved1; - } linux1; - struct { - __u32 h_i_translator; - } hurd1; - struct { - __u32 m_i_reserved1; - } 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 { - __u8 l_i_frag; /* Fragment number */ - __u8 l_i_fsize; /* Fragment size */ - __u16 i_pad1; - __u32 l_i_reserved2[2]; - } 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 { - __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 */ -}; +struct ext2_inode + { + __u16 i_mode; /* File mode */ + __u16 i_uid; /* Owner Uid */ + __u32 i_size; /* 4: Size in bytes */ + __u32 i_atime; /* Access time */ + __u32 i_ctime; /* 12: Creation time */ + __u32 i_mtime; /* Modification time */ + __u32 i_dtime; /* 20: Deletion Time */ + __u16 i_gid; /* Group Id */ + __u16 i_links_count; /* 24: Links count */ + __u32 i_blocks; /* Blocks count */ + __u32 i_flags; /* 32: File flags */ + union + { + struct + { + __u32 l_i_reserved1; + } + linux1; + struct + { + __u32 h_i_translator; + } + hurd1; + struct + { + __u32 m_i_reserved1; + } + 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 + { + __u8 l_i_frag; /* Fragment number */ + __u8 l_i_fsize; /* Fragment size */ + __u16 i_pad1; + __u32 l_i_reserved2[2]; + } + 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 + { + __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 */ + }; /* linux/limits.h */ -#define NAME_MAX 255 /* # chars in a file name */ +#define NAME_MAX 255 /* # chars in a file name */ /* linux/posix_type.h */ typedef long off_t; /* linux/ext2fs.h */ #define EXT2_NAME_LEN 255 -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 */ -}; +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 */ /* @@ -175,10 +194,10 @@ struct ext2_dir_entry { /* ext2/super.c */ #define log2(n) ffz(~(n)) -#define EXT2_SUPER_MAGIC 0xEF53 /* include/linux/ext2_fs.h */ -#define EXT2_ROOT_INO 2 /* include/linux/ext2_fs.h */ -#define PATH_MAX 1024 /* include/linux/limits.h */ -#define MAX_LINK_COUNT 5 /* number of symbolic links to follow */ +#define EXT2_SUPER_MAGIC 0xEF53 /* include/linux/ext2_fs.h */ +#define EXT2_ROOT_INO 2 /* include/linux/ext2_fs.h */ +#define PATH_MAX 1024 /* include/linux/limits.h */ +#define MAX_LINK_COUNT 5 /* number of symbolic links to follow */ /* made up, these are pointers into FSYS_BUF */ /* read once, always stays there: */ @@ -219,27 +238,28 @@ 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)); - return 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)) - && (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) - || SUPERBLOCK->s_magic != EXT2_SUPER_MAGIC) - retval = 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) + || SUPERBLOCK->s_magic != EXT2_SUPER_MAGIC) + retval = 0; return retval; } @@ -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,93 +284,110 @@ 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(" "); } - } - printf("logical block %d\n", logical_block); + 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 (" "); + } + } + 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", 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]; - } + return INODE->i_block[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)) { - errnum = ERR_FSYS_CORRUPT; - return -1; + 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]; } - mapblock1 = 1; - 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))) { - int bnum; - if ( mapblock1 != 2 - && !ext2_rdfsb(INODE->i_block[EXT2_DIND_BLOCK], DATABLOCK1)) { - errnum = ERR_FSYS_CORRUPT; - return -1; + 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)) + { + errnum = ERR_FSYS_CORRUPT; + return -1; + } + mapblock1 = 2; + if ((bnum = (((__u32 *) DATABLOCK1) + [logical_block >> EXT2_ADDR_PER_BLOCK_BITS (SUPERBLOCK)])) + != mapblock2 + && !ext2_rdfsb (bnum, DATABLOCK2)) + { + errnum = ERR_FSYS_CORRUPT; + return -1; + } + mapblock2 = bnum; + return ((__u32 *) DATABLOCK2) + [logical_block & (EXT2_ADDR_PER_BLOCK (SUPERBLOCK) - 1)]; } - mapblock1 = 2; - if ( (bnum = (((__u32 *)DATABLOCK1) - [logical_block >> EXT2_ADDR_PER_BLOCK_BITS(SUPERBLOCK)])) - != mapblock2 - && !ext2_rdfsb(bnum, DATABLOCK2)) { - errnum = ERR_FSYS_CORRUPT; - return -1; - } - mapblock2 = bnum; - 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)) { - errnum = ERR_FSYS_CORRUPT; - return -1; - } + 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)) { - 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)) { - errnum = ERR_FSYS_CORRUPT; - return -1; - } - return ((__u32 *)DATABLOCK2) - [logical_block & (EXT2_ADDR_PER_BLOCK(SUPERBLOCK)-1)]; + 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)) + { + errnum = ERR_FSYS_CORRUPT; + return -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,48 +397,56 @@ 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) { - /* 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); + 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); #ifdef E2DEBUG - printf("map=%d\n", map); + printf ("map=%d\n", map); #endif /* E2DEBUG */ - if (map < 0) - break; + if (map < 0) + break; - size = EXT2_BLOCK_SIZE(SUPERBLOCK); - size -= offset; - if (size > len) - size = len; + size = EXT2_BLOCK_SIZE (SUPERBLOCK); + size -= offset; + if (size > len) + size = len; #ifndef NO_FANCY_STUFF - debug_fs_func = debug_fs; -#endif /* NO_FANCY_STUFF */ + debug_fs_func = debug_fs; +#endif /* NO_FANCY_STUFF */ - devread(map * (EXT2_BLOCK_SIZE(SUPERBLOCK) / DEV_BSIZE), - offset, size, addr); + devread (map * (EXT2_BLOCK_SIZE (SUPERBLOCK) / DEV_BSIZE), + offset, size, addr); #ifndef NO_FANCY_STUFF - debug_fs_func = NULL; -#endif /* NO_FANCY_STUFF */ + debug_fs_func = NULL; +#endif /* NO_FANCY_STUFF */ - addr += size; - len -= size; - filepos += size; - ret += size; - } + addr += size; + len -= size; + filepos += size; + ret += size; + } if (errnum) ret = 0; @@ -440,271 +486,289 @@ 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 current_ino = EXT2_ROOT_INO; /* start at the root */ int updir_ino = current_ino; /* the parent of the current directory */ - int group_id; /* which group the inode is in */ - int group_desc; /* fs pointer to that group */ - 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 */ + int group_id; /* which group the inode is in */ + int group_desc; /* fs pointer to that group */ + 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 */ - char linkbuf[PATH_MAX]; /* buffer for following symbolic links */ + char linkbuf[PATH_MAX]; /* buffer for following symbolic links */ int link_count = 0; char *rest; - char ch; /* temp char holder */ + char ch; /* temp char holder */ - int off; /* offset within block of directory entry (off mod blocksize) */ - int loc; /* location within a directory */ - int blk; /* which data blk within dir entry (off div blocksize) */ - long map; /* fs pointer of a particular block from dir entry */ - struct ext2_dir_entry *dp; /* pointer to directory entry */ + int off; /* offset within block of directory entry (off mod blocksize) */ + int loc; /* location within a directory */ + int blk; /* which data blk within dir entry (off div blocksize) */ + long map; /* fs pointer of a particular block from dir entry */ + 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 dirname = pointer to filename component we are cur looking up within - the directory known pointed to by current_ino (if any) - */ + 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); + /* 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); #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( - (WHICH_SUPER + group_desc + SUPERBLOCK->s_first_data_block), - (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))); -#ifdef E2DEBUG - printf("inode table fsblock=%d\n", ino_blk); -#endif /* E2DEBUG */ - if (!ext2_rdfsb(ino_blk, (int)INODE)) { - return 0; - } - - /* reset indirect blocks! */ - mapblock2 = mapblock1 = -1; - - raw_inode = INODE + - ((current_ino - 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("first word=%x\n", *((int *)raw_inode)); -#endif /* E2DEBUG */ - - /* copy inode to fixed location */ - bcopy((void *)raw_inode, (void *)INODE, sizeof(struct ext2_inode)); - -#ifdef E2DEBUG - 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)) - { - int len, remaining; - if (++ link_count > MAX_LINK_COUNT) - { - errnum = ERR_SYMLINK_LOOP; - return 0; - } - - /* Find out how long our remaining name is. */ - len = 0; - while (dirname[len] && !isspace (dirname[len])) - len ++; - - /* Get the symlink size. */ - filemax = (INODE->i_size); - if (filemax + len > sizeof (linkbuf) - 2) - { - errnum = ERR_FILELENGTH; - return 0; - } - - if (len) - { - /* Copy the remaining name to the end of the symlink data. - Note that DIRNAME and LINKBUF may overlap! */ - bcopy (dirname, linkbuf + filemax, len); - } - linkbuf[filemax + len] = '\0'; - - /* Read the symlink data. */ - if (INODE->i_blocks) - { - /* Read the necessary blocks, and reset the file pointer. */ - len = read ((int) linkbuf, filemax); - filepos = 0; - if (!len) - return 0; - } - else - { - /* Copy the data directly from the inode. */ - len = filemax; - bcopy ((char *) INODE->i_block, linkbuf, len); - } - -#if E2DEBUG - printf ("symlink=%s\n", linkbuf); -#endif - - dirname = linkbuf; - if (*dirname == '/') - { - /* It's an absolute link, so look it up in root. */ - current_ino = EXT2_ROOT_INO; - updir_ino = current_ino; - } - else - { - /* Relative, so look it up in our parent directory. */ - current_ino = updir_ino; - } - - /* Try again using the new name. */ - continue; - } - - /* if end of filename, INODE points to the file's inode */ - if (!*dirname || isspace(*dirname)) - { - if (!S_ISREG(INODE->i_mode)) - { - errnum = ERR_BAD_FILETYPE; - return 0; - } - - filemax = (INODE->i_size); - return 1; - } - - /* else we have to traverse a directory */ - updir_ino = current_ino; - - /* skip over slashes */ - while (*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)) - { - errnum = ERR_BAD_FILETYPE; - return 0; - } - - /* skip to next slash or end of filename (space) */ - 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 { - -#ifdef E2DEBUG - 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'); - } - else { - errnum = ERR_FILE_NOT_FOUND; - *rest = ch; - } - return (print_possibilities < 0); - } - - /* else, find the (logical) block component of our location */ - 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); -#ifdef E2DEBUG - printf("fs block=%d\n", map); -#endif /* E2DEBUG */ - mapblock2 = -1; - 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); - /* 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); - if (dp->inode) - printf("entry=%s\n", dp->name); -#endif /* E2DEBUG */ - - if (dp->inode) + if (!ext2_rdfsb ( + (WHICH_SUPER + group_desc + SUPERBLOCK->s_first_data_block), + (int) GROUP_DESC)) { - int saved_c = dp->name[dp->name_len]; + 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))); +#ifdef E2DEBUG + printf ("inode table fsblock=%d\n", ino_blk); +#endif /* E2DEBUG */ + if (!ext2_rdfsb (ino_blk, (int) INODE)) + { + return 0; + } - dp->name[dp->name_len] = 0; - str_chk = substring(dirname, dp->name); + /* reset indirect blocks! */ + mapblock2 = mapblock1 = -1; - if (print_possibilities && ch != '/' - && (!*dirname || str_chk <= 0)) + raw_inode = INODE + + ((current_ino - 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)) { - if (print_possibilities > 0) - print_possibilities = -print_possibilities; - printf(" %s", dp->name); + printf ("\n"); + } + 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)); + +#ifdef E2DEBUG + 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)) + { + int len, remaining; + if (++link_count > MAX_LINK_COUNT) + { + errnum = ERR_SYMLINK_LOOP; + return 0; } - dp->name[dp->name_len] = saved_c; + /* Find out how long our remaining name is. */ + len = 0; + while (dirname[len] && !isspace (dirname[len])) + len++; + + /* Get the symlink size. */ + filemax = (INODE->i_size); + if (filemax + len > sizeof (linkbuf) - 2) + { + errnum = ERR_FILELENGTH; + return 0; + } + + if (len) + { + /* Copy the remaining name to the end of the symlink data. + Note that DIRNAME and LINKBUF may overlap! */ + bcopy (dirname, linkbuf + filemax, len); + } + linkbuf[filemax + len] = '\0'; + + /* Read the symlink data. */ + if (INODE->i_blocks) + { + /* Read the necessary blocks, and reset the file pointer. */ + len = read ((int) linkbuf, filemax); + filepos = 0; + if (!len) + return 0; + } + else + { + /* Copy the data directly from the inode. */ + len = filemax; + bcopy ((char *) INODE->i_block, linkbuf, len); + } + +#if E2DEBUG + printf ("symlink=%s\n", linkbuf); +#endif + + dirname = linkbuf; + if (*dirname == '/') + { + /* It's an absolute link, so look it up in root. */ + current_ino = EXT2_ROOT_INO; + updir_ino = current_ino; + } + else + { + /* Relative, so look it up in our parent directory. */ + current_ino = updir_ino; + } + + /* Try again using the new name. */ + continue; } - } while (!dp->inode || (str_chk || (print_possibilities && ch != '/')) ); + /* if end of filename, INODE points to the file's inode */ + if (!*dirname || isspace (*dirname)) + { + if (!S_ISREG (INODE->i_mode)) + { + errnum = ERR_BAD_FILETYPE; + return 0; + } - current_ino = dp->inode; - *(dirname = rest) = ch; - } + filemax = (INODE->i_size); + return 1; + } + + /* else we have to traverse a directory */ + updir_ino = current_ino; + + /* skip over slashes */ + while (*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)) + { + errnum = ERR_BAD_FILETYPE; + return 0; + } + + /* skip to next slash or end of filename (space) */ + 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 + { + +#ifdef E2DEBUG + 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'); + } + else + { + errnum = ERR_FILE_NOT_FOUND; + *rest = ch; + } + return (print_possibilities < 0); + } + + /* else, find the (logical) block component of our location */ + 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); +#ifdef E2DEBUG + printf ("fs block=%d\n", map); +#endif /* E2DEBUG */ + mapblock2 = -1; + 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); + /* 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); + if (dp->inode) + printf ("entry=%s\n", dp->name); +#endif /* E2DEBUG */ + + if (dp->inode) + { + int saved_c = dp->name[dp->name_len]; + + dp->name[dp->name_len] = 0; + 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); + } + + dp->name[dp->name_len] = saved_c; + } + + } + while (!dp->inode || (str_chk || (print_possibilities && ch != '/'))); + + current_ino = dp->inode; + *(dirname = rest) = ch; + } /* never get here */ } diff --git a/shared_src/fsys_fat.c b/shared_src/fsys_fat.c index c153d85ce..5147b6327 100644 --- a/shared_src/fsys_fat.c +++ b/shared_src/fsys_fat.c @@ -30,31 +30,31 @@ static int data_offset; static int fat_size; /* pointer(s) into filesystem info buffer for DOS stuff */ -#define BPB ( FSYS_BUF + 32256 ) /* 512 bytes long */ -#define FAT_BUF ( FSYS_BUF + 30208 ) /* 4 sector FAT buffer */ +#define BPB ( FSYS_BUF + 32256 ) /* 512 bytes long */ +#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)) - && (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) ) ) + 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))) 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,10 +109,10 @@ 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), - 0, SECTOR_SIZE * 4, FAT_BUF)) + 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; diff --git a/shared_src/fsys_ffs.c b/shared_src/fsys_ffs.c index 56e2e8c57..06c13b800 100644 --- a/shared_src/fsys_ffs.c +++ b/shared_src/fsys_ffs.c @@ -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; @@ -136,13 +136,13 @@ ffs_read(int addr, int len) #ifndef NO_FANCY_STUFF debug_fs_func = debug_fs; -#endif /* NO_FANCY_STUFF */ +#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; -#endif /* NO_FANCY_STUFF */ +#endif /* NO_FANCY_STUFF */ addr += size; len -= size; @@ -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)), - 0, SUPERBLOCK->fs_bsize, FSYS_BUF)) - return 0; /* XXX what return value? */ + 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 */ diff --git a/shared_src/gunzip.c b/shared_src/gunzip.c index 8b7206b42..d17efa5a1 100644 --- a/shared_src/gunzip.c +++ b/shared_src/gunzip.c @@ -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); } @@ -236,13 +236,13 @@ bad_field(int len) #define MAX_METHODS 9 /* gzip flag byte */ -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define COMMENT 0x10 /* bit 4 set: file comment present */ -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ -#define RESERVED 0xC0 /* bit 6,7: reserved */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ +#define RESERVED 0xC0 /* bit 6,7: reserved */ #define UNSUPP_FLAGS (CONTINUATION|ENCRYPTED|RESERVED) @@ -251,9 +251,9 @@ bad_field(int len) #define INFLATE_FIXED 1 #define INFLATE_DYNAMIC 2 -typedef unsigned char uch; +typedef unsigned char uch; typedef unsigned short ush; -typedef unsigned long ulg; +typedef unsigned long ulg; /* * Window Size @@ -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 { - uch e; /* number of extra bits or operation */ - uch b; /* number of bits in this code or subcode */ - union { - ush n; /* literal, length base, or distance base */ - struct huft *t; /* pointer to next level of table */ - } v; +struct huft +{ + uch e; /* number of extra bits or operation */ + uch b; /* number of bits in this code or subcode */ + union + { + ush n; /* literal, length base, or distance base */ + struct huft *t; /* pointer to next level of table */ + } + v; }; @@ -355,23 +358,28 @@ static unsigned wp; /* Tables for deflate from PKZIP's appnote.txt. */ -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 */ - 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 */ - 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 */ - 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 */ - 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}; +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 */ + 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 */ + 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 */ + 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 */ + 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}; /* @@ -407,16 +415,16 @@ static ush cpdext[] = { /* Extra bits for distance codes */ */ -static int lbits = 9; /* bits in base literal/length lookup table */ -static int dbits = 6; /* bits in base distance lookup table */ +static int lbits = 9; /* bits in base literal/length lookup table */ +static int dbits = 6; /* bits in base distance lookup table */ /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ -#define BMAX 16 /* maximum bit length of any code (16 for explode) */ -#define N_MAX 288 /* maximum number of codes in any set */ +#define BMAX 16 /* maximum bit length of any code (16 for explode) */ +#define N_MAX 288 /* maximum number of codes in any set */ -static unsigned hufts; /* track memory usage */ +static unsigned hufts; /* track memory usage */ /* Macros for inflate() bit peeking and grabbing. @@ -449,13 +457,14 @@ static unsigned hufts; /* track memory usage */ the stream. */ -static ulg bb; /* bit buffer */ -static unsigned bk; /* bits in bit buffer */ +static ulg bb; /* bit buffer */ +static unsigned bk; /* bits in bit buffer */ -static ush mask_bits[] = { - 0x0000, - 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, - 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff +static ush mask_bits[] = +{ + 0x0000, + 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, + 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff }; #define NEEDBITS(n) do {while(k<(n)){b|=((ulg)get_byte())< i) + g = i; /* maximum code length */ + if ((unsigned) l > i) l = i; *m = l; /* Adjust last length count to fill out codes, if needed */ for (y = 1 << j; j < i; j++, y <<= 1) if ((y -= c[j]) < 0) - return 2; /* bad input: more codes than bits */ + return 2; /* bad input: more codes than bits */ if ((y -= c[i]) < 0) return 2; c[i] += y; /* 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 */ - *xp++ = (j += *p++); - } + 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 { - if ((j = *p++) != 0) - v[x[j]++] = i; - } while (++i < n); + p = b; + i = 0; + do + { + if ((j = *p++) != 0) + v[x[j]++] = i; + } + 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 */ - z = 0; /* ditto */ + 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 */ + z = 0; /* ditto */ /* go through the bit lengths (k already is bits in shortest code) */ for (; k <= g; k++) - { - a = c[k]; - while (a--) { - /* here i is the Huffman code of length k bits for value *p */ - /* make tables up to required level */ - while (k > w + l) - { - h++; - w += l; /* previous table always l bits */ + a = c[k]; + while (a--) + { + /* here i is the Huffman code of length k bits for value *p */ + /* make tables up to required level */ + while (k > w + l) + { + h++; + 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 */ - 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 */ - xp = c + k; - while (++j < z) /* try smaller tables up to z bits */ - { - if ((f <<= 1) <= *++xp) - break; /* enough codes to use up j bits */ - f -= *xp; /* else deduct codes from patterns */ - } - } - z = 1 << j; /* table entries for j-bit table */ + /* compute minimum size table less than or equal to l bits */ + 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 */ + xp = c + k; + while (++j < z) /* try smaller tables up to z bits */ + { + if ((f <<= 1) <= *++xp) + break; /* enough codes to use up j bits */ + f -= *xp; /* else deduct codes from patterns */ + } + } + z = 1 << j; /* table entries for j-bit table */ - /* allocate and link in new table */ - q = (struct huft *)linalloc((z + 1)*sizeof(struct huft)); + /* allocate and link in new table */ + 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; - u[h] = ++q; /* table starts after link */ + hufts += z + 1; /* track memory usage */ + *t = q + 1; /* link to list for huft_free() */ + *(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.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 */ - } - } + /* 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.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 */ + } + } - /* set up table entry in r */ - 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 */ - p++; /* one compiler does not like *p++ */ - } - else - { - r.e = (uch)e[*p - s]; /* non-simple--look up in lists */ - r.v.n = d[*p++ - s]; - } + /* set up table entry in r */ + 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 */ + p++; /* one compiler does not like *p++ */ + } + else + { + r.e = (uch) e[*p - s]; /* non-simple--look up in lists */ + r.v.n = d[*p++ - s]; + } - /* fill code-like entries with r */ - f = 1 << (k - w); - for (j = i >> w; j < z; j += f) - q[j] = r; + /* fill code-like entries with r */ + f = 1 << (k - w); + for (j = i >> w; j < z; j += f) + q[j] = r; - /* backwards increment the k-bit code i */ - for (j = 1 << (k - 1); i & j; j >>= 1) - i ^= j; - i ^= j; + /* backwards increment the k-bit code i */ + for (j = 1 << (k - 1); i & j; j >>= 1) + i ^= j; + i ^= j; - /* backup over finished tables */ - while ((i & ((1 << w) - 1)) != x[h]) - { - h--; /* don't need to update q */ - w -= l; - } + /* backup over finished tables */ + while ((i & ((1 << w) - 1)) != x[h]) + { + h--; /* don't need to update q */ + w -= l; + } + } } - } /* Return true (1) if we were given an incomplete table */ return y != 0 && g != 1; @@ -683,51 +700,54 @@ 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 */ - unsigned w; /* current window position */ - struct huft *t; /* pointer to table entry */ - unsigned ml, md; /* masks for bl and bd bits */ - register ulg b; /* bit buffer */ - register unsigned k; /* number of bits in bit buffer */ + register unsigned e; /* table entry flag/number of extra bits */ + unsigned n, d; /* length and index for copy */ + unsigned w; /* current window position */ + struct huft *t; /* pointer to table entry */ + unsigned ml, md; /* masks for bl and bd bits */ + register ulg b; /* bit buffer */ + register unsigned k; /* number of bits in bit buffer */ /* make local copies of globals */ d = inflate_d; n = inflate_n; - b = bb; /* initialize bit buffer */ + b = bb; /* initialize bit buffer */ k = bk; - w = wp; /* initialize window position */ + w = wp; /* initialize window position */ /* inflate the coded data */ - ml = mask_bits[bl]; /* precompute masks for speed */ + ml = mask_bits[bl]; /* precompute masks for speed */ md = mask_bits[bd]; - for (;;) /* do until end of block */ + for (;;) /* do until end of block */ { if (!code_state) { - 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); - e -= 16; - NEEDBITS(e); - } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); - DUMPBITS(t->b); + 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); + e -= 16; + 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 */ + 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 { - if (e == 99) - { - errnum = ERR_BAD_GZIP_DATA; - return 0; - } - 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 ((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); + 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); 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); - if (w - d >= e) - { - bcopy(slide + d, slide + w, e); - w += e; - d += e; - } - else /* purposefully use the overlap for extra copies here!! */ - { - while (e--) - slide[w++] = slide[d++]; - } - if (w == WSIZE) - break; - } while (n); + do + { + n -= (e = (e = WSIZE - ((d &= WSIZE - 1) > w ? d : w)) > n ? n + : e); + if (w - d >= e) + { + bcopy (slide + d, slide + w, e); + w += e; + d += e; + } + else + /* purposefully use the overlap for extra copies here!! */ + { + while (e--) + slide[w++] = slide[d++]; + } + if (w == WSIZE) + break; + } + while (n); if (!n) code_state--; @@ -794,8 +821,8 @@ inflate_codes_in_window(void) /* restore the globals from the locals */ inflate_d = d; inflate_n = n; - wp = w; /* restore global window pointer */ - bb = b; /* restore global bit buffer */ + wp = w; /* restore global window pointer */ + bb = b; /* restore global bit buffer */ bk = k; return !block_len; @@ -805,26 +832,26 @@ 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 */ + register ulg b; /* bit buffer */ + register unsigned k; /* number of bits in bit buffer */ /* make local copies of globals */ - b = bb; /* initialize bit buffer */ + b = bb; /* initialize bit buffer */ 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,10 +864,10 @@ 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 */ + int i; /* temporary variable */ + unsigned l[288]; /* length list for huft_build */ /* set up literal table */ for (i = 0; i < 144; i++) @@ -849,20 +876,20 @@ init_fixed_block() l[i] = 9; for (; i < 280; i++) l[i] = 7; - for (; i < 288; i++) /* make a complete, but wrong code set */ + 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; } /* set up distance table */ - for (i = 0; i < 30; i++) /* make an incomplete code set */ + 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,34 +904,34 @@ 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 */ + int i; /* temporary variables */ unsigned j; - unsigned l; /* last length */ - unsigned m; /* mask for bit lengths table */ - unsigned n; /* number of lengths to get */ - 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 */ - register ulg b; /* bit buffer */ - register unsigned k; /* number of bits in bit buffer */ + unsigned l; /* last length */ + unsigned m; /* mask for bit lengths table */ + unsigned n; /* number of lengths to get */ + 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 */ + register ulg b; /* bit buffer */ + register unsigned k; /* number of bits in bit buffer */ /* make local bit buffer */ b = bb; 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 */ + 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; @@ -954,12 +981,12 @@ init_dynamic_block(void) while (j--) ll[i++] = l; } - else if (j == 17) /* 3 to 10 zero length codes */ + 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,10 +1050,10 @@ 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 */ + register ulg b; /* bit buffer */ + register unsigned k; /* number of bits in bit buffer */ hufts = 0; @@ -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 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; } - diff --git a/shared_src/i386-elf.h b/shared_src/i386-elf.h index 7d3800c00..bf234cc10 100644 --- a/shared_src/i386-elf.h +++ b/shared_src/i386-elf.h @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -19,19 +20,20 @@ /* 32-bit data types */ -typedef unsigned long Elf32_Addr; -typedef unsigned short Elf32_Half; -typedef unsigned long Elf32_Off; -typedef signed long Elf32_Sword; -typedef unsigned long Elf32_Word; +typedef unsigned long Elf32_Addr; +typedef unsigned short Elf32_Half; +typedef unsigned long Elf32_Off; +typedef signed long Elf32_Sword; +typedef unsigned long Elf32_Word; /* "unsigned char" already exists */ /* ELF header */ -typedef struct { +typedef struct + { #define EI_NIDENT 16 - /* first four characters are defined below */ + /* first four characters are defined below */ #define EI_MAG0 0 #define ELFMAG0 0x7f #define EI_MAG1 1 @@ -41,34 +43,34 @@ typedef struct { #define EI_MAG3 3 #define ELFMAG3 'F' -#define EI_CLASS 4 /* data sizes */ -#define ELFCLASS32 1 /* i386 -- up to 32-bit data sizes present */ +#define EI_CLASS 4 /* data sizes */ +#define ELFCLASS32 1 /* i386 -- up to 32-bit data sizes present */ -#define EI_DATA 5 /* data type and ordering */ -#define ELFDATA2LSB 1 /* i386 -- LSB 2's complement */ +#define EI_DATA 5 /* data type and ordering */ +#define ELFDATA2LSB 1 /* i386 -- LSB 2's complement */ -#define EI_VERSION 6 /* version number. "e_version" must be the same */ -#define EV_CURRENT 1 /* current version number */ +#define EI_VERSION 6 /* version number. "e_version" must be the same */ +#define EV_CURRENT 1 /* current version number */ -#define EI_PAD 7 /* from here in is just padding */ +#define EI_PAD 7 /* from here in is just padding */ - unsigned char e_ident[EI_NIDENT]; /* basic identification block */ + unsigned char e_ident[EI_NIDENT]; /* basic identification block */ -#define ET_EXEC 2 /* we only care about executable types */ - Elf32_Half e_type; /* file types */ +#define ET_EXEC 2 /* we only care about executable types */ + Elf32_Half e_type; /* file types */ -#define EM_386 3 /* i386 -- obviously use this one */ - Elf32_Half e_machine; /* machine types */ - Elf32_Word e_version; /* use same as "EI_VERSION" above */ - Elf32_Addr e_entry; /* entry point of the program */ - Elf32_Off e_phoff; /* program header table file offset */ - Elf32_Off e_shoff; /* section header table file offset */ - Elf32_Word e_flags; /* flags */ - Elf32_Half e_ehsize; /* elf header size in bytes */ - Elf32_Half e_phentsize; /* program header entry size */ - Elf32_Half e_phnum; /* number of entries in program header */ - Elf32_Half e_shentsize; /* section header entry size */ - Elf32_Half e_shnum; /* number of entries in section header */ +#define EM_386 3 /* i386 -- obviously use this one */ + Elf32_Half e_machine; /* machine types */ + Elf32_Word e_version; /* use same as "EI_VERSION" above */ + Elf32_Addr e_entry; /* entry point of the program */ + Elf32_Off e_phoff; /* program header table file offset */ + Elf32_Off e_shoff; /* section header table file offset */ + Elf32_Word e_flags; /* flags */ + Elf32_Half e_ehsize; /* elf header size in bytes */ + Elf32_Half e_phentsize; /* program header entry size */ + Elf32_Half e_phnum; /* number of entries in program header */ + Elf32_Half e_shentsize; /* section header entry size */ + Elf32_Half e_shnum; /* number of entries in section header */ #define SHN_UNDEF 0 #define SHN_LORESERVE 0xff00 @@ -77,8 +79,9 @@ typedef struct { #define SHN_ABS 0xfff1 #define SHN_COMMON 0xfff2 #define SHN_HIRESERVE 0xffff - Elf32_Half e_shstrndx; /* section header table index */ -} Elf32_Ehdr; + Elf32_Half e_shstrndx; /* section header table index */ + } +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; + { + 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_Half st_shndx; + } +Elf32_Sym; /* symbol type and binding attributes - page 4-26 */ @@ -134,16 +138,18 @@ typedef struct /* program header - page 5-2, figure 5-1 */ -typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; +typedef struct + { + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; + } +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 { - Elf32_Sword d_tag; - union { - Elf32_Word d_val; - Elf32_Addr d_ptr; - } d_un; -} Elf32_Dyn; +typedef struct + { + Elf32_Sword d_tag; + union + { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } + 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 - diff --git a/shared_src/imgact_aout.h b/shared_src/imgact_aout.h index a8b947d06..eb83b7ddb 100644 --- a/shared_src/imgact_aout.h +++ b/shared_src/imgact_aout.h @@ -1,3 +1,4 @@ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -94,7 +95,7 @@ /* Text segment offset. */ #define N_TXTOFF(ex) \ (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ - N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) + N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) /* Data segment offset. */ #define N_DATOFF(ex) \ @@ -117,23 +118,24 @@ * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h */ -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 */ - unsigned long a_bss; /* uninitialized data size */ - unsigned long a_syms; /* symbol table size */ - 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 */ +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 */ + unsigned long a_bss; /* uninitialized data size */ + unsigned long a_syms; /* symbol table size */ + 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 */ -#define OMAGIC 0x107 /* 0407 old impure format */ -#define NMAGIC 0x108 /* 0410 read-only text */ -#define ZMAGIC 0x10b /* 0413 demand load format */ -#define QMAGIC 0xcc /* 0314 "compact" demand load format */ +#define OMAGIC 0x107 /* 0407 old impure format */ +#define NMAGIC 0x108 /* 0410 read-only text */ +#define ZMAGIC 0x10b /* 0413 demand load format */ +#define QMAGIC 0xcc /* 0314 "compact" demand load format */ /* a_mid */ #define MID_ZERO 0 /* unknown - implementation dependent */ @@ -144,7 +146,7 @@ struct exec { #define MID_HP200 200 /* hp200 (68010) BSD binary */ #define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ #define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ -#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ +#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ /* * a_flags diff --git a/shared_src/mb_header.h b/shared_src/mb_header.h index 675f390cd..0d33dd290 100644 --- a/shared_src/mb_header.h +++ b/shared_src/mb_header.h @@ -22,27 +22,27 @@ */ struct multiboot_header -{ - /* Must be MULTIBOOT_MAGIC - see below. */ - unsigned magic; + { + /* Must be MULTIBOOT_MAGIC - see below. */ + unsigned magic; - /* Feature flags - see below. */ - unsigned flags; + /* Feature flags - see below. */ + unsigned flags; - /* - * Checksum - * - * The above fields plus this one must equal 0 mod 2^32. - */ - unsigned checksum; + /* + * Checksum + * + * The above fields plus this one must equal 0 mod 2^32. + */ + unsigned checksum; - /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ - unsigned header_addr; - unsigned load_addr; - unsigned load_end_addr; - unsigned bss_end_addr; - unsigned entry_addr; -}; + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ + unsigned header_addr; + unsigned load_addr; + 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 - diff --git a/shared_src/mb_info.h b/shared_src/mb_info.h index bd0bdf61f..91b3876db 100644 --- a/shared_src/mb_info.h +++ b/shared_src/mb_info.h @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -22,17 +23,17 @@ */ struct mod_list -{ - /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ - unsigned long mod_start; - unsigned long mod_end; + { + /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ + unsigned long mod_start; + unsigned long mod_end; - /* Module command line */ - unsigned long cmdline; + /* Module command line */ + unsigned long cmdline; - /* padding to take it to 16 bytes (must be zero) */ - unsigned long pad; -}; + /* padding to take it to 16 bytes (must be zero) */ + unsigned long pad; + }; /* @@ -43,16 +44,16 @@ struct mod_list */ struct AddrRangeDesc -{ - unsigned long size; - unsigned long BaseAddrLow; - unsigned long BaseAddrHigh; - unsigned long LengthLow; - unsigned long LengthHigh; - unsigned long Type; + { + unsigned long size; + unsigned long BaseAddrLow; + unsigned long BaseAddrHigh; + unsigned long LengthLow; + unsigned long LengthHigh; + unsigned long Type; - /* unspecified optional padding... */ -}; + /* unspecified optional padding... */ + }; /* usable memory "Type", all others are reserved. */ #define MB_ARD_MEMORY 1 @@ -66,49 +67,52 @@ struct AddrRangeDesc */ struct multiboot_info -{ - /* MultiBoot info version number */ - unsigned long flags; - - /* Available memory from BIOS */ - unsigned long mem_lower; - unsigned long mem_upper; - - /* "root" partition */ - unsigned long boot_device; - - /* Kernel command line */ - unsigned long cmdline; - - /* Boot-Module list */ - unsigned long mods_count; - unsigned long mods_addr; - - union { - struct - { - /* (a.out) Kernel symbol table info */ - unsigned long tabsize; - unsigned long strsize; - unsigned long addr; - unsigned long pad; - } a; + /* MultiBoot info version number */ + unsigned long flags; - struct - { - /* (ELF) Kernel section header table */ - unsigned long num; - unsigned long size; - unsigned long addr; - unsigned long shndx; - } e; - } syms; + /* Available memory from BIOS */ + unsigned long mem_lower; + unsigned long mem_upper; - /* Memory Mapping buffer */ - unsigned long mmap_length; - unsigned long mmap_addr; -}; + /* "root" partition */ + unsigned long boot_device; + + /* Kernel command line */ + unsigned long cmdline; + + /* Boot-Module list */ + unsigned long mods_count; + unsigned long mods_addr; + + union + { + struct + { + /* (a.out) Kernel symbol table info */ + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long pad; + } + a; + + struct + { + /* (ELF) Kernel section header table */ + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; + } + 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 - diff --git a/shared_src/pc_slice.h b/shared_src/pc_slice.h index a67337667..7e2fc8e2f 100644 --- a/shared_src/pc_slice.h +++ b/shared_src/pc_slice.h @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -170,33 +171,32 @@ /* possible values for the "DISKTYPE"... all essentially irrelevant except for DTYPE_SCSI */ -#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ -#define DTYPE_MSCP 2 /* MSCP */ -#define DTYPE_DEC 3 /* other DEC (rk, rl) */ -#define DTYPE_SCSI 4 /* SCSI */ -#define DTYPE_ESDI 5 /* ESDI interface */ -#define DTYPE_ST506 6 /* ST506 etc. */ -#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ -#define DTYPE_HPFL 8 /* HP Fiber-link */ -#define DTYPE_FLOPPY 10 /* floppy */ +#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define DTYPE_MSCP 2 /* MSCP */ +#define DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define DTYPE_SCSI 4 /* SCSI */ +#define DTYPE_ESDI 5 /* ESDI interface */ +#define DTYPE_ST506 6 /* ST506 etc. */ +#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define DTYPE_HPFL 8 /* HP Fiber-link */ +#define DTYPE_FLOPPY 10 /* floppy */ /* possible values for the *BSD-style partition type */ -#define FS_UNUSED 0 /* unused */ -#define FS_SWAP 1 /* swap */ -#define FS_V6 2 /* Sixth Edition */ -#define FS_V7 3 /* Seventh Edition */ -#define FS_SYSV 4 /* System V */ -#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ -#define FS_V8 6 /* Eighth Edition, 4K blocks */ -#define FS_BSDFFS 7 /* 4.2BSD fast file system */ -#define FS_MSDOS 8 /* MSDOS file system */ -#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ -#define FS_OTHER 10 /* in use, but unknown/unsupported */ -#define FS_HPFS 11 /* OS/2 high-performance file system */ -#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ -#define FS_BOOT 13 /* partition contains bootstrap */ +#define FS_UNUSED 0 /* unused */ +#define FS_SWAP 1 /* swap */ +#define FS_V6 2 /* Sixth Edition */ +#define FS_V7 3 /* Seventh Edition */ +#define FS_SYSV 4 /* System V */ +#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define FS_V8 6 /* Eighth Edition, 4K blocks */ +#define FS_BSDFFS 7 /* 4.2BSD fast file system */ +#define FS_MSDOS 8 /* MSDOS file system */ +#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ +#define FS_OTHER 10 /* in use, but unknown/unsupported */ +#define FS_HPFS 11 /* OS/2 high-performance file system */ +#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ +#define FS_BOOT 13 /* partition contains bootstrap */ -#endif /* _PC_SLICE_H */ - +#endif /* _PC_SLICE_H */ diff --git a/shared_src/shared.h b/shared_src/shared.h index 48b82ceae..187be48b7 100644 --- a/shared_src/shared.h +++ b/shared_src/shared.h @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -154,18 +155,18 @@ #define VARIABLE(x) ENTRY(x) -#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */ -#define K_STATUS 0x64 /* keyboard status */ -#define K_CMD 0x64 /* keybd ctlr command (write-only) */ +#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */ +#define K_STATUS 0x64 /* keyboard status */ +#define K_CMD 0x64 /* keybd ctlr command (write-only) */ -#define K_OBUF_FUL 0x01 /* output buffer full */ -#define K_IBUF_FUL 0x02 /* input buffer full */ +#define K_OBUF_FUL 0x01 /* output buffer full */ +#define K_IBUF_FUL 0x02 /* input buffer full */ -#define KC_CMD_WIN 0xd0 /* read output port */ -#define KC_CMD_WOUT 0xd1 /* write output port */ -#define KB_OUTPUT_MASK 0xdd /* enable output buffer full interrupt - enable data line - enable clock line */ +#define KC_CMD_WIN 0xd0 /* read output port */ +#define KC_CMD_WOUT 0xd1 /* write output port */ +#define KB_OUTPUT_MASK 0xdd /* enable output buffer full interrupt + enable data line + enable clock line */ #define KB_A20_ENABLE 0x02 @@ -178,18 +179,18 @@ static inline unsigned char -inb(unsigned short port) +inb (unsigned short port) { - unsigned char data; + unsigned char data; - __asm __volatile("inb %1,%0" : "=a" (data) : "d" (port)); - return data; + __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)); } @@ -198,10 +199,12 @@ outb(unsigned short port, unsigned char val) #include "mb_header.h" #include "mb_info.h" -extern char end[]; /* will be the end of the bss */ +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 sector, int nsec, int segment); -void stop_floppy(void); + int get_diskinfo (int drive); + int biosdisk (int subfunc, int drive, int geometry, + int sector, int nsec, int segment); + 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 */ +#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,44 +315,45 @@ int enter_cmdline(char *script, char *heap); #ifndef _CHAR_IO_C -int special_attribute; + int special_attribute; -#endif /* _CHAR_IO_C */ +#endif /* _CHAR_IO_C */ -enum grub_error_t { - ERR_NONE = 0, - ERR_BAD_FILENAME, - ERR_BAD_FILETYPE, - ERR_BAD_GZIP_DATA, - ERR_BAD_GZIP_HEADER, - ERR_BAD_PART_TABLE, - ERR_BAD_VERSION, - ERR_BELOW_1MB, - ERR_BOOT_COMMAND, - ERR_BOOT_FAILURE, - ERR_BOOT_FEATURES, - ERR_DEV_FORMAT, - ERR_DEV_VALUES, - ERR_EXEC_FORMAT, - ERR_FILELENGTH, - ERR_FILE_NOT_FOUND, - ERR_FSYS_CORRUPT, - ERR_FSYS_MOUNT, - ERR_GEOM, - ERR_NEED_LX_KERNEL, - ERR_NEED_MB_KERNEL, - ERR_NO_DISK, - ERR_NO_PART, - ERR_NUMBER_PARSING, - ERR_OUTSIDE_PART, - ERR_READ, - ERR_SYMLINK_LOOP, - ERR_UNRECOGNIZED, - ERR_WONT_FIT, - ERR_WRITE, + enum grub_error_t + { + ERR_NONE = 0, + ERR_BAD_FILENAME, + ERR_BAD_FILETYPE, + ERR_BAD_GZIP_DATA, + ERR_BAD_GZIP_HEADER, + ERR_BAD_PART_TABLE, + ERR_BAD_VERSION, + ERR_BELOW_1MB, + ERR_BOOT_COMMAND, + ERR_BOOT_FAILURE, + ERR_BOOT_FEATURES, + ERR_DEV_FORMAT, + ERR_DEV_VALUES, + ERR_EXEC_FORMAT, + ERR_FILELENGTH, + ERR_FILE_NOT_FOUND, + ERR_FSYS_CORRUPT, + ERR_FSYS_MOUNT, + ERR_GEOM, + ERR_NEED_LX_KERNEL, + ERR_NEED_MB_KERNEL, + ERR_NO_DISK, + ERR_NO_PART, + ERR_NUMBER_PARSING, + ERR_OUTSIDE_PART, + ERR_READ, + ERR_SYMLINK_LOOP, + ERR_UNRECOGNIZED, + ERR_WONT_FIT, + ERR_WRITE, - MAX_ERR_NUM -}; + 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 - disk buffer */ + 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 */ +#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,55 +411,55 @@ int gunzip_read(int addr, int len); #ifndef NO_FANCY_STUFF /* instrumentation variables */ -extern void (*debug_fs)(int); -extern void (*debug_fs_func)(int); -#endif /* NO_FANCY_STUFF */ + 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; -#endif /* NO_BLOCK_FILES */ + 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 */ +#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 - places it into the global parameters */ -int open_device(void); -int make_saved_active(void); /* sets the active partition to the that - represented by the "saved_" parameters */ + 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 + represented by the "saved_" parameters */ -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 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 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 - completions */ -void copy_current_part_entry(int addr); /* copies the current partition data - to the desired address */ + 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 + completions */ + 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 */ +#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 */ +#endif /* _COMMON_C */ -void init_bios_info(void) __attribute__ ((noreturn)); + void init_bios_info (void) __attribute__ ((noreturn)); #endif /* ASM_FILE */ diff --git a/shared_src/smp-imps.c b/shared_src/smp-imps.c index 86aeb8e6d..a6e4151bf 100644 --- a/shared_src/smp-imps.c +++ b/shared_src/smp-imps.c @@ -1,3 +1,4 @@ + /* * * @@ -66,36 +67,121 @@ #define DEF_ENTRIES 23 static int lapic_dummy = 0; -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} } +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 + } + } }; /* @@ -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; + unsigned sum = 0; - while (length-- > 0) { - sum += *((unsigned char *) (start++)); - } + while (length-- > 0) + { + sum += *((unsigned char *) (start++)); + } - return (sum&0xFF); + return (sum & 0xFF); } @@ -138,55 +225,56 @@ 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); + int apicid = proc->apic_id; + unsigned bootaddr, send_status, accept_status, cfg; + unsigned bios_reset_vector = PHYS_TO_VIRTUAL (BIOS_RESET_VECTOR); - /* %%%%% ESB */ - extern char patch_code[]; - bootaddr = 256*1024; - bcopy(patch_code, (char *)bootaddr, 32); + /* %%%%% ESB */ + extern char patch_code[]; + bootaddr = 256 * 1024; + bcopy (patch_code, (char *) bootaddr, 32); - /* - * Generic CPU startup sequence starts here. - */ + /* + * Generic CPU startup sequence starts here. + */ - /* set BIOS reset vector */ - CMOS_WRITE_BYTE(CMOS_RESET_CODE, CMOS_RESET_JUMP); - *((volatile unsigned *) bios_reset_vector) = bootaddr << 12; + /* set BIOS reset vector */ + 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); - } + /* clear the error register */ + 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 &= LAPIC_DEST_MASK; - IMPS_LAPIC_WRITE(LAPIC_ICR+1, cfg); - cfg = IMPS_LAPIC_READ(LAPIC_ACR); - cfg &= ; + /* assert INIT IPI */ + 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 &=; - /* %%%%% ESB finish adding startup sequence */ + /* %%%%% ESB finish adding startup sequence */ #endif - /* clean up BIOS reset vector */ - CMOS_WRITE_BYTE(CMOS_RESET_CODE, 0); - *((volatile unsigned *) bios_reset_vector) = 0; + /* clean up BIOS reset vector */ + CMOS_WRITE_BYTE (CMOS_RESET_CODE, 0); + *((volatile unsigned *) bios_reset_vector) = 0; - /* - * Generic CPU startup sequence ends here. - */ + /* + * Generic CPU startup sequence ends here. + */ - KERNEL_PRINT(("\n")); + KERNEL_PRINT (("\n")); - return 1; + return 1; - /* XXXXX add OS-specific initialization here! */ + /* XXXXX add OS-specific initialization here! */ } @@ -195,233 +283,267 @@ boot_cpu(imps_processor *proc) */ static void -add_processor(imps_processor *proc) +add_processor (imps_processor * proc) { - int apicid = proc->apic_id; + int apicid = proc->apic_id; - KERNEL_PRINT((" Processor [APIC id %d ver %d]: ", - apicid, proc->apic_ver)); - if (!(proc->flags & IMPS_FLAG_ENABLED)) { - KERNEL_PRINT(("DISABLED\n")); - return; - } - if (proc->apic_ver > 0xF) { - imps_any_new_apics = 1; - } - 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)) { + KERNEL_PRINT ((" Processor [APIC id %d ver %d]: ", + apicid, proc->apic_ver)); + if (!(proc->flags & IMPS_FLAG_ENABLED)) + { + KERNEL_PRINT (("DISABLED\n")); + return; + } + if (proc->apic_ver > 0xF) + { + imps_any_new_apics = 1; + } + 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)) + { - /* XXXXX add OS-specific setup for secondary CPUs here */ + /* XXXXX add OS-specific setup for secondary CPUs here */ - imps_num_cpus++; - } + imps_num_cpus++; + } } static void -add_bus(imps_bus *bus) +add_bus (imps_bus * bus) { - char str[8]; + char str[8]; - bcopy(bus->bus_type, str, 6); - str[6] = 0; - KERNEL_PRINT((" Bus id %d is %s\n", bus->id, str)); + bcopy (bus->bus_type, str, 6); + str[6] = 0; + KERNEL_PRINT ((" Bus id %d is %s\n", bus->id, str)); - /* XXXXX add OS-specific code here */ + /* 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 ", - ioapic->id, ioapic->ver, ioapic->addr)); - if (!(ioapic->flags & IMPS_FLAG_ENABLED)) { - KERNEL_PRINT(("DISABLED\n")); - return; - } - KERNEL_PRINT(("\n")); + 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")); + return; + } + KERNEL_PRINT (("\n")); - /* XXXXX add OS-specific code here */ + /* 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)) { - case IMPS_BCT_PROCESSOR: - add_processor((imps_processor *)start); - start += 12; /* 20 total */ - break; - case IMPS_BCT_BUS: - add_bus((imps_bus *)start); - break; - case IMPS_BCT_IOAPIC: - 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); - break; + while (count-- > 0) + { + switch (*((unsigned char *) start)) + { + case IMPS_BCT_PROCESSOR: + add_processor ((imps_processor *) start); + start += 12; /* 20 total */ + break; + case IMPS_BCT_BUS: + add_bus ((imps_bus *) start); + break; + case IMPS_BCT_IOAPIC: + 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); + break; #endif -#if 0 /* XXXXX uncomment this if "add_local_interrupt" is implemented */ - case IMPS_BCT_LOCAL_INTERRUPT: - add_local_interupt((imps_interrupt *)start); - break; +#if 0 /* XXXXX uncomment this if "add_local_interrupt" is implemented */ + case IMPS_BCT_LOCAL_INTERRUPT: + add_local_interupt ((imps_interrupt *) start); + break; #endif - default: - } - start += 8; + default: } + start += 8; + } } 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); + int sum; + imps_cth *local_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", - fps_ptr->feature_info[0])); - return 1; + 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, + 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)); + return 1; } - - 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)); - 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)); - return 1; - } - 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)); - return 1; - } - } - } else if (!fps_ptr->feature_info[0]) { - KERNEL_PRINT((" Missing configuration information\n")); - 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)); + return 1; } + 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)); + return 1; + } + } + } + else if (!fps_ptr->feature_info[0]) + { + KERNEL_PRINT ((" Missing configuration information\n")); + return 1; + } - return 0; + return 0; } 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); - char *str_ptr; + int apicid; + unsigned cth_start, cth_count; + imps_cth *local_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", - fps_ptr->spec_rev)); + KERNEL_PRINT (("Intel MultiProcessor Spec 1.%d BIOS support detected\n", + fps_ptr->spec_rev)); - /* - * Do all checking of errors which would definitely - * lead to failure of the SMP boot here. - */ + /* + * Do all checking of errors which would definitely + * lead to failure of the SMP boot here. + */ - if (imps_bad_bios(fps_ptr)) { - KERNEL_PRINT((" Disabling MPS support\n")); - return; + if (imps_bad_bios (fps_ptr)) + { + KERNEL_PRINT ((" Disabling MPS support\n")); + return; + } + + if (fps_ptr->feature_info[1] & IMPS_FPS_IMCRP_BIT) + { + str_ptr = "IMCR and PIC"; + } + else + { + str_ptr = "Virtual Wire"; + } + if (fps_ptr->cth_ptr) + { + imps_lapic_addr = local_cth_ptr->lapic_addr; + } + else + { + imps_lapic_addr = LAPIC_ADDR_DEFAULT; + } + 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); + + /* + * 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)); + imps_cpu_apic_map[0] = apicid; + imps_apic_cpu_map[apicid] = 0; + + if (fps_ptr->cth_ptr) + { + char str1[16], str2[16]; + bcopy (local_cth_ptr->oem_id, str1, 8); + str1[8] = 0; + 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); + cth_count = local_cth_ptr->entry_count; + } + else + { + *((volatile unsigned *) IOAPIC_ADDR_DEFAULT) = IOAPIC_ID; + defconfig.ioapic.id + = 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))); + defconfig.proc[apicid].flags + = 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); } - - if (fps_ptr->feature_info[1] & IMPS_FPS_IMCRP_BIT) { - str_ptr = "IMCR and PIC"; - } else { - str_ptr = "Virtual Wire"; + if (fps_ptr->feature_info[0] == 4 + || fps_ptr->feature_info[0] == 7) + { + bcopy ("MCA ", defconfig.bus[0].bus_type, 6); } - if (fps_ptr->cth_ptr) { - imps_lapic_addr = local_cth_ptr->lapic_addr; - } else { - imps_lapic_addr = LAPIC_ADDR_DEFAULT; + 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; } - 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); - - /* - * 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)); - imps_cpu_apic_map[0] = apicid; - imps_apic_cpu_map[apicid] = 0; - - if (fps_ptr->cth_ptr) { - char str1[16], str2[16]; - bcopy(local_cth_ptr->oem_id, str1, 8); - str1[8] = 0; - 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); - cth_count = local_cth_ptr->entry_count; - } else { - *((volatile unsigned *) IOAPIC_ADDR_DEFAULT) = IOAPIC_ID; - defconfig.ioapic.id - = 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))); - defconfig.proc[apicid].flags - = 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); - } - if (fps_ptr->feature_info[0] == 4 - || fps_ptr->feature_info[0] == 7) { - bcopy("MCA ", defconfig.bus[0].bus_type, 6); - } - 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) { - defconfig.intin[2].type = 255; - defconfig.intin[13].type = 255; - } - if (fps_ptr->feature_info[0] == 7) { - defconfig.intin[0].type = 255; - } - cth_start = (unsigned) &defconfig; - cth_count = DEF_ENTRIES; + if (fps_ptr->feature_info[0] == 2) + { + defconfig.intin[2].type = 255; + defconfig.intin[13].type = 255; } - imps_read_config_table(cth_start, cth_count); + 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); - /* %%%%% ESB read extended entries here */ + /* %%%%% ESB read extended entries here */ - imps_enabled = 1; + imps_enabled = 1; } @@ -441,28 +563,30 @@ 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", - start, length)); + 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); - return 1; - } - - length -= 16; - start += 16; + 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); + return 1; } - return 0; + length -= 16; + start += 16; + } + + return 0; } @@ -496,54 +620,56 @@ 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; + /* + * Determine possible address of the EBDA + */ + unsigned ebda_addr = *((unsigned short *) + PHYS_TO_VIRTUAL (EBDA_SEG_ADDR)) << 4; - /* - * Determine amount of installed lower memory (not *available* - * lower memory). - * - * NOTE: This should work reliably as long as we verify the - * 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; + /* + * Determine amount of installed lower memory (not *available* + * lower memory). + * + * NOTE: This should work reliably as long as we verify the + * 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; #ifdef IMPS_DEBUG - imps_enabled = 0; - imps_num_cpus = 1; + imps_enabled = 0; + imps_num_cpus = 1; #endif - /* - * 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) { - return 0; - } + /* + * 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) + { + return 0; + } - if (ebda_addr > mem_lower - 1024 - || ebda_addr + *((unsigned char *) PHYS_TO_VIRTUAL(ebda_addr)) - * 1024 > mem_lower) { - ebda_addr = 0; - } + if (ebda_addr > mem_lower - 1024 + || 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) { - return 1; - } + if (((ebda_addr && imps_scan (ebda_addr, 1024)) + || (!ebda_addr && imps_scan (mem_lower - 1024, 1024)) + || imps_scan (0xF0000, 0x10000)) && imps_enabled) + { + return 1; + } - /* - * If no BIOS info on MPS hardware is found, then return failure. - */ + /* + * If no BIOS info on MPS hardware is found, then return failure. + */ - return 0; + return 0; } - diff --git a/shared_src/smp-imps.h b/shared_src/smp-imps.h index ca7abfc31..dc239942e 100644 --- a/shared_src/smp-imps.h +++ b/shared_src/smp-imps.h @@ -18,7 +18,7 @@ /* make sure "apic.h" is included */ #ifndef _APIC_H #error Must include "apic.h" before "smp-imps.h" -#endif /* !_APIC_H */ +#endif /* !_APIC_H */ /* * Defines used. @@ -26,7 +26,7 @@ #ifdef IMPS_DEBUG #define IMPS_DEBUG_PRINT(x) KERNEL_PRINT(x) -#else /* !IMPS_DEBUG */ +#else /* !IMPS_DEBUG */ #define IMPS_DEBUG_PRINT(x) #endif /* !IMPS_DEBUG */ @@ -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]; -}; + { + 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,21 +117,21 @@ struct imps_fps * this structure. */ struct imps_cth -{ - unsigned sig; - unsigned short base_length; - unsigned char spec_rev; - unsigned char checksum; - char oem_id[8]; - char prod_id[12]; - unsigned oem_table_ptr; - unsigned short oem_table_size; - unsigned short entry_count; - unsigned lapic_addr; - unsigned short extended_length; - unsigned char extended_checksum; - char reserved[1]; -}; + { + unsigned sig; + unsigned short base_length; + unsigned char spec_rev; + unsigned char checksum; + char oem_id[8]; + char prod_id[12]; + unsigned oem_table_ptr; + unsigned short oem_table_size; + unsigned short entry_count; + unsigned lapic_addr; + unsigned short extended_length; + unsigned char extended_checksum; + char reserved[1]; + }; /* * Base MP Configuration Table Types. They are sorted according to @@ -140,42 +140,42 @@ struct imps_cth */ struct imps_processor -{ - unsigned char type; /* must be 0 */ - unsigned char apic_id; - unsigned char apic_ver; - unsigned char flags; - unsigned signature; - unsigned features; - char reserved[8]; -}; + { + unsigned char type; /* must be 0 */ + unsigned char apic_id; + unsigned char apic_ver; + unsigned char flags; + unsigned signature; + unsigned features; + char reserved[8]; + }; struct imps_bus -{ - unsigned char type; /* must be 1 */ - unsigned char id; - char bus_type[6]; -}; + { + 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; -}; + { + 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; - unsigned char source_bus_id; - unsigned char source_bus_irq; - unsigned char dest_apic_id; - unsigned char dest_apic_intin; -}; + { + unsigned char type; /* must be 3 or 4 */ + unsigned char int_type; + unsigned short flags; + unsigned char source_bus_id; + 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); /* @@ -235,5 +235,4 @@ int imps_probe(void); #define IMPS_LAPIC_WRITE(x, y) \ (*((volatile unsigned *) (imps_lapic_addr+(x))) = (y)) -#endif /* !_SMP_IMPS_H */ - +#endif /* !_SMP_IMPS_H */ diff --git a/shared_src/stage1_5.c b/shared_src/stage1_5.c index de15dfbdb..8f9aaf7c9 100644 --- a/shared_src/stage1_5.c +++ b/shared_src/stage1_5.c @@ -1,3 +1,4 @@ + /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1996 Erich Boleyn @@ -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 (); } - diff --git a/stage1/stage1.S b/stage1/stage1.S index 35404cd38..6d525f58c 100644 --- a/stage1/stage1.S +++ b/stage1/stage1.S @@ -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 */