From bd8a47b12aa5d10d99147b75f1bb80d6bf07d48e Mon Sep 17 00:00:00 2001 From: Liu Aleaxander Date: Sun, 7 Jun 2009 06:44:06 +0800 Subject: [PATCH] Core:EXTLINUX: convert mangle name to C --- core/comboot.inc | 6 +++--- core/conio.inc | 2 +- core/ext2.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ core/extern.inc | 2 +- core/extlinux.asm | 49 ------------------------------------------------- core/parseconfig.inc | 10 +++++----- core/runkernel.inc | 2 +- core/ui.inc | 2 +- 8 files changed, 56 insertions(+), 61 deletions(-) diff --git a/core/comboot.inc b/core/comboot.inc index dee8405..8a7d95c 100644 --- a/core/comboot.inc +++ b/core/comboot.inc @@ -517,7 +517,7 @@ comapi_open: mov ds,P_ES mov si,P_SI mov di,InitRD - call mangle_name + pm_call mangle_name pop ds pm_call searchdir jz comapi_err @@ -748,7 +748,7 @@ comapi_runkernel: mov ds,P_DS mov si,P_SI mov di,KernelName - call mangle_name + pm_call mangle_name pop ds pm_call searchdir jz comapi_err @@ -904,7 +904,7 @@ comapi_opendir: mov ds,P_ES mov si,P_SI mov di,InitRD - call mangle_name + pm_call mangle_name pop ds pm_call searchdir jnz comapi_err ; Didn't find a directory diff --git a/core/conio.inc b/core/conio.inc index 72443e2..835359f 100644 --- a/core/conio.inc +++ b/core/conio.inc @@ -207,7 +207,7 @@ msg_viewimage: mov byte [si],0 ; Zero-terminate filename mov si,VGAFileBuf mov di,VGAFileMBuf - call mangle_name + pm_call mangle_name call core_open jz msg_putcharnext ; Not there call vgadisplayfile diff --git a/core/ext2.c b/core/ext2.c index 709c1f4..835b3ff 100644 --- a/core/ext2.c +++ b/core/ext2.c @@ -5,6 +5,8 @@ #include "disk.h" #include "ext2_fs.h" +#define FILENAME_MAX_LG2 8 +#define FILENAME_MAX (1 << FILENAME_MAX_LG2) #define MAX_OPEN_LG2 6 #define MAX_OPEN (1 << MAX_OPEN_LG2) #define MAX_SYMLINKS 64 @@ -97,6 +99,48 @@ void close_file(struct open_file_t *file) /** + * mangle_name: + * + * Mangle a filename pointed to by DS:SI(of regs) into a + * buffer pointed to by ES:DI(of regs); ends on encountering + * any whitespace. + * + */ +void mangle_name(com32sys_t *regs) +{ + char *src = (char *)MK_PTR(regs->ds, regs->esi.w[0]); + char *dst = (char *)MK_PTR(regs->es, regs->edi.w[0]); + char *p = dst; + int i = FILENAME_MAX -1; + + while(*src > ' ') { + if ( *src == '/' ) { + if ( *(src+1) == '/' ) { + src ++; + i --; + continue; + } + } + i --; + *dst++ = *src++; + } + + while ( 1 ) { + if ( dst >= p ) + break; + if ( *(dst-1) != '/' ) + break; + + dst --; + i ++; + } + + i ++; + for (; i > 0; i -- ) + *dst++ = '\0'; +} + +/** * get_group_desc: * * get the group's descriptor of group_num diff --git a/core/extern.inc b/core/extern.inc index 255a91f..086f1dd 100644 --- a/core/extern.inc +++ b/core/extern.inc @@ -19,6 +19,6 @@ extern load_config ; ext2.c - extern init_fs, searchdir, getfssec + extern init_fs, searchdir, getfssec, mangle_name %endif ; EXTERN_INC diff --git a/core/extlinux.asm b/core/extlinux.asm index 55ae363..741566c 100644 --- a/core/extlinux.asm +++ b/core/extlinux.asm @@ -183,55 +183,6 @@ ThisDir resd 1 section .text16 ; -; mangle_name: Mangle a filename pointed to by DS:SI into a buffer pointed -; to by ES:DI; ends on encountering any whitespace. -; DI is preserved. -; -; This verifies that a filename is < FILENAME_MAX characters, -; doesn't contain whitespace, zero-pads the output buffer, -; and removes redundant slashes, -; so "repe cmpsb" can do a compare, and the -; path-searching routine gets a bit of an easier job. -; -; FIX: we may want to support \-escapes here (and this would -; be the place.) -; -mangle_name: - push di - push bx - xor ax,ax - mov cx,FILENAME_MAX-1 - mov bx,di - -.mn_loop: - lodsb - cmp al,' ' ; If control or space, end - jna .mn_end - cmp al,ah ; Repeated slash? - je .mn_skip - xor ah,ah - cmp al,'/' - jne .mn_ok - mov ah,al -.mn_ok stosb -.mn_skip: loop .mn_loop -.mn_end: - cmp bx,di ; At the beginning of the buffer? - jbe .mn_zero - cmp byte [di-1],'/' ; Terminal slash? - jne .mn_zero -.mn_kill: dec di ; If so, remove it - inc cx - jmp short .mn_end -.mn_zero: - inc cx ; At least one null byte - xor ax,ax ; Zero-fill name - rep stosb - pop bx - pop di - ret ; Done - -; ; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled ; filename to the conventional representation. This is needed ; for the BOOT_IMAGE= parameter for the kernel. diff --git a/core/parseconfig.inc b/core/parseconfig.inc index f8cead0..37091c9 100644 --- a/core/parseconfig.inc +++ b/core/parseconfig.inc @@ -104,7 +104,7 @@ pc_kernel: cmp byte [VKernel],0 mov [VKernelBuf+vk_type],al call pc_getline mov di,VKernelBuf+vk_rname - call mangle_name + pm_call mangle_name .err: ret ; @@ -147,7 +147,7 @@ pc_setint16: pc_filecmd: push ax ; Function to tailcall call pc_getline mov di,MNameBuf - call mangle_name + pm_call mangle_name pm_call searchdir jnz .ok pop ax ; Drop the successor function @@ -160,7 +160,7 @@ pc_filecmd: push ax ; Function to tailcall pc_opencmd: push ax ; Function to tailcall call pc_getline mov di,MNameBuf - call mangle_name + pm_call mangle_name call core_open jnz .ok pop ax ; Drop the successor function @@ -289,7 +289,7 @@ pc_serial: call getint pc_filename: push ax call pc_getline pop di - call mangle_name ; Mangle file name + pm_call mangle_name ; Mangle file name ret ; @@ -314,7 +314,7 @@ pc_label: call commit_vk ; Commit any current vkernel mov byte [VKernel],1 ; We've seen a "label" statement mov si,VKernelBuf+vk_vname ; By default, rname == mangled vname mov di,VKernelBuf+vk_rname - call mangle_name + pm_call mangle_name mov si,AppendBuf ; Default append==global append mov di,VKernelBuf+vk_append mov cx,[AppendLen] diff --git a/core/runkernel.inc b/core/runkernel.inc index 65c1993..f44e8b3 100644 --- a/core/runkernel.inc +++ b/core/runkernel.inc @@ -538,7 +538,7 @@ parse_load_initrd: push di mov di,InitRD ; Target buffer for mangled name - call mangle_name + pm_call mangle_name pop di call loadinitrd diff --git a/core/ui.inc b/core/ui.inc index 15ae449..508a6f2 100644 --- a/core/ui.inc +++ b/core/ui.inc @@ -318,7 +318,7 @@ load_kernel: ; Load the kernel now mov si,command_line mov di,KernelName push si - call mangle_name + pm_call mangle_name pop si ; ; Fast-forward to first option (we start over from the beginning, since -- 2.7.4