From nobody@FreeBSD.org  Mon Sep 30 15:21:24 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1041237B401
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 30 Sep 2002 15:21:24 -0700 (PDT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B503E43E65
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 30 Sep 2002 15:21:23 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g8UMLN7R088707
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 30 Sep 2002 15:21:23 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.6/8.12.6/Submit) id g8UMLNio088706;
	Mon, 30 Sep 2002 15:21:23 -0700 (PDT)
Message-Id: <200209302221.g8UMLNio088706@www.freebsd.org>
Date: Mon, 30 Sep 2002 15:21:23 -0700 (PDT)
From: Tim Kientzle <kientzle@acm.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: cdboot does not handle 'relaxed' ISO9660 discs
X-Send-Pr-Version: www-1.0

>Number:         43543
>Category:       misc
>Synopsis:       cdboot does not handle 'relaxed' ISO9660 discs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 30 15:30:01 PDT 2002
>Closed-Date:    Thu Dec 18 09:11:45 PST 2003
>Last-Modified:  Thu Dec 18 09:11:45 PST 2003
>Originator:     Tim Kientzle
>Release:        FreeBSD 4.6 (same problem found in 5.0-current)
>Organization:
>Environment:
N/A
>Description:
The 'cdboot' program, which supports non-emulation
booting of CD-ROM media, loads the /boot/loader
program from the CD-ROM.  It looks for the
file as /BOOT/LOADER, since 'normal' Rockridge
discs have all filenames forced to uppercase
in the catalog file.  mkisofs now supports
'relaxed' ISO filenaming, which allows the
catalog to contain mixed-case filenames.
Since cdboot does _not_ look for '/boot/loader',
it does not work on such discs.
>How-To-Repeat:
Create a directory 'image' with the following files:

image/boot/cdboot
image/boot/loader

use the following command to build an ISO9660 image:

mkisofs -U -R -b boot/cdboot -no-emul-boot -c boot.catalog -o image.iso image

Try to boot the resulting CD.  Note that
it fails because 'cdboot' tries to load
/BOOT/LOADER and does not try /boot/loader.

>Fix:
Alter 'cdboot' to try both filenames.
The following patch accomplishes this.
It alters the 'lookup' subroutine to
return an error code (rather than
abort immediately) if the file is not
found.  The top-level code is altered
to invoke the subroutine twice, once
with '/BOOT/LOADER' and once with
'/boot/loader'.  The patch also
adds a final 'boot failed' message
if the boot is unsuccessful.


ugly# diff -c cdboot.s-original cdboot.s
*** cdboot.s-original   Tue Nov  6 17:20:33 2001
--- cdboot.s    Fri Sep 27 11:39:54 2002
***************
*** 143,148 ****
--- 143,158 ----
  #
                mov $loader_path,%si            # File to lookup
                call lookup                     # Try to find it
+               cmp  $0,%bx
+               jne  lookup_found               # Found it, continue
+               mov $loader_alt,%si             # No, try another name
+               call lookup
+               cmp $0,%bx
+               jne  lookup_found               # Found it, continue
+               mov $msg_failed,%si
+               jmp  error                      # Nothing worked; halt.
+ lookup_found:
+
  #
  # Load the binary into the buffer.  Due to real mode addressing limitations
  # we have to read it in in 64k chunks.
***************
*** 266,272 ****
  # Lookup the file in the path at [SI] from the root directory.
  #
  # Trashes: All but BX
! # Returns: BX = pointer to record
  #
  lookup:               mov $VD_ROOTDIR+MEM_VOLDESC,%bx # Root directory record
                push %si
--- 276,282 ----
  # Lookup the file in the path at [SI] from the root directory.
  #
  # Trashes: All but BX
! # Returns: BX = pointer to record, or 0 if not found
  #
  lookup:               mov $VD_ROOTDIR+MEM_VOLDESC,%bx # Root directory record
                push %si
