config: allow a chdir at the time a new configuration file is loaded
authorH. Peter Anvin <hpa@zytor.com>
Sun, 14 Feb 2010 21:40:04 +0000 (13:40 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Sun, 14 Feb 2010 21:40:04 +0000 (13:40 -0800)
If a directory name/path prefix is appended to a loaded configuration
file, do a chdir at that point.  We finally have all the mechanism to
do this right.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
13 files changed:
core/cmdline.inc
core/comboot.inc
core/conio.inc
core/extern.inc
core/fs.c
core/include/core.h
core/include/fs.h
core/kernel.inc
core/newconfig.c [new file with mode: 0644]
core/parsecmd.inc
core/parseconfig.inc
core/runkernel.inc
core/ui.inc

index 8b84f48..d860ac7 100644 (file)
@@ -37,6 +37,7 @@ make_plain_cmdline:
 
                dec di
                mov [CmdLinePtr],di
+               mov byte [es:di],0              ; Null-terminate
 
                pop es
                ret
index e271b9e..25c4e18 100644 (file)
@@ -517,7 +517,7 @@ comapi_open:
                mov ds,P_ES
                mov si,P_SI
                mov di,InitRD
-               pm_call mangle_name
+               pm_call pm_mangle_name
                pop ds
                pm_call pm_searchdir
                jz comapi_err
@@ -749,7 +749,7 @@ comapi_runkernel:
                mov ds,P_DS
                mov si,P_SI
                mov di,KernelName
-               pm_call mangle_name
+               pm_call pm_mangle_name
                pop ds
                pm_call pm_searchdir
                jz comapi_err
index 835359f..60d1fcb 100644 (file)
@@ -207,7 +207,7 @@ msg_viewimage:
                mov byte [si],0                 ; Zero-terminate filename
                mov si,VGAFileBuf
                mov di,VGAFileMBuf
-               pm_call mangle_name
+               pm_call pm_mangle_name
                call core_open
                jz msg_putcharnext              ; Not there
                call vgadisplayfile
index da6c675..3e25226 100644 (file)
        extern hello
 
        ; fs.c
-       extern fs_init, pm_searchdir, getfssec, mangle_name, load_config
-        extern unmangle_name, close_file
+       extern fs_init, pm_searchdir, getfssec, pm_mangle_name, load_config
+        extern pm_unmangle_name, close_file
 
        ; chdir.c
        extern pm_realpath
 
         ; readdir.c
         extern opendir, readdir, closedir
+
+       ; newconfig.c
+       extern pm_is_config_file
+
 %if IS_PXELINUX
        ; pxe.c
        extern unload_pxe, reset_pxe
index 6acfd3b..c53636f 100644 (file)
--- a/core/fs.c
+++ b/core/fs.c
@@ -70,26 +70,39 @@ void load_config(void)
        printf("ERROR: No configuration file found\n");
 }
 
-void mangle_name(com32sys_t *regs)
+void pm_mangle_name(com32sys_t *regs)
 {
     const char *src = MK_PTR(regs->ds, regs->esi.w[0]);
     char       *dst = MK_PTR(regs->es, regs->edi.w[0]);
-    
-    this_fs->fs_ops->mangle_name(dst, src);
+
+    mangle_name(dst, src);
 }
 
+void mangle_name(char *dst, const char *src)
+{
+    this_fs->fs_ops->mangle_name(dst, src);
+}
 
-void unmangle_name(com32sys_t *regs)
+/*
+ * XXX: current unmangle_name() is stpcpy() on all filesystems; consider
+ * eliminating it as a method.
+ */
+void pm_unmangle_name(com32sys_t *regs)
 {
     const char *src = MK_PTR(regs->ds, regs->esi.w[0]);
     char       *dst = MK_PTR(regs->es, regs->edi.w[0]);
     
-    dst = this_fs->fs_ops->unmangle_name(dst, src);
+    dst = unmangle_name(dst, src);
 
     /* Update the di register to point to the last null char */
     regs->edi.w[0] = OFFS_WRT(dst, regs->es);
 }
 
+char *unmangle_name(char *dst, const char *src)
+{
+    return this_fs->fs_ops->unmangle_name(dst, src);
+}
+
 void getfssec(com32sys_t *regs)
 {
     int sectors;
index 88ced70..c955e73 100644 (file)
@@ -11,6 +11,9 @@ extern char CurrentDirName[];
 extern char SubvolName[];
 extern char ConfigName[];
 extern char KernelName[];
+extern char cmd_line[];
+extern char ConfigFile[];
+extern char KernelCName[];
 
 /* diskstart.inc isolinux.asm*/
 extern void getlinsec(void);
index 124a816..4902614 100644 (file)
@@ -166,8 +166,11 @@ static inline struct file *handle_to_file(uint16_t handle)
 }
 
 /* fs.c */
-void mangle_name(com32sys_t *);
+void pm_mangle_name(com32sys_t *);
+void pm_unmangle_name(com32sys_t *);
 void pm_searchdir(com32sys_t *);
+void mangle_name(char *, const char *);
+char *unmangle_name(char *, const char *);
 int searchdir(const char *name);
 void _close_file(struct file *);
 
index 5e1c7a3..3ac5af1 100644 (file)
@@ -62,6 +62,9 @@ linux_fdctab  resb 12
 cmd_line_here  equ $                   ; F800 Should be out of the way
                endstruc
 
+               global cmd_line
+cmd_line       equ (real_mode_seg << 4) + cmd_line_here
+
 ;
 ; Old kernel command line signature
 ;
diff --git a/core/newconfig.c b/core/newconfig.c
new file mode 100644 (file)
index 0000000..08027a3
--- /dev/null
@@ -0,0 +1,41 @@
+/* ----------------------------------------------------------------------- *
+ *
+ *   Copyright 2010 Intel Corporation; author: H. Peter Anvin
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ *   Boston MA 02110-1301, USA; either version 2 of the License, or
+ *   (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * newconfig.c
+ *
+ * Load a new configuration file
+ */
+
+#include "core.h"
+#include "fs.h"
+
+void pm_is_config_file(com32sys_t *regs)
+{
+    char target_cwd[FILENAME_MAX];
+    const char *p;
+
+    (void)regs;
+
+    /* Save configuration file as an absolute path for posterity */
+    realpath(ConfigName, KernelCName, FILENAME_MAX);
+
+    /* If we got anything on the command line, do a chdir */
+    p = cmd_line;
+    while (*p && !not_whitespace(*p))
+       p++;
+
+    if (*p) {
+       mangle_name(target_cwd, p);
+       chdir(target_cwd);
+    }
+}
index ab5a7df..b6a2c82 100644 (file)
@@ -122,17 +122,11 @@ Onerror           resb max_cmd_len+1      ; onerror
                section .bss16
 KbdMap         resb 256                ; Keyboard map
 FKeyName       resb MAX_FKEYS*FILENAME_MAX     ; File names for F-key help
-KernelCNameLen resw 1                  ; Length of unmangled kernel name
 InitRDCNameLen resw 1                  ; Length of unmangled initrd name
-%if IS_SYSLINUX
-KernelName      resb FILENAME_MAX+1    ; Mangled name for kernel
-KernelCName     resb FILENAME_MAX+2    ; Unmangled kernel name
-InitRDCName     resb FILENAME_MAX+2    ; Unmangled initrd name
-%else
+               global KernelName, KernelCName
 KernelName      resb FILENAME_MAX      ; Mangled name for kernel
 KernelCName     resb FILENAME_MAX      ; Unmangled kernel name
 InitRDCName     resb FILENAME_MAX      ; Unmangled initrd name
-%endif
 MNameBuf        resb FILENAME_MAX
 InitRD          resb FILENAME_MAX
 
index ad89f58..b30dbc2 100644 (file)
@@ -104,7 +104,7 @@ pc_kernel:  cmp byte [VKernel],0
                mov [VKernelBuf+vk_type],al
                call pc_getline
                mov di,VKernelBuf+vk_rname
-               pm_call mangle_name
+               pm_call pm_mangle_name
 .err:          ret
 
 ;
@@ -147,7 +147,7 @@ pc_setint16:
 pc_filecmd:    push ax                         ; Function to tailcall
                call pc_getline
                mov di,MNameBuf
-               pm_call mangle_name
+               pm_call pm_mangle_name
                pm_call pm_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
-               pm_call mangle_name
+               pm_call pm_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
-               pm_call mangle_name             ; Mangle file name
+               pm_call pm_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
-               pm_call mangle_name
+               pm_call pm_mangle_name
                mov si,AppendBuf                ; Default append==global append
                mov di,VKernelBuf+vk_append
                mov cx,[AppendLen]
@@ -409,7 +409,7 @@ commit_vk:
                mov cx,7        ; "initrd="
                rep movsb
                mov si,InitRD
-               pm_call unmangle_name
+               pm_call pm_unmangle_name
                mov al,' '
                stosb
 
index f07c70f..30177e8 100644 (file)
@@ -78,10 +78,8 @@ construct_cmdline:
                 mov cx,boot_image_len
                 rep movsb
                 mov si,KernelCName             ; Unmangled kernel name
-                mov cx,[KernelCNameLen]
-                rep movsb
-                mov al,' '                      ; Space
-                stosb
+               call strcpy
+               mov byte [es:di-1],' '          ; Follow by space
 
                call do_ip_append               ; Handle IPAppend
 
@@ -546,7 +544,7 @@ parse_load_initrd:
 
                push di
                mov di,InitRD           ; Target buffer for mangled name
-               pm_call mangle_name
+               pm_call pm_mangle_name
                pop di
                call loadinitrd
 
@@ -593,7 +591,7 @@ loadinitrd:
                push edi
                 mov si,InitRD
                 mov di,InitRDCName
-                pm_call unmangle_name             ; Create human-readable name
+                pm_call pm_unmangle_name             ; Create human-readable name
                 sub di,InitRDCName
                 mov [InitRDCNameLen],di
                 mov di,InitRD
index 827710f..5fe3e53 100644 (file)
@@ -333,11 +333,11 @@ load_kernel:                                      ; Load the kernel now
                mov si,command_line
                 mov di,KernelName
                 push si
-               pm_call mangle_name
+               pm_call pm_mangle_name
                 pop si
 ;
 ; Fast-forward to first option (we start over from the beginning, since
-; mangle_name doesn't necessarily return a consistent ending state.)
+; pm_mangle_name doesn't necessarily return a consistent ending state.)
 ;
 clin_non_wsp:   lodsb
                 cmp al,' '
@@ -400,6 +400,7 @@ vk_check:
                mov si,VKernelBuf+vk_append
                mov cx,[VKernelBuf+vk_appendlen]
                rep movsb
+               mov byte [es:di],cl             ; Null-terminate
                mov [CmdLinePtr],di             ; Where to add rest of cmd
                pop es
                mov di,KernelName
@@ -440,6 +441,7 @@ vk_check:
                 mov di,cmd_line_here
                 mov cx,[AppendLen]
                 rep movsb
+               mov byte [es:di],cl             ; Null-terminate
                 mov [CmdLinePtr],di
                 pop di
                 pop si
@@ -487,7 +489,7 @@ bad_kernel:
                mov si,KernelName
                 mov di,KernelCName
                push di
-                pm_call unmangle_name              ; Get human form
+                pm_call pm_unmangle_name              ; Get human form
                mov si,err_notfound             ; Complain about missing kernel
                call writestr
                pop si                          ; KernelCName
@@ -616,9 +618,7 @@ kernel_good:
 
                mov si,KernelName
                mov di,KernelCName
-               pm_call unmangle_name
-               sub di,KernelCName
-               mov [KernelCNameLen],di
+               pm_call pm_unmangle_name
 
                ; Default memory limit, can be overridden by image loaders
                mov eax,[HighMemRsvd]
@@ -675,9 +675,8 @@ is_unknown_filetype:
 
 is_config_file:
                push si
-               mov si,KernelCName              ; Save the config file name, for posterity
-               mov di,ConfigName
-               pm_call pm_realpath
+               call make_plain_cmdline
+               pm_call pm_is_config_file
                pop si
                call openfd
                call reset_config