New command checktime
PATCH 1/1 New command checktime
Hi,
I implement this command for grub4dos some time ago, now it's ported to grub2.
Usage:
checktime min hour day_of_month month day_of_week
The five parameters for checktime is the same as in crontab: minute, hour, day, month and day of week. This command check if the current daytime is within the range specified by the parameters, and return true or false accordingly. Combined this with the script support for grub2, you can perform some operation in a selected time range.
The range of the five parameters are:
minute: 0-59
hour: 0-23
day of month: 1-31
month 1-12
day of week 0-6 (0 is Sunday)
checktime * 12-15 * 1,3-5 *
Return true on afternoon of Jan, March, April and May.
checktime * * * */2 *
Return true on Month 1,3,5,7,9,11
For example, you can use a different background image according to the current season:
if checktime * * * 3-5 *; then
background_image /spring.png
fi
if checktime * * * 6-8 *; then
background_image /summer.png
fi
if checktime * * * 9-11 *; then
background_image /fall.png
fi
if checktime * * * 1-2,12 *; then
background_image /winter.png
fi
Or boot a different item in the morning, afternoon and evening.
2008-08-06 Bean <[email protected]>
* conf/i386-pc.rmk (kernel_img_HEADERS): Add machine/time.h. (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* include/grub/i386/pc/time.h: Add function grub_get_datetime.
* kern/i386/pc/startup.S: Add function grub_get_datetime.
* commands/i386/pc/checktime.c: New file.
Signature · 1 line
Bean
commands/i386/pc/checktime.c new file +165 -0
@@ -0,0 +1,165 @@ +/* checktime.c - command to test current date/time. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/machine/time.h> + +static int +grub_cmd_checktime (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +grub_uint32_t date, time; +int day, month, year, sec, min, hour, dow, i; +int limit[5 ][2 ] = {{0 ,59 }, {0 ,23 }, {1 ,31 }, {1 ,12 }, {0 ,7 }}; +int field[5 ]; + + autoint get_day_of_week (void ); +int get_day_of_week (void ) + { +int a, y, m; + + a = (14 - month) /12 ; + y = year - a; + m = month +12 * a -2 ; +return (day + y + y /4 - y /100 + y /400 + (31 * m /12 )) %7 ; + } + +grub_get_datetime (&date, &time); + + day = ((date >>4 ) &0xF ) *10 + (date &0xF ); + date >>=8 ; + + month = ((date >>4 ) &0xF ) *10 + (date &0xF ); + date >>=8 ; + + year = ((date >>4 ) &0xF ) *10 + (date &0xF ); + date >>=8 ; + year += (((date >>4 ) &0xF ) *10 + (date &0xF )) *100 ; + + time >>=8 ; + + sec = ((time >>4 ) &0xF ) *10 + (time &0xF ); + time >>=8 ; + + min = ((time >>4 ) &0xF ) *10 + (time &0xF ); + time >>=8 ; + + hour = ((time >>4 ) &0xF ) *10 + (time &0xF ); + + dow =get_day_of_week (); + + field[0 ] = min; + field[1 ] = hour; + field[2 ] = day; + field[3 ] = month; + field[4 ] = dow; + +if (argc ==0 ) + { +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %d\n" , + year, month, day, hour, min, sec, dow); + +return 0 ; + } + +for (i =0 ; i <5 ; i++) + { +char *p; +int ok =0 ; + +if (i >= argc) +return 0 ; + + p = args[i]; +while (1 ) + { +int m1, m2, m3, j; + +if (*p =='*' ) + { + m1 = limit[i][0 ]; + m2 = limit[i][1 ]; + p++; + } +else + { + m1 =grub_strtoul (p, &p,0 ); + +if (*p =='-' ) + { + p++; + m2 =grub_strtoul (p, &p,0 ); + } +else + m2 = m1; + } + +if ((m1 < limit[i][0 ]) || (m2 > limit[i][1 ]) || (m1 > m2)) +break ; + +if (*p =='/' ) + { + p++; + m3 =grub_strtoul (p, &p,0 ); + } +else + m3 =1 ; + +for (j = m1; j <= m2; j+= m3) + { +if (j == field[i]) + { + ok =1 ; +break ; + } + } + +if (ok) +break ; + +if (*p ==',' ) + p++; +else +break ; + } + +if (! ok) +break ; + } + +return (i ==5 ) ?0 :grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +GRUB_MOD_INIT (checktime) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("checktime" , grub_cmd_checktime, +GRUB_COMMAND_FLAG_BOTH , +"checktime min hour day_of_month month day_of_week" , +"Command to test current date/time." ,0 ); +} + +GRUB_MOD_FINI (checktime) +{ +grub_unregister_command ("checktime" ); +}
conf/i386-pc.rmk +7 -2
@@ -55,7 +55,7 @@ kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h + machine/kernel.h machine/pxe.h machine/time.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
@@ -163,7 +163,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod chktime.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +340,9 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/i386/pc/checktime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/i386/pc/time.h +2 -0
@@ -26,4 +26,6 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); +void EXPORT_FUNC (grub_get_datetime ) (grub_uint32_t *date,grub_uint32_t *time); +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
kern/i386/pc/startup.S +54 -0
57 lines not on this page · raw message
Quoted 8 lines · Bean
if checktime * * * 3-5 *; then
background_image/spring.png
fiif checktime * * * 6-8 *; then
background_image/summer.png
fi
Quoted 7 lines
if checktime * * * 9-11 *; then
background_image/fall.png
fiif checktime * * * 1-2,12 *; then
background_image/winter.png
fi
Nifty :-)
kern/i386/pc/startup.S FUNCTION(grub_pxe_call) · line 2173
Quoted 13 lines
kern/i386/pc/startup.S +13
-0+FUNCTION(grub_get_datetime) + pushl %ebp + pushl %ebx + + pushl %eax + pushl %edx + + call prot_to_real + .code16 + + movb $2, %ah + clc + int $0x1a
Can we make this portable by accessing 0x70 / 0x71 I/O ports instead?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 1 line · Robert Millan
Can we make this portable by accessing
0x70/0x71I/O ports instead?
Hi,
Good point. The new patch uses cmos to get datetime setting, it should be generic among i386 platforms.
2008-08-06 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* commands/checktime.c: New file.
* include/grub/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* kern/i386/datetime.c: Likewise.
Signature · 1 line
Bean
commands/checktime.c new file +147 -0
@@ -0,0 +1,147 @@ +/* checktime.c - command to test current date/time. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/i386/cmos.h> +#include <grub/datetime.h> + +static grub_err_t +grub_cmd_checktime (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +int day, month, year, sec, min, hour, dow, i; +int limit[5 ][2 ] = {{0 ,59 }, {0 ,23 }, {1 ,31 }, {1 ,12 }, {0 ,7 }}; +int field[5 ]; + + autoint get_day_of_week (void ); +int get_day_of_week (void ) + { +int a, y, m; + + a = (14 - month) /12 ; + y = year - a; + m = month +12 * a -2 ; +return (day + y + y /4 - y /100 + y /400 + (31 * m /12 )) %7 ; + } + +if ((grub_get_date (&year, &month, &day)) || + (grub_get_time (&hour, &min, &sec))) +return grub_errno; + + dow =get_day_of_week (); + + field[0 ] = min; + field[1 ] = hour; + field[2 ] = day; + field[3 ] = month; + field[4 ] = dow; + +if (argc ==0 ) + { +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %d\n" , + year, month, day, hour, min, sec, dow); + +return 0 ; + } + +for (i =0 ; i <5 ; i++) + { +char *p; +int ok =0 ; + +if (i >= argc) +return 0 ; + + p = args[i]; +while (1 ) + { +int m1, m2, m3, j; + +if (*p =='*' ) + { + m1 = limit[i][0 ]; + m2 = limit[i][1 ]; + p++; + } +else + { + m1 =grub_strtoul (p, &p,0 ); + +if (*p =='-' ) + { + p++; + m2 =grub_strtoul (p, &p,0 ); + } +else + m2 = m1; + } + +if ((m1 < limit[i][0 ]) || (m2 > limit[i][1 ]) || (m1 > m2)) +break ; + +if (*p =='/' ) + { + p++; + m3 =grub_strtoul (p, &p,0 ); + } +else + m3 =1 ; + +for (j = m1; j <= m2; j+= m3) + { +if (j == field[i]) + { + ok =1 ; +break ; + } + } + +if (ok) +break ; + +if (*p ==',' ) + p++; +else +break ; + } + +if (! ok) +break ; + } + +return (i ==5 ) ?0 :grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +GRUB_MOD_INIT (checktime) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("checktime" , grub_cmd_checktime, +GRUB_COMMAND_FLAG_BOTH , +"checktime min hour day_of_month month day_of_week" , +"Command to test current date/time." ,0 ); +} + +GRUB_MOD_FINI (checktime) +{ +grub_unregister_command ("checktime" ); +}
conf/i386-pc.rmk +6 -1
@@ -163,7 +163,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod chktime.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +340,9 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/checktime.c kern/i386/datetime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/datetime.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef KERNEL_DATETIME_HEADER +#define KERNEL_DATETIME_HEADER 1 + +#include <grub/types.h> + +/* Return date and time. */ +grub_err_t grub_get_date (int *year,int *month,int *day); +grub_err_t grub_get_time (int *hour,int *minute,int *second); + +#endif /* ! KERNEL_DATETIME_HEADER */
include/grub/i386/cmos.h new file +61 -0
61 lines not on this page · raw message
kern/i386/datetime.c new file +118 -0
118 lines not on this page · raw message
Quoted 7 lines · Bean
Quoted 1 line · Robert Millan
Can we make this portable by accessing
0x70/0x71I/O ports instead?Hi,
Good point. The new patch uses cmos to get datetime setting, it should be generic among i386 platforms.
Yep, this works on Coreboot as well (with the obvious i386-coreboot.rmk adjustment). Nice work!
commands/checktime.c line 62
Quoted 2 lines
commands/checktime.c new file +2
-0+grub_printf ("%d-%02d-%02d %02d:%02d:%02d %d\n" , + year, month, day, hour, min, sec, dow);
Btw, the dow part looks weird when printed. Without looking at the code, it's difficult to tell what that final number means.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 9 lines · Robert Millan
Quoted 7 lines · Bean
Quoted 1 line · Robert Millan
Can we make this portable by accessing
0x70/0x71I/O ports instead?Hi,
Good point. The new patch uses cmos to get datetime setting, it should be generic among i386 platforms.
Quoted 8 lines
Yep, this works on Coreboot as well (with the obvious i386-coreboot.rmk adjustment). Nice work!
Review
Quoted 2 lines
(quoted diff) +2
-0+ grub_printf ("%d-%02d-%02d %02d:%02d:%02d %d\n", + year, month, day, hour, min, sec, dow);Btw, the dow part looks weird when printed. Without looking at the code, it's difficult to tell what that final number means.
Hi,
This patch replaces the day of week number with string. Also, it extends to efi and other i386 platform as well.
2008-08-07 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* conf/i386-efi.rmk (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* conf/x86_64-efi.rmk (pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
* commands/checktime.c: New file.
* include/grub/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* kern/i386/datetime.c: Likewise.
* kern/efi/datetime.c: Likewise.
Signature · 1 line
Bean
commands/checktime.c new file +150 -0
@@ -0,0 +1,150 @@ +/* checktime.c - command to test current date/time. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/datetime.h> + +static int +get_day_of_week (struct grub_datetime *datetime) +{ +int a, y, m; + + a = (14 - datetime->month) /12 ; + y = datetime->year - a; + m = datetime->month +12 * a -2 ; + +return (datetime->day + y + y /4 - y /100 + y /400 + (31 * m /12 )) %7 ; +} + +static grub_err_t +grub_cmd_checktime (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int dow, i; +int limit[5 ][2 ] = {{0 ,59 }, {0 ,23 }, {1 ,31 }, {1 ,12 }, {0 ,7 }}; +int field[5 ]; +char * dow_names[7 ] = {"Sun" ,"Mon" ,"Tue" ,"Wed" ,"Thu" ,"Fri" ,"Sat" }; + +if (grub_get_datetime (&datetime)) +return grub_errno; + + dow =get_day_of_week (&datetime); + + field[0 ] = datetime.minute; + field[1 ] = datetime.hour; + field[2 ] = datetime.day; + field[3 ] = datetime.month; + field[4 ] = dow; + +if (argc ==0 ) + { +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n" , + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, + dow_names[dow]); + +return 0 ; + } + +for (i =0 ; i <5 ; i++) + { +char *p; +int ok =0 ; + +if (i >= argc) +return 0 ; + + p = args[i]; +while (1 ) + { +int m1, m2, m3, j; + +if (*p =='*' ) + { + m1 = limit[i][0 ]; + m2 = limit[i][1 ]; + p++; + } +else + { + m1 =grub_strtoul (p, &p,0 ); + +if (*p =='-' ) + { + p++; + m2 =grub_strtoul (p, &p,0 ); + } +else + m2 = m1; + } + +if ((m1 < limit[i][0 ]) || (m2 > limit[i][1 ]) || (m1 > m2)) +break ; + +if (*p =='/' ) + { + p++; + m3 =grub_strtoul (p, &p,0 ); + } +else + m3 =1 ; + +for (j = m1; j <= m2; j+= m3) + { +if (j == field[i]) + { + ok =1 ; +break ; + } + } + +if (ok) +break ; + +if (*p ==',' ) + p++; +else +break ; + } + +if (! ok) +break ; + } + +return (i ==5 ) ?0 :grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +GRUB_MOD_INIT (checktime) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("checktime" , grub_cmd_checktime, +GRUB_COMMAND_FLAG_BOTH , +"checktime min hour day_of_month month day_of_week" , +"Command to test current date/time." ,0 ); +} + +GRUB_MOD_FINI (checktime) +{ +grub_unregister_command ("checktime" ); +}
conf/i386-coreboot.rmk +6 -1
@@ -100,7 +100,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod chktime.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -185,4 +185,9 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/checktime.c kern/i386/datetime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +7 -1
@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + chktime.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -166,4 +167,9 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/checktime.c kern/efi/datetime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +6 -1
@@ -103,7 +106,7 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod chktime.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
@@ -187,4 +190,9 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/checktime.c kern/i386/datetime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +6 -1
@@ -163,7 +163,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod chktime.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +340,9 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/checktime.c kern/i386/datetime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/x86_64-efi.rmk +7 -1
@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + chktime.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +170,9 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For chktime.mod +chktime_mod_SOURCES = commands/checktime.c kern/efi/datetime.c +chktime_mod_CFLAGS = $(COMMON_CFLAGS) +chktime_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/datetime.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef KERNEL_DATETIME_HEADER +#define KERNEL_DATETIME_HEADER 1 + +#include <grub/types.h> +#include <grub/err.h> + +struct grub_datetime +{ +grub_uint16_t year; +grub_uint8_t month; +grub_uint8_t day; +grub_uint8_t hour; +grub_uint8_t minute; +grub_uint8_t second; +}; + +/* Return date and time. */ +grub_err_t grub_get_datetime (struct grub_datetime *datetime); + +#endif /* ! KERNEL_DATETIME_HEADER */
include/grub/i386/cmos.h new file +61 -0
61 lines not on this page · raw message
kern/efi/datetime.c new file +48 -0
48 lines not on this page · raw message
kern/i386/datetime.c new file +82 -0
82 lines not on this page · raw message
Quoted 4 lines · Bean
* conf/i386-ieee1275.rmk (
pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
Uhm I'm not sure those have a PC-compatible CMOS ...
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 7 lines · Robert Millan
Quoted 4 lines · Bean
* conf/i386-ieee1275.rmk (
pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.Uhm I'm not sure those have a PC-compatible CMOS ...
Hi,
Yes, I try it with olpc, it works.
Signature · 1 line
Bean
Quoted 7 lines · Bean
Quoted 6 lines · Robert Millan
Quoted 4 lines · Bean
* conf/i386-ieee1275.rmk (
pkglib_MODULES): Add chktime.mod. (chktime_mod_SOURCES): New macro. (chktime_mod_CFLAGS): Likewise. (chktime_mod_LDFLAGS): Likewise.
Quoted 5 lines
Quoted 1 line
Uhm I'm not sure those have a PC-compatible CMOS ...
Hi,
Yes, I try it with olpc, it works.
Hi,
I have seperated the commands as nyu suggests in the IRC.
1. date [MMDDhhmm[[CC]YY][.ss]]
Set/Display current datetime, to set date, The format is the same as the date command, you can also use - or : to seperate the numbers. For example:
date 0902
Sep, 2.
date 10-05-13-15
Oct 5, 13:15
2. crontab min hour day_of_month month day_of_week
It's the same as the previous checktime command, except that it doesn't display the current date when no parameter is provided.
2008-08-07 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise. (date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise. (crontab_mod_CFLAGS): Likewise. (crontab_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise.
(crontab_mod_CFLAGS): Likewise.
(crontab_mod_LDFLAGS): Likewise.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise.
(crontab_mod_CFLAGS): Likewise.
(crontab_mod_LDFLAGS): Likewise.
* conf/i386-efi.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise. (date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise. (crontab_mod_CFLAGS): Likewise. (crontab_mod_LDFLAGS): Likewise.
* conf/x86_64-efi.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise.
(crontab_mod_CFLAGS): Likewise.
(crontab_mod_LDFLAGS): Likewise.
* commands/date.c: New file.
* commands/crontab.c: Likewise.
* include/grub/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* kern/generic/get_dow.c: Likewise.
* kern/i386/datetime.c: Likewise.
* kern/efi/datetime.c: Likewise.
Signature · 1 line
Bean
commands/crontab.c new file +127 -0
@@ -0,0 +1,127 @@ +/* crontab.c - command to test current date/time. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/datetime.h> + +static grub_err_t +grub_cmd_crontab (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int dow, i; +int limit[5 ][2 ] = {{0 ,59 }, {0 ,23 }, {1 ,31 }, {1 ,12 }, {0 ,7 }}; +int field[5 ]; + +if (grub_get_datetime (&datetime)) +return grub_errno; + + dow =grub_get_day_of_week (&datetime); + + field[0 ] = datetime.minute; + field[1 ] = datetime.hour; + field[2 ] = datetime.day; + field[3 ] = datetime.month; + field[4 ] = dow; + +for (i =0 ; i <5 ; i++) + { +char *p; +int ok =0 ; + +if (i >= argc) +return 0 ; + + p = args[i]; +while (1 ) + { +int m1, m2, m3, j; + +if (*p =='*' ) + { + m1 = limit[i][0 ]; + m2 = limit[i][1 ]; + p++; + } +else + { + m1 =grub_strtoul (p, &p,0 ); + +if (*p =='-' ) + { + p++; + m2 =grub_strtoul (p, &p,0 ); + } +else + m2 = m1; + } + +if ((m1 < limit[i][0 ]) || (m2 > limit[i][1 ]) || (m1 > m2)) +break ; + +if (*p =='/' ) + { + p++; + m3 =grub_strtoul (p, &p,0 ); + } +else + m3 =1 ; + +for (j = m1; j <= m2; j+= m3) + { +if (j == field[i]) + { + ok =1 ; +break ; + } + } + +if (ok) +break ; + +if (*p ==',' ) + p++; +else +break ; + } + +if (! ok) +break ; + } + +return (i ==5 ) ?0 :grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +GRUB_MOD_INIT (crontab) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("crontab" , grub_cmd_crontab, +GRUB_COMMAND_FLAG_BOTH , +"crontab min hour day_of_month month day_of_week" , +"Command to test current date/time." ,0 ); +} + +GRUB_MOD_FINI (crontab) +{ +grub_unregister_command ("crontab" ); +}
commands/date.c new file +161 -0
161 lines not on this page · raw message
conf/i386-coreboot.rmk +16 -1
@@ -101,7 +101,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod datetime.mod date.mod crontab.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -186,4 +186,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/i386/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +17 -1
@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + datetime.mod date.mod crontab.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +168,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/efi/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +17 -1
@@ -104,7 +104,8 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + date.mod crontab.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
@@ -188,4 +189,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/i386/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +17 -1
@@ -163,7 +163,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ + crontab.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +341,19 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/i386/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/x86_64-efi.rmk +17 -1
@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + datetime.mod date.mod crontab.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +168,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/efi/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/datetime.h new file +57 -0
57 lines not on this page · raw message
include/grub/i386/cmos.h new file +74 -0
74 lines not on this page · raw message
kern/efi/datetime.c new file +87 -0
87 lines not on this page · raw message
kern/generic/get_dow.c new file +32 -0
@@ -0,0 +1,32 @@ +/* get_dow - Calculate the day of week. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/datetime.h> + +int +grub_get_day_of_week (struct grub_datetime *datetime) +{ +int a, y, m; + + a = (14 - datetime->month) /12 ; + y = datetime->year - a; + m = datetime->month +12 * a -2 ; + +return (datetime->day + y + y /4 - y /100 + y /400 + (31 * m /12 )) %7 ; +}
kern/i386/datetime.c new file +175 -0
175 lines not on this page · raw message
I just have a couple of suggestions:
Quoted 7 lines · On Fri, 8 Aug 2008 01:52:07 +0800 Bean <[email protected]> wrote:
On Thu, Aug 7, 2008 at 7:19 PM, Bean <[email protected]> wrote:
1. date [MMDDhhmm[[CC]YY][.ss]]Set/Display current datetime, to set date, The format is the same as the date command, you can also use - or : to seperate the numbers. For example:
Quoted 5 lines
date 0902
Sep, 2.date 10-05-13-15
Oct 5, 13:15
I know the reason for using that format is to be compatible with the Unix 'date' command, but I find it impossible to remember the arcane format it accepts. Do you think it would be more straightforward to accept the ISO standard date format (ISO 8601). For instance:
date 2008-10-05T13:15
(5 October 2008)
or, as syntactic sugar, let each argument be either a time or date:
date 2008-10-05 13:15
Quoted 1 line
2. crontab min hour
day_of_monthmonthday_of_week
This really doesn't allow you to edit a crontab, does it? If not, is there a more appropriate name we could use instead of 'crontab'? Perhaps 'testdate' or something?
Regards,
Colin
Quoted 15 lines · Colin D Bennett
I just have a couple of suggestions:
Quoted 10 lines · On Fri, 8 Aug 2008 01:52:07 +0800 Bean <[email protected]> wrote:
On Thu, Aug 7, 2008 at 7:19 PM, Bean <[email protected]> wrote:
1. date [MMDDhhmm[[CC]YY][.ss]]Set/Display current datetime, to set date, The format is the same as the date command, you can also use - or : to seperate the numbers. For example:
date 0902
Sep, 2.
Quoted 6 lines
Quoted 2 lines
date 10-05-13-15
Oct 5, 13:15I know the reason for using that format is to be compatible with the Unix 'date' command, but I find it impossible to remember the arcane format it accepts.
We could have its --help include this "[MMDDhhmm[[CC]YY][.ss]]" boilerplate, like with gnu date.
IMHO it's an advantage that the input for changing the date is defined simple instead of accepting lots of different layouts. This means less code size, less complexity and also makes the commands more usable in scripts and such.
Quoted 5 lines
Quoted 1 line
2. crontab min hour
day_of_monthmonthday_of_weekThis really doesn't allow you to edit a crontab, does it? If not, is there a more appropriate name we could use instead of 'crontab'? Perhaps 'testdate' or something?
I think it's good that it mentions crontab, since it basicaly works with that format, but I agree that it isn't consistent with the crontab command.
How about something that contains 'crontab' but isn't 'crontab'? Like 'test_crontab', 'crontab_check' or something like this?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 23 lines · Robert Millan
Quoted 15 lines · Colin D Bennett
I just have a couple of suggestions:
Quoted 10 lines · On Fri, 8 Aug 2008 01:52:07 +0800 Bean <[email protected]> wrote:
On Thu, Aug 7, 2008 at 7:19 PM, Bean <[email protected]> wrote:
1. date [MMDDhhmm[[CC]YY][.ss]]Set/Display current datetime, to set date, The format is the same as the date command, you can also use - or : to seperate the numbers. For example:
date 0902
Sep, 2.Quoted 6 lines
Quoted 2 lines
date 10-05-13-15
Oct 5, 13:15I know the reason for using that format is to be compatible with the Unix 'date' command, but I find it impossible to remember the arcane format it accepts.
Quoted 8 lines
We could have its --help include this "[MMDDhhmm[[CC]YY][.ss]]" boilerplate, like with gnu date.
IMHO it's an advantage that the input for changing the date is defined simple instead of accepting lots of different layouts. This means less code size, less complexity and also makes the commands more usable in scripts and such.
I agree with Colin the datetime representation should be more intuitive, but we should stick to one layout. I use the following format now:
date [[year-]month-day] [hour:minute[:second]]
date is separated by -' , and time :', year and second part can be omitted.
Quoted 11 lines
Quoted 5 lines
Quoted 1 line
2. crontab min hour
day_of_monthmonthday_of_weekThis really doesn't allow you to edit a crontab, does it? If not, is there a more appropriate name we could use instead of 'crontab'? Perhaps 'testdate' or something?
I think it's good that it mentions crontab, since it basicaly works with that format, but I agree that it isn't consistent with the crontab command.
How about something that contains 'crontab' but isn't 'crontab'? Like '
test_crontab', 'crontab_check' or something like this?
test_crontab looks good to me.
This is the new patch, if no one objects, I'd commit it soon.
2008-08-09 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise. (date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise. (crontab_mod_CFLAGS): Likewise. (crontab_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise.
(crontab_mod_CFLAGS): Likewise.
(crontab_mod_LDFLAGS): Likewise.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise.
(crontab_mod_CFLAGS): Likewise.
(crontab_mod_LDFLAGS): Likewise.
* conf/i386-efi.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise. (date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise. (crontab_mod_CFLAGS): Likewise. (crontab_mod_LDFLAGS): Likewise.
* conf/x86_64-efi.rmk (pkglib_MODULES): Add datetime.mod, date.mod and crontab.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(crontab_mod_SOURCES): Likewise.
(crontab_mod_CFLAGS): Likewise.
(crontab_mod_LDFLAGS): Likewise.
* commands/date.c: New file.
* commands/crontab.c: Likewise.
* include/grub/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* kern/generic/get_dow.c: Likewise.
* kern/i386/datetime.c: Likewise.
* kern/efi/datetime.c: Likewise.
Signature · 1 line
Bean
commands/crontab.c new file +127 -0
@@ -0,0 +1,127 @@ +/* crontab.c - command to test current date/time. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/datetime.h> + +static grub_err_t +grub_cmd_test_crontab (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int dow, i; +int limit[5 ][2 ] = {{0 ,59 }, {0 ,23 }, {1 ,31 }, {1 ,12 }, {0 ,7 }}; +int field[5 ]; + +if (grub_get_datetime (&datetime)) +return grub_errno; + + dow =grub_get_day_of_week (&datetime); + + field[0 ] = datetime.minute; + field[1 ] = datetime.hour; + field[2 ] = datetime.day; + field[3 ] = datetime.month; + field[4 ] = dow; + +for (i =0 ; i <5 ; i++) + { +char *p; +int ok =0 ; + +if (i >= argc) +return 0 ; + + p = args[i]; +while (1 ) + { +int m1, m2, m3, j; + +if (*p =='*' ) + { + m1 = limit[i][0 ]; + m2 = limit[i][1 ]; + p++; + } +else + { + m1 =grub_strtoul (p, &p,0 ); + +if (*p =='-' ) + { + p++; + m2 =grub_strtoul (p, &p,0 ); + } +else + m2 = m1; + } + +if ((m1 < limit[i][0 ]) || (m2 > limit[i][1 ]) || (m1 > m2)) +break ; + +if (*p =='/' ) + { + p++; + m3 =grub_strtoul (p, &p,0 ); + } +else + m3 =1 ; + +for (j = m1; j <= m2; j+= m3) + { +if (j == field[i]) + { + ok =1 ; +break ; + } + } + +if (ok) +break ; + +if (*p ==',' ) + p++; +else +break ; + } + +if (! ok) +break ; + } + +return (i ==5 ) ?0 :grub_error (GRUB_ERR_TEST_FAILURE ,"false" ); +} + +GRUB_MOD_INIT (crontab) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("test_crontab" , grub_cmd_test_crontab, +GRUB_COMMAND_FLAG_BOTH , +"test_crontab min hour day_of_month month day_of_week" , +"Command to test current datetime." ,0 ); +} + +GRUB_MOD_FINI (crontab) +{ +grub_unregister_command ("test_crontab" ); +}
commands/date.c new file +125 -0
125 lines not on this page · raw message
conf/i386-coreboot.rmk +16 -1
@@ -101,7 +101,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod datetime.mod date.mod crontab.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -186,4 +186,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/i386/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +17 -1
@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + datetime.mod date.mod crontab.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +168,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/efi/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +17 -1
@@ -104,7 +104,8 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + date.mod crontab.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
@@ -188,4 +189,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/i386/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +17 -1
@@ -163,7 +163,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ + crontab.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +341,19 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/i386/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/x86_64-efi.rmk +17 -1
@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + datetime.mod date.mod crontab.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -169,4 +170,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = kern/efi/datetime.c kern/generic/get_dow.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For crontab.mod +crontab_mod_SOURCES = commands/crontab.c +crontab_mod_CFLAGS = $(COMMON_CFLAGS) +crontab_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/datetime.h new file +57 -0
57 lines not on this page · raw message
include/grub/i386/cmos.h new file +74 -0
74 lines not on this page · raw message
kern/efi/datetime.c new file +87 -0
87 lines not on this page · raw message
kern/generic/get_dow.c new file +32 -0
@@ -0,0 +1,32 @@ +/* get_dow - Calculate the day of week. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/datetime.h> + +int +grub_get_day_of_week (struct grub_datetime *datetime) +{ +int a, y, m; + + a = (14 - datetime->month) /12 ; + y = datetime->year - a; + m = datetime->month +12 * a -2 ; + +return (datetime->day + y + y /4 - y /100 + y /400 + (31 * m /12 )) %7 ; +}
kern/i386/datetime.c new file +175 -0
175 lines not on this page · raw message
Quoted 7 lines · Bean
I agree with Colin the datetime representation should be more intuitive, but we should stick to one layout. I use the following format now:
date [[year-]month-day] [hour:minute[:second]]
date is separated by
-' , and time:', year and second part can be omitted.
I'm also a fan of ISO 8601, which has similarities to that above format
http://en.wikipedia.org/wiki/ISO_8601
(well, we may only want to use a subset of ISO 8601's formats.)
It did remind me since it has optional time zone info, that time zones exist :-) ... does GRUB have any idea what the local timezone is, or will it have to require the time-zone part? What about whether the hardware clock is UTC or local-time?
-Isaac
Quoted 11 lines · Isaac Dupree
Quoted 9 lines · Bean
I agree with Colin the datetime representation should be more intuitive, but we should stick to one layout. I use the following format now:
date [[year-]month-day] [hour:minute[:second]]
date is separated by
-' , and time:', year and second part can be omitted.
Quoted 8 lines
I'm also a fan of ISO 8601, which has similarities to that above format
http://en.wikipedia.org/wiki/ISO_8601
(well, we may only want to use a subset of ISO 8601's formats.)It did remind me since it has optional time zone info, that time zones exist :-) ... does GRUB have any idea what the local timezone is, or will it have to require the time-zone part? What about whether the hardware clock is UTC or local-time?
Hi,
The efi time service have time zone info, but pc cmos don't, although we can assume it's 0. But since pc is the platform for most user, I guess it's not very useful.
Signature · 1 line
Bean
Quoted 6 lines · Bean
Hi,
The efi time service have time zone info, but pc cmos don't, although we can assume it's 0. But since pc is the platform for most user, I guess it's not very useful.
It wouldn't be hard to make update-grub gather time zone information from the host system and put it in a variable in grub.cfg, or something like that.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 10 lines · Robert Millan
Quoted 6 lines · Bean
Hi,
The efi time service have time zone info, but pc cmos don't, although we can assume it's 0. But since pc is the platform for most user, I guess it's not very useful.
It wouldn't be hard to make update-grub gather time zone information from the host system and put it in a variable in grub.cfg, or something like that.
Hi,
Oh right, but the handling of timezone is not trivial, especially when it across date boundary. Perhaps we just ignore it for now.
Signature · 1 line
Bean
Quoted 8 lines · Bean
Quoted 2 lines · Robert Millan
It wouldn't be hard to make update-grub gather time zone information from the host system and put it in a variable in grub.cfg, or something like that.
Hi,
Oh right, but the handling of timezone is not trivial, especially when it across date boundary. Perhaps we just ignore it for now.
also, even if one's computer always stays in the same place, Daylight Savings can change the timezone you're in, while grub.cfg stays the same.
What is it that we're doing when we "ignore" it specifically? Assuming local-time and hardware-clock-time are both UTC? (and therefore if the date specifies a timezone, which is specified numerically, convert the time to UTC before doing anything with it) (The above behavior means that if the hardware-clock is actually local time, one could specify the time without a timezone / with timezone Z, and it will work to set the time, despite the incorrect assumptions.)
-Isaac
Quoted 10 lines · Isaac Dupree
also, even if one's computer always stays in the same place, Daylight Savings can change the timezone you're in, while grub.cfg stays the same.
What is it that we're doing when we "ignore" it specifically? Assuming local-time and hardware-clock-time are both UTC? (and therefore if the date specifies a timezone, which is specified numerically, convert the time to UTC before doing anything with it)
The hwclock time is always the same as UTC; except for some very weird OSes like Microsoft Windows ;-)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 2 lines · Bean
date 10-05-13-15
Oct 5, 13:15
Nice. Btw this will be real fun for translators when we have gettext support ;-)
Quoted 30 lines
commands/date.c new file +30
-0+if (n <0 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid date" ); + +switch (pos) + { +case 0 : +if ((n <1 ) || (n >12 )) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid date" ); + + mask |=GRUB_DATETIME_SET_MONTH ; + datetime.month = n; +break ; + +case 1 : +if ((n <1 ) || (n >31 )) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid date" ); + + mask |=GRUB_DATETIME_SET_DAY ; + datetime.day = n; +break ; + +case 2 : +if (n >23 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid date" ); + + mask |=GRUB_DATETIME_SET_HOUR ; + datetime.hour = n; +break ; + +case 3 :
commands/date.c line 115
Quoted 10 lines
commands/date.c new file +10
-0+if (n >59 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid date" ); + + mask |=GRUB_DATETIME_SET_MINUTE ; + datetime.minute = n; +break ; + +case 4 : +if (n >99 ) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid date" );
Since those grub_error calls are always the same, I think it'd be a good idea to group them together in a "fail:" section to save space.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Hi,
Quoted 5 lines · Bean
I implement this command for grub4dos some time ago, now it's ported to grub2.
Usage:
checktime min hour
day_of_monthmonthday_of_week
Personally I would prefer it if it worked a bit more GRUB2/bash like. So can you make this variables?
For example:
if ($WEEKDAY = Sunday); then
...
fi
The same can be done for all week number, day number, year, etc, etc.
The advantage of this is that many users are familiar with such syntax and it will give them more control. Furthermore, this is what I intended with the scripting support in the first place. So can you please follow such scheme?
--
Marco
Quoted 19 lines · Marco Gerards
Hi,
Quoted 5 lines · Bean
I implement this command for grub4dos some time ago, now it's ported to grub2.
Usage:
checktime min hour
day_of_monthmonthday_of_weekPersonally I would prefer it if it worked a bit more GRUB2/bash like. So can you make this variables?
For example:
if ($WEEKDAY = Sunday); then
...
fi
Quoted 6 lines
The same can be done for all week number, day number, year, etc, etc.
The advantage of this is that many users are familiar with such syntax and it will give them more control. Furthermore, this is what I intended with the scripting support in the first place. So can you please follow such scheme?
Hi,
As suggested by marco, this patch replaces the crontab command with variable hook. Now you can retrive current date/time with variable $YEAR, $MONTH, $DAY, $HOUR, $MINUTE, $SECOND and $WEEKDAY.
2008-08-11 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/i386-efi.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/x86_64-efi.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* commands/date.c: New file.
* commands/datetime.c: Likewise.
* include/grub/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* kern/i386/datetime.c: Likewise.
* kern/efi/datetime.c: Likewise.
Signature · 1 line
Bean
commands/date.c new file +124 -0
@@ -0,0 +1,124 @@ +/* date.c - command to display/set current datetime. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/datetime.h> + +static grub_err_t +grub_cmd_date (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int limit[6 ][2 ] = {{1980 ,2079 }, {1 ,12 }, {1 ,31 }, {0 ,23 }, {0 ,59 }, {0 ,59 }}; +int value[6 ], mask; + +if (argc ==0 ) + { +if (grub_get_datetime (&datetime)) +return grub_errno; + +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n" , + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, +grub_get_weekday_name (&datetime)); + +return 0 ; + } + +grub_memset (&value,0 ,sizeof (value)); + mask =0 ; + +for (; argc; argc--, args++) + { +char *p, c; +int m1, ofs, n, cur_mask; + + p = args[0 ]; + m1 =grub_strtoul (p, &p,10 ); + + c = *p; +if (c =='-' ) + ofs =0 ; +else if (c ==':' ) + ofs =3 ; +else + goto fail; + + value[ofs] = m1; + cur_mask = (1 << ofs); + mask &= ~(cur_mask * (1 +2 +4 )); + +for (n =1 ; (n <3 ) && (*p); n++) + { +if (*p != c) + goto fail; + + value[ofs + n] =grub_strtoul (p +1 , &p,10 ); + cur_mask |= (1 << (ofs + n)); + } + +if (*p) + goto fail; + +if ((ofs ==0 ) && (n ==2 )) + { + value[ofs +2 ] = value[ofs +1 ]; + value[ofs +1 ] = value[ofs]; + ofs++; + cur_mask <<=1 ; + } + +for (; n; n--, ofs++) +if ((value [ofs] < limit[ofs][0 ]) || + (value [ofs] > limit[ofs][1 ])) + goto fail; + + mask |= cur_mask; + } + + datetime.year = value[0 ]; + datetime.month = value[1 ]; + datetime.day = value[2 ]; + datetime.hour = value[3 ]; + datetime.minute = value[4 ]; + datetime.second = value[5 ]; + +return grub_set_datetime (&datetime, mask); + +fail: +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid datetime" ); +} + +GRUB_MOD_INIT (date) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("date" , grub_cmd_date, +GRUB_COMMAND_FLAG_BOTH , +"date [[year-]month-day] [hour:minute[:second]]" , +"Command to display/set current datetime." ,0 ); +} + +GRUB_MOD_FINI (date) +{ +grub_unregister_command ("date" ); +}
commands/datetime.c new file +132 -0
132 lines not on this page · raw message
conf/i386-coreboot.rmk +11 -1
@@ -101,7 +101,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod datetime.mod date.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -186,4 +186,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +12 -1
@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + datetime.mod date.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +168,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +12 -1
@@ -104,7 +104,8 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + date.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
@@ -188,4 +189,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +11 -1
@@ -163,7 +163,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +340,14 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/x86_64-efi.rmk +12 -1
@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + datetime.mod date.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -169,4 +170,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
include/grub/datetime.h new file +58 -0
58 lines not on this page · raw message
include/grub/i386/cmos.h new file +74 -0
74 lines not on this page · raw message
kern/efi/datetime.c new file +87 -0
87 lines not on this page · raw message
kern/i386/datetime.c new file +175 -0
175 lines not on this page · raw message
commands/datetime.c line 1
Quoted 4 lines · Bean
commands/datetime.c new file +1
-0@@ -0,0 +1,132 @@ +/* datetime.c - Module to export datetime variables. */
Shouldn't this be somewhere else? (other than commands/)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 67 lines · Bean
Quoted 19 lines · Marco Gerards
Hi,
Quoted 5 lines · Bean
I implement this command for grub4dos some time ago, now it's ported to grub2.
Usage:
checktime min hour
day_of_monthmonthday_of_weekPersonally I would prefer it if it worked a bit more GRUB2/bash like. So can you make this variables?
For example:
if ($WEEKDAY = Sunday); then
...
fiQuoted 6 lines
The same can be done for all week number, day number, year, etc, etc.
The advantage of this is that many users are familiar with such syntax and it will give them more control. Furthermore, this is what I intended with the scripting support in the first place. So can you please follow such scheme?
Hi,
As suggested by marco, this patch replaces the crontab command with variable hook. Now you can retrive current date/time with variable $YEAR, $MONTH, $DAY, $HOUR, $MINUTE, $SECOND and $WEEKDAY.
2008-08-11 Bean <[email protected]>
* conf/i386-pc.rmk (
pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.* conf/i386-coreboot.rmk (
pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.* conf/i386-ieee1275.rmk (
pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.* conf/i386-efi.rmk (
pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
Quoted 7 lines
* conf/x86_64-efi.rmk (
pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
Robert is right, we need an i386.rmk or similar file.
Quoted 3 lines
*
commands/date.c: New file.*
commands/datetime.c: Likewise.
This is not a command. But I do not really know a good place for this module...
Quoted 7 lines
*
include/grub/datetime.h: Likewise.*
include/grub/i386/cmos.h: Likewise.*
kern/i386/datetime.c: Likewise.*
kern/efi/datetime.c: Likewise.
Does this really belong in the kernel? You created lib/ (which I still not might agree with, but ok ;)). But that might be a better place than here.
Quoted 45 lines
Signature · 1 line
Beancommands/date.c new file +36
-0@@ -0,0 +1,124 @@ +/* date.c - command to display/set current datetime. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/datetime.h> + +static grub_err_t +grub_cmd_date (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int limit[6 ][2 ] = {{1980 ,2079 }, {1 ,12 }, {1 ,31 }, {0 ,23 }, {0 ,59 }, {0 ,59 }}; +int value[6 ], mask; + +if (argc ==0 ) + {
commands/date.c line 46
Quoted 10 lines
commands/date.c new file +10
-0+if (grub_get_datetime (&datetime)) +return grub_errno; + +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n" , + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, +grub_get_weekday_name (&datetime)); + +return 0 ; + }
Can you somehow use the argument parser here? This will give us --help for free :-)
Quoted 60 lines
commands/date.c new file +60
-0+grub_memset (&value,0 ,sizeof (value)); + mask =0 ; + +for (; argc; argc--, args++) + { +char *p, c; +int m1, ofs, n, cur_mask; + + p = args[0 ]; + m1 =grub_strtoul (p, &p,10 ); + + c = *p; +if (c =='-' ) + ofs =0 ; +else if (c ==':' ) + ofs =3 ; +else + goto fail; + + value[ofs] = m1; + cur_mask = (1 << ofs); + mask &= ~(cur_mask * (1 +2 +4 )); + +for (n =1 ; (n <3 ) && (*p); n++) + { +if (*p != c) + goto fail; + + value[ofs + n] =grub_strtoul (p +1 , &p,10 ); + cur_mask |= (1 << (ofs + n)); + } + +if (*p) + goto fail; + +if ((ofs ==0 ) && (n ==2 )) + { + value[ofs +2 ] = value[ofs +1 ]; + value[ofs +1 ] = value[ofs]; + ofs++; + cur_mask <<=1 ; + } + +for (; n; n--, ofs++) +if ((value [ofs] < limit[ofs][0 ]) || + (value [ofs] > limit[ofs][1 ])) + goto fail; + + mask |= cur_mask; + } + + datetime.year = value[0 ]; + datetime.month = value[1 ]; + datetime.day = value[2 ]; + datetime.hour = value[3 ]; + datetime.minute = value[4 ]; + datetime.second = value[5 ]; + +return grub_set_datetime (&datetime, mask); +
commands/date.c line 117
Quoted 10 lines
commands/date.c new file +10
-0+fail: +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid datetime" ); +} + +GRUB_MOD_INIT (date) +{ + (void ) mod;/* To stop warning. */ + grub_register_command ("date", grub_cmd_date, + GRUB_COMMAND_FLAG_BOTH, + "date [[year-]month-day] [hour:minute[:second]]",
This help string will not be shown if you do not use the argument parser to generate a --help
Furthermore, I can imagine more arguments should be added in the future.
Quoted 34 lines
commands/date.c new file +7
-0+ "Command to display/set current datetime.", 0); +} + +GRUB_MOD_FINI (date) +{ +grub_unregister_command ("date" ); +}commands/datetime.c new file +21
-0@@ -0,0 +1,132 @@ +/* datetime.c - Module to export datetime variables. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/types.h> +#include <grub/dl.h>
commands/datetime.c line 31
Quoted 10 lines
commands/datetime.c new file +10
-0+#include <grub/env.h> +#include <grub/misc.h> +#include <grub/normal.h> +#include <grub/datetime.h> + +static char *grub_weekday_names[] = +{ +"Sunday" , +"Monday" , +"Tueday" ,
Tuesday
commands/datetime.c line 33
Quoted 2 lines
commands/datetime.c new file +2
-0+"Wednesday" , + "Thusday",
Thursday
commands/datetime.c line 36
Quoted 3 lines
commands/datetime.c new file +3
-0+"Friday" , + "Saturday", +};
Please notice that, depending on the country, the week either starts on sunday or monday. Altough I am quite clueless about the specifics ;)
Quoted 11 lines
commands/datetime.c new file +11
-0+static char *grub_datetime_names[] = +{ +"YEAR" , +"MONTH" , +"DAY" , +"HOUR" , +"MINUTE" , +"SECOND" , +"WEEKDAY" , +}; +
commands/datetime.c line 58
Quoted 10 lines
commands/datetime.c new file +10
-0+int +grub_get_weekday (struct grub_datetime *datetime) +{ +int a, y, m; + + a = (14 - datetime->month) /12 ; + y = datetime->year - a; + m = datetime->month +12 * a -2 ; + +return (datetime->day + y + y /4 - y /100 + y /400 + (31 * m /12 )) %7 ;
Wow ;-)
Does this deal with leap years?
commands/datetime.c line 65
Quoted 7 lines
commands/datetime.c new file +7
-0+} + +char * +grub_get_weekday_name (struct grub_datetime *datetime) +{ +return grub_weekday_names[grub_get_weekday (datetime)]; +}
Shoudn't this be static? Or is this intentional?
Quoted 55 lines
commands/datetime.c new file +55
-0+static char * +grub_read_hook_datetime (struct grub_env_var *var, +const char *val __attribute__ ((unused))) +{ +struct grub_datetime datetime; +static char buf[6 ]; + + buf[0 ] =0 ; +if (!grub_get_datetime (&datetime)) + { +int i; + +for (i =0 ; i <7 ; i++) +if (!grub_strcmp (var->name, grub_datetime_names[i])) + { +int n; + +switch (i) + { +case 0 : + n = datetime.year; +break ; +case 1 : + n = datetime.month; +break ; +case 2 : + n = datetime.day; +break ; +case 3 : + n = datetime.hour; +break ; +case 4 : + n = datetime.minute; +break ; +case 5 : + n = datetime.second; +break ; +default : +return grub_get_weekday_name (&datetime); + } + +grub_sprintf (buf,"%d" , n); +break ; + } + } + +return buf; +} + +GRUB_MOD_INIT (datetime) +{ + (void )mod;/* To stop warning. */ +int i; + +for (i =0 ; i <7 ; i++)
commands/datetime.c line 131
Quoted 10 lines
commands/datetime.c new file +10
-0+grub_register_variable_hook (grub_datetime_names[i], + grub_read_hook_datetime,0 ); +} + +GRUB_MOD_FINI (datetime) +{ +int i; + +for (i =0 ; i <7 ; i++) +grub_register_variable_hook (grub_datetime_names[i],0 ,0 );
Perhaps it is even wise to unset the variables? As the contents are no longer valid.
Quoted 278 lines
commands/datetime.c new file +1
-0+}conf/i386-coreboot.rmk +11
-1@@ -101,7 +101,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod datetime.mod date.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c@@ -186,4 +186,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mkconf/i386-efi.rmk +12
-1@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + datetime.mod date.mod # For kernel.mod. kernel_mod_EXPORTS = no@@ -167,4 +168,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mkconf/i386-ieee1275.rmk +12
-1@@ -104,7 +104,8 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + date.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \@@ -188,4 +189,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mkconf/i386-pc.rmk +11
-1@@ -163,7 +163,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c@@ -340,4 +340,14 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mkconf/x86_64-efi.rmk +12
-1@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + datetime.mod date.mod # For kernel.mod. kernel_mod_EXPORTS = no@@ -169,4 +170,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = commands/datetime.c kern/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mkinclude/grub/datetime.h new file +58
-0@@ -0,0 +1,58 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef KERNEL_DATETIME_HEADER +#define KERNEL_DATETIME_HEADER 1 + +#include <grub/types.h> +#include <grub/err.h> + +#define GRUB_DATETIME_SET_YEAR 1 +#define GRUB_DATETIME_SET_MONTH 2 +#define GRUB_DATETIME_SET_DAY 4 +#define GRUB_DATETIME_SET_DATE (GRUB_DATETIME_SET_YEAR | \ + GRUB_DATETIME_SET_MONTH | \ + GRUB_DATETIME_SET_DAY) + +#define GRUB_DATETIME_SET_HOUR 8 +#define GRUB_DATETIME_SET_MINUTE 16 +#define GRUB_DATETIME_SET_SECOND 32 +#define GRUB_DATETIME_SET_TIME (GRUB_DATETIME_SET_HOUR | \ + GRUB_DATETIME_SET_MINUTE | \ + GRUB_DATETIME_SET_SECOND) + +struct grub_datetime +{ +grub_uint16_t year; +grub_uint8_t month; +grub_uint8_t day; +grub_uint8_t hour; +grub_uint8_t minute; +grub_uint8_t second; +}; + +/* Return date and time. */ +grub_err_t grub_get_datetime (struct grub_datetime *datetime); + +/* Set date and time. */ +grub_err_t grub_set_datetime (struct grub_datetime *datetime,int mask); + +int grub_get_weekday (struct grub_datetime *datetime); +char *grub_get_weekday_name (struct grub_datetime *datetime); + +#endif /* ! KERNEL_DATETIME_HEADER */ include/grub/i386/cmos.h new file +64
-0@@ -0,0 +1,74 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_CPU_CMOS_H +#define GRUB_CPU_CMOS_H 1 + +#include <grub/types.h> +#include <grub/i386/io.h> + +#define GRUB_CMOS_ADDR_REG 0x70 +#define GRUB_CMOS_DATA_REG 0x71 + +#define GRUB_CMOS_INDEX_SECOND 0 +#define GRUB_CMOS_INDEX_SECOND_ALARM 1 +#define GRUB_CMOS_INDEX_MINUTE 2 +#define GRUB_CMOS_INDEX_MINUTE_ALARM 3 +#define GRUB_CMOS_INDEX_HOUR 4 +#define GRUB_CMOS_INDEX_HOUR_ALARM 5 +#define GRUB_CMOS_INDEX_DAY_OF_WEEK 6 +#define GRUB_CMOS_INDEX_DAY_OF_MONTH 7 +#define GRUB_CMOS_INDEX_MONTH 8 +#define GRUB_CMOS_INDEX_YEAR 9 + +#define GRUB_CMOS_INDEX_STATUS_A 0xA +#define GRUB_CMOS_INDEX_STATUS_B 0xB +#define GRUB_CMOS_INDEX_STATUS_C 0xC +#define GRUB_CMOS_INDEX_STATUS_D 0xD + +#define GRUB_CMOS_STATUS_B_DAYLIGHT 1 +#define GRUB_CMOS_STATUS_B_24HOUR 2 +#define GRUB_CMOS_STATUS_B_BINARY 4 + +static inline grub_uint8_t +grub_bcd_to_num (grub_uint8_t a) +{ +return ((a >>4 ) *10 + (a &0xF )); +} + +static inline grub_uint8_t +grub_num_to_bcd (grub_uint8_t a) +{ +return (((a /10 ) <<4 ) + (a %10 )); +} + +static inline grub_uint8_t +grub_cmos_read (grub_uint8_t index) +{ +grub_outb (index,GRUB_CMOS_ADDR_REG ); +return grub_inb (GRUB_CMOS_DATA_REG );
include/grub/i386/cmos.h line 74
Quoted 10 lines
include/grub/i386/cmos.h new file +10
-0+} + +static inline void +grub_cmos_write (grub_uint8_t index,grub_uint8_t value) +{ +grub_outb (index,GRUB_CMOS_ADDR_REG ); +grub_outb (value,GRUB_CMOS_DATA_REG ); +} + +#endif /* GRUB_CPU_PCI_H */
PCI? :-)
Quoted 32 lines
kern/efi/datetime.c new file +26
-0@@ -0,0 +1,87 @@ +/* kern/efi/datetime.c - efi datetime function. +* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/types.h> +#include <grub/symbol.h> +#include <grub/efi/api.h> +#include <grub/efi/efi.h> +#include <grub/datetime.h> + +grub_err_t
kern/efi/datetime.c line 36
Quoted 10 lines
kern/efi/datetime.c new file +10
-0+grub_get_datetime (struct grub_datetime *datetime) +{ +grub_efi_status_t status; +struct grub_efi_time efi_time; + + status =efi_call_2 (grub_efi_system_table->runtime_services->get_time, + &efi_time,0 ); + +if (status) +return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,"can\'t get datetime" );
You implemented the function here!
Quoted 8 lines
kern/efi/datetime.c new file +8
-0+else + { + datetime->year = efi_time.year; + datetime->month = efi_time.month; + datetime->day = efi_time.day; + datetime->hour = efi_time.hour; + datetime->minute = efi_time.minute; + datetime->second = efi_time.second;
kern/efi/datetime.c line 54
Quoted 10 lines
kern/efi/datetime.c new file +10
-0+ } + +return 0 ; +} + +grub_err_t +grub_set_datetime (struct grub_datetime *datetime,int mask) +{ +grub_efi_status_t status; +struct grub_efi_time efi_time;
Why do you use a mask? Isn't it better to let the caller to deal with this by calling grub_get_datetime? Perhaps I do not see the results of dealing with this either way.
Quoted 217 lines
kern/efi/datetime.c new file +32
-0+ status =efi_call_2 (grub_efi_system_table->runtime_services->get_time, + &efi_time,0 ); + +if (status) +return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,"can\'t get datetime" ); + +if (mask &GRUB_DATETIME_SET_YEAR ) + efi_time.year = datetime->year; + +if (mask &GRUB_DATETIME_SET_MONTH ) + efi_time.month = datetime->month; + +if (mask &GRUB_DATETIME_SET_DAY ) + efi_time.day = datetime->day; + +if (mask &GRUB_DATETIME_SET_HOUR ) + efi_time.hour = datetime->hour; + +if (mask &GRUB_DATETIME_SET_MINUTE ) + efi_time.minute = datetime->minute; + +if (mask &GRUB_DATETIME_SET_SECOND ) + efi_time.second = datetime->second; + + status =efi_call_1 (grub_efi_system_table->runtime_services->set_time, + &efi_time); + +if (status) +return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,"can\'t set datetime" ); + +return 0 ; +}kern/i386/datetime.c new file +175
-0@@ -0,0 +1,175 @@ +/* kern/i386/datetime.c - x86 CMOS datetime function. +* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/datetime.h> +#include <grub/i386/cmos.h> + +grub_err_t +grub_get_datetime (struct grub_datetime *datetime) +{ +int is_bcd, is_12hour; +grub_uint8_t value, flag; + + flag =grub_cmos_read (GRUB_CMOS_INDEX_STATUS_B ); + + is_bcd = ! (flag &GRUB_CMOS_STATUS_B_BINARY ); + + value =grub_cmos_read (GRUB_CMOS_INDEX_YEAR ); +if (is_bcd) + value =grub_bcd_to_num (value); + + datetime->year = value; + datetime->year += (value <80 ) ?2000 :1900 ; + + value =grub_cmos_read (GRUB_CMOS_INDEX_MONTH ); +if (is_bcd) + value =grub_bcd_to_num (value); + + datetime->month = value; + + value =grub_cmos_read (GRUB_CMOS_INDEX_DAY_OF_MONTH ); +if (is_bcd) + value =grub_bcd_to_num (value); + + datetime->day = value; + + is_12hour = ! (flag &GRUB_CMOS_STATUS_B_24HOUR ); + + value =grub_cmos_read (GRUB_CMOS_INDEX_HOUR ); +if (is_12hour) + { + is_12hour = (value &0x80 ); + + value &=0x7F ; + value--; + } + +if (is_bcd) + value =grub_bcd_to_num (value); + +if (is_12hour) + value +=12 ; + + datetime->hour = value; + + value =grub_cmos_read (GRUB_CMOS_INDEX_MINUTE ); +if (is_bcd) + value =grub_bcd_to_num (value); + + datetime->minute = value; + + value =grub_cmos_read (GRUB_CMOS_INDEX_SECOND ); +if (is_bcd) + value =grub_bcd_to_num (value); + + datetime->second = value; + +return 0 ; +} + +grub_err_t +grub_set_datetime (struct grub_datetime *datetime,int mask) +{ +int is_bcd; +grub_uint8_t value, flag; + + flag =grub_cmos_read (GRUB_CMOS_INDEX_STATUS_B ); + + is_bcd = ! (flag &GRUB_CMOS_STATUS_B_BINARY ); + +if (mask &GRUB_DATETIME_SET_YEAR ) + { + value = ((datetime->year >=2000 ) ? datetime->year -2000 : + datetime->year -1900 ); + +if (is_bcd) + value =grub_num_to_bcd (value); + +grub_cmos_write (GRUB_CMOS_INDEX_YEAR , value); + } + +if (mask &GRUB_DATETIME_SET_MONTH ) + { + value = datetime->month; + +if (is_bcd) + value =grub_num_to_bcd (value); + +grub_cmos_write (GRUB_CMOS_INDEX_MONTH , value); + } + +if (mask &GRUB_DATETIME_SET_DAY ) + { + value = datetime->day; + +if (is_bcd) + value =grub_num_to_bcd (value); + +grub_cmos_write (GRUB_CMOS_INDEX_DAY_OF_MONTH , value); + } + +if (mask &GRUB_DATETIME_SET_HOUR ) + { +int is_12hour; + + value = datetime->hour; + + is_12hour = (! (flag &GRUB_CMOS_STATUS_B_24HOUR )); + +if (is_12hour) + { + value++; + +if (value >12 ) + value -=12 ; +else + is_12hour =0 ; + } + +if (is_bcd) + value =grub_num_to_bcd (value); + +if (is_12hour) + value |=0x80 ; + +grub_cmos_write (GRUB_CMOS_INDEX_HOUR , value); + } + +if (mask &GRUB_DATETIME_SET_MINUTE ) + { + value = datetime->minute; + +if (is_bcd) + value =grub_num_to_bcd (value); + +grub_cmos_write (GRUB_CMOS_INDEX_MINUTE , value); + } + +if (mask &GRUB_DATETIME_SET_SECOND ) + { + value = datetime->second; + +if (is_bcd) + value =grub_num_to_bcd (value); + +grub_cmos_write (GRUB_CMOS_INDEX_SECOND , value); + } + +return 0 ; +}_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 7 lines · Marco Gerards
Quoted 4 lines
*
commands/date.c: New file.*
commands/datetime.c: Likewise.This is not a command. But I do not really know a good place for this module...
How about the /hook directory ?
Quoted 5 lines
Quoted 5 lines
*
include/grub/datetime.h: Likewise.*
include/grub/i386/cmos.h: Likewise.
Quoted 7 lines
Quoted 3 lines
*
kern/i386/datetime.c: Likewise.*
kern/efi/datetime.c: Likewise.Does this really belong in the kernel? You created
lib/(which I still not might agree with, but ok ;)). But that might be a better place than here.
Ok.
Quoted 10 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ "Sunday", + "Monday", + "Tueday",Tuesday
Review
Quoted 2 lines
(quoted diff) +2
-0+ "Wednesday", + "Thusday",Thursday
Oh, fixed.
Quoted 13 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+int +grub_get_weekday (struct grub_datetime *datetime) +{ + int a, y, m; + + a = (14 - datetime->month) / 12; + y = datetime->year - a; + m = datetime->month + 12 * a - 2; + + return (datetime->day + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7;Wow ;-)
Quoted 1 line
Does this deal with leap years?
It should be able to handle leap years.
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+GRUB_MOD_FINI(datetime) +{ + int i; + + for (i = 0; i < 7; i++) + grub_register_variable_hook (grub_datetime_names[i], 0, 0);Perhaps it is even wise to unset the variables? As the contents are no longer valid.
Right, fixed.
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+grub_err_t +grub_get_datetime (struct grub_datetime *datetime) +{ + grub_efi_status_t status; + struct grub_efi_time efi_time;
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + status = efi_call_2 (grub_efi_system_table->runtime_services->get_time, + &efi_time, 0); + + if (status) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "can\'t get datetime");You implemented the function here!
Ok, change the error code.
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+grub_err_t +grub_set_datetime (struct grub_datetime *datetime, int mask) +{ + grub_efi_status_t status; + struct grub_efi_time efi_time;Why do you use a mask? Isn't it better to let the caller to deal with this by calling
grub_get_datetime? Perhaps I do not see the results of dealing with this either way.
Ok then.
2008-08-12 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/i386-efi.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* conf/x86_64-efi.rmk (pkglib_MODULES): Add datetime.mod and date.mod. (datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
* commands/date.c: New file.
* hook/datetime.c: Likewise.
* include/grub/lib/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* lib/i386/datetime.c: Likewise.
* lib/efi/datetime.c: Likewise.
Signature · 1 line
Bean
commands/date.c new file +145 -0
@@ -0,0 +1,145 @@ +/* date.c - command to display/set current datetime. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/lib/datetime.h> + +#define GRUB_DATETIME_SET_YEAR 1 +#define GRUB_DATETIME_SET_MONTH 2 +#define GRUB_DATETIME_SET_DAY 4 +#define GRUB_DATETIME_SET_HOUR 8 +#define GRUB_DATETIME_SET_MINUTE 16 +#define GRUB_DATETIME_SET_SECOND 32 + +static grub_err_t +grub_cmd_date (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int limit[6 ][2 ] = {{1980 ,2079 }, {1 ,12 }, {1 ,31 }, {0 ,23 }, {0 ,59 }, {0 ,59 }}; +int value[6 ], mask; + +if (argc ==0 ) + { +if (grub_get_datetime (&datetime)) +return grub_errno; + +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n" , + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, +grub_get_weekday_name (&datetime)); + +return 0 ; + } + +grub_memset (&value,0 ,sizeof (value)); + mask =0 ; + +for (; argc; argc--, args++) + { +char *p, c; +int m1, ofs, n, cur_mask; + + p = args[0 ]; + m1 =grub_strtoul (p, &p,10 ); + + c = *p; +if (c =='-' ) + ofs =0 ; +else if (c ==':' ) + ofs =3 ; +else + goto fail; + + value[ofs] = m1; + cur_mask = (1 << ofs); + mask &= ~(cur_mask * (1 +2 +4 )); + +for (n =1 ; (n <3 ) && (*p); n++) + { +if (*p != c) + goto fail; + + value[ofs + n] =grub_strtoul (p +1 , &p,10 ); + cur_mask |= (1 << (ofs + n)); + } + +if (*p) + goto fail; + +if ((ofs ==0 ) && (n ==2 )) + { + value[ofs +2 ] = value[ofs +1 ]; + value[ofs +1 ] = value[ofs]; + ofs++; + cur_mask <<=1 ; + } + +for (; n; n--, ofs++) +if ((value [ofs] < limit[ofs][0 ]) || + (value [ofs] > limit[ofs][1 ])) + goto fail; + + mask |= cur_mask; + } + +if (grub_get_datetime (&datetime)) +return grub_errno; + +if (mask &GRUB_DATETIME_SET_YEAR ) + datetime.year = value[0 ]; + +if (mask &GRUB_DATETIME_SET_MONTH ) + datetime.month = value[1 ]; + +if (mask &GRUB_DATETIME_SET_DAY ) + datetime.day = value[2 ]; + +if (mask &GRUB_DATETIME_SET_HOUR ) + datetime.hour = value[3 ]; + +if (mask &GRUB_DATETIME_SET_MINUTE ) + datetime.minute = value[4 ]; + +if (mask &GRUB_DATETIME_SET_SECOND ) + datetime.second = value[5 ]; + +return grub_set_datetime (&datetime); + +fail: +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid datetime" ); +} + +GRUB_MOD_INIT (date) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("date" , grub_cmd_date, +GRUB_COMMAND_FLAG_BOTH , +"date [[year-]month-day] [hour:minute[:second]]" , +"Command to display/set current datetime." ,0 ); +} + +GRUB_MOD_FINI (date) +{ +grub_unregister_command ("date" ); +}
conf/i386-coreboot.rmk +11 -1
@@ -102,7 +102,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod datetime.mod date.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -187,4 +187,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = hook/datetime.c lib/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +12 -1
@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + datetime.mod date.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +168,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = hook/datetime.c lib/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +12 -1
@@ -104,7 +104,8 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + date.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
@@ -188,4 +189,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = hook/datetime.c lib/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +11 -1
@@ -163,7 +163,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +340,14 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = hook/datetime.c lib/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/x86_64-efi.rmk +12 -1
@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + datetime.mod date.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -169,4 +170,14 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = hook/datetime.c lib/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
hook/datetime.c new file +135 -0
135 lines not on this page · raw message
include/grub/i386/cmos.h new file +74 -0
74 lines not on this page · raw message
include/grub/lib/datetime.h new file +44 -0
44 lines not on this page · raw message
lib/efi/datetime.c new file +79 -0
79 lines not on this page · raw message
lib/i386/datetime.c new file +155 -0
155 lines not on this page · raw message
Quoted 10 lines · Bean
Quoted 7 lines · Marco Gerards
Quoted 4 lines
*
commands/date.c: New file.*
commands/datetime.c: Likewise.This is not a command. But I do not really know a good place for this module...
How about the /hook directory ?
Perhaps? Do you have suggestions what we can place there, besides this?
Otherwise the patch looks fine to me :-)
--
Marco
Quoted 11 lines · Marco Gerards
Quoted 9 lines · Bean
Quoted 7 lines · Marco Gerards
Quoted 4 lines
*
commands/date.c: New file.*
commands/datetime.c: Likewise.This is not a command. But I do not really know a good place for this module...
Quoted 6 lines
Quoted 1 line
How about the /hook directory ?
Perhaps? Do you have suggestions what we can place there, besides this?
Otherwise the patch looks fine to me :-)
Hi,
Oh, please take a look at my other post "Idea: implementation of the password command", it sugguest to implement password with hooks, for example, reading $GET_PASSWORD would prompt the user for password and return the encrypted form.
BTW, I'm thinking perhaps it's better to move the hook function from datetime.mod to datehook.mod, and datetime.mod only contain grub_get_datetime, grub_set_datetime, grub_get_weekday and grub_get_weekday_name. Module like date.mod only need the datetime functions, it's a little wired to install the hook as a side effect.
Signature · 1 line
Bean
Quoted 26 lines · Bean
Quoted 11 lines · Marco Gerards
Quoted 9 lines · Bean
Quoted 7 lines · Marco Gerards
Quoted 4 lines
*
commands/date.c: New file.*
commands/datetime.c: Likewise.This is not a command. But I do not really know a good place for this module...
Quoted 6 lines
Quoted 1 line
How about the /hook directory ?
Perhaps? Do you have suggestions what we can place there, besides this?
Otherwise the patch looks fine to me :-)
Hi,
Oh, please take a look at my other post "Idea: implementation of the password command", it sugguest to implement password with hooks, for example, reading $GET_PASSWORD would prompt the user for password and return the encrypted form.
Quoted 5 lines
BTW, I'm thinking perhaps it's better to move the hook function from datetime.mod to datehook.mod, and datetime.mod only contain
grub_get_datetime,grub_set_datetime,grub_get_weekdayandgrub_get_weekday_name. Module like date.mod only need the datetime functions, it's a little wired to install the hook as a side effect.
Hi,
This is the new patch. BTW. when testing datehook.mod, I found a serious bug in grub_env_insert:
static voidgrub_env_insert (struct grub_env_context *context,
struct grub_env_var *var)
{
int idx = grub_env_hashval (var->name);
/* Insert the variable into the hashtable. */
var->prevp = &context->vars[idx];
var->next = context->vars[idx];
if (var->next)
- var->next->prevp = &var;
+ var->next->prevp = &(var->next);
context->vars[idx] = var;
}
prevp should point to the variable that points to the next item, so it should be &(var->next) instead of &var. To see the effect, you can insmod datehook then rmmod datehook. The old code would either hang, or you can see some of the datetime variable, like $YEAR, still present in the variable list. If you try to unset it, it will cause allocate magic broken error.
2008-08-11 Bean <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add datetime.mod, date.mod and datehook.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise. (date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise. (datehook_mod_SOURCES): Likewise. (datehook_mod_CFLAGS): Likewise. (datehook_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk (pkglib_MODULES): Add datetime.mod, date.mod and datehook.mod.
(datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(datehook_mod_SOURCES): Likewise.
(datehook_mod_CFLAGS): Likewise.
(datehook_mod_LDFLAGS): Likewise.
* conf/i386-ieee1275.rmk (pkglib_MODULES): Add datetime.mod, date.mod and datehook.mod.
(datetime_mod_SOURCES): New macro.
(datetime_mod_CFLAGS): Likewise.
(datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(datehook_mod_SOURCES): Likewise.
(datehook_mod_CFLAGS): Likewise.
(datehook_mod_LDFLAGS): Likewise.
* conf/i386-efi.rmk (pkglib_MODULES): Add datetime.mod, date.mod and datehook.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise. (date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise. (datehook_mod_SOURCES): Likewise. (datehook_mod_CFLAGS): Likewise. (datehook_mod_LDFLAGS): Likewise.
* conf/x86_64-efi.rmk (pkglib_MODULES): Add datetime.mod, date.mod and datehook.mod.
(datetime_mod_SOURCES): New macro. (datetime_mod_CFLAGS): Likewise. (datetime_mod_LDFLAGS): Likewise.
(date_mod_SOURCES): Likewise.
(date_mod_CFLAGS): Likewise.
(date_mod_LDFLAGS): Likewise.
(datehook_mod_SOURCES): Likewise. (datehook_mod_CFLAGS): Likewise. (datehook_mod_LDFLAGS): Likewise.
* kern/env.c (grub_env_insert): Fix a bug in prevp pointer.
* commands/date.c: New file.
* hook/datetime.c: Likewise.
* include/grub/lib/datetime.h: Likewise.
* include/grub/i386/cmos.h: Likewise.
* lib/datetime.c: Likewise.
* lib/i386/datetime.c: Likewise.
* lib/efi/datetime.c: Likewise.
Signature · 1 line
Bean
commands/date.c new file +145 -0
@@ -0,0 +1,145 @@ +/* date.c - command to display/set current datetime. */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2008 Free Software Foundation, Inc. +* +* GRUB 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 3 of the License, or +* (at your option) any later version. +* +* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <grub/normal.h> +#include <grub/dl.h> +#include <grub/arg.h> +#include <grub/err.h> +#include <grub/misc.h> +#include <grub/lib/datetime.h> + +#define GRUB_DATETIME_SET_YEAR 1 +#define GRUB_DATETIME_SET_MONTH 2 +#define GRUB_DATETIME_SET_DAY 4 +#define GRUB_DATETIME_SET_HOUR 8 +#define GRUB_DATETIME_SET_MINUTE 16 +#define GRUB_DATETIME_SET_SECOND 32 + +static grub_err_t +grub_cmd_date (struct grub_arg_list *state __attribute__ ((unused)), +int argc,char **args) +{ +struct grub_datetime datetime; +int limit[6 ][2 ] = {{1980 ,2079 }, {1 ,12 }, {1 ,31 }, {0 ,23 }, {0 ,59 }, {0 ,59 }}; +int value[6 ], mask; + +if (argc ==0 ) + { +if (grub_get_datetime (&datetime)) +return grub_errno; + +grub_printf ("%d-%02d-%02d %02d:%02d:%02d %s\n" , + datetime.year, datetime.month, datetime.day, + datetime.hour, datetime.minute, datetime.second, +grub_get_weekday_name (&datetime)); + +return 0 ; + } + +grub_memset (&value,0 ,sizeof (value)); + mask =0 ; + +for (; argc; argc--, args++) + { +char *p, c; +int m1, ofs, n, cur_mask; + + p = args[0 ]; + m1 =grub_strtoul (p, &p,10 ); + + c = *p; +if (c =='-' ) + ofs =0 ; +else if (c ==':' ) + ofs =3 ; +else + goto fail; + + value[ofs] = m1; + cur_mask = (1 << ofs); + mask &= ~(cur_mask * (1 +2 +4 )); + +for (n =1 ; (n <3 ) && (*p); n++) + { +if (*p != c) + goto fail; + + value[ofs + n] =grub_strtoul (p +1 , &p,10 ); + cur_mask |= (1 << (ofs + n)); + } + +if (*p) + goto fail; + +if ((ofs ==0 ) && (n ==2 )) + { + value[ofs +2 ] = value[ofs +1 ]; + value[ofs +1 ] = value[ofs]; + ofs++; + cur_mask <<=1 ; + } + +for (; n; n--, ofs++) +if ((value [ofs] < limit[ofs][0 ]) || + (value [ofs] > limit[ofs][1 ])) + goto fail; + + mask |= cur_mask; + } + +if (grub_get_datetime (&datetime)) +return grub_errno; + +if (mask &GRUB_DATETIME_SET_YEAR ) + datetime.year = value[0 ]; + +if (mask &GRUB_DATETIME_SET_MONTH ) + datetime.month = value[1 ]; + +if (mask &GRUB_DATETIME_SET_DAY ) + datetime.day = value[2 ]; + +if (mask &GRUB_DATETIME_SET_HOUR ) + datetime.hour = value[3 ]; + +if (mask &GRUB_DATETIME_SET_MINUTE ) + datetime.minute = value[4 ]; + +if (mask &GRUB_DATETIME_SET_SECOND ) + datetime.second = value[5 ]; + +return grub_set_datetime (&datetime); + +fail: +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid datetime" ); +} + +GRUB_MOD_INIT (date) +{ + (void ) mod;/* To stop warning. */ +grub_register_command ("date" , grub_cmd_date, +GRUB_COMMAND_FLAG_BOTH , +"date [[year-]month-day] [hour:minute[:second]]" , +"Command to display/set current datetime." ,0 ); +} + +GRUB_MOD_FINI (date) +{ +grub_unregister_command ("date" ); +}
conf/i386-coreboot.rmk +16 -1
@@ -102,7 +102,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod \ _multiboot.mod multiboot.mod aout.mod \ play.mod cpuid.mod serial.mod ata.mod \ memdisk.mod pci.mod lspci.mod reboot.mod \ - halt.mod + halt.mod datetime.mod date.mod datehook.mod # For _linux.mod. _linux_mod_SOURCES = loader/i386/pc/linux.c
@@ -187,4 +187,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = lib/datetime.c lib/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +17 -1
@@ -75,7 +75,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod + _linux.mod linux.mod cpuid.mod halt.mod reboot.mod pci.mod lspci.mod \ + datetime.mod date.mod datehook.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -167,4 +168,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = lib/datetime.c lib/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-ieee1275.rmk +17 -1
@@ -104,7 +104,8 @@ grub_install_SOURCES = util/ieee1275/grub-install.in # Modules. pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod cpuid.mod \ multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod \ - _linux.mod nand.mod memdisk.mod pci.mod lspci.mod + _linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod \ + date.mod datehook.mod # For normal.mod. normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
@@ -188,4 +189,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = lib/datetime.c lib/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +17 -1
@@ -163,7 +163,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \ ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \ - aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod + aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \ + datehook.mod # For biosdisk.mod. biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -340,4 +341,19 @@ pxecmd_mod_SOURCES = commands/i386/pc/pxecmd.c pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = lib/datetime.c lib/i386/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
conf/x86_64-efi.rmk +17 -1
@@ -77,7 +77,8 @@ grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \ - cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod + cpuid.mod halt.mod reboot.mod _linux.mod linux.mod pci.mod lspci.mod \ + datetime.mod date.mod datehook.mod # For kernel.mod. kernel_mod_EXPORTS = no
@@ -169,4 +170,19 @@ lspci_mod_SOURCES = commands/lspci.c lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For datetime.mod +datetime_mod_SOURCES = lib/datetime.c lib/efi/datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
hook/datehook.c new file +106 -0
106 lines not on this page · raw message
include/grub/i386/cmos.h new file +74 -0
74 lines not on this page · raw message
include/grub/lib/datetime.h new file +44 -0
44 lines not on this page · raw message
kern/env.c +2 -2
@@ -146,10 +146,10 @@ grub_env_insert (struct grub_env_context *context,int idx =grub_env_hashval (var->name);/* Insert the variable into the hashtable. */ - var->prevp = &context->vars[idx];; + var->prevp = &context->vars[idx]; var->next = context->vars[idx];if (var->next) - var->next->prevp = &var; + var->next->prevp = &(var->next); context->vars[idx] = var; }
lib/datetime.c new file +49 -0
49 lines not on this page · raw message
lib/efi/datetime.c new file +79 -0
79 lines not on this page · raw message
lib/i386/datetime.c new file +155 -0
155 lines not on this page · raw message
Hi,
Quoted 11 lines · Bean
Oh, please take a look at my other post "Idea: implementation of the password command", it sugguest to implement password with hooks, for example, reading $GET_PASSWORD would prompt the user for password and return the encrypted form.
BTW, I'm thinking perhaps it's better to move the hook function from datetime.mod to datehook.mod, and datetime.mod only contain
grub_get_datetime,grub_set_datetime,grub_get_weekdayandgrub_get_weekday_name. Module like date.mod only need the datetime functions, it's a little wired to install the hook as a side effect.
Fine for me :-)
--
Marco
Quoted 10 lines · Marco Gerards
Hi,
Quoted 6 lines · Bean
Oh, please take a look at my other post "Idea: implementation of the password command", it sugguest to implement password with hooks, for example, reading $GET_PASSWORD would prompt the user for password and return the encrypted form.
Quoted 7 lines
Quoted 5 lines
BTW, I'm thinking perhaps it's better to move the hook function from datetime.mod to datehook.mod, and datetime.mod only contain
grub_get_datetime,grub_set_datetime,grub_get_weekdayandgrub_get_weekday_name. Module like date.mod only need the datetime functions, it's a little wired to install the hook as a side effect.Fine for me :-)
Committed.
Signature · 1 line
Bean