home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <sys/file.h>
-
- #include <mon/nvram.h>
- #include <sgtty.h>
- #include <nextdev/video.h>
-
- #include <stdlib.h>
-
- /*
- * Code for manipulating the RTC for auto-power-on.
- * Based on some /usr/include-searching and disassembling Preferences
- * Hope you can use it.
- * These routines wants to be root; otherwise opening of /dev/vid0 will fail.
- * Caveat: these routines depends on 32bit int's (as god intended int's
- * to be :-) )
- */
-
-
-
- /*
- * Purpose: low-level routine to open device, make an ioctl and close
- * device.
- * Return Code: 0 if opening or ioctl fails; 1 for success
- * Side effects: data pointed to by ptr may be modified.
- */
- static int
- do_nvram_io( int code, void *ptr)
- {
- int fd,ret;
-
- ret = 0;
- if( (fd = open( "/dev/vid0", O_RDONLY)) >= 0 ) {
- if( ioctl( fd, code, ptr) >= 0) {
- ret = 1;
- }
- (void) close( fd );
- }
- return ret;
- }
-
-
- /*
- * Purpose: sets an epoche-time for powering on
- * Return-code: 0 for failure, 1 for success
- * Side-effects: sets a power-on date
- */
- int
- set_nvram_power_on_alarm( int argtime )
- {
- struct alarm tmpalarm;
-
- /* get old copy and modify it */
- if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
- tmpalarm.alarm_time = argtime;
- if( do_nvram_io( DKIOCSALARM, &tmpalarm) > 0) {
- return 1;
- }
- }
- return 0;
- }
-
- /*
- * Purpose: get current power-on time
- * return-code: date as epoche-time (seconds since 1970)
- */
- int
- get_nvram_power_on_alarm()
- {
- struct alarm tmpalarm;
-
- if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
- return tmpalarm.alarm_time;
- }
- return 0;
- }
-
- /*
- * Purpose: is the power-on-date feature enabled ?
- * return-code: 1 for yes, 0 for no or failure
- */
- int
- get_nvram_power_on_alarm_enabled()
- {
- struct alarm tmpalarm;
-
- if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
- return tmpalarm.alarm_enabled;
- }
- return 0;
- }
-
- /*
- * Purpose: enable/disable power-on-date feature
- * return-code: 0 for failure, 1 for success
- */
- int
- set_nvram_power_on_alarm_enabled( int argflag )
- {
- struct alarm tmpalarm;
-
- if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
- tmpalarm.alarm_enabled = argflag;
- if( do_nvram_io( DKIOCSALARM, &tmpalarm) > 0) {
- return 1;
- }
- }
- return 0;
- }
-