***************
*** 287,293 ****
                call find_file                  # Lookup first path item
                jnc lookup_dir                  # Try next component
                mov $msg_lookupfail,%si         # Not found.
!               jmp error
  lookup_done:  mov $msg_lookupok,%si           # Success message
                call putstr
                ret
--- 297,305 ----
                call find_file                  # Lookup first path item
                jnc lookup_dir                  # Try next component
                mov $msg_lookupfail,%si         # Not found.
!               call putstr
!               mov $0,%bx                      # Not found.
!               ret
  lookup_done:  mov $msg_lookupok,%si           # Success message
                call putstr
                ret
***************
*** 548,553 ****
--- 560,567 ----
  msg_lookupok: .asciz  "Found\r\n"
  msg_lookupfail:       .asciz  "File not found\r\n"
  msg_load2big: .asciz  "File too big\r\n"
+ msg_failed:   .asciz  "Boot failed\r\n"
  loader_path:  .asciz  "/BOOT/LOADER"
+ loader_alt:   .asciz  "/boot/loader"
  twiddle_chars:        .ascii  "|/-\\" 
>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@FreeBSD.org>
To: Tim Kientzle <kientzle@acm.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/43543: cdboot does not handle 'relaxed' ISO9660 discs
Date: Tue, 1 Oct 2002 04:26:58 +0300

 On 2002-09-30 15:21, Tim Kientzle <kientzle@acm.org> wrote:
 > Alter 'cdboot' to try both filenames.
 > The following patch accomplishes this.
 
 Nice idea.  But will this work for "/Boot/Loader" too?
 Is it possible to look for the name in any capitalisation?
 
 Perhaps by changing the bit in find_file that compares the filenames
 to ignore differences in lowercase and uppercase letters?  I haven't
 looked in x86 asm for a while, but how about something like this?
 
 * Note: This grows the size of the code a lot, and I haven't checked
 to see if it actually works, as I am in the middle of a long running
 buildworld.  It's just an idea.
 
 %%%
 Index: cdboot.s
 ===================================================================
 RCS file: /home/ncvs/src/sys/boot/i386/cdboot/cdboot.s,v
 retrieving revision 1.9
 diff -u -r1.9 cdboot.s
 --- cdboot.s	7 Nov 2001 01:20:33 -0000	1.9
 +++ cdboot.s	1 Oct 2002 01:25:09 -0000
 @@ -365,9 +365,22 @@
  		ret				# End of file, so not found
  ff.checkname:	lea DIR_NAME(%bx),%di		# Address name in record
  		push %si			# Save
 -		repe cmpsb			# Compare name
 +ff.cmpname:	push %ax
 +		lodsb				# fetch name char
 +		dec %di
 +		cmp $65,%al			# less than 'A' ?
 +		jb ff.lcase
 +		cmp $90,%al			# above 'Z' ?
 +		ja ff.lcase
 +		add $32,%al			# convert to lowercase
 +		stosb				# store back in name
 +		dec %di
 +ff.lcase:	pop %ax
 +		cmpsb				# Compare lowercase char.
 +		jnz ff.out			# Not a match.
 +		loop ff.cmpname			# Keep looking in name.
  		jcxz ff.match			# We have a winner!
 -		pop %si				# Restore
 +ff.out:		pop %si				# Restore
  		jmp ff.nextrec			# Keep looking.
  ff.match:	add $2,%sp			# Discard saved %si
  		clc				# Clear carry
 %%%

