From 3bb99eb225a264262bd480d725c336f4e0a14042 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Thu, 4 Dec 1997 21:52:47 +0000 Subject: [PATCH] Finally, implement a mini-parser for RockRidge alternative filenames, so the filenames can be displayed and selected in full beauty. If RR is present, the match is now case-sensitive, if RR is missing, the match is case-insensitive (as it used to be before). --- sys/i386/boot/biosboot/boot.h | 8 ++-- sys/i386/boot/biosboot/io.c | 14 ++----- sys/i386/boot/cdboot/boot.h | 5 ++- sys/i386/boot/cdboot/cdrom.c | 70 ++++++++++++++++++++++++++--------- 4 files changed, 63 insertions(+), 34 deletions(-) diff --git a/sys/i386/boot/biosboot/boot.h b/sys/i386/boot/biosboot/boot.h index e0907c2485c3..366dbfc3ce72 100644 --- a/sys/i386/boot/biosboot/boot.h +++ b/sys/i386/boot/biosboot/boot.h @@ -24,11 +24,10 @@ * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:35:03 rpd - * $Id: boot.h,v 1.21 1997/08/31 06:11:26 phk Exp $ + * $Id: boot.h,v 1.22 1997/09/24 07:44:34 phk Exp $ */ #include -#include #include #include @@ -81,10 +80,9 @@ void printf(const char *format, ...); void putchar(int c); void delay1ms(void); int gets(char *buf); -#ifndef CDBOOT int strcmp(const char *s1, const char *s2); -#else /* CDBOOT */ -int strncasecmp(const char *s1, const char *s2, size_t s); +#ifdef CDBOOT +int strcasecmp(const char *s1, const char *s2); #endif /* !CDBOOT */ void bcopy(const void *from, void *to, size_t len); void twiddle(void); diff --git a/sys/i386/boot/biosboot/io.c b/sys/i386/boot/biosboot/io.c index 1e0527c4279a..b9c40588c46b 100644 --- a/sys/i386/boot/biosboot/io.c +++ b/sys/i386/boot/biosboot/io.c @@ -24,7 +24,7 @@ * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:35:57 rpd - * $Id: io.c,v 1.23 1997/06/09 05:10:55 bde Exp $ + * $Id: io.c,v 1.24 1997/07/12 10:23:19 joerg Exp $ */ #include "boot.h" @@ -258,8 +258,6 @@ gets(char *buf) return 0; } -#ifndef CDBOOT - int strcmp(const char *s1, const char *s2) { @@ -271,26 +269,22 @@ strcmp(const char *s1, const char *s2) return 1; } -#else /* CDBOOT */ - +#ifdef CDBOOT int -strncasecmp(const char *s1, const char *s2, size_t s) +strcasecmp(const char *s1, const char *s2) { /* * We only consider ASCII chars and don't anticipate * control characters (they are invalid in filenames * anyway). */ - while (s > 0 && (*s1 & 0x5f) == (*s2 & 0x5f)) { + while ((*s1 & 0x5f) == (*s2 & 0x5f)) { if (!*s1++) return 0; s2++; } - if (s == 0) - return 0; return 1; } - #endif /* !CDBOOT */ void diff --git a/sys/i386/boot/cdboot/boot.h b/sys/i386/boot/cdboot/boot.h index b71f457072fb..4604c0877937 100644 --- a/sys/i386/boot/cdboot/boot.h +++ b/sys/i386/boot/cdboot/boot.h @@ -24,7 +24,7 @@ * the rights to redistribute these changes. * * from: Mach, Revision 2.2 92/04/04 11:35:03 rpd - * $Id$ + * $Id: boot.h,v 1.1 1997/07/11 05:52:38 joerg Exp $ */ /* * Extensions for El Torito CD-ROM booting: @@ -155,7 +155,8 @@ void printf(const char *format, ...); void putchar(int c); void delay1ms(void); int gets(char *buf); -int strncasecmp(const char *s1, const char *s2, size_t s); +int strcasecmp(const char *s1, const char *s2); +int strcmp(const char *s1, const char *s2); void bcopy(const void *from, void *to, size_t len); void twiddle(void); diff --git a/sys/i386/boot/cdboot/cdrom.c b/sys/i386/boot/cdboot/cdrom.c index 23d51b74ed12..d9555852e7fc 100644 --- a/sys/i386/boot/cdboot/cdrom.c +++ b/sys/i386/boot/cdboot/cdrom.c @@ -27,7 +27,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: cdrom.c,v 1.1 1997/07/11 05:52:39 joerg Exp $ + * $Id: cdrom.c,v 1.2 1997/12/02 21:13:59 joerg Exp $ */ @@ -52,6 +52,7 @@ static u_int32_t curblk, startblk, filesize, offset; static int bread(u_int32_t rba, size_t nblks, void *buf); static void badread(const char *msg, u_int32_t blkno); static struct iso_directory_record *find(const char *path, int list_only); +static char *get_rr_name(struct iso_directory_record *dirp, size_t *len_ret); static int iread(u_char *buf, size_t len, void (*copyfun)(const void *src, void *dst, size_t size)); @@ -207,18 +208,56 @@ xread(u_char *buf, size_t len) return iread(buf, len, pcpy); } -/* - * XXX Todo: - * Use RR attributes if present - */ +static char * +get_rr_name(struct iso_directory_record *dirp, size_t *len_ret) +{ + struct rr_header { + char type[2]; + u_char len; + u_char version; + } *rrp; + struct rr_nm_header { + struct rr_header rrh; + u_char flags; + char name[0]; /* XXX -- using gcc extension */ + } *rrnmp; + char *cp; + + cp = dirp->name + (u_char)dirp->name_len[0]; + /* round up to 16-bit boundary; ugly */ + cp = (char *)(((int)cp + 1) & ~1); + rrp = (struct rr_header *)cp; + + if (rrp->type[0] != 'R' || rrp->type[1] != 'R') { + DPRINTF(("no RR, ")); + return 0; + } + + DPRINTF(("RR attribs: ")); + cp += rrp->len; + while (cp - (char *)dirp <= (u_char)dirp->length[0]) { + rrp = (struct rr_header *)cp; + DPRINTF(("%c%c ", rrp->type[0], rrp->type[1])); + if (rrp->type[0] == 'N' && rrp->type[1] == 'M') { + rrnmp = (struct rr_nm_header *)rrp; + *len_ret = rrp->len - sizeof(struct rr_nm_header); + return rrnmp->name; + } + cp += rrp->len; + } + + return 0; +} + static struct iso_directory_record * find(const char *path, int list_only) { struct iso_directory_record *dirp; - char *ptr; + char *ptr, *rrname; size_t len, entrylen; char namebuf[256]; int i; + int (*comp)(const char *, const char *); while (*path && *path == '/') path++; @@ -261,21 +300,18 @@ find(const char *path, int list_only) DPRINTF(("directory\n")); continue; } + rrname = get_rr_name(dirp, &len); + comp = rrname? strcmp: strcasecmp; -#ifdef DEBUG - bcopy(dirp->name, namebuf, len); + bcopy(rrname? rrname: dirp->name, namebuf, len); namebuf[len] = 0; DPRINTF(("name `%s'\n", namebuf)); -#else /* !DEBUG */ - if (list_only) { - bcopy(dirp->name, namebuf, len); - namebuf[len] = 0; - printf("%s ", namebuf); - } -#endif /* DEBUG */ - if (!list_only && - strncasecmp(path, dirp->name, len) == 0) + if (list_only) { +#ifndef DEBUG + printf("%s ", namebuf); +#endif + } else if (comp(path, namebuf) == 0) return dirp; } #ifndef DEBUG