Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/boot/settime.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname boot/settime.c 1992/0318
## diff -e /dev/null /n/bootesdump/1992/0318/sys/src/9/boot/settime.c
0a
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include "../boot/boot.h"

void
settime(int islocal)
{
	int n, f;
	int timeset;
	Dir dir;
	char dirbuf[DIRLEN];
	char *srvname;

	print("time...");
	timeset = 0;
	if(islocal){
		/*
		 *  set the time from the real time clock
		 */
		f = open("#r/rtc", ORDWR);
		if(f >= 0){
			if((n = read(f, dirbuf, sizeof(dirbuf)-1)) > 0){
				dirbuf[n] = 0;
				timeset = 1;
			}
			close(f);
		}
	}
	if(timeset == 0){
		/*
		 *  set the time from the access time of the root
		 */
		f = open("#s/boot", ORDWR);
		if(f < 0)
			return;
		if(mount(f, "/n/boot", MREPL, "", "") < 0){
			close(f);
			return;
		}
		close(f);
		if(stat("/n/boot", dirbuf) < 0)
			fatal("stat");
		convM2D(dirbuf, &dir);
		sprint(dirbuf, "%ld", dir.atime);
		unmount(0, "/n/boot");
		/*
		 *  set real time clock if there is one
		 */
		f = open("#r/rtc", ORDWR);
		if(f > 0){
			write(f, dirbuf, strlen(dirbuf));
			close(f);
		}
		close(f);
	}

	f = open("#c/time", OWRITE);
	write(f, dirbuf, strlen(dirbuf));
	close(f);
}
.
## diffname boot/settime.c 1992/0325
## diff -e /n/bootesdump/1992/0318/sys/src/9/boot/settime.c /n/bootesdump/1992/0325/sys/src/9/boot/settime.c
37c
		if(mount(f, "/n/boot", MREPL, "", sauth) < 0){
.
## diffname boot/settime.c 1992/0611
## diff -e /n/bootesdump/1992/0325/sys/src/9/boot/settime.c /n/bootesdump/1992/0611/sys/src/9/boot/settime.c
60a
}

#define SEC2MIN 60L
#define SEC2HOUR (60L*SEC2MIN)
#define SEC2DAY (24L*SEC2HOUR)

int
g2(char **pp)
{
	int v;

	v = 10*((*pp)[0]-'0') + (*pp)[1]-'0';
	*pp += 2;
	return v;
}

/*
 *  days per month plus days/year
 */