From: Tim Kientzle <kientzle@acm.org>
To: Giorgos Keramidas <keramida@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: misc/43543: cdboot does not handle 'relaxed' ISO9660 discs
Date: Mon, 30 Sep 2002 20:43:56 -0700

 I don't see the point of this.  FreeBSD/UFS
 is case sensitive, and the boot loader should
 always be called '/boot/loader'.  (I doubt
 the hard-disk boot blocks look for anything
 other than the all-lowercase version.)
 
 Supporting the all-uppercase '/BOOT/LOADER' is
 a concession to ISO9660, which encourages the
 use of all-uppercase names for compatibility
 (i.e., MSDOS).  Note that the uppercase version
 appears only in the internal disc catalog; the
 running system will see the lowercase RockRidge
 names, which are stored separately.  (With the
 -U option, mkisofs will put lowercase chars
 into the catalog.  People are starting to recommend
 that option for bootable discs of this sort,
 hence the need for my patch.)  The "/boot/loader"
 name should never appear in mixed case.
 
 In fact, case-insensitive comparisons are arguably
 wrong.  If someone has both "/boot/loader" and
 "/BoOt/LoAdEr" on the same disk, you want to
 always grab "/boot/loader".  With your change,
 you'd get whichever one appeared first in
 the catalog.  (In fact, my original patch should
 probably be modified to try the lower-case version
 first, then the uppercase.)
 
 Code size is not an issue.  CD sector sizes
 are 2048, the current code is under 1200 bytes.
 You'd have to add a lot to change the disc usage
 at all.  Beyond that, 'no emulation' booting is
 supposed to allow arbitrarily large boot files,
 so there should be no practical limitation.
 
 Tim Kientzle
 
 Giorgos Keramidas wrote:
 
 > On 2002-09-30 15:21, Tim Kientzle <kientzle@acm.org> wrote:
 > 
 >>Alter 'cdboot' to try both filenames.
 >>The following patch accomplishes this.
 >>
 > 
 > Nice idea.  But will this work for "/Boot/Loader" too?
 > Is it possible to look for the name in any capitalisation?
 > 
 > Perhaps by changing the bit in find_file that compares the filenames
 > to ignore differences in lowercase and uppercase letters?  I haven't
 > looked in x86 asm for a while, but how about something like this?
 > 
 > * Note: This grows the size of the code a lot, and I haven't checked
 > to see if it actually works, as I am in the middle of a long running
 > buildworld.  It's just an idea.
 > 
 > %%%
 > Index: cdboot.s
 > ===================================================================
 > RCS file: /home/ncvs/src/sys/boot/i386/cdboot/cdboot.s,v
 > retrieving revision 1.9
 > diff -u -r1.9 cdboot.s
 > --- cdboot.s	7 Nov 2001 01:20:33 -0000	1.9
 > +++ cdboot.s	1 Oct 2002 01:25:09 -0000
 > @@ -365,9 +365,22 @@
 >  		ret				# End of file, so not found
 >  ff.checkname:	lea DIR_NAME(%bx),%di		# Address name in record
 >  		push %si			# Save
 > -		repe cmpsb			# Compare name
 > +ff.cmpname:	push %ax
 > +		lodsb				# fetch name char
 > +		dec %di
 > +		cmp $65,%al			# less than 'A' ?
 > +		jb ff.lcase
 > +		cmp $90,%al			# above 'Z' ?
 > +		ja ff.lcase
 > +		add $32,%al			# convert to lowercase
 > +		stosb				# store back in name
 > +		dec %di
 > +ff.lcase:	pop %ax
 > +		cmpsb				# Compare lowercase char.
 > +		jnz ff.out			# Not a match.
 > +		loop ff.cmpname			# Keep looking in name.
 >  		jcxz ff.match			# We have a winner!
 > -		pop %si				# Restore
 > +ff.out:		pop %si				# Restore
 >  		jmp ff.nextrec			# Keep looking.
 >  ff.match:	add $2,%sp			# Discard saved %si
 >  		clc				# Clear carry
 > %%%
 > 
 > 
 > 
 
 
 
Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: kris 
Responsible-Changed-When: Fri Jul 18 15:04:14 PDT 2003 
Responsible-Changed-Why:  
Assign to cdboot maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43543 
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Thu Dec 11 14:42:55 PST 2003 
State-Changed-Why:  
Alternative fix commited to current and will be MFC'd in a week or so. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43543 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Thu Dec 18 09:11:27 PST 2003 
State-Changed-Why:  
Fix was MFC'd. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43543 
>Unformatted:
