diff --git a/ChangeLog b/ChangeLog index b7ce5cbe6..0f953e970 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,75 @@ +2005-08-18 Yoshinori K. Okuji + + * normal/misc.c: New file. + + * DISTLIST: Added normal/misc.c. + + * partmap/amiga.c (amiga_partition_map_iterate): Add an argument + DISK to HOOK. Call HOOK with DISK. + * partmap/apple.c (apple_partition_map_iterate): Likewise. + * partmap/pc.c (pc_partition_map_iterate): Likewise. + * partmap/sun.c (sun_partition_map_iterate): Likewise. + + * normal/menu_entry.c (struct screen): Added a new member + "completion_shown". + (completion_buffer): New global variable. + (make_screen): Set SCREEN->COMPLETION_SHOWN to zero. + (store_completion): New function. + (complete): Likewise. + (clear_completions): Likewise. + (grub_menu_entry_run): If SCREEN->COMPLETION_SHOWN is non-zero, + call clear_completions and reset SCREEN->COMPLETION_SHOWN. If C is + a tab, call complete. + + * normal/completion.c (disk_dev): Removed. + (print_simple_completion): Likewise. + (print_partition_completion): Likewise. + (print_func): New global variable. + (add_completion): Do not take the arguments WHAT or PRINT any + longer. Added a new argument TYPE. Instead of printing directly, + call PRINT_FUNC if not NULL. + All callers changed. + (complete_device): Use a local variable DEV instead of + DISK_DEV. Do not move CURRENT_WORD to the end of a device name. + (grub_normal_do_completion): Take a new argument HOOK. Do not + initialize DISK_DEV. Initialize PRINT_FUNC to HOOK. If RET is an + empty string, return NULL instead. + All callers changed. + + * normal/cmdline.c (print_completion): New function. + + * kern/partition.c (grub_partition_iterate): Add an argument DISK + to HOOK. + All callers changed. + + * kern/disk.c (grub_print_partinfo): Removed. + + * include/grub/partition.h (struct grub_partition_map): Add a new + argument DISK into HOOK of ITERATE. + (grub_partition_iterate): Add a new argument DISK to HOOK. + + * include/grub/normal.h (enum grub_completion_type): New enum. + (grub_completion_type_t): New type. + (GRUB_COMPLETION_TYPE_COMMAND): New constant. + (GRUB_COMPLETION_TYPE_DEVICE): Likewise. + (GRUB_COMPLETION_TYPE_PARTITION): Likewise. + (GRUB_COMPLETION_TYPE_FILE): Likewise. + (grub_normal_do_completion): Added a new argument HOOK. + (grub_normal_print_device_info): New prototype. + + * include/grub/disk.h (grub_print_partinfo): Removed. + + * conf/i386-pc.rmk (grub_emu_SOURCES): Added normal/misc.c. + (normal_mod_SOURCES): Likewise. + * conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise. + (normal_mod_SOURCES): Likewise. + + * commands/ls.c (grub_ls_list_disks): Use + grub_normal_print_device_info instead of grub_print_partinfo. Free + PNAME. + (grub_ls_list_files): Use grub_normal_print_device_info instead of + duplicating the code. + 2005-08-16 Vesa Jaaskelainen * commands/i386/pc/vbe_list_modes.c: Update source formatting to diff --git a/NEWS b/NEWS index b9d621d20..e7c0cd406 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,11 @@ New in 1.91: * Add support for LZO version 2. +* Support completion in the entry editor. + +* Add VBE support. + + New in 1.90 - 2005-08-07: * Rename the project name PUPA to GRUB. Now this version is the diff --git a/commands/ls.c b/commands/ls.c index dc762bc4c..5b1b5a70a 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -48,18 +48,26 @@ grub_ls_list_disks (int longlist) int grub_ls_print_disks (const char *name) { grub_device_t dev; - auto int print_partition (const grub_partition_t p); + auto int print_partition (grub_disk_t disk, const grub_partition_t p); - int print_partition (const grub_partition_t p) + int print_partition (grub_disk_t disk __attribute__ ((unused)), + const grub_partition_t p) { char *pname = grub_partition_get_name (p); if (pname) { if (longlist) - grub_print_partinfo (dev, pname); + { + char device_name[grub_strlen (name) + 1 + + grub_strlen (pname) + 1]; + grub_sprintf (device_name, "%s,%s", name, pname); + grub_normal_print_device_info (device_name); + } else grub_printf ("(%s,%s) ", name, pname); + + grub_free (pname); } return 0; @@ -71,36 +79,7 @@ grub_ls_list_disks (int longlist) if (dev) { if (longlist) - { - grub_printf ("Device: %s", name); - - if (! dev->disk || ! dev->disk->has_partitions) - { - grub_fs_t fs; - char *label; - - fs = grub_fs_probe (dev); - grub_errno = GRUB_ERR_NONE; - - grub_printf (", Filesystem type %s", - fs ? fs->name : "unknown"); - - if (fs && fs->label) - { - (fs->label) (dev, &label); - if (grub_errno == GRUB_ERR_NONE) - { - if (label && grub_strlen (label)) - grub_printf (", Label: %s", label); - grub_free (label); - } - else - grub_errno = GRUB_ERR_NONE; - } - } - - grub_putchar ('\n'); - } + grub_normal_print_device_info (name); else grub_printf ("(%s) ", name); @@ -223,26 +202,8 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) { if (grub_errno == GRUB_ERR_UNKNOWN_FS) grub_errno = GRUB_ERR_NONE; - - grub_printf ("(%s): Filesystem is %s", - device_name, fs ? fs->name : "unknown"); - - if (fs && fs->label) - { - char *label; - - (fs->label) (dev, &label); - if (grub_errno == GRUB_ERR_NONE) - { - if (label && grub_strlen (label)) - grub_printf (", Label: %s", label); - grub_free (label); - } - else - grub_errno = GRUB_ERR_NONE; - } - - grub_putchar ('\n'); + + grub_normal_print_device_info (device_name); } else if (fs) { diff --git a/conf/i386-pc.mk b/conf/i386-pc.mk index 0d65502e4..c013a6784 100644 --- a/conf/i386-pc.mk +++ b/conf/i386-pc.mk @@ -684,15 +684,15 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ - normal/menu.c normal/menu_entry.c \ + normal/menu.c normal/menu_entry.c normal/misc.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ util/console.c util/grub-emu.c util/misc.c \ util/i386/pc/biosdisk.c util/i386/pc/getroot.c \ util/i386/pc/misc.c -CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o -MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_i386_pc_halt.d grub_emu-commands_i386_pc_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_i386_pc_misc.d +CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o +MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_i386_pc_halt.d grub_emu-commands_i386_pc_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_i386_pc_misc.d -grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o +grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_i386_pc_misc.o $(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(grub_emu_LDFLAGS) grub_emu-commands_boot.o: commands/boot.c @@ -1023,6 +1023,14 @@ grub_emu-normal_menu_entry.d: normal/menu_entry.c -include grub_emu-normal_menu_entry.d +grub_emu-normal_misc.o: normal/misc.c + $(BUILD_CC) -Inormal -I$(srcdir)/normal $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $< + +grub_emu-normal_misc.d: normal/misc.c + set -e; $(BUILD_CC) -Inormal -I$(srcdir)/normal $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -M $< | sed 's,misc\.o[ :]*,grub_emu-normal_misc.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@ + +-include grub_emu-normal_misc.d + grub_emu-partmap_amiga.o: partmap/amiga.c $(BUILD_CC) -Ipartmap -I$(srcdir)/partmap $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $< @@ -1701,9 +1709,10 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ - normal/menu.c normal/menu_entry.c normal/i386/setjmp.S -CLEANFILES += normal.mod mod-normal.o mod-normal.c pre-normal.o normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_i386_setjmp.o def-normal.lst und-normal.lst -MOSTLYCLEANFILES += normal_mod-normal_arg.d normal_mod-normal_cmdline.d normal_mod-normal_command.d normal_mod-normal_completion.d normal_mod-normal_context.d normal_mod-normal_main.d normal_mod-normal_menu.d normal_mod-normal_menu_entry.d normal_mod-normal_i386_setjmp.d + normal/menu.c normal/menu_entry.c normal/misc.c \ + normal/i386/setjmp.S +CLEANFILES += normal.mod mod-normal.o mod-normal.c pre-normal.o normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_misc.o normal_mod-normal_i386_setjmp.o def-normal.lst und-normal.lst +MOSTLYCLEANFILES += normal_mod-normal_arg.d normal_mod-normal_cmdline.d normal_mod-normal_command.d normal_mod-normal_completion.d normal_mod-normal_context.d normal_mod-normal_main.d normal_mod-normal_menu.d normal_mod-normal_menu_entry.d normal_mod-normal_misc.d normal_mod-normal_i386_setjmp.d DEFSYMFILES += def-normal.lst UNDSYMFILES += und-normal.lst @@ -1712,7 +1721,7 @@ normal.mod: pre-normal.o mod-normal.o $(LD) -r -d -o $@ $^ $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ -pre-normal.o: normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_i386_setjmp.o +pre-normal.o: normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_misc.o normal_mod-normal_i386_setjmp.o -rm -f $@ $(LD) -r -d -o $@ $^ @@ -1881,6 +1890,25 @@ fs-menu_entry.lst: normal/menu_entry.c genfslist.sh set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh normal > $@ || (rm -f $@; exit 1) +normal_mod-normal_misc.o: normal/misc.c + $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -c -o $@ $< + +normal_mod-normal_misc.d: normal/misc.c + set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -M $< | sed 's,misc\.o[ :]*,normal_mod-normal_misc.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@ + +-include normal_mod-normal_misc.d + +CLEANFILES += cmd-misc.lst fs-misc.lst +COMMANDFILES += cmd-misc.lst +FSFILES += fs-misc.lst + +cmd-misc.lst: normal/misc.c gencmdlist.sh + set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh normal > $@ || (rm -f $@; exit 1) + +fs-misc.lst: normal/misc.c genfslist.sh + set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh normal > $@ || (rm -f $@; exit 1) + + normal_mod-normal_i386_setjmp.o: normal/i386/setjmp.S $(CC) -Inormal/i386 -I$(srcdir)/normal/i386 $(CPPFLAGS) $(ASFLAGS) $(normal_mod_ASFLAGS) -c -o $@ $< diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 3e93b2c86..3a18e1d6f 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -88,7 +88,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ - normal/menu.c normal/menu_entry.c \ + normal/menu.c normal/menu_entry.c normal/misc.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ util/console.c util/grub-emu.c util/misc.c \ util/i386/pc/biosdisk.c util/i386/pc/getroot.c \ @@ -165,7 +165,8 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ - normal/menu.c normal/menu_entry.c normal/i386/setjmp.S + normal/menu.c normal/menu_entry.c normal/misc.c \ + normal/i386/setjmp.S normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/conf/powerpc-ieee1275.mk b/conf/powerpc-ieee1275.mk index c20d1b711..04da8ecf5 100644 --- a/conf/powerpc-ieee1275.mk +++ b/conf/powerpc-ieee1275.mk @@ -75,15 +75,15 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c \ - normal/main.c normal/menu.c normal/menu_entry.c \ + normal/main.c normal/menu.c normal/menu_entry.c normal/misc.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ util/console.c util/grub-emu.c util/misc.c \ util/i386/pc/biosdisk.c util/i386/pc/getroot.c \ util/powerpc/ieee1275/misc.c -CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o -MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_ieee1275_halt.d grub_emu-commands_ieee1275_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_powerpc_ieee1275_misc.d +CLEANFILES += grub-emu grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o +MOSTLYCLEANFILES += grub_emu-commands_boot.d grub_emu-commands_cat.d grub_emu-commands_cmp.d grub_emu-commands_configfile.d grub_emu-commands_default.d grub_emu-commands_help.d grub_emu-commands_terminal.d grub_emu-commands_ls.d grub_emu-commands_timeout.d grub_emu-commands_ieee1275_halt.d grub_emu-commands_ieee1275_reboot.d grub_emu-disk_loopback.d grub_emu-fs_ext2.d grub_emu-fs_fat.d grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_ufs.d grub_emu-kern_device.d grub_emu-kern_disk.d grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d grub_emu-kern_file.d grub_emu-kern_fs.d grub_emu-kern_loader.d grub_emu-kern_main.d grub_emu-kern_misc.d grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d grub_emu-normal_arg.d grub_emu-normal_cmdline.d grub_emu-normal_command.d grub_emu-normal_completion.d grub_emu-normal_context.d grub_emu-normal_main.d grub_emu-normal_menu.d grub_emu-normal_menu_entry.d grub_emu-normal_misc.d grub_emu-partmap_amiga.d grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d grub_emu-util_console.d grub_emu-util_grub_emu.d grub_emu-util_misc.d grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d grub_emu-util_powerpc_ieee1275_misc.d -grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o +grub-emu: grub_emu-commands_boot.o grub_emu-commands_cat.o grub_emu-commands_cmp.o grub_emu-commands_configfile.o grub_emu-commands_default.o grub_emu-commands_help.o grub_emu-commands_terminal.o grub_emu-commands_ls.o grub_emu-commands_timeout.o grub_emu-commands_ieee1275_halt.o grub_emu-commands_ieee1275_reboot.o grub_emu-disk_loopback.o grub_emu-fs_ext2.o grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o grub_emu-fs_ufs.o grub_emu-kern_device.o grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o grub_emu-kern_err.o grub_emu-kern_file.o grub_emu-kern_fs.o grub_emu-kern_loader.o grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_partition.o grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o grub_emu-normal_cmdline.o grub_emu-normal_command.o grub_emu-normal_completion.o grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o grub_emu-normal_menu_entry.o grub_emu-normal_misc.o grub_emu-partmap_amiga.o grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o grub_emu-util_console.o grub_emu-util_grub_emu.o grub_emu-util_misc.o grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o grub_emu-util_powerpc_ieee1275_misc.o $(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(grub_emu_LDFLAGS) grub_emu-commands_boot.o: commands/boot.c @@ -414,6 +414,14 @@ grub_emu-normal_menu_entry.d: normal/menu_entry.c -include grub_emu-normal_menu_entry.d +grub_emu-normal_misc.o: normal/misc.c + $(BUILD_CC) -Inormal -I$(srcdir)/normal $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $< + +grub_emu-normal_misc.d: normal/misc.c + set -e; $(BUILD_CC) -Inormal -I$(srcdir)/normal $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -M $< | sed 's,misc\.o[ :]*,grub_emu-normal_misc.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@ + +-include grub_emu-normal_misc.d + grub_emu-partmap_amiga.o: partmap/amiga.c $(BUILD_CC) -Ipartmap -I$(srcdir)/partmap $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=1 $(grub_emu_CFLAGS) -c -o $@ $< @@ -1189,9 +1197,10 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ - normal/menu.c normal/menu_entry.c normal/powerpc/setjmp.S -CLEANFILES += normal.mod mod-normal.o mod-normal.c pre-normal.o normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_powerpc_setjmp.o def-normal.lst und-normal.lst -MOSTLYCLEANFILES += normal_mod-normal_arg.d normal_mod-normal_cmdline.d normal_mod-normal_command.d normal_mod-normal_completion.d normal_mod-normal_context.d normal_mod-normal_main.d normal_mod-normal_menu.d normal_mod-normal_menu_entry.d normal_mod-normal_powerpc_setjmp.d + normal/menu.c normal/menu_entry.c normal/misc.c \ + normal/powerpc/setjmp.S +CLEANFILES += normal.mod mod-normal.o mod-normal.c pre-normal.o normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_misc.o normal_mod-normal_powerpc_setjmp.o def-normal.lst und-normal.lst +MOSTLYCLEANFILES += normal_mod-normal_arg.d normal_mod-normal_cmdline.d normal_mod-normal_command.d normal_mod-normal_completion.d normal_mod-normal_context.d normal_mod-normal_main.d normal_mod-normal_menu.d normal_mod-normal_menu_entry.d normal_mod-normal_misc.d normal_mod-normal_powerpc_setjmp.d DEFSYMFILES += def-normal.lst UNDSYMFILES += und-normal.lst @@ -1200,7 +1209,7 @@ normal.mod: pre-normal.o mod-normal.o $(LD) -r -d -o $@ $^ $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ -pre-normal.o: normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_powerpc_setjmp.o +pre-normal.o: normal_mod-normal_arg.o normal_mod-normal_cmdline.o normal_mod-normal_command.o normal_mod-normal_completion.o normal_mod-normal_context.o normal_mod-normal_main.o normal_mod-normal_menu.o normal_mod-normal_menu_entry.o normal_mod-normal_misc.o normal_mod-normal_powerpc_setjmp.o -rm -f $@ $(LD) -r -d -o $@ $^ @@ -1369,6 +1378,25 @@ fs-menu_entry.lst: normal/menu_entry.c genfslist.sh set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh normal > $@ || (rm -f $@; exit 1) +normal_mod-normal_misc.o: normal/misc.c + $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -c -o $@ $< + +normal_mod-normal_misc.d: normal/misc.c + set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -M $< | sed 's,misc\.o[ :]*,normal_mod-normal_misc.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@ + +-include normal_mod-normal_misc.d + +CLEANFILES += cmd-misc.lst fs-misc.lst +COMMANDFILES += cmd-misc.lst +FSFILES += fs-misc.lst + +cmd-misc.lst: normal/misc.c gencmdlist.sh + set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh normal > $@ || (rm -f $@; exit 1) + +fs-misc.lst: normal/misc.c genfslist.sh + set -e; $(CC) -Inormal -I$(srcdir)/normal $(CPPFLAGS) $(CFLAGS) $(normal_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh normal > $@ || (rm -f $@; exit 1) + + normal_mod-normal_powerpc_setjmp.o: normal/powerpc/setjmp.S $(CC) -Inormal/powerpc -I$(srcdir)/normal/powerpc $(CPPFLAGS) $(ASFLAGS) $(normal_mod_ASFLAGS) -c -o $@ $< diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index b6112e29a..a7fa2f53c 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -45,7 +45,7 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \ kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c \ - normal/main.c normal/menu.c normal/menu_entry.c \ + normal/main.c normal/menu.c normal/menu_entry.c normal/misc.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ util/console.c util/grub-emu.c util/misc.c \ util/i386/pc/biosdisk.c util/i386/pc/getroot.c \ @@ -119,7 +119,8 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ - normal/menu.c normal/menu_entry.c normal/powerpc/setjmp.S + normal/menu.c normal/menu_entry.c normal/misc.c \ + normal/powerpc/setjmp.S normal_mod_CFLAGS = $(COMMON_CFLAGS) normal_mod_ASFLAGS = $(COMMON_ASFLAGS) diff --git a/include/grub/disk.h b/include/grub/disk.h index c579df0e8..09908c97d 100644 --- a/include/grub/disk.h +++ b/include/grub/disk.h @@ -129,7 +129,5 @@ grub_err_t EXPORT_FUNC(grub_disk_write) (grub_disk_t disk, unsigned long size, const char *buf); -grub_err_t EXPORT_FUNC(grub_print_partinfo) (grub_device_t disk, - char *partname); #endif /* ! GRUB_DISK_HEADER */ diff --git a/include/grub/normal.h b/include/grub/normal.h index b89004000..b6814e951 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -44,6 +44,16 @@ /* Not loaded yet. Used for auto-loading. */ #define GRUB_COMMAND_FLAG_NOT_LOADED 0x20 +/* The type of a completion item. */ +enum grub_completion_type + { + GRUB_COMPLETION_TYPE_COMMAND, + GRUB_COMPLETION_TYPE_DEVICE, + GRUB_COMPLETION_TYPE_PARTITION, + GRUB_COMPLETION_TYPE_FILE, + }; +typedef enum grub_completion_type grub_completion_type_t; + /* The command description. */ struct grub_command { @@ -178,7 +188,9 @@ grub_context_t grub_context_get (void); grub_menu_t grub_context_get_current_menu (void); grub_menu_t grub_context_push_menu (grub_menu_t menu); void grub_context_pop_menu (void); -char *grub_normal_do_completion (char *buf, int *restore); +char *grub_normal_do_completion (char *buf, int *restore, + void (*hook) (const char *item, grub_completion_type_t type, int count)); +grub_err_t grub_normal_print_device_info (const char *name); #ifdef GRUB_UTIL void grub_normal_init (void); diff --git a/include/grub/partition.h b/include/grub/partition.h index 255fb9924..4cd1eb15a 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -34,7 +34,7 @@ struct grub_partition_map /* Call HOOK with each partition, until HOOK returns non-zero. */ grub_err_t (*iterate) (struct grub_disk *disk, - int (*hook) (const grub_partition_t partition)); + int (*hook) (struct grub_disk *disk, const grub_partition_t partition)); /* Return the partition named STR on the disk DISK. */ grub_partition_t (*probe) (struct grub_disk *disk, @@ -73,7 +73,7 @@ struct grub_partition grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk, const char *str); grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk, - int (*hook) (const grub_partition_t partition)); + int (*hook) (struct grub_disk *disk, const grub_partition_t partition)); char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition); int EXPORT_FUNC(grub_partition_map_iterate) (int (*hook) (const grub_partition_map_t partmap)); diff --git a/kern/disk.c b/kern/disk.c index 02a49b6c9..ecd0b7b1d 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -513,44 +513,3 @@ grub_disk_write (grub_disk_t disk, unsigned long sector, return grub_errno; } - -grub_err_t -grub_print_partinfo (grub_device_t disk, char *partname) -{ - grub_fs_t fs = 0; - grub_device_t part; - char devname[20]; - - grub_sprintf (devname, "%s,%s", disk->disk->name, partname); - part = grub_device_open (devname); - if (!part) - grub_printf ("\tPartition num:%s, Filesystem cannot be accessed", - partname); - else - { - char *label; - - fs = grub_fs_probe (part); - /* Ignore all errors. */ - grub_errno = 0; - - grub_printf ("\tPartition num:%s, Filesystem type %s", - partname, fs ? fs->name : "Unknown"); - - if (fs && fs->label) - { - (fs->label) (part, &label); - if (grub_errno == GRUB_ERR_NONE) - { - if (label && grub_strlen (label)) - grub_printf (", Label: %s", label); - grub_free (label); - } - grub_errno = GRUB_ERR_NONE; - } - grub_device_close (part); - } - - grub_printf ("\n"); - return grub_errno; -} diff --git a/kern/partition.c b/kern/partition.c index fd0f51220..3eea7ae0d 100644 --- a/kern/partition.c +++ b/kern/partition.c @@ -85,14 +85,17 @@ grub_partition_probe (struct grub_disk *disk, const char *str) grub_err_t grub_partition_iterate (struct grub_disk *disk, - int (*hook) (const grub_partition_t partition)) + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { grub_partition_map_t partmap = 0; auto int part_map_iterate (const grub_partition_map_t p); - auto int part_map_iterate_hook (const grub_partition_t partition); + auto int part_map_iterate_hook (grub_disk_t d, + const grub_partition_t partition); - int part_map_iterate_hook (const grub_partition_t partition __attribute__ ((unused))) + int part_map_iterate_hook (grub_disk_t d __attribute__ ((unused)), + const grub_partition_t partition __attribute__ ((unused))) { return 1; } diff --git a/kern/rescue.c b/kern/rescue.c index b5a3cb3dd..fa1ee80f0 100644 --- a/kern/rescue.c +++ b/kern/rescue.c @@ -171,9 +171,10 @@ static int grub_rescue_print_disks (const char *name) { grub_device_t dev; - auto int print_partition (const grub_partition_t p); + auto int print_partition (grub_disk_t disk, const grub_partition_t p); - int print_partition (const grub_partition_t p) + int print_partition (grub_disk_t disk __attribute__ ((unused)), + const grub_partition_t p) { char *pname = grub_partition_get_name (p); diff --git a/normal/cmdline.c b/normal/cmdline.c index b8475474f..844864147 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -164,6 +164,46 @@ grub_cmdline_run (int nested) } } +/* A completion hook to print items. */ +static void +print_completion (const char *item, grub_completion_type_t type, int count) +{ + if (count == 0) + { + /* If this is the first time, print a label. */ + const char *what; + + switch (type) + { + case GRUB_COMPLETION_TYPE_COMMAND: + what = "commands"; + break; + case GRUB_COMPLETION_TYPE_DEVICE: + what = "devices"; + break; + case GRUB_COMPLETION_TYPE_FILE: + what = "files"; + break; + case GRUB_COMPLETION_TYPE_PARTITION: + what = "partitions"; + break; + default: + what = "things"; + break; + } + + grub_printf ("\nPossible %s are:\n", what); + } + + if (type == GRUB_COMPLETION_TYPE_PARTITION) + { + grub_normal_print_device_info (item); + grub_errno = GRUB_ERR_NONE; + } + else + grub_printf (" %s", item); +} + /* Get a command-line. If ECHO_CHAR is not zero, echo it instead of input characters. If READLINE is non-zero, readline-like key bindings are available. If ESC is pushed, return zero, otherwise return non-zero. */ @@ -309,7 +349,8 @@ grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, buf[lpos] = '\0'; - insert = grub_normal_do_completion (buf, &restore); + insert = grub_normal_do_completion (buf, &restore, + print_completion); /* Restore the original string. */ buf[lpos] = backup; diff --git a/normal/completion.c b/normal/completion.c index cde420fe7..7e4e77d2c 100644 --- a/normal/completion.c +++ b/normal/completion.c @@ -26,9 +26,6 @@ #include #include -/* The disk that is used for grub_partition_iterate. */ -static grub_device_t disk_dev; - /* The current word. */ static char *current_word; @@ -41,29 +38,17 @@ static int num_found; /* The string to be appended. */ static const char *suffix; +/* The callback function to print items. */ +static void (*print_func) (const char *, grub_completion_type_t, int); + -static void -print_simple_completion (const char *str) -{ - grub_printf (" %s", str); -} - -static void -print_partition_completion (const char *str) -{ - grub_print_partinfo (disk_dev, (char *) str); - grub_errno = GRUB_ERR_NONE; -} - /* Add a string to the list of possible completions. COMPLETION is the string that should be added. EXTRA will be appended if COMPLETION - matches uniquely. The string WHAT contains a description of the - kind of data that is added. Use PRINT to show the completions - if there are multiple matches. */ + matches uniquely. The type TYPE specifies what kind of data is added. */ static int -add_completion (const char *completion, const char *extra, const char *what, - void (*print) (const char *)) +add_completion (const char *completion, const char *extra, + grub_completion_type_t type) { if (grub_strncmp (current_word, completion, grub_strlen (current_word)) == 0) { @@ -79,8 +64,8 @@ add_completion (const char *completion, const char *extra, const char *what, break; case 2: - grub_printf ("\nPossible %s are:\n", what); - print (match); + if (print_func) + print_func (match, type, 0); /* Fall through. */ @@ -88,8 +73,9 @@ add_completion (const char *completion, const char *extra, const char *what, { char *s = match; const char *t = completion; - - print (completion); + + if (print_func) + print_func (completion, type, num_found - 1); /* Detect the matched portion. */ while (*s && *t && *s == *t) @@ -108,10 +94,30 @@ add_completion (const char *completion, const char *extra, const char *what, } static int -iterate_partition (const grub_partition_t p) +iterate_partition (grub_disk_t disk, const grub_partition_t p) { - return add_completion (grub_partition_get_name (p), ")", "partitions", - print_partition_completion); + const char *disk_name = disk->name; + char *partition_name = grub_partition_get_name (p); + char *name; + int ret; + + if (! partition_name) + return 1; + + name = grub_malloc (grub_strlen (disk_name) + 1 + + grub_strlen (partition_name) + 1); + if (! name) + { + grub_free (partition_name); + return 1; + } + + grub_sprintf (name, "%s,%s", disk_name, partition_name); + grub_free (partition_name); + + ret = add_completion (name, ")", GRUB_COMPLETION_TYPE_PARTITION); + grub_free (name); + return ret; } static int @@ -119,7 +125,7 @@ iterate_dir (const char *filename, int dir) { if (! dir) { - if (add_completion (filename, " ", "files", print_simple_completion)) + if (add_completion (filename, " ", GRUB_COMPLETION_TYPE_FILE)) return 1; } else @@ -127,7 +133,7 @@ iterate_dir (const char *filename, int dir) char fname[grub_strlen (filename) + 2]; grub_sprintf (fname, "%s/", filename); - if (add_completion (fname, "", "files", print_simple_completion)) + if (add_completion (fname, "", GRUB_COMPLETION_TYPE_FILE)) return 1; } @@ -146,14 +152,12 @@ iterate_dev (const char *devname) { if (dev->disk && dev->disk->has_partitions) { - if (add_completion (devname, ",", "devices", - print_simple_completion)) + if (add_completion (devname, ",", GRUB_COMPLETION_TYPE_DEVICE)) return 1; } else { - if (add_completion (devname, ")", "devices", - print_simple_completion)) + if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_DEVICE)) return 1; } } @@ -169,8 +173,7 @@ iterate_command (grub_command_t cmd) { if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE) { - if (add_completion (cmd->name, " ", "commands", - print_simple_completion)) + if (add_completion (cmd->name, " ", GRUB_COMPLETION_TYPE_COMMAND)) return 1; } } @@ -184,6 +187,7 @@ complete_device (void) { /* Check if this is a device or a partition. */ char *p = grub_strchr (++current_word, ','); + grub_device_t dev; if (! p) { @@ -195,24 +199,22 @@ complete_device (void) { /* Complete the partition part. */ *p = '\0'; - disk_dev = grub_device_open (current_word); + dev = grub_device_open (current_word); *p = ','; grub_errno = GRUB_ERR_NONE; - if (disk_dev) + if (dev) { - if (disk_dev->disk && disk_dev->disk->has_partitions) + if (dev->disk && dev->disk->has_partitions) { - current_word = p + 1; - - if (grub_partition_iterate (disk_dev->disk, iterate_partition)) + if (grub_partition_iterate (dev->disk, iterate_partition)) { - grub_device_close (disk_dev); + grub_device_close (dev); return 1; } } - grub_device_close (disk_dev); + grub_device_close (dev); } else return 1; @@ -303,18 +305,19 @@ complete_file (void) /* Try to complete the string in BUF. Return the characters that should be added to the string. This command outputs the possible - completions, in that case set RESTORE to 1 so the caller can - restore the prompt. */ + completions by calling HOOK, in that case set RESTORE to 1 so the + caller can restore the prompt. */ char * -grub_normal_do_completion (char *buf, int *restore) +grub_normal_do_completion (char *buf, int *restore, + void (*hook) (const char *, grub_completion_type_t, int)) { char *first_word; /* Initialize variables. */ - disk_dev = 0; match = 0; num_found = 0; suffix = ""; + print_func = hook; *restore = 1; @@ -376,6 +379,12 @@ grub_normal_do_completion (char *buf, int *restore) grub_free (match); + if (*ret == '\0') + { + grub_free (ret); + return 0; + } + return ret; } diff --git a/normal/menu_entry.c b/normal/menu_entry.c index 81ff8fe12..9cde3d4f0 100644 --- a/normal/menu_entry.c +++ b/normal/menu_entry.c @@ -58,8 +58,13 @@ struct screen int y; /* The kill buffer. */ char *killed_text; + /* The flag of a completion window. */ + int completion_shown; }; +/* Used for storing completion items temporarily. */ +static struct line completion_buffer; + /* Initialize a line. */ static int init_line (struct line *linep) @@ -422,6 +427,7 @@ make_screen (grub_menu_entry_t entry) screen->x = 0; screen->y = 0; screen->killed_text = 0; + screen->completion_shown = 0; screen->lines = grub_malloc (sizeof (struct line)); if (! screen->lines) goto fail; @@ -809,6 +815,163 @@ open_line (struct screen *screen, int update) return 1; } +/* A completion hook to print items. */ +static void +store_completion (const char *item, grub_completion_type_t type, int count) +{ + char *p; + + if (count == 0) + { + /* If this is the first time, print a label. */ + const char *what; + + switch (type) + { + case GRUB_COMPLETION_TYPE_COMMAND: + what = "commands"; + break; + case GRUB_COMPLETION_TYPE_DEVICE: + what = "devices"; + break; + case GRUB_COMPLETION_TYPE_FILE: + what = "files"; + break; + case GRUB_COMPLETION_TYPE_PARTITION: + what = "partitions"; + break; + default: + what = "things"; + break; + } + + grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); + grub_printf (" Possible %s are:\n ", what); + } + + /* Make sure that the completion buffer has enough room. */ + if (completion_buffer.max_len < (completion_buffer.len + + (int) grub_strlen (item) + 1 + 1)) + { + grub_size_t new_len; + + new_len = completion_buffer.len + grub_strlen (item) + 80; + p = grub_realloc (completion_buffer.buf, new_len); + if (! p) + { + /* Possibly not fatal. */ + grub_errno = GRUB_ERR_NONE; + return; + } + p[completion_buffer.len] = 0; + completion_buffer.buf = p; + completion_buffer.max_len = new_len; + } + + p = completion_buffer.buf + completion_buffer.len; + if (completion_buffer.len != 0) + { + *p++ = ' '; + completion_buffer.len++; + } + grub_strcpy (p, item); + completion_buffer.len += grub_strlen (item); +} + +static int +complete (struct screen *screen, int continuous, int update) +{ + grub_uint16_t pos; + char saved_char; + struct line *linep; + int restore; + char *insert; + static int count = -1; + + if (continuous) + count++; + else + count = 0; + + pos = grub_getxy (); + grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); + + completion_buffer.buf = 0; + completion_buffer.len = 0; + completion_buffer.max_len = 0; + + linep = screen->lines + screen->line; + saved_char = linep->buf[screen->column]; + linep->buf[screen->column] = '\0'; + + insert = grub_normal_do_completion (linep->buf, &restore, store_completion); + + linep->buf[screen->column] = saved_char; + + if (restore) + { + char *p = completion_buffer.buf; + + screen->completion_shown = 1; + + if (p) + { + int num_sections = ((completion_buffer.len + GRUB_TERM_WIDTH - 8 - 1) + / (GRUB_TERM_WIDTH - 8)); + char *endp; + + p += (count % num_sections) * (GRUB_TERM_WIDTH - 8); + endp = p + (GRUB_TERM_WIDTH - 8); + + if (p != completion_buffer.buf) + grub_putcode (GRUB_TERM_DISP_LEFT); + else + grub_putchar (' '); + + while (*p && p < endp) + grub_putchar (*p++); + + if (*p) + grub_putcode (GRUB_TERM_DISP_RIGHT); + } + } + + grub_gotoxy (pos >> 8, pos & 0xFF); + + if (insert) + { + insert_string (screen, insert, update); + count = -1; + grub_free (insert); + } + else if (update) + grub_refresh (); + + grub_free (completion_buffer.buf); + return 1; +} + +/* Clear displayed completions. */ +static void +clear_completions (void) +{ + grub_uint16_t pos; + int i, j; + + pos = grub_getxy (); + grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); + + for (i = 0; i < 2; i++) + { + for (j = 0; j < GRUB_TERM_WIDTH - 1; j++) + grub_putchar (' '); + grub_putchar ('\n'); + } + + grub_gotoxy (pos >> 8, pos & 0xFF); + grub_refresh (); +} + /* Execute the command list in the screen SCREEN. */ static int run (struct screen *screen) @@ -880,6 +1043,12 @@ grub_menu_entry_run (grub_menu_entry_t entry) while (1) { int c = GRUB_TERM_ASCII_CHAR (grub_getkey ()); + + if (screen->completion_shown) + { + clear_completions (); + screen->completion_shown = 0; + } switch (c) { @@ -914,7 +1083,8 @@ grub_menu_entry_run (grub_menu_entry_t entry) break; case '\t': /* C-i */ - /* FIXME: Completion */ + if (! complete (screen, prev_c == c, 1)) + goto fail; break; case 4: /* C-d */ diff --git a/normal/misc.c b/normal/misc.c new file mode 100644 index 000000000..a89b8e45c --- /dev/null +++ b/normal/misc.c @@ -0,0 +1,70 @@ +/* misc.c - miscellaneous functions */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include + +/* Print the information on the device NAME. */ +grub_err_t +grub_normal_print_device_info (const char *name) +{ + grub_device_t dev; + char *p; + + p = grub_strchr (name, ','); + if (p) + grub_printf ("\tPartition %s: ", name); + else + grub_printf ("Device %s: ", name); + + dev = grub_device_open (name); + if (! dev) + grub_printf ("Filesystem cannot be accessed"); + else if (! dev->disk || ! dev->disk->has_partitions || dev->disk->partition) + { + char *label; + grub_fs_t fs; + + fs = grub_fs_probe (dev); + /* Ignore all errors. */ + grub_errno = 0; + + grub_printf ("Filesystem type %s", fs ? fs->name : "unknown"); + + if (fs && fs->label) + { + (fs->label) (dev, &label); + if (grub_errno == GRUB_ERR_NONE) + { + if (label && grub_strlen (label)) + grub_printf (", Label %s", label); + grub_free (label); + } + grub_errno = GRUB_ERR_NONE; + } + grub_device_close (dev); + } + + grub_printf ("\n"); + return grub_errno; +} diff --git a/partmap/amiga.c b/partmap/amiga.c index b19a559d0..90959449e 100644 --- a/partmap/amiga.c +++ b/partmap/amiga.c @@ -71,10 +71,13 @@ static struct grub_partition_map grub_amiga_partition_map; #ifndef GRUB_UTIL static grub_dl_t my_mod; #endif + + static grub_err_t amiga_partition_map_iterate (grub_disk_t disk, - int (*hook) (const grub_partition_t partition)) + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition part; struct grub_amiga_rdsk rdsk; @@ -130,7 +133,7 @@ amiga_partition_map_iterate (grub_disk_t disk, part.index = partno; part.partmap = &grub_amiga_partition_map; - if (hook (&part)) + if (hook (disk, &part)) return grub_errno; next = grub_be_to_cpu32 (apart.next); @@ -148,9 +151,10 @@ amiga_partition_map_probe (grub_disk_t disk, const char *str) int partnum = 0; char *s = (char *) str; - auto int find_func (const grub_partition_t partition); + auto int find_func (grub_disk_t d, const grub_partition_t partition); - int find_func (const grub_partition_t partition) + int find_func (grub_disk_t d __attribute__ ((unused)), + const grub_partition_t partition) { if (partnum == partition->index) { diff --git a/partmap/apple.c b/partmap/apple.c index 200d54d67..8b934632b 100644 --- a/partmap/apple.c +++ b/partmap/apple.c @@ -95,7 +95,8 @@ static grub_dl_t my_mod; static grub_err_t apple_partition_map_iterate (grub_disk_t disk, - int (*hook) (const grub_partition_t partition)) + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition part; struct grub_apple_part apart; @@ -134,7 +135,7 @@ apple_partition_map_iterate (grub_disk_t disk, partno, apart.partname, apart.parttype, apart.first_phys_block, apart.blockcnt); - if (hook (&part)) + if (hook (disk, &part)) return grub_errno; if (apart.first_phys_block == GRUB_DISK_SECTOR_SIZE * 2) @@ -159,9 +160,10 @@ apple_partition_map_probe (grub_disk_t disk, const char *str) int partnum = 0; char *s = (char *) str; - auto int find_func (const grub_partition_t partition); + auto int find_func (grub_disk_t d, const grub_partition_t partition); - int find_func (const grub_partition_t partition) + int find_func (grub_disk_t d __attribute__ ((unused)), + const grub_partition_t partition) { if (partnum == partition->index) { diff --git a/partmap/pc.c b/partmap/pc.c index 398786f27..2f96dc4c7 100644 --- a/partmap/pc.c +++ b/partmap/pc.c @@ -93,7 +93,8 @@ grub_partition_parse (const char *str) static grub_err_t pc_partition_map_iterate (grub_disk_t disk, - int (*hook) (const grub_partition_t partition)) + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition p; struct grub_pc_partition pcdata; @@ -145,7 +146,7 @@ pc_partition_map_iterate (grub_disk_t disk, { pcdata.dos_part++; - if (hook (&p)) + if (hook (disk, &p)) goto finish; /* Check if this is a BSD partition. */ @@ -183,7 +184,7 @@ pc_partition_map_iterate (grub_disk_t disk, pcdata.bsd_type = be->fs_type; if (be->fs_type != GRUB_PC_PARTITION_BSD_TYPE_UNUSED) - if (hook (&p)) + if (hook (disk, &p)) goto finish; } } @@ -225,9 +226,10 @@ pc_partition_map_probe (grub_disk_t disk, const char *str) grub_partition_t p; struct grub_pc_partition *pcdata; - auto int find_func (const grub_partition_t partition); + auto int find_func (grub_disk_t d, const grub_partition_t partition); - int find_func (const grub_partition_t partition) + int find_func (grub_disk_t d __attribute__ ((unused)), + const grub_partition_t partition) { struct grub_pc_partition *partdata = partition->data; if ((pcdata->dos_part == partdata->dos_part || pcdata->dos_part == -1) diff --git a/partmap/sun.c b/partmap/sun.c index 9c851202e..a65d4ff62 100644 --- a/partmap/sun.c +++ b/partmap/sun.c @@ -85,7 +85,8 @@ grub_sun_is_valid (struct grub_sun_block *label) static grub_err_t sun_partition_map_iterate (grub_disk_t disk, - int (*hook) (const grub_partition_t partition)) + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition *p; struct grub_disk raw; @@ -122,7 +123,7 @@ sun_partition_map_iterate (grub_disk_t disk, p->index = partnum; if (p->len) { - if (hook (p)) + if (hook (disk, p)) partnum = GRUB_PARTMAP_SUN_MAX_PARTS; } } @@ -139,14 +140,16 @@ sun_partition_map_probe (grub_disk_t disk, const char *str) int partnum = 0; char *s = (char *) str; - auto int find_func (const grub_partition_t partition); - int find_func (const grub_partition_t partition) + auto int find_func (grub_disk_t d, const grub_partition_t partition); + + int find_func (grub_disk_t d __attribute__ ((unused)), + const grub_partition_t partition) { if (partnum == partition->index) { p = (grub_partition_t) grub_malloc (sizeof (*p)); if (p) - grub_memcpy(p, partition, sizeof (*p)); + grub_memcpy (p, partition, sizeof (*p)); return 1; } return 0; diff --git a/util/i386/pc/biosdisk.c b/util/i386/pc/biosdisk.c index 634414f47..b2d317fd3 100644 --- a/util/i386/pc/biosdisk.c +++ b/util/i386/pc/biosdisk.c @@ -733,9 +733,11 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) struct hd_geometry hdg; int dos_part = -1; int bsd_part = -1; - auto int find_partition (const grub_partition_t partition); + auto int find_partition (grub_disk_t disk, + const grub_partition_t partition); - int find_partition (const grub_partition_t partition) + int find_partition (grub_disk_t disk __attribute__ ((unused)), + const grub_partition_t partition) { struct grub_pc_partition *pcdata = 0; diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c index a2ff6fbf3..91faa9998 100644 --- a/util/i386/pc/grub-setup.c +++ b/util/i386/pc/grub-setup.c @@ -106,9 +106,11 @@ setup (const char *prefix, const char *dir, auto void save_blocklists (unsigned long sector, unsigned offset, unsigned length); - auto int find_first_partition_start (const grub_partition_t p); + auto int find_first_partition_start (grub_disk_t disk, + const grub_partition_t p); - int find_first_partition_start (const grub_partition_t p) + int find_first_partition_start (grub_disk_t disk __attribute__ ((unused)), + const grub_partition_t p) { struct grub_pc_partition *pcdata = p->data;