Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!lll-winken!csustan!helium!scott From: scott@helium.UUCP (Scott Hazen Mueller) Newsgroups: comp.unix.xenix Subject: uPort V/386 h/w clock Message-ID: <222@helium.UUCP> Date: Mon, 19-Oct-87 18:10:44 EDT Article-I.D.: helium.222 Posted: Mon Oct 19 18:10:44 1987 Date-Received: Tue, 20-Oct-87 23:48:35 EDT Reply-To: scott@helium.UUCP (Scott Hazen Mueller) Organization: City of Turlock, CA Lines: 89 Keywords: program, small, set h/w clock Summary: a program For whatever reason, it's not possible to set the AT(-style) hardware clock on a Microport V/386 system from Unix. In other words, you've got to boot the MsDos setup disk in order to reset the h/w clock, and if you're like me, your built-in clock loses time and your system (software) clock gains time. Not a pretty situation, nor terribly robust. Unfortunately for me, the support person at Microport seems to have been having a bit of difficulty with the notion of there being two clocks, both of which are wrong. So, I've not been able to get them to admit to the existence of a clock setter; given that, I just decided that I would poke around the /usr/include directory until I figured out a little about what's going on. Here's a little hackish program to throw some settings into the clock, then. Please note that I'm giving away all rights, such as they are, and have no intentions of supporting this thing (not as a private citizen, anyway - anybody wanna hire me? :-) though I'm obviously willing to junk it if it proves to be a) dangerous or b) superfluous. Program follows. \scott ----- Snip snip ----- /* Set hardware clock. Input format is on the command line; e.g. stime with white space separating the arguments (that is, don't concatenate them into one big schlurg...). Or, for the perverse the command stime `date '+ %y %m %d %H %M'` can be used. This assumes that your s/w clock is more correct. Since in my case, both are usually wrong, I'll keep it simple. Oh, yeah: this was written under Microport System V/386, release 1.0. It probably won't work under V/AT; it may or may not work on other derivatives of Interactive's port of System V to the 80386. ***** NO ERROR CHECKING ***** Scott Hazen Mueller City of Turlock 901 S. Walnut Rd. Turlock CA 95380 (209) 668-5590 lll-crg!csustan!helium!scott uunet!zorch!helium!scott Disclaimer: this is *free*; I'm giving it away, hoping to stir someone with some documentation into writing a real program, with error-checking and all. I hereby release this program into the public domain and disclaim its fitness for any purpose whatsoever. Use at your own risk. */ #include #include main( argc, argv ) int argc; char *argv[]; { char buf[80]; /* Overkill */ int cd, i; cd = open( "/dev/rtc", O_RDONLY ); /* This is the way these locations were when I first read them. They probably do neat stuff like set daylight savings mode and such. It'd be nice if they were documented. */ buf[0] = 0x0; buf[1] = buf[3] = buf[5] = 1; buf[6] = 6; /* This is gross and disgusting. For some reason, the time values to be set are hex dates. That is, if it's October, and you print the month in decimal, you get '16', but if you use a hex format you get '10'. What I've got to do, then, is scan off the args in hex and stuff them into character- sized locations. There's probably a better way; what do you expect for free? */ sscanf( argv[1], "%x", &i ); buf[9] |= i; sscanf( argv[2], "%x", &i ); buf[8] |= i; sscanf( argv[3], "%x", &i ); buf[7] |= i; sscanf( argv[4], "%x", &i ); buf[4] |= i; sscanf( argv[5], "%x", &i ); buf[2] |= i; /* The year had all of this crud; I dunno why. Real easy to mask it in, though. */ buf[9] |= 0xffffff00; /* Once you've gotten this far, the actual work is trivially simple. */ ioctl( cd, RTCSTIME, buf ); close( cd ); }