static	int	dmsize[] =
{
	365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
static	int	ldmsize[] =
{
	366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};

/*
 *  return the days/month for the given year
 */
static int *
yrsize(int yr)
{
	if((yr % 4) == 0)
		return ldmsize;
	else
		return dmsize;
}

/*
 *  compute seconds since Jan 1 1970
 */
static long
lusertime(char *argbuf)
{
	char *buf;
	ulong secs;
	int i, y, m;
	int *d2m;

	buf = argbuf;
	i = strlen(buf);
	if(i != 10 && i != 12)
		return -1;
	secs = 0;
	y = g2(&buf);
	m = g2(&buf);
	if(y < 70)
		y += 2000;
	else
		y += 1900;

	/*
	 *  seconds per year
	 */
	for(i = 1970; i < y; i++){
		d2m = yrsize(i);
		secs += d2m[0] * SEC2DAY;
	}

	/*
	 *  seconds per month
	 */
	d2m = yrsize(y);
	for(i = 1; i < m; i++)
		secs += d2m[i] * SEC2DAY;

	secs += (g2(&buf)-1) * SEC2DAY;
	secs += g2(&buf) * SEC2HOUR;
	secs += g2(&buf) * SEC2MIN;
	if(*buf)
		secs += g2(&buf);

	sprint(argbuf, "%ld", secs);
	return secs;
.
59c
	if(write(f, dirbuf, strlen(dirbuf)) < 0)
		warning("can't set #c/time");
.
55d
28c
		}else do{
			strcpy(dirbuf, "yymmddhhmm[ss]");
			outin("\ndate/time ", dirbuf, sizeof(dirbuf));
		}while((timeset=lusertime(dirbuf)) <= 0);
.
5a
static long lusertime(char*);

.
## diffname boot/settime.c 1992/0808
## diff -e /n/bootesdump/1992/0611/sys/src/9/boot/settime.c /n/bootesdump/1992/0808/sys/src/9/boot/settime.c
15d
## diffname boot/settime.c 1992/0909
## diff -e /n/bootesdump/1992/0808/sys/src/9/boot/settime.c /n/bootesdump/1992/0909/sys/src/9/boot/settime.c
38c
		f = open(timeserver, ORDWR);
.
7a
char *timeserver = "#s/boot";

.
## diffname boot/settime.c 1992/0912
## diff -e /n/bootesdump/1992/0909/sys/src/9/boot/settime.c /n/bootesdump/1992/0912/sys/src/9/boot/settime.c
43,46c
		if(mount(f, "/n/boot", MREPL, "", sauth) < 0)
			if(mount(f, "/n/boot", MREPL, "", "any") < 0){
				close(f);
				return;
			}
.
## diffname boot/settime.c 1993/0330
## diff -e /n/bootesdump/1992/0912/sys/src/9/boot/settime.c /n/bootesdump/1993/0330/sys/src/9/boot/settime.c
43,47c
		if(mount(f, "/n/boot", MREPL, "") < 0){
warning("settime mount");
			close(f);
			return;
		}
.
2a
#include <auth.h>
.
## diffname boot/settime.c 1993/0501
## diff -e /n/bootesdump/1993/0330/sys/src/9/boot/settime.c /n/fornaxdump/1993/0501/sys/src/brazil/boot/settime.c
68a
	print("\n");
.
45c
			warning("settime mount");
.
## diffname boot/settime.c 1999/0113
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/boot/settime.c /n/emeliedump/1999/0113/sys/src/brazil/boot/settime.c
104c

	if((y%4) == 0 && ((y%100) != 0 || (y%400) == 0))
.
102c
yrsize(int y)
.
## diffname boot/settime.c 1999/0305
## diff -e /n/emeliedump/1999/0113/sys/src/brazil/boot/settime.c /n/emeliedump/1999/0305/sys/src/brazil/boot/settime.c
55,62d
## diffname boot/settime.c 2000/0310
## diff -e /n/emeliedump/1999/0305/sys/src/brazil/boot/settime.c /n/emeliedump/2000/0310/sys/src/9/boot/settime.c
54c
		unmount(0, "/mnt");
.
50c
		if(stat("/mnt", dirbuf) < 0)
.
44c
		if(mount(f, "/mnt", MREPL, "") < 0){
.
## diffname boot/settime.c 2001/0527
## diff -e /n/emeliedump/2000/0310/sys/src/9/boot/settime.c /n/emeliedump/2001/0527/sys/src/9/boot/settime.c
58c
	if(write(f, timebuf, strlen(timebuf)) < 0)
.
52,53c
		convM2D(statbuf, sizeof statbuf, &dir[0], (char*)&dir[1]);
		sprint(timebuf, "%ld", dir[0].atime);
.
50c
		if(stat("/mnt", statbuf, sizeof statbuf) < 0)
.
33,35c
			strcpy(timebuf, "yymmddhhmm[ss]");
			outin("\ndate/time ", timebuf, sizeof(timebuf));
		}while((timeset=lusertime(timebuf)) <= 0);
.
27,28c
			if((n = read(f, timebuf, sizeof(timebuf)-1)) > 0){
				timebuf[n] = '\0';
.
16,17c
	Dir dir[2];
	char timebuf[64];
.
5a
/*BUG transition*/
int client9p=2;
int kernel9p=2;
.
## diffname boot/settime.c 2001/0819
## diff -e /n/emeliedump/2001/0527/sys/src/9/boot/settime.c /n/emeliedump/2001/0819/sys/src/9/boot/settime.c
57c
		unmount(0, "/tmp");
.
53c
		if(stat("/tmp", statbuf, sizeof statbuf) < 0)
.
47c
		if(mount(f, afd, "/tmp", MREPL, "") < 0){
.
15c
settime(int islocal, int afd)
.
## diffname boot/settime.c 2002/0115
## diff -e /n/emeliedump/2001/0819/sys/src/9/boot/settime.c /n/emeliedump/2002/0115/sys/src/9/boot/settime.c
6,8d
## diffname boot/settime.c 2002/1002
## diff -e /n/emeliedump/2002/0115/sys/src/9/boot/settime.c /n/emeliedump/2002/1002/sys/src/9/boot/settime.c
44c
		if(mount(f, afd, "/tmp", MREPL, rp) < 0){
.
12c
settime(int islocal, int afd, char *rp)
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].